@@ -114,7 +114,7 @@ use crate::blinded_path::BlindedPath;
114
114
use crate :: ln:: types:: PaymentHash ;
115
115
use crate :: ln:: channelmanager:: PaymentId ;
116
116
use crate :: ln:: features:: { BlindedHopFeatures , Bolt12InvoiceFeatures , InvoiceRequestFeatures , OfferFeatures } ;
117
- use crate :: ln:: inbound_payment:: ExpandedKey ;
117
+ use crate :: ln:: inbound_payment:: { ExpandedKey , IV_LEN } ;
118
118
use crate :: ln:: msgs:: DecodeError ;
119
119
use crate :: offers:: invoice_macros:: { invoice_accessors_common, invoice_builder_methods_common} ;
120
120
use crate :: offers:: invoice_request:: { INVOICE_REQUEST_PAYER_ID_TYPE , INVOICE_REQUEST_TYPES , IV_BYTES as INVOICE_REQUEST_IV_BYTES , InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
@@ -123,7 +123,7 @@ use crate::offers::nonce::Nonce;
123
123
use crate :: offers:: offer:: { Amount , OFFER_TYPES , OfferTlvStream , OfferTlvStreamRef , Quantity } ;
124
124
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
125
125
use crate :: offers:: payer:: { PAYER_METADATA_TYPE , PayerTlvStream , PayerTlvStreamRef } ;
126
- use crate :: offers:: refund:: { IV_BYTES as REFUND_IV_BYTES , Refund , RefundContents } ;
126
+ use crate :: offers:: refund:: { IV_BYTES_WITH_METADATA as REFUND_IV_BYTES_WITH_METADATA , IV_BYTES_WITHOUT_METADATA as REFUND_IV_BYTES_WITHOUT_METADATA , Refund , RefundContents } ;
127
127
use crate :: offers:: signer:: { Metadata , self } ;
128
128
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Iterable , Readable , SeekReadable , WithoutLength , Writeable , Writer } ;
129
129
use crate :: util:: string:: PrintableString ;
@@ -778,11 +778,15 @@ impl Bolt12Invoice {
778
778
pub fn verify_using_metadata < T : secp256k1:: Signing > (
779
779
& self , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
780
780
) -> Result < PaymentId , ( ) > {
781
- let metadata = match & self . contents {
782
- InvoiceContents :: ForOffer { invoice_request, .. } => & invoice_request. inner . payer . 0 ,
783
- InvoiceContents :: ForRefund { refund, .. } => & refund. payer . 0 ,
781
+ let ( metadata, iv_bytes) = match & self . contents {
782
+ InvoiceContents :: ForOffer { invoice_request, .. } => {
783
+ ( & invoice_request. inner . payer . 0 , INVOICE_REQUEST_IV_BYTES )
784
+ } ,
785
+ InvoiceContents :: ForRefund { refund, .. } => {
786
+ ( & refund. payer . 0 , REFUND_IV_BYTES_WITH_METADATA )
787
+ } ,
784
788
} ;
785
- self . contents . verify ( TlvStream :: new ( & self . bytes ) , metadata, key, secp_ctx)
789
+ self . contents . verify ( TlvStream :: new ( & self . bytes ) , metadata, key, iv_bytes , secp_ctx)
786
790
}
787
791
788
792
/// Verifies that the invoice was for a request or refund created using the given key by
@@ -792,7 +796,11 @@ impl Bolt12Invoice {
792
796
& self , payment_id : PaymentId , nonce : Nonce , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
793
797
) -> Result < PaymentId , ( ) > {
794
798
let metadata = Metadata :: payer_data ( payment_id, nonce, key) ;
795
- self . contents . verify ( TlvStream :: new ( & self . bytes ) , & metadata, key, secp_ctx)
799
+ let iv_bytes = match & self . contents {
800
+ InvoiceContents :: ForOffer { .. } => INVOICE_REQUEST_IV_BYTES ,
801
+ InvoiceContents :: ForRefund { .. } => REFUND_IV_BYTES_WITHOUT_METADATA ,
802
+ } ;
803
+ self . contents . verify ( TlvStream :: new ( & self . bytes ) , & metadata, key, iv_bytes, secp_ctx)
796
804
. and_then ( |extracted_payment_id| ( payment_id == extracted_payment_id)
797
805
. then ( || payment_id)
798
806
. ok_or ( ( ) )
@@ -1028,7 +1036,7 @@ impl InvoiceContents {
1028
1036
1029
1037
fn verify < T : secp256k1:: Signing > (
1030
1038
& self , tlv_stream : TlvStream < ' _ > , metadata : & Metadata , key : & ExpandedKey ,
1031
- secp_ctx : & Secp256k1 < T >
1039
+ iv_bytes : & [ u8 ; IV_LEN ] , secp_ctx : & Secp256k1 < T >
1032
1040
) -> Result < PaymentId , ( ) > {
1033
1041
let offer_records = tlv_stream. clone ( ) . range ( OFFER_TYPES ) ;
1034
1042
let invreq_records = tlv_stream. range ( INVOICE_REQUEST_TYPES ) . filter ( |record| {
@@ -1041,11 +1049,6 @@ impl InvoiceContents {
1041
1049
let tlv_stream = offer_records. chain ( invreq_records) ;
1042
1050
1043
1051
let payer_id = self . payer_id ( ) ;
1044
- let iv_bytes = match self {
1045
- InvoiceContents :: ForOffer { .. } => INVOICE_REQUEST_IV_BYTES ,
1046
- InvoiceContents :: ForRefund { .. } => REFUND_IV_BYTES ,
1047
- } ;
1048
-
1049
1052
signer:: verify_payer_metadata (
1050
1053
metadata. as_ref ( ) , key, iv_bytes, payer_id, tlv_stream, secp_ctx,
1051
1054
)
0 commit comments