How to use the bcrypto/lib/blake2b.digest 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 / primitives / tx.js View on Github external
const {base, witness} = this.getSizes();
    const raw = this.encode();

    assert(raw.length === base + witness);

    // Normal data.
    const ndata = raw.slice(0, base);

    // Witness data.
    const wdata = raw.slice(base, base + witness);

    // Left = HASH(normal-data) = normal txid
    const hash = blake2b.digest(ndata);

    // Right = HASH(witness-data)
    const wdhash = blake2b.digest(wdata);

    // WTXID = HASH(normal-txid || witness-data-hash)
    const whash = blake2b.root(hash, wdhash);

    if (!this.mutable) {
      this._hash = hash;
      this._wdhash = wdhash;
      this._whash = whash;
    }

    return [hash, wdhash, whash];
  }
github handshake-org / hsd / lib / protocol / cuckoo.js View on Github external
sipkey(hdr) {
    const hash = blake2b.digest(hdr, 32);

    // Legacy hashing only uses the first 128 bits.
    if (this.siphash32 === siphash32)
      return hash.slice(0, 16);

    return hash;
  }
github handshake-org / bcuckoo / lib / cuckoo.js View on Github external
sipkey(hdr) {
    const hash = blake2b.digest(hdr, 32);

    // Legacy hashing only uses the first 128 bits.
    if (this.siphash32 === siphash32)
      return hash.slice(0, 16);

    return hash;
  }
github handshake-org / faucet-tool / lib / address.js View on Github external
fromWitness(witness) {
    const [, pk] = witness.getPubkeyhashInput();

    // We're pretty much screwed here
    // since we can't get the version.
    if (pk) {
      this.hash = blake2b.digest(pk, 20);
      this.version = 0;
      return this;
    }

    const redeem = witness.getScripthashInput();

    if (redeem) {
      this.hash = blake2b.digest(redeem);
      this.version = 0;
      return this;
    }

    return null;
  }
github handshake-org / hsd / lib / node / rpc.js View on Github external
throw new RPCError(errs.TYPE_ERROR, 'Invalid parameters.');

    const addr = parseAddress(b58, this.network);

    if (addr.version !== 0 || addr.hash.length !== 20)
      return false;

    const msg = Buffer.from(MAGIC_STRING + str, 'utf8');
    const hash = blake2b.digest(msg);

    const key = secp256k1.recover(hash, sig, 0, true);

    if (!key)
      return false;

    return safeEqual(blake2b.digest(key, 20), addr.hash);
  }
github handshake-org / hs-airdrop / lib / proof.js View on Github external
verifyMerkle(expect) {
    if (expect == null) {
      expect = this.isAddress()
        ? FAUCET_ROOT
        : AIRDROP_ROOT;
    }

    assert(Buffer.isBuffer(expect));
    assert(expect.length === 32);

    const {subproof, subindex} = this;
    const {proof, index} = this;
    const leaf = blake2b.digest(this.key);

    if (this.isAddress()) {
      const root = merkle.deriveRoot(blake2b, leaf, proof, index);

      return root.equals(expect);
    }

    const subroot = merkle.deriveRoot(blake2b, leaf, subproof, subindex);
    const root = merkle.deriveRoot(blake2b, subroot, proof, index);

    return root.equals(expect);
  }
github handshake-org / hsd / lib / wallet / wallet.js View on Github external
getToken(nonce) {
    if (!this.master.key)
      throw new Error('Cannot derive token.');

    const key = this.master.key.derive(44, true);

    const bw = bio.write(36);
    bw.writeBytes(key.privateKey);
    bw.writeU32(nonce);

    return blake2b.digest(bw.render());
  }
github handshake-org / hsd / lib / covenants / rules.js View on Github external
rules.blind = function blind(value, nonce) {
  assert(Number.isSafeInteger(value) && value >= 0);
  assert(Buffer.isBuffer(nonce) && nonce.length === 32);

  const bw = bio.write(40);
  bw.writeU64(value);
  bw.writeBytes(nonce);

  return blake2b.digest(bw.render());
};
github handshake-org / hsd / lib / primitives / airdropproof.js View on Github external
verifyMerkle(expect) {
    if (expect == null) {
      expect = this.isAddress()
        ? FAUCET_ROOT
        : AIRDROP_ROOT;
    }

    assert(Buffer.isBuffer(expect));
    assert(expect.length === 32);

    const {subproof, subindex} = this;
    const {proof, index} = this;
    const leaf = blake2b.digest(this.key);

    if (this.isAddress()) {
      const root = merkle.deriveRoot(blake2b, leaf, proof, index);

      return root.equals(expect);
    }

    const subroot = merkle.deriveRoot(blake2b, leaf, subproof, subindex);
    const root = merkle.deriveRoot(blake2b, subroot, proof, index);

    return root.equals(expect);
  }