we still dynamically import the web did doc resolver if we need to resolve a did:web: but since it's an async import it should get codesplit on the client side
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import type { DidDocument } from "@atcute/identity";
|
|
import type { WebDidDocumentResolver } from "@atcute/identity-resolver";
|
|
import type { ATProtoUniverse } from "@char/lexicon.ts/atproto";
|
|
import { XRPC } from "@char/lexicon.ts/rpc";
|
|
|
|
const bskyPublic = new XRPC<ATProtoUniverse>("https://public.api.bsky.app");
|
|
|
|
export async function resolveHandle(handle: string): Promise<`did:${string}`> {
|
|
const { did } = await bskyPublic.get("com.atproto.identity.resolveHandle", {
|
|
params: { handle },
|
|
});
|
|
return did;
|
|
}
|
|
|
|
export async function resolveDid(did: string): Promise<DidDocument> {
|
|
if (did.startsWith("did:plc:")) {
|
|
const doc = await fetch("https://plc.directory/" + did).then((r) =>
|
|
r.json()
|
|
);
|
|
return doc;
|
|
} else if (did.startsWith("did:web:")) {
|
|
// TODO: write our own did:web resolver (maybe use a CORS proxy on clientside)
|
|
const resolver: WebDidDocumentResolver = await import(
|
|
"@atcute/identity-resolver"
|
|
)
|
|
.then((m) => m.WebDidDocumentResolver)
|
|
.then((r) => new r());
|
|
return resolver.resolve(did as `did:web:${string}`);
|
|
}
|
|
|
|
throw new Error("unsupported did type: " + did);
|
|
}
|