Skip to content

Commit af4d95f

Browse files
committed
Include OfferId in VerifiedInvoiceRequest
Extract the OfferId from the offer metadata sent back in the InvoiceRequest and include it in VerifiedInvoiceRequest. This can be used to correspond the eventual payment for the invoice response by including it in the invoice's blinded payment paths.
1 parent f85fc8a commit af4d95f

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lightning/src/offers/invoice_request.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
7373
use crate::ln::msgs::DecodeError;
7474
use crate::offers::invoice::BlindedPayInfo;
7575
use crate::offers::merkle::{SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, self};
76-
use crate::offers::offer::{Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef};
76+
use crate::offers::offer::{Offer, OfferContents, OfferId, OfferTlvStream, OfferTlvStreamRef};
7777
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, Bolt12SemanticError};
7878
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
7979
use crate::offers::signer::{Metadata, MetadataMaterial};
@@ -607,6 +607,9 @@ pub struct InvoiceRequest {
607607
/// ways to respond depending on whether the signing keys were derived.
608608
#[derive(Clone, Debug)]
609609
pub struct VerifiedInvoiceRequest {
610+
/// The identifier of the [`Offer`] for which the [`InvoiceRequest`] was made.
611+
pub offer_id: OfferId,
612+
610613
/// The verified request.
611614
inner: InvoiceRequest,
612615

@@ -764,8 +767,9 @@ macro_rules! invoice_request_verify_method { ($self: ident, $self_type: ty) => {
764767
#[cfg(c_bindings)]
765768
secp_ctx: &Secp256k1<secp256k1::All>,
766769
) -> Result<VerifiedInvoiceRequest, ()> {
767-
let keys = $self.contents.inner.offer.verify(&$self.bytes, key, secp_ctx)?;
770+
let (offer_id, keys) = $self.contents.inner.offer.verify(&$self.bytes, key, secp_ctx)?;
768771
Ok(VerifiedInvoiceRequest {
772+
offer_id,
769773
#[cfg(not(c_bindings))]
770774
inner: $self,
771775
#[cfg(c_bindings)]

lightning/src/offers/offer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ impl OfferContents {
870870
/// Verifies that the offer metadata was produced from the offer in the TLV stream.
871871
pub(super) fn verify<T: secp256k1::Signing>(
872872
&self, bytes: &[u8], key: &ExpandedKey, secp_ctx: &Secp256k1<T>
873-
) -> Result<Option<KeyPair>, ()> {
873+
) -> Result<(OfferId, Option<KeyPair>), ()> {
874874
match self.metadata() {
875875
Some(metadata) => {
876876
let tlv_stream = TlvStream::new(bytes).range(OFFER_TYPES).filter(|record| {
@@ -882,9 +882,11 @@ impl OfferContents {
882882
_ => true,
883883
}
884884
});
885-
signer::verify_recipient_metadata(
885+
let (keys, nonce) = signer::verify_recipient_metadata(
886886
metadata, key, IV_BYTES, self.signing_pubkey(), tlv_stream, secp_ctx
887-
)
887+
)?;
888+
let offer_id = OfferId(nonce);
889+
Ok((offer_id, keys))
888890
},
889891
None => Err(()),
890892
}

lightning/src/offers/signer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ pub(super) fn verify_recipient_metadata<'a, T: secp256k1::Signing>(
271271
metadata: &[u8], expanded_key: &ExpandedKey, iv_bytes: &[u8; IV_LEN],
272272
signing_pubkey: PublicKey, tlv_stream: impl core::iter::Iterator<Item = TlvRecord<'a>>,
273273
secp_ctx: &Secp256k1<T>
274-
) -> Result<Option<KeyPair>, ()> {
274+
) -> Result<(Option<KeyPair>, Nonce), ()> {
275275
let mut hmac = hmac_for_message(metadata, expanded_key, iv_bytes, tlv_stream)?;
276276
hmac.input(WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT);
277277

278-
verify_metadata(metadata, Hmac::from_engine(hmac), signing_pubkey, secp_ctx)
278+
let keys = verify_metadata(metadata, Hmac::from_engine(hmac), signing_pubkey, secp_ctx)?;
279+
let nonce = Nonce::try_from(&metadata[..Nonce::LENGTH]).unwrap();
280+
Ok((keys, nonce))
279281
}
280282

281283
fn verify_metadata<T: secp256k1::Signing>(

0 commit comments

Comments
 (0)