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

    Function timingSafeEqual

    • Constant-time equality of two strings or two byte sequences. Pure JS, so it works where node:crypto is missing.

      Two strings are compared code unit by code unit, so the result is exactly a === b. When either side is bytes (a Uint8Array or an ArrayBuffer), a string on the other side is compared as its UTF-8 bytes (an unpaired surrogate encodes as U+FFFD there). Any other input throws a TypeError.

      Returns false without comparing when the lengths differ or either side is empty: an empty signature must never verify. For equal lengths, the time taken depends only on the length, not on where the inputs differ.

      Parameters

      • a: string | ArrayBuffer | Uint8Array<ArrayBufferLike>
      • b: string | ArrayBuffer | Uint8Array<ArrayBufferLike>

      Returns boolean

      if (!timingSafeEqual(signatureFromHeader, expectedSignature)) {
      return { valid: false, error: 'Invalid signature' };
      }