Skip to content

otplib API Documentation / @otplib/core / utils / validateCounterTolerance

Function: validateCounterTolerance() ​

validateCounterTolerance(counterTolerance, guardrails?): void

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

Validate counter tolerance for HOTP verification

Prevents DoS attacks by limiting the number of counter values checked.

Parameters ​

counterTolerance ​

number | [number, number]

Counter tolerance specification (number or array of offsets)

guardrails? ​

OTPGuardrails = DEFAULT_GUARDRAILS

Validation guardrails (defaults to RFC recommendations)

Returns ​

void

Throws ​

If tolerance size exceeds MAX_WINDOW

Example ​

ts
validateCounterTolerance(1);        // OK: [0, 1] = 2 checks
validateCounterTolerance(98);       // OK: [0, 98] = 99 checks
validateCounterTolerance(99);       // Throws: exceeds MAX_WINDOW
validateCounterTolerance([0, 1]);   // OK: 2 offsets

Released under the MIT License.