Skip to content

otplib API Documentation / @otplib/totp / verifySync

Function: verifySync() ​

verifySync(options): VerifyResult

Defined in: totp/src/index.ts:419

Verify a TOTP 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 ​

TOTPVerifyOptions

TOTP verification options

Returns ​

VerifyResult

Verification result with validity and optional delta

See ​

Throws ​

If the algorithm is invalid or unsupported by the plugin

Throws ​

If HMAC computation fails or the plugin does not support sync operations

Example ​

ts
import { verifySync } from '@otplib/totp';
import { NodeCryptoPlugin } from '@otplib/plugin-crypto-node';

const result = verifySync({
  secret: mySecret,
  token: '123456',
  epochTolerance: 30,
  crypto: new NodeCryptoPlugin(),
});
if (result.valid) {
  console.log(`Token matched at epoch: ${result.epoch}`);
}

Released under the MIT License.