Verification example
import crypto from 'node:crypto';
function verifyFoxpaySignature(rawBody, receivedSignature, secret) {
const signature = receivedSignature.replace(/^sha256=/, '');
const expected = crypto
.createHmac('sha256', secret)
.update(rawBody)
.digest('hex');
if (signature.length !== expected.length) {
return false;
}
return crypto.timingSafeEqual(
Buffer.from(expected, 'utf8'),
Buffer.from(signature, 'utf8')
);
}