7
7
// You may not use this file except in accordance with one or both of these
8
8
// licenses.
9
9
10
+ use bitcoin:: hashes:: hmac:: Hmac ;
10
11
use bitcoin:: hashes:: hex:: FromHex ;
12
+ use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
11
13
use bitcoin:: secp256k1:: { PublicKey , Scalar , Secp256k1 , SecretKey , schnorr} ;
12
14
use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
13
15
use bitcoin:: secp256k1:: ecdsa:: { RecoverableSignature , Signature } ;
@@ -17,16 +19,18 @@ use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsP
17
19
use crate :: ln:: types:: ChannelId ;
18
20
use crate :: types:: payment:: { PaymentHash , PaymentSecret } ;
19
21
use crate :: ln:: channelmanager;
20
- use crate :: ln:: channelmanager:: { HTLCFailureMsg , PaymentId , RecipientOnionFields } ;
22
+ use crate :: ln:: channelmanager:: { HTLCFailureMsg , PaymentId , RecipientOnionFields , Verification } ;
21
23
use crate :: types:: features:: { BlindedHopFeatures , ChannelFeatures , NodeFeatures } ;
22
24
use crate :: ln:: functional_test_utils:: * ;
25
+ use crate :: ln:: inbound_payment:: ExpandedKey ;
23
26
use crate :: ln:: msgs;
24
27
use crate :: ln:: msgs:: { ChannelMessageHandler , UnsignedGossipMessage } ;
25
28
use crate :: ln:: onion_payment;
26
29
use crate :: ln:: onion_utils;
27
30
use crate :: ln:: onion_utils:: INVALID_ONION_BLINDING ;
28
31
use crate :: ln:: outbound_payment:: { Retry , IDEMPOTENCY_TIMEOUT_TICKS } ;
29
32
use crate :: offers:: invoice:: UnsignedBolt12Invoice ;
33
+ use crate :: offers:: nonce:: Nonce ;
30
34
use crate :: prelude:: * ;
31
35
use crate :: routing:: router:: { BlindedTail , Path , Payee , PaymentParameters , RouteHop , RouteParameters } ;
32
36
use crate :: sign:: { KeyMaterial , NodeSigner , Recipient } ;
@@ -69,15 +73,19 @@ fn blinded_payment_path(
69
73
. unwrap_or_else ( || channel_upds[ idx - 1 ] . htlc_maximum_msat ) ,
70
74
} ) ;
71
75
}
76
+
77
+ let payment_context = PaymentContext :: unknown ( ) ;
72
78
let payee_tlvs = ReceiveTlvs {
73
79
payment_secret,
74
80
payment_constraints : PaymentConstraints {
75
81
max_cltv_expiry : u32:: max_value ( ) ,
76
82
htlc_minimum_msat :
77
83
intro_node_min_htlc_opt. unwrap_or_else ( || channel_upds. last ( ) . unwrap ( ) . htlc_minimum_msat ) ,
78
84
} ,
79
- payment_context : PaymentContext :: unknown ( ) ,
85
+ authentication : hmac_payment_context ( & payment_context, keys_manager) ,
86
+ payment_context,
80
87
} ;
88
+
81
89
let mut secp_ctx = Secp256k1 :: new ( ) ;
82
90
BlindedPaymentPath :: new (
83
91
& intermediate_nodes[ ..] , * node_ids. last ( ) . unwrap ( ) , payee_tlvs,
@@ -86,6 +94,15 @@ fn blinded_payment_path(
86
94
) . unwrap ( )
87
95
}
88
96
97
+ fn hmac_payment_context (
98
+ payment_context : & PaymentContext , keys_manager : & test_utils:: TestKeysInterface ,
99
+ ) -> ( Hmac < Sha256 > , Nonce ) {
100
+ let nonce = Nonce ( [ 42u8 ; 16 ] ) ;
101
+ let expanded_key = ExpandedKey :: new ( & keys_manager. get_inbound_payment_key_material ( ) ) ;
102
+ let hmac = payment_context. hmac_for_offer_payment ( nonce, & expanded_key) ;
103
+ ( hmac, nonce)
104
+ }
105
+
89
106
pub fn get_blinded_route_parameters (
90
107
amt_msat : u64 , payment_secret : PaymentSecret , intro_node_min_htlc : u64 , intro_node_max_htlc : u64 ,
91
108
node_ids : Vec < PublicKey > , channel_upds : & [ & msgs:: UnsignedChannelUpdate ] ,
@@ -116,13 +133,15 @@ fn do_one_hop_blinded_path(success: bool) {
116
133
117
134
let amt_msat = 5000 ;
118
135
let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 1 ] , Some ( amt_msat) , None ) ;
136
+ let payment_context = PaymentContext :: unknown ( ) ;
119
137
let payee_tlvs = ReceiveTlvs {
120
138
payment_secret,
121
139
payment_constraints : PaymentConstraints {
122
140
max_cltv_expiry : u32:: max_value ( ) ,
123
141
htlc_minimum_msat : chan_upd. htlc_minimum_msat ,
124
142
} ,
125
- payment_context : PaymentContext :: unknown ( ) ,
143
+ authentication : hmac_payment_context ( & payment_context, & chanmon_cfgs[ 1 ] . keys_manager ) ,
144
+ payment_context,
126
145
} ;
127
146
let mut secp_ctx = Secp256k1 :: new ( ) ;
128
147
let blinded_path = BlindedPaymentPath :: new (
@@ -160,13 +179,15 @@ fn mpp_to_one_hop_blinded_path() {
160
179
161
180
let amt_msat = 15_000_000 ;
162
181
let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 3 ] , Some ( amt_msat) , None ) ;
182
+ let payment_context = PaymentContext :: unknown ( ) ;
163
183
let payee_tlvs = ReceiveTlvs {
164
184
payment_secret,
165
185
payment_constraints : PaymentConstraints {
166
186
max_cltv_expiry : u32:: max_value ( ) ,
167
187
htlc_minimum_msat : chan_upd_1_3. htlc_minimum_msat ,
168
188
} ,
169
- payment_context : PaymentContext :: unknown ( ) ,
189
+ authentication : hmac_payment_context ( & payment_context, & chanmon_cfgs[ 3 ] . keys_manager ) ,
190
+ payment_context,
170
191
} ;
171
192
let blinded_path = BlindedPaymentPath :: new (
172
193
& [ ] , nodes[ 3 ] . node . get_our_node_id ( ) , payee_tlvs, u64:: MAX , TEST_FINAL_CLTV as u16 ,
@@ -302,7 +323,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
302
323
let mut route_params = get_blinded_route_parameters ( amt_msat, payment_secret, 1 , 1_0000_0000 ,
303
324
nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) ,
304
325
& [ & chan_upd_1_2, & chan_upd_2_3] , & chanmon_cfgs[ 3 ] . keys_manager ) ;
305
- route_params. payment_params . max_path_length = 18 ;
326
+ route_params. payment_params . max_path_length = 17 ;
306
327
307
328
let route = get_route ( & nodes[ 0 ] , & route_params) . unwrap ( ) ;
308
329
node_cfgs[ 0 ] . router . expect_find_route ( route_params. clone ( ) , Ok ( route. clone ( ) ) ) ;
@@ -1375,13 +1396,15 @@ fn custom_tlvs_to_blinded_path() {
1375
1396
1376
1397
let amt_msat = 5000 ;
1377
1398
let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 1 ] , Some ( amt_msat) , None ) ;
1399
+ let payment_context = PaymentContext :: unknown ( ) ;
1378
1400
let payee_tlvs = ReceiveTlvs {
1379
1401
payment_secret,
1380
1402
payment_constraints : PaymentConstraints {
1381
1403
max_cltv_expiry : u32:: max_value ( ) ,
1382
1404
htlc_minimum_msat : chan_upd. htlc_minimum_msat ,
1383
1405
} ,
1384
- payment_context : PaymentContext :: unknown ( ) ,
1406
+ authentication : hmac_payment_context ( & payment_context, & chanmon_cfgs[ 1 ] . keys_manager ) ,
1407
+ payment_context,
1385
1408
} ;
1386
1409
let mut secp_ctx = Secp256k1 :: new ( ) ;
1387
1410
let blinded_path = BlindedPaymentPath :: new (
0 commit comments