Add signed Coinbase webhook example endpoint with HMAC verification#296
Merged
GsCommand merged 1 commit intoMay 23, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Motivation
X-Hook0-SignatureHMAC before parsing JSON and only signs normalized CLAS receipts after successful verification.Description
api/examples/coinbase-webhook.jsimplementing a POST-only endpoint that useslib/coinbaseWebhook.jsto parset,h,v1, reconstruct the signed payload (${timestamp}.${signedHeaderNames}.${signedHeaderValues}.${rawBody}), enforce freshness (COINBASE_WEBHOOK_MAX_AGE_SECONDS, default300), verify HMAC-SHA256 withcrypto.timingSafeEqual, and parse JSON only after HMAC passes.lib/receiptSigning.jsto canonicalize receipts withjson.sorted_keys.v1, compute SHA-256 of the canonical payload, and produce an Ed25519 signature placed inmetadata.proofwithhash,signature(alg: "Ed25519",kid,value,role: "runtime"),canonicalization, andsigner_idfields consistent withlib/verifyReceipt.jsexpectations.receipt_id: rcpt:coinbase_cdp:<event_id>,verb: observe,source: coinbase.cdp.webhook,metadata.trace, andmetadata.proof; the endpoint deduplicates by Coinbase event id using an in-memoryMapfor the example.docs/integrations/coinbase-cdp-webhook-receipts.mdwith a new "Signed example endpoint" section and required env vars:COINBASE_WEBHOOK_SECRET,COINBASE_WEBHOOK_MAX_AGE_SECONDS(optional),CL_RECEIPT_SIGNER_ID,CL_RECEIPT_SIGNING_PRIVATE_KEY_PEM, andCL_RECEIPT_SIGNING_KID.Testing
tests/api-coinbase-webhook.test.jscovering: non-POST405, missing Coinbase secret503, missing signature400, malformed signature400, stale timestamp400, invalid HMAC400, malformed JSON after valid HMAC400, missing signing env503, valid signed payload200with duplicate replay returning the same receipt; tests exercise local verification via an injected ENS text resolver.npm test(node --test tests/*.test.js) and all tests passed (62 passing, 0 failing).rg -n "erc8211\.merkle\.v1"returned no matches.Codex Task