From f42f35f569883aa18e769ced183c0b20b1d34f0e Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 13 Dec 2024 10:11:23 +0000 Subject: [PATCH] feat(cli): allow read base58btc encoded multihash as well as CID --- packages/cli/bin.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/cli/bin.js b/packages/cli/bin.js index c7b1526..0663e2b 100755 --- a/packages/cli/bin.js +++ b/packages/cli/bin.js @@ -7,7 +7,10 @@ import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { inspect } from 'node:util' import { Writable } from 'node:stream' +import { base58btc } from 'multiformats/bases/base58' +import * as raw from 'multiformats/codecs/raw' import * as Link from 'multiformats/link' +import * as Digest from 'multiformats/hashes/digest' import * as ed25519 from '@ucanto/principal/ed25519' import { DID, UCAN } from '@ucanto/core' import * as Delegation from '@ucanto/core/delegation' @@ -206,7 +209,12 @@ prog .option('--verbose', 'Write claim information to stderr.') .option('-o, --output', 'Write output to this file.') .action(async (contentArg, opts) => { - const content = Link.parse(contentArg) + let content + try { + content = Link.parse(contentArg) + } catch { + content = Link.create(raw.code, Digest.decode(base58btc.decode(contentArg))) + } const walk = Array.isArray(opts.walk) ? opts.walk : opts.walk?.split(',') const res = await Client.fetch(content.multihash, { walk, serviceURL }) if (!res.ok) throw new Error(`unexpected service status: ${res.status}`, { cause: await res.text() })