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

native-jwe

v1.0.0

Published

[![Donate with PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/thangngh)

Readme

In-House High-Performance JWE/JWS Core Engine

Donate with PayPal

A high-performance JWE/JWS encryption/decryption and signing module, with zero dependencies (using only Node.js crypto & zlib), specifically optimized for multi-session IAM (Identity and Access Management) systems.

1. Design Philosophy

  • Zero-Dependency: Utilizes only native Node.js crypto and zlib modules. Minimizes Supply Chain Attack risks and keeps the source code lean.
  • Low-Level Optimization: Directly manipulates Buffers to optimize RAM and CPU usage.
  • Security First: Hardened against common attack vectors such as DoS, Zip Bombs, Timing Attacks, and Information Leakage.
  • Robustness: Prioritizes operational stability, fail-safe mechanisms, and resource protection.

2. Technical Architecture & Performance Optimization

This Core Engine is not just a simple wrapper; it applies deep processing techniques:

⚡ Direct Native Bindings (OpenSSL Support)

Instead of processing encryption logic with slow pure Javascript, all heavy tasks (createCipheriv, publicEncrypt, verify) are bound directly to the C++ OpenSSL layer of Node.js.

  • => Speed: Comparable to compiled languages like Go/Rust for Crypto tasks.

🚀 Zero-Copy & Native Base64Url

The system completely eliminates manual regex string processing functions (which are memory-intensive and slow). Instead, it uses the Buffer.from(str, 'base64url') API (Node.js native):

  • Minimizes Intermediate Memory Allocation.
  • Avoids Memory Fragmentation when handling thousands of concurrent requests.

🛡️ Memory Protection (First Line of Defense)

Before any logic runs, the system applies "Hard Limits":

  • JWE Max Size: 200KB.
  • JWS Max Size: 50KB.
  • Zip Max Output: 2MB.
  • Effect: Prevents DoS attacks aiming for Out-Of-Memory (OOM) via large malicious payloads.

3. Security Hardening Features

The engine has been patched and fortified against the following vulnerabilities:

| Threat Vector | Technical Countermeasure | | :--- | :--- | | Zip Bomb (DoS) | Limits gunzipSync output to a maximum of 2MB. | | Information Leakage | decrypt only returns a generic DecryptionFailed error. Does not reveal specific Header/Key errors to prevent Enumeration. | | Timing Attacks | Uses safe comparison functions or appropriate fail-fast logic at the Header level. | | Downgrade Attacks | Hardcodes the strongest algorithms RSA-OAEP-256 and AES-256-GCM. Rejects all weaker algorithms. |

4. Operational Usage in IAM Systems

Scenarios

  1. JWS (Signature): Used as Access Token (short-term).
    • Location: API Gateway.
    • Pros: Extremely fast verify, high load tolerance.
  2. JWE (Encryption): Used as Refresh Token or Secure Cookie (long-term).
    • Location: Auth Service.
    • Pros: Completely hides token structure, protects session information (Session ID) stored on Client.

Best Practices

  • Key Management: The module uses PEM keys. In Production, mount Keys from a Secret Manager (Vault/AWS/K8s Secrets) into RAM at startup; avoid hardcoding them.
  • Error Logging: Although generic errors are returned to the Client, the system still logs details via console.error. Connect these logs to a Monitoring system (ELK, Loki) to detect attack signs.

5. Credits & Acknowledgments

This project is inspired by and based on portions of the work from psenger/jwe_example.

6. License

MIT License.