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 🙏

© 2024 – Pkg Stats / Ryan Hefner

keylab

v0.1.32

Published

keylab is a library aiming to create and validate JSON Web Tokens without hussle or prerequisitie cryptography knowledge.

Downloads

35

Readme

keylab

Build Status CircleCI codecov npm version code style: prettier bundle size

Keylab is a Node.js library designed to simplify the creation and validation of JSON Web Tokens, eliminating the need for prior knowledge in cryptography.

Install

with yarn

yarn add keylab

with pnpm

pnpm add keylab

with npm

npm install keylab

Get Started

Signin a Token with a Private key


// ES256

import {getKeyPair, signJwtWithPrivateKey, Algs} from "keylab"

const keyPairES256 = await getKeyPair({
    keyFormat: "pem",
    algorithmIdentifier: Algs?.ES256,
    keySize: 4096
});

const signedPayloadEs256 = await signJwtWithPrivateKey(
    {
        aid: "12345",
        sub: "sub:12345",
        iss: "issuer:12345",
        aud: ["aud:12345"],
        scp: ["a", "b:c", "d"].join(" ")
    },
    Algs.ES256,
    keyPairES256.privateKey
);

Verify a token with private key (symetric)

  • HS256

import {verifyHSTokenWithSecretString, Algs} from "keylab"

const isVerified = await verifyHSTokenWithSecretString(
    signedToken,
    SECRET_STRING,
    Algs.HS256
);

Verify a token with a public OpenID endpoint (asymetric)

  • ES512

import {checkTokenValidness} from "keylab"

const signedPayloadEs512 = "ey.....";
const jwksUri = `https://openid.auth.dog/.well-known/jwks.json`;

const isValid = await checkTokenValidness(
    signedPayloadEs512,
    {
        jwksUri
    }
);

Changelog

  • 0.1.31: Bump jose dependency, fix fetch in Jest, enable Ed25519, Ed448
  • 0.1.30: Fix support for adhoc jwks
  • 0.1.26: Remove fetchJwksWithUri, remove node-fetch dependency
  • 0.1.20: Improve Cloudflare Workers compatibility for verify
  • 0.1.19: Export getKeyPair
  • 0.1.18: Export pemToJwk
  • 0.1.14: Extract alg to verify token with PEM
  • 0.1.13: Validate tokens signed with PEM
  • 0.1.12:
  • Remove jws from dependencies
  • improve compatibility with Cloudflare Workers
  • 0.1.11: Add support for keyid injection in jwt header (required for Apple OAuth2.0 flow)
  • 0.0.0: JWT signed with a JSON Web Key can be "ad-hoc" validated
  • 0.0.0: verifyRSATokenWithUri has been replaced with verifyRSAToken

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

References

  • https://w3c.github.io/webcrypto/
  • https://nodejs.org/docs/latest-v15.x/api/crypto.html

License

This project is licensed under the MIT license. See the LICENSE file for more info.