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

@pipobscure/jwt

v0.1.4

Published

JWT Token Management

Readme

@pipobscure/jwt

A lightweight, dependency-free JWT (JSON Web Token) utility built on the Web Crypto API.

Supports HMAC, RSA, and ECDSA signature algorithms (HS*, RS*, ES*, PS*).
Implements creation, signing, verification, and extraction of JWTs with minimal overhead.

Supported Algorithms

| Algorithm | Type | Hash | Notes | |------------|--------|-----------|-------| | HS256 | HMAC | SHA-256 | Symmetric (shared secret) | | HS384 | HMAC | SHA-384 | Symmetric (shared secret) | | HS512 | HMAC | SHA-512 | Symmetric (shared secret) | | RS256 | RSA | SHA-256 | Asymmetric (RSA PKCS#1 v1.5) | | RS384 | RSA | SHA-384 | Asymmetric (RSA PKCS#1 v1.5) | | RS512 | RSA | SHA-512 | Asymmetric (RSA PKCS#1 v1.5) | | ES256 | ECDSA | SHA-256 | Asymmetric (P-256 curve) | | ES384 | ECDSA | SHA-384 | Asymmetric (P-384 curve) | | ES512 | ECDSA | SHA-512 | Asymmetric (P-384 curve) | | PS256 | RSA-PSS | SHA-256 | Asymmetric (RSA PSS) | | PS384 | RSA-PSS | SHA-384 | Asymmetric (RSA PSS) | | PS512 | RSA-PSS | SHA-512 | Asymmetric (RSA PSS) |

API Overview

generate(payload: any, key?: CryptoKey): Promise<string>

Creates and signs a new JWT.

Parameters

  • payload: Any serializable JavaScript object to embed in the JWT.
  • key: A CryptoKey object usable for signing.

Returns

  • A Promise<string> — the encoded and signed JWT string (header.payload.signature).

Example

import { generate } from '@pipobscure/jwt';

const jwt = await generate({ sub: 'user123', exp: 1710000000 }, secretKey);
console.log(jwt);

extract(jwt: string, key?: CryptoKey): Promise<any>

Extracts and decodes the payload from a JWT, optionally verifying the signature.

Parameters

  • jwt: The JWT string.
  • key: (optional) A CryptoKey. If provided, the signature will be verified before extraction.

Returns

  • The decoded payload object.

Throws

  • Error('invalid signature') if verification fails when a key is supplied.

Example

const payload = await extract(token, publicKey);
console.log(payload.sub);

header(jwt: string): { typ: string; alg: Algorithm }

Returns the decoded header section of a JWT.

Example

const { alg } = header(token);
console.log(`Algorithm used: ${alg}`);

payload(jwt: string): any

Returns the decoded payload section of a JWT without verifying the signature.

Example

const claims = payload(token);
console.log(claims.exp);

sign(alg: Algorithm, key: CryptoKey, payload: Uint8Array) : Promise<string>

Signs the payload using the alg and key and returns the Base64 encoded signature.

verify(alg: Algorithm, key: CryptoKey, signature: string, payload: Uint8Array) : Promise<boolean>

Verifies the signature is valid for the payload.

Key Management

You can create compatible keys using the Web Crypto API:

// Example: Generate HMAC key
const key = await crypto.subtle.generateKey(
  { name: 'HMAC', hash: 'SHA-256' },
  true,
  ['sign', 'verify']
);

Or import an existing key:

const key = await crypto.subtle.importKey(
  'raw',
  new TextEncoder().encode('supersecret'),
  { name: 'HMAC', hash: 'SHA-256' },
  false,
  ['sign', 'verify']
);

License

Copyright 2025 Philipp Dunkel

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.