https://github.com/haikelfazzani/otp
🔐 Zero dependencies Deno/Bun/Node/Browser module for TOTP and HOTP generator based on RFC 6238 and RFC 4226 🗝️
https://github.com/haikelfazzani/otp
2fa browser bun cryptography deno hotp nodejs one-time-password otp rfc-6238 rfc4226 security totp web-crypto web-cryptography-api
Last synced: 5 months ago
JSON representation
🔐 Zero dependencies Deno/Bun/Node/Browser module for TOTP and HOTP generator based on RFC 6238 and RFC 4226 🗝️
- Host: GitHub
- URL: https://github.com/haikelfazzani/otp
- Owner: haikelfazzani
- License: gpl-3.0
- Created: 2024-05-23T10:34:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-14T12:44:17.000Z (about 1 year ago)
- Last Synced: 2025-04-24T22:58:42.252Z (6 months ago)
- Topics: 2fa, browser, bun, cryptography, deno, hotp, nodejs, one-time-password, otp, rfc-6238, rfc4226, security, totp, web-crypto, web-cryptography-api
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/one-time-pass
- Size: 31.3 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# one-time password (OTP) generator
🔐 Deno/Bun/Node/Browser module for TOTP and HOTP generator based on
RFC 6238 and RFC 4226 🗝️- Zero dependencies: Works seamlessly across different environments without requiring additional libraries.
- Supports TOTP and HOTP: Generate both time-based and counter-based one-time passwords
![]()
![]()
![]()
![]()
![]()
Try it out on JSFiddle: [Live Demo](https://jsfiddle.net/HaikelFazzani/e5dz6g2x/2/)
# Install
```
npm i one-time-pass
```# Usage
## Import
```js
import { generateTOTP } from "one-time-pass";
// Deno
import { generateTOTP } from "npm:one-time-pass";
// Nodejs
const { generateTOTP } = require("one-time-pass");// Or include it via CDN
window.otp.generateTOTP("key");
```## Examples
**generate TOTP**
```js
import { generateTOTP } from "one-time-pass";(async () => {
const defaultOptions = {
hash: 'SHA-1',
timeStep: 30, // epoch interval
digits: 6,
timestamp: Date.now()
}const code = await generateTOTP("key", defaultOptions?);
console.log(code);
})();
```**generate HOTP**
```js
import { generateHOTP } from "one-time-pass";(async () => {
const counter = 14653;
const hash = "SHA-1";
const digits = 6;const code = await generateHOTP("secretKey", counter, hash, digits);
console.log(code);
})();
```## Ressouces
- [rfc6238](https://datatracker.ietf.org/doc/html/rfc6238)
- [rfc4226](https://datatracker.ietf.org/doc/html/rfc4226)### Notes
- We welcome pull requests! Feel free to contribute to this project.
### Author
- [Haikel Fazzani](https://github.com/haikelfazzani)
# License
GNU GENERAL PUBLIC LICENSE V3