|
14 | 14 | use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey}; |
15 | 15 |
|
16 | 16 | use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp}; |
17 | | -use crate::blinded_path::utils; |
| 17 | +use crate::blinded_path::utils::{self, WithPadding}; |
18 | 18 | use crate::crypto::streams::ChaChaPolyReadAdapter; |
19 | 19 | use crate::io; |
20 | 20 | use crate::io::Cursor; |
@@ -86,6 +86,7 @@ pub(crate) enum BlindedPaymentTlvs { |
86 | 86 | } |
87 | 87 |
|
88 | 88 | // Used to include forward and receive TLVs in the same iterator for encoding. |
| 89 | +#[derive(Clone)] |
89 | 90 | enum BlindedPaymentTlvsRef<'a> { |
90 | 91 | Forward(&'a ForwardTlvs), |
91 | 92 | Receive(&'a ReceiveTlvs), |
@@ -226,7 +227,6 @@ impl Writeable for ReceiveTlvs { |
226 | 227 |
|
227 | 228 | impl<'a> Writeable for BlindedPaymentTlvsRef<'a> { |
228 | 229 | fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> { |
229 | | - // TODO: write padding |
230 | 230 | match self { |
231 | 231 | Self::Forward(tlvs) => tlvs.write(w)?, |
232 | 232 | Self::Receive(tlvs) => tlvs.write(w)?, |
@@ -278,7 +278,15 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>( |
278 | 278 | .chain(core::iter::once(&payee_node_id)); |
279 | 279 | let tlvs = intermediate_nodes.iter().map(|node| BlindedPaymentTlvsRef::Forward(&node.tlvs)) |
280 | 280 | .chain(core::iter::once(BlindedPaymentTlvsRef::Receive(&payee_tlvs))); |
281 | | - utils::construct_blinded_hops(secp_ctx, pks, tlvs, session_priv) |
| 281 | + |
| 282 | + let max_length = tlvs.clone() |
| 283 | + .map(|tlv| tlv.serialized_length()) |
| 284 | + .max() |
| 285 | + .unwrap_or(0); |
| 286 | + |
| 287 | + let length_tlvs = tlvs.map(|tlvs| WithPadding { max_length, tlvs }); |
| 288 | + |
| 289 | + utils::construct_blinded_hops(secp_ctx, pks, length_tlvs, session_priv) |
282 | 290 | } |
283 | 291 |
|
284 | 292 | // Advance the blinded onion payment path by one hop, so make the second hop into the new |
|
0 commit comments