OTPAuth

HOTP and TOTP one-time password library for Node.js, Deno, Bun, and browsers

Library
npm
v9.5.2
1,488 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
69 /100 Good
Development Activity 64
Maintenance 64
Community 48
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 80
Code Quality 78
Innovation 68
Learning Curve 75

OTPAuth is a zero-dependency-friendly One Time Password library implementing HMAC-based (HOTP, RFC 4226) and time-based (TOTP, RFC 6238) one-time passwords, the algorithms behind most two-factor authentication (2FA) and multi-factor authentication (MFA) flows. It runs across Node.js, Deno, Bun, and browsers via ESM, CommonJS, and UMD builds, and ships slim and bare variants so consumers can swap in their own HMAC implementation or drop the bundled crypto entirely.

The library covers the full lifecycle of an OTP credential: generating cryptographically secure secrets, producing and validating tokens with a configurable search window, computing time-to-expiry, and converting to and from the otpauth:// key URI format used by Google Authenticator and compatible apps (typically encoded as a QR code during enrollment). Its small, dependency-light surface and RFC-compliant defaults make it a common choice for adding 2FA to authentication systems without hand-rolling the underlying HMAC/counter math.

What You Get

  • HOTP and TOTP classes with a shared config shape (issuer, label, algorithm, digits, secret) for generating and validating one-time passwords
  • A Secret class that generates cryptographically secure random keys and converts between Base32, Hex, Latin-1, and UTF-8 encodings
  • Token validation with a configurable search window to tolerate clock drift between client and server, returning a delta rather than a plain boolean
  • URI.stringify/URI.parse for converting to and from the otpauth:// key URI format used by Google Authenticator and compatible apps
  • Three build variants — full (bundled @noble/hashes crypto), slim (no bundled dependencies), and bare (bring-your-own HMAC function) — published as ESM, CommonJS, and UMD

Common Use Cases

  • Adding TOTP-based two-factor authentication (2FA) to a login flow, with QR-code enrollment via the otpauth:// URI format
  • Building an authenticator app or browser extension that generates rotating 6-digit codes for multiple accounts
  • Implementing server-side HOTP/TOTP verification with a tolerance window to accept slightly out-of-sync client clocks
  • Running one shared OTP implementation across a Node.js backend, a Deno/Bun service, and a browser-based client without swapping libraries

Under The Hood

Architecture — The library is organized as four small public classes (HOTP, TOTP, Secret, URI) exported from src/index.js, backed by an internal/ layer that isolates environment-specific and cryptographic concerns: internal/crypto/hmac-digest.js wraps HMAC computation (via the bundled @noble/hashes in the default build, or a caller-supplied function in the bare build), internal/crypto/random-bytes.js and internal/crypto/timing-safe-equal.js handle secure randomness and constant-time comparison, and internal/encoding/*.js provides Base32/Hex/Latin-1/UTF-8/uint codecs used by Secret and the token algorithms. TOTP is implemented as a thin wrapper that derives an HOTP counter from the current time and period, then delegates to HOTP’s generate/validate logic, keeping the RFC 4226 math in one place.

Tech Stack — Plain JavaScript (no TypeScript source; hand-written JSDoc types compiled to .d.ts/.d.cts via tsc), built with Rollup into ESM/CJS/UMD bundles for Node.js, Deno, Bun, and browsers. The only runtime dependency is @noble/hashes for HMAC/SHA implementations, and even that is optional in the slim/bare export variants. Tooling includes ESLint, Prettier, TypeDoc, and Mocha/Chai-based tests run across Node (ESM+CJS), Deno, Bun, and Playwright-driven browser engines (Chromium, Firefox, WebKit).

Code Quality — Test coverage is broad in surface (dedicated suites per runtime: node.test.mjs/.cjs, deno.test.mjs, bun.test.mjs, browser.test.mjs, quickjs.test.mjs, each with minified-build variants) though the actual assertions live in a single shared test/test.mjs. Source files are consistently documented with JSDoc typing every public method and property, class fields use Object.defineProperty to enforce immutability where appropriate (e.g. Secret.bytes), and the linting pipeline (eslint --max-warnings 0, strict tsc --noEmit against the JSDoc types) enforces a zero-warning, type-checked bar on every change.

API Design — The public API is deliberately narrow: constructors take a single options object with sensible RFC-aligned defaults (SHA1, 6 digits, 30s period), generate()/validate() are the only methods most consumers need, and toString()/URI.parse() round-trip cleanly with authenticator-app QR codes. Choosing between the full, slim, and bare builds via subpath exports (otpauth, otpauth/slim, otpauth/bare) is a deliberate, low-boilerplate way to control bundle size and crypto dependencies without changing calling code.

Used by 15 apps in this directory

TypeScript
91%
AGPL 3.0

PeerTube

Social Media

15,362

A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.

View details
96
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 91%
Updated 1 weeks ago
TypeScript
64%
AGPL 3.0

Puter

Developer Tools · File Storage

43,864

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 64%
JavaScript 33%
Updated 5 days ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

113,827

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript 72%
MDX 26%
Updated 5 days ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 5 days ago
Rust
83%
AGPL 3.0

Vaultwarden

Password Manager · Security

69,556

Unofficial Bitwarden-compatible server in Rust — run the full Bitwarden ecosystem on a Raspberry Pi using every official client you already have, without the multi-container overhead.

View details
89
Repo Health
69
Technical
69
Dependency
Built with
Rust 83%
Updated 1 weeks ago
TypeScript
80%
AGPL 3.0

VoidAuth

Authentication · Security

2,889

Self-hosted SSO with OIDC, LDAP, passkeys, and proxy auth for your entire self-hosted stack

View details
83
Repo Health
77
Technical
72
Dependency
Built with
TypeScript 80%
HTML 14%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers