Skip to content

Commit a5b7cf2

Browse files
Move blinded path util into blinded_path::utils
This way it can be more easily reused for blinded payment paths.
1 parent 4fb5708 commit a5b7cf2

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::sign::{EntropySource, NodeSigner, Recipient};
1717
use crate::onion_message::ControlTlvs;
1818
use crate::ln::msgs::DecodeError;
1919
use crate::ln::onion_utils;
20-
use crate::util::chacha20poly1305rfc::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter};
21-
use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Readable, VecWriter, Writeable, Writer};
20+
use crate::util::chacha20poly1305rfc::ChaChaPolyReadAdapter;
21+
use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Readable, Writeable, Writer};
2222

2323
use core::mem;
2424
use core::ops::Deref;
@@ -124,7 +124,7 @@ fn blinded_message_hops<T: secp256k1::Signing + secp256k1::Verification>(
124124
};
125125
blinded_hops.push(BlindedHop {
126126
blinded_node_id: prev_blinded_node_id,
127-
encrypted_payload: encrypt_payload(payload, prev_ss),
127+
encrypted_payload: utils::encrypt_payload(payload, prev_ss),
128128
});
129129
} else { debug_assert!(false); }
130130
}
@@ -135,21 +135,13 @@ fn blinded_message_hops<T: secp256k1::Signing + secp256k1::Verification>(
135135
let final_payload = ReceiveTlvs { path_id: None };
136136
blinded_hops.push(BlindedHop {
137137
blinded_node_id: final_blinded_node_id,
138-
encrypted_payload: encrypt_payload(final_payload, final_ss),
138+
encrypted_payload: utils::encrypt_payload(final_payload, final_ss),
139139
});
140140
} else { debug_assert!(false) }
141141

142142
Ok(blinded_hops)
143143
}
144144

145-
/// Encrypt TLV payload to be used as a [`BlindedHop::encrypted_payload`].
146-
fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8; 32]) -> Vec<u8> {
147-
let mut writer = VecWriter(Vec::new());
148-
let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_ss, &payload);
149-
write_adapter.write(&mut writer).expect("In-memory writes cannot fail");
150-
writer.0
151-
}
152-
153145
impl Writeable for BlindedPath {
154146
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
155147
self.introduction_node_id.write(w)?;

lightning/src/blinded_path/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
1818
use super::BlindedPath;
1919
use crate::ln::onion_utils;
2020
use crate::onion_message::Destination;
21+
use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter;
22+
use crate::util::ser::{VecWriter, Writeable};
2123

2224
use crate::prelude::*;
2325

@@ -96,3 +98,12 @@ pub(crate) fn construct_keys_callback<T: secp256k1::Signing + secp256k1::Verific
9698
}
9799
Ok(())
98100
}
101+
102+
/// Encrypt TLV payload to be used as a [`crate::blinded_path::BlindedHop::encrypted_payload`].
103+
pub(super) fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8; 32]) -> Vec<u8> {
104+
let mut writer = VecWriter(Vec::new());
105+
let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_ss, &payload);
106+
write_adapter.write(&mut writer).expect("In-memory writes cannot fail");
107+
writer.0
108+
}
109+

0 commit comments

Comments
 (0)