otplib API Documentation / otplib / functional / generateSync
Function: generateSync()
generateSync(
options):string
Defined in: packages/otplib/src/functional.ts:264
Generate an OTP code synchronously
This is the synchronous version of generate. It requires a crypto plugin that supports synchronous HMAC operations.
Parameters
options
OTP generation options
Returns
string
OTP code
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 { generateSync } from 'otplib';
const token = generateSync({
secret: 'JBSWY3DPEHPK3PXP',
});