@@ -58,14 +58,14 @@ use crate::util::invoice::construct_invoice_preimage;
5858#[ derive( Hash , Copy , Clone , PartialEq , Eq , Debug ) ]
5959pub struct KeyMaterial ( pub [ u8 ; 32 ] ) ;
6060
61- /// Information about a spendable output to a ` P2WSH` script.
61+ /// Information about a spendable output to a P2WSH script.
6262///
6363/// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
6464#[ derive( Clone , Debug , PartialEq , Eq ) ]
6565pub struct DelayedPaymentOutputDescriptor {
6666 /// The outpoint which is spendable.
6767 pub outpoint : OutPoint ,
68- /// Per commitment point to derive `delayed_payment_key` by key holder
68+ /// Per commitment point to derive the delayed payment key by key holder.
6969 pub per_commitment_point : PublicKey ,
7070 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
7171 /// the witness_script.
@@ -151,40 +151,46 @@ pub enum SpendableOutputDescriptor {
151151 /// The output which is referenced by the given outpoint.
152152 output : TxOut ,
153153 } ,
154- /// An output to a ` P2WSH` script which can be spent with a single signature after an `OP_CSV`
154+ /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
155155 /// delay.
156156 ///
157157 /// The witness in the spending input should be:
158158 /// ```bitcoin
159159 /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
160160 /// ```
161161 ///
162- /// Note that the `nSequence` field in the spending input must be set to `to_self_delay` (which
163- /// means the transaction is not broadcastable until at least `to_self_delay` blocks after the
164- /// outpoint confirms, see [BIP
165- /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)).
162+ /// Note that the `nSequence` field in the spending input must be set to
163+ /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
164+ /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
165+ /// the outpoint confirms, see [BIP
166+ /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
167+ /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
168+ /// is reached.
166169 ///
167170 /// These are generally the result of a "revocable" output to us, spendable only by us unless
168171 /// it is an output from an old state which we broadcast (which should never happen).
169172 ///
170- /// To derive the `delayed_payment` key which is used to sign this input, you must pass the
171- /// holder ` delayed_payment_base_key` (i.e., the private key which corresponds to the
172- /// ` delayed_payment_basepoint` in [`BaseSign::pubkeys`]) and the provided
173- /// ` per_commitment_point` to [`chan_utils::derive_private_key`]. The public key can be
173+ /// To derive the delayed payment key which is used to sign this input, you must pass the
174+ /// holder [`InMemorySigner:: delayed_payment_base_key`] (i.e., the private key which corresponds to the
175+ /// [`ChannelPublicKeys:: delayed_payment_basepoint`] in [`BaseSign::pubkeys`]) and the provided
176+ /// [`DelayedPaymentOutputDescriptor:: per_commitment_point`] to [`chan_utils::derive_private_key`]. The public key can be
174177 /// generated without the secret key using [`chan_utils::derive_public_key`] and only the
175- /// ` delayed_payment_basepoint` which appears in [`BaseSign::pubkeys`].
178+ /// [`ChannelPublicKeys:: delayed_payment_basepoint`] which appears in [`BaseSign::pubkeys`].
176179 ///
177- /// To derive the `revocation_pubkey` provided here (which is used in the witness script
178- /// generation), you must pass the counterparty `revocation_basepoint` (which appears in the
179- /// call to [`Sign::provide_channel_parameters`]) and the provided per_commitment point to
180+ /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
181+ /// used in the witness script generation), you must pass the counterparty
182+ /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
183+ /// [`BaseSign::provide_channel_parameters`]) and the provided
184+ /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
180185 /// [`chan_utils::derive_public_revocation_key`].
181186 ///
182187 /// The witness script which is hashed and included in the output `script_pubkey` may be
183- /// regenerated by passing the `revocation_pubkey` (derived as above), our `delayed_payment`
184- /// pubkey (derived as above), and the `to_self_delay` contained here to
188+ /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
189+ /// as explained above), our delayed payment pubkey (derived as explained above), and the
190+ /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
185191 /// [`chan_utils::get_revokeable_redeemscript`].
186192 DelayedPaymentOutput ( DelayedPaymentOutputDescriptor ) ,
187- /// An output to a ` P2WPKH` , spendable exclusively by our payment key (i.e., the private key
193+ /// An output to a P2WPKH, spendable exclusively by our payment key (i.e., the private key
188194 /// which corresponds to the `payment_point` in [`BaseSign::pubkeys`]). The witness
189195 /// in the spending input is, thus, simply:
190196 /// ```bitcoin
@@ -209,24 +215,10 @@ impl_writeable_tlv_based_enum!(SpendableOutputDescriptor,
209215/// A trait to sign Lightning channel transactions as described in
210216/// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
211217///
212- /// Signing services could be implemented on a hardware wallet. In this case,
213- /// the current [`BaseSign`] would be a front-end on top of a communication
214- /// channel connected to your secure device and lightning key material wouldn't
215- /// reside on a hot server. Nevertheless, a this deployment would still need
216- /// to trust the ChannelManager to avoid loss of funds as this latest component
217- /// could ask to sign commitment transaction with HTLCs paying to attacker pubkeys.
218- ///
219- /// A more secure iteration would be to use hashlock (or payment points) to pair
220- /// invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-[`ChannelManager`]
221- /// at the price of more state and computation on the hardware wallet side. In the future,
222- /// we are looking forward to design such interface.
223- ///
224- /// In any case, [`ChannelMonitor`] or fallback watchtowers are always going to be trusted
225- /// to act, as liveness and breach reply correctness are always going to be hard requirements
226- /// of LN security model, orthogonal of key management issues.
227- ///
228- /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
229- /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
218+ /// Signing services could be implemented on a hardware wallet and should implement signing
219+ /// policies in order to be secure. Please refer to the [VLS Policy
220+ /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
221+ /// for an example of such policies.
230222pub trait BaseSign {
231223 /// Gets the per-commitment point for a specific commitment number
232224 ///
@@ -287,12 +279,15 @@ pub trait BaseSign {
287279 /// forward and it is safe to sign the next counterparty commitment.
288280 fn validate_counterparty_revocation ( & self , idx : u64 , secret : & SecretKey ) -> Result < ( ) , ( ) > ;
289281 /// Creates a signature for a holder's commitment transaction and its claiming HTLC transactions.
290- /// This will only ever be called with a non-revoked `commitment_tx`. This will be called with the
291- /// latest `commitment_tx` when we initiate a force-close.
292- /// This will be called with the previous latest `commitment_tx`, just to get claiming HTLC
293- /// signatures, if we are reacting to a [`ChannelMonitor`]
294- /// [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
295- /// that decided to broadcast before it had been updated to the latest `commitment_tx`.
282+ ///
283+ /// This will be called
284+ /// - with a non-revoked `commitment_tx`.
285+ /// - with the latest `commitment_tx` when we initiate a force-close.
286+ /// - with the previous `commitment_tx`, just to get claiming HTLC
287+ /// signatures, if we are reacting to a [`ChannelMonitor`]
288+ /// [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
289+ /// that decided to broadcast before it had been updated to the latest `commitment_tx`.
290+ ///
296291 /// This may be called multiple times for the same transaction.
297292 ///
298293 /// An external signer implementation should check that the commitment has not been revoked.
@@ -305,10 +300,10 @@ pub trait BaseSign {
305300 // TODO: Key derivation failure should panic rather than Err
306301 fn sign_holder_commitment_and_htlcs ( & self , commitment_tx : & HolderCommitmentTransaction ,
307302 secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > ;
308- /// Same as `sign_holder_commitment` , but exists only for tests to get access to holder commitment
309- /// transactions which will be broadcasted later, after the channel has moved on to a newer
310- /// state. Thus, needs its own method as `sign_holder_commitment` may enforce that we only ever
311- /// get called once.
303+ /// Same as [`sign_holder_commitment_and_htlcs`] , but exists only for tests to get access to
304+ /// holder commitment transactions which will be broadcasted later, after the channel has moved
305+ /// on to a newer state. Thus, needs its own method as [`sign_holder_commitment_and_htlcs`] may
306+ /// enforce that we only ever get called once.
312307 #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
313308 fn unsafe_sign_holder_commitment_and_htlcs ( & self , commitment_tx : & HolderCommitmentTransaction ,
314309 secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > ;
@@ -437,7 +432,7 @@ pub enum Recipient {
437432
438433/// A trait to describe an object which can get user secrets and key material.
439434pub trait KeysInterface {
440- /// A type which implements Sign which will be returned by [`derive_channel_signer`].
435+ /// A type which implements [` Sign`] which will be returned by [`Self:: derive_channel_signer`].
441436 type Signer : Sign ;
442437 /// Get node secret key based on the provided [`Recipient`].
443438 ///
@@ -617,52 +612,38 @@ impl InMemorySigner {
617612
618613 /// Returns the counterparty's pubkeys.
619614 ///
620- /// Will panic if [`provide_channel_parameters`] has not been called before.
621- ///
622- /// [`ready_channel`]: BaseSign::ready_channel
615+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
623616 pub fn counterparty_pubkeys ( & self ) -> & ChannelPublicKeys { & self . get_channel_parameters ( ) . counterparty_parameters . as_ref ( ) . unwrap ( ) . pubkeys }
624617 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
625618 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
626619 /// broadcast a transaction.
627620 ///
628- /// Will panic if [`provide_channel_parameters`] has not been called before.
629- ///
630- /// [`provide_channel_parameters`]: BaseSign::provide_channel_parameters
621+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
631622 pub fn counterparty_selected_contest_delay ( & self ) -> u16 { self . get_channel_parameters ( ) . counterparty_parameters . as_ref ( ) . unwrap ( ) . selected_contest_delay }
632623 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
633624 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
634625 /// if they broadcast a transaction.
635626 ///
636- /// Will panic if [`provide_channel_parameters`] has not been called before.
637- ///
638- /// [`provide_channel_parameters`]: BaseSign::provide_channel_parameters
627+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
639628 pub fn holder_selected_contest_delay ( & self ) -> u16 { self . get_channel_parameters ( ) . holder_selected_contest_delay }
640629 /// Returns whether the holder is the initiator.
641630 ///
642- /// Will panic if [`provide_channel_parameters`] has not been called before.
643- ///
644- /// [`provide_channel_parameters`]: BaseSign::provide_channel_parameters
631+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
645632 pub fn is_outbound ( & self ) -> bool { self . get_channel_parameters ( ) . is_outbound_from_holder }
646633 /// Funding outpoint
647634 ///
648- /// Will panic if [`provide_channel_parameters`] has not been called before.
649- ///
650- /// [`provide_channel_parameters`]: BaseSign::provide_channel_parameters
635+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
651636 pub fn funding_outpoint ( & self ) -> & OutPoint { self . get_channel_parameters ( ) . funding_outpoint . as_ref ( ) . unwrap ( ) }
652637 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
653638 /// building transactions.
654639 ///
655- /// Will panic if [`provide_channel_parameters`] has not been called before.
656- ///
657- /// [`provide_channel_parameters`]: BaseSign::provide_channel_parameters
640+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
658641 pub fn get_channel_parameters ( & self ) -> & ChannelTransactionParameters {
659642 self . channel_parameters . as_ref ( ) . unwrap ( )
660643 }
661644 /// Returns whether anchors should be used.
662645 ///
663- /// Will panic if [`provide_channel_parameters`] has not been called before.
664- ///
665- /// [`provide_channel_parameters`]: BaseSign::provide_channel_parameters
646+ /// Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
666647 pub fn opt_anchors ( & self ) -> bool {
667648 self . get_channel_parameters ( ) . opt_anchors . is_some ( )
668649 }
0 commit comments