High-performance hash functions for JavaScript/TypeScript, powered by Rust and WebAssembly.
- BLAKE3 — fast cryptographic hash with streaming support
- SHA-256 — industry-standard hash and HMAC-SHA256
- Streaming — incremental hashing via
Hasherinterface and async iterables - Synchronous WASM — WASM is inlined as base64, no async loading required
- Cross-platform — works in Node.js, Deno, Bun, and browsers
- TypeScript-first — full type definitions with
Uint8ArrayI/O - TC39 Explicit Resource Management —
Symbol.disposesupport
| Package | NPM | Description |
|---|---|---|
@hashbuf/blake3 |
BLAKE3 hash, double hash, keyed MAC, streaming | |
@hashbuf/sha256 |
SHA-256 hash, double hash, HMAC-SHA256, streaming | |
@hashbuf/types |
Shared Hasher and HashAlgorithm interfaces |
npm install @hashbuf/blake3
# or
npm install @hashbuf/sha256import { blake3, blake3Hex } from '@hashbuf/blake3';
import { sha256, sha256Hex } from '@hashbuf/sha256';
const data = new TextEncoder().encode('hello');
const b3 = blake3(data); // Uint8Array (32 bytes)
const b3h = blake3Hex(data); // hex string (64 chars)
const s2 = sha256(data); // Uint8Array (32 bytes)
const s2h = sha256Hex(data); // hex string (64 chars)import { Blake3Hasher } from '@hashbuf/blake3';
const hasher = new Blake3Hasher();
hasher.update(chunk1);
hasher.update(chunk2);
const hash = hasher.finalize(); // 32 bytes, non-consumptive
hasher.free(); // release WASM memoryWith consumptive digest() — auto-frees the hasher:
const hasher = new Blake3Hasher();
hasher.update(data);
const hex = hasher.digest('hex'); // hex string, single WASM callOr with TC39 Explicit Resource Management:
using hasher = new Blake3Hasher();
hasher.update(data);
const hash = hasher.finalize();
// automatically freed when leaving scopeimport { blake3Stream } from '@hashbuf/blake3';
const hash = await blake3Stream(readableStream);import { BLAKE3 } from '@hashbuf/blake3';
import { SHA256 } from '@hashbuf/sha256';
function hashWith(algo: HashAlgorithm, data: Uint8Array): Uint8Array {
return algo.hash(data);
}
hashWith(BLAKE3, data);
hashWith(SHA256, data);- Node.js >= 25.0.0
- pnpm
- Rust toolchain with
wasm-pack
# Install dependencies
pnpm install
# Build everything (Rust → WASM → TypeScript)
pnpm run build:all
# Or step by step:
pnpm run build:rust # Compile Rust to WASM
pnpm run sync:from-rust # Copy WASM to TS packages
pnpm run build # Inline WASM + compile TypeScriptpnpm testpnpm run check # Biome lint + formathashbuf/
├── rust/ # Rust workspace
│ ├── blake3/ # BLAKE3 Rust crate
│ └── sha256/ # SHA-256 Rust crate
└── packages/ # TypeScript pnpm monorepo
├── blake3/ # @hashbuf/blake3
├── sha256/ # @hashbuf/sha256
└── types/ # @hashbuf/types
Each hash package follows this pipeline:
- Rust → compile with
wasm-packto produce WASM + JS bindings - Inline → encode WASM binary as base64 for synchronous loading
- TypeScript → wrap with type-safe API and streaming support
Apache-2.0