@@ -37,26 +37,18 @@ use crate::prelude::*;
37
37
/// A blinded path to be used for sending or receiving a payment, hiding the identity of the
38
38
/// recipient.
39
39
#[ 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 ,
52
44
}
53
45
54
46
impl BlindedPaymentPath {
55
47
/// Create a one-hop blinded path for a payment.
56
48
pub fn one_hop < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
57
49
payee_node_id : PublicKey , payee_tlvs : ReceiveTlvs , min_final_cltv_expiry_delta : u16 ,
58
50
entropy_source : ES , secp_ctx : & Secp256k1 < T >
59
- ) -> Result < ( BlindedPayInfo , Self ) , ( ) > where ES :: Target : EntropySource {
51
+ ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
60
52
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
61
53
// be in relation to a specific channel.
62
54
let htlc_maximum_msat = u64:: max_value ( ) ;
@@ -77,7 +69,7 @@ impl BlindedPaymentPath {
77
69
intermediate_nodes : & [ ForwardNode ] , payee_node_id : PublicKey , payee_tlvs : ReceiveTlvs ,
78
70
htlc_maximum_msat : u64 , min_final_cltv_expiry_delta : u16 , entropy_source : ES ,
79
71
secp_ctx : & Secp256k1 < T >
80
- ) -> Result < ( BlindedPayInfo , Self ) , ( ) > where ES :: Target : EntropySource {
72
+ ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
81
73
let introduction_node = IntroductionNode :: NodeId (
82
74
intermediate_nodes. first ( ) . map_or ( payee_node_id, |n| n. node_id )
83
75
) ;
@@ -87,38 +79,41 @@ impl BlindedPaymentPath {
87
79
let blinded_payinfo = compute_payinfo (
88
80
intermediate_nodes, & payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
89
81
) ?;
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
+ } )
97
92
}
98
93
99
94
/// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e.,
100
95
/// it is found in the network graph).
101
96
pub fn public_introduction_node_id < ' a > (
102
97
& self , network_graph : & ' a ReadOnlyNetworkGraph
103
98
) -> Option < & ' a NodeId > {
104
- self . 0 . public_introduction_node_id ( network_graph)
99
+ self . inner_path . public_introduction_node_id ( network_graph)
105
100
}
106
101
107
102
/// The [`IntroductionNode`] of the blinded path.
108
103
pub fn introduction_node ( & self ) -> & IntroductionNode {
109
- & self . 0 . introduction_node
104
+ & self . inner_path . introduction_node
110
105
}
111
106
112
107
/// Used by the [`IntroductionNode`] to decrypt its [`encrypted_payload`] to forward the payment.
113
108
///
114
109
/// [`encrypted_payload`]: BlindedHop::encrypted_payload
115
110
pub fn blinding_point ( & self ) -> PublicKey {
116
- self . 0 . blinding_point
111
+ self . inner_path . blinding_point
117
112
}
118
113
119
114
/// The [`BlindedHop`]s within the blinded path.
120
115
pub fn blinded_hops ( & self ) -> & [ BlindedHop ] {
121
- & self . 0 . blinded_hops
116
+ & self . inner_path . blinded_hops
122
117
}
123
118
124
119
/// Advance the blinded onion payment path by one hop, making the second hop into the new
@@ -133,9 +128,9 @@ impl BlindedPaymentPath {
133
128
NL :: Target : NodeIdLookUp ,
134
129
T : secp256k1:: Signing + secp256k1:: Verification ,
135
130
{
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 ) ?;
137
132
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 ;
139
134
let mut s = Cursor :: new ( encrypted_control_tlvs) ;
140
135
let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
141
136
match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
@@ -147,31 +142,43 @@ impl BlindedPaymentPath {
147
142
None => return Err ( ( ) ) ,
148
143
} ;
149
144
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 ( )
151
146
) . 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 ) ;
155
150
Ok ( ( ) )
156
151
} ,
157
152
_ => Err ( ( ) )
158
153
}
159
154
}
160
155
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
+
161
164
#[ cfg( any( test, fuzzing) ) ]
162
165
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
164
168
) -> 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
+ }
170
177
}
171
178
172
179
#[ cfg( test) ]
173
180
pub fn clear_blinded_hops ( & mut self ) {
174
- self . 0 . blinded_hops . clear ( )
181
+ self . inner_path . blinded_hops . clear ( )
175
182
}
176
183
}
177
184
0 commit comments