Browse Source

txb: add fixes for P2SH(P2WSH(...)) and P2WSH(...) in BIP143 compliance

hk-custom-address
Daniel Cousens 7 years ago
parent
commit
7be698b5a1
  1. 8
      src/transaction_builder.js

8
src/transaction_builder.js

@ -708,8 +708,12 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
var signed = input.pubKeys.some(function (pubKey, i) {
if (!kpPubKey.equals(pubKey)) return false
if (input.signatures[i]) throw new Error('Signature already exists')
if (kpPubKey.length !== 33 &&
input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
if (kpPubKey.length !== 33 && (
input.signType === scriptTypes.P2WPKH ||
input.redeemScriptType === scriptTypes.P2WSH ||
input.prevOutType === scriptTypes.P2WSH
)) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
var signature = keyPair.sign(signatureHash)
if (Buffer.isBuffer(signature)) signature = ECSignature.fromRSBuffer(signature)

Loading…
Cancel
Save