Skip to content
English
  • There are no suggestions because the search field is empty.

Webhook Signatures

Confirm that every notification came from iDonate and wasn't changed on the way.

Webhook signatures let you check that a request to your endpoint came from iDonate and not from someone else. If your webhook configuration has a Webhook Signing Secret, every request includes an X-iDonate-Signature header, which you can use to verify the request is genuine.

Signature Anatomy

iDonate webhook signatures use this format:

  • X-iDonate-Signature: t=<timestamp>,v1=<signature hash>

The signature has two parts.

timestamp

The time the request was signed, in Unix time (seconds since January 1, 1970, UTC).

  • Example: 1795453571

signature hash

A Base64-encoded HMAC SHA-256 hash of the timestamp and the payload sent by the webhook.

  • Example: ukpNKivkHbJCZgfO7JShD/Gby1aZC6on+jP7gEFK73M=

Put together, a signature header looks like this:

  • X-iDonate-Signature: t=1795453571,v1=ukpNKivkHbJCZgfO7JShD/Gby1aZC6on+jP7gEFK73M=

How are Signature Hashes Created

First, the timestamp and the payload are joined in this format: <timestamp>.<payload of the request>

  • Example: 1795453571.{"id":"evt_123","type":"transaction_set.created","payload":{"amount":"25.00"}}

Next, that string is hashed with HMAC SHA-256, using your Webhook Signing Secret as the key. The result is Base64-encoded and sent in the header along with the timestamp.

  • Example: t=1795453571,v1=ukpNKivkHbJCZgfO7JShD/Gby1aZC6on+jP7gEFK73M=

Signature Verification

To verify a request, follow these steps.

Step 1

Get your signing secret. Open your iDonate Webhook configuration and copy the Webhook Signing Secret (it starts with whsec_). Store it securely on your server, for example in an environment variable.

Step 2

Parse the X-iDonate-Signature header to get the timestamp and the signature hash. You can use this regex:

  • ^t=(\d+),v1=(.+)$

The regex returns these groups:

  • [0]: entire string
  • [1]: timestamp
  • [2]: signature hash

Step 3

Check the timestamp. If it is more than 5 minutes from your server’s current time, reject the request. This stops an old request from being replayed.

Step 4

Build a string from the timestamp in the header and the raw body of the request.

The string must use this format: {timestamp}.{body}

  • Example: 1795453571.{"id":"evt_123","type":"transaction_set.created","payload":{"amount":"25.00"}}

Use the body exactly as you received it. Don’t parse and re-serialize the JSON: any change to spacing or key order will make verification fail.

Step 5

Compute the HMAC SHA-256 hash of that string with your signing secret, and Base64-encode the result.

const crypto = require("crypto");
const textToSign = `${timestamp}.${rawBody}`;
const expected = crypto.createHmac("sha256",secret).update(textToSign).digest("base64");

Step 6

Compare your result with the signature hash from the header. Use a constant-time comparison such as crypto.timingSafeEqual in Node or hmac.compare_digest in Python. If the two values match, the request is from iDonate. If they don’t, reject the request with 401.