@@ -15,6 +15,8 @@ pub(crate) mod utils;
1515
1616use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
1717
18+ use core:: ops:: Deref ;
19+
1820use crate :: ln:: msgs:: DecodeError ;
1921use crate :: offers:: invoice:: BlindedPayInfo ;
2022use crate :: routing:: gossip:: { NodeId , ReadOnlyNetworkGraph } ;
@@ -115,9 +117,9 @@ pub struct BlindedHop {
115117
116118impl BlindedPath {
117119 /// Create a one-hop blinded path for a message.
118- pub fn one_hop_for_message < ES : EntropySource + ? Sized , T : secp256k1:: Signing + secp256k1:: Verification > (
119- recipient_node_id : PublicKey , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
120- ) -> Result < Self , ( ) > {
120+ pub fn one_hop_for_message < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
121+ recipient_node_id : PublicKey , entropy_source : ES , secp_ctx : & Secp256k1 < T >
122+ ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
121123 Self :: new_for_message ( & [ recipient_node_id] , entropy_source, secp_ctx)
122124 }
123125
@@ -126,9 +128,9 @@ impl BlindedPath {
126128 ///
127129 /// Errors if no hops are provided or if `node_pk`(s) are invalid.
128130 // TODO: make all payloads the same size with padding + add dummy hops
129- pub fn new_for_message < ES : EntropySource + ? Sized , T : secp256k1:: Signing + secp256k1:: Verification > (
130- node_pks : & [ PublicKey ] , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
131- ) -> Result < Self , ( ) > {
131+ pub fn new_for_message < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
132+ node_pks : & [ PublicKey ] , entropy_source : ES , secp_ctx : & Secp256k1 < T >
133+ ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
132134 if node_pks. is_empty ( ) { return Err ( ( ) ) }
133135 let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
134136 let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
@@ -142,15 +144,15 @@ impl BlindedPath {
142144 }
143145
144146 /// Create a one-hop blinded path for a payment.
145- pub fn one_hop_for_payment < ES : EntropySource + ? Sized , T : secp256k1:: Signing + secp256k1:: Verification > (
147+ pub fn one_hop_for_payment < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
146148 payee_node_id : PublicKey , payee_tlvs : payment:: ReceiveTlvs , min_final_cltv_expiry_delta : u16 ,
147- entropy_source : & ES , secp_ctx : & Secp256k1 < T >
148- ) -> Result < ( BlindedPayInfo , Self ) , ( ) > {
149+ entropy_source : ES , secp_ctx : & Secp256k1 < T >
150+ ) -> Result < ( BlindedPayInfo , Self ) , ( ) > where ES :: Target : EntropySource {
149151 // This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
150152 // be in relation to a specific channel.
151153 let htlc_maximum_msat = u64:: max_value ( ) ;
152154 Self :: new_for_payment (
153- & [ ] , payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
155+ Vec :: new ( ) , payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
154156 entropy_source, secp_ctx
155157 )
156158 }
@@ -164,25 +166,25 @@ impl BlindedPath {
164166 ///
165167 /// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
166168 // TODO: make all payloads the same size with padding + add dummy hops
167- pub fn new_for_payment < ES : EntropySource + ? Sized , T : secp256k1:: Signing + secp256k1:: Verification > (
168- intermediate_nodes : & [ payment:: ForwardNode ] , payee_node_id : PublicKey ,
169+ pub fn new_for_payment < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
170+ intermediate_nodes : Vec < payment:: ForwardNode > , payee_node_id : PublicKey ,
169171 payee_tlvs : payment:: ReceiveTlvs , htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 ,
170- entropy_source : & ES , secp_ctx : & Secp256k1 < T >
171- ) -> Result < ( BlindedPayInfo , Self ) , ( ) > {
172+ entropy_source : ES , secp_ctx : & Secp256k1 < T >
173+ ) -> Result < ( BlindedPayInfo , Self ) , ( ) > where ES :: Target : EntropySource {
172174 let introduction_node = IntroductionNode :: NodeId (
173175 intermediate_nodes. first ( ) . map_or ( payee_node_id, |n| n. node_id )
174176 ) ;
175177 let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
176178 let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
177179
178180 let blinded_payinfo = payment:: compute_payinfo (
179- intermediate_nodes, & payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
181+ & intermediate_nodes, & payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
180182 ) ?;
181183 Ok ( ( blinded_payinfo, BlindedPath {
182184 introduction_node,
183185 blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
184186 blinded_hops : payment:: blinded_hops (
185- secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, & blinding_secret
187+ secp_ctx, & intermediate_nodes, payee_node_id, payee_tlvs, & blinding_secret
186188 ) . map_err ( |_| ( ) ) ?,
187189 } ) )
188190 }
@@ -266,15 +268,15 @@ impl_writeable!(BlindedHop, {
266268
267269impl Direction {
268270 /// Returns the [`NodeId`] from the inputs corresponding to the direction.
269- pub fn select_node_id < ' a > ( & self , node_a : & ' a NodeId , node_b : & ' a NodeId ) -> & ' a NodeId {
271+ pub ( crate ) fn select_node_id < ' a > ( & self , node_a : & ' a NodeId , node_b : & ' a NodeId ) -> & ' a NodeId {
270272 match self {
271273 Direction :: NodeOne => core:: cmp:: min ( node_a, node_b) ,
272274 Direction :: NodeTwo => core:: cmp:: max ( node_a, node_b) ,
273275 }
274276 }
275277
276278 /// Returns the [`PublicKey`] from the inputs corresponding to the direction.
277- pub fn select_pubkey < ' a > ( & self , node_a : & ' a PublicKey , node_b : & ' a PublicKey ) -> & ' a PublicKey {
279+ pub ( crate ) fn select_pubkey < ' a > ( & self , node_a : & ' a PublicKey , node_b : & ' a PublicKey ) -> & ' a PublicKey {
278280 let ( node_one, node_two) = if NodeId :: from_pubkey ( node_a) < NodeId :: from_pubkey ( node_b) {
279281 ( node_a, node_b)
280282 } else {
0 commit comments