Node.js / Express
import crypto from "node:crypto";
const signed = Buffer.concat([
Buffer.from(timestamp + "."),
rawBody,
]);
const expected = crypto
.createHmac("sha256", WEBHOOK_SECRET)
.update(signed)
.digest();
const received = Buffer.from(signature, "hex");
const valid =
received.length === expected.length &&
crypto.timingSafeEqual(received, expected);