const crypto = require("crypto");
function verifyWebhook(rawBody, headers, secret) {
const timestamp = headers["x-meum-timestamp"];
const signature = headers["x-meum-signature"];
if (!timestamp || !signature) return false;
if (Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > 300) return false;
const signed = `${timestamp}.${rawBody}`;
const expected = "v1=" + crypto.createHmac("sha256", secret).update(signed).digest("hex");
try {
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
} catch {
return false;
}
}