What it builds
- ✓HMAC-SHA256 signature verification (no SDK dependency)
- ✓Event normalisation into a stable 7-field schema
- ✓Idempotent writes — Stripe retries dedupe on event_id
- ✓Local testing via stripe listen + stripe trigger
The key step
async function verifyStripeSignature(payload, header, secret) {
const { t, v1 } = Object.fromEntries(header.split(',').map(p => p.split('=')))
const key = await crypto.subtle.importKey('raw',
new TextEncoder().encode(secret),
{ name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
const sig = await crypto.subtle.sign('HMAC', key,
new TextEncoder().encode(`${t}.${payload}`))
return toHex(sig) === v1 // constant-time in real code
}note ▸
This is the core of the recipe. The full file (including setup, error handling, and the surrounding scaffolding) lives in the GitHub folder linked below — clone or copy it directly.
Run it
Stack
cloudflare-workerstypescriptstripe
Full source on GitHub
README, runnable code, .env.example, dependencies — all in one folder.