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

fast-blake3

v1.0.1

Published

Fast BLAKE3 cryptographic hash function with TypeScript support

Readme

fast-blake3

High-performance BLAKE3 cryptographic hash implementation for JavaScript/TypeScript

Features

  • Basic hashing
  • Streaming/incremental hashing
  • Keyed hashing (MAC)
  • Key derivation (KDF)
  • ESM and CommonJS support
  • Full TypeScript types

Installation

npm install fast-blake3

Quick Start

import { hash, createHasher, keyedHash, deriveKey } from 'fast-blake3';

// Basic hash
const digest = hash('hello world');           // Uint8Array(32)
const longHash = hash('hello world', 64);     // Uint8Array(64)

// Streaming hash
const hasher = createHasher();
hasher.update('hello').update(' world');
const result = hasher.finalize();

// Keyed hash (MAC)
const key = new Uint8Array(32).fill(0x42);
const mac = keyedHash(key, 'message');

// Key derivation (KDF)
const derivedKey = deriveKey('myapp context', 'password');

API Reference

hash(data, outputLength?)

Computes the BLAKE3 hash of the provided input.

Parameters:

| Name | Type | Description | |------|------|-------------| | data | Uint8Array \| string | Input data to hash | | outputLength | number | Output length in bytes (default: 32) |

Returns: Uint8Array

hash('hello');                    // 32-byte hash (default)
hash('hello', 64);                // 64-byte hash
hash(new Uint8Array([1,2,3]));    // Binary input

createHasher(options?)

Creates a streaming hasher for incremental hashing.

Parameters:

| Name | Type | Description | |------|------|-------------| | options.key | Uint8Array | 32-byte key for keyed hashing mode | | options.context | string | Context string for key derivation mode |

Returns: Blake3Hasher with methods:

  • update(data) - Add data, returns hasher for chaining
  • finalize(outputLength?) - Finalize and return hash
  • reset() - Reset hasher to initial state
const hasher = createHasher();
hasher.update('chunk1');
hasher.update('chunk2');
const digest = hasher.finalize();      // 32 bytes
const long = hasher.reset().update('data').finalize(64);  // 64 bytes

keyedHash(key, message, outputLength?)

Computes a keyed hash (MAC) using BLAKE3.

Parameters:

| Name | Type | Description | |------|------|-------------| | key | Uint8Array | 32-byte secret key | | message | Uint8Array \| string | Message to authenticate | | outputLength | number | Output length in bytes (default: 32) |

Returns: Uint8Array

const key = new Uint8Array(32).fill(0x42);
const mac = keyedHash(key, 'message');       // 32-byte MAC
const longMac = keyedHash(key, 'message', 64); // 64-byte MAC

deriveKey(context, keyMaterial, outputLength?)

Derives a key using BLAKE3's KDF mode.

Parameters:

| Name | Type | Description | |------|------|-------------| | context | string | Context string (unique to your application) | | keyMaterial | Uint8Array \| string | Input key material | | outputLength | number | Output length in bytes (default: 32) |

Returns: Uint8Array

const key = deriveKey('myapp v1 encryption', 'password');
const longKey = deriveKey('myapp v1', 'password', 64);

rawHash(data, outputLength?)

Low-level function that operates directly on Uint8Array and returns the raw hash.

Parameters:

| Name | Type | Description | |------|------|-------------| | data | Uint8Array | Input data | | outputLength | number | Output length in bytes (default: 32) |

Returns: Uint8Array

import { rawHash } from 'fast-blake3';

const input = new Uint8Array([1, 2, 3]);
const output = rawHash(input);       // 32 bytes
const long = rawHash(input, 64);     // 64 bytes

Blake3 Class

Static class providing an object-oriented interface.

| Method | Description | |--------|-------------| | Blake3.hash(data, options?) | Hash data with optional encoding | | Blake3.createHasher(options?) | Create streaming hasher | | Blake3.keyedHash(key, message, options?) | Keyed hash (MAC) | | Blake3.deriveKey(context, material, options?) | Key derivation (KDF) |

Options:

| Name | Type | Description | |------|------|-------------| | encoding | 'hex' \| 'base64' \| 'buffer' | Output format (default: 'hex') | | outputLength | number | Output length in bytes (default: 32) |

Returns: string | Uint8Array

import { Blake3 } from 'fast-blake3';

// Hash with encoding
Blake3.hash('test', { encoding: 'hex' });      // hex string
Blake3.hash('test', { encoding: 'base64' });   // base64 string
Blake3.hash('test', { encoding: 'buffer' });   // Uint8Array
Blake3.hash('test', { encoding: 'hex', outputLength: 64 });

// Keyed hash with encoding
Blake3.keyedHash(key, 'msg', { encoding: 'hex' });

// Key derivation (defaults to buffer for security)
Blake3.deriveKey('ctx', 'material', { encoding: 'buffer' });

Utility Functions

import { toHex, fromHex } from 'fast-blake3';

toHex(new Uint8Array([1, 2, 3]));  // '010203'
fromHex('010203');                  // Uint8Array([1, 2, 3])

CommonJS Usage

(async () => {
  const { hash, keyedHash, deriveKey } = await import('fast-blake3');
  console.log(hash('hello'));
})();

Browser Usage

<script type="module">
  import { hash } from './dist/esm/index.js';
  console.log(hash('hello'));
</script>

TypeScript

Full type definitions included.

import { 
  hash, 
  createHasher, 
  keyedHash, 
  deriveKey,
  Blake3,
  Blake3Options,
  Blake3Hasher 
} from 'fast-blake3';

const digest: Uint8Array = hash('test');
const hasher: Blake3Hasher = createHasher();