Skip to content

Commit 3ba17a1

Browse files
committed
TxBuilder: restrict uncompressed keyPairs for P2WPK and P2WSH
1 parent 3ffac6c commit 3ba17a1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/transaction_builder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
693693
var signed = input.pubKeys.some(function (pubKey, i) {
694694
if (!kpPubKey.equals(pubKey)) return false
695695
if (input.signatures[i]) throw new Error('Signature already exists')
696+
if (!keyPair.compressed &&
697+
input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
696698

697699
input.signatures[i] = keyPair.sign(signatureHash).toScriptSignature(hashType)
698700
return true

test/fixtures/transaction_builder.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@
401401
}
402402
]
403403
},
404-
405404
{
406405
"description": "Transaction w/ P2WSH|P2PK -> P2PKH",
407406
"txHex": "010000000001014533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02473044022039725bb7291a14dd182dafdeaf3ea0d5c05c34f4617ccbaa46522ca913995c4e02203b170d072ed2e489e7424ad96d8fa888deb530be2d4c5d9aaddf111a7efdb2d3012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
@@ -1838,6 +1837,29 @@
18381837
}
18391838
]
18401839
},
1840+
{
1841+
"exception": "BIP143 rejects uncompressed public keys in P2WPKH or P2WSH",
1842+
"inputs": [
1843+
{
1844+
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
1845+
"vout": 0,
1846+
"prevTxScript": "OP_0 15a71ffa7b5bb70cddefcf364494071022efe390",
1847+
"signs": [
1848+
{
1849+
"keyPair": "5JiHJJjdufSiMxbvnyNcKtQNLYH6SvUpQnRv9yZENFDWTQKQkzC",
1850+
"value": 10000,
1851+
"throws": true
1852+
}
1853+
]
1854+
}
1855+
],
1856+
"outputs": [
1857+
{
1858+
"script": "OP_0 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5",
1859+
"value": 10000
1860+
}
1861+
]
1862+
},
18411863
{
18421864
"exception": "RedeemScript not supported \"OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474\"",
18431865
"inputs": [

0 commit comments

Comments
 (0)