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

@bleskomat/scrypt

v1.0.0

Published

Node.js module that provides a wrapper API to node's built-in scrypt implementation.

Downloads

48

Readme

scrypt-node

Build Status

Node.js module that provides a wrapper API to node's built-in scrypt implementation.

Why not just use the built-in scrypt of Node.js? You could, but it's nice to have a portable serialization format that can be stored in a database or configuration file long-term without worrying about incompatibility when changing hashing options. An example of the serialization format used by this module:

$scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=

$scrypt$ is the prefix and the $ symbol is used as a delimiter. The first value is the serialization format version - in this case 1. The second value is the cost exponent - in this case 14 meaning the cost is equal to 2^14 or 16384. The third value is the base64-encoded salt. And the fourth value is the base64-encoded derived key.

Installation

Add to your application via npm:

npm install @bleskomat/scrypt

Usage

Create a hash of a secret:

const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const salt = scrypt.generateSalt();
scrypt.hash(secret, salt).then(result => {
	console.log(result);
	// $scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=
});

The complete function signature is scrypt.hash(secret, salt, keylen, options). The keylen and options arguments are passed to crypto.scrypt. The default value for keylen is 32 bytes.

And scrypt.generateSalt(numBytes) where numBytes are the number of random bytes to generate. The default value for numBytes is 20.

Check if a secret matches a hash:

const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const hash = '$scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=';
scrypt.compare(secret, hash).then(result => {
	console.log(result ? 'OK' : 'DOES NOT MATCH');
});

Synchronous Usage

Synchronously create a hash:

const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const salt = scrypt.generateSalt();
const result = scrypt.hashSync(secret, salt);
console.log(result);
// $scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=

The complete function signature is scrypt.hashSync(secret, salt, keylen, options). The keylen and options arguments are passed to crypto.scryptSync. The default value for keylen is 32 bytes.

And scrypt.generateSalt(numBytes) where numBytes are the number of random bytes to generate. The default value for numBytes is 20.

Synchronously check if a secret matches a hash:

const scrypt = require('@bleskomat/scrypt');
const secret = 'super secret password';
const hash = '$scrypt$1$14$iAoNah2WdPs7s2JZTd0Velb6ycQ=$ttq2cz7NoXNkAs6Nbl+TNKZsYFaEQJFcIWNTApiV67k=';
const result = scrypt.compareSync(secret, hash);
console.log(result ? 'OK' : 'DOES NOT MATCH');

Tests

Run automated tests as follows:

npm test

Changelog

See CHANGELOG.md

License

This software is MIT licensed:

A short, permissive software license. Basically, you can do whatever you want as long as you include the original copyright and license notice in any copy of the software/source. There are many variations of this license in use.