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

@trellisfw/signatures

v2.1.3

Published

Generate and verify Json Web Tokens within food safety audits.

Downloads

16

Readme

trellisfw-signatures

Create and verify RS256 based JWT oauth-jwt-bearer client authentications.

Installation

npm install @trellisfw/signatures

Require Usage

var tSignature = require('@trellisfw/signatures');
const objToSign = {
  "hello": "world"
};
const key = require('./jwkprivatekey.json');

// Sign an object:
try {
  tSignature.sign(objToSign, key);
  // This mutates objToSign by adding a `signatures` key as an array.
  console.log('Successfully signed object.  Singed document = ', objToSign);
} catch(err ){
  console.log('Failed to sign object.  Error was: ", err);
}

// Verify the last (latest) signature in the signatures array on a signed object:
const signedObj = objToSign; // mutated above to add signatures key
try {
  const { trusted, valid, payload, unchanged, messages } = tSignature.validate(signedObj);
  console.log('Was signature signed by a trusted key: ', trusted);
  console.log('Was signature a valid JWT according to the key used to sign it: ', valid);
  console.log('Was the document changed since the signature was applied: ', unchanged);
  console.log('The payload of the signature was: ', payload);
  console.log('The library told us these things about the decoding process: ', messages);
} catch(err) {
  console.log('Signature verification failed.');
}

API

sign(jsonobject, key, headers)

Generate a signed jsonobject with the given headers and the client's private key. The sign function appends a Json Web Token (JWT) to the jsonobject's signatures key.

Parameters

jsonobject {Object} Any JSON object, such as a food safety audit.

key {JWK} The key used to sign the audit, as a JWK.

headers {Object} The headers parameter is sent on to oada-certs to be used in the signature process. The typ and alg keys are retained if present. Note If there is a key id in the headers (headers.kid), and there is also a kid in the JWK passed as the signing key, the one in the headers will override the one in the key.

validate(jsonobject,options)

Determine if the last item in a jsonobject's signatures key is trusted, valid, and if the document itself is unchanged since the signature was applied.

Returns { trusted, valid, unchanged, payload, messages }

  • valid: true if signature is a valid JWT and a public key is available to check it against.
  • trusted: true if signature is valid and was signed with a JWK from the trusted list.
  • unchanged: true if the signature is valid and the payload hashes to the same value as the current document.
  • payload: the actual decoded payload of the signature.
  • messages: an array of debugging messages designed to help you figure out why the library has made the determinations that it returns.

Parameters

  • jsonobject: an object with a signatures key that is an array with at least one JWT signature in it.
  • options: object with options to pass directly to oada-certs library.
    Please refer to the docuentation for oada-certs for details, but this can include things like alternate trusted lists, etc. Please note that this library will always pre-prend the main Trellis trusted list onto the front of any additional trusted lists that are passed in options.