Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function mine(raw, target, rounds) {
const hdr = Headers.fromMiner(raw);
const data = hdr.toPrehead();
const pad8 = hdr.padding(8);
const pad32 = hdr.padding(32);
let nonce = 0;
// The heart and soul of the miner: match the target.
for (let i = 0; i < rounds; i++) {
const left = BLAKE2b.digest(data, 64);
const right = SHA3.multi(data, pad8);
const hash = BLAKE2b.multi(left, pad32, right);
if (hash.compare(target) <= 0)
return [nonce, true];
nonce += 1;
bio.writeU32(data, nonce, 0);
}
return [nonce, false];
}
generateNonce(nameHash, address, value) {
const path = this.getPath(address.hash);
if (!path)
throw new Error('Account not found.');
const hi = (value * (1 / 0x100000000)) >>> 0;
const lo = value >>> 0;
const index = (hi ^ lo) & 0x7fffffff;
const {publicKey} = this.master.derive(index);
return blake2b.multi(address.hash, publicKey, nameHash);
}
getKey() {
const hash = blake2b.multi(this.toHead(), this.keyNonce);
return hash.slice(0, 16);
}
if (!path)
throw new Error('Account not found.');
const account = await this.getAccount(path.account);
if (!account)
throw new Error('Account not found.');
const hi = (value * (1 / 0x100000000)) >>> 0;
const lo = value >>> 0;
const index = (hi ^ lo) & 0x7fffffff;
const {publicKey} = account.accountKey.derive(index);
return blake2b.multi(address.hash, publicKey, nameHash);
}