From 7be698b5a17ded3121376cfea4770ce2556c518d Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 17 Jan 2018 14:49:19 +1100 Subject: [PATCH] txb: add fixes for P2SH(P2WSH(...)) and P2WSH(...) in BIP143 compliance --- src/transaction_builder.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index f0f9efe..e5e4b2c 100644 --- a/src/transaction_builder.js +++ b/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)