mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-13 14:52:21 +01:00
Add issuer_signing_pubkey to Bolt12Invoice
Useful for determining if the signing_pubkey is the issuer_signing_pubkey or is from a blinded path.
This commit is contained in:
parent
73512709e7
commit
a466f2e2f4
3 changed files with 73 additions and 5 deletions
|
@ -714,6 +714,16 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
|
|||
$contents.supported_quantity()
|
||||
}
|
||||
|
||||
/// The public key used by the recipient to sign invoices.
|
||||
///
|
||||
/// From [`Offer::issuer_signing_pubkey`] and may be `None`; also `None` if the invoice was
|
||||
/// created in response to a [`Refund`].
|
||||
///
|
||||
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
|
||||
pub fn issuer_signing_pubkey(&$self) -> Option<PublicKey> {
|
||||
$contents.issuer_signing_pubkey()
|
||||
}
|
||||
|
||||
/// An unpredictable series of bytes from the payer.
|
||||
///
|
||||
/// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
|
||||
|
@ -761,13 +771,37 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
|
|||
}
|
||||
} }
|
||||
|
||||
|
||||
macro_rules! invoice_accessors_signing_pubkey {
|
||||
($self: ident, $contents: expr, $invoice_type: ty) =>
|
||||
{
|
||||
/// A typically transient public key corresponding to the key used to sign the invoice.
|
||||
///
|
||||
/// If the invoices was created in response to an [`Offer`], then this will be:
|
||||
/// - [`Offer::issuer_signing_pubkey`] if it's `Some`, otherwise
|
||||
/// - the final blinded node id from a [`BlindedMessagePath`] in [`Offer::paths`] if `None`.
|
||||
///
|
||||
/// If the invoice was created in response to a [`Refund`], then it is a valid pubkey chosen by
|
||||
/// the recipient.
|
||||
///
|
||||
/// [`Offer`]: crate::offers::offer::Offer
|
||||
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
|
||||
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
|
||||
/// [`Refund`]: crate::offers::refund::Refund
|
||||
pub fn signing_pubkey(&$self) -> PublicKey {
|
||||
$contents.signing_pubkey()
|
||||
}
|
||||
} }
|
||||
|
||||
impl UnsignedBolt12Invoice {
|
||||
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
|
||||
invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice);
|
||||
invoice_accessors!(self, self.contents);
|
||||
}
|
||||
|
||||
impl Bolt12Invoice {
|
||||
invoice_accessors_common!(self, self.contents, Bolt12Invoice);
|
||||
invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice);
|
||||
invoice_accessors!(self, self.contents);
|
||||
|
||||
/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
|
||||
|
@ -954,6 +988,15 @@ impl InvoiceContents {
|
|||
}
|
||||
}
|
||||
|
||||
fn issuer_signing_pubkey(&self) -> Option<PublicKey> {
|
||||
match self {
|
||||
InvoiceContents::ForOffer { invoice_request, .. } => {
|
||||
invoice_request.inner.offer.issuer_signing_pubkey()
|
||||
},
|
||||
InvoiceContents::ForRefund { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn payer_metadata(&self) -> &[u8] {
|
||||
match self {
|
||||
InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.metadata(),
|
||||
|
|
|
@ -139,11 +139,6 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice
|
|||
pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures {
|
||||
$contents.features()
|
||||
}
|
||||
|
||||
/// The public key corresponding to the key used to sign the invoice.
|
||||
pub fn signing_pubkey(&$self) -> PublicKey {
|
||||
$contents.signing_pubkey()
|
||||
}
|
||||
} }
|
||||
|
||||
pub(super) use invoice_accessors_common;
|
||||
|
|
|
@ -241,6 +241,30 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
|
|||
pub fn supported_quantity(&$self) -> Quantity {
|
||||
$contents.supported_quantity()
|
||||
}
|
||||
|
||||
/// The public key used by the recipient to sign invoices, from
|
||||
/// [`Offer::issuer_signing_pubkey`].
|
||||
///
|
||||
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
|
||||
pub fn issuer_signing_pubkey(&$self) -> Option<PublicKey> {
|
||||
$contents.issuer_signing_pubkey()
|
||||
}
|
||||
} }
|
||||
|
||||
macro_rules! invoice_accessors_signing_pubkey {
|
||||
($self: ident, $contents: expr, $invoice_type: ty) =>
|
||||
{
|
||||
/// The public key corresponding to the key used to sign the invoice.
|
||||
///
|
||||
/// This will be:
|
||||
/// - [`Offer::issuer_signing_pubkey`] if it's `Some`, otherwise
|
||||
/// - the final blinded node id from a [`BlindedMessagePath`] in [`Offer::paths`] if `None`.
|
||||
///
|
||||
/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey
|
||||
/// [`Offer::paths`]: crate::offers::offer::Offer::paths
|
||||
pub fn signing_pubkey(&$self) -> PublicKey {
|
||||
$contents.signing_pubkey()
|
||||
}
|
||||
} }
|
||||
|
||||
impl UnsignedStaticInvoice {
|
||||
|
@ -272,6 +296,7 @@ impl UnsignedStaticInvoice {
|
|||
}
|
||||
|
||||
invoice_accessors_common!(self, self.contents, StaticInvoice);
|
||||
invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice);
|
||||
invoice_accessors!(self, self.contents);
|
||||
}
|
||||
|
||||
|
@ -307,6 +332,7 @@ where
|
|||
|
||||
impl StaticInvoice {
|
||||
invoice_accessors_common!(self, self.contents, StaticInvoice);
|
||||
invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice);
|
||||
invoice_accessors!(self, self.contents);
|
||||
|
||||
/// Signature of the invoice verified using [`StaticInvoice::signing_pubkey`].
|
||||
|
@ -418,6 +444,10 @@ impl InvoiceContents {
|
|||
self.offer.supported_quantity()
|
||||
}
|
||||
|
||||
fn issuer_signing_pubkey(&self) -> Option<PublicKey> {
|
||||
self.offer.issuer_signing_pubkey()
|
||||
}
|
||||
|
||||
fn payment_paths(&self) -> &[BlindedPaymentPath] {
|
||||
&self.payment_paths[..]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue