]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Signer extended with method to sign prev funding transaction input
authoroptout <13562139+optout21@users.noreply.github.com>
Tue, 15 Oct 2024 21:12:43 +0000 (23:12 +0200)
committeroptout <13562139+optout21@users.noreply.github.com>
Tue, 15 Oct 2024 21:13:14 +0000 (23:13 +0200)
lightning/src/sign/ecdsa.rs
lightning/src/sign/mod.rs
lightning/src/util/test_channel_signer.rs

index ecdd45aa3f5e0b5b401843bff17327aa04dbdaec..3390f9ce184081ae0b3c9a54cf80e730267f49ec 100644 (file)
@@ -209,4 +209,18 @@ pub trait EcdsaChannelSigner: ChannelSigner {
        fn sign_channel_announcement_with_funding_key(
                &self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
        ) -> Result<Signature, ()>;
+
+       /// Signs the input of a splicing funding transaction with our funding key.
+       ///
+       /// In splicing, the previous funding transaction output is spent as the input of
+       /// the new funding transaction, and is a 2-of-2 multisig.
+       ///
+       /// `input_index`: The index of the input within the new funding transaction `tx`,
+       ///    spending the previous funding transaction's output
+       ///
+       /// `input_value`: The value of the previous funding transaction output.
+       fn sign_splicing_funding_input(
+               &self, tx: &Transaction, input_index: usize, input_value: u64,
+               secp_ctx: &Secp256k1<secp256k1::All>,
+       ) -> Result<Signature, ()>;
 }
index 8ad34f2d653de9481c170ec3e709dd121a61315b..25164f0575898ba2bff16a73ec5f5a262cb1909d 100644 (file)
@@ -1695,6 +1695,27 @@ impl EcdsaChannelSigner for InMemorySigner {
                let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
                Ok(secp_ctx.sign_ecdsa(&msghash, &self.funding_key))
        }
+
+       fn sign_splicing_funding_input(
+               &self, tx: &Transaction, input_index: usize, input_value: u64,
+               secp_ctx: &Secp256k1<secp256k1::All>,
+       ) -> Result<Signature, ()> {
+               let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
+               let counterparty_funding_key =
+                       &self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
+               let funding_redeemscript =
+                       make_funding_redeemscript(&funding_pubkey, counterparty_funding_key);
+               let sighash = &sighash::SighashCache::new(tx)
+                       .p2wsh_signature_hash(
+                               input_index,
+                               &funding_redeemscript,
+                               Amount::from_sat(input_value),
+                               EcdsaSighashType::All,
+                       )
+                       .unwrap()[..];
+               let msg = hash_to_message!(sighash);
+               Ok(sign(secp_ctx, &msg, &self.funding_key))
+       }
 }
 
 #[cfg(taproot)]
index 9aa34fd4ca601fb4cbee58032f2d0bcdbfc3a393..d9df500f2f82c2d7b8dab78bd89c2edece7de3d9 100644 (file)
@@ -353,6 +353,13 @@ impl EcdsaChannelSigner for TestChannelSigner {
        ) -> Result<Signature, ()> {
                self.inner.sign_channel_announcement_with_funding_key(msg, secp_ctx)
        }
+
+       fn sign_splicing_funding_input(
+               &self, tx: &Transaction, input_index: usize, input_value: u64,
+               secp_ctx: &Secp256k1<secp256k1::All>,
+       ) -> Result<Signature, ()> {
+               self.inner.sign_splicing_funding_input(tx, input_index, input_value, secp_ctx)
+       }
 }
 
 #[cfg(taproot)]