Skip to content

Commit 7be698b

Browse files
committed
txb: add fixes for P2SH(P2WSH(...)) and P2WSH(...) in BIP143 compliance
1 parent 39a681d commit 7be698b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/transaction_builder.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,12 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
708708
var signed = input.pubKeys.some(function (pubKey, i) {
709709
if (!kpPubKey.equals(pubKey)) return false
710710
if (input.signatures[i]) throw new Error('Signature already exists')
711-
if (kpPubKey.length !== 33 &&
712-
input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
711+
712+
if (kpPubKey.length !== 33 && (
713+
input.signType === scriptTypes.P2WPKH ||
714+
input.redeemScriptType === scriptTypes.P2WSH ||
715+
input.prevOutType === scriptTypes.P2WSH
716+
)) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
713717

714718
var signature = keyPair.sign(signatureHash)
715719
if (Buffer.isBuffer(signature)) signature = ECSignature.fromRSBuffer(signature)

0 commit comments

Comments
 (0)