otplib API Documentation / @otplib/hotp / verifySync
Function: verifySync()
verifySync(
options):VerifyResult
Defined in: hotp/src/index.ts:306
Verify an HOTP code synchronously
This is the synchronous version of verify. It requires a crypto plugin that supports synchronous HMAC operations (e.g., NodeCryptoPlugin or NobleCryptoPlugin). Using this with WebCryptoPlugin will throw an error.
Parameters
options
HOTP verification options
Returns
Verification result with validity and optional delta
See
- verify for the async version
- RFC 4226 Section 7.2
Throws
If the crypto plugin doesn't support sync operations
Example
ts
import { verifySync } from '@otplib/hotp';
import { NodeCryptoPlugin } from '@otplib/plugin-crypto-node';
const result = verifySync({
secret: new Uint8Array([1, 2, 3, 4, 5]),
counter: 0,
token: '123456',
crypto: new NodeCryptoPlugin(),
});
// Returns: { valid: true, delta: 0 }