@@ -212,18 +212,12 @@ 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
+ pub trait ChannelSigner {
223
216
/// Gets the per-commitment point for a specific commitment number
224
217
///
225
218
/// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
226
219
fn get_per_commitment_point ( & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> PublicKey ;
220
+
227
221
/// Gets the commitment secret for a specific commitment number as part of the revocation process
228
222
///
229
223
/// An external signer implementation should error here if the commitment was already signed
@@ -234,6 +228,7 @@ pub trait EcdsaChannelSigner {
234
228
/// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
235
229
// TODO: return a Result so we can signal a validation error
236
230
fn release_commitment_secret ( & self , idx : u64 ) -> [ u8 ; 32 ] ;
231
+
237
232
/// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
238
233
///
239
234
/// This is required in order for the signer to make sure that releasing a commitment
@@ -249,12 +244,35 @@ pub trait EcdsaChannelSigner {
249
244
/// irrelevant or duplicate preimages.
250
245
fn validate_holder_commitment ( & self , holder_tx : & HolderCommitmentTransaction ,
251
246
preimages : Vec < PaymentPreimage > ) -> Result < ( ) , ( ) > ;
247
+
252
248
/// Returns the holder's channel public keys and basepoints.
253
249
fn pubkeys ( & self ) -> & ChannelPublicKeys ;
250
+
254
251
/// Returns an arbitrary identifier describing the set of keys which are provided back to you in
255
252
/// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
256
253
/// [`BaseSign`] object uniquely and lookup or re-derive its keys.
257
254
fn channel_keys_id ( & self ) -> [ u8 ; 32 ] ;
255
+
256
+ /// Set the counterparty static channel data, including basepoints,
257
+ /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
258
+ ///
259
+ /// This data is static, and will never change for a channel once set. For a given [`BaseSign`]
260
+ /// instance, LDK will call this method exactly once - either immediately after construction
261
+ /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
262
+ /// information has been generated.
263
+ ///
264
+ /// channel_parameters.is_populated() MUST be true.
265
+ fn provide_channel_parameters ( & mut self , channel_parameters : & ChannelTransactionParameters ) ;
266
+ }
267
+
268
+ /// A trait to sign Lightning channel transactions as described in
269
+ /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
270
+ ///
271
+ /// Signing services could be implemented on a hardware wallet and should implement signing
272
+ /// policies in order to be secure. Please refer to the [VLS Policy
273
+ /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
274
+ /// for an example of such policies.
275
+ pub trait EcdsaChannelSigner : ChannelSigner {
258
276
/// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
259
277
///
260
278
/// Note that if signing fails or is rejected, the channel will be force-closed.
@@ -395,16 +413,6 @@ pub trait EcdsaChannelSigner {
395
413
fn sign_channel_announcement_with_funding_key (
396
414
& self , msg : & UnsignedChannelAnnouncement , secp_ctx : & Secp256k1 < secp256k1:: All >
397
415
) -> 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 [`BaseSign`]
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
416
}
409
417
410
418
/// A writeable signer.
@@ -725,7 +733,7 @@ impl InMemorySigner {
725
733
}
726
734
}
727
735
728
- impl EcdsaChannelSigner for InMemorySigner {
736
+ impl ChannelSigner for InMemorySigner {
729
737
fn get_per_commitment_point ( & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> PublicKey {
730
738
let commitment_secret = SecretKey :: from_slice ( & chan_utils:: build_commitment_secret ( & self . commitment_seed , idx) ) . unwrap ( ) ;
731
739
PublicKey :: from_secret_key ( secp_ctx, & commitment_secret)
@@ -743,6 +751,18 @@ impl EcdsaChannelSigner for InMemorySigner {
743
751
744
752
fn channel_keys_id ( & self ) -> [ u8 ; 32 ] { self . channel_keys_id }
745
753
754
+ fn provide_channel_parameters ( & mut self , channel_parameters : & ChannelTransactionParameters ) {
755
+ assert ! ( self . channel_parameters. is_none( ) || self . channel_parameters. as_ref( ) . unwrap( ) == channel_parameters) ;
756
+ if self . channel_parameters . is_some ( ) {
757
+ // The channel parameters were already set and they match, return early.
758
+ return ;
759
+ }
760
+ assert ! ( channel_parameters. is_populated( ) , "Channel parameters must be fully populated" ) ;
761
+ self . channel_parameters = Some ( channel_parameters. clone ( ) ) ;
762
+ }
763
+ }
764
+
765
+ impl EcdsaChannelSigner for InMemorySigner {
746
766
fn sign_counterparty_commitment ( & self , commitment_tx : & CommitmentTransaction , _preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
747
767
let trusted_tx = commitment_tx. trust ( ) ;
748
768
let keys = trusted_tx. keys ( ) ;
@@ -871,16 +891,6 @@ impl EcdsaChannelSigner for InMemorySigner {
871
891
let msghash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
872
892
Ok ( sign ( secp_ctx, & msghash, & self . funding_key ) )
873
893
}
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
894
}
885
895
886
896
const SERIALIZATION_VERSION : u8 = 1 ;
0 commit comments