UNPKG

@rocksky/cli

Version:

Command-line interface for Rocksky – scrobble tracks, view stats, and manage your listening history

34 lines (28 loc) 894 B
export default async function extractPdsFromDid( did: string, ): Promise<string | null> { let didDocUrl: string; if (did.startsWith("did:plc:")) { didDocUrl = `https://plc.directory/${did}`; } else if (did.startsWith("did:web:")) { const domain = did.substring("did:web:".length); didDocUrl = `https://${domain}/.well-known/did.json`; } else { throw new Error("Unsupported DID method"); } const response = await fetch(didDocUrl); if (!response.ok) throw new Error("Failed to fetch DID doc"); const doc: { service?: Array<{ type: string; id: string; serviceEndpoint: string; }>; } = await response.json(); // Find the atproto PDS service const pdsService = doc.service?.find( (s: any) => s.type === "AtprotoPersonalDataServer" && s.id.endsWith("#atproto_pds"), ); return pdsService?.serviceEndpoint ?? null; }