Something went wrong. Try again.
A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536import { PLC_DIRECTORY_URL } from "./plc";
export default async function extractPdsFromDid( did: string,): Promise<string | null> { let didDocUrl: string;
if (did.startsWith("did:plc:")) { didDocUrl = `${PLC_DIRECTORY_URL}/${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;}