1.0.15 • Published 6 months ago

@blackhan-software/wasm-miner v1.0.15

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
6 months ago

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

Copyright

© 2023 Blackhan Software Ltd

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago