-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce custom TLV support for OnionMessage #2830
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,9 +55,9 @@ impl Readable for BlindedMessagePath { | |
impl BlindedMessagePath { | ||
/// Create a one-hop blinded path for a message. | ||
pub fn one_hop<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>( | ||
recipient_node_id: PublicKey, context: MessageContext, entropy_source: ES, secp_ctx: &Secp256k1<T> | ||
recipient_node_id: PublicKey, context: MessageContext, custom_tlvs: Vec<u8>, entropy_source: ES, secp_ctx: &Secp256k1<T> | ||
) -> Result<Self, ()> where ES::Target: EntropySource { | ||
Self::new(&[], recipient_node_id, context, entropy_source, secp_ctx) | ||
Self::new(&[], recipient_node_id, context, custom_tlvs, entropy_source, secp_ctx) | ||
} | ||
|
||
/// Create a path for an onion message, to be forwarded along `node_pks`. The last node | ||
|
@@ -67,7 +67,7 @@ impl BlindedMessagePath { | |
// TODO: make all payloads the same size with padding + add dummy hops | ||
pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>( | ||
intermediate_nodes: &[MessageForwardNode], recipient_node_id: PublicKey, | ||
context: MessageContext, entropy_source: ES, secp_ctx: &Secp256k1<T>, | ||
context: MessageContext, custom_tlvs: Vec<u8>, entropy_source: ES, secp_ctx: &Secp256k1<T>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should pass |
||
) -> Result<Self, ()> where ES::Target: EntropySource { | ||
let introduction_node = IntroductionNode::NodeId( | ||
intermediate_nodes.first().map_or(recipient_node_id, |n| n.node_id) | ||
|
@@ -80,7 +80,7 @@ impl BlindedMessagePath { | |
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret), | ||
blinded_hops: blinded_hops( | ||
secp_ctx, intermediate_nodes, recipient_node_id, | ||
context, &blinding_secret, | ||
context, custom_tlvs, &blinding_secret, | ||
).map_err(|_| ())?, | ||
})) | ||
} | ||
|
@@ -241,7 +241,10 @@ pub(crate) struct ReceiveTlvs { | |
/// If `context` is `Some`, it is used to identify the blinded path that this onion message is | ||
/// sending to. This is useful for receivers to check that said blinded path is being used in | ||
/// the right context. | ||
pub context: Option<MessageContext> | ||
pub context: Option<MessageContext>, | ||
|
||
/// Custom Tlvs. A user can use this to send custom tlvs information back to themself. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure someone reading this would understand what it means. Could you be clearer? |
||
pub custom_tlvs: Option<Vec<u8>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this is just custom data rather than custom TLVs. Nothing is enforcing that this data is encoded as a TLV stream. @TheBlueMatt Not sure if you have any thoughts on how if we should make this a |
||
} | ||
|
||
impl Writeable for ForwardTlvs { | ||
|
@@ -265,6 +268,7 @@ impl Writeable for ReceiveTlvs { | |
// TODO: write padding | ||
encode_tlv_stream!(writer, { | ||
(65537, self.context, option), | ||
(65539, self.custom_tlvs, option), | ||
}); | ||
Ok(()) | ||
} | ||
|
@@ -456,7 +460,7 @@ impl_writeable_tlv_based!(DNSResolverContext, { | |
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`. | ||
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>( | ||
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[MessageForwardNode], | ||
recipient_node_id: PublicKey, context: MessageContext, session_priv: &SecretKey, | ||
recipient_node_id: PublicKey, context: MessageContext, custom_tlvs: Vec<u8>, session_priv: &SecretKey, | ||
) -> Result<Vec<BlindedHop>, secp256k1::Error> { | ||
let pks = intermediate_nodes.iter().map(|node| node.node_id) | ||
.chain(core::iter::once(recipient_node_id)); | ||
|
@@ -468,7 +472,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>( | |
None => NextMessageHop::NodeId(pubkey), | ||
}) | ||
.map(|next_hop| ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override: None })) | ||
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs{ context: Some(context) }))); | ||
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs{ context: Some(context), custom_tlvs: Some(custom_tlvs) }))); | ||
|
||
let path = pks.zip(tlvs); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First commit message doesn't seem accurate. It says "reply path of a sent onion message", but this isn't restricted to reply paths. One could use this to include custom TLVs in an blinded path, including one in an offer.