one-time-pass
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

one-time password (OTP) generator

Zero dependencies 🔐 Node/Browser module for TOTP and HOTP generator based on RFC 6238 and RFC 4226 🗝️

one-time-pass one-time-pass one-time-pass one-time-pass one-time-pass

Usage

generate TOTP

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

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);
})();

Or include it via jsDelivr CDN (UMD):

<script src="https://cdn.jsdelivr.net/npm/one-time-pass/dist/index.umd.js"></script>
<!-- Access via global object : window.OTP -->

window.OTP.generateTOTP("key");

Ressouces

Notes

  • All pull requests are welcome, feel free.

Author

License

GNU GENERAL PUBLIC LICENSE V3

Package Sidebar

Install

npm i one-time-pass

Weekly Downloads

10

Version

1.0.5

License

GPL-3.0-only

Unpacked Size

42.3 kB

Total Files

6

Last publish

Collaborators

  • haikel