Skip to navigation

Verify Signatures

View as Markdown

SimZ signs webhook deliveries with HMAC-SHA256 when the webhook has a secret.

Headers

HeaderValue
X-Webhook-Signaturesha256=<hex HMAC>
X-Webhook-TimestampUnix timestamp in seconds

Signed payload

HMAC-SHA256(secret, "<X-Webhook-Timestamp>.<raw request body>")

Node.js example

const crypto = require("crypto");
function verifySimzWebhook(rawBody, headers, secret) {
const signatureHeader = headers["x-webhook-signature"] || "";
const timestamp = headers["x-webhook-timestamp"] || "";
const expected =
"sha256=" +
crypto
.createHmac("sha256", secret)
.update(`${timestamp}.${rawBody}`)
.digest("hex");
const a = Buffer.from(signatureHeader);
const b = Buffer.from(expected);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}