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

blake2s-js

v1.3.0

Published

Pure JavaScript implementation of BLAKE2s cryptographic hash function.

Downloads

137

Readme

BLAKE2s implementation in JavaScript

BLAKE2 is a fast and secure cryptographic hash function.

This is a pure JavaScript public domain implementation of its BLAKE2s flavor (currently without tree mode support).

Build Status

Looking for BLAKE2b implementation? Check out: https://github.com/dcposch/blakejs

Installation

Via NPM:

$ npm install blake2s-js

Via Bower:

$ bower install blake2s-js

or just download blake2s.min.js.

Usage

new BLAKE2s(digestLength, key)

new BLAKE2s(digestLength, config)

Creates a new instance of BLAKE2s hash with the given length of digest (default and maximum 32) and an optional secret key (a Uint8Array or Array of bytes) or config object in the following format:

{
    salt: // 8-byte Uint8Array or Array of bytes
    personalization: // 8-byte Uint8Array or Array of bytes
    key: // 0-32-byte Uint8Array or Array of bytes
}

All keys in config are optional.

.update(data[, offset, length])

Updates the hash with data (a Uint8Array or Array of bytes). starting at the given offset (optional, defaults to 0) and consuming the given length (optional, defaults to the length of data minus offset).

Returns this instance to enable method chaining.

.digest()

Returns a Uint8Array with the digest of consumed data. Further updates will throw error. Repeat calls of digest() will return the same digest.

.hexDigest()

Like digest(), but returns a hex-encoded string.

BLAKE2s.digestLength = 32

Maximum digest length.

BLAKE2s.blockLength = 64

Block size of the hash function.

BLAKE2s.keyLength = 32

Maximum key length.

BLAKE2s.personalizationLength = 8

Length of personalization parameter.

BLAKE2s.saltLength = 8

Length of salt parameter.

Example

var h = new BLAKE2s(32);
h.update(new Uint8Array([1,2,3]));
h.hexDigest();  // returns string with hex digest
h.digest();     // returns Uint8Array

// Keyed:
var key = new Uint8Array(BLAKE2s.keyLength);
window.crypto.getRandomValues(key);
var h = new BLAKE2s(32, key);
...

// Keyed and salted:
var key = new Uint8Array(BLAKE2s.keyLength);
var salt = new Uint8Array(BLAKE2s.saltLength);
window.crypto.getRandomValues(key);
window.crypto.getRandomValues(salt);
var h = new BLAKE2s(32, { key: key, salt: salt });
...

// Personalized:
var data = new Uint8Array([1, 2, 3]);
var pers1 = new Uint8Array([1, 0, 0, 0, 0, 0, 0, 0]);
var h1 = new BLAKE2s(32, { personalization: pers1 });
h1.update(data);

var pers2 = new Uint8Array([2, 0, 0, 0, 0, 0, 0, 0]);
var h2 = new BLAKE2s(32, { personalization: pers2 });
h2.update(data);

h1.hexDigest() !== h2.hexDigest() // true