Skip to content

Commit b7de01f

Browse files
committed
Signer extended with method to sign prev funding transaction input
1 parent 02973ea commit b7de01f

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Diff for: lightning/src/sign/ecdsa.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Defines ECDSA-specific signer types.
22
3-
use bitcoin::transaction::Transaction;
3+
use bitcoin::{Script, Transaction};
44

55
use bitcoin::secp256k1;
66
use bitcoin::secp256k1::ecdsa::Signature;
@@ -209,4 +209,11 @@ pub trait EcdsaChannelSigner: ChannelSigner {
209209
fn sign_channel_announcement_with_funding_key(
210210
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
211211
) -> Result<Signature, ()>;
212+
/// Sign an input of a transaction with our funding key.
213+
/// Used for splicing, when signing the previous funding transaction.
214+
/// The previous funding transaction becomes an input to the new funding transaction,
215+
/// and it is a multisig, which we also need to sign.
216+
fn sign_transaction_input(
217+
&self, tx: &Transaction, input_index: u16, input_value: u64, input_redeem_script: &Script, secp_ctx: &Secp256k1<secp256k1::All>
218+
) -> Result<Signature, ()>;
212219
}

Diff for: lightning/src/sign/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,14 @@ impl EcdsaChannelSigner for InMemorySigner {
16951695
let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
16961696
Ok(secp_ctx.sign_ecdsa(&msghash, &self.funding_key))
16971697
}
1698+
1699+
fn sign_transaction_input(
1700+
&self, tx: &Transaction, input_index: u16, input_value: u64, input_redeem_script: &Script, secp_ctx: &Secp256k1<secp256k1::All>
1701+
) -> Result<Signature, ()> {
1702+
let sighash = &sighash::SighashCache::new(tx).p2wsh_signature_hash(input_index as usize, &input_redeem_script, Amount::from_sat(input_value), EcdsaSighashType::All).unwrap()[..];
1703+
let msg = hash_to_message!(sighash);
1704+
Ok(sign(secp_ctx, &msg, &self.funding_key))
1705+
}
16981706
}
16991707

17001708
#[cfg(taproot)]

Diff for: lightning/src/util/test_channel_signer.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use core::cmp;
2222
use crate::sync::{Mutex, Arc};
2323
#[cfg(test)] use crate::sync::MutexGuard;
2424

25-
use bitcoin::transaction::Transaction;
25+
use bitcoin::{Script, Transaction};
2626
use bitcoin::hashes::Hash;
2727
use bitcoin::sighash;
2828
use bitcoin::sighash::EcdsaSighashType;
@@ -353,6 +353,12 @@ impl EcdsaChannelSigner for TestChannelSigner {
353353
) -> Result<Signature, ()> {
354354
self.inner.sign_channel_announcement_with_funding_key(msg, secp_ctx)
355355
}
356+
357+
fn sign_transaction_input(
358+
&self, tx: &Transaction, input_index: u16, input_value: u64, input_redeem_script: &Script, secp_ctx: &Secp256k1<secp256k1::All>
359+
) -> Result<Signature, ()> {
360+
self.inner.sign_transaction_input(tx, input_index, input_value, input_redeem_script, secp_ctx)
361+
}
356362
}
357363

358364
#[cfg(taproot)]

0 commit comments

Comments
 (0)