Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bellstrand/totp-generator
Generate TOTP tokens from key
https://github.com/bellstrand/totp-generator
totp-tokens
Last synced: 4 days ago
JSON representation
Generate TOTP tokens from key
- Host: GitHub
- URL: https://github.com/bellstrand/totp-generator
- Owner: bellstrand
- License: mit
- Created: 2016-06-07T13:01:09.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T07:52:49.000Z (about 1 month ago)
- Last Synced: 2024-12-30T05:11:57.221Z (10 days ago)
- Topics: totp-tokens
- Language: TypeScript
- Size: 586 KB
- Stars: 256
- Watchers: 3
- Forks: 39
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# totp-generator
[![Test](https://github.com/bellstrand/totp-generator/workflows/Test/badge.svg)](https://github.com/bellstrand/totp-generator/actions?query=workflow%3ATest)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5ea846f544cbf46ffcee/test_coverage)](https://codeclimate.com/github/bellstrand/totp-generator/test_coverage)
[![npm Version](https://img.shields.io/npm/v/totp-generator.svg)](https://www.npmjs.com/package/totp-generator)totp-generator lets you generate TOTP tokens from a TOTP key
## How to use
```javascript
import { TOTP } from "totp-generator"// Keys provided must be base32 strings, ie. only containing characters matching (A-Z, 2-7, =).
const { otp, expires } = await 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:
```javascript
import { TOTP } from "totp-generator"const { otp } = await TOTP.generate("JBSWY3DPEHPK3PXP", { digits: 8 })
console.log(otp) // prints an 8-digit tokenconst { otp } = await TOTP.generate("JBSWY3DPEHPK3PXP", { algorithm: "SHA-512" })
console.log(otp) // prints a token created using a different algorithmconst { otp } = await TOTP.generate("JBSWY3DPEHPK3PXP", { period: 60 })
console.log(otp) // prints a token using a 60-second epoch intervalconst { otp } = await TOTP.generate("JBSWY3DPEHPK3PXP", { timestamp: 1465324707000 })
console.log(otp) // prints a token for given timeconst { otp } = await TOTP.generate("JBSWY3DPEHPK3PXP", {
digits: 8,
algorithm: "SHA-512",
period: 60,
timestamp: 1465324707000,
})
console.log(otp) // 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)