feat(sdk): add versioned delegate-SD-JWT golden vectors + consumer test - #307
feat(sdk): add versioned delegate-SD-JWT golden vectors + consumer test#307vishkaty wants to merge 1 commit into
Conversation
Add a keyed, versioned golden-vector set for the AP2 delegation chain layer (the SD-JWT ~~ wire), addressing issue google-agentic-commerce#303. Every vector is minted by the real reference SDK (ap2.sdk) rather than hand-forged, so the committed serializations are authoritative. Vectors (delegate_sd_jwt_vectors/delegate_sd_jwt_vectors.json): - root-single-sd-jwt: a lone SD-JWT (ends with ~, zero ~~ joins) - single-hop-payment-chain: one hop via MandateClient.present (one ~~) - multi-hop-payment-chain: Bank -> SA -> CP -> Merchant (two ~~ joins) - single-hop-checkout-chain: the checkout mandate family (one ~~) delegate_sd_jwt_vector_tests.py consumes the frozen set and asserts the on-wire invariants (single ends ~, N-segment chain has N-1 ~~ joins) and that each vector verifies against the SDK with the expected resolved payloads. generate_vectors.py regenerates the set from pinned P-256 keys; salts and ES256 signatures are randomized by design, so the committed JSON is the frozen artifact the test verifies.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
A note on the red Lint Code Base check: the failures are not from files in this diff. Super Linter runs Biome across the whole workspace whenever a PR touches a Biome relevant file type, and this PR includes two JSON files, so the check surfaced the preexisting Biome findings in the repo. A clean checkout of main at e1ea56d shows the same 65 errors, mostly a11y title elements in the docs assets SVGs and button type props in the web client. The five files changed here lint clean under the same Biome major version. PRs that touch only Python files skip Biome entirely, which is why the check is green on some sibling PRs and red here. I am happy to file a separate PR that clears the preexisting findings if that would be useful. |
|
Following up on the note above: #311 clears the preexisting findings and the Lint Code Base check is green there, so once it lands this PR can be rebased to pick up a meaningful lint signal. |
Summary
Adds a versioned, self-describing golden-vector set for the delegate-SD-JWT chain layer, plus a consumer test that verifies each vector against the SDK and asserts the compact-serialization wire invariants. Addresses #303.
The SDK builds delegation chains inline in
chain_tests.pybut ships no on-disk golden-vector artifact, so a spec/format change can silently alter the~~-joined wire without a frozen reference catching it. These vectors are that reference.What's included
code/sdk/python/ap2/tests/delegate_sd_jwt_vectors/delegate_sd_jwt_vectors.json— 4 frozen vectors, each with its public JWK, kids, verification inputs, and anexpectedblock (hop_count,double_tilde_joins,ends_with_tilde, payload assertions).generate_vectors.py— the generator (pinned keys), mirroring the SDK's canonical Bank → Shopping-Agent → Credentials-Provider → Merchant flow.delegate_sd_jwt_vector_tests.py— consumer/verifier.All four vectors are minted by the real
ap2.sdk(sd_jwt.create/kb_sd_jwt.create/MandateClient.present) — not hand-authored strings:~~joins~root-single-sd-jwtsingle-hop-payment-chainmulti-hop-payment-chainsingle-hop-checkout-chainVerification
~; an N-segment chain has exactly N−1~~joins).InvalidJWSSignature; collapsing a~~→~→ wire-shape + verify failure. Both revert clean.kb_sd_jwt_intermediate_testsfailures pre-exist on a pristine checkout).ruff check/formatclean on the new Python.Reproducibility
Keys are pinned and embedded, so signature verification is fully deterministic on any machine. Per RFC 9901 the compact serializations are intentionally not byte-reproducible (random disclosure salts; randomized ECDSA
k) — regeneration yields semantically identical, byte-different vectors, so the committed JSON is the frozen artifact the consumer test verifies. This is documented ingenerate_vectors.pyand the JSON'sreproducibilityblock.Note
Two minimal repo-config edits keep spellcheck CI green on the new files: a
.cspell.jsonignore-glob for the vector JSON (base64 crypto blobs) and addingsdjwtto the custom dictionary. Happy to adjust if you'd prefer a different exclusion mechanism.Closes #303