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 Oct 9, 2024
1 parent 02973ea commit 09d4590
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lightning/src/sign/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,15 @@ 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.
/// [`input_index`]: The index of the input that was the previous funding transaction,
/// within the new funding transaction.
/// [`input_value`]: The value of the previous funding transaction.
fn sign_splicing_funding_input(
&self, tx: &Transaction, input_index: u16, input_value: u64,
secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<Signature, ()>;
}
21 changes: 21 additions & 0 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: u16, 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 as usize,
&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)]
Expand Down
7 changes: 7 additions & 0 deletions lightning/src/util/test_channel_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: u16, 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)]
Expand Down

0 comments on commit 09d4590

Please sign in to comment.