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

jwe-ez

v1.0.6

Published

convenience token API for creating JWE tokens with AES128CBC_HMACSHA256 confidentiality and integrity

Downloads

1

Readme

JavaScript Style Guide

jwe-ez

Easy usage confidential tamper-proofed tokens using A128CBC-HS256

Setup

Install the necessary node packages by doing:

cd jwe-ez
npm install

Usage

Provide a config object and a developmentKeyId which is used to detect if we should not be running in production. NB. "k" is a base64url encoded representation of a 256 bit symmetric key.

const config = {
  "tokenProperties": {
    "iss": "alice",
    "validAudiences": ["alice", "bob"],
    "expirySeconds": 1
  },
  "keyDefinition": {
    "kty": "oct",
    "kid": "JWE-EZ_DEVELOPMENT",
    "k":   "Ls_HQn6Dow0dH_v4DQ5WZr5zfhqVdsaRlx416AOQ59M",
    "alg": "A256KW",
    "use": "enc"
  }
}
const developmentKeyId = 'JWE-EZ_DEVELOPMENT'
const je = require('jwe-ez')(config, developmentKeyId)

var claims = { foo: 'bar', stuff: 'nonsense', aud: 'bob' }
je.createJWE(claims, (err, tokenString) => {
  console.log(tokenString)
  /*
  eyJhbGciOiJBMjU2S1ciLCJraWQiOiJKV0UtRVpfREVWRUxPUE1FTlQiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.ox5JW3b5F-LuvHK60KK6ZxTNSsEL-eQOxXXrXGDqLeok2aOOPR_pqA.sbWamMH2WtXPiCO1VCbrqw.uhEhWKfA0hhEAzbsTOxaiSf9d45RHmxesDqs2fJYRzs6C0NWsL8SF6PdBzaOPqAUwgnR9-Fq1Ldsg6cRbJBnGQ.IasqvzuX7XXLgvBrOFrHgQ
  */

  je.verifyJWE(tokenString, (err, verifiedClaims) => {
    console.log(verifiedClaims)
    /*
    { foo: 'bar',
      stuff: 'nonsense',
      aud: 'bob',
      iss: 'alice',
      iat: 1523891758,
      exp: 1523891759
    }
    */
  })
})

Generating Keys

require('crypto').randomBytes(32).toString('base64').replace(/=/g,'').replace(/\+/g, '-').replace(/\//g,'_')
/* nbE6srz6D31mXs9WMzKK-KOgNrYY1ctTF7bn0s_kTW8 */

Linting

npm run lint

This runs the linting standards imposed by the "standard" JS package from https://github.com/feross/standard

Testing

npm test

This runs all the test files that have been written into /test/tests.js by using the "tape" JS test framework from https://github.com/substack/tape

TODO

  • move payloads to the "sub" claim
  • move developmentKeyId to config
  • assert(JWK.isKey(input.key)) for key verification
  • whitelist claimsObject keys in createJWE from config