@litert/[email protected]
该文章根据 CC-BY-4.0 协议发表,转载请遵循该协议。
本文地址:https://fenying.net/en/project/litert/otp/v2.0.0/
The TOTP & HOTP implement for Node.JS.
v2.0.0 Changes
- build(project): refactored with supports for full OTP features.
- feat(hotp): added support for other digest algorithms.
- feat(totp): added support for other digest algorithms.
- feat(url): added support for generating OTP URLs.
- feat(cli): added CLI tool for OTP operations.
- build(test): added unit tests for all features.
- build(docs): added full documentation for the library and CLI tool.
Documents
Features
- HOTP (HMAC-based One-Time Password) algorithm implementation.
- TOTP (Time-based One-Time Password) algorithm implementation.
- OTP URL encoding and decoding.
- Command line tool:
- Generating OTP codes.
- Generating OTP URLs.
- Inspecting OTP URLs.
- Customization:
- Digits length from 4 - 10
- TOTP time-step (period)
- Digest algorithms including SHA-1, SHA-256, and SHA-512
Requirements
- TypeScript v5.0.x (Or newer)
- NodeJS v18.x (Or newer)
Installation
1npm i @litert/otp --save
Usage
Use in code
See examples:
Click here 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:
-
Use
npx
to run the CLI without installing it manually.1npx @litert/otp -k 'raw:1234567890' 2 3# Check the help message 4npx @litert/otp --help
-
Install it globally or locally in your project.
1npm i -g @litert/otp 2# or install in local project only 3npm i @litert/otp # -D # if only used in dev environment
Then you can use the
otp
command directly:1npx otp -k 'raw:1234567890'
Click here for more details about the CLI usage.
License
This library is published under Apache-2.0 license.