Skip to content

Commit

Permalink
Signer extended with method to sign prev funding transaction input
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Sep 16, 2024
1 parent 02973ea commit b7de01f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lightning/src/sign/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -209,4 +209,11 @@ pub trait EcdsaChannelSigner: ChannelSigner {
fn sign_channel_announcement_with_funding_key(
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()>;
/// 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<secp256k1::All>
) -> Result<Signature, ()>;
}
8 changes: 8 additions & 0 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<secp256k1::All>
) -> Result<Signature, ()> {
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)]
Expand Down
8 changes: 7 additions & 1 deletion lightning/src/util/test_channel_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -353,6 +353,12 @@ impl EcdsaChannelSigner for TestChannelSigner {
) -> Result<Signature, ()> {
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<secp256k1::All>
) -> Result<Signature, ()> {
self.inner.sign_transaction_input(tx, input_index, input_value, input_redeem_script, secp_ctx)
}
}

#[cfg(taproot)]
Expand Down

0 comments on commit b7de01f

Please sign in to comment.