Verify signatures and retries
Webhook endpoints should accept only signed events over HTTPS, enforce idempotency on your side, and log delivery failures with enough context to replay safely.
tsverify-webhook.ts
01 import crypto from 'node:crypto'
02
03 export function verifySignature(payload: string, secret: string, signature: string) {
04 const digest = crypto.createHmac('sha256', secret).update(payload).digest('hex')
05 return crypto.timingSafeEqual(Buffer.from(digest), Buffer.from(signature))
06 }