Skip to content

Commit 62ed503

Browse files
committed
Implement Script for Witness and Add Tweak in PSBT.
Adding Witness Script and key tweaks makes a Partially Signed Bitcoin Transaction the single data source needed for a Signer to produce valid signatures. A Signer is not required to be able to generate L2 keys, e.g delayed payment basepoint.
1 parent cfb4391 commit 62ed503

File tree

3 files changed

+911
-313
lines changed

3 files changed

+911
-313
lines changed

lightning/src/chain/channelmonitor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4289,6 +4289,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42894289
revocation_pubkey: broadcasted_holder_revokable_script.2,
42904290
channel_keys_id: self.channel_keys_id,
42914291
channel_value_satoshis: self.channel_value_satoshis,
4292+
channel_transaction_parameters: Some(self.onchain_tx_handler.channel_transaction_parameters.clone()),
42924293
}));
42934294
}
42944295
}

lightning/src/ln/channel_keys.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,30 @@ macro_rules! basepoint_impl {
3737
pub fn to_public_key(&self) -> PublicKey {
3838
self.0
3939
}
40+
41+
/// Derives a per-commitment-transaction (eg an htlc key or delayed_payment key) private key addition tweak
42+
/// from a basepoint and a per_commitment_point:
43+
/// `privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`
44+
/// This calculates the hash part in the tweak derivation process, which is used to ensure
45+
/// that each key is unique and cannot be guessed by an external party. It is equivalent
46+
/// to the `from_basepoint` method, but without the addition operation, providing just the
47+
/// tweak from the hash of the per_commitment_point and the basepoint.
48+
pub fn derive_add_tweak(
49+
&self,
50+
per_commitment_point: &PublicKey,
51+
) -> [u8; 32] {
52+
let mut sha = Sha256::engine();
53+
sha.input(&per_commitment_point.serialize());
54+
sha.input(&self.to_public_key().serialize());
55+
Sha256::from_engine(sha).to_byte_array()
56+
}
4057
}
4158

4259
impl From<PublicKey> for $BasepointT {
4360
fn from(value: PublicKey) -> Self {
4461
Self(value)
4562
}
4663
}
47-
4864
}
4965
}
5066
macro_rules! key_impl {

0 commit comments

Comments
 (0)