import { OAuthClient } from '@atproto/oauth-client-node' export interface BidirectionalResolver { resolveDidToHandle(did: string): Promise resolveDidsToHandles( dids: string[], ): Promise> } export function createBidirectionalResolver({ identityResolver, }: OAuthClient): BidirectionalResolver { return { async resolveDidToHandle(did: string): Promise { try { const { handle } = await identityResolver.resolve(did) if (handle) return handle } catch { // Ignore } }, async resolveDidsToHandles( dids: string[], ): Promise> { const uniqueDids = [...new Set(dids)] return Object.fromEntries( await Promise.all( uniqueDids.map((did) => this.resolveDidToHandle(did).then((handle) => [did, handle]), ), ), ) }, } }