SHA-1 for WebAssembly
WebAssembly port of RustCrypto's SHA-1, a Rust implementations of SHA-1 hashing.
npm i @hazae41/morax
Next.js CodeSandbox 🪣 • Deno CodeSandbox 🪣 • Node CodeSandbox 🪣
Use case
This WebAssembly module is useful when you want to use SHA-1 incrementially, as WebCrypto doesn't support incremental hashing, and want good performances.
Performances | Incremental hashing | |
---|---|---|
Morax | ⭐️⭐️⭐️⭐️ | ✅ |
WebCrypto | ⭐️⭐️⭐️⭐️⭐️ | ❌ |
JavaScript | ⭐️⭐️⭐️ | ✅ |
Usage
import * as Morax from "@hazae41/morax";
import { Sha1Hasher } from "@hazae41/morax";
// Wait for WASM to load
Morax.initSyncBundledOnce()
// Create a hash
const hasher = new Sha1Hasher()
// Data to be hashed
const hello = new TextEncoder().encode("Hello World")
// Update the hash with your data
hasher.update(hello)
// Grab the digest (20 bytes)
const digest = hasher.finalize()
// Update the hash another time
hasher.update(hello)
// Grab the digest (20 bytes)
const digest2 = hasher.finalize()
// digest !== digest2
console.log(digest)
console.log(digest2)
Building
- Install Deno
- Install binaryen (for wasm-opt) and add it your PATH
https://github.com/WebAssembly/binaryen/releases
- Install wasm-pack
cargo install wasm-pack
- Install dependencies
npm install
- Build wasm and module
npm run build