11"""Quickstart helpers for beginner users of DIDComm."""
2- from typing import Optional , Dict , List , Any , Union , Callable , Awaitable , Sequence
2+ from typing import (
3+ Optional ,
4+ Dict ,
5+ List ,
6+ Any ,
7+ Union ,
8+ Callable ,
9+ Awaitable ,
10+ Sequence ,
11+ Tuple ,
12+ )
313import aiohttp
414import attr
515import attrs
@@ -106,7 +116,7 @@ def set_id(method):
106116 return DIDDocument .deserialize (doc )
107117
108118
109- def generate_did ():
119+ def generate_did () -> Tuple [ DID , Tuple [ Key , Key ]] :
110120 """Use Askar to generate encryption/verification keys, then return a DID from both."""
111121
112122 verkey = Key .generate (KeyAlg .ED25519 )
@@ -139,7 +149,9 @@ def generate_did():
139149 return did , (verkey , xkey )
140150
141151
142- async def setup_default (did , did_secrets , enable_compatibility_prefix = False ):
152+ async def setup_default (
153+ did : DID , did_secrets : Tuple [Key , Key ], enable_compatibility_prefix : bool = False
154+ ) -> DIDCommMessaging :
143155 """Setup a pre-configured DIDCommMessaging instance."""
144156
145157 # The Crypto Service is used to encrypt, decrypt, sign and verify messages.
@@ -215,7 +227,7 @@ async def setup_default(did, did_secrets, enable_compatibility_prefix=False):
215227
216228async def send_http_message (
217229 dmp : DIDCommMessaging , my_did : DID , message : Message , target : DID
218- ):
230+ ) -> Optional [ Message ] :
219231 """Send a message via HTTP."""
220232
221233 # Get the message as a dictionary
@@ -234,31 +246,31 @@ async def send_http_message(
234246 endpoint = packy .get_endpoint ("http" )
235247
236248 async with aiohttp .ClientSession () as session :
237- LOG .info ("posting message type %s to %s" % ( message_wrapper .type , endpoint ) )
249+ LOG .info ("posting message type %s to %s" , message_wrapper .type , endpoint )
238250
239251 async with session .post (endpoint , data = packed ) as resp :
240- LOG .debug ("posted message: %s" % ( message ) )
241- LOG .debug ("message ID: %s" % ( message_wrapper .id ) )
252+ LOG .debug ("posted message: %s" , message )
253+ LOG .debug ("message ID: %s" , message_wrapper .id )
242254 packed = await resp .text ()
243255
244256 # If the HTTP enpoint responded with a message, decode it
245257 if len (packed ) > 0 :
246258 unpacked = await dmp .packaging .unpack (packed )
247259 msg = unpacked [0 ].decode ()
248- LOG .debug ("Raw message from remote %s" % msg )
260+ LOG .debug ("Raw message from remote %s" , msg )
249261 return Message .from_json (msg )
250262 return
251263
252264
253265async def setup_relay (
254266 dmp : DIDCommMessaging , my_did : DID , relay_did : DID , keys : Sequence [Key ]
255267) -> Union [DID , None ]:
256- """Negotiate services with an outbound relay.
268+ """Negotiate services with an inbound relay.
257269
258270 Returns a DID upon successful negotiation.
259271 """
260272
261- # Request mediation from the outbound relay
273+ # Request mediation from the inbound relay
262274 message = Message (
263275 type = "https://didcomm.org/coordinate-mediation/3.0/mediate-request" ,
264276 id = str (uuid .uuid4 ()),
@@ -289,7 +301,7 @@ async def setup_relay(
289301 }
290302 ],
291303 )
292- LOG .info ("relayed did: " , new_did )
304+ LOG .info ("relayed did: %s " , new_did )
293305
294306 # A couple of helpers variables to simplify the next few lines
295307 resolver = dmp .resolver
@@ -369,7 +381,7 @@ async def fetch_relayed_messages(
369381 LOG .info ("Received message %s" , attach ["id" ][:- 58 ])
370382
371383 # Decrypt/Unpack the encrypted message attachment
372- unpacked = await dmp .packaging . unpack (json .dumps (attach ["data" ]["json" ]))
384+ unpacked = await dmp .unpack (json .dumps (attach ["data" ]["json" ]))
373385 msg = unpacked .message
374386 msg = Message .from_json (msg )
375387
@@ -379,7 +391,7 @@ async def fetch_relayed_messages(
379391
380392 if msg .type == "https://didcomm.org/basicmessage/2.0/message" :
381393 logmsg = msg .body ["content" ].replace ("\n " , " " ).replace ("\r " , "" )
382- LOG .info (f"Got message: { logmsg } " )
394+ LOG .info (f"Got message: %s" , logmsg )
383395
384396 message = Message (
385397 type = "https://didcomm.org/messagepickup/3.0/messages-received" ,
0 commit comments