Skip to content

Commit 0ed568d

Browse files
committed
refactor: rename to V1
DIDComm v1 isn't quite legacy yet Signed-off-by: Daniel Bluhm <[email protected]>
1 parent ab50096 commit 0ed568d

File tree

10 files changed

+83
-83
lines changed

10 files changed

+83
-83
lines changed

didcomm_messaging/legacy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Legacy DIDComm v1 Interfaces.
1+
"""V1 DIDComm v1 Interfaces.
22
33
These components are intended to provide a similar structure to the DIDComm v2
44
interfaces provided by this library. While the community is transitioning from

didcomm_messaging/legacy/askar.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""LegacyCryptoService implementation for askar."""
1+
"""V1CryptoService implementation for askar."""
22

33
from collections import OrderedDict
44
from typing import Optional, Sequence, Tuple, cast
@@ -8,8 +8,8 @@
88

99
from didcomm_messaging.crypto.jwe import JweBuilder, JweEnvelope, JweRecipient
1010
from didcomm_messaging.legacy.base import (
11-
LegacyCryptoService,
12-
LegacyUnpackResult,
11+
V1CryptoService,
12+
V1UnpackResult,
1313
RecipData,
1414
)
1515

@@ -18,11 +18,11 @@
1818
from aries_askar.bindings import key_get_secret_bytes
1919
from didcomm_messaging.crypto.backend.askar import AskarKey, AskarSecretKey
2020
except ImportError:
21-
raise ImportError("Legacy Askar backend requires the 'askar' extra to be installed")
21+
raise ImportError("V1 Askar backend requires the 'askar' extra to be installed")
2222

2323

24-
class AskarLegacyCryptoService(LegacyCryptoService[AskarKey, AskarSecretKey]):
25-
"""Legacy crypto service implementation for askar."""
24+
class AskarV1CryptoService(V1CryptoService[AskarKey, AskarSecretKey]):
25+
"""V1 crypto service implementation for askar."""
2626

2727
def kid_to_public_key(self, kid: str) -> AskarKey:
2828
"""Get a public key from a kid.
@@ -97,7 +97,7 @@ async def unpack_message(
9797
wrapper: JweEnvelope,
9898
recip_key: AskarSecretKey,
9999
recip_data: RecipData,
100-
) -> LegacyUnpackResult:
100+
) -> V1UnpackResult:
101101
"""Decode a message using the DIDComm v1 'unpack' algorithm."""
102102
payload_key, sender_vk = self._extract_payload_key(recip_key.key, recip_data)
103103

@@ -108,7 +108,7 @@ async def unpack_message(
108108
tag=wrapper.tag,
109109
aad=wrapper.protected_b64,
110110
)
111-
return LegacyUnpackResult(message, recip_key.kid, sender_vk)
111+
return V1UnpackResult(message, recip_key.kid, sender_vk)
112112

113113
def _extract_payload_key(
114114
self, recip_key: Key, recip_data: RecipData

didcomm_messaging/legacy/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class RecipData(NamedTuple):
1818
enc_cek: bytes
1919

2020

21-
class LegacyUnpackResult(NamedTuple):
21+
class V1UnpackResult(NamedTuple):
2222
"""Result of unpacking."""
2323

2424
message: bytes
2525
recip: str
2626
sender: Optional[str]
2727

2828

29-
class LegacyCryptoService(ABC, Generic[P, S]):
29+
class V1CryptoService(ABC, Generic[P, S]):
3030
"""CryptoService interface for DIDComm v1."""
3131

3232
b64url = Base64UrlEncoder()
@@ -52,5 +52,5 @@ async def pack_message(
5252
@abstractmethod
5353
async def unpack_message(
5454
self, wrapper: JweEnvelope, recip_key: S, recip_data: RecipData
55-
) -> LegacyUnpackResult:
55+
) -> V1UnpackResult:
5656
"""Decode a message using DIDCvomm v1 'unpack' algorithm."""

didcomm_messaging/legacy/crypto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""DIDComm v1 packing and unpacking.
22
33
This implementation is kept around for backwards compatibility. It is
4-
likely that you should use the LegacyCryptoService interfaces instead.
4+
likely that you should use the V1CryptoService interfaces instead.
55
"""
66

77
from collections import OrderedDict
@@ -19,7 +19,7 @@
1919
import nacl.utils
2020
except ImportError as err:
2121
raise ImportError(
22-
"Legacy implementation requires 'legacy' extra to be installed"
22+
"V1 implementation requires 'legacy' extra to be installed"
2323
) from err
2424

2525
from didcomm_messaging.multiformats.multibase import Base64UrlEncoder

didcomm_messaging/legacy/messaging.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Legacy messaging service."""
1+
"""V1 messaging service."""
22

33
from dataclasses import dataclass
44
import json
@@ -10,25 +10,25 @@
1010
from pydid.service import DIDCommV1Service
1111

1212
from didcomm_messaging.crypto import P, S, SecretsManager
13-
from didcomm_messaging.legacy.base import LegacyCryptoService
14-
from didcomm_messaging.legacy.packaging import LegacyPackagingService
13+
from didcomm_messaging.legacy.base import V1CryptoService
14+
from didcomm_messaging.legacy.packaging import V1PackagingService
1515
from didcomm_messaging.resolver import DIDResolver
1616

1717

18-
class LegacyDIDCommMessagingError(Exception):
18+
class V1DIDCommMessagingError(Exception):
1919
"""Raised on error in legacy didcomm messaging."""
2020

2121

2222
@dataclass
23-
class LegacyPackResult:
23+
class V1PackResult:
2424
"""Result of packing a message."""
2525

2626
message: bytes
2727
target_service: str
2828

2929

3030
@dataclass
31-
class LegacyUnpackResult:
31+
class V1UnpackResult:
3232
"""Result of unpacking a message."""
3333

3434
unpacked: bytes
@@ -55,11 +55,11 @@ class Target:
5555
endpoint: str
5656

5757

58-
class LegacyDIDCommMessagingService(Generic[P, S]):
58+
class V1DIDCommMessagingService(Generic[P, S]):
5959
"""Main entrypoint for DIDComm Messaging."""
6060

6161
async def did_to_target(
62-
self, crypto: LegacyCryptoService[P, S], resolver: DIDResolver, did: str
62+
self, crypto: V1CryptoService[P, S], resolver: DIDResolver, did: str
6363
) -> Target:
6464
"""Resolve recipient information from a DID."""
6565
doc = await resolver.resolve_and_parse(did)
@@ -69,7 +69,7 @@ async def did_to_target(
6969
if isinstance(service, DIDCommV1Service)
7070
]
7171
if not services:
72-
raise LegacyDIDCommMessagingError(f"Unable to send message to DID {did}")
72+
raise V1DIDCommMessagingError(f"Unable to send message to DID {did}")
7373
target = services[0]
7474

7575
recipient_keys = [
@@ -92,14 +92,14 @@ async def did_to_target(
9292
if isinstance(endpoint, AnyUrl):
9393
endpoint = str(endpoint)
9494
if not endpoint.startswith("http") and not endpoint.startswith("ws"):
95-
raise LegacyDIDCommMessagingError(
95+
raise V1DIDCommMessagingError(
9696
f"Unable to send message to endpoint {endpoint}"
9797
)
9898

9999
return Target(recipient_keys, routing_keys, endpoint)
100100

101101
async def from_did_to_kid(
102-
self, crypto: LegacyCryptoService[P, S], resolver: DIDResolver, did: str
102+
self, crypto: V1CryptoService[P, S], resolver: DIDResolver, did: str
103103
) -> str:
104104
"""Resolve our DID to a kid to be used by crypto layers."""
105105
doc = await resolver.resolve_and_parse(did)
@@ -109,7 +109,7 @@ async def from_did_to_kid(
109109
if isinstance(service, DIDCommV1Service)
110110
]
111111
if not services:
112-
raise LegacyDIDCommMessagingError(f"Unable to send message to DID {did}")
112+
raise V1DIDCommMessagingError(f"Unable to send message to DID {did}")
113113
target = services[0]
114114

115115
recipient_keys = [
@@ -133,10 +133,10 @@ def forward_wrap(self, to: str, msg: str) -> bytes:
133133

134134
async def pack(
135135
self,
136-
crypto: LegacyCryptoService[P, S],
136+
crypto: V1CryptoService[P, S],
137137
resolver: DIDResolver,
138138
secrets: SecretsManager[S],
139-
packaging: LegacyPackagingService[P, S],
139+
packaging: V1PackagingService[P, S],
140140
message: Union[dict, str, bytes],
141141
to: Union[str, Target],
142142
frm: Optional[str] = None,
@@ -197,19 +197,19 @@ async def pack(
197197
)
198198
forward_to = routing_key
199199

200-
return LegacyPackResult(encoded_message.to_json().encode(), target.endpoint)
200+
return V1PackResult(encoded_message.to_json().encode(), target.endpoint)
201201

202202
async def unpack(
203203
self,
204-
crypto: LegacyCryptoService[P, S],
204+
crypto: V1CryptoService[P, S],
205205
secrets: SecretsManager[S],
206-
packaging: LegacyPackagingService[P, S],
206+
packaging: V1PackagingService[P, S],
207207
encoded_message: bytes,
208208
**options,
209-
) -> LegacyUnpackResult:
209+
) -> V1UnpackResult:
210210
"""Unpack a message."""
211211
unpacked, recip, sender = await packaging.unpack(crypto, secrets, encoded_message)
212-
return LegacyUnpackResult(
212+
return V1UnpackResult(
213213
unpacked,
214214
encrytped=bool(recip),
215215
authenticated=bool(sender),
@@ -218,30 +218,30 @@ async def unpack(
218218
)
219219

220220

221-
class LegacyDIDCommMessaging(Generic[P, S]):
221+
class V1DIDCommMessaging(Generic[P, S]):
222222
"""Main entrypoint for DIDComm Messaging."""
223223

224224
def __init__(
225225
self,
226-
crypto: LegacyCryptoService[P, S],
226+
crypto: V1CryptoService[P, S],
227227
secrets: SecretsManager[S],
228228
resolver: DIDResolver,
229-
packaging: LegacyPackagingService[P, S],
229+
packaging: V1PackagingService[P, S],
230230
):
231231
"""Initialize the DIDComm Messaging service."""
232232
self.crypto = crypto
233233
self.secrets = secrets
234234
self.resolver = resolver
235235
self.packaging = packaging
236-
self.dmp = LegacyDIDCommMessagingService()
236+
self.dmp = V1DIDCommMessagingService()
237237

238238
async def pack(
239239
self,
240240
message: Union[dict, str, bytes],
241241
to: Union[str, Target],
242242
frm: Optional[str] = None,
243243
**options,
244-
) -> LegacyPackResult:
244+
) -> V1PackResult:
245245
"""Pack a message.
246246
247247
Args:
@@ -252,7 +252,7 @@ async def pack(
252252
options: arbitrary values to pass to the packaging service
253253
254254
Returns:
255-
LegacyPackResult with packed message and target services
255+
V1PackResult with packed message and target services
256256
"""
257257
return await self.dmp.pack(
258258
self.crypto,
@@ -269,7 +269,7 @@ async def unpack(
269269
self,
270270
encoded_message: bytes,
271271
**options,
272-
) -> LegacyUnpackResult:
272+
) -> V1UnpackResult:
273273
"""Unpack a message."""
274274
return await self.dmp.unpack(
275275
self.crypto,

didcomm_messaging/legacy/nacl.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""LegacyCryptoService implementation for pynacl."""
1+
"""V1CryptoService implementation for pynacl."""
22

33
from dataclasses import dataclass
44
from typing import Dict, Optional, OrderedDict, Sequence, Tuple
@@ -10,15 +10,15 @@
1010
from didcomm_messaging.crypto.jwe import JweBuilder, JweEnvelope, JweRecipient
1111
from didcomm_messaging.multiformats import multibase, multicodec
1212

13-
from .base import LegacyCryptoService, LegacyUnpackResult, RecipData
13+
from .base import V1CryptoService, V1UnpackResult, RecipData
1414

1515
try:
1616
import nacl.bindings
1717
import nacl.exceptions
1818
import nacl.utils
1919
except ImportError as err:
2020
raise ImportError(
21-
"Legacy implementation requires 'legacy' extra to be installed"
21+
"V1 implementation requires 'legacy' extra to be installed"
2222
) from err
2323

2424

@@ -75,8 +75,8 @@ def key_bytes(self) -> bytes:
7575
return self.value
7676

7777

78-
class NaclLegacyCryptoService(LegacyCryptoService[EdPublicKey, KeyPair]):
79-
"""Legacy crypto service using pynacl."""
78+
class NaclV1CryptoService(V1CryptoService[EdPublicKey, KeyPair]):
79+
"""V1 crypto service using pynacl."""
8080

8181
def kid_to_public_key(self, kid: str):
8282
"""Get a public key from a kid.
@@ -180,15 +180,15 @@ def _extract_payload_key(self, recip_key: KeyPair, recip_data: RecipData):
180180

181181
async def unpack_message(
182182
self, wrapper: JweEnvelope, recip_key: KeyPair, recip_data: RecipData
183-
) -> LegacyUnpackResult:
183+
) -> V1UnpackResult:
184184
"""Decode a message using DIDCvomm v1 'unpack' algorithm."""
185185
cek, sender_vk = self._extract_payload_key(recip_key, recip_data)
186186

187187
payload_bin = wrapper.ciphertext + wrapper.tag
188188
message = nacl.bindings.crypto_aead_chacha20poly1305_ietf_decrypt(
189189
payload_bin, wrapper.protected_b64, wrapper.iv, cek
190190
)
191-
return LegacyUnpackResult(message, recip_key.kid, sender_vk)
191+
return V1UnpackResult(message, recip_key.kid, sender_vk)
192192

193193

194194
class InMemSecretsManager(SecretsManager[KeyPair]):

0 commit comments

Comments
 (0)