this repo has no description
0
fork

Configure Feed

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

Fix attempting to parse did:key twice

Fixes #1

futurGH 024e7006 75410cf5

+6 -7
+6 -7
src/util/crypto.ts
··· 152 152 */ 153 153 function verifySignatureWithKey(didKey: string, msgBytes: Uint8Array, sigBytes: Uint8Array) { 154 154 if (!didKey.startsWith("did:key:")) throw new Error("Incorrect prefix for did:key: " + didKey); 155 - const multikey = didKey.slice("did:key:".length); 156 - const { jwtAlg } = parseMultikey(multikey); 155 + const { jwtAlg } = parseDidMultikey(didKey); 157 156 const curve = jwtAlg === P256_JWT_ALG ? "p256" : "k256"; 158 157 return verifyDidSig(curve, didKey, msgBytes, sigBytes); 159 158 } ··· 185 184 } else if (key.type === "EcdsaSecp256k1VerificationKey2019") { 186 185 didKey = formatDidKey(SECP256K1_JWT_ALG, keyBytes); 187 186 } else if (key.type === "Multikey") { 188 - const parsed = parseMultikey(key.publicKeyMultibase); 187 + const parsed = parseDidMultikey("did:key:" + key.publicKeyMultibase); 189 188 didKey = formatDidKey(parsed.jwtAlg, parsed.keyBytes); 190 189 } 191 190 if (!didKey) throw new Error(`Could not parse signingKey from doc: ${JSON.stringify(doc)}`); ··· 304 303 305 304 /** 306 305 * Parses and decompresses the public key and JWT algorithm from multibase. 307 - * @param key The multikey to parse. 306 + * @param didKey The did:key to parse. 308 307 */ 309 - const parseMultikey = ( 310 - key: string, 308 + const parseDidMultikey = ( 309 + didKey: string, 311 310 ): { jwtAlg: typeof P256_JWT_ALG | typeof SECP256K1_JWT_ALG; keyBytes: Uint8Array } => { 312 - const multikey = extractMultikey(key); 311 + const multikey = extractMultikey(didKey); 313 312 const prefixedBytes = extractPrefixedBytes(multikey); 314 313 315 314 const keyCurve = hasPrefix(prefixedBytes, P256_DID_PREFIX)