How to use the bcrypto/lib/sha3.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 / script / script.js View on Github external
const stack = witness.toStack();

    let redeem = null;

    if (addr.version === 0) {
      if (addr.hash.length === 32) {
        if (stack.length === 0)
          throw new ScriptError('WITNESS_PROGRAM_WITNESS_EMPTY');

        const witnessScript = stack.pop();

        if (witnessScript.length > consensus.MAX_SCRIPT_SIZE)
          throw new ScriptError('SCRIPT_SIZE');

        if (!sha3.digest(witnessScript).equals(addr.hash))
          throw new ScriptError('WITNESS_PROGRAM_MISMATCH');

        redeem = Script.decode(witnessScript);
      } else if (addr.hash.length === 20) {
        if (stack.length !== 2)
          throw new ScriptError('WITNESS_PROGRAM_MISMATCH');

        redeem = Script.fromPubkeyhash(addr.hash);
      } else {
        // Failure on version=0 (bad program data length).
        throw new ScriptError('WITNESS_PROGRAM_WRONG_LENGTH');
      }
    } else {
      if (flags & Script.flags.VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM)
        throw new ScriptError('DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM');
      return;
github handshake-org / hsd / lib / covenants / reserved-browser.js View on Github external
function hashName(name) {
  const raw = Buffer.from(name.toLowerCase(), 'ascii');
  return sha3.digest(raw);
}
github handshake-org / hsd / lib / script / script.js View on Github external
sha3() {
    return sha3.digest(this.encode());
  }
github handshake-org / hsd / lib / covenants / rules.js View on Github external
rules.hashBinary = function hashBinary(name) {
  assert(Buffer.isBuffer(name));
  assert(rules.verifyBinary(name));
  return sha3.digest(name);
};
github handshake-org / hsd / lib / covenants / reserved.js View on Github external
function hashName(name) {
  const raw = Buffer.from(name.toLowerCase(), 'ascii');
  return sha3.digest(raw);
}
github handshake-org / hsd / lib / primitives / address.js View on Github external
fromWitness(witness) {
    const [, pk] = witness.getPubkeyhashInput();

    if (pk) {
      this.hash = blake2b.digest(pk, 20);
      this.version = 0;
      return this;
    }

    const redeem = witness.getScripthashInput();

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

    return null;
  }
github handshake-org / bcuckoo / lib / cuckoo.js View on Github external
sha3(enc) {
    const hash = sha3.digest(this.proof);
    if (enc === 'hex')
      return hash.toString('hex');
    return hash;
  }
github handshake-org / hs-airdrop / lib / key.js View on Github external
key.tweak = s_prime;

        return [s_prime, key];
      }

      case keyTypes.P256: {
        let tweak;

        do {
          tweak = SHA256.digest(random.randomBytes(64));
        } while (!p256.privateKeyVerify(tweak));

        const key = this.clone();

        key.point = p256.publicKeyTweakMul(this.point, tweak);
        key.nonce = SHA3.digest(tweak);
        key.tweak = tweak;

        return [tweak, key];
      }

      case keyTypes.ED25519: {
        const raw = SHA256.digest(random.randomBytes(64));
        const tweak = ed25519.scalarClamp(raw);
        const key = this.clone();

        key.point = ed25519.publicKeyTweakMul(this.point, tweak);
        key.nonce = SHA3.digest(tweak);
        key.tweak = tweak;

        return [tweak, key];
      }
github handshake-org / hsd / lib / primitives / address.js View on Github external
fromScript(script) {
    assert(script && typeof script.encode === 'function');
    return this.fromHash(sha3.digest(script.encode()), 0);
  }