mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Move blinded path util into blinded_path::utils
This way it can be more easily reused for blinded payment paths.
This commit is contained in:
parent
4fb5708eec
commit
a5b7cf2c69
2 changed files with 15 additions and 12 deletions
|
@ -17,8 +17,8 @@ use crate::sign::{EntropySource, NodeSigner, Recipient};
|
|||
use crate::onion_message::ControlTlvs;
|
||||
use crate::ln::msgs::DecodeError;
|
||||
use crate::ln::onion_utils;
|
||||
use crate::util::chacha20poly1305rfc::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter};
|
||||
use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Readable, VecWriter, Writeable, Writer};
|
||||
use crate::util::chacha20poly1305rfc::ChaChaPolyReadAdapter;
|
||||
use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Readable, Writeable, Writer};
|
||||
|
||||
use core::mem;
|
||||
use core::ops::Deref;
|
||||
|
@ -124,7 +124,7 @@ fn blinded_message_hops<T: secp256k1::Signing + secp256k1::Verification>(
|
|||
};
|
||||
blinded_hops.push(BlindedHop {
|
||||
blinded_node_id: prev_blinded_node_id,
|
||||
encrypted_payload: encrypt_payload(payload, prev_ss),
|
||||
encrypted_payload: utils::encrypt_payload(payload, prev_ss),
|
||||
});
|
||||
} else { debug_assert!(false); }
|
||||
}
|
||||
|
@ -135,21 +135,13 @@ fn blinded_message_hops<T: secp256k1::Signing + secp256k1::Verification>(
|
|||
let final_payload = ReceiveTlvs { path_id: None };
|
||||
blinded_hops.push(BlindedHop {
|
||||
blinded_node_id: final_blinded_node_id,
|
||||
encrypted_payload: encrypt_payload(final_payload, final_ss),
|
||||
encrypted_payload: utils::encrypt_payload(final_payload, final_ss),
|
||||
});
|
||||
} else { debug_assert!(false) }
|
||||
|
||||
Ok(blinded_hops)
|
||||
}
|
||||
|
||||
/// Encrypt TLV payload to be used as a [`BlindedHop::encrypted_payload`].
|
||||
fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8; 32]) -> Vec<u8> {
|
||||
let mut writer = VecWriter(Vec::new());
|
||||
let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_ss, &payload);
|
||||
write_adapter.write(&mut writer).expect("In-memory writes cannot fail");
|
||||
writer.0
|
||||
}
|
||||
|
||||
impl Writeable for BlindedPath {
|
||||
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
|
||||
self.introduction_node_id.write(w)?;
|
||||
|
|
|
@ -18,6 +18,8 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
|
|||
use super::BlindedPath;
|
||||
use crate::ln::onion_utils;
|
||||
use crate::onion_message::Destination;
|
||||
use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter;
|
||||
use crate::util::ser::{VecWriter, Writeable};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -96,3 +98,12 @@ pub(crate) fn construct_keys_callback<T: secp256k1::Signing + secp256k1::Verific
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Encrypt TLV payload to be used as a [`crate::blinded_path::BlindedHop::encrypted_payload`].
|
||||
pub(super) fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8; 32]) -> Vec<u8> {
|
||||
let mut writer = VecWriter(Vec::new());
|
||||
let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_ss, &payload);
|
||||
write_adapter.write(&mut writer).expect("In-memory writes cannot fail");
|
||||
writer.0
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue