@bates-solutions/payments-core API Reference - v0.2.0
    Preparing search index...

    Function hmacSha256

    • HMAC-SHA256 of payload under secret, computed with WebCrypto (globalThis.crypto.subtle), so it runs on Node 22+, Deno, Bun and Workers with no Node built-ins. Strings are encoded as UTF-8.

      Returns the raw 32-byte digest; encode it with toHex or toBase64 to compare against a provider's signature header.

      The promise rejects with a WebCrypto DataError for an empty secret, which WebCrypto does not accept as an HMAC key. Check for a missing secret before calling, as the providers do.

      Parameters

      • secret: string | Uint8Array<ArrayBufferLike>
      • payload: string | Uint8Array<ArrayBufferLike>

      Returns Promise<Uint8Array<ArrayBufferLike>>

      const digest = await hmacSha256(secret, `${timestamp}.${rawBody}`);
      const expected = toHex(digest);