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

one-time-jwt

v1.0.0

Published

One-Time JWT is a TypeScript library for creating and verifying one-time JSON Web Tokens (JWTs) with an associated One-Time Password (OTP). It is designed to provide secure, purpose-specific tokens for authentication and other use cases.

Downloads

4

Readme

One-Time JWT

One-Time JWT is a TypeScript library for creating and verifying one-time JSON Web Tokens (JWTs) with an associated One-Time Password (OTP). It is designed to provide secure, purpose-specific tokens for authentication and other use cases.

Features

  • Generate one-time JWTs with customizable OTPs.
  • Verify JWTs using the associated OTP.
  • Support for various OTP types (digits, letters, alphanumeric, base64).
  • Configurable logging and token options.
  • Safe methods for error handling during token creation and verification.

Installation

Install the package using npm:

npm install one-time-jwt

Or using Bun:

bun add one-time-jwt

Usage

Importing the Library

import OneTimeJwt from 'one-time-jwt'

Creating a Token

const jwt = new OneTimeJwt('baseSecret')
const result = await jwt.createToken(
  'login',
  { userId: 123 },
  { otpType: 'numeric', otpLength: 6 }
)
console.log(result.token, result.otp)

Verifying a Token

const payload = await jwt.verifyToken('login', result.token, result.otp)
console.log(payload)

Safe Methods

Safe methods handle errors gracefully and return a tuple with the result or an error.

Safe Create Token

const [result, error] = await jwt.safeCreateToken('login', { userId: 123 })
if (error) {
  console.error(error)
} else {
  console.log(result.token, result.otp)
}

Safe Verify Token

const [payload, error] = await jwt.safeVerifyToken(
  'login',
  result.token,
  result.otp
)
if (error) {
  console.error(error)
} else {
  console.log(payload)
}

Configuration

The OneTimeJwt class accepts a baseSecret and an optional configuration object:

const jwt = new OneTimeJwt('baseSecret', {
  logLevel: 'debug',
  secretDivider: '::',
  maxTokenLimitPerPurpose: 5,
})

Options

  • logLevel: Logging level (debug, info, warn, error, silent).
  • secretDivider: String used to separate components of the secret.
  • maxTokenLimitPerPurpose: Maximum number of tokens allowed per purpose.

OTP Types

The library supports the following OTP types:

  • digits: Numeric OTP.
  • base64: Base64 OTP.
  • letters: Alphabetic OTP (mixed case).
  • letters-upper: Uppercase alphabetic OTP.
  • letters-lower: Lowercase alphabetic OTP.
  • alphanumeric: Alphanumeric OTP (mixed case).
  • alphanumeric-upper: Uppercase alphanumeric OTP.
  • alphanumeric-lower: Lowercase alphanumeric OTP.

Error Handling

The library provides custom error classes for better error handling:

  • InvalidTokenError
  • InvalidOTPError
  • IncorrectOTPError
  • InvalidPurposeError
  • UnknownError

Testing

Run the tests using Bun:

bun test

License

This project is licensed under the MIT License.