File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,19 @@ pub enum OffersContext {
347
347
///
348
348
/// [`Bolt12Invoice::payment_hash`]: crate::offers::invoice::Bolt12Invoice::payment_hash
349
349
payment_hash : PaymentHash ,
350
+
351
+ /// A nonce used for authenticating that a received [`InvoiceError`] is for a valid
352
+ /// sent [`Bolt12Invoice`].
353
+ ///
354
+ /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
355
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
356
+ nonce : Nonce ,
357
+
358
+ /// Authentication code for the [`PaymentHash`], which should be checked when the context is
359
+ /// used to log the received [`InvoiceError`].
360
+ ///
361
+ /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
362
+ hmac : Hmac < Sha256 > ,
350
363
} ,
351
364
}
352
365
@@ -366,6 +379,8 @@ impl_writeable_tlv_based_enum!(OffersContext,
366
379
} ,
367
380
( 2 , InboundPayment ) => {
368
381
( 0 , payment_hash, required) ,
382
+ ( 1 , nonce, required) ,
383
+ ( 2 , hmac, required)
369
384
} ,
370
385
) ;
371
386
Original file line number Diff line number Diff line change @@ -9226,8 +9226,10 @@ where
9226
9226
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9227
9227
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9228
9228
9229
+ let nonce = Nonce::from_entropy_source(entropy);
9230
+ let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9229
9231
let context = OffersContext::InboundPayment {
9230
- payment_hash: invoice.payment_hash(),
9232
+ payment_hash: invoice.payment_hash(), nonce, hmac
9231
9233
};
9232
9234
let reply_paths = self.create_blinded_paths(context)
9233
9235
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
@@ -10987,7 +10989,12 @@ where
10987
10989
},
10988
10990
OffersMessage::InvoiceError(invoice_error) => {
10989
10991
let payment_hash = match context {
10990
- Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash),
10992
+ Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => {
10993
+ match payment_hash.verify(hmac, nonce, expanded_key) {
10994
+ Ok(_) => Some(payment_hash),
10995
+ Err(_) => None,
10996
+ }
10997
+ },
10991
10998
_ => None,
10992
10999
};
10993
11000
You can’t perform that action at this time.
0 commit comments