otplib API Documentation / @otplib/core / validateCounterTolerance
Function: validateCounterTolerance()
validateCounterTolerance(
counterTolerance,guardrails):void
Defined in: packages/core/src/utils.ts:356
Validate counter tolerance for HOTP verification
Prevents DoS attacks by limiting the number of counter values checked.
Parameters
counterTolerance
Counter tolerance specification (number or array of offsets)
number | number[]
guardrails
OTPGuardrails = DEFAULT_GUARDRAILS
Validation guardrails (defaults to RFC recommendations)
Returns
void
Throws
If tolerance size exceeds MAX_WINDOW
Example
ts
validateCounterTolerance(1); // OK: 3 offsets [-1, 0, 1]
validateCounterTolerance(100); // OK: 201 offsets [-100, ..., 100]
validateCounterTolerance(101); // Throws: exceeds MAX_WINDOW
validateCounterTolerance([0, 1]); // OK: 2 offsets