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

jwty

v0.0.11

Published

A lightweight and secure JSON Web Token (JWT) implementation for TypeScript/JavaScript applications.

Readme

JWT

A lightweight and secure JSON Web Token (JWT) implementation for TypeScript/JavaScript applications.

Installation

npm install jwt
# or
yarn add jwt
# or
pnpm add jwt

Supported Algorithms

This library supports the following algorithms:

HMAC-based Algorithms

  • HS256 (HMAC with SHA-256): The most commonly used algorithm, providing a good balance between security and performance. Recommended for most applications.
  • HS384 (HMAC with SHA-384): Offers increased security over HS256 with slightly lower performance. Suitable for applications requiring higher security levels.
  • HS512 (HMAC with SHA-512): Provides the highest security level among the supported HMAC algorithms. Best for applications with strict security requirements.

RSA-based Algorithms

  • RS256 (RSA with SHA-256): RSA-based signing with 2048-bit key length, suitable for most applications requiring asymmetric cryptography.
  • RS384 (RSA with SHA-384): Increased security with 3072-bit key length, recommended for higher security requirements.
  • RS512 (RSA with SHA-512): Maximum security with 4096-bit key length, ideal for highly sensitive applications.

Key Generation for RSA

For RSA-based algorithms, you'll need to generate a public/private key pair. Here's how to generate them using OpenSSL:

# Generate private key
openssl genrsa -out private.pem 2048

# Extract public key from private key
openssl rsa -in private.pem -pubout -out public.pem

Usage

Environment-Specific Imports

The package provides different entry points for browser and Node.js environments:

// For browser environments
import { encodeSession, decodeSession, checkExpirationStatus } from 'jwt/web';

// For Node.js environments
import { encodeSession, decodeSession, checkExpirationStatus } from 'jwt/auth';

Basic Example

import { encodeSession, decodeSession, checkExpirationStatus } from 'jwt';

// Create a new session token
const partialSession = {
    id: "user123",
    username: "john.doe",
    role: "admin"
};

// For HMAC-based algorithms
const secretKey = "your-secret-key";
const algorithm = "HS256"; // Supported HMAC algorithms: HS256, HS384, HS512

// For RSA-based algorithms
const privateKey = fs.readFileSync('private.pem');
const publicKey = fs.readFileSync('public.pem');
const rsaAlgorithm = "RS256"; // Supported RSA algorithms: RS256, RS384, RS512

// Encode session
const { token, issued, expires } = encodeSession(secretKey, partialSession, algorithm);

// Decode session
const decodedResult = decodeSession(secretKey, token, false, algorithm);

// Check token expiration status
if (decodedResult.type === 'valid') {
    const expirationStatus = checkExpirationStatus(decodedResult.session);
    console.log('Token status:', expirationStatus); // 'active', 'grace', or 'expired'
}

Custom Session Types

You can extend the default Session interface by declaring your own interface in the JWT namespace:

declare namespace JWT {
    interface Session {
        id: string;
        username: string;
        role: string;
        // Add your custom properties here
        permissions?: string[];
        organization?: string;
        // ... any other custom fields
    }
}

API Reference

encodeSession(secretKey, partialSession, algorithm)

Creates a new JWT session token.

  • secretKey: String - The secret key used for signing the token
  • partialSession: Object - The session data to encode
  • algorithm: String - The signing algorithm to use (HS256, HS384, HS512)

Returns an object containing:

  • token: The JWT string
  • issued: Timestamp when the token was issued
  • expires: Timestamp when the token will expire

decodeSession(secretKey, tokenString, noVerify, algorithm)

Decodes and verifies a JWT token.

  • secretKey: String - The secret key used for verification
  • tokenString: String - The JWT token to decode
  • noVerify: Boolean - Skip signature verification if true
  • algorithm: String - The algorithm used for verification

Returns a DecodeResult object with either:

  • Valid token: { type: 'valid', session: Session }
  • Invalid token: { type: 'invalid', error: string }

checkExpirationStatus(token)

Checks the expiration status of a decoded token.

  • token: Session - The decoded token session

Returns one of:

  • 'active': Token is still valid
  • 'grace': Token is expired but within grace period (3 hours)
  • 'expired': Token is expired and beyond grace period

License

MIT

Author

Danutu89