1.0.15 • Published 2 years ago
@blackhan-software/wasm-miner v1.0.15
WASM Miner with Keccak-256
Installation
npm install @blackhan-software/wasm-minerUsage
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 installLint
npm run -- lint [--fix]Build
npm run build # requires dockerTest
npm testClean
npm run cleanCopyright
© 2023 Blackhan Software Ltd