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

gilde

v2.0.1

Published

Time and shared secret based hash creation/validation library

Downloads

13

Readme

gilde

Time and shared secret based hash creation/validation library.

npm version Build status Coverage Status

Use cases

Use Gilde to create and validate shared secret and time based hashes derived from any JSON-serializable data. Gilde is mostly useful in a controlled environment (such as a set of microservices within one organization/infrastructure) and not suitable for public-facing authorizations.

Usage

npm install gilde

Create a hash

var Gilde = require('gilde'),
	gilde = new Gilde().setSecret('Thirteen stone columns inside a pyramid.');

var data = {
	some: 'awesome data'
};

var hash = gilde.create(data);

This will create a time and shared secret based derived hash, based on the given data. Then, in another part of your system, you can validate the given data against the given hash, using the following syntax.

Validate a hash

Once you've created a hash, you can validate it, using:

var result = gilde.validate(hash, data);
// returns either true or false

This will return a boolean value of the validation result.

Validate with options

var result = gilde.validate(hash, data, { timeout: 5000 });
// returns either true or false

Furthermore, you can pass a third argument to .validate() — currently, it only supports the timeout option which will control the threshold (in milliseconds) of timestamps that are still considered valid. In the given example, any hash older than 5000 milliseconds (5 s) will be considered invalid.

How it works

Creating the hashes

hashing diagram

The shared secret, JSON serialized data and the current UNIX timestamp in milliseconds are hashed together using the SHA256 algorhythm into hashA. The derived hashA is then hashed again together with the same UNIX timestamp using the SHA256 algorhythm into hashB. The resulting hashB is joined with the same timestamp and returned from the function as a single string, e.g. 57b91ea40b4bc28baa4ff782e661c5a6a12db97a3f60f4bd272ff32d9d77d8ed,1444044349222.

The result of calling gilde.create() thus returns a string that contains the derived hash and the timestamp used in the hashing process. Revealing the timestamp in a non-hashed format is acceptable and required, since this is used for validation on the other end, and timeouts are used to invalidate any hashes marked as older than a configurable threshold.

Validating the hashes

When validating the hashes, gilde.validate() requires you to supply the resulting created hash and the underlying data in question. It will then try to recreate the hash using the supplied timestamp and will produce a positive result if both the hash can be recreated (meaning the shared secret is the same and data matches) and time threshold is not exceeded (e.g. hash is validated within N milliseconds after it was first created).

Gilde vs HMAC

  • Gilde works out of the box with nested objects (You don't have to worry about serialization of the data as such).
  • Gilde provides out of the box functionality for time based invalidation (which you would have to manually implement on top of the standard HMAC).

Licence

MIT.