Skip to content

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

HOTPVerifyOptions

HOTP verification options

Returns

VerifyResult

Verification result with validity and optional delta

See

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 }

Released under the MIT License.