@@ -110,6 +110,7 @@ use core::time::Duration;
110110use crate :: io;
111111use crate :: blinded_path:: BlindedPath ;
112112use crate :: ln:: PaymentHash ;
113+ use crate :: ln:: channelmanager:: PaymentId ;
113114use crate :: ln:: features:: { BlindedHopFeatures , Bolt12InvoiceFeatures , InvoiceRequestFeatures , OfferFeatures } ;
114115use crate :: ln:: inbound_payment:: ExpandedKey ;
115116use crate :: ln:: msgs:: DecodeError ;
@@ -695,10 +696,11 @@ impl Bolt12Invoice {
695696 merkle:: message_digest ( SIGNATURE_TAG , & self . bytes ) . as_ref ( ) . clone ( )
696697 }
697698
698- /// Verifies that the invoice was for a request or refund created using the given key.
699+ /// Verifies that the invoice was for a request or refund created using the given key. Returns
700+ /// the associated [`PaymentId`] to use when sending the payment.
699701 pub fn verify < T : secp256k1:: Signing > (
700702 & self , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
701- ) -> bool {
703+ ) -> Result < PaymentId , ( ) > {
702704 self . contents . verify ( TlvStream :: new ( & self . bytes ) , key, secp_ctx)
703705 }
704706
@@ -947,7 +949,7 @@ impl InvoiceContents {
947949
948950 fn verify < T : secp256k1:: Signing > (
949951 & self , tlv_stream : TlvStream < ' _ > , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
950- ) -> bool {
952+ ) -> Result < PaymentId , ( ) > {
951953 let offer_records = tlv_stream. clone ( ) . range ( OFFER_TYPES ) ;
952954 let invreq_records = tlv_stream. range ( INVOICE_REQUEST_TYPES ) . filter ( |record| {
953955 match record. r#type {
@@ -967,10 +969,7 @@ impl InvoiceContents {
967969 } ,
968970 } ;
969971
970- match signer:: verify_metadata ( metadata, key, iv_bytes, payer_id, tlv_stream, secp_ctx) {
971- Ok ( _) => true ,
972- Err ( ( ) ) => false ,
973- }
972+ signer:: verify_payer_metadata ( metadata, key, iv_bytes, payer_id, tlv_stream, secp_ctx)
974973 }
975974
976975 fn derives_keys ( & self ) -> bool {
@@ -1642,36 +1641,31 @@ mod tests {
16421641 . build ( ) . unwrap ( )
16431642 . sign ( payer_sign) . unwrap ( ) ;
16441643
1645- if let Err ( e) = invoice_request
1646- . verify_and_respond_using_derived_keys_no_std (
1647- payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & secp_ctx
1648- )
1649- . unwrap ( )
1644+ if let Err ( e) = invoice_request. clone ( )
1645+ . verify ( & expanded_key, & secp_ctx) . unwrap ( )
1646+ . respond_using_derived_keys_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) ) . unwrap ( )
16501647 . build_and_sign ( & secp_ctx)
16511648 {
16521649 panic ! ( "error building invoice: {:?}" , e) ;
16531650 }
16541651
16551652 let expanded_key = ExpandedKey :: new ( & KeyMaterial ( [ 41 ; 32 ] ) ) ;
1656- match invoice_request. verify_and_respond_using_derived_keys_no_std (
1657- payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & secp_ctx
1658- ) {
1659- Ok ( _) => panic ! ( "expected error" ) ,
1660- Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: InvalidMetadata ) ,
1661- }
1653+ assert ! ( invoice_request. verify( & expanded_key, & secp_ctx) . is_err( ) ) ;
16621654
16631655 let desc = "foo" . to_string ( ) ;
16641656 let offer = OfferBuilder
16651657 :: deriving_signing_pubkey ( desc, node_id, & expanded_key, & entropy, & secp_ctx)
16661658 . amount_msats ( 1000 )
1659+ // Omit the path so that node_id is used for the signing pubkey instead of deriving
16671660 . build ( ) . unwrap ( ) ;
16681661 let invoice_request = offer. request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) ) . unwrap ( )
16691662 . build ( ) . unwrap ( )
16701663 . sign ( payer_sign) . unwrap ( ) ;
16711664
1672- match invoice_request. verify_and_respond_using_derived_keys_no_std (
1673- payment_paths ( ) , payment_hash ( ) , now ( ) , & expanded_key, & secp_ctx
1674- ) {
1665+ match invoice_request
1666+ . verify ( & expanded_key, & secp_ctx) . unwrap ( )
1667+ . respond_using_derived_keys_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) )
1668+ {
16751669 Ok ( _) => panic ! ( "expected error" ) ,
16761670 Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: InvalidMetadata ) ,
16771671 }
0 commit comments