mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 11:35:40 +01:00
core: Add TaprootWitness.sigVersion
(#5954)
* core: Add TaprootWitness.sigVersion * Remove uneeded pattern match * Be more precise with types
This commit is contained in:
parent
6287e41281
commit
6d240d5c54
2 changed files with 21 additions and 6 deletions
|
@ -448,12 +448,8 @@ case class TaprootTxSigComponent(
|
|||
|
||||
override val witnessVersion: WitnessVersion1.type = WitnessVersion1
|
||||
|
||||
override def sigVersion: SigVersionTaproot = {
|
||||
witness match {
|
||||
case _: TaprootKeyPath => SigVersionTaprootKeySpend
|
||||
case _: TaprootScriptPath | _: TaprootUnknownPath => SigVersionTapscript
|
||||
}
|
||||
}
|
||||
override def sigVersion: SigVersionTaproot = witness.sigVersion
|
||||
|
||||
}
|
||||
|
||||
object BaseTxSigComponent {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.protocol.CompactSizeUInt
|
||||
import org.bitcoins.core.protocol.script.LeafVersion.UnknownLeafVersion
|
||||
import org.bitcoins.core.script.constant.{OP_0, ScriptNumberOperation}
|
||||
import org.bitcoins.core.serializers.script.{
|
||||
RawScriptWitnessParser,
|
||||
|
@ -236,6 +237,8 @@ sealed trait TaprootWitness extends ScriptWitness {
|
|||
CryptoUtil.sha256(cmpct.bytes ++ annex)
|
||||
}
|
||||
}
|
||||
|
||||
def sigVersion: SigVersionTaproot
|
||||
}
|
||||
|
||||
object TaprootWitness extends Factory[TaprootWitness] {
|
||||
|
@ -277,6 +280,9 @@ case class TaprootKeyPath(
|
|||
Vector(signature.bytes)
|
||||
}
|
||||
}
|
||||
|
||||
override def sigVersion: SigVersionTaprootKeySpend.type =
|
||||
SigVersionTaprootKeySpend
|
||||
}
|
||||
|
||||
object TaprootKeyPath extends Factory[TaprootKeyPath] {
|
||||
|
@ -401,6 +407,14 @@ case class TaprootScriptPath(stack: Vector[ByteVector]) extends TaprootWitness {
|
|||
* defined as in BIP340. Fail if this point is not on the curve.
|
||||
*/
|
||||
def p: XOnlyPubKey = controlBlock.p
|
||||
|
||||
def leafVersion: LeafVersion = controlBlock.leafVersion
|
||||
|
||||
override def sigVersion: SigVersionTapscript.type = leafVersion match {
|
||||
case LeafVersion.Tapscript => SigVersionTapscript
|
||||
case UnknownLeafVersion(toByte) =>
|
||||
sys.error(s"Unknown leaf version=$toByte, cannot determine sigVersion")
|
||||
}
|
||||
}
|
||||
|
||||
object TaprootScriptPath extends Factory[TaprootScriptPath] {
|
||||
|
@ -567,4 +581,9 @@ case class TaprootUnknownPath(stack: Vector[ByteVector])
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
override def sigVersion: SigVersionTaproot = {
|
||||
// default to tapscript for unknown leafver and sigversion?
|
||||
SigVersionTapscript
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue