33Resolution is performed using the IndyLedger class.
44"""
55
6- from typing import Pattern
6+ from typing import Any , Mapping , Pattern
77
88from pydid import DID , DIDDocumentBuilder
9- from pydid .verification_method import Ed25519VerificationKey2018
9+ from pydid .verification_method import Ed25519VerificationKey2018 , VerificationMethod
1010
1111from ...config .injection_context import InjectionContext
1212from ...core .profile import Profile
@@ -29,7 +29,10 @@ class NoIndyLedger(ResolverError):
2929class IndyDIDResolver (BaseDIDResolver ):
3030 """Indy DID Resolver."""
3131
32- AGENT_SERVICE_TYPE = "did-communication"
32+ SERVICE_TYPE_DID_COMMUNICATION = "did-communication"
33+ SERVICE_TYPE_DIDCOMM = "DIDComm"
34+ SERVICE_TYPE_ENDPOINT = "endpoint"
35+ CONTEXT_DIDCOMM_V2 = "https://didcomm.org/messaging/contexts/v2"
3336
3437 def __init__ (self ):
3538 """Initialize Indy Resolver."""
@@ -43,6 +46,60 @@ def supported_did_regex(self) -> Pattern:
4346 """Return supported_did_regex of Indy DID Resolver."""
4447 return IndyDID .PATTERN
4548
49+ def _add_endpoint_as_endpoint_value_pair (
50+ self ,
51+ builder : DIDDocumentBuilder ,
52+ endpoint : str ,
53+ recipient_key : VerificationMethod ,
54+ ):
55+ builder .service .add_didcomm (
56+ ident = self .SERVICE_TYPE_DID_COMMUNICATION ,
57+ type_ = self .SERVICE_TYPE_DID_COMMUNICATION ,
58+ service_endpoint = endpoint ,
59+ priority = 1 ,
60+ recipient_keys = [recipient_key ],
61+ routing_keys = [],
62+ )
63+
64+ def _add_endpoint_as_map (
65+ self ,
66+ builder : DIDDocumentBuilder ,
67+ endpoint : Mapping [str , Any ],
68+ recipient_key : VerificationMethod ,
69+ ):
70+ types = endpoint .get ("types" , [self .SERVICE_TYPE_DID_COMMUNICATION ])
71+ routing_keys = endpoint .get ("routingKeys" , [])
72+ endpoint_url = endpoint .get ("endpoint" )
73+ if not endpoint_url :
74+ raise ValueError ("endpoint url not found in endpoint attrib" )
75+
76+ if self .SERVICE_TYPE_DIDCOMM in types :
77+ builder .service .add (
78+ ident = "#didcomm-1" ,
79+ type_ = self .SERVICE_TYPE_DIDCOMM ,
80+ service_endpoint = endpoint_url ,
81+ recipient_keys = [recipient_key .id ],
82+ routing_keys = routing_keys ,
83+ accept = ["didcomm/v2" ],
84+ )
85+ builder .context .append (self .CONTEXT_DIDCOMM_V2 )
86+ if self .SERVICE_TYPE_DID_COMMUNICATION in types :
87+ builder .service .add (
88+ ident = "did-communication" ,
89+ type_ = self .SERVICE_TYPE_DID_COMMUNICATION ,
90+ service_endpoint = endpoint_url ,
91+ priority = 1 ,
92+ routing_keys = routing_keys ,
93+ recipient_keys = [recipient_key .id ],
94+ accept = ["didcomm/aip2;env=rfc19" ],
95+ )
96+ if self .SERVICE_TYPE_ENDPOINT in types :
97+ builder .service .add (
98+ ident = "endpoint" ,
99+ service_endpoint = endpoint_url ,
100+ type_ = self .SERVICE_TYPE_ENDPOINT ,
101+ )
102+
46103 async def _resolve (self , profile : Profile , did : str ) -> dict :
47104 """Resolve an indy DID."""
48105 multitenant_mgr = profile .inject_or (BaseMultitenantManager )
@@ -76,16 +133,14 @@ async def _resolve(self, profile: Profile, did: str) -> dict:
76133 if endpoints :
77134 for type_ , endpoint in endpoints .items ():
78135 if type_ == EndpointType .ENDPOINT .indy :
79- builder .service .add_didcomm (
80- ident = self .AGENT_SERVICE_TYPE ,
81- type_ = self .AGENT_SERVICE_TYPE ,
82- service_endpoint = endpoint ,
83- priority = 1 ,
84- recipient_keys = [vmethod ],
85- routing_keys = [],
86- )
136+ if isinstance (endpoint , dict ):
137+ self ._add_endpoint_as_map (builder , endpoint , vmethod )
138+ else :
139+ self ._add_endpoint_as_endpoint_value_pair (
140+ builder , endpoint , vmethod
141+ )
87142 else :
88- # Accept all service types for now
143+ # Accept all service types for now, i.e. profile, linked_domains
89144 builder .service .add (
90145 ident = type_ ,
91146 type_ = type_ ,
0 commit comments