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

@trap_stevo/verikey

v0.0.5

Published

The pinnacle of seamless, legendary authentication through a hybrid, precision-crafted access system built for real-time protection, dynamic client validation, and seamless token orchestration. Define flexible credential flows, enforce contextual policies

Downloads

14

Readme

🛡️ VeriKey · Legendary Hybrid Authentication

The pinnacle of legendary authentication through a hybrid, precision-crafted access system built for real-time protection, dynamic client validation, and seamless token orchestration.
Secure every route with scalable, token-backed control. Adapt effortlessly to evolving security demands across any application layer.


🚀 Features

  • 🔐 Hybrid header + token-based authentication
  • ⚡ Real-time client validation
  • 🧠 Contextual claim injection
  • 🗃 Persistent client identity via LevelDB
  • ⚙️ Fully extensible configuration per client
  • 🔄 Runtime instance configuration control
  • 📁 Client grouping via appName and configName
  • 🧩 Drop-in middleware for route protection

📦 Installation

npm install @trap_stevo/verikey

🔧 Quick Start

const express = require("express");
const { VeriKey, VeriGuard } = require("@trap_stevo/verikey");

VeriKey.enablePersistence("./verikey-db");

(async () => {
      await VeriKey.addClient("MyApp", "ProdConfig", "frontend-client", {
            baseSecret : "super-secret",
            headers : { "x-access" : "super-secret" },
            useStrictMode : false,
            jwtSecret : "custom-jwt-secret",
            jwtExpiresIn : "1h",
            refreshTokenEnabled : true,
            refreshTokenTTL : "7d",
            refreshRotation : true
      });
})();

const app = express();
app.use(express.json());

app.post("/auth", async (req, res) => {
      const result = await VeriKey.verifyClientAccess("frontend-client", req);
      if (!result.success) return res.status(result.code).json({ message : result.message });
      res.json({ token : result.token, refreshToken : result.refreshToken });
});

app.post("/auth/refresh", async (req, res) => {
      const { clientID, refreshToken } = req.body;
      const result = VeriKey.verifyRefreshToken(clientID, refreshToken);
      if (!result.success) return res.status(401).json({ message : result.message });
      res.json({ token : result.token, refreshToken : result.refreshToken });
});

app.get("/secure", VeriGuard(), (req, res) => {
      res.json({ message : "Access granted!", claims : req.clientClaims });
});

🔑 API Overview

VeriKey.addClient(appName, configName, clientID, options)

Registers a new client with optional JWT settings, headers, IP restrictions, and optional namespace.

VeriKey.verifyClientAccess(clientID, req)

Validates a client’s credentials and generates a token (and refresh token if enabled).

VeriKey.verifyRefreshToken(clientID, refreshToken)

Verifies and rotates a refresh token to issue a new token (and new refresh token if rotation is enabled).

VeriKey.verifyClientJWT(clientID, token)

Validates an issued token using the client’s configuration.

VeriKey.enablePersistence(dbPath)

Enables persistent client storage at the provided path.

VeriKey.disablePersistence()

Disables persistence and safely closes the database.

VeriKey.setInstanceConfig(config)

Globally updates VeriKey configuration (e.g. defaultNamespace, refreshCleanupInterval).

VeriKey.getClientsByApp(appName) / VeriKey.getClientsByConfig(configName)

Filters and retrieves clients by grouping metadata.

VeriKey.getClientsByNamespace(namespace)

Returns clients registered under the specified namespace.

VeriKey.listNamespaces()

Lists all active namespaces stored in persistent mode.

VeriKey.deleteNamespace(namespace)

Deletes all clients under a given namespace (from memory and disk).

VeriGuard(options)

Express middleware for protecting routes using JWT tokens. Accepts { clientID } or reads from x-client-id header.


🛠 Configuration Options

{
      baseSecret           : "string",          // Used for HMAC or plain secret validation
      headers              : { key: value },    // Header name and value
      useStrictMode        : true | false,      // Compare against derived HMAC if true
      ipWhitelist          : [ "x.x.x.x" ],
      ipBlacklist          : [ "y.y.y.y" ],
      jwtEnabled           : true | false,
      jwtSecret            : "jwt-secret-key",
      jwtExpiresIn         : "30m",             // 1s, 1m, 1h, 1w, 1mo, 1d, 1y, 1dec, 1gen, 1cen, ...
      jwtAlgorithm         : "HS256",
      jwtInjectClaims      : (req, clientID) => ({ ... }),
      refreshTokenEnabled  : true | false,
      refreshTokenTTL      : "7d",
      refreshRotation      : true | false       // If true, old refresh tokens revoke on use
}

📂 Persistent Storage

VeriKey supports persistent client authentication across restarts, allowing full recovery of registered clients and their configurations.

✅ Enable Persistence

VeriKey.enablePersistence("./verikey-db");

This activates persistent storage using the provided path. Clients added afterward are retained between application restarts automatically.

🧠 Namespace Support

You can group clients into isolated scopes using namespaces:

await VeriKey.addClient("MyApp", "ProdConfig", "admin-panel", {
      namespace : "internal"
});

Set a default namespace globally:

VeriKey.setInstanceConfig({
      defaultNamespace : "internal"
});

🔁 Disable Persistence

To turn off persistence and cleanly unload stored data:

await VeriKey.disablePersistence();

🔍 Namespace Tools

await VeriKey.listNamespaces();            // → [ "internal", "partner", "admin" ]
await VeriKey.getClientsByNamespace("internal");
await VeriKey.deleteNamespace("partner");  // ⚠ Removes all clients under "partner"

Seamless, scoped, and storage-aware — VeriKey adapts to any scale or architecture 🔐


🧪 Example Curl Usage

# Authenticate and receive token
curl -X POST http://localhost:3000/auth \
  -H "x-access: super-secret" \
  -H "Content-Type: application/json" \
  -d '{}'

# Access secure route
curl -X GET http://localhost:3000/secure \
  -H "Authorization: Bearer <your-token>" \
  -H "x-client-id: frontend-client"

🧱 Use Cases

  • Secure multi-client apps with isolated auth logic
  • Protect internal services and dashboards
  • Grant tiered access via injected claims
  • Track identity persistently across service boundaries

📜 License

See License in LICENSE.md

Engineered for real-time protection and unmatched flexibility.