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

ts-jose

v5.9.6

Published

Wrap functions of JOSE in steady interface

Downloads

60,381

Readme

TS JOSE

test Version

codecov Quality

Dependencies Node Version Activity License

Wrap functions of JOSE in steady interface.

[!Note]

This package's version will FOLLOW the version of JOSE

JWT

verify

JOSE ref

Additional options

| name | Description | | ---- | ---------------------------- | | kid | Using specific key in JWKS | | jti | Verify payload jti |

// `key` must be JWK or JWKS.
await JWT.verify(token, key, options);
// Use embedded key instead given one.
await JWT.verify(token, undefined, options);

sign

Using JOSE options

| name | Referrer | | --------- | ----------------- | | issuer | setIssuer | | audience | setAudience | | subject | setSubject | | exp | setExpirationTime | | jti | setJti | | notBefore | setNotBefore | | iat | setIssuedAt | | typ | Header | | kid | Header | | alg | Header |

Additional options

| name | type | default | description | | ---- | --------- | ------- | ------------------------------ | | jwk | boolean | false | Whether embedded key to header |

await JWT.sign(payload, key, options); // key must be JWK or JWKS

decrypt

JOSE ref

Additional options

| name | Description | | ---- | ---------------------------- | | kid | Using specific key in JWKS | | enc | Encrypt algorithm | | alg | Key management algorithm |

await JWT.decrypt(cypher, key, options);

encrypt

JOSE ref

Using JOSE options

| name | Referrer | | --------- | ----------------- | | issuer | setIssuer | | audience | setAudience | | subject | setSubject | | exp | setExpirationTime | | jti | setJti | | notBefore | setNotBefore | | iat | setIssuedAt | | typ | Header | | kid | Header | | enc | Header | | alg | Header |

await JWT.encrypt(payload, key, options);

JWS

You can sign pure string.

verify

JOSE ref

await JWS.verify(data, key, options);

sign

JOSE ref

Only using below JWT.sign's options:

  • typ
  • kid
  • alg
  • jwk
await JWS.sign('some-data', key, options);

JWE

You can encrypt pure string.

decrypt

JOSE ref

Additional options

Same as JWT.decrypt

await JWE.decrypt(cypher, key, options);

encrypt

JOSE ref

Only using below JWT.encrypt's options:

  • kid
  • alg
  • enc
await JWE.encrypt('some-data', key, options);

JWK

JOSE ref

// generate key
const key: JWK = await JWK.generate('ES256', {
  kid: 'some-id',
  use: 'sig',
  // crv: string, some algorithms need to add curve - EdDSA
  // modulusLength: number, some algorithms need to add length - RSA
});

// object to JWK
const key: JWK = await JWK.fromObject({
  kid: 'some-id',
  alg: 'ES256',
  kty: 'EC',
  crv: 'P-256',
  x: '123',
  y: '456',
  d: '789',
});

// JWK to object
const keyObject: JWKObject = key.toObject(false); // true to output private object, default: false

// private JWK to public JWK
const newKey: JWK = await key.toPublic();

// get key's status
key.isPrivate;

// check key "id", "use", "alg"
try {
  // return `this` if all pass
  key.getKey({ kid: 'some-id', use: 'sig', alg: 'ES256' });
} catch (err) {
  // throw error if this key has different metadata from options
}

JWKS

// object to JWKS
const keys = await JWKS.fromObject({
  keys: [
    {
      alg: 'ES256',
      kty: 'EC',
      x: '123',
      y: '456',
    },
  ],
});

// get key from store in specific options
try {
  const key: JWK = keys.getKey({ kid: 'some-id', use: 'sig', alg: 'ES256' });
} catch (err) {
  // throw error if not found
}
const key: JWK = keys.getKeyByKid('some-id');
const key: JWK = keys.getKeyByUse('sig');
const key: JWK = keys.getKeyByAlg('ES256');
const publicKeys = await keys.toPublic();