Skip to content

@xtandard/webhooks/signing

Standard Webhooks symmetric (v1) signing and verification.

Pure and zero-dependency (Web Crypto only) — safe on the request path and in any WinterCG runtime. Shared by the sender (the dispatcher signs outgoing deliveries) and the receiver subpath (@xtandard/webhooks/receiver), and compatible with any Standard Webhooks implementation, including Svix.

The wire contract (https://www.standardwebhooks.com):

  • secrets are whsec_ + base64-encoded key material (24–64 bytes decoded)
  • the signed content is ${id}.${timestamp}.${body}
  • the signature is v1, + base64(HMAC-SHA256(key, signedContent))
  • webhook-signature may carry several space-separated signatures (secret rotation); a receiver accepts if any matches
  • webhook-timestamp (unix seconds) must be within tolerance, both ways
import { … } from "@xtandard/webhooks/signing";
Name Summary
generateSecret Generate a new signing secret: whsec_ + base64 of 24 crypto-random bytes.
sign Sign one delivery attempt with one secret: v1, + base64(HMAC-SHA256 over ${id}.${timestamp}.${body}). timestamp is unix seconds.
signatureHeader Build the full webhook-signature header value: one signature per secret, space-separated (multiple entries appear during secret rotation).
verify Verify an incoming Standard Webhooks request (from any compliant sender, not just this package). Checks the timestamp tolerance, then compares every v1, signature in the header against every candidate secret in constant time. Returns the parsed envelope on success; throws WebhookVerificationError otherwise.
Name Summary
WebhookVerificationError Thrown by verify / receiver helpers when a webhook fails verification.
Name Summary
VerifyInput Input to verify.
Name Summary
SECRET_PREFIX Prefix of every symmetric Standard Webhooks secret.
Name Documented on
WebhookEnvelope @xtandard/webhooks/schema