Skip to content

Commit 6e38b75

Browse files
committed
f - replace invoice_code with invoice_node_id
1 parent b249e9b commit 6e38b75

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

lightning/src/offers/invoice.rs

+22-29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
use bitcoin::blockdata::constants::ChainHash;
1313
use bitcoin::network::constants::Network;
14+
use bitcoin::secp256k1::PublicKey;
1415
use bitcoin::secp256k1::schnorr::Signature;
1516
use bitcoin::util::address::{Address, Payload, WitnessVersion};
1617
use core::convert::TryFrom;
@@ -48,7 +49,7 @@ const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice", "signature")
4849
pub struct Invoice {
4950
bytes: Vec<u8>,
5051
contents: InvoiceContents,
51-
signature: Option<Signature>,
52+
signature: Signature,
5253
}
5354

5455
/// The contents of an [`Invoice`] for responding to either an [`Offer`] or a [`Refund`].
@@ -82,7 +83,7 @@ struct InvoiceFields {
8283
amount_msats: u64,
8384
fallbacks: Option<Vec<FallbackAddress>>,
8485
features: Bolt12InvoiceFeatures,
85-
code: Option<String>,
86+
signing_pubkey: PublicKey,
8687
}
8788

8889
impl Invoice {
@@ -186,16 +187,13 @@ impl Invoice {
186187
&self.contents.fields().features
187188
}
188189

189-
/// A short string used for verifying the recipient when issuing a refund. The payer should only
190-
/// pay the invoice after confirming with recipient out-of-band that this code is correct.
191-
pub fn code(&self) -> Option<&str> {
192-
self.contents.fields().code.as_ref().map(|code| code.as_str())
190+
/// The public key used to sign invoices.
191+
pub fn signing_pubkey(&self) -> PublicKey {
192+
self.contents.fields().signing_pubkey
193193
}
194194

195-
/// Signature of the invoice using [`signing_pubkey`]. `None` for invoices paying refunds.
196-
///
197-
/// [`signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
198-
pub fn signature(&self) -> Option<Signature> {
195+
/// Signature of the invoice using [`Invoice::signing_pubkey`].
196+
pub fn signature(&self) -> Signature {
199197
self.signature
200198
}
201199
}
@@ -240,7 +238,7 @@ tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, 160..240, {
240238
(170, amount: (u64, HighZeroBytesDroppedBigSize)),
241239
(172, fallbacks: (Vec<FallbackAddress>, WithoutLength)),
242240
(174, features: (Bolt12InvoiceFeatures, WithoutLength)),
243-
(176, code: (String, WithoutLength)),
241+
(176, node_id: PublicKey),
244242
});
245243

246244
/// Information needed to route a payment across a [`BlindedPath`] hop.
@@ -303,18 +301,12 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Invoice {
303301
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream)
304302
)?;
305303

306-
match &contents {
307-
InvoiceContents::ForOffer { invoice_request, .. } => match &signature {
308-
None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
309-
Some(signature) => {
310-
let pubkey = invoice_request.offer.signing_pubkey();
311-
merkle::verify_signature(signature, SIGNATURE_TAG, &bytes, pubkey)?;
312-
},
313-
},
314-
InvoiceContents::ForRefund { .. } => if let Some(_) = &signature {
315-
return Err(ParseError::InvalidSemantics(SemanticError::UnexpectedSignature));
316-
},
317-
}
304+
let signature = match signature {
305+
None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
306+
Some(signature) => signature,
307+
};
308+
let pubkey = contents.fields().signing_pubkey;
309+
merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, pubkey)?;
318310

319311
Ok(Invoice { bytes, contents, signature })
320312
}
@@ -330,7 +322,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
330322
invoice_request_tlv_stream,
331323
InvoiceTlvStream {
332324
paths, blindedpay, created_at, relative_expiry, payment_hash, amount, fallbacks,
333-
features, code,
325+
features, node_id,
334326
},
335327
) = tlv_stream;
336328

@@ -365,17 +357,18 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
365357

366358
let features = features.unwrap_or_else(Bolt12InvoiceFeatures::empty);
367359

360+
let signing_pubkey = match node_id {
361+
None => return Err(SemanticError::MissingSigningPubkey),
362+
Some(node_id) => node_id,
363+
};
364+
368365
let fields = InvoiceFields {
369366
paths, payinfo, created_at, relative_expiry, payment_hash, amount_msats, fallbacks,
370-
features, code,
367+
features, signing_pubkey,
371368
};
372369

373370
match offer_tlv_stream.node_id {
374371
Some(_) => {
375-
if fields.code.is_some() {
376-
return Err(SemanticError::UnexpectedCode);
377-
}
378-
379372
let invoice_request = InvoiceRequestContents::try_from(
380373
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
381374
)?;

lightning/src/offers/offer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl OfferContents {
486486
}
487487
}
488488

489-
pub fn signing_pubkey(&self) -> PublicKey {
489+
pub(super) fn signing_pubkey(&self) -> PublicKey {
490490
self.signing_pubkey
491491
}
492492

lightning/src/offers/parse.rs

-4
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,8 @@ pub enum SemanticError {
167167
MissingCreationTime,
168168
/// An invoice payment hash was expected but was missing.
169169
MissingPaymentHash,
170-
///
171-
UnexpectedCode,
172170
/// A signature was expected but was missing.
173171
MissingSignature,
174-
///
175-
UnexpectedSignature,
176172
}
177173

178174
impl From<bech32::Error> for ParseError {

0 commit comments

Comments
 (0)