Verify a Stripe webhook signature.
Reimplements Stripe's signing scheme (HMAC-SHA256 over ${timestamp}.${body}) using WebCrypto, so verification needs neither a Stripe SDK instance, a network call, nor any Node built-in — it runs on Node 22+, Deno, Bun, and Workers.
${timestamp}.${body}
The raw request body as a string
The stripe-signature header value
stripe-signature
Your webhook signing secret (whsec_…)
whsec_…
Optional
Verification options (timestamp tolerance)
Verification result with a valid flag and optional error
valid
import { verifySignature } from '@bates-solutions/stripe/server';const result = await verifySignature( rawBody, req.headers['stripe-signature'], process.env.STRIPE_WEBHOOK_SECRET!);if (!result.valid) { return res.status(400).json({ error: result.error });} Copy
import { verifySignature } from '@bates-solutions/stripe/server';const result = await verifySignature( rawBody, req.headers['stripe-signature'], process.env.STRIPE_WEBHOOK_SECRET!);if (!result.valid) { return res.status(400).json({ error: result.error });}
Verify a Stripe webhook signature.
Reimplements Stripe's signing scheme (HMAC-SHA256 over
${timestamp}.${body}) using WebCrypto, so verification needs neither a Stripe SDK instance, a network call, nor any Node built-in — it runs on Node 22+, Deno, Bun, and Workers.