@@ -65,10 +65,10 @@ use crate::ln::inbound_payment::{ExpandedKey, Nonce};
65
65
use crate :: ln:: msgs:: DecodeError ;
66
66
use crate :: offers:: invoice:: { BlindedPayInfo , InvoiceBuilder } ;
67
67
use crate :: offers:: merkle:: { SignError , SignatureTlvStream , SignatureTlvStreamRef , TlvStream , self } ;
68
- use crate :: offers:: offer:: { Offer , OfferContents , OfferTlvStream , OfferTlvStreamRef } ;
68
+ use crate :: offers:: offer:: { OFFER_TYPES , Offer , OfferContents , OfferTlvStream , OfferTlvStreamRef } ;
69
69
use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
70
- use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
71
- use crate :: offers:: signer:: { MetadataMaterial , SigningPubkey } ;
70
+ use crate :: offers:: payer:: { PAYER_METADATA_TYPE , PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
71
+ use crate :: offers:: signer:: { MetadataMaterial , SigningPubkey , self } ;
72
72
use crate :: onion_message:: BlindedPath ;
73
73
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
74
74
use crate :: util:: string:: PrintableString ;
@@ -430,6 +430,20 @@ impl InvoiceRequestContents {
430
430
self . chain . unwrap_or_else ( || self . offer . implied_chain ( ) )
431
431
}
432
432
433
+ /// Verifies that the payer metadata was produced from the invoice request in the TLV stream.
434
+ pub ( super ) fn verify ( & self , tlv_stream : TlvStream < ' _ > , key : & ExpandedKey ) -> bool {
435
+ let offer_records = tlv_stream. clone ( ) . range ( OFFER_TYPES ) ;
436
+ let invreq_records = tlv_stream. range ( INVOICE_REQUEST_TYPES ) . filter ( |record| {
437
+ match record. r#type {
438
+ PAYER_METADATA_TYPE => false , // Should be outside range
439
+ INVOICE_REQUEST_PAYER_ID_TYPE => false ,
440
+ _ => true ,
441
+ }
442
+ } ) ;
443
+ let tlv_stream = offer_records. chain ( invreq_records) ;
444
+ signer:: verify_metadata ( & self . payer . 0 , key, tlv_stream)
445
+ }
446
+
433
447
pub ( super ) fn as_tlv_stream ( & self ) -> PartialInvoiceRequestTlvStreamRef {
434
448
let payer = PayerTlvStreamRef {
435
449
metadata : Some ( & self . payer . 0 ) ,
@@ -467,12 +481,20 @@ impl Writeable for InvoiceRequestContents {
467
481
}
468
482
}
469
483
470
- tlv_stream ! ( InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef , 80 ..160 , {
484
+ /// Valid type range for invoice_request TLV records.
485
+ const INVOICE_REQUEST_TYPES : core:: ops:: Range < u64 > = 80 ..160 ;
486
+
487
+ /// TLV record type for [`InvoiceRequest::payer_id`] and [`Refund::payer_id`].
488
+ ///
489
+ /// [`Refund::payer_id`]: crate::offers::refund::Refund::payer_id
490
+ const INVOICE_REQUEST_PAYER_ID_TYPE : u64 = 88 ;
491
+
492
+ tlv_stream ! ( InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef , INVOICE_REQUEST_TYPES , {
471
493
( 80 , chain: ChainHash ) ,
472
494
( 82 , amount: ( u64 , HighZeroBytesDroppedBigSize ) ) ,
473
495
( 84 , features: ( InvoiceRequestFeatures , WithoutLength ) ) ,
474
496
( 86 , quantity: ( u64 , HighZeroBytesDroppedBigSize ) ) ,
475
- ( 88 , payer_id: PublicKey ) ,
497
+ ( INVOICE_REQUEST_PAYER_ID_TYPE , payer_id: PublicKey ) ,
476
498
( 89 , payer_note: ( String , WithoutLength ) ) ,
477
499
} ) ;
478
500
0 commit comments