@@ -71,6 +71,7 @@ use crate::io;
71
71
use crate :: ln:: channelmanager:: PaymentId ;
72
72
use crate :: ln:: inbound_payment:: { ExpandedKey , IV_LEN } ;
73
73
use crate :: ln:: msgs:: DecodeError ;
74
+ use crate :: offers:: invoice:: { DerivedSigningPubkey , ExplicitSigningPubkey , SigningPubkeyStrategy } ;
74
75
use crate :: offers:: merkle:: {
75
76
self , SignError , SignFn , SignatureTlvStream , SignatureTlvStreamRef , TaggedHash , TlvStream ,
76
77
} ;
@@ -96,7 +97,7 @@ use bitcoin::secp256k1::schnorr::Signature;
96
97
use bitcoin:: secp256k1:: { self , Keypair , PublicKey , Secp256k1 } ;
97
98
98
99
#[ cfg( not( c_bindings) ) ]
99
- use crate :: offers:: invoice:: { DerivedSigningPubkey , ExplicitSigningPubkey , InvoiceBuilder } ;
100
+ use crate :: offers:: invoice:: InvoiceBuilder ;
100
101
#[ cfg( c_bindings) ]
101
102
use crate :: offers:: invoice:: {
102
103
InvoiceWithDerivedSigningPubkeyBuilder , InvoiceWithExplicitSigningPubkeyBuilder ,
@@ -615,6 +616,50 @@ pub struct VerifiedInvoiceRequestLegacy {
615
616
pub keys : Option < Keypair > ,
616
617
}
617
618
619
+ /// An [`InvoiceRequest`] that has been verified by [`InvoiceRequest::verify_using_metadata`] or
620
+ /// [`InvoiceRequest::verify_using_recipient_data`] and exposes different ways to respond depending
621
+ /// on whether the signing keys were derived.
622
+ #[ derive( Clone , Debug ) ]
623
+ pub struct VerifiedInvoiceRequest < S : SigningPubkeyStrategy > {
624
+ /// The identifier of the [`Offer`] for which the [`InvoiceRequest`] was made.
625
+ pub offer_id : OfferId ,
626
+
627
+ /// The verified request.
628
+ pub ( crate ) inner : InvoiceRequest ,
629
+
630
+ /// Keys for signing a [`Bolt12Invoice`] for the request.
631
+ ///
632
+ /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
633
+ pub keys : S ,
634
+ }
635
+
636
+ /// An enum representing a verified invoice request, which can either have derived signing keys or
637
+ /// require explicit signing keys.
638
+ pub enum VerifiedInvoiceRequestEnum {
639
+ /// An invoice request with signing keys that can be derived from the metadata.
640
+ WithKeys ( VerifiedInvoiceRequest < DerivedSigningPubkey > ) ,
641
+ /// An invoice request without derived signing keys, which must be explicitly provided.
642
+ WithoutKeys ( VerifiedInvoiceRequest < ExplicitSigningPubkey > ) ,
643
+ }
644
+
645
+ impl VerifiedInvoiceRequestEnum {
646
+ /// Returns a reference to the underlying `InvoiceRequest`.
647
+ pub fn inner ( & self ) -> & InvoiceRequest {
648
+ match self {
649
+ VerifiedInvoiceRequestEnum :: WithKeys ( req) => & req. inner ,
650
+ VerifiedInvoiceRequestEnum :: WithoutKeys ( req) => & req. inner ,
651
+ }
652
+ }
653
+
654
+ /// Returns the `OfferId` of the offer this invoice request is for.
655
+ pub fn offer_id ( & self ) -> OfferId {
656
+ match self {
657
+ VerifiedInvoiceRequestEnum :: WithKeys ( req) => req. offer_id ,
658
+ VerifiedInvoiceRequestEnum :: WithoutKeys ( req) => req. offer_id ,
659
+ }
660
+ }
661
+ }
662
+
618
663
/// The contents of an [`InvoiceRequest`], which may be shared with an [`Bolt12Invoice`].
619
664
///
620
665
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
@@ -1022,6 +1067,24 @@ impl VerifiedInvoiceRequestLegacy {
1022
1067
) ;
1023
1068
}
1024
1069
1070
+ impl VerifiedInvoiceRequest < DerivedSigningPubkey > {
1071
+ offer_accessors ! ( self , self . inner. contents. inner. offer) ;
1072
+ invoice_request_accessors ! ( self , self . inner. contents) ;
1073
+ fields_accessor ! ( self , self . inner. contents) ;
1074
+ }
1075
+
1076
+ impl VerifiedInvoiceRequest < ExplicitSigningPubkey > {
1077
+ offer_accessors ! ( self , self . inner. contents. inner. offer) ;
1078
+ invoice_request_accessors ! ( self , self . inner. contents) ;
1079
+ fields_accessor ! ( self , self . inner. contents) ;
1080
+ }
1081
+
1082
+ impl VerifiedInvoiceRequestEnum {
1083
+ offer_accessors ! ( self , self . inner( ) . contents. inner. offer) ;
1084
+ invoice_request_accessors ! ( self , self . inner( ) . contents) ;
1085
+ fields_accessor ! ( self , self . inner( ) . contents) ;
1086
+ }
1087
+
1025
1088
/// `String::truncate(new_len)` panics if you split inside a UTF-8 code point,
1026
1089
/// which would leave the `String` containing invalid UTF-8. This function will
1027
1090
/// instead truncate the string to the next smaller code point boundary so the
0 commit comments