@@ -15,6 +15,8 @@ pub(crate) mod utils;
15
15
16
16
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
17
17
18
+ use core:: ops:: Deref ;
19
+
18
20
use crate :: ln:: msgs:: DecodeError ;
19
21
use crate :: offers:: invoice:: BlindedPayInfo ;
20
22
use crate :: routing:: gossip:: { NodeId , ReadOnlyNetworkGraph } ;
@@ -115,9 +117,9 @@ pub struct BlindedHop {
115
117
116
118
impl BlindedPath {
117
119
/// 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 {
121
123
Self :: new_for_message ( & [ recipient_node_id] , entropy_source, secp_ctx)
122
124
}
123
125
@@ -126,9 +128,9 @@ impl BlindedPath {
126
128
///
127
129
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
128
130
// 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 {
132
134
if node_pks. is_empty ( ) { return Err ( ( ) ) }
133
135
let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
134
136
let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
@@ -142,15 +144,15 @@ impl BlindedPath {
142
144
}
143
145
144
146
/// 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 > (
146
148
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 {
149
151
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
150
152
// be in relation to a specific channel.
151
153
let htlc_maximum_msat = u64:: max_value ( ) ;
152
154
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,
154
156
entropy_source, secp_ctx
155
157
)
156
158
}
@@ -164,25 +166,25 @@ impl BlindedPath {
164
166
///
165
167
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
166
168
// 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 ,
169
171
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 {
172
174
let introduction_node = IntroductionNode :: NodeId (
173
175
intermediate_nodes. first ( ) . map_or ( payee_node_id, |n| n. node_id )
174
176
) ;
175
177
let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
176
178
let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
177
179
178
180
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
180
182
) ?;
181
183
Ok ( ( blinded_payinfo, BlindedPath {
182
184
introduction_node,
183
185
blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
184
186
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
186
188
) . map_err ( |_| ( ) ) ?,
187
189
} ) )
188
190
}
@@ -266,15 +268,15 @@ impl_writeable!(BlindedHop, {
266
268
267
269
impl Direction {
268
270
/// 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 {
270
272
match self {
271
273
Direction :: NodeOne => core:: cmp:: min ( node_a, node_b) ,
272
274
Direction :: NodeTwo => core:: cmp:: max ( node_a, node_b) ,
273
275
}
274
276
}
275
277
276
278
/// 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 {
278
280
let ( node_one, node_two) = if NodeId :: from_pubkey ( node_a) < NodeId :: from_pubkey ( node_b) {
279
281
( node_a, node_b)
280
282
} else {
0 commit comments