|
25 | 25 | from didcomm_messaging.multiformats import multibase, multicodec |
26 | 26 | from didcomm_messaging.packaging import PackagingService |
27 | 27 | from didcomm_messaging.resolver import PrefixResolver |
| 28 | +from didcomm_messaging.resolver.web import DIDWeb |
28 | 29 | from didcomm_messaging.resolver.peer import Peer2, Peer4 |
29 | 30 | from didcomm_messaging.routing import RoutingService |
30 | 31 |
|
@@ -89,22 +90,26 @@ async def setup_default(did: DID, did_secrets: Tuple[Key, Key]) -> DIDCommMessag |
89 | 90 | # |
90 | 91 | # At present, the PrefixResolver is used to determine which library should |
91 | 92 | # be used to convert a DID into a DIDDocument. |
92 | | - resolver = PrefixResolver({"did:peer:2": Peer2(), "did:peer:4": Peer4()}) |
| 93 | + resolver = PrefixResolver({ |
| 94 | + "did:peer:2": Peer2(), |
| 95 | + "did:peer:4": Peer4(), |
| 96 | + "did:web:": DIDWeb(), |
| 97 | + }) |
93 | 98 |
|
94 | 99 | # The Packaging Service is where a lot of the magic happens. Similar to a |
95 | 100 | # shipping box, the PackagingService will "pack" and "unpack" an encrypted |
96 | 101 | # message. When packing a message, the PackagingService will encrypt the |
97 | 102 | # message to a single target, however. If the message needs to be forwarded |
98 | 103 | # (because the recipient is behind a relay), then those messages will need |
99 | 104 | # to be handled by the RoutingService. |
100 | | - packer = PackagingService(resolver, crypto, secrets) |
| 105 | + packer = PackagingService() |
101 | 106 |
|
102 | 107 | # The RoutingService handles the routing of messages through relays. When a |
103 | 108 | # message needs to be forwarded, the RoutingService will handle wrapping |
104 | 109 | # each encrypted message within a forward message. The built-in |
105 | 110 | # RoutingService allows for multiple levels of relays, so you don't need to |
106 | 111 | # worry about how a message is routed to the recipient. |
107 | | - router = RoutingService(packaging=packer, resolver=resolver) |
| 112 | + router = RoutingService() |
108 | 113 |
|
109 | 114 | # Once everything is setup, we need to store the DID Secrets within the |
110 | 115 | # SecretsService. We do this by taking the secrets that were passed in, |
@@ -180,10 +185,10 @@ async def send_http_message( |
180 | 185 |
|
181 | 186 | # If the HTTP enpoint responded with a message, decode it |
182 | 187 | if len(packed) > 0: |
183 | | - unpacked = await dmp.packaging.unpack(packed) |
184 | | - msg = unpacked[0].decode() |
| 188 | + unpacked = await dmp.unpack(packed) |
| 189 | + msg = unpacked.message |
185 | 190 | LOG.debug("Raw message from remote %s", msg) |
186 | | - return json.loads(msg) |
| 191 | + return msg |
187 | 192 | return |
188 | 193 |
|
189 | 194 |
|
@@ -396,9 +401,8 @@ async def handle_websocket( |
396 | 401 | try: |
397 | 402 | # Unpack/Decrypt the message, decode it, and load the JSON into |
398 | 403 | # a native python object. |
399 | | - unpacked_message, metadata = await dmp.packaging.unpack(message) |
400 | | - msg = unpacked_message.decode() |
401 | | - msg = json.loads(msg) |
| 404 | + unpacked_message = await dmp.unpack(message) |
| 405 | + msg = unpacked_message.message |
402 | 406 | LOG.debug("Received websocket message %s", msg["type"]) |
403 | 407 |
|
404 | 408 | # If the message is not from the relay, process it via the callback |
|
0 commit comments