Skip to content

Commit cff6e34

Browse files
Support checking that a static invoice matches an outbound invreq.
Useful for ensuring that an inbound static invoice matches one of our outbound invreqs, otherwise it is an unexpected invoice and should be ignored and not paid.
1 parent 3d5d64a commit cff6e34

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lightning/src/offers/invoice_request.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ impl InvoiceRequest {
840840
invoice_request_accessors!(self, self.contents);
841841
invoice_request_respond_with_explicit_signing_pubkey_methods!(self, self, InvoiceBuilder<ExplicitSigningPubkey>);
842842
invoice_request_verify_method!(self, Self);
843+
844+
#[cfg(async_payments)]
845+
pub(super) fn bytes(&self) -> &Vec<u8> {
846+
&self.bytes
847+
}
843848
}
844849

845850
#[cfg(c_bindings)]

lightning/src/offers/merkle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl<'a> TlvStream<'a> {
249249
}
250250

251251
/// A slice into a [`TlvStream`] for a record.
252+
#[derive(Eq, PartialEq)]
252253
pub(super) struct TlvRecord<'a> {
253254
pub(super) r#type: u64,
254255
type_bytes: &'a [u8],

lightning/src/offers/static_invoice.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ use crate::offers::invoice::{
2020
InvoiceTlvStream, InvoiceTlvStreamRef,
2121
};
2222
use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common};
23+
use crate::offers::invoice_request::InvoiceRequest;
2324
use crate::offers::merkle::{
24-
self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash,
25+
self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream,
2526
};
2627
use crate::offers::nonce::Nonce;
2728
use crate::offers::offer::{
28-
Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity,
29+
Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity, OFFER_TYPES,
2930
};
3031
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
3132
use crate::util::ser::{CursorReadable, Iterable, WithoutLength, Writeable, Writer};
@@ -312,6 +313,16 @@ impl StaticInvoice {
312313
pub fn signature(&self) -> Signature {
313314
self.signature
314315
}
316+
317+
pub(crate) fn from_same_offer(&self, invreq: &InvoiceRequest) -> bool {
318+
let invoice_offer_tlv_stream = TlvStream::new(&self.bytes)
319+
.range(OFFER_TYPES)
320+
.map(|tlv_record| tlv_record.record_bytes);
321+
let invreq_offer_tlv_stream = TlvStream::new(invreq.bytes())
322+
.range(OFFER_TYPES)
323+
.map(|tlv_record| tlv_record.record_bytes);
324+
invoice_offer_tlv_stream.eq(invreq_offer_tlv_stream)
325+
}
315326
}
316327

317328
impl InvoiceContents {

0 commit comments

Comments
 (0)