Skip to content

Commit 84c739f

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

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lightning/src/sign/ecdsa.rs

+14
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,18 @@ 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+
213+
/// Signs the input of a splicing funding transaction with our funding key.
214+
///
215+
/// In splicing, the previous funding transaction output is spent as the input of
216+
/// the new funding transaction, and is a 2-of-2 multisig.
217+
///
218+
/// `input_index`: The index of the input within the new funding transaction `tx`,
219+
/// spending the previous funding transaction's output
220+
///
221+
/// `input_value`: The value of the previous funding transaction output.
222+
fn sign_splicing_funding_input(
223+
&self, tx: &Transaction, input_index: u16, input_value: u64,
224+
secp_ctx: &Secp256k1<secp256k1::All>,
225+
) -> Result<Signature, ()>;
212226
}

lightning/src/sign/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,27 @@ 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_splicing_funding_input(
1700+
&self, tx: &Transaction, input_index: u16, input_value: u64,
1701+
secp_ctx: &Secp256k1<secp256k1::All>,
1702+
) -> Result<Signature, ()> {
1703+
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
1704+
let counterparty_funding_key =
1705+
&self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR).funding_pubkey;
1706+
let funding_redeemscript =
1707+
make_funding_redeemscript(&funding_pubkey, counterparty_funding_key);
1708+
let sighash = &sighash::SighashCache::new(tx)
1709+
.p2wsh_signature_hash(
1710+
input_index as usize,
1711+
&funding_redeemscript,
1712+
Amount::from_sat(input_value),
1713+
EcdsaSighashType::All,
1714+
)
1715+
.unwrap()[..];
1716+
let msg = hash_to_message!(sighash);
1717+
Ok(sign(secp_ctx, &msg, &self.funding_key))
1718+
}
16981719
}
16991720

17001721
#[cfg(taproot)]

lightning/src/util/test_channel_signer.rs

+7
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ impl EcdsaChannelSigner for TestChannelSigner {
353353
) -> Result<Signature, ()> {
354354
self.inner.sign_channel_announcement_with_funding_key(msg, secp_ctx)
355355
}
356+
357+
fn sign_splicing_funding_input(
358+
&self, tx: &Transaction, input_index: u16, input_value: u64,
359+
secp_ctx: &Secp256k1<secp256k1::All>,
360+
) -> Result<Signature, ()> {
361+
self.inner.sign_splicing_funding_input(tx, input_index, input_value, secp_ctx)
362+
}
356363
}
357364

358365
#[cfg(taproot)]

0 commit comments

Comments
 (0)