Skip to content

feat(sdk): add versioned delegate-SD-JWT golden vectors + consumer test - #307

Open
vishkaty wants to merge 1 commit into
google-agentic-commerce:mainfrom
vishkaty:feat/delegate-sd-jwt-golden-vectors
Open

feat(sdk): add versioned delegate-SD-JWT golden vectors + consumer test#307
vishkaty wants to merge 1 commit into
google-agentic-commerce:mainfrom
vishkaty:feat/delegate-sd-jwt-golden-vectors

Conversation

@vishkaty

Copy link
Copy Markdown

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.py but 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 an expected block (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:

vector segments ~~ joins ends ~
root-single-sd-jwt 1 0
single-hop-payment-chain 2 1
multi-hop-payment-chain 3 2
single-hop-checkout-chain 2 1

Verification

  • Consumer test: 10 passed — asserts each vector verifies against the SDK with the expected resolved payloads, and the wire shape (single SD-JWT ends ~; an N-segment chain has exactly N−1 ~~ joins).
  • Kill-tests (proving the vectors actually gate): flipping a signature byte → InvalidJWSSignature; collapsing a ~~~ → wire-shape + verify failure. Both revert clean.
  • Full SDK suite green with these added (the 2 unrelated kb_sd_jwt_intermediate_tests failures pre-exist on a pristine checkout). ruff check/format clean 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 in generate_vectors.py and the JSON's reproducibility block.

Note

Two minimal repo-config edits keep spellcheck CI green on the new files: a .cspell.json ignore-glob for the vector JSON (base64 crypto blobs) and adding sdjwt to the custom dictionary. Happy to adjust if you'd prefer a different exclusion mechanism.

Closes #303

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.
@vishkaty
vishkaty requested a review from a team as a code owner July 28, 2026 20:01
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal]: versioned delegate-SD-JWT chain golden vectors + a CI drift canary against the reference

2 participants