@bates-solutions/squareup API Reference - v3.2.0
    Preparing search index...

    Function verifySignatureAsync

    • Verify a Square webhook signature with WebCrypto (edge-safe, async).

      The same check as verifySignature, HMAC-SHA256 over notificationUrl + rawBody compared in constant time, but computed with globalThis.crypto.subtle instead of node:crypto. Use it on Deno, Supabase Edge Functions, Cloudflare Workers or Bun, where node:crypto may be missing. WebCrypto is promise-based, so this returns a Promise.

      On Node, the synchronous verifySignature is still available and is what the Express, Next.js and Lambda adapters use.

      Parameters

      • rawBody: string

        The raw request body as a string

      • signature: string

        The signature from the x-square-hmacsha256-signature header

      • signatureKey: WebhookSignatureKey

        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)

      Returns Promise<WebhookVerificationResult>

      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 });
      }