Crear cuenta

Verificar la firma

Comprueba que cada aviso viene de Closeford.

CabeceraContiene
X-Webhook-EventEl evento, como record.created.
X-Webhook-DeliveryUn id único por entrega, para ignorar repeticiones.
X-Webhook-TimestampCuándo se envió, en segundos Unix.
X-Webhook-Signaturesha256= y el HMAC-SHA256 de timestamp.body con el secreto de tu webhook.
import crypto from "node:crypto";

// raw = the request body as received (string), before JSON.parse
export function verify(raw, headers, secret) {
  const ts = headers["x-webhook-timestamp"];
  const expected = "sha256=" + crypto
    .createHmac("sha256", secret)
    .update(`${ts}.${raw}`)
    .digest("hex");
  const got = headers["x-webhook-signature"] ?? "";
  return got.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expected));
}

Calcula la firma sobre el cuerpo tal cual llega, antes de convertirlo en JSON.