CLI tool
yeojz/otplib avatar
yeojz/otplib

otplib v13: a TOTP and HOTP library rebuilt around async calls and swappable crypto plugins

One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator

2,310 stars147 forksTypeScriptMIT

At a glance

What is it?
otplib generates and verifies one-time passwords for Node, Bun, Deno and browsers. Version 13 is a rewrite that removed the separate authenticator package, made calls async by default, and moved cryptography into plugins. This review covers what changed, what the packages split into, and what the README does not specify.
Who is it for?
otplib suits JavaScript and TypeScript developers who need to generate or check RFC 6238 and RFC 4226 codes in more than one runtime and want to choose the cryptography underneath. It is a poor fit for anyone upgrading from v12 on a deadline, since v13 breaks the API and removes the authenticator package.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 22 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • yeojz/otplib2,310 ★ · +15
Star history
Repository2026-10-142026-11-25
yeojz/otplib2.3k2.3k

15 Stars in the last 42 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Version 13 removed the authenticator package and the legacy crypto adapters

The README opens its important note with a blunt line: v13 is a complete rewrite with breaking changes. Two removals are named. The separate authenticator package is gone, because TOTP now covers all authenticator functionality with the default plugins. The outdated plugins are gone too, meaning legacy crypto adapters were dropped in favor of modern, audited alternatives.

For a project that imports the old authenticator package, this is a code change and not a version bump. The README points to a migration guide at otplib.yeojz.dev/guide/v12-adapter.html for details, and the page name suggests a v12 adapter exists, though the README does not describe it.

A detail in the repository can confuse tooling. The root package.json is named otplib-repo, marked private, and carries version 12.0.1, while the releases are v13.5.0, v13.4.1 and v13.4.0. The root manifest is a workspace shell and not the published package, so read versions from npm or the releases list.

Four calls cover secret creation, code generation, verification and URIs

The quick start imports four functions from the otplib package: generateSecret, generate, verify and generateURI. The sample creates a secret, produces a TOTP token with generate({ secret }), and checks it with verify({ secret, token }), logging result.valid.

typescript
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

Two things stand out. The calls are awaited, since the library is async-first, and verify returns an object with a valid field and not a bare boolean. An object is truthy in JavaScript whatever valid says, so an if statement written as if verify returned a boolean would accept every token. Read each call site that checks a result when you upgrade, and test with a wrong token as well as a right one. generateURI is imported but never shown in use, so the README leaves the shape of its options to the guide.

Async by default, with sync variants only where the plugin allows

The README states that all operations are async by default and that sync variants are available for compatible plugins. The reason is visible in the browser: the Web Crypto API hashes asynchronously, so a design that must run in browsers cannot assume a synchronous HMAC. A Node-only crypto plugin can still offer a sync path, and the package list includes @otplib/plugin-crypto-node alongside @otplib/plugin-crypto-web and @otplib/plugin-crypto-noble.

The consequence is a split in what you can promise callers. If you write code that must run on every runtime, treat verification as async everywhere. If you choose a sync-capable plugin, a sync call works only with that plugin, and swapping to another plugin later breaks it.

The README does not say which plugins are sync-capable or what the sync function names are. That detail lives in the guide and the API reference, so check them before building a sync code path.

A monorepo of ten packages, split by RFC and by plugin

The packages table lists ten npm packages. otplib is the main entry. @otplib/core is the shared base. @otplib/totp and @otplib/hotp implement the two algorithms from RFC 6238 and RFC 4226, and @otplib/uri handles the otpauth style links used by authenticator apps. Four plugins cover the cryptographic and base32 needs: @otplib/plugin-base32-scure, @otplib/plugin-crypto-noble, @otplib/plugin-crypto-node and @otplib/plugin-crypto-web. otplib-cli is a command-line package.

The split lets a small project depend on only the pieces it needs, such as @otplib/hotp plus a single crypto plugin. The README does not publish bundle sizes, but the root package.json has size and size:check scripts that run a build and a check-size.mjs script, so the project measures them itself.

Build tooling is Turbo with pnpm workspaces, formatting is oxfmt, and linting is oxlint, with lefthook installed on postinstall. These matter only if you contribute.

Audited defaults: @noble/hashes for hashing and @scure/base for base32

By default, the cryptography comes from @noble/hashes and the base32 encoding from @scure/base. The README says both are independently audited, and presents that as the reason the plugin set was rebuilt. This is a statement about the dependencies. It says nothing about an audit of otplib's own code.

A SECURITY.md file sits at the top level, and the documentation menu includes a Security Considerations guide. The package.json has an audit script that runs pnpm audit --prod --audit-level=moderate, and its release scripts publish with the --provenance flag, so published tarballs carry build provenance.

Plugins are the way out of the defaults. If your platform requires a particular crypto implementation, the README says the plugin interface lets you deviate from the defaults for both cryptographic and base32 requirements. Writing your own plugin means implementing that interface, whose contract is documented in the guide, not in the README.

Zero configuration means defaults you have not chosen

The README advertises zero configuration: it works out of the box with sensible defaults. That is convenient for a prototype and a risk for a production login flow, because the defaults are decisions made for you. The README text does not list the digit count, the time step, the hash algorithm or the accepted time window, so the quick start gives no way to confirm them.

The library claims RFC compliance with RFC 6238 for TOTP and RFC 4226 for HOTP, plus Google Authenticator compatibility. Compatibility with the app is a practical test you can run yourself: the project hosts a web demo at otplib.yeojz.dev where you scan sample TOTP and HOTP QR codes with your own authenticator app.

What the README leaves out is the part that decides whether users get locked out: how far the clock may drift, whether verify rejects a reused token, and whether it limits repeated guesses. Those are documented, if at all, in the guide and API reference. Replay protection and rate limiting are application concerns that the README does not claim to handle.

Runtime coverage is tested in CI scripts for Bun and Deno, and AI assistance is disclosed

Cross-platform support is stated as tested against Node.js, Bun, Deno and browsers. The package.json backs that with distribution test scripts such as test:dist-bun, which runs bun test on a file under internal/distribution-tests, and a Deno counterpart that runs deno test. The repository also has a deno.json and a deno.lock. Deno users install with deno install npm:otplib, and Bun users with bun add otplib.

Node users have three package manager lines, all for the same package:

bash
npm install otplib
pnpm add otplib
yarn add otplib

The README includes an AI usage disclosure. Since v13, parts of the codebase, tests and documentation have been refined with AI assistance, and all outputs were reviewed by humans. CONTRIBUTING.md carries the guidelines. For a security library this is useful to know, and reading the test suite for the verify path is the proportionate response.

The latest release in the list is v13.5.0 from 2026-08-21, and the last push was on 2026-10-25. The two releases before it, v13.4.1 on 2026-05-30 and v13.4.0 on 2026-03-19, show a release every few months since the rewrite, with the license staying MIT throughout. The package.json also defines bench scripts for base32, hotp, totp and utils, so the project keeps benchmarks in the repository, though the README prints no results from them.

Editorial conclusion

otplib suits JavaScript and TypeScript developers who need to generate or check RFC 6238 and RFC 4226 codes in more than one runtime and want to choose the cryptography underneath. It is a poor fit for anyone upgrading from v12 on a deadline, since v13 breaks the API and removes the authenticator package. Before adopting it, read the migration guide, then check how your verify call handles clock drift, because the README shows only the default call.

Frequently asked questions

What is otplib?

otplib is a TypeScript-first library for HOTP and TOTP codes with Google Authenticator compatibility. It runs on Node, Bun, Deno and browsers through plugins.

How do I install otplib?

Run npm install otplib, pnpm add otplib or yarn add otplib for Node. Bun uses bun add otplib and Deno uses deno install npm:otplib.

Is otplib v13 compatible with v12?

No. The README calls v13 a complete rewrite with breaking changes, including removal of the separate authenticator package. A migration guide is linked from the README.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. yeojz/otplib on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/yeojz-otplib.svg)](https://hysenlabs.com/projects/yeojz-otplib)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/yeojz-otplib.svg)](https://hysenlabs.com/projects/yeojz-otplib)

Was this useful?