mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-18 21:34:39 +01:00
refactor: Use ECDigitalSignature.appendHashType() throughout codebase (#5761)
This commit is contained in:
parent
39e23c2a09
commit
d255914765
@ -80,8 +80,7 @@ sealed abstract class TransactionSignatureCreator {
|
||||
taprootOptions = TaprootSerializationOptions.empty)
|
||||
val signature = sign(hash.bytes)
|
||||
// append 1 byte hash type onto the end
|
||||
val sig = signature.map(s =>
|
||||
ECDigitalSignature(s.bytes ++ ByteVector.fromByte(hashType.byte)))
|
||||
val sig = signature.map(_.appendHashType(hashType))
|
||||
sig.map { s =>
|
||||
require(
|
||||
s.isStrictEncoded,
|
||||
|
@ -134,15 +134,14 @@ trait Sign extends AsyncSign {
|
||||
bytes: ByteVector,
|
||||
hashType: HashType): ECDigitalSignature = {
|
||||
val sigNoHashType = sign(bytes)
|
||||
sigNoHashType.copy(bytes =
|
||||
sigNoHashType.bytes ++ ByteVector.fromByte(hashType.byte))
|
||||
sigNoHashType.appendHashType(hashType)
|
||||
}
|
||||
|
||||
def signLowRWithHashType(
|
||||
bytes: ByteVector,
|
||||
hashType: HashType): ECDigitalSignature = {
|
||||
val lowR = signLowR(bytes)
|
||||
lowR.copy(lowR.bytes ++ ByteVector.fromByte(hashType.byte))
|
||||
lowR.appendHashType(hashType)
|
||||
}
|
||||
override def asyncSign(bytes: ByteVector): Future[ECDigitalSignature] = {
|
||||
Future.successful(sign(bytes))
|
||||
|
@ -25,7 +25,6 @@ import org.bitcoins.crypto.{
|
||||
HashType
|
||||
}
|
||||
import org.scalacheck.Gen
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.concurrent.duration.DurationInt
|
||||
@ -50,9 +49,7 @@ sealed abstract class ScriptGenerators {
|
||||
for {
|
||||
sig <- CryptoGenerators.digitalSignature
|
||||
hashType <- CryptoGenerators.hashType
|
||||
digitalSignature = ECDigitalSignature(
|
||||
sig.bytes ++ ByteVector.fromByte(hashType.byte)
|
||||
)
|
||||
digitalSignature = sig.appendHashType(hashType)
|
||||
} yield P2PKScriptSignature(digitalSignature)
|
||||
|
||||
def p2pkhScriptSignature: Gen[P2PKHScriptSignature] =
|
||||
@ -60,9 +57,8 @@ sealed abstract class ScriptGenerators {
|
||||
privKey <- CryptoGenerators.privateKey
|
||||
hash <- CryptoGenerators.doubleSha256Digest
|
||||
hashType <- CryptoGenerators.hashType
|
||||
signature = ECDigitalSignature.fromBytes(
|
||||
privKey.sign(hash).bytes ++ ByteVector.fromByte(hashType.byte)
|
||||
)
|
||||
signature = privKey.sign(hash).appendHashType(hashType)
|
||||
|
||||
} yield P2PKHScriptSignature(signature, privKey.publicKey)
|
||||
|
||||
def p2pkWithTimeoutScriptSignature: Gen[ConditionalScriptSignature] =
|
||||
@ -70,9 +66,7 @@ sealed abstract class ScriptGenerators {
|
||||
privKey <- CryptoGenerators.privateKey
|
||||
hash <- CryptoGenerators.doubleSha256Digest
|
||||
hashType <- CryptoGenerators.hashType
|
||||
signature = ECDigitalSignature.fromBytes(
|
||||
privKey.sign(hash).bytes ++ ByteVector.fromByte(hashType.byte)
|
||||
)
|
||||
signature = privKey.sign(hash).appendHashType(hashType)
|
||||
beforeTimeout <- NumberGenerator.bool
|
||||
} yield P2PKWithTimeoutScriptSignature(beforeTimeout, signature)
|
||||
|
||||
@ -84,9 +78,7 @@ sealed abstract class ScriptGenerators {
|
||||
privKeys <- CryptoGenerators.privateKeySeq(numKeys)
|
||||
} yield for {
|
||||
privKey <- privKeys
|
||||
} yield ECDigitalSignature.fromBytes(
|
||||
privKey.sign(hash).bytes ++ ByteVector.fromByte(hashType.byte)
|
||||
)
|
||||
} yield privKey.sign(hash).appendHashType(hashType)
|
||||
signatures.map(sigs => MultiSignatureScriptSignature(sigs))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user