Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): allow read base58btc encoded multihash as well as CID #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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() })
Expand Down
Loading