Skip to main content
Compares two buffers in time that depends only on their length, so the comparison does not reveal where they differ. Use it to check secrets, such as webhook signatures, instead of ===. It has the same signature as Node’s crypto.timingSafeEqual.

Example: Verifying a webhook signature

src/app/webhooks/signed-event.webhook.ts

API

timingSafeEqual(a, b): boolean

Returns true when both buffers hold the same bytes.

Parameters

ArrayBuffer | ArrayBufferView
required
The first buffer.
ArrayBuffer | ArrayBufferView
required
The second buffer. Must have the same byte length as a.

Errors

  • Throws a RangeError when a and b have different byte lengths.
  • Throws a TypeError when either input is not an ArrayBuffer or a view, such as a string.