this repo has no description
0
fork

Configure Feed

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

Fix parsing invalid/not found DID document

futurGH a38a6da7 043696ab

+10 -6
+10 -6
src/util/crypto.ts
··· 1 1 import { XRPCError } from "@atcute/client"; 2 + import type { DidDocument } from "@atcute/client/utils/did"; 2 3 import { p256 } from "@noble/curves/p256"; 3 4 import { secp256k1 as k256 } from "@noble/curves/secp256k1"; 4 5 import { sha256 } from "@noble/hashes/sha256"; ··· 41 42 }); 42 43 if (!res.ok) throw new Error(`Could not resolve DID: ${did}`); 43 44 44 - didKey = parseKeyFromDidDocument(await res.json(), did); 45 + didKey = parseKeyFromDidDocument(await res.json() as never, did); 45 46 } else if (didMethod === "web") { 46 47 if (!didValueParts.length) throw new Error(`Poorly formatted DID: ${did}`); 47 48 if (didValueParts.length > 1) throw new Error(`Unsupported did:web paths: ${did}`); ··· 52 53 }); 53 54 if (!res.ok) throw new Error(`Could not resolve DID: ${did}`); 54 55 55 - didKey = parseKeyFromDidDocument(await res.json(), did); 56 + didKey = parseKeyFromDidDocument(await res.json() as never, did); 56 57 } 57 58 58 59 if (!didKey) throw new Error(`Could not resolve DID: ${did}`); ··· 163 164 * @param did The DID the document is for. 164 165 * @returns The atproto signing key. 165 166 */ 166 - const parseKeyFromDidDocument = (doc: any, did: string): string => { 167 - const key = (doc as Array<any>).find((method) => 168 - method.id === `${did}#atproto` || method.id === `#atproto` 167 + const parseKeyFromDidDocument = (doc: DidDocument, did: string): string => { 168 + if (!Array.isArray(doc?.verificationMethod)) { 169 + throw new Error(`Could not parse signingKey from doc: ${JSON.stringify(doc)}`); 170 + } 171 + const key = doc.verificationMethod.find((method) => 172 + method?.id === `${did}#atproto` || method?.id === `#atproto` 169 173 ); 170 174 if ( 171 175 !key || typeof key !== "object" || !("type" in key) || typeof key.type !== "string" ··· 184 188 const parsed = parseMultikey(key.publicKeyMultibase); 185 189 didKey = formatDidKey(parsed.jwtAlg, parsed.keyBytes); 186 190 } 187 - if (!didKey) throw new Error(`Could not parse signingKey from doc: ${doc}`); 191 + if (!didKey) throw new Error(`Could not parse signingKey from doc: ${JSON.stringify(doc)}`); 188 192 return didKey; 189 193 }; 190 194