import { verifyWebhook } from '@prudra/webhooks';
app.post('/webhooks/prudra', express.raw({ type: '*/*' }), (req, res) => {
res.sendStatus(200);
const isValid = verifyWebhook({
payload: req.body as Buffer,
signature: req.headers['x-prudra-signature'] as string,
timestamp: req.headers['x-prudra-timestamp'] as string,
secret: process.env.PRUDRA_WEBHOOK_SECRET!,
});
if (!isValid) return;
const event = JSON.parse((req.body as Buffer).toString());
if (event.type === 'transfer.completed') {
const { transactionId, toChain, confirmedAt } = event.payload;
console.log(`Transfer ${transactionId} confirmed on ${toChain} at ${confirmedAt}`);
// Update your database, notify your users, etc.
}
if (event.type === 'transfer.failed') {
const { transactionId, reason, refundTxHash } = event.payload;
console.log(`Transfer ${transactionId} failed: ${reason}`);
console.log(`Funds returned: ${refundTxHash}`);
}
});