@@ -37,26 +37,18 @@ use crate::prelude::*;
3737/// A blinded path to be used for sending or receiving a payment, hiding the identity of the
3838/// recipient.
3939#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
40- pub struct BlindedPaymentPath ( pub ( super ) BlindedPath ) ;
41-
42- impl Writeable for BlindedPaymentPath {
43- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
44- self . 0 . write ( w)
45- }
46- }
47-
48- impl Readable for BlindedPaymentPath {
49- fn read < R : io:: Read > ( r : & mut R ) -> Result < Self , DecodeError > {
50- Ok ( Self ( BlindedPath :: read ( r) ?) )
51- }
40+ pub struct BlindedPaymentPath {
41+ pub ( super ) inner_path : BlindedPath ,
42+ /// The [`BlindedPayInfo`] used to pay this blinded path.
43+ pub payinfo : BlindedPayInfo ,
5244}
5345
5446impl BlindedPaymentPath {
5547 /// Create a one-hop blinded path for a payment.
5648 pub fn one_hop < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
5749 payee_node_id : PublicKey , payee_tlvs : ReceiveTlvs , min_final_cltv_expiry_delta : u16 ,
5850 entropy_source : ES , secp_ctx : & Secp256k1 < T >
59- ) -> Result < ( BlindedPayInfo , Self ) , ( ) > where ES :: Target : EntropySource {
51+ ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
6052 // This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
6153 // be in relation to a specific channel.
6254 let htlc_maximum_msat = u64:: max_value ( ) ;
@@ -77,7 +69,7 @@ impl BlindedPaymentPath {
7769 intermediate_nodes : & [ ForwardNode ] , payee_node_id : PublicKey , payee_tlvs : ReceiveTlvs ,
7870 htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 , entropy_source : ES ,
7971 secp_ctx : & Secp256k1 < T >
80- ) -> Result < ( BlindedPayInfo , Self ) , ( ) > where ES :: Target : EntropySource {
72+ ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
8173 let introduction_node = IntroductionNode :: NodeId (
8274 intermediate_nodes. first ( ) . map_or ( payee_node_id, |n| n. node_id )
8375 ) ;
@@ -87,38 +79,41 @@ impl BlindedPaymentPath {
8779 let blinded_payinfo = compute_payinfo (
8880 intermediate_nodes, & payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
8981 ) ?;
90- Ok ( ( blinded_payinfo, Self ( BlindedPath {
91- introduction_node,
92- blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
93- blinded_hops : blinded_hops (
94- secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, & blinding_secret
95- ) . map_err ( |_| ( ) ) ?,
96- } ) ) )
82+ Ok ( Self {
83+ inner_path : BlindedPath {
84+ introduction_node,
85+ blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
86+ blinded_hops : blinded_hops (
87+ secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, & blinding_secret
88+ ) . map_err ( |_| ( ) ) ?,
89+ } ,
90+ payinfo : blinded_payinfo
91+ } )
9792 }
9893
9994 /// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e.,
10095 /// it is found in the network graph).
10196 pub fn public_introduction_node_id < ' a > (
10297 & self , network_graph : & ' a ReadOnlyNetworkGraph
10398 ) -> Option < & ' a NodeId > {
104- self . 0 . public_introduction_node_id ( network_graph)
99+ self . inner_path . public_introduction_node_id ( network_graph)
105100 }
106101
107102 /// The [`IntroductionNode`] of the blinded path.
108103 pub fn introduction_node ( & self ) -> & IntroductionNode {
109- & self . 0 . introduction_node
104+ & self . inner_path . introduction_node
110105 }
111106
112107 /// Used by the [`IntroductionNode`] to decrypt its [`encrypted_payload`] to forward the payment.
113108 ///
114109 /// [`encrypted_payload`]: BlindedHop::encrypted_payload
115110 pub fn blinding_point ( & self ) -> PublicKey {
116- self . 0 . blinding_point
111+ self . inner_path . blinding_point
117112 }
118113
119114 /// The [`BlindedHop`]s within the blinded path.
120115 pub fn blinded_hops ( & self ) -> & [ BlindedHop ] {
121- & self . 0 . blinded_hops
116+ & self . inner_path . blinded_hops
122117 }
123118
124119 /// Advance the blinded onion payment path by one hop, making the second hop into the new
@@ -133,9 +128,9 @@ impl BlindedPaymentPath {
133128 NL :: Target : NodeIdLookUp ,
134129 T : secp256k1:: Signing + secp256k1:: Verification ,
135130 {
136- let control_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & self . 0 . blinding_point , None ) ?;
131+ let control_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & self . inner_path . blinding_point , None ) ?;
137132 let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
138- let encrypted_control_tlvs = & self . 0 . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
133+ let encrypted_control_tlvs = & self . inner_path . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
139134 let mut s = Cursor :: new ( encrypted_control_tlvs) ;
140135 let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
141136 match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
@@ -147,31 +142,43 @@ impl BlindedPaymentPath {
147142 None => return Err ( ( ) ) ,
148143 } ;
149144 let mut new_blinding_point = onion_utils:: next_hop_pubkey (
150- secp_ctx, self . 0 . blinding_point , control_tlvs_ss. as_ref ( )
145+ secp_ctx, self . inner_path . blinding_point , control_tlvs_ss. as_ref ( )
151146 ) . map_err ( |_| ( ) ) ?;
152- mem:: swap ( & mut self . 0 . blinding_point , & mut new_blinding_point) ;
153- self . 0 . introduction_node = IntroductionNode :: NodeId ( next_node_id) ;
154- self . 0 . blinded_hops . remove ( 0 ) ;
147+ mem:: swap ( & mut self . inner_path . blinding_point , & mut new_blinding_point) ;
148+ self . inner_path . introduction_node = IntroductionNode :: NodeId ( next_node_id) ;
149+ self . inner_path . blinded_hops . remove ( 0 ) ;
155150 Ok ( ( ) )
156151 } ,
157152 _ => Err ( ( ) )
158153 }
159154 }
160155
156+ pub ( crate ) fn inner_blinded_path ( & self ) -> & BlindedPath {
157+ & self . inner_path
158+ }
159+
160+ pub ( crate ) fn from_parts ( inner_path : BlindedPath , payinfo : BlindedPayInfo ) -> Self {
161+ Self { inner_path, payinfo }
162+ }
163+
161164 #[ cfg( any( test, fuzzing) ) ]
162165 pub fn from_raw (
163- introduction_node_id : PublicKey , blinding_point : PublicKey , blinded_hops : Vec < BlindedHop >
166+ introduction_node_id : PublicKey , blinding_point : PublicKey , blinded_hops : Vec < BlindedHop > ,
167+ payinfo : BlindedPayInfo
164168 ) -> Self {
165- Self ( BlindedPath {
166- introduction_node : IntroductionNode :: NodeId ( introduction_node_id) ,
167- blinding_point,
168- blinded_hops,
169- } )
169+ Self {
170+ inner_path : BlindedPath {
171+ introduction_node : IntroductionNode :: NodeId ( introduction_node_id) ,
172+ blinding_point,
173+ blinded_hops,
174+ } ,
175+ payinfo
176+ }
170177 }
171178
172179 #[ cfg( test) ]
173180 pub fn clear_blinded_hops ( & mut self ) {
174- self . 0 . blinded_hops . clear ( )
181+ self . inner_path . blinded_hops . clear ( )
175182 }
176183}
177184
0 commit comments