Commit 7649576
authored
feat: v0.2.0 EvidenceReceipt v2 + well-known directory (#8)
* feat: v0.2.0 — EvidenceReceipt v2 + well-known directory
Adds EvidenceReceipt v2 verification alongside the existing ActionReceipt
v1 path. v1 callers see no behavior change. New v2 surface is required by
Pipelock v2.4 release-spec criteria 2 and 5: every contract-aware proxy
decision and contract-lifecycle event ships in the new envelope, and
external auditors must be able to verify them.
New surface:
- Version routing in `verify()`: dispatches on the top-level `record_type`
discriminator. `"action_receipt_v1"` (or absent) routes to v1.
`"evidence_receipt_v2"` routes to v2. Unknown types are rejected with
a clear error.
- `verify_evidence()` for direct v2 verification with full payload detail.
- 13 EvidenceReceipt v2 payload kinds: `proxy_decision`,
`contract_ratified`, `contract_promote_intent`,
`contract_promote_committed`, `contract_rollback_authorized`,
`contract_rollback_committed`, `contract_demoted`, `contract_expired`,
`contract_drift`, `shadow_delta`, `opportunity_missing`,
`key_rotation`, `contract_redaction_request`. Each has its own schema
validator with strict unknown-field rejection.
- Key-purpose authority matrix: receipts must carry the correct
`key_purpose` for their payload kind. Mismatches reject.
- RFC 8785 JCS canonicalization (`_jcs.py`) for signable preimage
computation. Mirrors the Go reference: parse strict, reject duplicate
keys, reject floats, NFC-normalize strings, sort keys.
- Well-known directory fetch (`_directory.py`): `fetch_directory()` and
`parse_directory()` per RFC 9421. The README example switches from
hardcoded SHA hex to directory-based key discovery.
Backward compatibility: confirmed across all 62 original tests. Public
v1 API surface unchanged. v1 conformance golden files verify
byte-identically.
Tests: 172 pass (62 v1 unchanged + 110 new). Build: clean wheel + sdist.
Lint: ruff check + ruff format both pass.
Follow-ups (tracked):
- Cross-implementation Go-generated v2 conformance golden vectors not
yet in `tests/conformance/`. v2 signature round-trip is currently
proven via Python-generated keys only. To prove byte-for-byte parity
with the Go reference, generate v2 fixtures from
`internal/contract/receipt` and copy them in.
- `verify_chain()` still validates v1 chain linkage only. Mixed v1/v2
chains require a chain-verifier upgrade in a follow-up.
* tests: cross-implementation conformance for EvidenceReceipt v2
Adds three Go-emitted v2 receipt fixtures and a conformance test suite
that loads each via the Python verifier. Proves byte-for-byte JCS
preimage parity between the Go reference (internal/contract/receipt)
and the Python implementation for the proxy_decision, contract_promote_
committed, and shadow_delta payload kinds — the load-bearing audit
kinds for the v2.4 release spec's external verification claim.
Fixtures (under tests/conformance/):
valid-evidence-proxy-decision.json
valid-evidence-promote-committed.json
valid-evidence-shadow-delta.json
Each is signed with the RFC 8032 section 7.1 test-1 private seed, so
the corresponding public key (also in v2-test-keys.json) is the same
across both implementations. A divergence in either side's
canonicalisation logic surfaces here as a signature mismatch.
tests/test_v2_conformance.py covers:
- parametrised happy-path verification for each fixture
- tampered-payload rejection (single-byte verdict flip on
proxy_decision must invalidate the signature)
- wrong-key rejection (all-zero public key must fail)
172 v2 tests in test_evidence.py + 18 in test_directory.py + 5 here +
the v0.1.x suite = 178 total. All pass.
Follow-up: the remaining 10 v2 payload kinds (contract_ratified,
contract_promote_intent, contract_rollback_authorized/committed,
contract_demoted, contract_expired, contract_drift, opportunity_missing,
key_rotation, contract_redaction_request) are still synthesised
internally by test_evidence.py and not yet covered by Go-emitted
goldens. Adding them follows the same pattern: emit from
internal/contract/receipt/golden_vectors_test.go with UPDATE_GOLDEN=1,
copy into tests/conformance/, append to V2_FIXTURES.
* fix: break import cycle between _verify and _evidence
Extract InvalidReceiptError, _is_valid_rfc3339, and _RFC3339_RE into a
new leaf module _common.py. Both _verify (v1) and _evidence (v2) now
import from _common, which has no intra-package imports of its own.
This removes the static cycle CodeQL flagged at _evidence.py:19 and
_verify.py:184.
The class object identity is preserved (re-exported via `import X as X`
from _verify), so existing `except InvalidReceiptError` callers and the
public pipelock_verify.InvalidReceiptError API continue to work.
* fix: report declared chain_seq in v2 fail-closed chain branch
The v2-in-chain fail-closed branch reported the list index for
broken_at_seq instead of the receipt's declared chain_seq, which
diverges from the v1 branch (which reads action_record.chain_seq
with index fallback). Auditors now see the same sequence number the
emitter wrote.
Defensive: only accept int values (rejecting bool, which Python
treats as int). Missing or non-int chain_seq falls back to the list
index so broken_at_seq is never None on the fail-closed path.
Adds three regression tests covering declared, missing, and non-int
chain_seq cases.
* chore: fix lint + typecheck CI (pre-existing, surfaced after b64fa7d)
CI on the branch has been failing both lint (ruff format) and
typecheck (mypy strict no-any-return) since b64fa7d. Fixing both
together so the branch goes green.
mypy: _PAYLOAD_VALIDATORS was typed `dict[str, Any]`, which lost
the validators' `(payload: dict[str, Any]) -> str | None` signature
and made `_validate_payload` return Any from a `str | None` slot.
Replace with `dict[str, Callable[[dict[str, Any]], str | None]]` so
the return type checks through the dispatch.
ruff format: blank-line and string-wrap normalisations across
_verify.py and the new test_regressions.py block. Auto-applied.1 parent ca2e635 commit 7649576
19 files changed
Lines changed: 2521 additions & 106 deletions
File tree
- .github/workflows
- pipelock_verify
- tests
- conformance
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
41 | 48 | | |
42 | 49 | | |
43 | | - | |
44 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
| |||
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
76 | 170 | | |
77 | 171 | | |
78 | | - | |
| 172 | + | |
79 | 173 | | |
80 | 174 | | |
81 | 175 | | |
| |||
86 | 180 | | |
87 | 181 | | |
88 | 182 | | |
89 | | - | |
| 183 | + | |
90 | 184 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
98 | 194 | | |
99 | | - | |
100 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
101 | 202 | | |
102 | 203 | | |
103 | 204 | | |
104 | 205 | | |
105 | 206 | | |
106 | | - | |
| 207 | + | |
107 | 208 | | |
108 | 209 | | |
109 | 210 | | |
110 | | - | |
111 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
112 | 214 | | |
113 | 215 | | |
114 | 216 | | |
115 | 217 | | |
116 | 218 | | |
117 | 219 | | |
118 | 220 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | 221 | | |
137 | 222 | | |
138 | | - | |
| 223 | + | |
139 | 224 | | |
140 | 225 | | |
141 | 226 | | |
| |||
0 commit comments