diff --git a/lightning/src/sign/ecdsa.rs b/lightning/src/sign/ecdsa.rs index ecdd45aa3f5..0d02c2ec8f2 100644 --- a/lightning/src/sign/ecdsa.rs +++ b/lightning/src/sign/ecdsa.rs @@ -1,6 +1,6 @@ //! Defines ECDSA-specific signer types. -use bitcoin::transaction::Transaction; +use bitcoin::{Script, Transaction}; use bitcoin::secp256k1; use bitcoin::secp256k1::ecdsa::Signature; @@ -209,4 +209,11 @@ pub trait EcdsaChannelSigner: ChannelSigner { fn sign_channel_announcement_with_funding_key( &self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1, ) -> Result; + /// Sign an input of a transaction with our funding key. + /// Used for splicing, when signing the previous funding transaction. + /// The previous funding transaction becomes an input to the new funding transaction, + /// and it is a multisig, which we also need to sign. + fn sign_transaction_input( + &self, tx: &Transaction, input_index: u16, input_value: u64, input_redeem_script: &Script, secp_ctx: &Secp256k1 + ) -> Result; } diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index 4b8a9e0255a..9b87f32845e 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -1695,6 +1695,14 @@ impl EcdsaChannelSigner for InMemorySigner { let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]); Ok(secp_ctx.sign_ecdsa(&msghash, &self.funding_key)) } + + fn sign_transaction_input( + &self, tx: &Transaction, input_index: u16, input_value: u64, input_redeem_script: &Script, secp_ctx: &Secp256k1 + ) -> Result { + let sighash = &sighash::SighashCache::new(tx).p2wsh_signature_hash(input_index as usize, &input_redeem_script, Amount::from_sat(input_value), EcdsaSighashType::All).unwrap()[..]; + let msg = hash_to_message!(sighash); + Ok(sign(secp_ctx, &msg, &self.funding_key)) + } } #[cfg(taproot)] diff --git a/lightning/src/util/test_channel_signer.rs b/lightning/src/util/test_channel_signer.rs index 9aa34fd4ca6..50cbe773d62 100644 --- a/lightning/src/util/test_channel_signer.rs +++ b/lightning/src/util/test_channel_signer.rs @@ -22,7 +22,7 @@ use core::cmp; use crate::sync::{Mutex, Arc}; #[cfg(test)] use crate::sync::MutexGuard; -use bitcoin::transaction::Transaction; +use bitcoin::{Script, Transaction}; use bitcoin::hashes::Hash; use bitcoin::sighash; use bitcoin::sighash::EcdsaSighashType; @@ -353,6 +353,12 @@ impl EcdsaChannelSigner for TestChannelSigner { ) -> Result { self.inner.sign_channel_announcement_with_funding_key(msg, secp_ctx) } + + fn sign_transaction_input( + &self, tx: &Transaction, input_index: u16, input_value: u64, input_redeem_script: &Script, secp_ctx: &Secp256k1 + ) -> Result { + self.inner.sign_transaction_input(tx, input_index, input_value, input_redeem_script, secp_ctx) + } } #[cfg(taproot)]