Skip to content

Commit 3654a46

Browse files
committed
Implement DelayedPaymentBasepoint and DelayedPaymentKey wrappers to explicitly specify those types of keys in functions and structs allowing the language to verify what key is being used and enable idiomatic derivation of one key from another.
1 parent 44e87b8 commit 3654a46

File tree

6 files changed

+253
-46
lines changed

6 files changed

+253
-46
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use bitcoin::{secp256k1, EcdsaSighashType};
3535
use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
3636
use crate::ln::{PaymentHash, PaymentPreimage};
3737
use crate::ln::msgs::DecodeError;
38-
use crate::ln::chan_utils;
38+
use crate::ln::chan_utils::{self, DelayedPaymentKey, DelayedPaymentBasepoint};
3939
use crate::ln::chan_utils::{CommitmentTransaction, CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HTLCClaim, ChannelTransactionParameters, HolderCommitmentTransaction, TxCreationKeys};
4040
use crate::ln::channelmanager::{HTLCSource, SentHTLCId};
4141
use crate::chain;
@@ -239,7 +239,7 @@ struct HolderSignedTx {
239239
revocation_key: PublicKey,
240240
a_htlc_key: PublicKey,
241241
b_htlc_key: PublicKey,
242-
delayed_payment_key: PublicKey,
242+
delayed_payment_key: DelayedPaymentKey,
243243
per_commitment_point: PublicKey,
244244
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
245245
to_self_value_sat: u64,
@@ -276,7 +276,7 @@ impl HolderSignedTx {
276276
/// justice or 2nd-stage preimage/timeout transactions.
277277
#[derive(Clone, PartialEq, Eq)]
278278
struct CounterpartyCommitmentParameters {
279-
counterparty_delayed_payment_base_key: PublicKey,
279+
counterparty_delayed_payment_base_key: DelayedPaymentBasepoint,
280280
counterparty_htlc_base_key: PublicKey,
281281
on_counterparty_tx_csv: u16,
282282
}
@@ -2925,9 +2925,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29252925
let revocation_pubkey = chan_utils::derive_public_revocation_key(
29262926
&self.onchain_tx_handler.secp_ctx, &their_per_commitment_point,
29272927
&self.holder_revocation_basepoint);
2928-
let delayed_key = chan_utils::derive_public_key(&self.onchain_tx_handler.secp_ctx,
2929-
&their_per_commitment_point,
2930-
&self.counterparty_commitment_params.counterparty_delayed_payment_base_key);
2928+
let delayed_payment_basepoint = DelayedPaymentBasepoint::from(self.counterparty_commitment_params.counterparty_delayed_payment_base_key);
2929+
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx,
2930+
&delayed_payment_basepoint,
2931+
&their_per_commitment_point);
29312932
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,
29322933
self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
29332934

@@ -2991,7 +2992,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29912992
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
29922993
let per_commitment_point = PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key);
29932994
let revocation_pubkey = chan_utils::derive_public_revocation_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_point, &self.holder_revocation_basepoint);
2994-
let delayed_key = chan_utils::derive_public_key(&self.onchain_tx_handler.secp_ctx, &PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key), &self.counterparty_commitment_params.counterparty_delayed_payment_base_key);
2995+
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.counterparty_commitment_params.counterparty_delayed_payment_base_key, &PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key));
29952996

29962997
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
29972998
let revokeable_p2wsh = revokeable_redeemscript.to_v0_p2wsh();
@@ -3105,9 +3106,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31053106
if let Some(transaction) = tx {
31063107
let revocation_pubkey = chan_utils::derive_public_revocation_key(
31073108
&self.onchain_tx_handler.secp_ctx, &per_commitment_point, &self.holder_revocation_basepoint);
3108-
let delayed_key = chan_utils::derive_public_key(&self.onchain_tx_handler.secp_ctx,
3109-
&per_commitment_point,
3110-
&self.counterparty_commitment_params.counterparty_delayed_payment_base_key);
3109+
3110+
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.counterparty_commitment_params.counterparty_delayed_payment_base_key, &per_commitment_point);
3111+
31113112
let revokeable_p2wsh = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,
31123113
self.counterparty_commitment_params.on_counterparty_tx_csv,
31133114
&delayed_key).to_v0_p2wsh();
@@ -4503,7 +4504,7 @@ mod tests {
45034504
use crate::chain::transaction::OutPoint;
45044505
use crate::sign::InMemorySigner;
45054506
use crate::ln::{PaymentPreimage, PaymentHash};
4506-
use crate::ln::chan_utils;
4507+
use crate::ln::chan_utils::{self, DelayedPaymentBasepoint, DelayedPaymentKey};
45074508
use crate::ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
45084509
use crate::ln::channelmanager::{PaymentSendFailure, PaymentId, RecipientOnionFields};
45094510
use crate::ln::functional_test_utils::*;
@@ -4672,7 +4673,7 @@ mod tests {
46724673
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
46734674
revocation_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()),
46744675
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
4675-
delayed_payment_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap()),
4676+
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
46764677
htlc_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap())
46774678
};
46784679
let funding_outpoint = OutPoint { txid: Txid::all_zeros(), index: u16::max_value() };
@@ -4772,7 +4773,7 @@ mod tests {
47724773
payment_hash: PaymentHash([1; 32]),
47734774
transaction_output_index: Some($idx as u32),
47744775
};
4775-
let redeem_script = if *$weight == WEIGHT_REVOKED_OUTPUT { chan_utils::get_revokeable_redeemscript(&pubkey, 256, &pubkey) } else { chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, $opt_anchors, &pubkey, &pubkey, &pubkey) };
4776+
let redeem_script = if *$weight == WEIGHT_REVOKED_OUTPUT { chan_utils::get_revokeable_redeemscript(&pubkey, 256, &DelayedPaymentKey::from_basepoint(&secp_ctx, &DelayedPaymentBasepoint::from(pubkey), &pubkey)) } else { chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, $opt_anchors, &pubkey, &pubkey, &pubkey) };
47764777
let sighash = hash_to_message!(&$sighash_parts.segwit_signature_hash($idx, &redeem_script, $amount, EcdsaSighashType::All).unwrap()[..]);
47774778
let sig = secp_ctx.sign_ecdsa(&sighash, &privkey);
47784779
let mut ser_sig = sig.serialize_der().to_vec();

lightning/src/chain/package.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bitcoin::hash_types::Txid;
2121
use bitcoin::secp256k1::{SecretKey,PublicKey};
2222

2323
use crate::ln::PaymentPreimage;
24-
use crate::ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment};
24+
use crate::ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment, DelayedPaymentBasepoint};
2525
use crate::ln::chan_utils;
2626
use crate::ln::msgs::DecodeError;
2727
use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT, compute_feerate_sat_per_1000_weight, FEERATE_FLOOR_SATS_PER_KW};
@@ -114,7 +114,7 @@ const HIGH_FREQUENCY_BUMP_INTERVAL: u32 = 1;
114114
#[derive(Clone, PartialEq, Eq)]
115115
pub(crate) struct RevokedOutput {
116116
per_commitment_point: PublicKey,
117-
counterparty_delayed_payment_base_key: PublicKey,
117+
counterparty_delayed_payment_base_key: DelayedPaymentBasepoint,
118118
counterparty_htlc_base_key: PublicKey,
119119
per_commitment_key: SecretKey,
120120
weight: u64,
@@ -124,7 +124,7 @@ pub(crate) struct RevokedOutput {
124124
}
125125

126126
impl RevokedOutput {
127-
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, counterparty_htlc_base_key: PublicKey, per_commitment_key: SecretKey, amount: u64, on_counterparty_tx_csv: u16, is_counterparty_balance_on_anchors: bool) -> Self {
127+
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: DelayedPaymentBasepoint, counterparty_htlc_base_key: PublicKey, per_commitment_key: SecretKey, amount: u64, on_counterparty_tx_csv: u16, is_counterparty_balance_on_anchors: bool) -> Self {
128128
RevokedOutput {
129129
per_commitment_point,
130130
counterparty_delayed_payment_base_key,
@@ -160,7 +160,7 @@ impl_writeable_tlv_based!(RevokedOutput, {
160160
#[derive(Clone, PartialEq, Eq)]
161161
pub(crate) struct RevokedHTLCOutput {
162162
per_commitment_point: PublicKey,
163-
counterparty_delayed_payment_base_key: PublicKey,
163+
counterparty_delayed_payment_base_key: DelayedPaymentBasepoint,
164164
counterparty_htlc_base_key: PublicKey,
165165
per_commitment_key: SecretKey,
166166
weight: u64,
@@ -169,7 +169,7 @@ pub(crate) struct RevokedHTLCOutput {
169169
}
170170

171171
impl RevokedHTLCOutput {
172-
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, counterparty_htlc_base_key: PublicKey, per_commitment_key: SecretKey, amount: u64, htlc: HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures) -> Self {
172+
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: DelayedPaymentBasepoint, counterparty_htlc_base_key: PublicKey, per_commitment_key: SecretKey, amount: u64, htlc: HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures) -> Self {
173173
let weight = if htlc.offered { weight_revoked_offered_htlc(channel_type_features) } else { weight_revoked_received_htlc(channel_type_features) };
174174
RevokedHTLCOutput {
175175
per_commitment_point,
@@ -204,15 +204,15 @@ impl_writeable_tlv_based!(RevokedHTLCOutput, {
204204
#[derive(Clone, PartialEq, Eq)]
205205
pub(crate) struct CounterpartyOfferedHTLCOutput {
206206
per_commitment_point: PublicKey,
207-
counterparty_delayed_payment_base_key: PublicKey,
207+
counterparty_delayed_payment_base_key: DelayedPaymentBasepoint,
208208
counterparty_htlc_base_key: PublicKey,
209209
preimage: PaymentPreimage,
210210
htlc: HTLCOutputInCommitment,
211211
channel_type_features: ChannelTypeFeatures,
212212
}
213213

214214
impl CounterpartyOfferedHTLCOutput {
215-
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, counterparty_htlc_base_key: PublicKey, preimage: PaymentPreimage, htlc: HTLCOutputInCommitment, channel_type_features: ChannelTypeFeatures) -> Self {
215+
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: DelayedPaymentBasepoint, counterparty_htlc_base_key: PublicKey, preimage: PaymentPreimage, htlc: HTLCOutputInCommitment, channel_type_features: ChannelTypeFeatures) -> Self {
216216
CounterpartyOfferedHTLCOutput {
217217
per_commitment_point,
218218
counterparty_delayed_payment_base_key,
@@ -282,14 +282,14 @@ impl Readable for CounterpartyOfferedHTLCOutput {
282282
#[derive(Clone, PartialEq, Eq)]
283283
pub(crate) struct CounterpartyReceivedHTLCOutput {
284284
per_commitment_point: PublicKey,
285-
counterparty_delayed_payment_base_key: PublicKey,
285+
counterparty_delayed_payment_base_key: DelayedPaymentBasepoint,
286286
counterparty_htlc_base_key: PublicKey,
287287
htlc: HTLCOutputInCommitment,
288288
channel_type_features: ChannelTypeFeatures,
289289
}
290290

291291
impl CounterpartyReceivedHTLCOutput {
292-
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, counterparty_htlc_base_key: PublicKey, htlc: HTLCOutputInCommitment, channel_type_features: ChannelTypeFeatures) -> Self {
292+
pub(crate) fn build(per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: DelayedPaymentBasepoint, counterparty_htlc_base_key: PublicKey, htlc: HTLCOutputInCommitment, channel_type_features: ChannelTypeFeatures) -> Self {
293293
CounterpartyReceivedHTLCOutput {
294294
per_commitment_point,
295295
counterparty_delayed_payment_base_key,
@@ -1190,6 +1190,7 @@ mod tests {
11901190
use crate::chain::Txid;
11911191
use crate::ln::chan_utils::HTLCOutputInCommitment;
11921192
use crate::ln::{PaymentPreimage, PaymentHash};
1193+
use crate::ln::chan_utils::DelayedPaymentBasepoint;
11931194

11941195
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
11951196
use bitcoin::blockdata::script::Script;
@@ -1206,7 +1207,7 @@ mod tests {
12061207
{
12071208
let dumb_scalar = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
12081209
let dumb_point = PublicKey::from_secret_key(&$secp_ctx, &dumb_scalar);
1209-
PackageSolvingData::RevokedOutput(RevokedOutput::build(dumb_point, dumb_point, dumb_point, dumb_scalar, 0, 0, $is_counterparty_balance_on_anchors))
1210+
PackageSolvingData::RevokedOutput(RevokedOutput::build(dumb_point, DelayedPaymentBasepoint::from(dumb_point), dumb_point, dumb_scalar, 0, 0, $is_counterparty_balance_on_anchors))
12101211
}
12111212
}
12121213
}
@@ -1218,7 +1219,7 @@ mod tests {
12181219
let dumb_point = PublicKey::from_secret_key(&$secp_ctx, &dumb_scalar);
12191220
let hash = PaymentHash([1; 32]);
12201221
let htlc = HTLCOutputInCommitment { offered: true, amount_msat: $amt, cltv_expiry: 0, payment_hash: hash, transaction_output_index: None };
1221-
PackageSolvingData::CounterpartyReceivedHTLCOutput(CounterpartyReceivedHTLCOutput::build(dumb_point, dumb_point, dumb_point, htlc, $opt_anchors))
1222+
PackageSolvingData::CounterpartyReceivedHTLCOutput(CounterpartyReceivedHTLCOutput::build(dumb_point, DelayedPaymentBasepoint::from(dumb_point), dumb_point, htlc, $opt_anchors))
12221223
}
12231224
}
12241225
}
@@ -1231,7 +1232,7 @@ mod tests {
12311232
let hash = PaymentHash([1; 32]);
12321233
let preimage = PaymentPreimage([2;32]);
12331234
let htlc = HTLCOutputInCommitment { offered: false, amount_msat: $amt, cltv_expiry: 1000, payment_hash: hash, transaction_output_index: None };
1234-
PackageSolvingData::CounterpartyOfferedHTLCOutput(CounterpartyOfferedHTLCOutput::build(dumb_point, dumb_point, dumb_point, preimage, htlc, $opt_anchors))
1235+
PackageSolvingData::CounterpartyOfferedHTLCOutput(CounterpartyOfferedHTLCOutput::build(dumb_point, DelayedPaymentBasepoint::from(dumb_point), dumb_point, preimage, htlc, $opt_anchors))
12351236
}
12361237
}
12371238
}

lightning/src/events/bump_transaction.rs

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::chain::chaininterface::{BroadcasterInterface, fee_for_weight};
1818
use crate::chain::ClaimId;
1919
use crate::io_extras::sink;
2020
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
21-
use crate::ln::chan_utils;
21+
use crate::ln::chan_utils::{self, DelayedPaymentKey};
2222
use crate::ln::chan_utils::{
2323
ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
2424
HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT, HTLCOutputInCommitment
@@ -102,6 +102,123 @@ impl AnchorDescriptor {
102102
}
103103
}
104104

105+
/// A descriptor used to sign for a commitment transaction's HTLC output.
106+
#[derive(Clone, Debug, PartialEq, Eq)]
107+
pub struct HTLCDescriptor {
108+
/// The parameters required to derive the signer for the HTLC input.
109+
pub channel_derivation_parameters: ChannelDerivationParameters,
110+
/// The txid of the commitment transaction in which the HTLC output lives.
111+
pub commitment_txid: Txid,
112+
/// The number of the commitment transaction in which the HTLC output lives.
113+
pub per_commitment_number: u64,
114+
/// The key tweak corresponding to the number of the commitment transaction in which the HTLC
115+
/// output lives. This tweak is applied to all the basepoints for both parties in the channel to
116+
/// arrive at unique keys per commitment.
117+
///
118+
/// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
119+
pub per_commitment_point: PublicKey,
120+
/// The details of the HTLC as it appears in the commitment transaction.
121+
pub htlc: HTLCOutputInCommitment,
122+
/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
123+
/// taken.
124+
pub preimage: Option<PaymentPreimage>,
125+
/// The counterparty's signature required to spend the HTLC output.
126+
pub counterparty_sig: Signature
127+
}
128+
129+
impl_writeable_tlv_based!(HTLCDescriptor, {
130+
(0, channel_derivation_parameters, required),
131+
(2, commitment_txid, required),
132+
(4, per_commitment_number, required),
133+
(6, per_commitment_point, required),
134+
(8, htlc, required),
135+
(10, preimage, option),
136+
(12, counterparty_sig, required),
137+
});
138+
139+
impl HTLCDescriptor {
140+
/// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
141+
/// being spent by the HTLC input in the HTLC transaction.
142+
pub fn outpoint(&self) -> OutPoint {
143+
OutPoint {
144+
txid: self.commitment_txid,
145+
vout: self.htlc.transaction_output_index.unwrap(),
146+
}
147+
}
148+
149+
/// Returns the UTXO to be spent by the HTLC input, which can be obtained via
150+
/// [`Self::unsigned_tx_input`].
151+
pub fn previous_utxo<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> TxOut {
152+
TxOut {
153+
script_pubkey: self.witness_script(secp).to_v0_p2wsh(),
154+
value: self.htlc.amount_msat / 1000,
155+
}
156+
}
157+
158+
/// Returns the unsigned transaction input spending the HTLC output in the commitment
159+
/// transaction.
160+
pub fn unsigned_tx_input(&self) -> TxIn {
161+
chan_utils::build_htlc_input(&self.commitment_txid, &self.htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies())
162+
}
163+
164+
/// Returns the delayed output created as a result of spending the HTLC output in the commitment
165+
/// transaction.
166+
pub fn tx_output<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> TxOut {
167+
let channel_params = self.channel_derivation_parameters.transaction_parameters.as_holder_broadcastable();
168+
let broadcaster_keys = channel_params.broadcaster_pubkeys();
169+
let counterparty_keys = channel_params.countersignatory_pubkeys();
170+
let broadcaster_delayed_key = DelayedPaymentKey::from_basepoint(&secp, &broadcaster_keys.delayed_payment_basepoint, &self.per_commitment_point);
171+
let counterparty_revocation_key = chan_utils::derive_public_revocation_key(
172+
secp, &self.per_commitment_point, &counterparty_keys.revocation_basepoint
173+
);
174+
chan_utils::build_htlc_output(
175+
0 /* feerate_per_kw */, channel_params.contest_delay(), &self.htlc,
176+
&ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &broadcaster_delayed_key, &counterparty_revocation_key
177+
)
178+
}
179+
180+
/// Returns the witness script of the HTLC output in the commitment transaction.
181+
pub fn witness_script<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> Script {
182+
let channel_params = self.channel_derivation_parameters.transaction_parameters.as_holder_broadcastable();
183+
let broadcaster_keys = channel_params.broadcaster_pubkeys();
184+
let counterparty_keys = channel_params.countersignatory_pubkeys();
185+
let broadcaster_htlc_key = chan_utils::derive_public_key(
186+
secp, &self.per_commitment_point, &broadcaster_keys.htlc_basepoint
187+
);
188+
let counterparty_htlc_key = chan_utils::derive_public_key(
189+
secp, &self.per_commitment_point, &counterparty_keys.htlc_basepoint
190+
);
191+
let counterparty_revocation_key = chan_utils::derive_public_revocation_key(
192+
secp, &self.per_commitment_point, &counterparty_keys.revocation_basepoint
193+
);
194+
chan_utils::get_htlc_redeemscript_with_explicit_keys(
195+
&self.htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &broadcaster_htlc_key, &counterparty_htlc_key,
196+
&counterparty_revocation_key,
197+
)
198+
}
199+
200+
/// Returns the fully signed witness required to spend the HTLC output in the commitment
201+
/// transaction.
202+
pub fn tx_input_witness(&self, signature: &Signature, witness_script: &Script) -> Witness {
203+
chan_utils::build_htlc_input_witness(
204+
signature, &self.counterparty_sig, &self.preimage, witness_script, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() /* opt_anchors */
205+
)
206+
}
207+
208+
/// Derives the channel signer required to sign the HTLC input.
209+
pub fn derive_channel_signer<S: WriteableEcdsaChannelSigner, SP: Deref>(&self, signer_provider: &SP) -> S
210+
where
211+
SP::Target: SignerProvider<Signer = S>
212+
{
213+
let mut signer = signer_provider.derive_channel_signer(
214+
self.channel_derivation_parameters.value_satoshis,
215+
self.channel_derivation_parameters.keys_id,
216+
);
217+
signer.provide_channel_parameters(&self.channel_derivation_parameters.transaction_parameters);
218+
signer
219+
}
220+
}
221+
105222
/// Represents the different types of transactions, originating from LDK, to be bumped.
106223
#[derive(Clone, Debug, PartialEq, Eq)]
107224
pub enum BumpTransactionEvent {

0 commit comments

Comments
 (0)