@@ -20,6 +20,7 @@ use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessage
2020use crate :: blinded_path:: utils;
2121use crate :: io;
2222use crate :: io:: Cursor ;
23+ use crate :: ln:: channelmanager:: PaymentId ;
2324use crate :: ln:: onion_utils;
2425use crate :: onion_message:: packet:: ControlTlvs ;
2526use crate :: sign:: { NodeSigner , Recipient } ;
@@ -52,10 +53,10 @@ pub(crate) struct ForwardTlvs {
5253
5354/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
5455pub ( crate ) struct ReceiveTlvs {
55- /// If `path_id ` is `Some`, it is used to identify the blinded path that this onion message is
56+ /// If `context ` is `Some`, it is used to identify the blinded path that this onion message is
5657 /// sending to. This is useful for receivers to check that said blinded path is being used in
5758 /// the right context.
58- pub ( crate ) path_id : Option < [ u8 ; 32 ] > ,
59+ pub context : Option < MessageContext >
5960}
6061
6162impl Writeable for ForwardTlvs {
@@ -78,16 +79,62 @@ impl Writeable for ReceiveTlvs {
7879 fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
7980 // TODO: write padding
8081 encode_tlv_stream ! ( writer, {
81- ( 6 , self . path_id , option) ,
82+ ( 65537 , self . context , option) ,
8283 } ) ;
8384 Ok ( ( ) )
8485 }
8586}
8687
88+ /// Represents additional data included by the recipient in a [`BlindedPath`].
89+ ///
90+ /// This data is encrypted by the recipient and remains invisible to anyone else.
91+ /// It is included in the [`BlindedPath`], making it accessible again to the recipient
92+ /// whenever the [`BlindedPath`] is used.
93+ /// The recipient can authenticate the message and utilize it for further processing
94+ /// if needed.
95+ #[ derive( Clone , Debug ) ]
96+ pub enum MessageContext {
97+ /// Represents the data specific to [`OffersMessage`]
98+ ///
99+ /// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
100+ Offers ( OffersContext ) ,
101+ /// Represents custom data received in a Custom Onion Message.
102+ Custom ( Vec < u8 > ) ,
103+ }
104+
105+ /// Contains the data specific to [`OffersMessage`]
106+ ///
107+ /// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
108+ #[ derive( Clone , Debug ) ]
109+ pub enum OffersContext {
110+ /// Represents an unknown BOLT12 payment context.
111+ /// This variant is used when a message is sent without
112+ /// using a [`BlindedPath`] or over one created prior to
113+ /// LDK version 0.0.124.
114+ Unknown { } ,
115+ /// Represents an outbound BOLT12 payment context.
116+ OutboundPayment {
117+ /// Payment ID of the outbound BOLT12 payment.
118+ payment_id : PaymentId
119+ } ,
120+ }
121+
122+ impl_writeable_tlv_based_enum ! ( MessageContext , ;
123+ ( 0 , Offers ) ,
124+ ( 1 , Custom ) ,
125+ ) ;
126+
127+ impl_writeable_tlv_based_enum ! ( OffersContext ,
128+ ( 0 , Unknown ) => { } ,
129+ ( 1 , OutboundPayment ) => {
130+ ( 0 , payment_id, required) ,
131+ } ,
132+ ; ) ;
133+
87134/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
88135pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
89136 secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ ForwardNode ] , recipient_node_id : PublicKey ,
90- session_priv : & SecretKey
137+ context : MessageContext , session_priv : & SecretKey
91138) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
92139 let pks = intermediate_nodes. iter ( ) . map ( |node| & node. node_id )
93140 . chain ( core:: iter:: once ( & recipient_node_id) ) ;
@@ -99,7 +146,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
99146 None => NextMessageHop :: NodeId ( * pubkey) ,
100147 } )
101148 . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
102- . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { path_id : None } ) ) ) ;
149+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context ) } ) ) ) ;
103150
104151 utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
105152}
0 commit comments