WASM Miner with Keccak-256
Installation
npm install @blackhan-software/wasm-miner
Usage
import { KeccakHasher, keccak } from '@blackhan-software/wasm-miner';
Prepare a long enough input data array of bytes:
const encoder = new TextEncoder();
const data = encoder.encode('data:0000000000000000');
Digest data using the Keccak 256-bit algorithm:
const hasher = await KeccakHasher();
const digest: Uint8Array = hasher.digest(data);
console.assert(digest.length === 32);
const hashed: Uint8Array = await keccak(data);
console.assert(hashed.length === 32);
Reduce data over range
invoking callback
if hash
of nonce
has enough leading zeros
:
const hasher = await KeccakHasher();
const hashed: Uint8Array = hasher.reduce(data, {
// invoked in reduction (default: ()=>{})
callback: (
nonce: bigint, zeros: number, hash: Uint8Array
) => {
console.assert(nonce >= 0 && nonce < 1e6);
console.assert(hash.length === 32);
console.assert(zeros >= 4);
},
// [min_nonce, max_nonce] (default: [0n, 1n])
range: [BigInt(0), BigInt(1e6)],
// callback filter (default: 0)
zeros: 4
});
console.assert(hashed.length == 32);
Development
Installation
npm install
Lint
npm run -- lint [--fix]
Build
npm run build # requires docker
Test
npm test
Clean
npm run clean
Copyright
© 2023 Blackhan Software Ltd