@@ -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 } ;
@@ -716,6 +715,36 @@ impl HTLCDescriptor {
716715 }
717716}
718717
718+ /// Extension trait for [`ChannelSigner`] providing access to additional channel-specific
719+ /// details. In particular, this is useful for functional tests.
720+ pub trait ChannelSignerExt : ChannelSigner {
721+ /// Returns the commitment seed for the channel.
722+ fn commitment_seed ( & self ) -> [ u8 ; 32 ] ;
723+ /// Returns the counterparty's pubkeys.
724+ ///
725+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
726+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
727+ fn counterparty_pubkeys ( & self ) -> Option < & ChannelPublicKeys > ;
728+ /// Funding outpoint
729+ ///
730+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
731+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
732+ fn funding_outpoint ( & self ) -> Option < & OutPoint > ;
733+ /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
734+ /// building transactions.
735+ ///
736+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
737+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
738+ fn get_channel_parameters ( & self ) -> Option < & ChannelTransactionParameters > ;
739+
740+ /// Returns the channel type features of the channel parameters. Should be helpful for
741+ /// determining a channel's category, i.e. legacy/anchors/taproot/etc.
742+ ///
743+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
744+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
745+ fn channel_type_features ( & self ) -> Option < & ChannelTypeFeatures > ;
746+ }
747+
719748/// A trait to handle Lightning channel key material without concretizing the channel type or
720749/// the signature mechanism.
721750///
@@ -920,10 +949,10 @@ pub trait OutputSpender {
920949 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
921950 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
922951 /// does not match the one we can spend.
923- fn spend_spendable_outputs < C : Signing > (
952+ fn spend_spendable_outputs (
924953 & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > ,
925954 change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 ,
926- locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ,
955+ locktime : Option < LockTime > , secp_ctx : & Secp256k1 < All > ,
927956 ) -> Result < Transaction , ( ) > ;
928957}
929958
@@ -1129,16 +1158,6 @@ impl InMemorySigner {
11291158 }
11301159 }
11311160
1132- /// Returns the counterparty's pubkeys.
1133- ///
1134- /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1135- /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1136- pub fn counterparty_pubkeys ( & self ) -> Option < & ChannelPublicKeys > {
1137- self . get_channel_parameters ( ) . and_then ( |params| {
1138- params. counterparty_parameters . as_ref ( ) . map ( |params| & params. pubkeys )
1139- } )
1140- }
1141-
11421161 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
11431162 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
11441163 /// broadcast a transaction.
@@ -1169,14 +1188,6 @@ impl InMemorySigner {
11691188 self . get_channel_parameters ( ) . map ( |params| params. is_outbound_from_holder )
11701189 }
11711190
1172- /// Funding outpoint
1173- ///
1174- /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1175- /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1176- pub fn funding_outpoint ( & self ) -> Option < & OutPoint > {
1177- self . get_channel_parameters ( ) . map ( |params| params. funding_outpoint . as_ref ( ) ) . flatten ( )
1178- }
1179-
11801191 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
11811192 /// building transactions.
11821193 ///
@@ -1186,15 +1197,6 @@ impl InMemorySigner {
11861197 self . channel_parameters . as_ref ( )
11871198 }
11881199
1189- /// Returns the channel type features of the channel parameters. Should be helpful for
1190- /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1191- ///
1192- /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1193- /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1194- pub fn channel_type_features ( & self ) -> Option < & ChannelTypeFeatures > {
1195- self . get_channel_parameters ( ) . map ( |params| & params. channel_type_features )
1196- }
1197-
11981200 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
11991201 /// by `descriptor`, returning the witness stack for the input.
12001202 ///
@@ -1346,6 +1348,35 @@ impl EntropySource for InMemorySigner {
13461348 }
13471349}
13481350
1351+ impl ChannelSignerExt for InMemorySigner {
1352+ fn commitment_seed ( & self ) -> [ u8 ; 32 ] {
1353+ self . commitment_seed
1354+ }
1355+
1356+ fn counterparty_pubkeys ( & self ) -> Option < & ChannelPublicKeys > {
1357+ self . get_channel_parameters ( ) . and_then ( |params| {
1358+ params. counterparty_parameters . as_ref ( ) . map ( |params| & params. pubkeys )
1359+ } )
1360+ }
1361+
1362+ fn funding_outpoint ( & self ) -> Option < & OutPoint > {
1363+ self . get_channel_parameters ( ) . map ( |params| params. funding_outpoint . as_ref ( ) ) . flatten ( )
1364+ }
1365+
1366+ fn get_channel_parameters ( & self ) -> Option < & ChannelTransactionParameters > {
1367+ self . channel_parameters . as_ref ( )
1368+ }
1369+
1370+ /// Returns the channel type features of the channel parameters. Should be helpful for
1371+ /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1372+ ///
1373+ /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1374+ /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1375+ fn channel_type_features ( & self ) -> Option < & ChannelTypeFeatures > {
1376+ self . get_channel_parameters ( ) . map ( |params| & params. channel_type_features )
1377+ }
1378+ }
1379+
13491380impl ChannelSigner for InMemorySigner {
13501381 fn get_per_commitment_point (
13511382 & self , idx : u64 , secp_ctx : & Secp256k1 < secp256k1:: All > ,
@@ -1478,7 +1509,7 @@ impl EcdsaChannelSigner for InMemorySigner {
14781509 ) )
14791510 }
14801511
1481- #[ cfg( any( test, feature = "unsafe_revoked_tx_signing" ) ) ]
1512+ #[ cfg( any( test, feature = "_test_utils" , feature = " unsafe_revoked_tx_signing") ) ]
14821513 fn unsafe_sign_holder_commitment (
14831514 & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ,
14841515 ) -> Result < Signature , ( ) > {
@@ -2227,10 +2258,10 @@ impl OutputSpender for KeysManager {
22272258 ///
22282259 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
22292260 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2230- fn spend_spendable_outputs < C : Signing > (
2261+ fn spend_spendable_outputs (
22312262 & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > ,
22322263 change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 ,
2233- locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ,
2264+ locktime : Option < LockTime > , secp_ctx : & Secp256k1 < All > ,
22342265 ) -> Result < Transaction , ( ) > {
22352266 let ( mut psbt, expected_max_weight) =
22362267 SpendableOutputDescriptor :: create_spendable_outputs_psbt (
@@ -2385,10 +2416,10 @@ impl NodeSigner for PhantomKeysManager {
23852416impl OutputSpender for PhantomKeysManager {
23862417 /// See [`OutputSpender::spend_spendable_outputs`] and [`KeysManager::spend_spendable_outputs`]
23872418 /// for documentation on this method.
2388- fn spend_spendable_outputs < C : Signing > (
2419+ fn spend_spendable_outputs (
23892420 & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > ,
23902421 change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 ,
2391- locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ,
2422+ locktime : Option < LockTime > , secp_ctx : & Secp256k1 < All > ,
23922423 ) -> Result < Transaction , ( ) > {
23932424 self . inner . spend_spendable_outputs (
23942425 descriptors,
0 commit comments