https://github.com/litert/otp.js
The TOTP & HOTP implement for Node.JS.
https://github.com/litert/otp.js
2fa hotp otp otpauth password totp
Last synced: 4 months ago
JSON representation
The TOTP & HOTP implement for Node.JS.
- Host: GitHub
- URL: https://github.com/litert/otp.js
- Owner: litert
- License: apache-2.0
- Created: 2019-12-20T16:43:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2026-03-11T06:29:56.000Z (5 months ago)
- Last Synced: 2026-03-18T22:11:08.377Z (5 months ago)
- Topics: 2fa, hotp, otp, otpauth, password, totp
- Language: TypeScript
- Homepage: https://litert.org/projects/otp.js/
- Size: 433 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# LiteRT/OTP
[](https://www.typescriptlang.org)
[](https://www.npmjs.com/package/@litert/otp "Stable Version")
[](https://github.com/litert/otp/blob/master/LICENSE)
[](https://github.com/litert/otp.js/issues)
[](https://github.com/litert/otp.js/releases "Stable Release")
The TOTP & HOTP implement for Node.JS.
## Features
- [x] HOTP (HMAC-based One-Time Password) algorithm implementation.
- [x] TOTP (Time-based One-Time Password) algorithm implementation.
- [x] OTP URL encoding and decoding.
- [x] Command line tool:
- [x] Generating OTP codes.
- [x] Generating OTP URLs.
- [x] Inspecting OTP URLs.
- [x] Customization:
- [x] Digits length from 4 - 10
- [x] TOTP time-step (period)
- [x] Digest algorithms including SHA-1, SHA-256, and SHA-512
## Requirements
- TypeScript v3.1.x (Or newer)
## Installation
```sh
npm i @litert/otp --save
```
## Usage
### Use in code
See examples:
- [HOTP](./src/examples/hotp.ts)
- [TOTP](./src/examples/totp.ts)
Click [here](./docs/en-us/quick-start.md) for a quick start guide.
### Use as a command line tool
You can use this library as a command line tool to do OTP operations.
There are two ways to use the CLI:
1. Use `npx` to run the CLI without installing it manually.
```sh
npx @litert/otp -k 'raw:1234567890'
# Check the help message
npx @litert/otp --help
```
2. Install it globally or locally in your project.
```sh
npm i -g @litert/otp
# or install in local project only
npm i @litert/otp # -D # if only used in dev environment
```
Then you can use the `otp` command directly:
```sh
npx otp -k 'raw:1234567890'
```
Click [here](./docs/en-us/cli-usage.md) for more details about the CLI usage.
## Documents
- [en-US](https://litert.org/projects/otp.js/)
## License
This library is published under [Apache-2.0](./LICENSE) license.