@@ -138,6 +138,50 @@ impl BlindedMessagePath {
138138 & self . 0 . blinded_hops
139139 }
140140
141+ /// Advance the blinded onion message path by one hop, making the second hop into the new
142+ /// introduction node.
143+ ///
144+ /// Will only modify `path` when returning `Ok`.
145+ pub fn advance_path_by_one < NS : Deref , NL : Deref , T > (
146+ & mut self , node_signer : & NS , node_id_lookup : & NL , secp_ctx : & Secp256k1 < T >
147+ ) -> Result < ( ) , ( ) >
148+ where
149+ NS :: Target : NodeSigner ,
150+ NL :: Target : NodeIdLookUp ,
151+ T : secp256k1:: Signing + secp256k1:: Verification ,
152+ {
153+ let control_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & self . 0 . blinding_point , None ) ?;
154+ let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
155+ let encrypted_control_tlvs = & self . 0 . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
156+ let mut s = Cursor :: new ( encrypted_control_tlvs) ;
157+ let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
158+ match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
159+ Ok ( ChaChaPolyReadAdapter {
160+ readable : ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override } )
161+ } ) => {
162+ let next_node_id = match next_hop {
163+ NextMessageHop :: NodeId ( pubkey) => pubkey,
164+ NextMessageHop :: ShortChannelId ( scid) => match node_id_lookup. next_node_id ( scid) {
165+ Some ( pubkey) => pubkey,
166+ None => return Err ( ( ) ) ,
167+ } ,
168+ } ;
169+ let mut new_blinding_point = match next_blinding_override {
170+ Some ( blinding_point) => blinding_point,
171+ None => {
172+ onion_utils:: next_hop_pubkey ( secp_ctx, self . 0 . blinding_point ,
173+ control_tlvs_ss. as_ref ( ) ) . map_err ( |_| ( ) ) ?
174+ }
175+ } ;
176+ mem:: swap ( & mut self . 0 . blinding_point , & mut new_blinding_point) ;
177+ self . 0 . introduction_node = IntroductionNode :: NodeId ( next_node_id) ;
178+ self . 0 . blinded_hops . remove ( 0 ) ;
179+ Ok ( ( ) )
180+ } ,
181+ _ => Err ( ( ) )
182+ }
183+ }
184+
141185 pub ( crate ) fn set_introduction_node_id ( & mut self , node_id : PublicKey ) {
142186 self . 0 . introduction_node = IntroductionNode :: NodeId ( node_id) ;
143187 }
@@ -345,46 +389,3 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
345389 utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
346390}
347391
348- /// Advance the blinded onion message path by one hop, making the second hop into the new
349- /// introduction node.
350- ///
351- /// Will only modify `path` when returning `Ok`.
352- pub fn advance_path_by_one < NS : Deref , NL : Deref , T > (
353- path : & mut BlindedMessagePath , node_signer : & NS , node_id_lookup : & NL , secp_ctx : & Secp256k1 < T >
354- ) -> Result < ( ) , ( ) >
355- where
356- NS :: Target : NodeSigner ,
357- NL :: Target : NodeIdLookUp ,
358- T : secp256k1:: Signing + secp256k1:: Verification ,
359- {
360- let control_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & path. 0 . blinding_point , None ) ?;
361- let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
362- let encrypted_control_tlvs = & path. 0 . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
363- let mut s = Cursor :: new ( encrypted_control_tlvs) ;
364- let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
365- match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
366- Ok ( ChaChaPolyReadAdapter {
367- readable : ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override } )
368- } ) => {
369- let next_node_id = match next_hop {
370- NextMessageHop :: NodeId ( pubkey) => pubkey,
371- NextMessageHop :: ShortChannelId ( scid) => match node_id_lookup. next_node_id ( scid) {
372- Some ( pubkey) => pubkey,
373- None => return Err ( ( ) ) ,
374- } ,
375- } ;
376- let mut new_blinding_point = match next_blinding_override {
377- Some ( blinding_point) => blinding_point,
378- None => {
379- onion_utils:: next_hop_pubkey ( secp_ctx, path. 0 . blinding_point ,
380- control_tlvs_ss. as_ref ( ) ) . map_err ( |_| ( ) ) ?
381- }
382- } ;
383- mem:: swap ( & mut path. 0 . blinding_point , & mut new_blinding_point) ;
384- path. 0 . introduction_node = IntroductionNode :: NodeId ( next_node_id) ;
385- path. 0 . blinded_hops . remove ( 0 ) ;
386- Ok ( ( ) )
387- } ,
388- _ => Err ( ( ) )
389- }
390- }
0 commit comments