9
9
10
10
//! Creating blinded paths and related utilities live here.
11
11
12
+ pub ( crate ) mod message;
12
13
pub ( crate ) mod utils;
13
14
14
15
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
@@ -73,7 +74,7 @@ impl BlindedPath {
73
74
Ok ( BlindedPath {
74
75
introduction_node_id,
75
76
blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
76
- blinded_hops : blinded_message_hops ( secp_ctx, node_pks, & blinding_secret) . map_err ( |_| ( ) ) ?,
77
+ blinded_hops : message :: blinded_hops ( secp_ctx, node_pks, & blinding_secret) . map_err ( |_| ( ) ) ?,
77
78
} )
78
79
}
79
80
@@ -89,7 +90,7 @@ impl BlindedPath {
89
90
let mut s = Cursor :: new ( & encrypted_control_tlvs) ;
90
91
let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
91
92
match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
92
- Ok ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Forward ( ForwardTlvs {
93
+ Ok ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Forward ( message :: ForwardTlvs {
93
94
mut next_node_id, next_blinding_override,
94
95
} ) } ) => {
95
96
let mut new_blinding_point = match next_blinding_override {
@@ -108,40 +109,6 @@ impl BlindedPath {
108
109
}
109
110
}
110
111
111
- /// Construct blinded onion message hops for the given `unblinded_path`.
112
- fn blinded_message_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
113
- secp_ctx : & Secp256k1 < T > , unblinded_path : & [ PublicKey ] , session_priv : & SecretKey
114
- ) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
115
- let mut blinded_hops = Vec :: with_capacity ( unblinded_path. len ( ) ) ;
116
-
117
- let mut prev_ss_and_blinded_node_id = None ;
118
- utils:: construct_keys_callback ( secp_ctx, unblinded_path, None , session_priv, |blinded_node_id, _, _, encrypted_payload_ss, unblinded_pk, _| {
119
- if let Some ( ( prev_ss, prev_blinded_node_id) ) = prev_ss_and_blinded_node_id {
120
- if let Some ( pk) = unblinded_pk {
121
- let payload = ForwardTlvs {
122
- next_node_id : pk,
123
- next_blinding_override : None ,
124
- } ;
125
- blinded_hops. push ( BlindedHop {
126
- blinded_node_id : prev_blinded_node_id,
127
- encrypted_payload : utils:: encrypt_payload ( payload, prev_ss) ,
128
- } ) ;
129
- } else { debug_assert ! ( false ) ; }
130
- }
131
- prev_ss_and_blinded_node_id = Some ( ( encrypted_payload_ss, blinded_node_id) ) ;
132
- } ) ?;
133
-
134
- if let Some ( ( final_ss, final_blinded_node_id) ) = prev_ss_and_blinded_node_id {
135
- let final_payload = ReceiveTlvs { path_id : None } ;
136
- blinded_hops. push ( BlindedHop {
137
- blinded_node_id : final_blinded_node_id,
138
- encrypted_payload : utils:: encrypt_payload ( final_payload, final_ss) ,
139
- } ) ;
140
- } else { debug_assert ! ( false ) }
141
-
142
- Ok ( blinded_hops)
143
- }
144
-
145
112
impl Writeable for BlindedPath {
146
113
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
147
114
self . introduction_node_id . write ( w) ?;
@@ -177,41 +144,3 @@ impl_writeable!(BlindedHop, {
177
144
encrypted_payload
178
145
} ) ;
179
146
180
- /// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
181
- /// route, they are encoded into [`BlindedHop::encrypted_payload`].
182
- pub ( crate ) struct ForwardTlvs {
183
- /// The node id of the next hop in the onion message's path.
184
- pub ( super ) next_node_id : PublicKey ,
185
- /// Senders to a blinded path use this value to concatenate the route they find to the
186
- /// introduction node with the blinded path.
187
- pub ( super ) next_blinding_override : Option < PublicKey > ,
188
- }
189
-
190
- /// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
191
- pub ( crate ) struct ReceiveTlvs {
192
- /// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is
193
- /// sending to. This is useful for receivers to check that said blinded path is being used in
194
- /// the right context.
195
- pub ( super ) path_id : Option < [ u8 ; 32 ] > ,
196
- }
197
-
198
- impl Writeable for ForwardTlvs {
199
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
200
- // TODO: write padding
201
- encode_tlv_stream ! ( writer, {
202
- ( 4 , self . next_node_id, required) ,
203
- ( 8 , self . next_blinding_override, option)
204
- } ) ;
205
- Ok ( ( ) )
206
- }
207
- }
208
-
209
- impl Writeable for ReceiveTlvs {
210
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
211
- // TODO: write padding
212
- encode_tlv_stream ! ( writer, {
213
- ( 6 , self . path_id, option) ,
214
- } ) ;
215
- Ok ( ( ) )
216
- }
217
- }
0 commit comments