Fork of atp.tools as a universal profile for people on the ATmosphere
1import { DidDocument } from "@atcute/client/utils/did";
2
3export default async function getDidDoc(did: string): Promise<DidDocument> {
4 try {
5 if (did.startsWith("did:web:")) {
6 const response = await fetch(
7 `https://${did.replace("did:web:", "")}/.well-known/did.json`,
8 );
9 return await response.json();
10 } else if (did.startsWith("did:plc")) {
11 const response = await fetch(`https://plc.directory/${did}`);
12 return await response.json();
13 }
14 throw new Error(`Unsupported DID format: ${did}`);
15 } catch (error) {
16 throw new Error(
17 `Failed to fetch DID document: ${error instanceof Error ? error.message : String(error)}`,
18 );
19 }
20}