Skip to content

Commit 6385ab0

Browse files
committed
Add issuer_signing_pubkey to Bolt12Invoice
Useful for determining if the signing_pubkey is the issuer_signing_pubkey or is from a blinded path.
1 parent 6f7df83 commit 6385ab0

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

lightning/src/offers/invoice.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,16 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
714714
$contents.supported_quantity()
715715
}
716716

717+
/// The public key used by the recipient to sign invoices.
718+
///
719+
/// From [`Offer::issuer_signing_pubkey`] and may be `None`; also `None` if the invoice was
720+
/// created in response to a [`Refund`].
721+
///
722+
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
723+
pub fn issuer_signing_pubkey(&$self) -> Option<PublicKey> {
724+
$contents.issuer_signing_pubkey()
725+
}
726+
717727
/// An unpredictable series of bytes from the payer.
718728
///
719729
/// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
@@ -761,13 +771,37 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
761771
}
762772
} }
763773

774+
775+
macro_rules! invoice_accessors_signing_pubkey {
776+
($self: ident, $contents: expr, $invoice_type: ty) =>
777+
{
778+
/// The public key corresponding to the key used to sign the invoice.
779+
///
780+
/// If the invoices was created in response to an [`Offer`], then this will be:
781+
/// - [`Offer::issuer_signing_pubkey`] if it's `Some`, otherwise
782+
/// - the final blinded node id from a [`BlindedMessagePath`] in [`Offer::paths`] if `None`.
783+
///
784+
/// If the invoice was created in response to a [`Refund`], then this may be a transient id
785+
/// chosen by the recipient.
786+
///
787+
/// [`Offer`]: crate::offers::offer::Offer
788+
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
789+
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
790+
/// [`Refund`]: crate::offers::refund::Refund
791+
pub fn signing_pubkey(&$self) -> PublicKey {
792+
$contents.signing_pubkey()
793+
}
794+
} }
795+
764796
impl UnsignedBolt12Invoice {
765797
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
798+
invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice);
766799
invoice_accessors!(self, self.contents);
767800
}
768801

769802
impl Bolt12Invoice {
770803
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
804+
invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice);
771805
invoice_accessors!(self, self.contents);
772806

773807
/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
@@ -954,6 +988,15 @@ impl InvoiceContents {
954988
}
955989
}
956990

991+
fn issuer_signing_pubkey(&self) -> Option<PublicKey> {
992+
match self {
993+
InvoiceContents::ForOffer { invoice_request, .. } => {
994+
invoice_request.inner.offer.issuer_signing_pubkey()
995+
},
996+
InvoiceContents::ForRefund { .. } => None,
997+
}
998+
}
999+
9571000
fn payer_metadata(&self) -> &[u8] {
9581001
match self {
9591002
InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.metadata(),

lightning/src/offers/invoice_macros.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice
139139
pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
140140
$contents.features()
141141
}
142-
143-
/// The public key corresponding to the key used to sign the invoice.
144-
pub fn signing_pubkey(&$self) -> PublicKey {
145-
$contents.signing_pubkey()
146-
}
147142
} }
148143

149144
pub(super) use invoice_accessors_common;

lightning/src/offers/static_invoice.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,30 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
241241
pub fn supported_quantity(&$self) -> Quantity {
242242
$contents.supported_quantity()
243243
}
244+
245+
/// The public key used by the recipient to sign invoices, from
246+
/// [`Offer::issuer_signing_pubkey`].
247+
///
248+
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
249+
pub fn issuer_signing_pubkey(&$self) -> Option<PublicKey> {
250+
$contents.issuer_signing_pubkey()
251+
}
252+
} }
253+
254+
macro_rules! invoice_accessors_signing_pubkey {
255+
($self: ident, $contents: expr, $invoice_type: ty) =>
256+
{
257+
/// The public key corresponding to the key used to sign the invoice.
258+
///
259+
/// This will be:
260+
/// - [`Offer::issuer_signing_pubkey`] if it's `Some`, otherwise
261+
/// - the final blinded node id from a [`BlindedMessagePath`] in [`Offer::paths`] if `None`.
262+
///
263+
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
264+
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
265+
pub fn signing_pubkey(&$self) -> PublicKey {
266+
$contents.signing_pubkey()
267+
}
244268
} }
245269

246270
impl UnsignedStaticInvoice {
@@ -272,6 +296,7 @@ impl UnsignedStaticInvoice {
272296
}
273297

274298
invoice_accessors_common!(self, self.contents, StaticInvoice);
299+
invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice);
275300
invoice_accessors!(self, self.contents);
276301
}
277302

@@ -307,6 +332,7 @@ where
307332

308333
impl StaticInvoice {
309334
invoice_accessors_common!(self, self.contents, StaticInvoice);
335+
invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice);
310336
invoice_accessors!(self, self.contents);
311337

312338
/// Signature of the invoice verified using [`StaticInvoice::signing_pubkey`].
@@ -418,6 +444,10 @@ impl InvoiceContents {
418444
self.offer.supported_quantity()
419445
}
420446

447+
fn issuer_signing_pubkey(&self) -> Option<PublicKey> {
448+
self.offer.issuer_signing_pubkey()
449+
}
450+
421451
fn payment_paths(&self) -> &[BlindedPaymentPath] {
422452
&self.payment_paths[..]
423453
}

0 commit comments

Comments
 (0)