@@ -20,6 +20,7 @@ use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessage
20
20
use crate :: blinded_path:: utils;
21
21
use crate :: io;
22
22
use crate :: io:: Cursor ;
23
+ use crate :: ln:: channelmanager:: PaymentId ;
23
24
use crate :: ln:: onion_utils;
24
25
use crate :: onion_message:: packet:: ControlTlvs ;
25
26
use crate :: sign:: { NodeSigner , Recipient } ;
@@ -52,10 +53,10 @@ pub(crate) struct ForwardTlvs {
52
53
53
54
/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
54
55
pub ( 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
56
57
/// sending to. This is useful for receivers to check that said blinded path is being used in
57
58
/// the right context.
58
- pub ( crate ) path_id : Option < [ u8 ; 32 ] > ,
59
+ pub context : Option < MessageContext >
59
60
}
60
61
61
62
impl Writeable for ForwardTlvs {
@@ -78,16 +79,62 @@ impl Writeable for ReceiveTlvs {
78
79
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
79
80
// TODO: write padding
80
81
encode_tlv_stream ! ( writer, {
81
- ( 6 , self . path_id , option) ,
82
+ ( 65537 , self . context , option) ,
82
83
} ) ;
83
84
Ok ( ( ) )
84
85
}
85
86
}
86
87
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
+
87
134
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
88
135
pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
89
136
secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ ForwardNode ] , recipient_node_id : PublicKey ,
90
- session_priv : & SecretKey
137
+ context : MessageContext , session_priv : & SecretKey
91
138
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
92
139
let pks = intermediate_nodes. iter ( ) . map ( |node| & node. node_id )
93
140
. chain ( core:: iter:: once ( & recipient_node_id) ) ;
@@ -99,7 +146,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
99
146
None => NextMessageHop :: NodeId ( * pubkey) ,
100
147
} )
101
148
. 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 ) } ) ) ) ;
103
150
104
151
utils:: construct_blinded_hops ( secp_ctx, pks, tlvs, session_priv)
105
152
}
0 commit comments