@@ -108,12 +108,13 @@ use crate::ln::PaymentHash;
108108use crate :: ln:: features:: { BlindedHopFeatures , Bolt12InvoiceFeatures } ;
109109use crate :: ln:: inbound_payment:: ExpandedKey ;
110110use crate :: ln:: msgs:: DecodeError ;
111- use crate :: offers:: invoice_request:: { InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
111+ use crate :: offers:: invoice_request:: { INVOICE_REQUEST_PAYER_ID_TYPE , INVOICE_REQUEST_TYPES , IV_BYTES as INVOICE_REQUEST_IV_BYTES , InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
112112use crate :: offers:: merkle:: { SignError , SignatureTlvStream , SignatureTlvStreamRef , TlvStream , WithoutSignatures , self } ;
113- use crate :: offers:: offer:: { Amount , OfferTlvStream , OfferTlvStreamRef } ;
113+ use crate :: offers:: offer:: { Amount , OFFER_TYPES , OfferTlvStream , OfferTlvStreamRef } ;
114114use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
115- use crate :: offers:: payer:: { PayerTlvStream , PayerTlvStreamRef } ;
116- use crate :: offers:: refund:: { Refund , RefundContents } ;
115+ use crate :: offers:: payer:: { PAYER_METADATA_TYPE , PayerTlvStream , PayerTlvStreamRef } ;
116+ use crate :: offers:: refund:: { IV_BYTES as REFUND_IV_BYTES , Refund , RefundContents } ;
117+ use crate :: offers:: signer;
117118use crate :: onion_message:: BlindedPath ;
118119use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Iterable , SeekReadable , WithoutLength , Writeable , Writer } ;
119120
@@ -531,13 +532,32 @@ impl InvoiceContents {
531532 fn verify < T : secp256k1:: Signing > (
532533 & self , tlv_stream : TlvStream < ' _ > , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
533534 ) -> bool {
534- match self {
535+ let offer_records = tlv_stream. clone ( ) . range ( OFFER_TYPES ) ;
536+ let invreq_records = tlv_stream. range ( INVOICE_REQUEST_TYPES ) . filter ( |record| {
537+ match record. r#type {
538+ PAYER_METADATA_TYPE => false , // Should be outside range
539+ INVOICE_REQUEST_PAYER_ID_TYPE => !self . derives_keys ( ) ,
540+ _ => true ,
541+ }
542+ } ) ;
543+ let tlv_stream = offer_records. chain ( invreq_records) ;
544+
545+ let ( metadata, payer_id, iv_bytes) = match self {
535546 InvoiceContents :: ForOffer { invoice_request, .. } => {
536- invoice_request. verify ( tlv_stream , key , secp_ctx )
547+ ( invoice_request. metadata ( ) , invoice_request . payer_id ( ) , INVOICE_REQUEST_IV_BYTES )
537548 } ,
538549 InvoiceContents :: ForRefund { refund, .. } => {
539- refund. verify ( tlv_stream , key , secp_ctx )
550+ ( refund. metadata ( ) , refund . payer_id ( ) , REFUND_IV_BYTES )
540551 } ,
552+ } ;
553+
554+ signer:: verify_metadata ( metadata, key, iv_bytes, payer_id, tlv_stream, secp_ctx)
555+ }
556+
557+ fn derives_keys ( & self ) -> bool {
558+ match self {
559+ InvoiceContents :: ForOffer { invoice_request, .. } => invoice_request. derives_keys ( ) ,
560+ InvoiceContents :: ForRefund { refund, .. } => refund. derives_keys ( ) ,
541561 }
542562 }
543563
0 commit comments