Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
function hashName(name) {
const raw = Buffer.from(name.toLowerCase(), 'ascii');
return sha3.digest(raw);
}
sha3() {
return sha3.digest(this.encode());
}
rules.hashBinary = function hashBinary(name) {
assert(Buffer.isBuffer(name));
assert(rules.verifyBinary(name));
return sha3.digest(name);
};
function hashName(name) {
const raw = Buffer.from(name.toLowerCase(), 'ascii');
return sha3.digest(raw);
}
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;
}
sha3(enc) {
const hash = sha3.digest(this.proof);
if (enc === 'hex')
return hash.toString('hex');
return hash;
}
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];
}
fromScript(script) {
assert(script && typeof script.encode === 'function');
return this.fromHash(sha3.digest(script.encode()), 0);
}