This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: implement resolveToHandle method using agent.getProfile for DID resolution

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

+61
+61
src/modules/atproto/infrastructure/services/ATProtoIdentityResolutionService.ts
··· 2 2 import { IIdentityResolutionService } from '../../domain/services/IIdentityResolutionService'; 3 3 import { DID } from '../../domain/DID'; 4 4 import { DIDOrHandle } from '../../domain/DIDOrHandle'; 5 + import { Handle } from '../../domain/Handle'; 5 6 import { IAgentService } from '../../application/IAgentService'; 6 7 7 8 export class ATProtoIdentityResolutionService ··· 64 65 return err( 65 66 new Error( 66 67 `Error resolving identifier to DID: ${error instanceof Error ? error.message : String(error)}`, 68 + ), 69 + ); 70 + } 71 + } 72 + 73 + async resolveToHandle(identifier: DIDOrHandle): Promise<Result<Handle>> { 74 + try { 75 + // If it's already a handle, return it directly 76 + if (identifier.isHandle) { 77 + const handle = identifier.getHandle(); 78 + if (!handle) { 79 + return err(new Error('Invalid handle in identifier')); 80 + } 81 + return ok(handle); 82 + } 83 + 84 + // If it's a DID, resolve it to a handle 85 + const did = identifier.getDID(); 86 + if (!did) { 87 + return err(new Error('Invalid DID in identifier')); 88 + } 89 + 90 + // Get an unauthenticated agent to resolve the DID 91 + const agentResult = this.agentService.getUnauthenticatedAgent(); 92 + if (agentResult.isErr()) { 93 + return err( 94 + new Error( 95 + `Failed to get agent for DID resolution: ${agentResult.error.message}`, 96 + ), 97 + ); 98 + } 99 + 100 + const agent = agentResult.value; 101 + 102 + // Get the profile to extract the handle 103 + const profileResult = await agent.getProfile({ actor: did.value }); 104 + 105 + if (!profileResult.success) { 106 + return err( 107 + new Error( 108 + `Failed to resolve DID ${did.value}: ${JSON.stringify(profileResult)}`, 109 + ), 110 + ); 111 + } 112 + 113 + // Create and return the Handle 114 + const handleResult = Handle.create(profileResult.data.handle); 115 + if (handleResult.isErr()) { 116 + return err( 117 + new Error( 118 + `Invalid handle returned from DID resolution: ${handleResult.error.message}`, 119 + ), 120 + ); 121 + } 122 + 123 + return ok(handleResult.value); 124 + } catch (error) { 125 + return err( 126 + new Error( 127 + `Error resolving identifier to handle: ${error instanceof Error ? error.message : String(error)}`, 67 128 ), 68 129 ); 69 130 }