diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 14b6ce53..6b7a3f19 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -735,9 +735,6 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type TX.prototype.checksig = function checksig(index, prev, value, sig, key, version) { var type, hash; - if (type == null) - type = Script.hashType.ALL; - if (sig.length === 0) return false; @@ -754,6 +751,7 @@ TX.prototype.checksig = function checksig(index, prev, value, sig, key, version) * (in the case of witnesspubkeyhash, this should be the generated * p2pkh script). * @param {Amount} value - Previous output value. + * @param {Buffer} key * @param {SighashType} type * @param {Number} version - Sighash version (0=legacy, 1=segwit). * @returns {Buffer} Signature in DER format. @@ -765,6 +763,9 @@ TX.prototype.signature = function signature(index, prev, value, key, type, versi if (type == null) type = Script.hashType.ALL; + if (version == null) + version = 0; + hash = this.signatureHash(index, prev, value, type, version); sig = ec.sign(hash, key);