12
12
use bitcoin:: hashes:: hmac:: Hmac ;
13
13
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
14
14
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
15
+ use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
15
16
16
17
use crate :: blinded_path:: { BlindedHop , BlindedPath , IntroductionNode , NodeIdLookUp } ;
17
18
use crate :: blinded_path:: utils;
@@ -170,15 +171,8 @@ impl BlindedPaymentPath {
170
171
NL :: Target : NodeIdLookUp ,
171
172
T : secp256k1:: Signing + secp256k1:: Verification ,
172
173
{
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_intro_payload :: < NS > ( node_signer) {
175
+ Ok ( ( BlindedPaymentTlvs :: Forward ( ForwardTlvs { short_channel_id, .. } ) , control_tlvs_ss) ) => {
182
176
let next_node_id = match node_id_lookup. next_node_id ( short_channel_id) {
183
177
Some ( node_id) => node_id,
184
178
None => return Err ( ( ) ) ,
@@ -195,6 +189,20 @@ impl BlindedPaymentPath {
195
189
}
196
190
}
197
191
192
+ pub ( crate ) fn decrypt_intro_payload < NS : Deref > (
193
+ & self , 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 ( 0 ) . 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
+
198
206
pub ( crate ) fn inner_blinded_path ( & self ) -> & BlindedPath {
199
207
& self . inner_path
200
208
}
0 commit comments