99
1010//! Creating blinded paths and related utilities live here.
1111
12+ pub ( crate ) mod message;
1213pub ( crate ) mod utils;
1314
1415use bitcoin:: hashes:: { Hash , HashEngine } ;
@@ -75,7 +76,7 @@ impl BlindedPath {
7576 Ok ( BlindedPath {
7677 introduction_node_id,
7778 blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
78- blinded_hops : blinded_message_hops ( secp_ctx, node_pks, & blinding_secret) . map_err ( |_| ( ) ) ?,
79+ blinded_hops : message :: blinded_hops ( secp_ctx, node_pks, & blinding_secret) . map_err ( |_| ( ) ) ?,
7980 } )
8081 }
8182
@@ -91,7 +92,7 @@ impl BlindedPath {
9192 let mut s = Cursor :: new ( & encrypted_control_tlvs) ;
9293 let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
9394 match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
94- Ok ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Forward ( ForwardTlvs {
95+ Ok ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Forward ( message :: ForwardTlvs {
9596 mut next_node_id, next_blinding_override,
9697 } ) } ) => {
9798 let mut new_blinding_point = match next_blinding_override {
@@ -116,40 +117,6 @@ impl BlindedPath {
116117 }
117118}
118119
119- /// Construct blinded onion message hops for the given `unblinded_path`.
120- fn blinded_message_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
121- secp_ctx : & Secp256k1 < T > , unblinded_path : & [ PublicKey ] , session_priv : & SecretKey
122- ) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
123- let mut blinded_hops = Vec :: with_capacity ( unblinded_path. len ( ) ) ;
124-
125- let mut prev_ss_and_blinded_node_id = None ;
126- utils:: construct_keys_callback ( secp_ctx, unblinded_path, None , session_priv, |blinded_node_id, _, _, encrypted_payload_ss, unblinded_pk, _| {
127- if let Some ( ( prev_ss, prev_blinded_node_id) ) = prev_ss_and_blinded_node_id {
128- if let Some ( pk) = unblinded_pk {
129- let payload = ForwardTlvs {
130- next_node_id : pk,
131- next_blinding_override : None ,
132- } ;
133- blinded_hops. push ( BlindedHop {
134- blinded_node_id : prev_blinded_node_id,
135- encrypted_payload : utils:: encrypt_payload ( payload, prev_ss) ,
136- } ) ;
137- } else { debug_assert ! ( false ) ; }
138- }
139- prev_ss_and_blinded_node_id = Some ( ( encrypted_payload_ss, blinded_node_id) ) ;
140- } ) ?;
141-
142- if let Some ( ( final_ss, final_blinded_node_id) ) = prev_ss_and_blinded_node_id {
143- let final_payload = ReceiveTlvs { path_id : None } ;
144- blinded_hops. push ( BlindedHop {
145- blinded_node_id : final_blinded_node_id,
146- encrypted_payload : utils:: encrypt_payload ( final_payload, final_ss) ,
147- } ) ;
148- } else { debug_assert ! ( false ) }
149-
150- Ok ( blinded_hops)
151- }
152-
153120impl Writeable for BlindedPath {
154121 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
155122 self . introduction_node_id . write ( w) ?;
@@ -185,41 +152,3 @@ impl_writeable!(BlindedHop, {
185152 encrypted_payload
186153} ) ;
187154
188- /// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
189- /// route, they are encoded into [`BlindedHop::encrypted_payload`].
190- pub ( crate ) struct ForwardTlvs {
191- /// The node id of the next hop in the onion message's path.
192- pub ( super ) next_node_id : PublicKey ,
193- /// Senders to a blinded path use this value to concatenate the route they find to the
194- /// introduction node with the blinded path.
195- pub ( super ) next_blinding_override : Option < PublicKey > ,
196- }
197-
198- /// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
199- pub ( crate ) struct ReceiveTlvs {
200- /// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is
201- /// sending to. This is useful for receivers to check that said blinded path is being used in
202- /// the right context.
203- pub ( super ) path_id : Option < [ u8 ; 32 ] > ,
204- }
205-
206- impl Writeable for ForwardTlvs {
207- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
208- // TODO: write padding
209- encode_tlv_stream ! ( writer, {
210- ( 4 , self . next_node_id, required) ,
211- ( 8 , self . next_blinding_override, option)
212- } ) ;
213- Ok ( ( ) )
214- }
215- }
216-
217- impl Writeable for ReceiveTlvs {
218- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
219- // TODO: write padding
220- encode_tlv_stream ! ( writer, {
221- ( 6 , self . path_id, option) ,
222- } ) ;
223- Ok ( ( ) )
224- }
225- }
0 commit comments