Something went wrong. Try again.
Scratch space for learning atproto app development
Something went wrong. Try again.
973 B · 37 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738import { OAuthClient } from '@atproto/oauth-client-node'
export interface BidirectionalResolver { resolveDidToHandle(did: string): Promise<string | undefined> resolveDidsToHandles( dids: string[], ): Promise<Record<string, string | undefined>>}
export function createBidirectionalResolver({ identityResolver,}: OAuthClient): BidirectionalResolver { return { async resolveDidToHandle(did: string): Promise<string | undefined> { try { const { handle } = await identityResolver.resolve(did) if (handle) return handle } catch { // Ignore } },
async resolveDidsToHandles( dids: string[], ): Promise<Record<string, string | undefined>> { const uniqueDids = [...new Set(dids)]
return Object.fromEntries( await Promise.all( uniqueDids.map((did) => this.resolveDidToHandle(did).then((handle) => [did, handle]), ), ), ) }, }}