Skip to content

Commit

Permalink
Add issuer_id to Bolt12Invoice and StaticInvoice
Browse files Browse the repository at this point in the history
Useful for determining if the signing_pubkey is the issuer_id or from a
blinded path.
  • Loading branch information
jkczyz committed Aug 1, 2024
1 parent bfef96c commit 217036d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,16 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
$contents.supported_quantity()
}

/// A possibly transient id of the recipient.
///
/// From [`Offer::issuer_id`]; `None` if the invoice was created in response to a [`Refund`].
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`Offer::issuer_id`]: crate::offers::offer::Offer::issuer_id
pub fn issuer_id(&$self) -> Option<PublicKey> {
$contents.issuer_id()
}

/// An unpredictable series of bytes from the payer.
///
/// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
Expand Down Expand Up @@ -936,6 +946,15 @@ impl InvoiceContents {
}
}

fn issuer_id(&self) -> Option<PublicKey> {
match self {
InvoiceContents::ForOffer { invoice_request, .. } => {
invoice_request.inner.offer.issuer_id()
},
InvoiceContents::ForRefund { .. } => None,
}
}

fn payer_metadata(&self) -> &[u8] {
match self {
InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.metadata(),
Expand Down
12 changes: 12 additions & 0 deletions lightning/src/offers/invoice_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice
}

/// The public key corresponding to the key used to sign the invoice.
///
/// If the invoices was created in response to an [`Offer`], then will be:
/// - [`Offer::issuer_id`] if `Some`, otherwise
/// - the final blinded node id from a [`BlindedPath`] in [`Offer::paths`] if `None`.
///
/// If the invoice was created in response to a [`Refund`], then may be transient id chosen by
/// the recipient.
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`Offer::issuer_id`]: crate::offers::offer::Offer::issuer_id
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
/// [`Refund`]: crate::offers::refund::Refund
pub fn signing_pubkey(&$self) -> PublicKey {
$contents.signing_pubkey()
}
Expand Down
11 changes: 11 additions & 0 deletions lightning/src/offers/static_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
pub fn supported_quantity(&$self) -> Quantity {
$contents.supported_quantity()
}

/// A possibly transient id of the recipient, from [`Offer::issuer_id`].
///
/// [`Offer::issuer_id`]: crate::offers::offer::Offer::issuer_id
pub fn issuer_id(&$self) -> Option<PublicKey> {
$contents.issuer_id()
}
} }

impl UnsignedStaticInvoice {
Expand Down Expand Up @@ -405,6 +412,10 @@ impl InvoiceContents {
self.offer.supported_quantity()
}

fn issuer_id(&self) -> Option<PublicKey> {
self.offer.issuer_id()
}

fn payment_paths(&self) -> &[(BlindedPayInfo, BlindedPath)] {
&self.payment_paths[..]
}
Expand Down

0 comments on commit 217036d

Please sign in to comment.