@blackhan-software/wasm-miner
TypeScript icon, indicating that this package has built-in type declarations

1.0.15 • Public • Published

WASM Miner with Keccak-256

npm package CI Main codecov

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

© 2023 Blackhan Software Ltd

Readme

Keywords

Package Sidebar

Install

npm i @blackhan-software/wasm-miner

Weekly Downloads

1

Version

1.0.15

License

GPL-3.0

Unpacked Size

139 kB

Total Files

34

Last publish

Collaborators

  • hsk81