Skip to content

Commit 6679c4f

Browse files
committed
Add a OfferFromHrn type to wrap Offers which came from HRNs
In a coming commit we'll provide users a different `ChannelManager` method for sending to `Offer`s which were fetched by resolving an HRN. Here, we first ad a wrapper type which can be used by HRN resolution methods to nudge users towards calling the correct payment method on `ChannelManager`.
1 parent 882a0cb commit 6679c4f

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

lightning/src/offers/offer.rs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ use crate::offers::merkle::{TaggedHash, TlvRecord, TlvStream};
8686
use crate::offers::nonce::Nonce;
8787
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
8888
use crate::offers::signer::{self, Metadata, MetadataMaterial};
89+
use crate::onion_message::dns_resolution::HumanReadableName;
8990
use crate::types::features::OfferFeatures;
9091
use crate::types::string::PrintableString;
9192
use crate::util::ser::{
@@ -577,6 +578,20 @@ impl<'a> From<OfferWithDerivedMetadataBuilder<'a>>
577578
}
578579
}
579580

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+
580595
/// An `Offer` is a potentially long-lived proposal for payment of a good or service.
581596
///
582597
/// An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
@@ -750,7 +765,7 @@ impl Offer {
750765
}
751766
}
752767

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) => {
754769
/// Creates an [`InvoiceRequestBuilder`] for the offer, which
755770
/// - derives the [`InvoiceRequest::payer_signing_pubkey`] such that a different key can be used
756771
/// 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
779794
secp_ctx: &'b Secp256k1<secp256k1::All>,
780795
payment_id: PaymentId
781796
) -> Result<$builder, Bolt12SemanticError> {
782-
if $self.offer_features().requires_unknown_bits() {
797+
if $offer.offer_features().requires_unknown_bits() {
783798
return Err(Bolt12SemanticError::UnknownRequiredFeatures);
784799
}
785800

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)
787813
}
788814
} }
789815

790816
#[cfg(not(c_bindings))]
791817
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+
);
793829
}
794830

795831
#[cfg(c_bindings)]
796832
impl Offer {
797833
request_invoice_derived_signing_pubkey!(
798834
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)
800848
);
801849
}
802850

0 commit comments

Comments
 (0)