swarmauri_signing_dsse 0.2.1.dev2__tar.gz → 0.11.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/PKG-INFO +5 -3
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/README.md +4 -2
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/pyproject.toml +1 -1
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/swarmauri_signing_dsse/codec_json.py +6 -4
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/swarmauri_signing_dsse/signer.py +32 -11
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/swarmauri_signing_dsse/types.py +22 -7
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_signing_dsse-0.2.1.dev2 → swarmauri_signing_dsse-0.11.0.dev1}/swarmauri_signing_dsse/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: swarmauri_signing_dsse
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
4
|
Summary: Composable DSSE envelope adapter that layers Pre-Authentication Encoding onto Swarmauri signing providers
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -42,8 +42,8 @@ Description-Content-Type: text/markdown
|
|
|
42
42
|
<img src="https://img.shields.io/pypi/l/swarmauri_signing_dsse" alt="PyPI - License"/></a>
|
|
43
43
|
<a href="https://pypi.org/project/swarmauri_signing_dsse/">
|
|
44
44
|
<img src="https://img.shields.io/pypi/v/swarmauri_signing_dsse?label=swarmauri_signing_dsse&color=green" alt="PyPI - swarmauri_signing_dsse"/></a>
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
46
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
47
47
|
|
|
48
48
|
# Swarmauri Signing DSSE
|
|
49
49
|
|
|
@@ -104,3 +104,5 @@ assert await dsse_signer.verify_envelope(envelope, signatures)
|
|
|
104
104
|
|
|
105
105
|
This project is licensed under the [Apache License 2.0](LICENSE).
|
|
106
106
|
|
|
107
|
+
|
|
108
|
+
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
<img src="https://img.shields.io/pypi/l/swarmauri_signing_dsse" alt="PyPI - License"/></a>
|
|
12
12
|
<a href="https://pypi.org/project/swarmauri_signing_dsse/">
|
|
13
13
|
<img src="https://img.shields.io/pypi/v/swarmauri_signing_dsse?label=swarmauri_signing_dsse&color=green" alt="PyPI - swarmauri_signing_dsse"/></a>
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
16
16
|
|
|
17
17
|
# Swarmauri Signing DSSE
|
|
18
18
|
|
|
@@ -72,3 +72,5 @@ assert await dsse_signer.verify_envelope(envelope, signatures)
|
|
|
72
72
|
## License
|
|
73
73
|
|
|
74
74
|
This project is licensed under the [Apache License 2.0](LICENSE).
|
|
75
|
+
|
|
76
|
+
|
|
@@ -15,9 +15,9 @@ class DSSEJsonCodec:
|
|
|
15
15
|
"""Serialize a DSSE envelope into canonical JSON bytes."""
|
|
16
16
|
|
|
17
17
|
payload = envelope.to_mapping()
|
|
18
|
-
return json.dumps(
|
|
19
|
-
"
|
|
20
|
-
)
|
|
18
|
+
return json.dumps(
|
|
19
|
+
payload, separators=(",", ":"), sort_keys=True
|
|
20
|
+
).encode("utf-8")
|
|
21
21
|
|
|
22
22
|
def decode(
|
|
23
23
|
self, blob: bytes | bytearray | str | Mapping[str, Any] | DSSEEnvelope
|
|
@@ -33,7 +33,9 @@ class DSSEJsonCodec:
|
|
|
33
33
|
elif isinstance(blob, str):
|
|
34
34
|
data = json.loads(blob)
|
|
35
35
|
else:
|
|
36
|
-
raise TypeError(
|
|
36
|
+
raise TypeError(
|
|
37
|
+
"Unsupported DSSE envelope representation for decoding"
|
|
38
|
+
)
|
|
37
39
|
if not isinstance(data, Mapping):
|
|
38
40
|
raise TypeError("Decoded DSSE envelope must produce a mapping")
|
|
39
41
|
return DSSEEnvelope.from_mapping(data)
|
|
@@ -59,22 +59,30 @@ class DSSESigner(SigningBase):
|
|
|
59
59
|
codec: DSSEJsonCodec = Field(default_factory=DSSEJsonCodec)
|
|
60
60
|
|
|
61
61
|
def __init__(
|
|
62
|
-
self,
|
|
62
|
+
self,
|
|
63
|
+
inner: SigningBase,
|
|
64
|
+
*,
|
|
65
|
+
codec: Optional[DSSEJsonCodec] = None,
|
|
66
|
+
**data,
|
|
63
67
|
) -> None:
|
|
64
68
|
"""Initialize the adapter with an inner signer and optional codec."""
|
|
65
69
|
|
|
66
70
|
super().__init__(inner=inner, codec=codec or DSSEJsonCodec(), **data)
|
|
67
71
|
|
|
68
|
-
# --------------------------- Capability surface
|
|
72
|
+
# --------------------------- Capability surface
|
|
73
|
+
# ---------------------------
|
|
69
74
|
def supports(self) -> Mapping[str, Iterable[str]]:
|
|
70
|
-
"""
|
|
75
|
+
"""
|
|
76
|
+
Return the merged capability matrix from the inner signer and DSSE.
|
|
77
|
+
"""
|
|
71
78
|
|
|
72
79
|
inner = self.inner.supports()
|
|
73
80
|
return {
|
|
74
81
|
"algs": inner.get("algs", ()),
|
|
75
82
|
"canons": tuple(set(inner.get("canons", ())) | {"dsse-pae"}),
|
|
76
83
|
"signs": tuple(
|
|
77
|
-
set(inner.get("signs", ()))
|
|
84
|
+
set(inner.get("signs", ()))
|
|
85
|
+
| {"envelope", "bytes", "digest", "stream"}
|
|
78
86
|
),
|
|
79
87
|
"verifies": tuple(
|
|
80
88
|
set(inner.get("verifies", ()))
|
|
@@ -86,7 +94,8 @@ class DSSESigner(SigningBase):
|
|
|
86
94
|
),
|
|
87
95
|
}
|
|
88
96
|
|
|
89
|
-
# --------------------------- Bytes / Digest / Stream
|
|
97
|
+
# --------------------------- Bytes / Digest / Stream
|
|
98
|
+
# ---------------------------
|
|
90
99
|
async def sign_bytes(
|
|
91
100
|
self,
|
|
92
101
|
key: KeyRef,
|
|
@@ -176,7 +185,9 @@ class DSSESigner(SigningBase):
|
|
|
176
185
|
"""Canonicalize an envelope using DSSE PAE when requested."""
|
|
177
186
|
|
|
178
187
|
if canon not in (None, "dsse-pae"):
|
|
179
|
-
return await self.inner.canonicalize_envelope(
|
|
188
|
+
return await self.inner.canonicalize_envelope(
|
|
189
|
+
env, canon=canon, opts=opts
|
|
190
|
+
)
|
|
180
191
|
|
|
181
192
|
envelope = self.decode_envelope(env)
|
|
182
193
|
payload = _b64d(envelope.payload_b64)
|
|
@@ -191,7 +202,8 @@ class DSSESigner(SigningBase):
|
|
|
191
202
|
canon: Optional[Canon] = None,
|
|
192
203
|
opts: Optional[Mapping[str, object]] = None,
|
|
193
204
|
) -> Sequence[Signature]:
|
|
194
|
-
"""Sign a DSSE envelope by delegating to the wrapped signer over the
|
|
205
|
+
"""Sign a DSSE envelope by delegating to the wrapped signer over the
|
|
206
|
+
PAE."""
|
|
195
207
|
|
|
196
208
|
pae = await self.canonicalize_envelope(
|
|
197
209
|
env, canon=canon or "dsse-pae", opts=opts
|
|
@@ -207,7 +219,8 @@ class DSSESigner(SigningBase):
|
|
|
207
219
|
require: Optional[Mapping[str, object]] = None,
|
|
208
220
|
opts: Optional[Mapping[str, object]] = None,
|
|
209
221
|
) -> bool:
|
|
210
|
-
"""Verify a DSSE envelope by delegating to the wrapped signer over the
|
|
222
|
+
"""Verify a DSSE envelope by delegating to the wrapped signer over the
|
|
223
|
+
PAE."""
|
|
211
224
|
|
|
212
225
|
pae = await self.canonicalize_envelope(
|
|
213
226
|
env, canon=canon or "dsse-pae", opts=opts
|
|
@@ -216,15 +229,23 @@ class DSSESigner(SigningBase):
|
|
|
216
229
|
pae, signatures, require=require, opts=opts
|
|
217
230
|
)
|
|
218
231
|
|
|
219
|
-
# --------------------------- Helpers for (de)serialization
|
|
220
|
-
|
|
232
|
+
# --------------------------- Helpers for (de)serialization
|
|
233
|
+
# ---------------------------
|
|
234
|
+
def encode_envelope(
|
|
235
|
+
self, envelope: DSSEEnvelope | Mapping[str, object]
|
|
236
|
+
) -> bytes:
|
|
221
237
|
"""Encode an envelope (object or mapping) into JSON bytes."""
|
|
222
238
|
|
|
223
239
|
return self.codec.encode(self.decode_envelope(envelope))
|
|
224
240
|
|
|
225
241
|
def decode_envelope(
|
|
226
242
|
self,
|
|
227
|
-
blob: Envelope
|
|
243
|
+
blob: Envelope
|
|
244
|
+
| bytes
|
|
245
|
+
| bytearray
|
|
246
|
+
| str
|
|
247
|
+
| Mapping[str, object]
|
|
248
|
+
| DSSEEnvelope,
|
|
228
249
|
) -> DSSEEnvelope:
|
|
229
250
|
"""Decode envelope inputs into a :class:`DSSEEnvelope` instance."""
|
|
230
251
|
|
|
@@ -19,10 +19,14 @@ class DSSESignatureRecord:
|
|
|
19
19
|
"""Construct a signature record from a mapping."""
|
|
20
20
|
|
|
21
21
|
if "sig" not in data:
|
|
22
|
-
raise ValueError(
|
|
22
|
+
raise ValueError(
|
|
23
|
+
"DSSE signature mapping is missing the 'sig' field"
|
|
24
|
+
)
|
|
23
25
|
sig_value = data["sig"]
|
|
24
26
|
if not isinstance(sig_value, str):
|
|
25
|
-
raise TypeError(
|
|
27
|
+
raise TypeError(
|
|
28
|
+
"DSSE signature field 'sig' must be a base64 string"
|
|
29
|
+
)
|
|
26
30
|
|
|
27
31
|
keyid_value = data.get("keyid")
|
|
28
32
|
if keyid_value is not None and not isinstance(keyid_value, str):
|
|
@@ -33,7 +37,10 @@ class DSSESignatureRecord:
|
|
|
33
37
|
cert_value = data.get("cert")
|
|
34
38
|
if cert_value is not None and not isinstance(cert_value, str):
|
|
35
39
|
raise TypeError(
|
|
36
|
-
|
|
40
|
+
(
|
|
41
|
+
"DSSE signature field 'cert' must be a PEM string when "
|
|
42
|
+
"provided"
|
|
43
|
+
)
|
|
37
44
|
)
|
|
38
45
|
|
|
39
46
|
return cls(sig=sig_value, keyid=keyid_value, cert=cert_value)
|
|
@@ -80,10 +87,14 @@ class DSSEEnvelope:
|
|
|
80
87
|
return signature
|
|
81
88
|
if isinstance(signature, Mapping):
|
|
82
89
|
return DSSESignatureRecord.from_mapping(signature)
|
|
83
|
-
raise TypeError(
|
|
90
|
+
raise TypeError(
|
|
91
|
+
"Unsupported signature representation in DSSE envelope"
|
|
92
|
+
)
|
|
84
93
|
|
|
85
94
|
def to_mapping(self) -> MutableMapping[str, object]:
|
|
86
|
-
"""
|
|
95
|
+
"""
|
|
96
|
+
Return the JSON-serializable mapping representation of the envelope.
|
|
97
|
+
"""
|
|
87
98
|
|
|
88
99
|
return {
|
|
89
100
|
"payloadType": self.payload_type,
|
|
@@ -112,7 +123,9 @@ class DSSEEnvelope:
|
|
|
112
123
|
if not isinstance(signatures, Iterable):
|
|
113
124
|
raise TypeError("signatures must be an iterable of mappings")
|
|
114
125
|
|
|
115
|
-
normalized_signatures = [
|
|
126
|
+
normalized_signatures = [
|
|
127
|
+
cls._coerce_signature(sig) for sig in signatures
|
|
128
|
+
]
|
|
116
129
|
return cls(
|
|
117
130
|
payload_type=payload_type,
|
|
118
131
|
payload_b64=payload_b64,
|
|
@@ -123,5 +136,7 @@ class DSSEEnvelope:
|
|
|
123
136
|
"""Return a copy of the envelope without signature records."""
|
|
124
137
|
|
|
125
138
|
return DSSEEnvelope(
|
|
126
|
-
payload_type=self.payload_type,
|
|
139
|
+
payload_type=self.payload_type,
|
|
140
|
+
payload_b64=self.payload_b64,
|
|
141
|
+
signatures=(),
|
|
127
142
|
)
|
|
File without changes
|
|
File without changes
|