Created
February 6, 2025 17:34
-
-
Save alanshaw/7925e7462e58aef1286619bf3452a2a9 to your computer and use it in GitHub Desktop.
Visualise a delegation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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