1.0.0 • Published 11 months ago

totp-generator v1.0.0

Weekly downloads
11,606
License
MIT
Repository
github
Last release
11 months ago

totp-generator

Test Test Coverage npm Version

totp-generator lets you generate TOTP tokens from a TOTP key

How to use

import { TOTP } from "totp-generator"

// Keys provided must be base32 strings, ie. only containing characters matching (A-Z, 2-7, =).
const { otp, expires } = TOTP.generate("JBSWY3DPEHPK3PXP")

console.log(otp) // prints a 6-digit time-based token based on provided key and current time

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) // prints an 8-digit token

const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { algorithm: "SHA-512" })
console.log(token) // prints a token created using a different algorithm

const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { period: 60 })
console.log(token) // prints a token using a 60-second epoch interval

const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", { timestamp: 1465324707000 })
console.log(token) // prints a token for given time

const { otp } = TOTP.generate("JBSWY3DPEHPK3PXP", {
	digits: 8,
	algorithm: "SHA-512",
	period: 60,
	timestamp: 1465324707000,
})
console.log(token) // prints a token using all custom settings combined

What do I use this library for?

  • TOTP generation
  • E2E tests (where you need to login with 2-factor authentication)
1.0.0

11 months ago

1.0.0-beta-1

11 months ago

1.0.0-beta-2

11 months ago

1.0.0-beta-3

11 months ago

1.0.0-beta-0

11 months ago

0.0.14

2 years ago

0.0.13

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

5 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago