Sifa professional network API (Fastify, AT Protocol, Jetstream) sifa.id/
at main 29 lines 858 B view raw
1import { isValidHandle, isValidDid } from '@atproto/syntax'; 2import { Agent } from '@atproto/api'; 3 4export const isHandle = isValidHandle; 5export const isDid = isValidDid; 6 7export async function resolveHandleOrDid( 8 handleOrDid: string, 9): Promise<{ did: string; handle: string }> { 10 const agent = new Agent('https://public.api.bsky.app'); 11 12 if (isDid(handleOrDid)) { 13 const profile = await agent.getProfile( 14 { actor: handleOrDid }, 15 { signal: AbortSignal.timeout(3000) }, 16 ); 17 return { did: profile.data.did, handle: profile.data.handle }; 18 } 19 20 if (isHandle(handleOrDid)) { 21 const resolved = await agent.resolveHandle( 22 { handle: handleOrDid }, 23 { signal: AbortSignal.timeout(3000) }, 24 ); 25 return { did: resolved.data.did, handle: handleOrDid }; 26 } 27 28 throw new Error(`Invalid handle or DID: ${handleOrDid}`); 29}