Skip to content

otplib API Documentation / @otplib/core / constantTimeEqual

Function: constantTimeEqual()

constantTimeEqual(a, b): boolean

Defined in: packages/core/src/utils.ts:510

Constant-time comparison to prevent timing attacks

This implements a timing-safe equality check as recommended in RFC 4226 Section 7.2 for token validation to prevent timing side-channel attacks.

Parameters

a

First value to compare

string | Uint8Array<ArrayBufferLike>

b

Second value to compare

string | Uint8Array<ArrayBufferLike>

Returns

boolean

true if values are equal, false otherwise

See

RFC 4226 Section 7.2 - Validation and Verification

Released under the MIT License.