12
12
use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
13
13
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
14
14
15
+ use crate :: blinded_path:: message:: MAX_DUMMY_HOPS_COUNT ;
15
16
use crate :: blinded_path:: utils:: { self , BlindedPathWithPadding } ;
16
17
use crate :: blinded_path:: { BlindedHop , BlindedPath , IntroductionNode , NodeIdLookUp } ;
17
18
use crate :: crypto:: streams:: ChaChaDualPolyReadAdapter ;
@@ -121,6 +122,32 @@ impl BlindedPaymentPath {
121
122
receive_auth_key : ReceiveAuthKey , payee_tlvs : ReceiveTlvs , htlc_maximum_msat : u64 ,
122
123
min_final_cltv_expiry_delta : u16 , entropy_source : ES , secp_ctx : & Secp256k1 < T > ,
123
124
) -> Result < Self , ( ) >
125
+ where
126
+ ES :: Target : EntropySource ,
127
+ {
128
+ BlindedPaymentPath :: new_with_dummy_hops (
129
+ intermediate_nodes,
130
+ payee_node_id,
131
+ 0 ,
132
+ receive_auth_key,
133
+ payee_tlvs,
134
+ htlc_maximum_msat,
135
+ min_final_cltv_expiry_delta,
136
+ entropy_source,
137
+ secp_ctx,
138
+ )
139
+ }
140
+
141
+ /// Same as [`BlindedPaymentPath::new`], but allows specifying a number of dummy hops.
142
+ ///
143
+ /// Note:
144
+ /// At most [`MAX_DUMMY_HOPS_COUNT`] dummy hops can be added to the blinded path.
145
+ pub fn new_with_dummy_hops < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
146
+ intermediate_nodes : & [ PaymentForwardNode ] , payee_node_id : PublicKey ,
147
+ dummy_hop_count : usize , receive_auth_key : ReceiveAuthKey , payee_tlvs : ReceiveTlvs ,
148
+ htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 , entropy_source : ES ,
149
+ secp_ctx : & Secp256k1 < T > ,
150
+ ) -> Result < Self , ( ) >
124
151
where
125
152
ES :: Target : EntropySource ,
126
153
{
@@ -145,6 +172,7 @@ impl BlindedPaymentPath {
145
172
secp_ctx,
146
173
intermediate_nodes,
147
174
payee_node_id,
175
+ dummy_hop_count,
148
176
payee_tlvs,
149
177
& blinding_secret,
150
178
receive_auth_key,
@@ -654,15 +682,19 @@ pub(crate) const PAYMENT_PADDING_ROUND_OFF: usize = 30;
654
682
/// Construct blinded payment hops for the given `intermediate_nodes` and payee info.
655
683
pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
656
684
secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ PaymentForwardNode ] , payee_node_id : PublicKey ,
657
- payee_tlvs : ReceiveTlvs , session_priv : & SecretKey , local_node_receive_key : ReceiveAuthKey ,
685
+ dummy_hop_count : usize , payee_tlvs : ReceiveTlvs , session_priv : & SecretKey ,
686
+ local_node_receive_key : ReceiveAuthKey ,
658
687
) -> Vec < BlindedHop > {
688
+ let dummy_count = core:: cmp:: min ( dummy_hop_count, MAX_DUMMY_HOPS_COUNT ) ;
659
689
let pks = intermediate_nodes
660
690
. iter ( )
661
691
. map ( |node| ( node. node_id , None ) )
692
+ . chain ( core:: iter:: repeat ( ( payee_node_id, Some ( local_node_receive_key) ) ) . take ( dummy_count) )
662
693
. chain ( core:: iter:: once ( ( payee_node_id, Some ( local_node_receive_key) ) ) ) ;
663
694
let tlvs = intermediate_nodes
664
695
. iter ( )
665
696
. map ( |node| BlindedPaymentTlvsRef :: Forward ( & node. tlvs ) )
697
+ . chain ( ( 0 ..dummy_count) . map ( |_| BlindedPaymentTlvsRef :: Dummy ( & PaymentDummyTlv ) ) )
666
698
. chain ( core:: iter:: once ( BlindedPaymentTlvsRef :: Receive ( & payee_tlvs) ) ) ;
667
699
668
700
let path = pks. zip (
0 commit comments