11import logging
2- from typing import Literal , cast
2+ from typing import cast
33
44from hiero_sdk_python import Client , PrivateKey , PublicKey , TopicMessageSubmitTransaction
55from hiero_sdk_python .transaction .transaction import Transaction
@@ -153,29 +153,19 @@ async def delete(self):
153153
154154 await self ._submit_transaction (DidDocumentOperation .DELETE , HcsDidDeleteEvent ())
155155
156- async def add_service (self , id_ : str , service_type : DidServiceType , service_endpoint : str ):
157- """Add Service to DID document
156+ async def add_or_update_service (self , id_ : str , service_type : DidServiceType , service_endpoint : str ):
157+ """Add or update DID document service
158158
159159 Args:
160160 id_: Service ID to create
161161 service_type: DID service type
162162 service_endpoint: Service endpoint
163163 """
164- await self ._add_or_update_service (
165- DidDocumentOperation .CREATE , id_ = id_ , type_ = service_type , service_endpoint = service_endpoint
166- )
164+ self ._assert_can_submit_transaction ()
167165
168- async def update_service (self , id_ : str , service_type : DidServiceType , service_endpoint : str ):
169- """Update existing DID document service
166+ hcs_event = HcsDidUpdateServiceEvent (id_ = id_ , type_ = service_type , service_endpoint = service_endpoint )
170167
171- Args:
172- id_: Service ID to update
173- service_type: DID service type
174- service_endpoint: Service endpoint
175- """
176- await self ._add_or_update_service (
177- DidDocumentOperation .UPDATE , id_ = id_ , type_ = service_type , service_endpoint = service_endpoint
178- )
168+ await self ._submit_transaction (DidDocumentOperation .UPDATE , hcs_event )
179169
180170 async def revoke_service (self , id_ : str ):
181171 """Revoke existing DID document service
@@ -188,52 +178,30 @@ async def revoke_service(self, id_: str):
188178 hcs_event = HcsDidRevokeServiceEvent (id_ )
189179 await self ._submit_transaction (DidDocumentOperation .REVOKE , hcs_event )
190180
191- async def add_verification_method (
181+ async def add_or_update_verification_method (
192182 self ,
193183 id_ : str ,
194184 controller : str ,
195185 public_key_der : str ,
196186 type_ : SupportedKeyType ,
197187 ):
198- """Add verification method to DID document
188+ """Add or update DID document verification method
199189
200190 Args:
201191 id_: Verification method ID to create
202192 controller: Verification method controller ID
203193 public_key_der: Verification method public key encoded in DER format
204194 type_: Verification method key type
205195 """
206- await self ._add_or_update_verification_method (
207- DidDocumentOperation .CREATE ,
208- id_ = id_ ,
209- controller = controller ,
210- public_key = PublicKey .from_string (public_key_der ),
211- type_ = type_ ,
212- )
213196
214- async def update_verification_method (
215- self ,
216- id_ : str ,
217- controller : str ,
218- public_key_der : str ,
219- type_ : SupportedKeyType ,
220- ):
221- """Update existing DID document verification method
197+ self ._assert_can_submit_transaction ()
222198
223- Args:
224- id_: Verification method ID to update
225- controller: Verification method controller ID
226- public_key_der: Verification method public key encoded in DER format
227- type_: Verification method key type
228- """
229- await self ._add_or_update_verification_method (
230- DidDocumentOperation .UPDATE ,
231- id_ = id_ ,
232- controller = controller ,
233- public_key = PublicKey .from_string (public_key_der ),
234- type_ = type_ ,
199+ hcs_event = HcsDidUpdateVerificationMethodEvent (
200+ id_ = id_ , controller = controller , public_key = PublicKey .from_string (public_key_der ), type_ = type_
235201 )
236202
203+ await self ._submit_transaction (DidDocumentOperation .UPDATE , hcs_event )
204+
237205 async def revoke_verification_method (self , id_ : str ):
238206 """Revoke existing DID document verification method
239207
@@ -245,15 +213,15 @@ async def revoke_verification_method(self, id_: str):
245213 hcs_event = HcsDidRevokeVerificationMethodEvent (id_ )
246214 await self ._submit_transaction (DidDocumentOperation .REVOKE , hcs_event )
247215
248- async def add_verification_relationship (
216+ async def add_or_update_verification_relationship (
249217 self ,
250218 id_ : str ,
251219 controller : str ,
252220 public_key_der : str ,
253221 relationship_type : VerificationRelationshipType ,
254222 type_ : SupportedKeyType ,
255223 ):
256- """Add verification relationship to DID document
224+ """Add or update DID document verification relationship
257225
258226 Args:
259227 id_: Verification relationship ID to create
@@ -262,41 +230,19 @@ async def add_verification_relationship(
262230 relationship_type: Verification relationship type
263231 type_: Verification relationship key type
264232 """
265- await self ._add_or_update_verification_relationship (
266- DidDocumentOperation .CREATE ,
267- id_ = id_ ,
268- controller = controller ,
269- public_key = PublicKey .from_string (public_key_der ),
270- relationship_type = relationship_type ,
271- type_ = type_ ,
272- )
273233
274- async def update_verification_relationship (
275- self ,
276- id_ : str ,
277- controller : str ,
278- public_key_der : str ,
279- relationship_type : VerificationRelationshipType ,
280- type_ : SupportedKeyType ,
281- ):
282- """Update existing DID document verification relationship
234+ self ._assert_can_submit_transaction ()
283235
284- Args:
285- id_: Verification relationship ID to update
286- controller: Verification relationship controller ID
287- public_key_der: Verification relationship public key encoded in DER format
288- relationship_type: Verification relationship type
289- type_: Verification relationship key type
290- """
291- await self ._add_or_update_verification_relationship (
292- DidDocumentOperation .UPDATE ,
236+ hcs_event = HcsDidUpdateVerificationRelationshipEvent (
293237 id_ = id_ ,
294- public_key = PublicKey .from_string (public_key_der ),
295238 controller = controller ,
239+ public_key = PublicKey .from_string (public_key_der ),
296240 relationship_type = relationship_type ,
297241 type_ = type_ ,
298242 )
299243
244+ await self ._submit_transaction (DidDocumentOperation .UPDATE , hcs_event )
245+
300246 async def revoke_verification_relationship (self , id_ : str , relationship_type : VerificationRelationshipType ):
301247 """Revoke existing DID document verification relationship
302248
@@ -323,27 +269,6 @@ def build_did_transaction(message_submit_transaction: TopicMessageSubmitTransact
323269
324270 await HcsMessageTransaction (self .topic_id , envelope , build_did_transaction ).execute (self ._client )
325271
326- async def _add_or_update_service (
327- self , operation : Literal [DidDocumentOperation .CREATE , DidDocumentOperation .UPDATE ], ** kwargs
328- ):
329- self ._assert_can_submit_transaction ()
330-
331- await self ._submit_transaction (operation , HcsDidUpdateServiceEvent (** kwargs ))
332-
333- async def _add_or_update_verification_method (
334- self , operation : Literal [DidDocumentOperation .CREATE , DidDocumentOperation .UPDATE ], ** kwargs
335- ):
336- self ._assert_can_submit_transaction ()
337-
338- await self ._submit_transaction (operation , HcsDidUpdateVerificationMethodEvent (** kwargs ))
339-
340- async def _add_or_update_verification_relationship (
341- self , operation : Literal [DidDocumentOperation .CREATE , DidDocumentOperation .UPDATE ], ** kwargs
342- ):
343- self ._assert_can_submit_transaction ()
344-
345- await self ._submit_transaction (operation , HcsDidUpdateVerificationRelationshipEvent (** kwargs ))
346-
347272 async def _handle_resolution_result (self , result : list [HcsDidMessageEnvelope ]):
348273 if not self .identifier :
349274 raise Exception ("Cannot handle DID resolution result: DID identifier is not defined" )
0 commit comments