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 🙏

© 2025 – Pkg Stats / Ryan Hefner

eat

v0.2.1

Published

Encrypted Authentication Tokens

Readme

Encrypted Authentication Tokens

travis build

Tokens used for authentication purposes in a client/server app architecture. Loosely based off the encrypted token pattern by OWASP for preventing CSRF attacks. Tokens are encrypted using aes-256-ctr with a random IV and a password that's generated using crypto.pbkdf2 from an app secret with a 32 byte random salt.

var eat = require('eat');

eat.encode({id: user.id, timestamp: Time.now}, 'mysupersecret', function(err, token) {
  if (err) throw err;
  //send token
});

eat.decode(token, 'mysupersecret', function(err, token) {
  if (err) throw err;
  //check if token is expired and if the id corresponds to a valid user
});

The resulting token will be base64 encoded and can be passed to client to use for authentication against the server. The token should only be able to be encoded on the server. This is not a substitute for using ssl/tls it should be used in conjunction with a secure connection. If an attacker gets ahold of the token they will be able to authenticate as the user until the token is expired or you change the salt/iv. These functions can be called on eat as follows.

if (server_compromised) {
  eat.genSalt(function() {
    console.log('salt generated');
  });

  eat.geniv(function() {
    console.log('iv generated');
  });
}

Either one of these functions will invalidate any token generated when using a different iv/salt. Another thing to keep in mind is that the iv/salt get regenerated everytime the server is reset. So, a server reset will invalidate all current tokens which might not be ideal for your use case. You can set the iv/salt parameters of the eat object although be careful as this can open you up to replay attacks. The salt can be length but the iv MUST be 32 bytes. Both must be contained in a buffer.

var eat = require('eat');
eat.salt = buffer.new('my new salt');
eat.iv = buffer.new('a 32 byte string'); //this string isn't actually 32 bytes