const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, timestamp, secret) {
const signedPayload = `${timestamp}.${payload}`;
const expectedSignature = crypto.createHmac('sha256', secret)
.update(signedPayload)
.digest('hex');
return expectedSignature === signature;
}
// In your webhook handler:
const webhookSecret = process.env.Gx402_WEBHOOK_SECRET;
const signature = req.headers['x-Gx402-signature'];
const timestamp = req.headers['x-Gx402-timestamp'];
const rawBody = req.rawBody; // Get the raw request body
if (verifyWebhookSignature(rawBody, signature, timestamp, webhookSecret)) {
// Process webhook event
} else {
// Signature verification failed
res.status(403).send('Invalid signature');
}