@@ -110,6 +110,7 @@ use core::time::Duration;
110
110
use crate :: io;
111
111
use crate :: blinded_path:: BlindedPath ;
112
112
use crate :: ln:: PaymentHash ;
113
+ use crate :: ln:: channelmanager:: PaymentId ;
113
114
use crate :: ln:: features:: { BlindedHopFeatures , Bolt12InvoiceFeatures , InvoiceRequestFeatures , OfferFeatures } ;
114
115
use crate :: ln:: inbound_payment:: ExpandedKey ;
115
116
use crate :: ln:: msgs:: DecodeError ;
@@ -695,10 +696,11 @@ impl Bolt12Invoice {
695
696
merkle:: message_digest ( SIGNATURE_TAG , & self . bytes ) . as_ref ( ) . clone ( )
696
697
}
697
698
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.
699
701
pub fn verify < T : secp256k1:: Signing > (
700
702
& self , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
701
- ) -> bool {
703
+ ) -> Result < PaymentId , ( ) > {
702
704
self . contents . verify ( TlvStream :: new ( & self . bytes ) , key, secp_ctx)
703
705
}
704
706
@@ -947,7 +949,7 @@ impl InvoiceContents {
947
949
948
950
fn verify < T : secp256k1:: Signing > (
949
951
& self , tlv_stream : TlvStream < ' _ > , key : & ExpandedKey , secp_ctx : & Secp256k1 < T >
950
- ) -> bool {
952
+ ) -> Result < PaymentId , ( ) > {
951
953
let offer_records = tlv_stream. clone ( ) . range ( OFFER_TYPES ) ;
952
954
let invreq_records = tlv_stream. range ( INVOICE_REQUEST_TYPES ) . filter ( |record| {
953
955
match record. r#type {
@@ -967,10 +969,7 @@ impl InvoiceContents {
967
969
} ,
968
970
} ;
969
971
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)
974
973
}
975
974
976
975
fn derives_keys ( & self ) -> bool {
@@ -1642,36 +1641,31 @@ mod tests {
1642
1641
. build ( ) . unwrap ( )
1643
1642
. sign ( payer_sign) . unwrap ( ) ;
1644
1643
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 ( )
1650
1647
. build_and_sign ( & secp_ctx)
1651
1648
{
1652
1649
panic ! ( "error building invoice: {:?}" , e) ;
1653
1650
}
1654
1651
1655
1652
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( ) ) ;
1662
1654
1663
1655
let desc = "foo" . to_string ( ) ;
1664
1656
let offer = OfferBuilder
1665
1657
:: deriving_signing_pubkey ( desc, node_id, & expanded_key, & entropy, & secp_ctx)
1666
1658
. amount_msats ( 1000 )
1659
+ // Omit the path so that node_id is used for the signing pubkey instead of deriving
1667
1660
. build ( ) . unwrap ( ) ;
1668
1661
let invoice_request = offer. request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) ) . unwrap ( )
1669
1662
. build ( ) . unwrap ( )
1670
1663
. sign ( payer_sign) . unwrap ( ) ;
1671
1664
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
+ {
1675
1669
Ok ( _) => panic ! ( "expected error" ) ,
1676
1670
Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: InvalidMetadata ) ,
1677
1671
}
0 commit comments