totp-generator
totp-generator lets you generate TOTP tokens from a TOTP key
How to use
import { TOTP } from "totp-generator"
const { otp, expires } = TOTP.generate("JBSWY3DPEHPK3PXP")
console.log(otp)
Default token settings
- SHA-1
- 30-second epoch interval
- 6-digit tokens
Custom token settings
Settings can be provided as an optional second parameter:
import { TOTP } from "totp-generator"
const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { digits: 8 })
console.log(token)
const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { algorithm: "SHA-512" })
console.log(token)
const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { period: 60 })
console.log(token)
const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { timestamp: 1465324707000 })
console.log(token)
const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", {
digits: 8,
algorithm: "SHA-512",
period: 60,
timestamp: 1465324707000,
})
console.log(token)
What do I use this library for?
- TOTP generation
- E2E tests (where you need to login with 2-factor authentication)