npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ja7ad/otp-js

v1.0.3

Published

Fast and zero-dependency WebAssembly HOTP/TOTP implementation in Go

Readme

🔐 otp-js

WebAssembly-powered One-Time Password (OTP) library with blazing-fast HOTP & TOTP generation and validation using Go — fully accessible from javascript.

✨ Features

  • ✅ TOTP & HOTP code generation
  • 🔐 RFC 4226 / 6238 compliant
  • ⚡️ High performance with Go + WebAssembly
  • 🧪 Fully unit tested with Jest
  • 🔄 Time skew support for validation
  • 📦 Generates otpauth:// URLs for authenticator apps (Google Authenticator, Authy, etc.)
  • 💻 Works in Node.js (browser support via bundler)

📦 Installation

npm i @ja7ad/otp-js

📊 Benchmark Results

Tests were run using Benchmark.js in Node.js with WebAssembly support enabled.

| Algorithm | Ops/sec | Margin of Error | Runs Sampled | |-----------|---------------|-----------------|---------------| | SHA1 | 2,512 ops/sec | ±3.84% | 67 | | SHA256 | 2,480 ops/sec | ±5.00% | 74 | | SHA512 | 2,550 ops/sec | ±2.04% | 75 |

🔍 Memory Used: ~1.4 MB
🚀 Fastest: SHA512 (closely followed by others)


🚀 Usage

1. Initialize the WASM runtime

const initWasm = require("otp-js");

(async () => {
  const otp = await initWasm();

  const code = otp.generateTOTP("JBSWY3DPEHPK3PXP", Math.floor(Date.now() / 1000), "6", "SHA1", 30);
  console.log("TOTP:", code);
})();

📚 API Reference

generateHOTP(secret, counter, digits, algorithm)

Generate a counter-based HOTP code.

  • secret (string) – Base32-encoded secret key
  • counter (number) – Counter value (int64)
  • digits (string) – OTP length: "6", "8", etc.
  • algorithm (string) – Hash algorithm: "SHA1", "SHA256", or "SHA512"

generateTOTP(secret, timestamp, digits, algorithm, period)

Generate a time-based TOTP code.

  • secret (string) – Base32-encoded secret
  • timestamp (number) – UNIX timestamp
  • digits (string) – OTP length
  • algorithm (string) – Algorithm name
  • period (number) – Time step in seconds (default: 30)

validateHOTP(secret, code, counter, digits, algorithm, skew)

Validate an HOTP code with optional skew.

  • code – The OTP to validate
  • skew (number) – Max allowed counter window (+/-)

Returns: true, false, or "error: ..."


validateTOTP(secret, code, timestamp, digits, algorithm, period, skew)

Validate a TOTP code.

  • timestamp – Current UNIX time
  • skew – Allowed time step window (±skew * period)

Returns: true, false, or "error: ..."


generateOTPURL(otpType, issuer, accountName, secret, digits, algorithm)

Generates a TOTP or HOTP otpauth:// URL.

Example:

const url = otp.generateOTPURL(
  "totp",
  "GitHub",
  "[email protected]",
  "JBSWY3DPEHPK3PXP",
  "6",
  "SHA1"
);
console.log(url); // otpauth://totp/GitHub:[email protected]?...

🧪 Running Tests

npm test

Running Benchmark

npm run benchmark