@@ -65,10 +65,10 @@ use crate::ln::inbound_payment::{ExpandedKey, Nonce};
6565use crate :: ln:: msgs:: DecodeError ;
6666use crate :: offers:: invoice:: { BlindedPayInfo , InvoiceBuilder } ;
6767use 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 } ;
6969use 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 } ;
7272use crate :: onion_message:: BlindedPath ;
7373use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
7474use crate :: util:: string:: PrintableString ;
@@ -430,6 +430,20 @@ impl InvoiceRequestContents {
430430 self . chain . unwrap_or_else ( || self . offer . implied_chain ( ) )
431431 }
432432
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+
433447 pub ( super ) fn as_tlv_stream ( & self ) -> PartialInvoiceRequestTlvStreamRef {
434448 let payer = PayerTlvStreamRef {
435449 metadata : Some ( & self . payer . 0 ) ,
@@ -467,12 +481,20 @@ impl Writeable for InvoiceRequestContents {
467481 }
468482}
469483
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 , {
471493 ( 80 , chain: ChainHash ) ,
472494 ( 82 , amount: ( u64 , HighZeroBytesDroppedBigSize ) ) ,
473495 ( 84 , features: ( InvoiceRequestFeatures , WithoutLength ) ) ,
474496 ( 86 , quantity: ( u64 , HighZeroBytesDroppedBigSize ) ) ,
475- ( 88 , payer_id: PublicKey ) ,
497+ ( INVOICE_REQUEST_PAYER_ID_TYPE , payer_id: PublicKey ) ,
476498 ( 89 , payer_note: ( String , WithoutLength ) ) ,
477499} ) ;
478500
0 commit comments