Fork of github.com/did-method-plc/did-method-plc
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

support rendering DID docs for unrecognized key formats

+17 -5
+17 -5
packages/lib/src/document.ts
··· 12 12 const verificationMethods: VerificationMethod[] = [] 13 13 for (const [keyid, key] of Object.entries(data.verificationMethods)) { 14 14 const info = formatKeyAndContext(key) 15 - if (!context.includes(info.context)) { 15 + if (info.context && !context.includes(info.context)) { 16 16 context.push(info.context) 17 17 } 18 18 verificationMethods.push({ ··· 55 55 } 56 56 57 57 type KeyAndContext = { 58 - context: string 58 + context?: string 59 59 type: string 60 - publicKeyMultibase 60 + publicKeyMultibase: string 61 61 } 62 62 63 63 const formatKeyAndContext = (key: string): KeyAndContext => { ··· 65 65 try { 66 66 keyInfo = crypto.parseDidKey(key) 67 67 } catch (err) { 68 - throw new UnsupportedKeyError(key, err) 68 + return { 69 + // we can't specify a context for a key type we don't recognize 70 + type: 'Multikey', 71 + publicKeyMultibase: key.replace(/^(did:key:)/, ''), 72 + } 69 73 } 70 74 const { jwtAlg } = keyInfo 71 75 ··· 82 86 publicKeyMultibase: key.replace(/^(did:key:)/, ''), 83 87 } 84 88 } 85 - throw new UnsupportedKeyError(key, `Unsupported key type: ${jwtAlg}`) 89 + 90 + // this codepath might seem unreachable/redundant, but it's possible 91 + // parseDidKey() supports more key formats in future, before this function 92 + // can be updated likewise 93 + return { 94 + // we can't specify a context for a key type we don't recognize 95 + type: 'Multikey', 96 + publicKeyMultibase: key.replace(/^(did:key:)/, ''), 97 + } 86 98 }