mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-18 21:34:39 +01:00
Tighten P2WSHWitnessSPKV0.apply() to only take RawScriptPubKey (#5509)
This commit is contained in:
parent
4ae9067083
commit
790327639a
@ -1410,7 +1410,7 @@ object P2WSHWitnessSPKV0 extends ScriptFactory[P2WSHWitnessSPKV0] {
|
||||
fromAsm(Seq(OP_0) ++ pushop ++ Seq(ScriptConstant(hash.bytes)))
|
||||
}
|
||||
|
||||
def apply(spk: ScriptPubKey): P2WSHWitnessSPKV0 = {
|
||||
def apply(spk: RawScriptPubKey): P2WSHWitnessSPKV0 = {
|
||||
require(
|
||||
BitcoinScriptUtil.isOnlyCompressedPubKey(spk),
|
||||
s"Public key must be compressed to be used in a segwit script, see BIP143")
|
||||
|
@ -378,7 +378,16 @@ case class PSBT(
|
||||
OutputPSBTRecord.RedeemScript(redeemScript)
|
||||
}
|
||||
case p2wsh: P2WSHWitnessSPKV0 =>
|
||||
val scriptHash = P2WSHWitnessSPKV0(redeemScript).scriptHash
|
||||
val scriptHash = {
|
||||
redeemScript match {
|
||||
case raw: RawScriptPubKey => P2WSHWitnessSPKV0(raw).scriptHash
|
||||
case nonraw @ (_: P2SHScriptPubKey | _: P2WPKHWitnessSPKV0 |
|
||||
_: TaprootScriptPubKey | _: UnassignedWitnessScriptPubKey |
|
||||
_: P2WSHWitnessSPKV0) =>
|
||||
throw new IllegalArgumentException(
|
||||
s"Cannot make p2wsh from non raw spk=$nonraw")
|
||||
}
|
||||
}
|
||||
if (scriptHash != p2wsh.scriptHash) {
|
||||
throw new IllegalArgumentException(
|
||||
s"The given script's hash does not match the expected script has, got: $scriptHash, expected ${p2wsh.scriptHash}")
|
||||
|
@ -346,7 +346,7 @@ sealed abstract class ScriptGenerators {
|
||||
|
||||
/** Generates a random P2WSHWitnessSPKV0 as well as it's corresponding private keys and redeem script */
|
||||
def p2wshSPKV0: Gen[(P2WSHWitnessSPKV0, Seq[ECPrivateKey], ScriptPubKey)] =
|
||||
randomNonP2SHScriptPubKey
|
||||
rawScriptPubKey
|
||||
.suchThat { case (spk, _) =>
|
||||
!redeemScriptTooBig(spk)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user