A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at main 33 lines 894 B view raw
1export default async function extractPdsFromDid( 2 did: string, 3): Promise<string | null> { 4 let didDocUrl: string; 5 6 if (did.startsWith("did:plc:")) { 7 didDocUrl = `https://plc.directory/${did}`; 8 } else if (did.startsWith("did:web:")) { 9 const domain = did.substring("did:web:".length); 10 didDocUrl = `https://${domain}/.well-known/did.json`; 11 } else { 12 throw new Error("Unsupported DID method"); 13 } 14 15 const response = await fetch(didDocUrl); 16 if (!response.ok) throw new Error("Failed to fetch DID doc"); 17 18 const doc: { 19 service?: Array<{ 20 type: string; 21 id: string; 22 serviceEndpoint: string; 23 }>; 24 } = await response.json(); 25 26 // Find the atproto PDS service 27 const pdsService = doc.service?.find( 28 (s: any) => 29 s.type === "AtprotoPersonalDataServer" && s.id.endsWith("#atproto_pds"), 30 ); 31 32 return pdsService?.serviceEndpoint ?? null; 33}