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

securend

v1.0.3

Published

a light fastify api endpoint with basic authentication

Downloads

301

Readme

secury

npm version License: MIT

Production-grade REST API factory with JWE & HMAC encryption for Node.js

secury is a lightweight, secure REST API framework built on top of Fastify. It provides enterprise-grade security features including JWE (JSON Web Encryption) decryption, HMAC signature verification, Bearer/Basic authentication, and built-in production hardening via Helmet and CORS — all with zero configuration required.

Features

  • 🔐 JWE Decryption - Automatically decrypt RSA-OAEP-256 encrypted payloads
  • 🛡️ HMAC Integrity - SHA-256 request signature verification
  • 🔑 Authentication - Built-in Bearer token and Basic auth support
  • 🚀 Fastify Powered - High-performance HTTP handling
  • 🏢 Production Ready - Helmet security headers, CORS, graceful shutdown
  • 📦 Zero Config - Sensible defaults, fully extensible

Installation

npm install secury

Quick Start

const secury = require('secury');

const app = secury({
  bearer: 'my-secret-token',
  verbose: true
});

// Define routes
app.get('/hello', async (ctx, res) => {
  return res({ message: 'Hello, World!' });
});

app.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log('Server running on http://localhost:3000');
});

API Reference

secury(options)

Creates and returns a Fastify instance with enhanced security middleware.

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | bearer | string | null | Static Bearer token for authentication | | basic | object | null | Basic auth credentials { user, pass } | | security | object | {} | Encryption settings (see below) | | verbose | boolean\\|function | false | Enable logging or provide custom logger | | cors | boolean\\|object | true | Enable CORS (pass object for custom config) | | limit | string | '1mb' | Request body size limit | | trustProxy | boolean | true | Trust proxy headers |

Security Options

{
  security: {
    jwePrivateKey: '-----BEGIN PRIVATE KEY-----...',  // RSA private key for JWE decryption
    hmacSecret: 'your-hmac-secret-key'                  // Secret for HMAC signature verification
  }
}

Route Methods

Pass route definitions in the options object:

  • get - GET routes
  • post - POST routes
  • put - PUT routes
  • delete - DELETE routes
  • patch - PATCH routes

Usage Examples

Basic Authentication

const app = secury({
  basic: { user: 'admin', pass: 'secret123' }
});

Bearer Token Authentication

const app = secury({
  bearer: process.env.API_TOKEN
});

JWE Decryption

Automatically decrypts JWE compact serialization payloads:

const app = secury({
  security: {
    jwePrivateKey: process.env.RSA_PRIVATE_KEY
  }
});

// POST with JWE encrypted body will be automatically decrypted
app.post('/secure', async (ctx, res) => {
  // ctx.body is the decrypted JSON payload
  return res({ received: ctx.body });
});

HMAC Signature Verification

Verifies request integrity using SHA-256 HMAC:

const app = secury({
  security: {
    hmacSecret: 'your-webhook-secret'
  }
});

// Client must include: X-Signature: sha256=<hex_digest>
app.post('/webhook', async (ctx, res) => {
  return res({ verified: true });
});

Combined Security

const app = secury({
  bearer: process.env.API_TOKEN,
  security: {
    jwePrivateKey: process.env.RSA_PRIVATE_KEY,
    hmacSecret: process.env.HMAC_SECRET
  },
  cors: { origin: 'https://trusted-domain.com' },
  verbose: true
});

Route Configuration with Schema

const app = secury({
  post: {
    '/users': {
      schema: {
        body: {
          type: 'object',
          properties: {
            name: { type: 'string' },
            email: { type: 'string', format: 'email' }
          },
          required: ['name', 'email']
        }
      },
      handler: async (ctx, res) => {
        const { name, email } = ctx.body;
        // Create user...
        return res({ id: 1, name, email }, 201);
      }
    }
  }
});

Handler Context

Each handler receives:

async (ctx, res) => {
  ctx.query    // Query parameters
  ctx.params   // URL parameters
  ctx.body     // Request body (decrypted if JWE enabled)
  ctx.headers  // Request headers
  ctx.ip       // Client IP
  ctx.req      // Raw Fastify request object
  
  // Response helpers
  res(data)           // Send response
  res(data, 201)      // Send with status code
  res.status(201).send(data)  // Chain status
}

Error Handling

secury automatically handles errors and returns appropriate HTTP responses:

  • 401 Unauthorized - Invalid or missing authentication
  • 403 Forbidden - Invalid HMAC signature
  • 400 Bad Request - JWE decryption failed
  • 500 Internal Server Error - Unexpected errors (with stack trace in verbose mode)

Dependencies

Requirements

  • Node.js >= 14.0.0

License

MIT © littlejustnode

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For bugs and feature requests, please open an issue.