mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 15:20:24 +01:00
BOLT 12 invoice: extract helper for invoice signing pubkey checks
Will be useful for static invoices.
This commit is contained in:
parent
b073711738
commit
f6bd1ebfc5
1 changed files with 34 additions and 30 deletions
|
@ -1337,37 +1337,18 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
|
||||||
features, signing_pubkey,
|
features, signing_pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
match (offer_tlv_stream.node_id, &offer_tlv_stream.paths) {
|
check_invoice_signing_pubkey(&fields.signing_pubkey, &offer_tlv_stream)?;
|
||||||
(Some(expected_signing_pubkey), _) => {
|
|
||||||
if fields.signing_pubkey != expected_signing_pubkey {
|
|
||||||
return Err(Bolt12SemanticError::InvalidSigningPubkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
let invoice_request = InvoiceRequestContents::try_from(
|
if offer_tlv_stream.node_id.is_none() && offer_tlv_stream.paths.is_none() {
|
||||||
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
|
let refund = RefundContents::try_from(
|
||||||
)?;
|
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
|
||||||
Ok(InvoiceContents::ForOffer { invoice_request, fields })
|
)?;
|
||||||
},
|
Ok(InvoiceContents::ForRefund { refund, fields })
|
||||||
(None, Some(paths)) => {
|
} else {
|
||||||
if !paths
|
let invoice_request = InvoiceRequestContents::try_from(
|
||||||
.iter()
|
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
|
||||||
.filter_map(|path| path.blinded_hops.last())
|
)?;
|
||||||
.any(|last_hop| fields.signing_pubkey == last_hop.blinded_node_id)
|
Ok(InvoiceContents::ForOffer { invoice_request, fields })
|
||||||
{
|
|
||||||
return Err(Bolt12SemanticError::InvalidSigningPubkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
let invoice_request = InvoiceRequestContents::try_from(
|
|
||||||
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
|
|
||||||
)?;
|
|
||||||
Ok(InvoiceContents::ForOffer { invoice_request, fields })
|
|
||||||
},
|
|
||||||
(None, None) => {
|
|
||||||
let refund = RefundContents::try_from(
|
|
||||||
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
|
|
||||||
)?;
|
|
||||||
Ok(InvoiceContents::ForRefund { refund, fields })
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1388,6 +1369,29 @@ pub(super) fn construct_payment_paths(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn check_invoice_signing_pubkey(
|
||||||
|
invoice_signing_pubkey: &PublicKey, offer_tlv_stream: &OfferTlvStream
|
||||||
|
) -> Result<(), Bolt12SemanticError> {
|
||||||
|
match (&offer_tlv_stream.node_id, &offer_tlv_stream.paths) {
|
||||||
|
(Some(expected_signing_pubkey), _) => {
|
||||||
|
if invoice_signing_pubkey != expected_signing_pubkey {
|
||||||
|
return Err(Bolt12SemanticError::InvalidSigningPubkey);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(None, Some(paths)) => {
|
||||||
|
if !paths
|
||||||
|
.iter()
|
||||||
|
.filter_map(|path| path.blinded_hops.last())
|
||||||
|
.any(|last_hop| invoice_signing_pubkey == &last_hop.blinded_node_id)
|
||||||
|
{
|
||||||
|
return Err(Bolt12SemanticError::InvalidSigningPubkey);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, FallbackAddress, FullInvoiceTlvStreamRef, InvoiceTlvStreamRef, SIGNATURE_TAG, UnsignedBolt12Invoice};
|
use super::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, FallbackAddress, FullInvoiceTlvStreamRef, InvoiceTlvStreamRef, SIGNATURE_TAG, UnsignedBolt12Invoice};
|
||||||
|
|
Loading…
Add table
Reference in a new issue