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

@satyajeetsahoo/otp

v2.1.3

Published

Store-independent secure OTP service for Node.js

Readme

@satyajeetsahoo/otp

A highly secure OTP generation and verification service.

Why use this package?

Storing plain-text OTPs in your database is a severe security risk. This package generates cryptographically secure numeric OTPs and only stores their HMAC hashes in your cache (Redis/Local). It also automatically handles attempt rate-limiting, cooldown periods, and expiration, ensuring your authentication flows are virtually impenetrable to brute-force attacks.

Features

  • Zero-knowledge Storage: Only stores HMAC SHA-256 hashes of OTPs.
  • Brute Force Protection: Built-in tracking of failed attempts (maxAttempts).
  • Cooldowns: Prevents users from spamming the "Resend OTP" button.

Installation

npm install @satyajeetsahoo/otp

Configuration

This package requires a Cache strategy (from @satyajeetsahoo/cache) to store the hashes.

import { createOtpService } from '@satyajeetsahoo/otp';
import { CacheService } from '@satyajeetsahoo/cache';

const cache = CacheService.createCache('redis', { client: redisInstance });

export const otp = createOtpService({
  storeType: 'redis', 
  cacheStrategy: cache, 
  config: {
    secret: process.env.OTP_SECRET, // Must be >= 32 characters!
    length: 6,                      // 6-digit OTP
    ttlSeconds: 300,                // Expires in 5 minutes
    maxAttempts: 5,                 // Locks out after 5 wrong tries
    keyPrefix: 'otp:auth:'
  }
});

Usage Examples

1. Generating & Sending an OTP

This package does NOT send SMS/Emails automatically, allowing you to integrate with Twilio, AWS SNS, SendGrid, etc.

// 1. Generate the OTP
const response = await otp.sendOtp('+919999999999');

// 2. The response object
console.log(response);
/*
{
  sent: true,
  expiresInSeconds: 300,
  debugOtp: '849201' // NOTE: Only present in non-production environments!
}
*/

// 3. Send it via your provider
await mySmsProvider.send('+919999999999', `Your code is ${response.debugOtp}`);

2. Verifying an OTP

try {
  // Returns true if valid, throws an OtpError otherwise
  await otp.verifyOtp('+919999999999', req.body.code);
  
  // Login successful!
} catch (error) {
  // e.g., "Invalid OTP", "Too many incorrect attempts", or "OTP expired"
  res.status(error.status).json({ message: error.message });
}