const crypto = require("crypto");
// Your secret key for generating and verifying signatures
const hashSecret = "{your-api-key}{your-secret-key}";
// Example: 80a2dc85-1o0s-4405-8cc4-08c1f457011b5b5e4b16-4f22-45d2-9poc-5e4e60915719
// Received webhook payload and signature from the request headers
const businessId =
"{your-business-id}"; /* Extract business ID from webhook page on Sigma dashboard */
const receivedSignature =
"{your-received-signature}"; /* Extract signature from request headers */
// Function to generate a signature for a given payload
function generateSignature(payload: string) {
const hmac = crypto.createHmac("sha256", hashSecret);
hmac.update(payload);
return hmac.digest("hex");
}
// Validate the received signature
const generatedSignature = generateSignature(businessId);
if (generatedSignature === receivedSignature) {
console.log(
"Webhook signature is valid. Proceed with processing the payload."
);
} else {
console.log("Webhook signature is invalid. Do not process the payload.");
}