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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@antmind/otp

v0.1.0

Published

OTP (One-Time Password) library for Node.js and browsers.

Downloads

97

Readme

@antmind/otp

A small, dependency-free TypeScript library for generating and verifying one-time passwords (OTP): HOTP and TOTP.

Features

  • RFC 4226 compliant HOTP
  • RFC 6238 compliant TOTP
  • Supports SHA-1, SHA-256, and SHA-512 hashing algorithms
  • Configurable code length
  • URI generation for easy integration with authenticator apps
  • Compatible with Google Authenticator and similar apps
  • Node.js and browser compatible
  • Simple API with TypeScript types

Install

Run the following command to install the package:

npm install @antmind/otp

Getting Started

TOTP is time-based and defined by the HOTP of a time counter. Common parameters are a time step (X) and start time T0.

The time counter is

$$ T = \left\lfloor \frac{\text{UnixTime} - T_0}{X} \right\rfloor $$

Generate and verify a TOTP:

import { TOTP } from '@antmind/otp'

const secret = '12345678901234567890';
const digits = 6;
const step = 30; // seconds

const totp = new TOTP({ digits, period: step });
const code = await totp.generate(secret);
console.log('TOTP:', code);

const valid = await totp.verify(secret, code);
console.log('valid:', valid)

Adjust step and digits to match the authenticator you are using.

API reference

  • class TOTP: TOTP generator and verifier class.
    • generate(secret: string, time?: number): Promise<string>: Generates a TOTP code for the given secret and time, defaulting to the current time.
    • verify(secret: string, token: string, time?: number): Promise<boolean>: Verifies a TOTP code for the given secret and time.
    • getURI(secret: string, account: string): string: Generates an otpauth URI for the TOTP configuration.
  • class HOTP: HOTP generator and verifier class.
    • generate(secret: string, counter: number): Promise<string>: Generates an HOTP code for the given secret and counter.
    • verify(secret: string, counter: number, token: string): Promise<boolean>: Verifies an HOTP code for the given secret and counter.
    • getURI(secret: string, account: string, counter?: number): string: Generates an otpauth URI for the HOTP configuration.

Testing

Run the test suite with:

npm test

Unit tests are located in the tests/ folder and use Jest.

Contributing

Contributions are welcome. Please follow these steps:

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feat/my-feature.
  3. Implement your changes and tests.
  4. Run npm run build and npm test.
  5. Open a pull request describing your changes.

Please keep changes small and focused. If you plan larger changes, open an issue first to discuss the design.

License

This project is open-sourced under the terms of the MIT License. See the LICENSE file for details.