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

    Function verifySignature

    • Verify a Square webhook signature using HMAC-SHA256

      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 where the webhook was sent (optional, for additional verification)

      Returns WebhookVerificationResult

      Verification result with valid flag and optional error

      import { verifySignature } from '@bates-solutions/squareup/server';

      const result = verifySignature(
      rawBody,
      req.headers['x-square-hmacsha256-signature'],
      process.env.SQUARE_WEBHOOK_KEY!
      );

      if (!result.valid) {
      return res.status(401).json({ error: result.error });
      }

      // While rotating the key, accept the new and the old one
      verifySignature(rawBody, signature, [process.env.SQUARE_WEBHOOK_KEY!, process.env.SQUARE_WEBHOOK_KEY_OLD!]);