Scratch space for learning atproto app development
1import { OAuthClient } from '@atproto/oauth-client-node' 2 3export interface BidirectionalResolver { 4 resolveDidToHandle(did: string): Promise<string | undefined> 5 resolveDidsToHandles( 6 dids: string[], 7 ): Promise<Record<string, string | undefined>> 8} 9 10export function createBidirectionalResolver({ 11 identityResolver, 12}: OAuthClient): BidirectionalResolver { 13 return { 14 async resolveDidToHandle(did: string): Promise<string | undefined> { 15 try { 16 const { handle } = await identityResolver.resolve(did) 17 if (handle) return handle 18 } catch { 19 // Ignore 20 } 21 }, 22 23 async resolveDidsToHandles( 24 dids: string[], 25 ): Promise<Record<string, string | undefined>> { 26 const uniqueDids = [...new Set(dids)] 27 28 return Object.fromEntries( 29 await Promise.all( 30 uniqueDids.map((did) => 31 this.resolveDidToHandle(did).then((handle) => [did, handle]), 32 ), 33 ), 34 ) 35 }, 36 } 37}