Node OTP
Node.js One-Time Password library
Features
- Zero Dependency
- TypeScript Definitions
- RFC4226 (HMAC One-Time Password)
- RFC6238 (Time-Based One-Time Password)
Installation
yarn add node-otp
or
npm install --save node-otp
Examples
const { hotp } = require('node-otp')
hotp({
secret: '12345678901234567890',
})
const { totp } = require('node-otp')
totp({
secret: '12345678901234567890',
})
APIs
hotp: (parameters: Parameters) => string
Parameters
secret: string | Buffer
movingFactor?: number
Default value of movingFactor
is 0codeDigits?: number
Default value of codeDigits
is 6addChecksum?: boolean
Default value of addChecksum
is falsetruncationOffset?: number
Default value of truncationOffset
is -1hmacAlgorithm?: 'sha1' | 'sha256' | 'sha512'
Default value of hmacAlgorithm
is sha1totp: (parameters: Parameters) => string
Parameters
secret: string | Buffer
step?: number
Default value of step
is 30time?: number
Default value of time
is 6initialTime?: number
Default value of initialTime
is 0codeDigits?: number
Default value of codeDigits
is 6hmacAlgorithm?: 'sha1' | 'sha256' | 'sha512'
Default value of hmacAlgorithm
is sha256