BLAKE3 Hashing (WebAssembly)

3.0.0 · active · verified Sun Apr 19

The `blake3-wasm` package provides high-performance WebAssembly bindings for the BLAKE3 cryptographic hash function, enabling efficient hashing operations in JavaScript environments, including Node.js (>=16) and modern browsers. BLAKE3 is renowned for its speed, security, and parallel processing capabilities, making it a robust choice for various applications. This package specifically wraps the BLAKE3 WebAssembly module, offering a lean implementation focused solely on WASM performance rather than hybrid native bindings. The current stable version, 3.0.0, marks a significant shift to an ES Modules-only API and requires explicit asynchronous initialization. While the major version hasn't seen frequent updates since its release (October 2022), the underlying `connor4312/blake3` project, from which this package is derived, appears to be actively maintained, suggesting a stable, feature-complete API for `blake3-wasm`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates asynchronous initialization, one-shot hashing, and incremental hashing using `createHasher` for larger data streams, including custom output lengths.

import { init, hash, createHasher } from 'blake3-wasm';

async function runBlake3Example() {
  console.log('Initializing BLAKE3 WebAssembly module...');
  await init();
  console.log('BLAKE3 module initialized.');

  // --- One-shot hashing ---
  const dataOneShot = new TextEncoder().encode('Hello, BLAKE3!');
  const hashResult = hash(dataOneShot);
  console.log('One-shot hash (Uint8Array):', hashResult);
  console.log('One-shot hash (hex):', Array.from(hashResult).map(b => b.toString(16).padStart(2, '0')).join(''));

  // --- Incremental hashing ---
  const hasher = createHasher();
  const chunk1 = new TextEncoder().encode('This is the first part');
  const chunk2 = new TextEncoder().encode(' and this is the second part.');

  hasher.update(chunk1);
  hasher.update(chunk2);

  const streamingHashResult = hasher.digest();
  console.log('Streaming hash (Uint8Array):', streamingHashResult);
  console.log('Streaming hash (hex):', Array.from(streamingHashResult).map(b => b.toString(16).padStart(2, '0')).join(''));

  // Example with custom output length (e.g., 16 bytes)
  const customLengthHash = hash(new TextEncoder().encode('Short hash example'), { length: 16 });
  console.log('Custom length hash (16 bytes hex):', Array.from(customLengthHash).map(b => b.toString(16).padStart(2, '0')).join(''));
}

runBlake3Example().catch(console.error);

view raw JSON →