@@ -55,9 +55,9 @@ impl Readable for BlindedMessagePath {
55
55
impl BlindedMessagePath {
56
56
/// Create a one-hop blinded path for a message.
57
57
pub fn one_hop < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
58
- recipient_node_id : PublicKey , context : MessageContext , entropy_source : ES , secp_ctx : & Secp256k1 < T >
58
+ recipient_node_id : PublicKey , context : MessageContext , custom_tlvs : Vec < u8 > , entropy_source : ES , secp_ctx : & Secp256k1 < T >
59
59
) -> Result < Self , ( ) > where ES :: Target : EntropySource {
60
- Self :: new ( & [ ] , recipient_node_id, context, entropy_source, secp_ctx)
60
+ Self :: new ( & [ ] , recipient_node_id, context, custom_tlvs , entropy_source, secp_ctx)
61
61
}
62
62
63
63
/// Create a path for an onion message, to be forwarded along `node_pks`. The last node
@@ -67,7 +67,7 @@ impl BlindedMessagePath {
67
67
// TODO: make all payloads the same size with padding + add dummy hops
68
68
pub fn new < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
69
69
intermediate_nodes : & [ MessageForwardNode ] , recipient_node_id : PublicKey ,
70
- context : MessageContext , entropy_source : ES , secp_ctx : & Secp256k1 < T > ,
70
+ context : MessageContext , custom_tlvs : Vec < u8 > , entropy_source : ES , secp_ctx : & Secp256k1 < T > ,
71
71
) -> Result < Self , ( ) > where ES :: Target : EntropySource {
72
72
let introduction_node = IntroductionNode :: NodeId (
73
73
intermediate_nodes. first ( ) . map_or ( recipient_node_id, |n| n. node_id )
@@ -80,7 +80,7 @@ impl BlindedMessagePath {
80
80
blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
81
81
blinded_hops : blinded_hops (
82
82
secp_ctx, intermediate_nodes, recipient_node_id,
83
- context, & blinding_secret,
83
+ context, custom_tlvs , & blinding_secret,
84
84
) . map_err ( |_| ( ) ) ?,
85
85
} ) )
86
86
}
@@ -241,7 +241,10 @@ pub(crate) struct ReceiveTlvs {
241
241
/// If `context` is `Some`, it is used to identify the blinded path that this onion message is
242
242
/// sending to. This is useful for receivers to check that said blinded path is being used in
243
243
/// the right context.
244
- pub context : Option < MessageContext >
244
+ pub context : Option < MessageContext > ,
245
+
246
+ /// Custom Tlvs. A user can use this to send custom tlvs information back to themself.
247
+ pub custom_tlvs : Option < Vec < u8 > > ,
245
248
}
246
249
247
250
impl Writeable for ForwardTlvs {
@@ -265,6 +268,7 @@ impl Writeable for ReceiveTlvs {
265
268
// TODO: write padding
266
269
encode_tlv_stream ! ( writer, {
267
270
( 65537 , self . context, option) ,
271
+ ( 65539 , self . custom_tlvs, option) ,
268
272
} ) ;
269
273
Ok ( ( ) )
270
274
}
@@ -456,7 +460,7 @@ impl_writeable_tlv_based!(DNSResolverContext, {
456
460
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
457
461
pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
458
462
secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ MessageForwardNode ] ,
459
- recipient_node_id : PublicKey , context : MessageContext , session_priv : & SecretKey ,
463
+ recipient_node_id : PublicKey , context : MessageContext , custom_tlvs : Vec < u8 > , session_priv : & SecretKey ,
460
464
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
461
465
let pks = intermediate_nodes. iter ( ) . map ( |node| node. node_id )
462
466
. chain ( core:: iter:: once ( recipient_node_id) ) ;
@@ -468,7 +472,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
468
472
None => NextMessageHop :: NodeId ( pubkey) ,
469
473
} )
470
474
. map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
471
- . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
475
+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) , custom_tlvs : Some ( custom_tlvs ) } ) ) ) ;
472
476
473
477
let path = pks. zip ( tlvs) ;
474
478
0 commit comments