@@ -31,7 +31,6 @@ use bitcoin::hashes::{Hash, HashEngine};
3131use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
3232use bitcoin:: secp256k1:: ecdsa:: { RecoverableSignature , Signature } ;
3333use bitcoin:: secp256k1:: schnorr;
34- #[ cfg( taproot) ]
3534use bitcoin:: secp256k1:: All ;
3635use bitcoin:: secp256k1:: { Keypair , PublicKey , Scalar , Secp256k1 , SecretKey , Signing } ;
3736use bitcoin:: { secp256k1, Psbt , Sequence , Txid , WPubkeyHash , Witness } ;
@@ -725,6 +724,36 @@ impl HTLCDescriptor {
725724 }
726725}
727726
727+ /// Extension trait for [`ChannelSigner`] providing access to additional channel-specific
728+ /// details. In particular, this is useful for functional tests.
729+ pub trait ChannelSignerExt : ChannelSigner {
730+ /// Returns the commitment seed for the channel.
731+ fn commitment_seed ( & self ) -> [ u8 ; 32 ] ;
732+ /// Returns the counterparty's pubkeys.
733+ ///
734+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
735+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
736+ fn counterparty_pubkeys ( & self ) -> Option < & ChannelPublicKeys > ;
737+ /// Funding outpoint
738+ ///
739+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
740+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
741+ fn funding_outpoint ( & self ) -> Option < & OutPoint > ;
742+ /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
743+ /// building transactions.
744+ ///
745+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
746+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
747+ fn get_channel_parameters ( & self ) -> Option < & ChannelTransactionParameters > ;
748+
749+ /// Returns the channel type features of the channel parameters. Should be helpful for
750+ /// determining a channel's category, i.e. legacy/anchors/taproot/etc.
751+ ///
752+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
753+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
754+ fn channel_type_features ( & self ) -> Option < & ChannelTypeFeatures > ;
755+ }
756+
728757/// A trait to handle Lightning channel key material without concretizing the channel type or
729758/// the signature mechanism.
730759///
@@ -929,10 +958,10 @@ pub trait OutputSpender {
929958 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
930959 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
931960 /// does not match the one we can spend.
932- fn spend_spendable_outputs < C : Signing > (
961+ fn spend_spendable_outputs (
933962 & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > ,
934963 change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 ,
935- locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ,
964+ locktime : Option < LockTime > , secp_ctx : & Secp256k1 < All > ,
936965 ) -> Result < Transaction , ( ) > ;
937966}
938967
@@ -1138,16 +1167,6 @@ impl InMemorySigner {
11381167 }
11391168 }
11401169
1141- /// Returns the counterparty's pubkeys.
1142- ///
1143- /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1144- /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1145- pub fn counterparty_pubkeys ( & self ) -> Option < & ChannelPublicKeys > {
1146- self . get_channel_parameters ( ) . and_then ( |params| {
1147- params. counterparty_parameters . as_ref ( ) . map ( |params| & params. pubkeys )
1148- } )
1149- }
1150-
11511170 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
11521171 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
11531172 /// broadcast a transaction.
@@ -1178,14 +1197,6 @@ impl InMemorySigner {
11781197 self . get_channel_parameters ( ) . map ( |params| params. is_outbound_from_holder )
11791198 }
11801199
1181- /// Funding outpoint
1182- ///
1183- /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1184- /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1185- pub fn funding_outpoint ( & self ) -> Option < & OutPoint > {
1186- self . get_channel_parameters ( ) . map ( |params| params. funding_outpoint . as_ref ( ) ) . flatten ( )
1187- }
1188-
11891200 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
11901201 /// building transactions.
11911202 ///
@@ -1195,15 +1206,6 @@ impl InMemorySigner {
11951206 self . channel_parameters . as_ref ( )
11961207 }
11971208
1198- /// Returns the channel type features of the channel parameters. Should be helpful for
1199- /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1200- ///
1201- /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1202- /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1203- pub fn channel_type_features ( & self ) -> Option < & ChannelTypeFeatures > {
1204- self . get_channel_parameters ( ) . map ( |params| & params. channel_type_features )
1205- }
1206-
12071209 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
12081210 /// by `descriptor`, returning the witness stack for the input.
12091211 ///
@@ -1355,6 +1357,35 @@ impl EntropySource for InMemorySigner {
13551357 }
13561358}
13571359
1360+ impl ChannelSignerExt for InMemorySigner {
1361+ fn commitment_seed ( & self ) -> [ u8 ; 32 ] {
1362+ self . commitment_seed
1363+ }
1364+
1365+ fn counterparty_pubkeys ( & self ) -> Option < & ChannelPublicKeys > {
1366+ self . get_channel_parameters ( ) . and_then ( |params| {
1367+ params. counterparty_parameters . as_ref ( ) . map ( |params| & params. pubkeys )
1368+ } )
1369+ }
1370+
1371+ fn funding_outpoint ( & self ) -> Option < & OutPoint > {
1372+ self . get_channel_parameters ( ) . map ( |params| params. funding_outpoint . as_ref ( ) ) . flatten ( )
1373+ }
1374+
1375+ fn get_channel_parameters ( & self ) -> Option < & ChannelTransactionParameters > {
1376+ self . channel_parameters . as_ref ( )
1377+ }
1378+
1379+ /// Returns the channel type features of the channel parameters. Should be helpful for
1380+ /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1381+ ///
1382+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1383+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1384+ fn channel_type_features ( & self ) -> Option < & ChannelTypeFeatures > {
1385+ self . get_channel_parameters ( ) . map ( |params| & params. channel_type_features )
1386+ }
1387+ }
1388+
13581389impl ChannelSigner for InMemorySigner {
13591390 fn get_per_commitment_point (
13601391 & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ,
@@ -1487,7 +1518,7 @@ impl EcdsaChannelSigner for InMemorySigner {
14871518 ) )
14881519 }
14891520
1490- #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
1521+ #[ cfg( any( test, feature = "_test_utils" , feature = " unsafe_revoked_tx_signing") ) ]
14911522 fn unsafe_sign_holder_commitment (
14921523 & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
14931524 ) -> Result < Signature , ( ) > {
@@ -2236,10 +2267,10 @@ impl OutputSpender for KeysManager {
22362267 ///
22372268 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
22382269 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2239- fn spend_spendable_outputs < C : Signing > (
2270+ fn spend_spendable_outputs (
22402271 & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > ,
22412272 change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 ,
2242- locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ,
2273+ locktime : Option < LockTime > , secp_ctx : & Secp256k1 < All > ,
22432274 ) -> Result < Transaction , ( ) > {
22442275 let ( mut psbt, expected_max_weight) =
22452276 SpendableOutputDescriptor :: create_spendable_outputs_psbt (
@@ -2394,10 +2425,10 @@ impl NodeSigner for PhantomKeysManager {
23942425impl OutputSpender for PhantomKeysManager {
23952426 /// See [`OutputSpender::spend_spendable_outputs`] and [`KeysManager::spend_spendable_outputs`]
23962427 /// for documentation on this method.
2397- fn spend_spendable_outputs < C : Signing > (
2428+ fn spend_spendable_outputs (
23982429 & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > ,
23992430 change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 ,
2400- locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ,
2431+ locktime : Option < LockTime > , secp_ctx : & Secp256k1 < All > ,
24012432 ) -> Result < Transaction , ( ) > {
24022433 self . inner . spend_spendable_outputs (
24032434 descriptors,
0 commit comments