@@ -86,6 +86,7 @@ use crate::offers::merkle::{TaggedHash, TlvRecord, TlvStream};
86
86
use crate :: offers:: nonce:: Nonce ;
87
87
use crate :: offers:: parse:: { Bech32Encode , Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
88
88
use crate :: offers:: signer:: { self , Metadata , MetadataMaterial } ;
89
+ use crate :: onion_message:: dns_resolution:: HumanReadableName ;
89
90
use crate :: types:: features:: OfferFeatures ;
90
91
use crate :: types:: string:: PrintableString ;
91
92
use crate :: util:: ser:: {
@@ -577,6 +578,20 @@ impl<'a> From<OfferWithDerivedMetadataBuilder<'a>>
577
578
}
578
579
}
579
580
581
+ /// An [`Offer`] which was fetched from a human readable name, ie through BIP 353.
582
+ pub struct OfferFromHrn {
583
+ /// The offer itself.
584
+ ///
585
+ /// When you resolve this into an [`InvoiceRequestBuilder`] you *must* call
586
+ /// [`InvoiceRequestBuilder::sourced_from_human_readable_name`].
587
+ ///
588
+ /// If you call [`Self::request_invoice`] rather than [`Offer::request_invoice`] this will be
589
+ /// handled for you.
590
+ pub offer : Offer ,
591
+ /// The human readable name which was resolved to fetch the [`Self::offer`].
592
+ pub hrn : HumanReadableName ,
593
+ }
594
+
580
595
/// An `Offer` is a potentially long-lived proposal for payment of a good or service.
581
596
///
582
597
/// An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
@@ -750,7 +765,7 @@ impl Offer {
750
765
}
751
766
}
752
767
753
- macro_rules! request_invoice_derived_signing_pubkey { ( $self: ident, $builder: ty) => {
768
+ macro_rules! request_invoice_derived_signing_pubkey { ( $self: ident, $offer : expr , $ builder: ty, $hrn : expr ) => {
754
769
/// Creates an [`InvoiceRequestBuilder`] for the offer, which
755
770
/// - derives the [`InvoiceRequest::payer_signing_pubkey`] such that a different key can be used
756
771
/// for each request in order to protect the sender's privacy,
@@ -779,24 +794,57 @@ macro_rules! request_invoice_derived_signing_pubkey { ($self: ident, $builder: t
779
794
secp_ctx: & ' b Secp256k1 <secp256k1:: All >,
780
795
payment_id: PaymentId
781
796
) -> Result <$builder, Bolt12SemanticError > {
782
- if $self . offer_features( ) . requires_unknown_bits( ) {
797
+ if $offer . offer_features( ) . requires_unknown_bits( ) {
783
798
return Err ( Bolt12SemanticError :: UnknownRequiredFeatures ) ;
784
799
}
785
800
786
- Ok ( <$builder>:: deriving_signing_pubkey( $self, expanded_key, nonce, secp_ctx, payment_id) )
801
+ let mut builder = <$builder>:: deriving_signing_pubkey( & $offer, expanded_key, nonce, secp_ctx, payment_id) ;
802
+ if let Some ( hrn) = $hrn {
803
+ #[ cfg( c_bindings) ]
804
+ {
805
+ builder. sourced_from_human_readable_name( hrn) ;
806
+ }
807
+ #[ cfg( not( c_bindings) ) ]
808
+ {
809
+ builder = builder. sourced_from_human_readable_name( hrn) ;
810
+ }
811
+ }
812
+ Ok ( builder)
787
813
}
788
814
} }
789
815
790
816
#[ cfg( not( c_bindings) ) ]
791
817
impl Offer {
792
- request_invoice_derived_signing_pubkey ! ( self , InvoiceRequestBuilder <' a, ' b, T >) ;
818
+ request_invoice_derived_signing_pubkey ! ( self , self , InvoiceRequestBuilder <' a, ' b, T >, None ) ;
819
+ }
820
+
821
+ #[ cfg( not( c_bindings) ) ]
822
+ impl OfferFromHrn {
823
+ request_invoice_derived_signing_pubkey ! (
824
+ self ,
825
+ self . offer,
826
+ InvoiceRequestBuilder <' a, ' b, T >,
827
+ Some ( self . hrn)
828
+ ) ;
793
829
}
794
830
795
831
#[ cfg( c_bindings) ]
796
832
impl Offer {
797
833
request_invoice_derived_signing_pubkey ! (
798
834
self ,
799
- InvoiceRequestWithDerivedPayerSigningPubkeyBuilder <' a, ' b>
835
+ self ,
836
+ InvoiceRequestWithDerivedPayerSigningPubkeyBuilder <' a, ' b>,
837
+ None
838
+ ) ;
839
+ }
840
+
841
+ #[ cfg( c_bindings) ]
842
+ impl OfferFromHrn {
843
+ request_invoice_derived_signing_pubkey ! (
844
+ self ,
845
+ self . offer,
846
+ InvoiceRequestWithDerivedPayerSigningPubkeyBuilder <' a, ' b>,
847
+ Some ( self . hrn)
800
848
) ;
801
849
}
802
850
0 commit comments