import * as crypto from 'crypto';
function validateSignature(secretKey: string, rawPayload: string, receivedSignature: string): boolean {
const expectedSignature = crypto.createHmac('sha256', secretKey).update(rawPayload).digest('hex');
return receivedSignature === expectedSignature;
}
app.post('/webhook', (req, res) => {
// Retrieve the signature from the headers
const receivedSignature = req.headers['http_x_fuse_signature_256'];
const secretKey = 'your_secret_key';
const isSignatureEqual = validateSignature(secretKey, JSON.stringify(req.body), receivedSignature);
// Compare the signatures
if (!isSignatureEqual) {
return res.status(401).send('Mismatched signatures');
}
// Process the webhook payload
// ...
res.status(200).send({ status: 'complete' });
});