@rasmx/blake3
v1.0.1
Published
The fastest BLAKE3 implementation for the Web. Rust/WASM powered, SIMD accelerated, Zero-Allocation architecture.
Downloads
184
Maintainers
Readme
@rasmx/blake3 ⚡️
The definitive BLAKE3 implementation for WebAssembly.
600+ MB/s of pure hashing power. Up to 40x faster than pure JS implementations.
Rasmx is a high-performance cryptographic library written in Rust and compiled to WebAssembly with manual SIMD128 optimizations. It bypasses traditional JS-to-WASM overhead using a Zero-Copy architecture.
🚀 Performance
| Algorithm | Engine | 10MB Throughput | Speedup | | :--- | :--- | :--- | :--- | | BLAKE3 | @rasmx/blake3 | ~670 MB/s | 35x | | BLAKE3 | @noble/hashes | ~19 MB/s | 1x | | SHA256 | WebCrypto (Native) | ~250 MB/s | 0.4x |
Tested on modern x86_64/ARM64 hardware in Chromium-based browsers.
🛠 Features
- SIMD Accelerated: Hand-crafted for WebAssembly SIMD instructions.
- Zero-Copy Architecture: Access WASM memory directly to avoid expensive data cloning.
- Zero-Allocation: No garbage collection overhead; contexts are managed in a static slab.
- Synchronous Execution: Once initialized, all calls are 100% synchronous.
- Streaming API: Efficiently process gigabytes of data in chunks.
📦 Installation
pnpm add @rasmx/blake3📖 Quick Start
The "God Mode" (Zero-Copy)
For maximum performance, write your data directly into the WASM buffer.
import { init, getBuffer, hashInplace } from '@rasmx/blake3';
await init();
const dataSize = 1024 * 1024; // 1MB
const buffer = getBuffer(dataSize);
// Fill the buffer directly (e.g., from a File or Stream)
// No .set() or extra copies!
for (let i = 0; i < dataSize; i++) {
buffer[i] = i & 0xff;
}
const result = hashInplace(dataSize);Simple One-Shot
Standard usage with automatic data copying.
import { init, hash } from '@rasmx/blake3';
await init();
const digest = hash(myUint8Array);Streaming API
Process data without loading it all into memory.
import { init, Hasher, getBuffer } from '@rasmx/blake3';
await init();
const hasher = new Hasher();
// Chunk 1
const buf1 = getBuffer(1024);
buf1.set(chunk1);
hasher.update(1024);
// Chunk 2
const buf2 = getBuffer(2048);
buf2.set(chunk2);
hasher.update(2048);
const finalHash = hasher.digest();🏗 Architecture
Rasmx uses a "Static Slab Allocation" strategy. It reserves 16 independent hashing contexts in the WASM linear memory at compile-time. This ensures that even with complex streaming, no memory allocation or deallocation occurs during runtime, preventing memory fragmentation and GC pauses.
License
MIT © Rasmx Team
