From 3cfb24d265ecd9a708aed0bb9de665760e16e999 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 6 Jun 2024 14:43:10 -0400 Subject: [PATCH] InvoiceTlvStream{Ref}: add message_paths field Will be used in static invoices. Also test that we'll fail to decode if these paths are included in single-use BOLT 12 invoices. --- lightning/src/offers/invoice.rs | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 0aed817b2..6695121b3 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -1102,6 +1102,7 @@ impl InvoiceFields { fallbacks: self.fallbacks.as_ref(), features, node_id: Some(&self.signing_pubkey), + message_paths: None, } } } @@ -1162,6 +1163,8 @@ tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, 160..240, { (172, fallbacks: (Vec, WithoutLength)), (174, features: (Bolt12InvoiceFeatures, WithoutLength)), (176, node_id: PublicKey), + // Only present in `StaticInvoice`s. + (238, message_paths: (Vec, WithoutLength)), }); pub(super) type BlindedPathIter<'a> = core::iter::Map< @@ -1299,10 +1302,12 @@ impl TryFrom for InvoiceContents { invoice_request_tlv_stream, InvoiceTlvStream { paths, blindedpay, created_at, relative_expiry, payment_hash, amount, fallbacks, - features, node_id, + features, node_id, message_paths, }, ) = tlv_stream; + if message_paths.is_some() { return Err(Bolt12SemanticError::UnexpectedPaths) } + let payment_paths = construct_payment_paths(blindedpay, paths)?; let created_at = match created_at { @@ -1568,6 +1573,7 @@ mod tests { fallbacks: None, features: None, node_id: Some(&recipient_pubkey()), + message_paths: None, }, SignatureTlvStreamRef { signature: Some(&invoice.signature()) }, ), @@ -1659,6 +1665,7 @@ mod tests { fallbacks: None, features: None, node_id: Some(&recipient_pubkey()), + message_paths: None, }, SignatureTlvStreamRef { signature: Some(&invoice.signature()) }, ), @@ -2429,4 +2436,35 @@ mod tests { Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)), } } + + #[test] + fn fails_parsing_invoice_with_message_paths() { + let invoice = OfferBuilder::new(recipient_pubkey()) + .amount_msats(1000) + .build().unwrap() + .request_invoice(vec![1; 32], payer_pubkey()).unwrap() + .build().unwrap() + .sign(payer_sign).unwrap() + .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap() + .build().unwrap() + .sign(recipient_sign).unwrap(); + + let blinded_path = BlindedPath { + introduction_node: IntroductionNode::NodeId(pubkey(40)), + blinding_point: pubkey(41), + blinded_hops: vec![ + BlindedHop { blinded_node_id: pubkey(42), encrypted_payload: vec![0; 43] }, + BlindedHop { blinded_node_id: pubkey(43), encrypted_payload: vec![0; 44] }, + ], + }; + + let mut tlv_stream = invoice.as_tlv_stream(); + let message_paths = vec![blinded_path]; + tlv_stream.3.message_paths = Some(&message_paths); + + match Bolt12Invoice::try_from(tlv_stream.to_bytes()) { + Ok(_) => panic!("expected error"), + Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedPaths)), + } + } } -- 2.39.5