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

@naskot/node-hmac-auth

v0.5.2

Published

Simple and reusable HMAC auth for Node.js APIs and microservices.

Downloads

1,280

Readme

node-hmac-auth

Simple, reusable HMAC authentication for Node.js APIs and microservices.

Redis is mandatory.

npm version TypeScript Ready Node >= 18 License: MIT

Documentation

Compatibility

  • TypeScript: native typings included (dist/index.d.ts)
  • JavaScript runtimes: Node.js >= 18
  • Module formats: ESM + CommonJS
  • Framework support: framework-agnostic core + Express adapter
  • Storage: Redis required

Redis Key Glossary

For namespace my_company_prod:

  • my_company_prod:clients (hash map of client credentials)
  • my_company_prod:nonce:* (anti-replay nonce keys)

Header Glossary

Incoming signed requests are validated with:

  • x-client-id
  • x-timestamp (epoch ms)
  • x-nonce
  • x-signature

Signature Glossary

Signing payload:

METHOD\n
PATH_WITH_QUERY\n
TIMESTAMP_MS\n
NONCE\n
SHA256(BODY)

API Glossary

Initialization

  • initializeHmacHttpAuth(options) (recommended for HTTP routes + signed fetch)
    • options.redis (required)
    • options.namespace?
    • options.maxSkewMs?
    • options.defaultSecretLengthBytes?
    • options.secretToken?
    • options.onBadSignature?(event)
    • options.internalManagementRoute? (ex: /api/internal/hmac)

event contains clientId, method, path, timestamp, nonce, receivedSignature, expectedSignature, headers, rawBody, and optional metadata.

  • initializeHmacMessageAuth(options) (recommended for message signing + verification)
    • options.redis (required)
    • options.namespace?
    • options.defaultSecretLengthBytes?
    • options.secretToken?

Verify helpers

  • verifyHttpRequest(req, res, next): middleware usage (default middleware signature)
  • verifyHttpSignature(input): low-level verifier usage (framework-agnostic input object)
  • createHttpMiddleware(options?): generic middleware factory (recommended name)
  • createExpressHttpMiddleware(options?): alias kept for backward compatibility

Middleware example:

app.use("/secure", hmacAuth.verifyHttpRequest);

Fetch helpers

  • buildHttpSignedHeaders(input)
  • signedHttpFetch(url, options)
  • createHttpSignedFetchClient(options)

Internal HTTP key-management helpers

Enabled only when internalManagementRoute is configured.

  • handleInternalManagementRequest(input)
  • createInternalManagementMiddleware(options?)
  • createExpressInternalManagementMiddleware(options?)
  • propagateClientToApis(options)

Route behavior for internalManagementRoute:

  • GET: healthcheck
  • POST: create/propagate client (201 accepted, 403 refused)
  • PUT: update secret (201 accepted, 403 refused)
  • DELETE: delete client (201 accepted, 403 refused)

Security rule:

  • If at least one client exists, route requires valid HMAC auth.
  • If no client exists yet, bootstrap creation is allowed (first key).

Message helpers

  • signMessage(input): low-level message signer (with explicit secret)
  • verifyMessage(input): low-level message signature verifier
  • hmacMessageAuth.signMessage({ clientId, message }): Redis-backed message signer
  • hmacMessageAuth.verifyMessage({ clientId, message, signature }): Redis-backed message verifier

Message helpers intentionally do not enforce timestamp skew checks or anti-replay.

Credential helpers

  • clients.create({ clientId, plainSecret?, expiresAt?, secretLengthBytes?, allowedIps? })
  • clients.listClientIds()
  • clients.get(clientId)
  • clients.delete(clientId)
  • clients.regenerateSecret(clientId, { plainSecret?, secretLengthBytes?, expiresAt?, preserveExpiresAt?, allowedIps? })
  • clients.setSecret(clientId, plainSecret, expiresAt?, allowedIps?)
  • clients.setSecretHash(clientId, secretHash, expiresAt?, allowedIps?)
  • clients.setAllowedIps(clientId, allowedIps)
  • clients.getSecretHash(clientId)

allowedIps supports IPv4/IPv6 exact IP and CIDR strings (examples: 195.7.8.9, 195.7.8.0/24). If empty (or omitted), any source IP is accepted.