Skip to content

Commit c22b10c

Browse files
authored
Merge pull request #98 from sicpa-dlab/main
Publish v0.3.2
2 parents 052492b + f1df987 commit c22b10c

File tree

72 files changed

+2036
-1961
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2036
-1961
lines changed

tox.ini .flake8

-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
[tox]
2-
isolated_build = true
3-
envlist =
4-
py{310,39,38,37}
5-
skip_missing_interpreters = true
6-
7-
[testenv]
8-
whitelist_externals = poetry
9-
commands =
10-
poetry install -v
11-
poetry run pytest
12-
131
[flake8]
142
# set the same as 'black' uses
153
max-line-length = 88

.github/workflows/verify.yml

+5-12
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,23 @@ jobs:
8888
unit:
8989
strategy:
9090
matrix:
91-
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
91+
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
9292
os: [ ubuntu-latest, windows-latest, macos-latest ]
93-
include:
94-
- {python-version: '3.10', toxenv: py310}
95-
- {python-version: '3.9', toxenv: py39}
96-
- {python-version: '3.8', toxenv: py38}
97-
- {python-version: '3.7', toxenv: py37}
9893
runs-on: ${{ matrix.os }}
9994
steps:
10095
- uses: actions/checkout@v3
10196

102-
- name: Install poetry
103-
run: pipx install poetry
104-
10597
- name: Set up Python ${{ matrix.python-version }}
10698
id: setup
10799
uses: actions/setup-python@v4
108100
with:
109101
python-version: ${{ matrix.python-version }}
110-
cache: 'poetry'
102+
103+
- name: Install poetry
104+
run: pipx install poetry --python ${{ steps.setup.outputs.python-path }}
111105

112106
- name: Install dependencies
113-
if: steps.setup.outputs.cache-hit != 'true'
114107
run: poetry install
115108

116109
- name: Test with pytest
117-
run: poetry run tox -e ${{ matrix.toxenv }}
110+
run: poetry run pytest

README.md

+69-25
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,66 @@ See `pack_encrypted` documentation for more details.
7474

7575
```
7676
# ALICE
77-
message = Message(body={"aaa": 1, "bbb": 2},
78-
id="1234567890", type="my-protocol/1.0",
79-
frm=ALICE_DID, to=[BOB_DID])
80-
pack_result = await pack_encrypted(message=message, frm=ALICE_DID, to=BOB_DID)
77+
message = Message(
78+
body={"aaa": 1, "bbb": 2},
79+
id="1234567890",
80+
type="my-protocol/1.0",
81+
frm=ALICE_DID,
82+
to=[BOB_DID],
83+
)
84+
pack_result = await pack_encrypted(
85+
resolvers_config=resolvers_config_alice,
86+
message=message,
87+
frm=ALICE_DID,
88+
to=BOB_DID,
89+
pack_config=PackEncryptedConfig(),
90+
)
8191
packed_msg = pack_result.packed_msg
8292
print(f"Sending ${packed_msg} to ${pack_result.service_metadata.service_endpoint}")
8393
8494
# BOB
85-
unpack_result = await unpack(packed_msg)
95+
unpack_result = await unpack(resolvers_config_bob, packed_msg)
8696
print(f"Got ${unpack_result.message} message")
8797
```
8898

8999
**Anonymous encryption** example:
90100

91101
```
92-
message = Message(body={"aaa": 1, "bbb": 2},
93-
id="1234567890", type="my-protocol/1.0",
94-
frm=ALICE_DID, to=[BOB_DID])
95-
pack_result = await pack_encrypted(message=message, to=BOB_DID)
102+
message = Message(
103+
body={"aaa": 1, "bbb": 2},
104+
id="1234567890",
105+
type="my-protocol/1.0",
106+
frm=ALICE_DID,
107+
to=[BOB_DID],
108+
)
109+
110+
pack_result = await pack_encrypted(
111+
resolvers_config=resolvers_config_alice,
112+
message=message,
113+
to=BOB_DID,
114+
pack_config=PackEncryptedConfig(),
115+
)
96116
```
97117

98118
**Encryption with non-repudiation** example:
99119

100120
```
101-
message = Message(body={"aaa": 1, "bbb": 2},
102-
id="1234567890", type="my-protocol/1.0",
103-
frm=ALICE_DID, to=[BOB_DID])
104-
pack_result = await pack_encrypted(message=message, frm=ALICE_DID, to=BOB_DID, sign_frm=ALICE_DID)
121+
message = Message(
122+
body={"aaa": 1, "bbb": 2},
123+
id="1234567890",
124+
type="my-protocol/1.0",
125+
frm=ALICE_DID,
126+
to=[BOB_DID],
127+
)
128+
129+
pack_result = await pack_encrypted(
130+
resolvers_config=resolvers_config_alice,
131+
message=message,
132+
frm=ALICE_DID,
133+
sign_frm=ALICE_DID,
134+
to=BOB_DID,
135+
pack_config=PackEncryptedConfig(),
136+
)
105137
```
106138

107139
### 2. Build an unencrypted but Signed DIDComm message
@@ -118,15 +150,23 @@ See `pack_signed` documentation for more details.
118150

119151
```
120152
# ALICE
121-
message = Message(body={"aaa": 1, "bbb": 2},
122-
id="1234567890", type="my-protocol/1.0",
123-
frm=ALICE_DID, to=[BOB_DID])
124-
packed_msg = await pack_signed(message=message, sign_frm=ALICE_DID)
153+
message = Message(
154+
body={"aaa": 1, "bbb": 2},
155+
id="1234567890",
156+
type="my-protocol/1.0",
157+
frm=ALICE_DID,
158+
to=[BOB_DID],
159+
)
160+
pack_result = await pack_signed(
161+
resolvers_config=resolvers_config_alice,
162+
message=message,
163+
sign_frm=ALICE_DID
164+
)
125165
packed_msg = pack_result.packed_msg
126166
print(f"Publishing ${packed_msg}")
127167
128168
# BOB
129-
unpack_result = await unpack(packed_msg)
169+
unpack_result = await unpack(resolvers_config_bob, packed_msg)
130170
print(f"Got ${unpack_result.message} message signed as ${unpack_result.metadata.signed_message}")
131171
```
132172

@@ -141,15 +181,19 @@ They are therefore not normally transported across security boundaries.
141181

142182
```
143183
# ALICE
144-
message = Message(body={"aaa": 1, "bbb": 2},
145-
id="1234567890", type="my-protocol/1.0",
146-
frm=ALICE_DID, to=[BOB_DID])
147-
packed_msg = await pack_plaintext(message)
148-
print(f"Publishing ${packed_msg}")
184+
message = Message(
185+
body={"aaa": 1, "bbb": 2},
186+
id="1234567890",
187+
type="my-protocol/1.0",
188+
frm=ALICE_DID,
189+
to=[BOB_DID],
190+
)
191+
pack_result = await pack_plaintext(resolvers_config=resolvers_config_alice, message)
192+
print(f"Publishing ${pack_result.packed_msg}")
149193
150194
# BOB
151-
unpack_result = await unpack(packed_msg)
152-
print(f"Got ${unpack_result.plaintext} message")
195+
unpack_result = await unpack(resolvers_config_bob, pack_result.packed_msg)
196+
print(f"Got ${unpack_result.message} message")
153197
```
154198

155199
## Contribution

didcomm/__init__.py

+113-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"
2+
3+
from didcomm.common.algorithms import AnonCryptAlg, AuthCryptAlg, SignAlg
4+
from didcomm.common.resolvers import ResolversConfig
5+
from didcomm.common.types import (
6+
DIDCommMessageMediaTypes,
7+
DIDCommMessageProtocolTypes,
8+
DIDCommMessageTypes,
9+
DIDDocServiceTypes,
10+
VerificationMethodType,
11+
VerificationMaterial,
12+
VerificationMaterialFormat,
13+
)
14+
from didcomm.did_doc.did_doc import DIDDoc, DIDCommService, VerificationMethod
15+
from didcomm.did_doc.did_resolver import DIDResolver
16+
from didcomm.did_doc.did_resolver_in_memory import DIDResolverInMemory
17+
from didcomm.message import (
18+
Attachment,
19+
AttachmentDataBase64,
20+
AttachmentDataJson,
21+
AttachmentDataLinks,
22+
FromPrior,
23+
GenericMessage,
24+
Message,
25+
)
26+
from didcomm.pack_encrypted import (
27+
pack_encrypted,
28+
PackEncryptedConfig,
29+
PackEncryptedParameters,
30+
PackEncryptedResult,
31+
)
32+
from didcomm.pack_plaintext import (
33+
pack_plaintext,
34+
PackPlaintextParameters,
35+
PackPlaintextResult,
36+
)
37+
from didcomm.pack_signed import pack_signed, PackSignedParameters, PackSignedResult
38+
from didcomm.protocols.routing.forward import (
39+
is_forward,
40+
unpack_forward,
41+
wrap_in_forward,
42+
ForwardBody,
43+
ForwardMessage,
44+
ForwardPackResult,
45+
ForwardResult,
46+
)
47+
from didcomm.unpack import unpack, Metadata, UnpackConfig, UnpackResult
48+
from didcomm.secrets.secrets_resolver import Secret, SecretsResolver
49+
from didcomm.secrets.secrets_resolver_in_memory import SecretsResolverInMemory
50+
51+
__all__ = [
52+
# didcomm.common.algorithms
53+
"AnonCryptAlg",
54+
"AuthCryptAlg",
55+
"SignAlg",
56+
# didcomm.common.resolvers
57+
"ResolversConfig",
58+
# didcomm.common.types
59+
"DIDCommMessageMediaTypes",
60+
"DIDCommMessageProtocolTypes",
61+
"DIDCommMessageTypes",
62+
"DIDDocServiceTypes",
63+
"VerificationMethodType",
64+
"VerificationMaterial",
65+
"VerificationMaterialFormat",
66+
# didcomm.did_doc.did_doc
67+
"DIDDoc",
68+
"DIDCommService",
69+
"VerificationMethod",
70+
# didcomm.did_doc.did_resolver
71+
"DIDResolver",
72+
# did_resolver_in_memory
73+
"DIDResolverInMemory",
74+
# didcomm.message
75+
"Attachment",
76+
"AttachmentDataBase64",
77+
"AttachmentDataJson",
78+
"AttachmentDataLinks",
79+
"FromPrior",
80+
"GenericMessage",
81+
"Message",
82+
# didcomm.pack_encrypted
83+
"pack_encrypted",
84+
"PackEncryptedConfig",
85+
"PackEncryptedParameters",
86+
"PackEncryptedResult",
87+
# didcomm.pack_plaintext
88+
"pack_plaintext",
89+
"PackPlaintextParameters",
90+
"PackPlaintextResult",
91+
# didcomm.pack_signed
92+
"pack_signed",
93+
"PackSignedParameters",
94+
"PackSignedResult",
95+
# didcomm.protocols.routing.forward
96+
"is_forward",
97+
"unpack_forward",
98+
"wrap_in_forward",
99+
"ForwardBody",
100+
"ForwardMessage",
101+
"ForwardPackResult",
102+
"ForwardResult",
103+
# didcomm.unpack
104+
"unpack",
105+
"Metadata",
106+
"UnpackConfig",
107+
"UnpackResult",
108+
# didcomm.secrets.secrets_resolver
109+
"Secret",
110+
"SecretsResolver",
111+
# didcomm.secrets.secrets_resolver_in_memory
112+
"SecretsResolverInMemory",
113+
]

didcomm/common/types.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
from dataclasses import dataclass
44
from enum import Enum
55
from typing import Dict, Any, Union, List
6+
from pydid.did import DID, DIDUrl
67

78
JSON_OBJ = Dict[str, Any]
8-
JSON_VALUE = Union[None, str, int, bool, float, JSON_OBJ, List[Any]]
9+
JSON_VALUE = Union[type(None), str, int, bool, float, Dict, List]
910
JSON = str
1011
JWK = JSON
1112
JWT = JSON
1213
JWS = JSON
13-
DID = str
14-
DID_URL = str
14+
DID_URL = DIDUrl
1515
DID_OR_DID_URL = Union[DID, DID_URL]
1616

1717

18-
class VerificationMethodType(Enum):
19-
JSON_WEB_KEY_2020 = 1
20-
X25519_KEY_AGREEMENT_KEY_2019 = 2
21-
ED25519_VERIFICATION_KEY_2018 = 3
22-
X25519_KEY_AGREEMENT_KEY_2020 = 4
23-
ED25519_VERIFICATION_KEY_2020 = 5
24-
# ECDSA_SECP_256K1_VERIFICATION_KEY_2019 = 6 - not supported now
25-
OTHER = 1000
18+
class VerificationMethodType:
19+
JSON_WEB_KEY_2020 = "JsonWebKey2020"
20+
X25519_KEY_AGREEMENT_KEY_2019 = "X25519KeyAgreementKey2019"
21+
ED25519_VERIFICATION_KEY_2018 = "Ed25519VerificationKey2018"
22+
X25519_KEY_AGREEMENT_KEY_2020 = "X25519KeyAgreementKey2020"
23+
ED25519_VERIFICATION_KEY_2020 = "Ed25519VerificationKey2020"
24+
# ECDSA_SECP_256K1_VERIFICATION_KEY_2019 = "EcdsaSecp256k1VerificationKey2019" - not supported now
25+
OTHER = "Other"
2626

2727

2828
class VerificationMaterialFormat(Enum):
@@ -65,7 +65,6 @@ class DIDCommMessageProtocolTypes(Enum):
6565

6666

6767
class JOSEFields:
68-
6968
# JOSE Header fields as defined in JWS and JWE specs
7069
# (RFCs 7515, 7516, 7518, 7519, 7797, 8225, 8555)
7170
# https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-header-parameters

didcomm/core/defaults.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
DEF_ENC_ALG_AUTH: AuthCryptAlg = AuthCryptAlg.A256CBC_HS512_ECDH_1PU_A256KW
5-
DEF_ENC_ALG_ANON: AuthCryptAlg = AnonCryptAlg.XC20P_ECDH_ES_A256KW
5+
DEF_ENC_ALG_ANON: AnonCryptAlg = AnonCryptAlg.XC20P_ECDH_ES_A256KW

didcomm/core/from_prior.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from didcomm.common.resolvers import ResolversConfig
88
from didcomm.common.types import DID_URL
99
from didcomm.core.keys.sign_keys_selector import find_signing_key, find_verification_key
10-
from didcomm.core.utils import extract_key, extract_sign_alg, is_did_url, get_did
10+
from didcomm.core.utils import (
11+
extract_key,
12+
extract_sign_alg,
13+
is_did_with_uri_fragment,
14+
get_did,
15+
)
1116
from didcomm.errors import (
1217
MalformedMessageError,
1318
MalformedMessageCode,
@@ -121,9 +126,9 @@ def __extract_from_prior_kid(from_prior_jwt: str) -> DID_URL:
121126
from_prior_jwt = to_bytes(from_prior_jwt)
122127
protected_segment = from_prior_jwt.split(b".")[0]
123128
protected = json_loads(urlsafe_b64decode(protected_segment).decode("utf-8"))
124-
if not is_did_url(protected.get("kid")):
129+
if not is_did_with_uri_fragment(protected.get("kid")):
125130
raise DIDCommValueError(
126-
f"from_prior `kid` value is not a valid DID URL: {protected.get('kid')}"
131+
f"from_prior `kid` value is not a valid DID URL containing a fragment: {protected.get('kid')}"
127132
)
128133
return protected["kid"]
129134
except Exception as exc:

didcomm/core/keys/anoncrypt_keys_selector.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def _find_anoncrypt_pack_recipient_public_keys_by_kid(
5959
if did_doc is None:
6060
raise DIDDocNotResolvedError(to_did)
6161

62-
if to_kid not in did_doc.key_agreement_kids:
62+
if not did_doc.key_agreement or to_kid not in did_doc.key_agreement:
6363
raise DIDUrlNotFoundError(
6464
f"DID URL `{to_kid}` is not found in keyAgreement verification relationships of DID `{to_did}`"
6565
)
@@ -78,7 +78,7 @@ async def _find_anoncrypt_pack_recipient_public_keys_by_did(
7878
if did_doc is None:
7979
raise DIDDocNotResolvedError(to_did)
8080

81-
kids = did_doc.key_agreement_kids
81+
kids = did_doc.key_agreement
8282
if not kids:
8383
raise DIDUrlNotFoundError(
8484
f"No keyAgreement verification relationships are found for DID `{to_did}`"

0 commit comments

Comments
 (0)