Skip to content

Commit

Permalink
Bolt12Invoice for Offer without signing_pubkey
Browse files Browse the repository at this point in the history
When parsing a Bolt12Invoice use both the Offer's signing_pubkey and
paths to determine if it is for an Offer or a Refund. Previously, an
Offer was required to have a signing_pubkey. But now that it is
optional, the Offers paths can be used to make the determination.
Additionally, check that the invoice matches one of the blinded node ids
from the paths' last hops.
  • Loading branch information
jkczyz committed Apr 24, 2024
1 parent d20de39 commit 94d12f9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,8 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
features, signing_pubkey,
};

match offer_tlv_stream.node_id {
Some(expected_signing_pubkey) => {
match (offer_tlv_stream.node_id, &offer_tlv_stream.paths) {
(Some(expected_signing_pubkey), _) => {
if fields.signing_pubkey != expected_signing_pubkey {
return Err(Bolt12SemanticError::InvalidSigningPubkey);
}
Expand All @@ -1458,7 +1458,21 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
)?;
Ok(InvoiceContents::ForOffer { invoice_request, fields })
},
None => {
(None, Some(paths)) => {
if !paths
.iter()
.filter_map(|path| path.blinded_hops.last())
.any(|last_hop| fields.signing_pubkey == last_hop.blinded_node_id)
{
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)
)?;
Expand Down

0 comments on commit 94d12f9

Please sign in to comment.