The raw request body as a string
The signature from the x-square-hmacsha256-signature header
Your webhook signature key from Square, or a list of keys while you rotate it (any match is valid)
OptionalnotificationUrl: string
The URL registered on the webhook subscription (Square signs it)
Verification result with valid flag and optional error
import { verifySignatureAsync, SIGNATURE_HEADER } from '@bates-solutions/squareup/server/web';
const rawBody = await request.text();
const result = await verifySignatureAsync(
rawBody,
request.headers.get(SIGNATURE_HEADER) ?? '',
Deno.env.get('SQUARE_WEBHOOK_KEY')!,
'https://example.com/webhook'
);
if (!result.valid) {
return Response.json({ error: result.error }, { status: 401 });
}
Verify a Square webhook signature with WebCrypto (edge-safe, async).
The same check as verifySignature, HMAC-SHA256 over
notificationUrl + rawBodycompared in constant time, but computed withglobalThis.crypto.subtleinstead ofnode:crypto. Use it on Deno, Supabase Edge Functions, Cloudflare Workers or Bun, wherenode:cryptomay be missing. WebCrypto is promise-based, so this returns aPromise.On Node, the synchronous verifySignature is still available and is what the Express, Next.js and Lambda adapters use.