otplib API Documentation / @otplib/hotp / generateSync
Function: generateSync()
generateSync(
options):string
Defined in: hotp/src/index.ts:132
Generate an HMAC-based One-Time Password (HOTP) synchronously
This is the synchronous version of generate. 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 generation options
Returns
string
The HOTP code as a string
See
- generate for the async version
- RFC 4226 Section 5.3
Throws
If the crypto plugin doesn't support sync operations
Example
ts
import { generateSync } from '@otplib/hotp';
import { NodeCryptoPlugin } from '@otplib/plugin-crypto-node';
const hotp = generateSync({
secret: new Uint8Array([1, 2, 3, 4, 5]),
counter: 0,
digits: 6,
crypto: new NodeCryptoPlugin(),
});
// Returns: '123456'