1+ """Quickstart helpers for beginner users of DIDComm."""
12from typing import Optional , Dict , List , Any , Union , Callable , Awaitable , Sequence
23import aiohttp
3- import attr , attrs
4+ import attr
5+ import attrs
46import json
57import logging
68import uuid
2830
2931@attr .s (auto_attribs = True )
3032class Message :
31- """Provide a nicer interface for messages than just Dictionaries"""
33+ """Provide a nicer interface for messages than just Dictionaries. """
3234
3335 type : str
3436 body : JSON_OBJ
@@ -51,15 +53,18 @@ class Message:
5153 # TODO: Add message validation for spec-defined fields
5254
5355 def __attrs_post_init__ (self ):
56+ """Ensure that id is set."""
5457 # super().__init__(*args, **kwargs)
5558 if self .id is None :
5659 self .id = str (uuid .uuid4 ())
5760
5861 def as_dict (self ):
62+ """Return message as a dictionary for serialization."""
5963 return attrs .asdict (self , filter = (lambda _ , x : x is not None ))
6064
6165 @classmethod
62- def from_json (cls , data ):
66+ def from_json (cls , data : str ):
67+ """Create a Message object from a JSON string."""
6368 data = json .loads (data )
6469 if "from" in data :
6570 data ["frm" ] = data ["from" ]
@@ -298,8 +303,10 @@ async def setup_relay(
298303 await secrets .add_secret (AskarSecretKey (keys [1 ], f"{ new_did } #key-2" ))
299304
300305 # Legacy formats
301- await secrets .add_secret (AskarSecretKey (verkey , doc .authentication [0 ]))
302- await secrets .add_secret (AskarSecretKey (xkey , doc .key_agreement [0 ]))
306+ # verkey
307+ await secrets .add_secret (AskarSecretKey (keys [0 ], doc .authentication [0 ]))
308+ # xkey
309+ await secrets .add_secret (AskarSecretKey (keys [1 ], doc .key_agreement [0 ]))
303310
304311 # Send a message to the relay informing it of our new endpoint that people
305312 # should contact us by
@@ -359,7 +366,7 @@ async def fetch_relayed_messages(
359366
360367 # Handle each stored message is order we receive it
361368 for attach in message .attachments :
362- logger .info ("Received message %s" , attach ["id" ][:- 58 ])
369+ LOG .info ("Received message %s" , attach ["id" ][:- 58 ])
363370
364371 # Decrypt/Unpack the encrypted message attachment
365372 unpacked = await dmp .packaging .unpack (json .dumps (attach ["data" ]["json" ]))
@@ -372,7 +379,7 @@ async def fetch_relayed_messages(
372379
373380 if msg .type == "https://didcomm.org/basicmessage/2.0/message" :
374381 logmsg = msg .body ["content" ].replace ("\n " , " " ).replace ("\r " , "" )
375- logger .info (f"Got message: { logmsg } " )
382+ LOG .info (f"Got message: { logmsg } " )
376383
377384 message = Message (
378385 type = "https://didcomm.org/messagepickup/3.0/messages-received" ,
0 commit comments