1212use bitcoin:: hashes:: hmac:: Hmac ;
1313use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
1414use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
15+ use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
1516
1617use crate :: blinded_path:: { BlindedHop , BlindedPath , IntroductionNode , NodeIdLookUp } ;
1718use crate :: blinded_path:: utils;
@@ -170,15 +171,8 @@ impl BlindedPaymentPath {
170171 NL :: Target : NodeIdLookUp ,
171172 T : secp256k1:: Signing + secp256k1:: Verification ,
172173 {
173- let control_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & self . inner_path . blinding_point , None ) ?;
174- let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
175- let encrypted_control_tlvs = & self . inner_path . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
176- let mut s = Cursor :: new ( encrypted_control_tlvs) ;
177- let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
178- match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
179- Ok ( ChaChaPolyReadAdapter {
180- readable : BlindedPaymentTlvs :: Forward ( ForwardTlvs { short_channel_id, .. } )
181- } ) => {
174+ match self . decrypt_blinded_payload :: < NS > ( 0 , node_signer) {
175+ Ok ( ( BlindedPaymentTlvs :: Forward ( ForwardTlvs { short_channel_id, .. } ) , control_tlvs_ss) ) => {
182176 let next_node_id = match node_id_lookup. next_node_id ( short_channel_id) {
183177 Some ( node_id) => node_id,
184178 None => return Err ( ( ) ) ,
@@ -195,6 +189,20 @@ impl BlindedPaymentPath {
195189 }
196190 }
197191
192+ pub ( crate ) fn decrypt_blinded_payload < NS : Deref > (
193+ & self , hop_idx : usize , node_signer : & NS
194+ ) -> Result < ( BlindedPaymentTlvs , SharedSecret ) , ( ) > where NS :: Target : NodeSigner {
195+ let control_tlvs_ss = node_signer. ecdh ( Recipient :: Node , & self . inner_path . blinding_point , None ) ?;
196+ let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
197+ let encrypted_control_tlvs = & self . inner_path . blinded_hops . get ( hop_idx) . ok_or ( ( ) ) ?. encrypted_payload ;
198+ let mut s = Cursor :: new ( encrypted_control_tlvs) ;
199+ let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
200+ match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
201+ Ok ( ChaChaPolyReadAdapter { readable, .. } ) => Ok ( ( readable, control_tlvs_ss) ) ,
202+ _ => Err ( ( ) )
203+ }
204+ }
205+
198206 pub ( crate ) fn inner_blinded_path ( & self ) -> & BlindedPath {
199207 & self . inner_path
200208 }
0 commit comments