diff --git a/lightning/src/sign/ecdsa.rs b/lightning/src/sign/ecdsa.rs index ecdd45aa3f5..00fd366d418 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,12 @@ 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..0e6af67c782 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -1695,6 +1695,22 @@ 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..170cff38a86 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,18 @@ 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)]