Webhooks
Verify every delivery before you trust it.
Each webhook body is signed with HMAC-SHA256 using the whsec_ secret shown once at creation. The signature arrives in the X-Stemma-Signature header as sha256=<hex>, computed over the raw request body. Compare it timing-safely, and use the Idempotency-Key header to drop redeliveries.
Plate III — Signature verificationnode.js
import { createHmac, timingSafeEqual } from 'node:crypto';
// Verify a Stemma webhook delivery.
// secret: the whsec_… value shown once when the webhook was created.
export function verifyStemmaWebhook(rawBody, headers, secret) {
const received = headers['x-stemma-signature'] ?? ''; // "sha256=<hex>"
const expected = 'sha256=' +
createHmac('sha256', secret).update(rawBody).digest('hex');
const a = Buffer.from(received);
const b = Buffer.from(expected);
return a.length === b.length && timingSafeEqual(a, b); // timing-safe
}