@@ -75,6 +75,7 @@ use crate::offers::offer::{Offer, OfferContents, OfferId, OfferTlvStream, OfferT
7575use crate :: offers:: parse:: { Bolt12ParseError , ParsedMessage , Bolt12SemanticError } ;
7676use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
7777use crate :: offers:: signer:: { Metadata , MetadataMaterial } ;
78+ use crate :: onion_message:: dns_resolution:: HumanReadableName ;
7879use crate :: util:: ser:: { CursorReadable , HighZeroBytesDroppedBigSize , Readable , WithoutLength , Writeable , Writer } ;
7980use crate :: util:: string:: { PrintableString , UntrustedString } ;
8081
@@ -241,6 +242,7 @@ macro_rules! invoice_request_builder_methods { (
241242 InvoiceRequestContentsWithoutPayerSigningPubkey {
242243 payer: PayerContents ( metadata) , offer, chain: None , amount_msats: None ,
243244 features: InvoiceRequestFeatures :: empty( ) , quantity: None , payer_note: None ,
245+ source_human_readable_name: None ,
244246 }
245247 }
246248
@@ -299,6 +301,14 @@ macro_rules! invoice_request_builder_methods { (
299301 $return_value
300302 }
301303
304+ /// Sets the [`InvoiceRequest::source_human_readable_name`].
305+ ///
306+ /// Successive calls to this method will override the previous setting.
307+ pub fn sourced_from_human_readable_name( $( $self_mut) * $self: $self_type, hrn: HumanReadableName ) -> $return_type {
308+ $self. invoice_request. source_human_readable_name = Some ( hrn) ;
309+ $return_value
310+ }
311+
302312 fn build_with_checks( $( $self_mut) * $self: $self_type) -> Result <
303313 ( UnsignedInvoiceRequest , Option <Keypair >, Option <& ' b Secp256k1 <$secp_context>>) ,
304314 Bolt12SemanticError
@@ -643,6 +653,7 @@ pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey {
643653 features : InvoiceRequestFeatures ,
644654 quantity : Option < u64 > ,
645655 payer_note : Option < String > ,
656+ source_human_readable_name : Option < HumanReadableName > ,
646657}
647658
648659macro_rules! invoice_request_accessors { ( $self: ident, $contents: expr) => {
@@ -687,6 +698,12 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => {
687698 pub fn payer_note( & $self) -> Option <PrintableString > {
688699 $contents. payer_note( )
689700 }
701+
702+ /// If the [`Offer`] was sourced from a BIP 353 Human Readable Name, this should be set by the
703+ /// builder to indicate the original [`HumanReadableName`] which was resolved.
704+ pub fn source_human_readable_name( & $self) -> & Option <HumanReadableName > {
705+ $contents. source_human_readable_name( )
706+ }
690707} }
691708
692709impl UnsignedInvoiceRequest {
@@ -940,7 +957,7 @@ impl VerifiedInvoiceRequest {
940957 let InvoiceRequestContents {
941958 payer_signing_pubkey,
942959 inner : InvoiceRequestContentsWithoutPayerSigningPubkey {
943- payer : _ , offer : _ , chain : _ , amount_msats : _ , features : _ , quantity, payer_note
960+ quantity, payer_note, ..
944961 } ,
945962 } = & self . inner . contents ;
946963
@@ -983,6 +1000,10 @@ impl InvoiceRequestContents {
9831000 . map ( |payer_note| PrintableString ( payer_note. as_str ( ) ) )
9841001 }
9851002
1003+ pub ( super ) fn source_human_readable_name ( & self ) -> & Option < HumanReadableName > {
1004+ & self . inner . source_human_readable_name
1005+ }
1006+
9861007 pub ( super ) fn as_tlv_stream ( & self ) -> PartialInvoiceRequestTlvStreamRef {
9871008 let ( payer, offer, mut invoice_request) = self . inner . as_tlv_stream ( ) ;
9881009 invoice_request. payer_id = Some ( & self . payer_signing_pubkey ) ;
@@ -1018,6 +1039,7 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
10181039 quantity : self . quantity ,
10191040 payer_id : None ,
10201041 payer_note : self . payer_note . as_ref ( ) ,
1042+ source_human_readable_name : self . source_human_readable_name . as_ref ( ) ,
10211043 paths : None ,
10221044 } ;
10231045
@@ -1070,6 +1092,7 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST
10701092 ( 89 , payer_note: ( String , WithoutLength ) ) ,
10711093 // Only used for Refund since the onion message of an InvoiceRequest has a reply path.
10721094 ( 90 , paths: ( Vec <BlindedMessagePath >, WithoutLength ) ) ,
1095+ ( 91 , source_human_readable_name: HumanReadableName ) ,
10731096} ) ;
10741097
10751098type FullInvoiceRequestTlvStream =
@@ -1154,6 +1177,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
11541177 offer_tlv_stream,
11551178 InvoiceRequestTlvStream {
11561179 chain, amount, features, quantity, payer_id, payer_note, paths,
1180+ source_human_readable_name,
11571181 } ,
11581182 ) = tlv_stream;
11591183
@@ -1188,6 +1212,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
11881212 Ok ( InvoiceRequestContents {
11891213 inner : InvoiceRequestContentsWithoutPayerSigningPubkey {
11901214 payer, offer, chain, amount_msats : amount, features, quantity, payer_note,
1215+ source_human_readable_name,
11911216 } ,
11921217 payer_signing_pubkey,
11931218 } )
@@ -1365,6 +1390,7 @@ mod tests {
13651390 payer_id: Some ( & payer_pubkey( ) ) ,
13661391 payer_note: None ,
13671392 paths: None ,
1393+ source_human_readable_name: None ,
13681394 } ,
13691395 SignatureTlvStreamRef { signature: Some ( & invoice_request. signature( ) ) } ,
13701396 ) ,
0 commit comments