@@ -212,18 +212,14 @@ impl_writeable_tlv_based_enum!(SpendableOutputDescriptor,
212212 ( 2 , StaticPaymentOutput ) ,
213213) ;
214214
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 {
223218 /// Gets the per-commitment point for a specific commitment number
224219 ///
225220 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
226221 fn get_per_commitment_point ( & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> PublicKey ;
222+
227223 /// Gets the commitment secret for a specific commitment number as part of the revocation process
228224 ///
229225 /// An external signer implementation should error here if the commitment was already signed
@@ -234,6 +230,7 @@ pub trait EcdsaChannelSigner {
234230 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
235231 // TODO: return a Result so we can signal a validation error
236232 fn release_commitment_secret ( & self , idx : u64 ) -> [ u8 ; 32 ] ;
233+
237234 /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
238235 ///
239236 /// This is required in order for the signer to make sure that releasing a commitment
@@ -249,12 +246,35 @@ pub trait EcdsaChannelSigner {
249246 /// irrelevant or duplicate preimages.
250247 fn validate_holder_commitment ( & self , holder_tx : & HolderCommitmentTransaction ,
251248 preimages : Vec < PaymentPreimage > ) -> Result < ( ) , ( ) > ;
249+
252250 /// Returns the holder's channel public keys and basepoints.
253251 fn pubkeys ( & self ) -> & ChannelPublicKeys ;
252+
254253 /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
255254 /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
256255 /// [`BaseSign`] object uniquely and lookup or re-derive its keys.
257256 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 [`BaseSign`]
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 {
258278 /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
259279 ///
260280 /// Note that if signing fails or is rejected, the channel will be force-closed.
@@ -395,16 +415,6 @@ pub trait EcdsaChannelSigner {
395415 fn sign_channel_announcement_with_funding_key (
396416 & self , msg : & UnsignedChannelAnnouncement , secp_ctx : & Secp256k1 < secp256k1:: All >
397417 ) -> 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 ) ;
408418}
409419
410420/// A writeable signer.
@@ -725,7 +735,7 @@ impl InMemorySigner {
725735 }
726736}
727737
728- impl EcdsaChannelSigner for InMemorySigner {
738+ impl ChannelSigner for InMemorySigner {
729739 fn get_per_commitment_point ( & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> PublicKey {
730740 let commitment_secret = SecretKey :: from_slice ( & chan_utils:: build_commitment_secret ( & self . commitment_seed , idx) ) . unwrap ( ) ;
731741 PublicKey :: from_secret_key ( secp_ctx, & commitment_secret)
@@ -743,6 +753,18 @@ impl EcdsaChannelSigner for InMemorySigner {
743753
744754 fn channel_keys_id ( & self ) -> [ u8 ; 32 ] { self . channel_keys_id }
745755
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 {
746768 fn sign_counterparty_commitment ( & self , commitment_tx : & CommitmentTransaction , _preimages : Vec < PaymentPreimage > , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
747769 let trusted_tx = commitment_tx. trust ( ) ;
748770 let keys = trusted_tx. keys ( ) ;
@@ -871,16 +893,6 @@ impl EcdsaChannelSigner for InMemorySigner {
871893 let msghash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
872894 Ok ( sign ( secp_ctx, & msghash, & self . funding_key ) )
873895 }
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- }
884896}
885897
886898const SERIALIZATION_VERSION : u8 = 1 ;
0 commit comments