Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created February 6, 2025 17:34
Show Gist options
  • Save alanshaw/7925e7462e58aef1286619bf3452a2a9 to your computer and use it in GitHub Desktop.
Save alanshaw/7925e7462e58aef1286619bf3452a2a9 to your computer and use it in GitHub Desktop.
Visualise a delegation
import fs from 'node:fs'
import { Readable } from 'node:stream'
import { CARReaderStream } from 'carstream'
import * as dagCBOR from '@ipld/dag-cbor'
import * as dagJSON from '@ipld/dag-json'
import * as DID from '@ipld/dag-ucan/did'
Readable.toWeb(fs.createReadStream('proof.car'))
.pipeThrough(new CARReaderStream())
.pipeTo(new WritableStream({
write (block) {
console.log(block.cid.toString())
const obj = dagCBOR.decode(block.bytes)
if (obj.iss) {
obj.iss = DID.decode(obj.iss).did()
}
if (obj.aud) {
obj.aud = DID.decode(obj.aud).did()
}
console.log(JSON.stringify(JSON.parse(dagJSON.format(obj)), null, 2))
console.log('===')
}
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment