OTPAuth

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

Library
npm
v9.5.1
1,470stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
57/100Fair
Development Activity36
Maintenance44
Community48
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture80
Code Quality78
Innovation68
Learning Curve75

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
75%
GPL 3.0

Bramble

Password Manager · Security · Authentication

315

Local-first, end-to-end encrypted password manager that syncs your vault directly between your own devices over a private peer-to-peer mesh — no server, no account, no cloud in the middle.

View details
73
Repo Health
84
Technical
72
Dependency
Built with
TypeScript75%
Updated today
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,041

Open-source reporting platform to build live dashboards from SQL, NoSQL, APIs, and SaaS tools with an AI assistant that creates charts from natural language.

View details
90
Repo Health
83
Technical
65
Dependency
Built with
JavaScript99%
Updated 6 days ago
TypeScript
95%
AGPL 3.0

Docmost

Productivity · Note Taking · Collaboration

21,411

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
71
Dependency
Built with
TypeScript95%
Updated yesterday
Clojure
54%
Other

Metabase

Analytics

48,828

The open-source BI platform that lets anyone ask questions and build dashboards without writing SQL — with an embedded analytics SDK and AI-powered query assistant included.

View details
95
Repo Health
84
Technical
65
Dependency
Built with
Clojure54%
TypeScript40%
Updated today
TypeScript
92%
Other

n8n

Automation · No Code Platforms

201,152

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
66
Dependency
Built with
TypeScript92%
Updated today
TypeScript
96%
Other

nango

Developer Tools · Automation · Authentication

11,501

Build product integrations with AI using 800+ APIs — auth, proxy, and TypeScript functions on production-grade infrastructure.

View details
94
Repo Health
85
Technical
69
Dependency
Built with
TypeScript96%
Updated today
TypeScript
92%
Apache 2.0

OneUptime

Monitoring

7,481

The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.

View details
90
Repo Health
81
Technical
66
Dependency
Built with
TypeScript92%
Updated today
Go
91%
Apache 2.0

Ory Kratos

Authentication

13,833

API-first identity and user management that handles login, registration, MFA, and recovery so your application never has to.

View details
85
Repo Health
78
Technical
69
Dependency
Built with
Go91%
Updated 3 weeks ago
JavaScript
98%
Apache 2.0

Parse Server

Developer Tools · Databases

21,409

Self-hosted Backend-as-a-Service for Node.js with REST, GraphQL, real-time Live Query, cloud code, and pluggable adapters for any infrastructure.

View details
96
Repo Health
81
Technical
78
Dependency
Built with
JavaScript98%
Updated 1 weeks 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

Search