import crypto from 'node:crypto';
import express from 'express';
const app = express();
app.post('/webhooks/gnosisramp', express.raw({ type: 'application/json' }), (req, res) => {
const timestamp = req.header('x-gnosisramp-timestamp');
const signature = req.header('x-gnosisramp-signature');
const clientId = req.header('x-gnosisramp-client-id');
if (!timestamp || !signature || !clientId) {
return res.status(400).send({ error: 'Missing headers' });
}
const clientSecret = lookupSecret(clientId); // fetch from your vault
const message = `${timestamp}.${req.body.toString('utf8')}`;
const expected = crypto.createHmac('sha256', clientSecret).update(message).digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(signature, 'hex'), Buffer.from(expected, 'hex'))) {
return res.status(401).send({ error: 'Invalid signature' });
}
const event = JSON.parse(req.body.toString('utf8'));
handleEvent(event);
res.status(200).send({ received: true });
});