@@ -75,7 +75,7 @@ pub struct DelayedPaymentOutputDescriptor {
75
75
/// The revocation point specific to the commitment transaction which was broadcast. Used to
76
76
/// derive the witnessScript for this output.
77
77
pub revocation_pubkey : PublicKey ,
78
- /// Arbitrary identification information returned by a call to [`EcdsaChannelSigner ::channel_keys_id`].
78
+ /// Arbitrary identification information returned by a call to [`ChannelSigner ::channel_keys_id`].
79
79
/// This may be useful in re-deriving keys used in the channel to spend the output.
80
80
pub channel_keys_id : [ u8 ; 32 ] ,
81
81
/// The value of the channel which this output originated from, possibly indirectly.
@@ -107,7 +107,7 @@ pub struct StaticPaymentOutputDescriptor {
107
107
pub outpoint : OutPoint ,
108
108
/// The output which is referenced by the given outpoint.
109
109
pub output : TxOut ,
110
- /// Arbitrary identification information returned by a call to [`EcdsaChannelSigner ::channel_keys_id`].
110
+ /// Arbitrary identification information returned by a call to [`ChannelSigner ::channel_keys_id`].
111
111
/// This may be useful in re-deriving keys used in the channel to spend the output.
112
112
pub channel_keys_id : [ u8 ; 32 ] ,
113
113
/// The value of the channel which this transactions spends.
@@ -172,15 +172,15 @@ pub enum SpendableOutputDescriptor {
172
172
///
173
173
/// To derive the delayed payment key which is used to sign this input, you must pass the
174
174
/// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
175
- /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`EcdsaChannelSigner ::pubkeys`]) and the provided
175
+ /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner ::pubkeys`]) and the provided
176
176
/// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The public key can be
177
177
/// generated without the secret key using [`chan_utils::derive_public_key`] and only the
178
- /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`EcdsaChannelSigner ::pubkeys`].
178
+ /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner ::pubkeys`].
179
179
///
180
180
/// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
181
181
/// used in the witness script generation), you must pass the counterparty
182
182
/// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
183
- /// [`EcdsaChannelSigner ::provide_channel_parameters`]) and the provided
183
+ /// [`ChannelSigner ::provide_channel_parameters`]) and the provided
184
184
/// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
185
185
/// [`chan_utils::derive_public_revocation_key`].
186
186
///
@@ -191,7 +191,7 @@ pub enum SpendableOutputDescriptor {
191
191
/// [`chan_utils::get_revokeable_redeemscript`].
192
192
DelayedPaymentOutput ( DelayedPaymentOutputDescriptor ) ,
193
193
/// An output to a P2WPKH, spendable exclusively by our payment key (i.e., the private key
194
- /// which corresponds to the `payment_point` in [`EcdsaChannelSigner ::pubkeys`]). The witness
194
+ /// which corresponds to the `payment_point` in [`ChannelSigner ::pubkeys`]). The witness
195
195
/// in the spending input is, thus, simply:
196
196
/// ```bitcoin
197
197
/// <BIP 143 signature> <payment key>
@@ -212,18 +212,14 @@ impl_writeable_tlv_based_enum!(SpendableOutputDescriptor,
212
212
( 2 , StaticPaymentOutput ) ,
213
213
) ;
214
214
215
- /// A trait to sign Lightning channel transactions as described in
216
- /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
217
- ///
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.
222
- pub trait EcdsaChannelSigner {
215
+ /// A trait to handle Lightning channel key material without concretizing the channel type or
216
+ /// the signature mechanism.
217
+ pub trait ChannelSigner {
223
218
/// Gets the per-commitment point for a specific commitment number
224
219
///
225
220
/// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
226
221
fn get_per_commitment_point ( & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> PublicKey ;
222
+
227
223
/// Gets the commitment secret for a specific commitment number as part of the revocation process
228
224
///
229
225
/// An external signer implementation should error here if the commitment was already signed
@@ -234,6 +230,7 @@ pub trait EcdsaChannelSigner {
234
230
/// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
235
231
// TODO: return a Result so we can signal a validation error
236
232
fn release_commitment_secret ( & self , idx : u64 ) -> [ u8 ; 32 ] ;
233
+
237
234
/// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
238
235
///
239
236
/// This is required in order for the signer to make sure that releasing a commitment
@@ -249,12 +246,35 @@ pub trait EcdsaChannelSigner {
249
246
/// irrelevant or duplicate preimages.
250
247
fn validate_holder_commitment ( & self , holder_tx : & HolderCommitmentTransaction ,
251
248
preimages : Vec < PaymentPreimage > ) -> Result < ( ) , ( ) > ;
249
+
252
250
/// Returns the holder's channel public keys and basepoints.
253
251
fn pubkeys ( & self ) -> & ChannelPublicKeys ;
252
+
254
253
/// Returns an arbitrary identifier describing the set of keys which are provided back to you in
255
254
/// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
256
255
/// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
257
256
fn channel_keys_id ( & self ) -> [ u8 ; 32 ] ;
257
+
258
+ /// Set the counterparty static channel data, including basepoints,
259
+ /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
260
+ ///
261
+ /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
262
+ /// instance, LDK will call this method exactly once - either immediately after construction
263
+ /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
264
+ /// information has been generated.
265
+ ///
266
+ /// channel_parameters.is_populated() MUST be true.
267
+ fn provide_channel_parameters ( & mut self , channel_parameters : & ChannelTransactionParameters ) ;
268
+ }
269
+
270
+ /// A trait to sign Lightning channel transactions as described in
271
+ /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
272
+ ///
273
+ /// Signing services could be implemented on a hardware wallet and should implement signing
274
+ /// policies in order to be secure. Please refer to the [VLS Policy
275
+ /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
276
+ /// for an example of such policies.
277
+ pub trait EcdsaChannelSigner : ChannelSigner {
258
278
/// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
259
279
///
260
280
/// Note that if signing fails or is rejected, the channel will be force-closed.
@@ -395,16 +415,6 @@ pub trait EcdsaChannelSigner {
395
415
fn sign_channel_announcement_with_funding_key (
396
416
& self , msg : & UnsignedChannelAnnouncement , secp_ctx : & Secp256k1 < secp256k1:: All >
397
417
) -> Result < Signature , ( ) > ;
398
- /// Set the counterparty static channel data, including basepoints,
399
- /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
400
- ///
401
- /// This data is static, and will never change for a channel once set. For a given [`EcdsaChannelSigner`]
402
- /// instance, LDK will call this method exactly once - either immediately after construction
403
- /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
404
- /// information has been generated.
405
- ///
406
- /// channel_parameters.is_populated() MUST be true.
407
- fn provide_channel_parameters ( & mut self , channel_parameters : & ChannelTransactionParameters ) ;
408
418
}
409
419
410
420
/// A writeable signer.
@@ -511,7 +521,7 @@ pub trait SignerProvider {
511
521
/// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
512
522
/// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
513
523
/// re-derived from its `channel_keys_id`, which can be obtained through its trait method
514
- /// [`EcdsaChannelSigner ::channel_keys_id`].
524
+ /// [`ChannelSigner ::channel_keys_id`].
515
525
fn derive_channel_signer ( & self , channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] ) -> Self :: Signer ;
516
526
517
527
/// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
@@ -620,38 +630,38 @@ impl InMemorySigner {
620
630
621
631
/// Returns the counterparty's pubkeys.
622
632
///
623
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
633
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
624
634
pub fn counterparty_pubkeys ( & self ) -> & ChannelPublicKeys { & self . get_channel_parameters ( ) . counterparty_parameters . as_ref ( ) . unwrap ( ) . pubkeys }
625
635
/// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
626
636
/// transactions, i.e., the amount of time that we have to wait to recover our funds if we
627
637
/// broadcast a transaction.
628
638
///
629
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
639
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
630
640
pub fn counterparty_selected_contest_delay ( & self ) -> u16 { self . get_channel_parameters ( ) . counterparty_parameters . as_ref ( ) . unwrap ( ) . selected_contest_delay }
631
641
/// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
632
642
/// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
633
643
/// if they broadcast a transaction.
634
644
///
635
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
645
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
636
646
pub fn holder_selected_contest_delay ( & self ) -> u16 { self . get_channel_parameters ( ) . holder_selected_contest_delay }
637
647
/// Returns whether the holder is the initiator.
638
648
///
639
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
649
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
640
650
pub fn is_outbound ( & self ) -> bool { self . get_channel_parameters ( ) . is_outbound_from_holder }
641
651
/// Funding outpoint
642
652
///
643
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
653
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
644
654
pub fn funding_outpoint ( & self ) -> & OutPoint { self . get_channel_parameters ( ) . funding_outpoint . as_ref ( ) . unwrap ( ) }
645
655
/// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
646
656
/// building transactions.
647
657
///
648
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
658
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
649
659
pub fn get_channel_parameters ( & self ) -> & ChannelTransactionParameters {
650
660
self . channel_parameters . as_ref ( ) . unwrap ( )
651
661
}
652
662
/// Returns whether anchors should be used.
653
663
///
654
- /// Will panic if [`EcdsaChannelSigner ::provide_channel_parameters`] has not been called before.
664
+ /// Will panic if [`ChannelSigner ::provide_channel_parameters`] has not been called before.
655
665
pub fn opt_anchors ( & self ) -> bool {
656
666
self . get_channel_parameters ( ) . opt_anchors . is_some ( )
657
667
}
@@ -725,7 +735,7 @@ impl InMemorySigner {
725
735
}
726
736
}
727
737
728
- impl EcdsaChannelSigner for InMemorySigner {
738
+ impl ChannelSigner for InMemorySigner {
729
739
fn get_per_commitment_point ( & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> PublicKey {
730
740
let commitment_secret = SecretKey :: from_slice ( & chan_utils:: build_commitment_secret ( & self . commitment_seed , idx) ) . unwrap ( ) ;
731
741
PublicKey :: from_secret_key ( secp_ctx, & commitment_secret)
@@ -743,6 +753,18 @@ impl EcdsaChannelSigner for InMemorySigner {
743
753
744
754
fn channel_keys_id ( & self ) -> [ u8 ; 32 ] { self . channel_keys_id }
745
755
756
+ fn provide_channel_parameters ( & mut self , channel_parameters : & ChannelTransactionParameters ) {
757
+ assert ! ( self . channel_parameters. is_none( ) || self . channel_parameters. as_ref( ) . unwrap( ) == channel_parameters) ;
758
+ if self . channel_parameters . is_some ( ) {
759
+ // The channel parameters were already set and they match, return early.
760
+ return ;
761
+ }
762
+ assert ! ( channel_parameters. is_populated( ) , "Channel parameters must be fully populated" ) ;
763
+ self . channel_parameters = Some ( channel_parameters. clone ( ) ) ;
764
+ }
765
+ }
766
+
767
+ impl EcdsaChannelSigner for InMemorySigner {
746
768
fn sign_counterparty_commitment ( & self , commitment_tx : & CommitmentTransaction , _preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
747
769
let trusted_tx = commitment_tx. trust ( ) ;
748
770
let keys = trusted_tx. keys ( ) ;
@@ -871,16 +893,6 @@ impl EcdsaChannelSigner for InMemorySigner {
871
893
let msghash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
872
894
Ok ( sign ( secp_ctx, & msghash, & self . funding_key ) )
873
895
}
874
-
875
- fn provide_channel_parameters ( & mut self , channel_parameters : & ChannelTransactionParameters ) {
876
- assert ! ( self . channel_parameters. is_none( ) || self . channel_parameters. as_ref( ) . unwrap( ) == channel_parameters) ;
877
- if self . channel_parameters . is_some ( ) {
878
- // The channel parameters were already set and they match, return early.
879
- return ;
880
- }
881
- assert ! ( channel_parameters. is_populated( ) , "Channel parameters must be fully populated" ) ;
882
- self . channel_parameters = Some ( channel_parameters. clone ( ) ) ;
883
- }
884
896
}
885
897
886
898
const SERIALIZATION_VERSION : u8 = 1 ;
0 commit comments