How to use the bcrypto/lib/blake2b.multi function in bcrypto

To help you get started, we’ve selected a few bcrypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github handshake-org / hsd / lib / mining / mine.js View on Github external
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];
}
github handshake-org / hsd / test / util / memwallet.js View on Github external
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);
  }
github handshake-org / hsd / lib / net / bip152.js View on Github external
getKey() {
    const hash = blake2b.multi(this.toHead(), this.keyNonce);
    return hash.slice(0, 16);
  }
github handshake-org / hsd / lib / wallet / wallet.js View on Github external
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);
  }