Conversation
|
@fforbeck do you want to update the dependencies? |
sure thing @alanshaw - but I need this PR merged and released first: storacha/upload-service#273 |
alanshaw
left a comment
There was a problem hiding this comment.
I left a few suggestions - would be good to get the options jsdoc changes done but everything else non-blocking :)
| const bytes = base58btc.decode(publicKeyMultibase) // assumes 'z'-prefix | ||
| const [code] = varint.decode(bytes) | ||
| switch (code) { | ||
| case 0xed: { // Ed25519 |
There was a problem hiding this comment.
| case 0xed: { // Ed25519 | |
| case ed25519.Verifier.code: { |
|
|
||
|
|
||
| /** | ||
| * @typedef {Record<`did:web:${string}`, `did:key:${string}`>} PrincipalMapping |
There was a problem hiding this comment.
Might be better to use DID<'web'> and DID<'key'> types?
| * @param {object} options | ||
| * @param {PrincipalMapping} options.principalMapping - Mapping of known WebDIDs to their corresponding DIDKeys | ||
| * @param {import('@storacha/did-plc').PlcClient} options.plcClient - PLC client to use for resolving PLC DIDs | ||
| * @returns {(did: `did:${string}:${string}`) => Promise<import('@ucanto/interface').Result<`did:key:${string}`[], DIDResolutionError>>} |
There was a problem hiding this comment.
Might be better to use DID<'web'> and DID<'key'> types?
| * @param {object} options | ||
| * @param {PrincipalMapping} options.principalMapping - Mapping of known WebDIDs to their corresponding DIDKeys | ||
| * @param {import('@storacha/did-plc').PlcClient} options.plcClient - PLC client to use for resolving PLC DIDs |
There was a problem hiding this comment.
| * @param {object} options | |
| * @param {PrincipalMapping} options.principalMapping - Mapping of known WebDIDs to their corresponding DIDKeys | |
| * @param {import('@storacha/did-plc').PlcClient} options.plcClient - PLC client to use for resolving PLC DIDs | |
| * @param {object} [options] | |
| * @param {PrincipalMapping} [options.principalMapping] - Mapping of known WebDIDs to their corresponding DIDKeys | |
| * @param {import('@storacha/did-plc').PlcClient} [options.plcClient] - PLC client to use for resolving PLC DIDs |
| * @param {`did:${string}:${string}`} did | ||
| */ | ||
| return async (did) => { | ||
| if (Schema.did({ method: 'web' }).is(did) && options.principalMapping) { |
There was a problem hiding this comment.
| if (Schema.did({ method: 'web' }).is(did) && options.principalMapping) { | |
| if (Schema.did({ method: 'web' }).is(did) && options?.principalMapping) { |
| return resolveDIDWeb(did, options.principalMapping) | ||
| } | ||
|
|
||
| if (Schema.did({ method: 'plc' }).is(did) && options.plcClient) { |
There was a problem hiding this comment.
| if (Schema.did({ method: 'plc' }).is(did) && options.plcClient) { | |
| if (Schema.did({ method: 'plc' }).is(did) && options?.plcClient) { |
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(`unable to parse public key from verification method ${publicKeyMultibase}`, err) |
There was a problem hiding this comment.
Still just a warning...
| console.error(`unable to parse public key from verification method ${publicKeyMultibase}`, err) | |
| console.warn(`unable to parse public key from verification method ${publicKeyMultibase}`, err) |
| const [code] = varint.decode(bytes) | ||
| switch (code) { | ||
| case 0xed: { // Ed25519 | ||
| return ed25519.Verifier.parse(publicKeyMultibase) |
There was a problem hiding this comment.
You return null either way (if it's unsupported or invalid), I'm not sure the complexity is worth it here just to log the right message. I'd just parse and change the log message in the catch to unsupported or invalid verification method: ${publicKeyMultibase}.
Hmm, I meant the ucanto dependencies that are referenced as |
DID PLC Resolver
Overview
Created a DID resolver helper to support both Web and PLC DID resolution. The resolver uses an optional
optionsobject and has dedicated resolution functions for each DID method that can be easily extended.Main Changes
createDidResolverto use optionaloptionsobjectresolveDIDWebandresolveDIDPlcfunctionsmultikeyformatUsage
Related: storacha/project-tracking#463