One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
See the codeTypeScript-first library for HOTP and TOTP / Authenticator with multi-runtime (Node, Bun, Deno, Browser) support via plugins.
[!TIP]
A web based demo is available at https://otplib.yeojz.dev.
You can scan and test the TOTP / HOTP QR Code samples with your chosen authenticator app.
@noble/hashes and @scure/base, both independently audited[!IMPORTANT]
v13 is a complete rewrite with breaking changes. For example:
- (Removed) Separate authenticator package — TOTP now covers all authenticator functionality with default plugins
- (Removed) Outdated plugins — Legacy crypto adapters removed in favor of modern, audited alternatives
See Migration Guide for details.
# Node
npm install otplib
pnpm add otplib
yarn add otplib
# Other runtimes
bun add otplib
deno install npm:otplib
import { generateSecret, generate, verify, generateURI } from "otplib";
// Generate a secret
const secret = generateSecret();
// Generate a TOTP token
const token = await generate({ secret });
// Verify a token
const result = await verify({ secret, token });
console.log(result.valid); // true
| Package | Version | Downloads |
|---|---|---|
otplib | ||
@otplib/core | ||
@otplib/totp | ||
@otplib/hotp | ||
@otplib/uri | ||
@otplib/plugin-base32-scure | ||
@otplib/plugin-crypto-noble | ||
@otplib/plugin-crypto-node | ||
@otplib/plugin-crypto-web | ||
otplib-cli |
Refer to the Getting Started Guide, or check out the other sections in the guide:
See CONTRIBUTING.md for development setup and guidelines.
Since v13, parts of the codebase, tests, and documentation have been refined with AI assistance, with all outputs reviewed by humans. See CONTRIBUTING.md for guidelines.
Overall
Maintained
Code review
npm
Latest release
Releases this year
510 followers · starred Jan 2026
6,235 followers · starred May 2020
359 followers · starred May 2020
135 followers · starred Jun 2020
One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator
See the codeTypeScript-first library for HOTP and TOTP / Authenticator with multi-runtime (Node, Bun, Deno, Browser) support via plugins.
[!TIP]
A web based demo is available at https://otplib.yeojz.dev.
You can scan and test the TOTP / HOTP QR Code samples with your chosen authenticator app.
@noble/hashes and @scure/base, both independently audited[!IMPORTANT]
v13 is a complete rewrite with breaking changes. For example:
- (Removed) Separate authenticator package — TOTP now covers all authenticator functionality with default plugins
- (Removed) Outdated plugins — Legacy crypto adapters removed in favor of modern, audited alternatives
See Migration Guide for details.
# Node
npm install otplib
pnpm add otplib
yarn add otplib
# Other runtimes
bun add otplib
deno install npm:otplib
import { generateSecret, generate, verify, generateURI } from "otplib";
// Generate a secret
const secret = generateSecret();
// Generate a TOTP token
const token = await generate({ secret });
// Verify a token
const result = await verify({ secret, token });
console.log(result.valid); // true
| Package | Version | Downloads |
|---|---|---|
otplib | ||
@otplib/core | ||
@otplib/totp | ||
@otplib/hotp | ||
@otplib/uri | ||
@otplib/plugin-base32-scure | ||
@otplib/plugin-crypto-noble | ||
@otplib/plugin-crypto-node | ||
@otplib/plugin-crypto-web | ||
otplib-cli |
Refer to the Getting Started Guide, or check out the other sections in the guide:
See CONTRIBUTING.md for development setup and guidelines.
Since v13, parts of the codebase, tests, and documentation have been refined with AI assistance, with all outputs reviewed by humans. See CONTRIBUTING.md for guidelines.
Overall
Maintained
Code review
npm
Latest release
Releases this year
510 followers · starred Jan 2026
6,235 followers · starred May 2020
359 followers · starred May 2020
135 followers · starred Jun 2020