11
11
12
12
use bitcoin:: hashes:: hmac:: Hmac ;
13
13
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
14
+ use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
14
15
use bitcoin:: secp256k1:: { self , PublicKey , Secp256k1 , SecretKey } ;
15
16
16
17
use crate :: blinded_path:: utils;
@@ -193,17 +194,11 @@ impl BlindedPaymentPath {
193
194
NL :: Target : NodeIdLookUp ,
194
195
T : secp256k1:: Signing + secp256k1:: Verification ,
195
196
{
196
- let control_tlvs_ss =
197
- node_signer. ecdh ( Recipient :: Node , & self . inner_path . blinding_point , None ) ?;
198
- let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
199
- let encrypted_control_tlvs =
200
- & self . inner_path . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
201
- let mut s = Cursor :: new ( encrypted_control_tlvs) ;
202
- let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
203
- match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
204
- Ok ( ChaChaPolyReadAdapter {
205
- readable : BlindedPaymentTlvs :: Forward ( ForwardTlvs { short_channel_id, .. } ) ,
206
- } ) => {
197
+ match self . decrypt_intro_payload :: < NS > ( node_signer) {
198
+ Ok ( (
199
+ BlindedPaymentTlvs :: Forward ( ForwardTlvs { short_channel_id, .. } ) ,
200
+ control_tlvs_ss,
201
+ ) ) => {
207
202
let next_node_id = match node_id_lookup. next_node_id ( short_channel_id) {
208
203
Some ( node_id) => node_id,
209
204
None => return Err ( ( ) ) ,
@@ -223,6 +218,25 @@ impl BlindedPaymentPath {
223
218
}
224
219
}
225
220
221
+ pub ( crate ) fn decrypt_intro_payload < NS : Deref > (
222
+ & self , node_signer : & NS ,
223
+ ) -> Result < ( BlindedPaymentTlvs , SharedSecret ) , ( ) >
224
+ where
225
+ NS :: Target : NodeSigner ,
226
+ {
227
+ let control_tlvs_ss =
228
+ node_signer. ecdh ( Recipient :: Node , & self . inner_path . blinding_point , None ) ?;
229
+ let rho = onion_utils:: gen_rho_from_shared_secret ( & control_tlvs_ss. secret_bytes ( ) ) ;
230
+ let encrypted_control_tlvs =
231
+ & self . inner_path . blinded_hops . get ( 0 ) . ok_or ( ( ) ) ?. encrypted_payload ;
232
+ let mut s = Cursor :: new ( encrypted_control_tlvs) ;
233
+ let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
234
+ match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
235
+ Ok ( ChaChaPolyReadAdapter { readable, .. } ) => Ok ( ( readable, control_tlvs_ss) ) ,
236
+ _ => Err ( ( ) ) ,
237
+ }
238
+ }
239
+
226
240
pub ( crate ) fn inner_blinded_path ( & self ) -> & BlindedPath {
227
241
& self . inner_path
228
242
}
0 commit comments