Skip to content

Commit 8f10d79

Browse files
committed
Fixup: remove Transaction.sign(), use TransactionWithInputInfo.sign() instead
1 parent 426af33 commit 8f10d79

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,19 @@ object Transactions {
132132
/** Sighash flags to use when signing the transaction. */
133133
def sighash(txOwner: TxOwner, commitmentFormat: CommitmentFormat): Int = SIGHASH_ALL
134134

135-
def sign(key: PrivateKey, txOwner: TxOwner, commitmentFormat: CommitmentFormat): ByteVector64 = Transactions.sign(this, key, sighash(txOwner, commitmentFormat))
135+
def sign(key: PrivateKey, txOwner: TxOwner, commitmentFormat: CommitmentFormat): ByteVector64 = {
136+
// NB: the tx may have multiple inputs, we will only sign the one provided in txinfo.input. Bear in mind that the
137+
// signature will be invalidated if other inputs are added *afterwards* and sighashType was SIGHASH_ALL.
138+
sign(key, sighash(txOwner, commitmentFormat))
139+
}
136140

137141
def sign(key: PrivateKey, sighashType: Int): ByteVector64 = {
138142
// NB: the tx may have multiple inputs, we will only sign the one provided in txinfo.input. Bear in mind that the
139143
// signature will be invalidated if other inputs are added *afterwards* and sighashType was SIGHASH_ALL.
140144
val inputIndex = tx.txIn.indexWhere(_.outPoint == input.outPoint)
141-
Transactions.sign(tx, input.redeemScriptOrEmptyScript, input.txOut.amount, key, sighashType, inputIndex)
145+
val sigDER = Transaction.signInput(tx, inputIndex, input.redeemScriptOrEmptyScript, sighashType, input.txOut.amount, SIGVERSION_WITNESS_V0, key)
146+
val sig64 = Crypto.der2compact(sigDER)
147+
sig64
142148
}
143149

144150
def checkSig(sig: ByteVector64, pubKey: PublicKey, txOwner: TxOwner, commitmentFormat: CommitmentFormat): Boolean = {
@@ -972,19 +978,6 @@ object Transactions {
972978
val PlaceHolderSig = ByteVector64(ByteVector.fill(64)(0xaa))
973979
assert(der(PlaceHolderSig).size == 72)
974980

975-
private def sign(tx: Transaction, redeemScript: ByteVector, amount: Satoshi, key: PrivateKey, sighashType: Int, inputIndex: Int): ByteVector64 = {
976-
val sigDER = Transaction.signInput(tx, inputIndex, redeemScript, sighashType, amount, SIGVERSION_WITNESS_V0, key)
977-
val sig64 = Crypto.der2compact(sigDER)
978-
sig64
979-
}
980-
981-
private def sign(txinfo: TransactionWithInputInfo, key: PrivateKey, sighashType: Int): ByteVector64 = {
982-
// NB: the tx may have multiple inputs, we will only sign the one provided in txinfo.input. Bear in mind that the
983-
// signature will be invalidated if other inputs are added *afterwards* and sighashType was SIGHASH_ALL.
984-
val inputIndex = txinfo.tx.txIn.zipWithIndex.find(_._1.outPoint == txinfo.input.outPoint).get._2
985-
sign(txinfo.tx, txinfo.input.redeemScriptOrEmptyScript, txinfo.input.txOut.amount, key, sighashType, inputIndex)
986-
}
987-
988981
def addSigs(commitTx: CommitTx, localFundingPubkey: PublicKey, remoteFundingPubkey: PublicKey, localSig: ByteVector64, remoteSig: ByteVector64): CommitTx = {
989982
val witness = Scripts.witness2of2(localSig, remoteSig, localFundingPubkey, remoteFundingPubkey)
990983
commitTx.copy(tx = commitTx.tx.updateWitness(0, witness))

0 commit comments

Comments
 (0)