TxBuilder: restrict uncompressed keyPairs for P2WPK and P2WSH
This commit is contained in:
parent
3ffac6cd39
commit
3ba17a1479
2 changed files with 25 additions and 1 deletions
|
@ -693,6 +693,8 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
|
||||||
var signed = input.pubKeys.some(function (pubKey, i) {
|
var signed = input.pubKeys.some(function (pubKey, i) {
|
||||||
if (!kpPubKey.equals(pubKey)) return false
|
if (!kpPubKey.equals(pubKey)) return false
|
||||||
if (input.signatures[i]) throw new Error('Signature already exists')
|
if (input.signatures[i]) throw new Error('Signature already exists')
|
||||||
|
if (!keyPair.compressed &&
|
||||||
|
input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
|
||||||
|
|
||||||
input.signatures[i] = keyPair.sign(signatureHash).toScriptSignature(hashType)
|
input.signatures[i] = keyPair.sign(signatureHash).toScriptSignature(hashType)
|
||||||
return true
|
return true
|
||||||
|
|
24
test/fixtures/transaction_builder.json
vendored
24
test/fixtures/transaction_builder.json
vendored
|
@ -401,7 +401,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"description": "Transaction w/ P2WSH|P2PK -> P2PKH",
|
"description": "Transaction w/ P2WSH|P2PK -> P2PKH",
|
||||||
"txHex": "010000000001014533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02473044022039725bb7291a14dd182dafdeaf3ea0d5c05c34f4617ccbaa46522ca913995c4e02203b170d072ed2e489e7424ad96d8fa888deb530be2d4c5d9aaddf111a7efdb2d3012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
|
"txHex": "010000000001014533a3bc1e039bd787656068e135aaee10aee95a64776bfc047ee6a7c1ebdd2f0000000000ffffffff0160ea0000000000001976a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac02473044022039725bb7291a14dd182dafdeaf3ea0d5c05c34f4617ccbaa46522ca913995c4e02203b170d072ed2e489e7424ad96d8fa888deb530be2d4c5d9aaddf111a7efdb2d3012321038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac00000000",
|
||||||
|
@ -1838,6 +1837,29 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"exception": "BIP143 rejects uncompressed public keys in P2WPKH or P2WSH",
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||||
|
"vout": 0,
|
||||||
|
"prevTxScript": "OP_0 15a71ffa7b5bb70cddefcf364494071022efe390",
|
||||||
|
"signs": [
|
||||||
|
{
|
||||||
|
"keyPair": "5JiHJJjdufSiMxbvnyNcKtQNLYH6SvUpQnRv9yZENFDWTQKQkzC",
|
||||||
|
"value": 10000,
|
||||||
|
"throws": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"script": "OP_0 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5",
|
||||||
|
"value": 10000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"exception": "RedeemScript not supported \"OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474\"",
|
"exception": "RedeemScript not supported \"OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474\"",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
|
Loading…
Reference in a new issue