Skip to content

Commit ae51409

Browse files
Support verifying that a static invoice matches an invreq.
Useful for ensuring that an inbound static invoice matches one of our outbound invreqs.
1 parent 7d50a2d commit ae51409

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lightning/src/offers/invoice_request.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ impl InvoiceRequest {
807807
invoice_request_accessors!(self, self.contents);
808808
invoice_request_respond_with_explicit_signing_pubkey_methods!(self, self, InvoiceBuilder<ExplicitSigningPubkey>);
809809
invoice_request_verify_method!(self, Self);
810+
811+
#[cfg(async_payments)]
812+
pub(super) fn bytes(&self) -> &Vec<u8> {
813+
&self.bytes
814+
}
810815
}
811816

812817
#[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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ use crate::offers::invoice::{
1919
FallbackAddress, InvoiceTlvStream, InvoiceTlvStreamRef,
2020
};
2121
use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common};
22+
use crate::offers::invoice_request::InvoiceRequest;
2223
use crate::offers::merkle::{
23-
self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash,
24+
self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream,
2425
};
2526
use crate::offers::offer::{
26-
Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity,
27+
Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity, OFFER_TYPES,
2728
};
2829
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
2930
use crate::util::ser::{Iterable, SeekReadable, WithoutLength, Writeable, Writer};
@@ -310,6 +311,12 @@ impl StaticInvoice {
310311
pub fn signature(&self) -> Signature {
311312
self.signature
312313
}
314+
315+
pub(crate) fn matches_invreq(&self, invreq: &InvoiceRequest) -> bool {
316+
let invoice_offer_tlv_stream = TlvStream::new(&self.bytes).range(OFFER_TYPES);
317+
let invreq_offer_tlv_stream = TlvStream::new(invreq.bytes()).range(OFFER_TYPES);
318+
invoice_offer_tlv_stream.zip(invreq_offer_tlv_stream).all(|(tlv1, tlv2)| tlv1 == tlv2)
319+
}
313320
}
314321

315322
impl InvoiceContents {

0 commit comments

Comments
 (0)