Signatures & Idempotency
Headers on every delivery
| Header | Meaning |
|---|---|
X-Signature | v1=<hex-hmac-sha256> — see below. |
X-Webhook-Event | The event type, same as the payload’s type field. |
Idempotency-Key | Stable across every automatic retry of one delivery — see below. Absent on simulator sends and manual re-sends. |
User-Agent | VectaPay-Webhooks/1.0 |
Verifying the signature
X-Signature is an HMAC-SHA256 of the exact raw request body, keyed with your webhook signing
secret and prefixed with a version tag (v1=) so the scheme can change later without breaking
existing integrations. Compare the hex digest in constant time; every SDK below does that with its
language’s standard primitive (crypto.subtle in TypeScript, hmac.compare_digest in Python,
MessageDigest.isEqual in Java, CryptographicOperations.FixedTimeEquals in C#) rather than a
hand-rolled byte loop, so response timing can’t leak how much of a guessed signature was right.
Verify the raw body string. Do not verify a re-serialized object unless you are sure your parser round-trips the bytes exactly — key order and number formatting can change on the way back out, and the signature is over what we sent, not what you rebuilt.
TypeScript
import { WebhookHandler } from "@vectapay/sdk";
const webhooks = new WebhookHandler(process.env.VECTAPAY_WEBHOOK_SECRET!);
// rawBodyString is the body exactly as received — e.g. Buffer.toString("utf8")
// from express.raw(), or await req.text() in Fetch-style handlers.
const isValid = await webhooks.verifySignature(rawBodyString, req.headers["x-signature"]);
if (!isValid) {
return new Response("Invalid signature", { status: 400 });
}
const event = JSON.parse(rawBodyString);The TypeScript and Python parseEvent/parse_event helpers take an already-parsed object and
re-serialize it to recompute the signature. That is convenient but can disagree with the bytes we
signed for payloads with unusual number or key ordering. Prefer verifySignature on the raw body
and parse afterwards, as above. The Java and C# helpers take the raw body directly.
Rotate your secret from Developer → Webhooks → Regenerate secret if you suspect it’s leaked. New deliveries are signed with the new secret immediately. A delivery that was already queued keeps the secret it was queued with for the rest of its retries, though — so if you rotate while deliveries are in flight, accept both the old and the new secret for a short window rather than rejecting the old one outright.
Idempotency
Deliveries are at-least-once. An automatic retry is a second attempt at the same delivery, so
your handler can see the same event twice even though it only happened once. Use the
Idempotency-Key header to make processing safe:
- It’s an opaque string identifying the delivery, and it is identical on every automatic retry of that delivery — the first attempt plus the ~1, 5, 15, and 60-minute retries. Don’t parse it; compare it.
- It is absent on simulator sends and on manual re-sends — those are new deliveries, not retries.
- When it’s absent, fall back to the event
id. It identifies the delivery, and a retry from the delivery log re-sends that delivery’s stored payload, so theidis unchanged. It is not unchanged on apayments.retryWebhook()re-send or a simulator send — those build a fresh event, and that’s the behavior you want: they are new deliveries and should be processed.
Store the key before or as part of applying the event, and treat a repeat as a no-op that still
returns 2xx:
Ordering is not guaranteed between different events. payment.failed and payment.late_success for
the same payment can reach you in either order, and two subscriptions’ events can interleave. Make
the work idempotent and state-based (set the order to “paid” if it isn’t already) rather than a
sequence of blind increments.