feat: independent Agent Commerce receipt verification (#2) - #3
Merged
Merged
Conversation
certifieddata-verify <receipt-id> now verifies payment receipts locally: fetch the payload+signature envelope from the public verify endpoint, fetch the Agent Commerce PEM from .well-known, RFC 8785 JCS-canonicalize (the repo's existing zero-dep canonicalizer), verify Ed25519 with Node crypto, and recompute SHA-256 against the stored receipt hash. The server's valid/signatureValid booleans are surfaced as informational metadata only — they never determine the verdict, proven by a lying- server test. Artifact-kind resolution per the issue spec (src/resolve.ts): prefix and URL-path hints, local JSON schema sniffing, and for bare UUIDs a dual probe of both public endpoints — exactly-one wins, both -> AMBIGUOUS (exit 64, require --type), neither -> NOT_FOUND, transport failure -> NETWORK (a server failure is never treated as absence). --type certificate|receipt overrides everything. Certificate behavior is unchanged (all 34 pre-existing tests pass untouched). Key handling fails closed: PEM endpoint 503/unreachable -> UNKNOWN_KEY exit with an explicit 'the server's own verdict is NOT accepted as a substitute' message; offline receipt verification requires --key <pem>. Tests: 15 new (49 total) — real Ed25519 over real JCS bytes; 9-field tamper matrix (amount, policy_hash, artifact_hash, agent, purpose, status, settlement_state, timestamp, receipt_id) each fails; stored-hash mismatch fails even with a valid signature; missing signature and wrong schema are MALFORMED; RSA key is UNKNOWN_KEY. Depends on platform PR #318 exposing signature + canonicalization + public_key_url on GET /api/payments/verify/:receiptId. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Live end-to-end against production is now confirmed — both platform deploys (#318 signature exposure, #319 PEM ESM fix) landed. Fresh receipt from a fully anonymous stranger run tonight: Auto-detection also confirmed live: the bare UUID resolved via the dual-endpoint probe (receipt exists, certificate doesn't → receipt path) with no The receipt itself carries the full evidence chain from #315: non-null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #2 —
certifieddata-verify <receipt-id>verifies Agent Commerce payment receipts locally: fetch the payload + signature envelope, fetch the Agent Commerce PEM from.well-known, RFC 8785 JCS-canonicalize (the repo's existing zero-dep canonicalizer), verify Ed25519 with Nodecrypto, recompute SHA-256 against the stored hash. Zero new dependencies.The server's booleans never determine the verdict — proven by a lying-server test where
{valid: true, signatureValid: true}accompanies a tampered payload and the CLI still says INVALID.Artifact-kind resolution (per spec)
src/resolve.ts: prefix hints → endpoint-URL hints → local JSON schema sniff → dual-endpoint probe for bare UUIDs. Exactly-one wins; both → AMBIGUOUS (exit 64, requires--type); neither → NOT_FOUND; transport failure → NETWORK, never "not found".--type certificate|receiptoverrides everything.Fail-closed key handling
PEM endpoint 503/unreachable → UNKNOWN_KEY exit with an explicit "the server's own verdict is NOT accepted as a substitute" message.
--offlinereceipts require--key <pem>.Acceptance criteria
--type receipt/--type certificateoverride detectioncrypto, not the server verdictcanonicalizeToBytesused for certs)/.well-known/certifieddata-public-key.pemsignature+canonicalization+public_key_urlon the verify endpoint) and platform#319 (fixes the PEM endpoint's ESM dynamic-require 503). Both merged; will confirm and post the terminal transcript here once production serves them.Tests: 49/49 (15 new). Lint + typecheck clean.
🤖 Generated with Claude Code