3535LOG = logging .getLogger (__name__ )
3636
3737
38- class CompatibilityPrefixResolver (PrefixResolver ):
39- """Provide backwards compatibility with older DID methods.
40-
41- This will be removed in the future, as the intent is for agents to follow
42- the did:peer:2 spec. The CompatibilityPrefixResolver allows for interaction
43- with agents that are using the old #key-byte-prefix. Once this changes,
44- this class will be removed.
45-
46- If you don't need this, it is recommended that you just use the
47- PrefixResolver directly.
48- """
49-
50- async def resolve_and_parse (self , did : str ) -> DIDDocument :
51- """Resolve a DID and parse the DID document."""
52- doc = await self .resolve (did )
53- # return DIDDocument.deserialize(doc)
54- id_map = {}
55-
56- def set_id (method ):
57- new_id = method ["publicKeyMultibase" ][1 :9 ]
58- id_map [method ["id" ]] = new_id
59- method ["id" ] = did + "#" + new_id
60- return method
61-
62- doc ["verificationMethod" ] = [
63- set_id (method ) for method in doc ["verificationMethod" ]
64- ]
65- doc ["authentication" ] = [
66- did + "#" + id_map .get (id ) for id in doc ["authentication" ]
67- ]
68- doc ["keyAgreement" ] = [did + "#" + id_map .get (id ) for id in doc ["keyAgreement" ]]
69- return DIDDocument .deserialize (doc )
70-
71-
7238def generate_did () -> Tuple [DID , Tuple [Key , Key ]]:
7339 """Use Askar to generate encryption/verification keys, then return a DID from both."""
7440
@@ -103,7 +69,7 @@ def generate_did() -> Tuple[DID, Tuple[Key, Key]]:
10369
10470
10571async def setup_default (
106- did : DID , did_secrets : Tuple [Key , Key ], enable_compatibility_prefix : bool = False
72+ did : DID , did_secrets : Tuple [Key , Key ]
10773) -> DIDCommMessaging :
10874 """Setup a pre-configured DIDCommMessaging instance."""
10975
@@ -125,12 +91,7 @@ async def setup_default(
12591 #
12692 # At present, the PrefixResolver is used to determine which library should
12793 # be used to convert a DID into a DIDDocument.
128- if enable_compatibility_prefix :
129- resolver = CompatibilityPrefixResolver (
130- {"did:peer:2" : Peer2 (), "did:peer:4" : Peer4 ()}
131- )
132- else :
133- resolver = PrefixResolver ({"did:peer:2" : Peer2 (), "did:peer:4" : Peer4 ()})
94+ resolver = PrefixResolver ({"did:peer:2" : Peer2 (), "did:peer:4" : Peer4 ()})
13495
13596 # The Packaging Service is where a lot of the magic happens. Similar to a
13697 # shipping box, the PackagingService will "pack" and "unpack" an encrypted
@@ -156,13 +117,6 @@ async def setup_default(
156117 await secrets .add_secret (AskarSecretKey (verkey , f"{ did } #key-1" ))
157118 await secrets .add_secret (AskarSecretKey (xkey , f"{ did } #key-2" ))
158119
159- # These can be removed once all keys being sent/received are in #key-N
160- # format. They basically do the same as above, except with the same public
161- # keys that are returned from the CompatibilityPrefixResolver.
162- doc = await resolver .resolve_and_parse (did )
163- await secrets .add_secret (AskarSecretKey (verkey , doc .authentication [0 ]))
164- await secrets .add_secret (AskarSecretKey (xkey , doc .key_agreement [0 ]))
165-
166120 # Finally, we put it all together in the DIDCommMessaging class. The
167121 # DIDCommMessaging handles the orchestration of each individual service,
168122 # ensuring that messages get packed and delivered via a simple and straight
0 commit comments