Skip to content

Commit 2c2f9f1

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

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lightning/src/sign/ecdsa.rs

+9-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,12 @@ 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,
218+
secp_ctx: &Secp256k1<secp256k1::All>,
219+
) -> Result<Signature, ()>;
212220
}

lightning/src/sign/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,22 @@ 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,
1701+
secp_ctx: &Secp256k1<secp256k1::All>,
1702+
) -> Result<Signature, ()> {
1703+
let sighash = &sighash::SighashCache::new(tx)
1704+
.p2wsh_signature_hash(
1705+
input_index as usize,
1706+
&input_redeem_script,
1707+
Amount::from_sat(input_value),
1708+
EcdsaSighashType::All,
1709+
)
1710+
.unwrap()[..];
1711+
let msg = hash_to_message!(sighash);
1712+
Ok(sign(secp_ctx, &msg, &self.funding_key))
1713+
}
16981714
}
16991715

17001716
#[cfg(taproot)]

lightning/src/util/test_channel_signer.rs

+13-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,18 @@ 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(
361+
tx,
362+
input_index,
363+
input_value,
364+
input_redeem_script,
365+
secp_ctx,
366+
)
367+
}
356368
}
357369

358370
#[cfg(taproot)]

0 commit comments

Comments
 (0)