Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-jose

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-jose

Wrap functions of JOSE in steady interface

  • 5.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

nameDescription
kidUsing specific key in JWKS
jtiVerify 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

nameReferrer
issuersetIssuer
audiencesetAudience
subjectsetSubject
expsetExpirationTime
jtisetJti
notBeforesetNotBefore
iatsetIssuedAt
typHeader
kidHeader
algHeader

Additional options

nametypedefaultdescription
jwkbooleanfalseWhether embedded key to header
await JWT.sign(payload, key, options); // key must be JWK or JWKS

decrypt

JOSE ref

Additional options

nameDescription
kidUsing specific key in JWKS
encEncrypt algorithm
algKey management algorithm
await JWT.decrypt(cypher, key, options);

encrypt

JOSE ref

Using JOSE options

nameReferrer
issuersetIssuer
audiencesetAudience
subjectsetSubject
expsetExpirationTime
jtisetJti
notBeforesetNotBefore
iatsetIssuedAt
typHeader
kidHeader
encHeader
algHeader
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');

Keywords

FAQs

Package last updated on 01 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc