From efed905a4f90a3ca86b08cd6fb111e7c790ce20d Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 15 Mar 2023 21:56:57 -0400 Subject: [PATCH] Move blinded_path and its utils into a new module --- fuzz/src/invoice_request_deser.rs | 2 +- fuzz/src/refund_deser.rs | 2 +- .../blinded_path.rs => blinded_path/mod.rs} | 5 +++-- lightning/src/{onion_message => blinded_path}/utils.rs | 6 +++--- lightning/src/lib.rs | 1 + lightning/src/offers/invoice.rs | 6 +++--- lightning/src/offers/invoice_request.rs | 2 +- lightning/src/offers/offer.rs | 6 +++--- lightning/src/offers/refund.rs | 6 +++--- lightning/src/offers/test_utils.rs | 2 +- lightning/src/onion_message/functional_tests.rs | 3 ++- lightning/src/onion_message/messenger.rs | 6 +++--- lightning/src/onion_message/mod.rs | 7 ++----- lightning/src/onion_message/packet.rs | 8 ++++---- 14 files changed, 31 insertions(+), 31 deletions(-) rename lightning/src/{onion_message/blinded_path.rs => blinded_path/mod.rs} (99%) rename lightning/src/{onion_message => blinded_path}/utils.rs (96%) diff --git a/fuzz/src/invoice_request_deser.rs b/fuzz/src/invoice_request_deser.rs index aa3045ccb..5239c1e79 100644 --- a/fuzz/src/invoice_request_deser.rs +++ b/fuzz/src/invoice_request_deser.rs @@ -10,13 +10,13 @@ use bitcoin::secp256k1::{KeyPair, Parity, PublicKey, Secp256k1, SecretKey, self}; use crate::utils::test_logger; use core::convert::{Infallible, TryFrom}; +use lightning::blinded_path::BlindedPath; use lightning::chain::keysinterface::EntropySource; use lightning::ln::PaymentHash; use lightning::ln::features::BlindedHopFeatures; use lightning::offers::invoice::{BlindedPayInfo, UnsignedInvoice}; use lightning::offers::invoice_request::InvoiceRequest; use lightning::offers::parse::SemanticError; -use lightning::onion_message::BlindedPath; use lightning::util::ser::Writeable; #[inline] diff --git a/fuzz/src/refund_deser.rs b/fuzz/src/refund_deser.rs index 9adaa3e95..fab303050 100644 --- a/fuzz/src/refund_deser.rs +++ b/fuzz/src/refund_deser.rs @@ -10,13 +10,13 @@ use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey, self}; use crate::utils::test_logger; use core::convert::{Infallible, TryFrom}; +use lightning::blinded_path::BlindedPath; use lightning::chain::keysinterface::EntropySource; use lightning::ln::PaymentHash; use lightning::ln::features::BlindedHopFeatures; use lightning::offers::invoice::{BlindedPayInfo, UnsignedInvoice}; use lightning::offers::parse::SemanticError; use lightning::offers::refund::Refund; -use lightning::onion_message::BlindedPath; use lightning::util::ser::Writeable; #[inline] diff --git a/lightning/src/onion_message/blinded_path.rs b/lightning/src/blinded_path/mod.rs similarity index 99% rename from lightning/src/onion_message/blinded_path.rs rename to lightning/src/blinded_path/mod.rs index 946e5e7cf..a4128d6a3 100644 --- a/lightning/src/onion_message/blinded_path.rs +++ b/lightning/src/blinded_path/mod.rs @@ -9,13 +9,14 @@ //! Creating blinded paths and related utilities live here. +pub(crate) mod utils; + use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey}; use crate::chain::keysinterface::{EntropySource, NodeSigner, Recipient}; -use super::packet::ControlTlvs; -use super::utils; +use crate::onion_message::ControlTlvs; use crate::ln::msgs::DecodeError; use crate::ln::onion_utils; use crate::util::chacha20poly1305rfc::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter}; diff --git a/lightning/src/onion_message/utils.rs b/lightning/src/blinded_path/utils.rs similarity index 96% rename from lightning/src/onion_message/utils.rs rename to lightning/src/blinded_path/utils.rs index ae9e0a7f6..1993ad932 100644 --- a/lightning/src/onion_message/utils.rs +++ b/lightning/src/blinded_path/utils.rs @@ -15,15 +15,15 @@ use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey, Scalar}; use bitcoin::secp256k1::ecdh::SharedSecret; +use super::BlindedPath; use crate::ln::onion_utils; -use super::blinded_path::BlindedPath; -use super::messenger::Destination; +use crate::onion_message::Destination; use crate::prelude::*; // TODO: DRY with onion_utils::construct_onion_keys_callback #[inline] -pub(super) fn construct_keys_callback, Option>)>( secp_ctx: &Secp256k1, unblinded_path: &[PublicKey], destination: Option, session_priv: &SecretKey, mut callback: FType diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index ad16914c3..668f752e6 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -81,6 +81,7 @@ pub mod ln; pub mod offers; pub mod routing; pub mod onion_message; +pub mod blinded_path; pub mod events; #[cfg(feature = "std")] diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index b2717f733..5c3148008 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -29,7 +29,7 @@ //! //! # use lightning::ln::PaymentHash; //! # use lightning::offers::invoice::BlindedPayInfo; -//! # use lightning::onion_message::BlindedPath; +//! # use lightning::blinded_path::BlindedPath; //! # //! # fn create_payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> { unimplemented!() } //! # fn create_payment_hash() -> PaymentHash { unimplemented!() } @@ -104,6 +104,7 @@ use bitcoin::util::schnorr::TweakedPublicKey; use core::convert::{Infallible, TryFrom}; use core::time::Duration; use crate::io; +use crate::blinded_path::BlindedPath; use crate::ln::PaymentHash; use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures}; use crate::ln::inbound_payment::ExpandedKey; @@ -115,7 +116,6 @@ use crate::offers::parse::{ParseError, ParsedMessage, SemanticError}; use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef}; use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents}; use crate::offers::signer; -use crate::onion_message::BlindedPath; use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, SeekReadable, WithoutLength, Writeable, Writer}; use crate::prelude::*; @@ -926,6 +926,7 @@ mod tests { use bitcoin::util::schnorr::TweakedPublicKey; use core::convert::TryFrom; use core::time::Duration; + use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::chain::keysinterface::KeyMaterial; use crate::ln::features::Bolt12InvoiceFeatures; use crate::ln::inbound_payment::ExpandedKey; @@ -937,7 +938,6 @@ mod tests { use crate::offers::payer::PayerTlvStreamRef; use crate::offers::refund::RefundBuilder; use crate::offers::test_utils::*; - use crate::onion_message::{BlindedHop, BlindedPath}; use crate::util::ser::{BigSize, Iterable, Writeable}; trait ToBytes { diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 92fabd6fd..e8aeb2c82 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -60,6 +60,7 @@ use core::convert::{Infallible, TryFrom}; use core::ops::Deref; use crate::chain::keysinterface::EntropySource; use crate::io; +use crate::blinded_path::BlindedPath; use crate::ln::PaymentHash; use crate::ln::features::InvoiceRequestFeatures; use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce}; @@ -70,7 +71,6 @@ use crate::offers::offer::{Offer, OfferContents, OfferTlvStream, OfferTlvStreamR use crate::offers::parse::{ParseError, ParsedMessage, SemanticError}; use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef}; use crate::offers::signer::{Metadata, MetadataMaterial}; -use crate::onion_message::BlindedPath; use crate::util::ser::{HighZeroBytesDroppedBigSize, SeekReadable, WithoutLength, Writeable, Writer}; use crate::util::string::PrintableString; diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index d2918e809..2d25f8d22 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -27,7 +27,7 @@ //! use lightning::offers::parse::ParseError; //! use lightning::util::ser::{Readable, Writeable}; //! -//! # use lightning::onion_message::BlindedPath; +//! # use lightning::blinded_path::BlindedPath; //! # #[cfg(feature = "std")] //! # use std::time::SystemTime; //! # @@ -76,6 +76,7 @@ use core::str::FromStr; use core::time::Duration; use crate::chain::keysinterface::EntropySource; use crate::io; +use crate::blinded_path::BlindedPath; use crate::ln::features::OfferFeatures; use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce}; use crate::ln::msgs::MAX_VALUE_MSAT; @@ -83,7 +84,6 @@ use crate::offers::invoice_request::{DerivedPayerId, ExplicitPayerId, InvoiceReq use crate::offers::merkle::TlvStream; use crate::offers::parse::{Bech32Encode, ParseError, ParsedMessage, SemanticError}; use crate::offers::signer::{Metadata, MetadataMaterial, self}; -use crate::onion_message::BlindedPath; use crate::util::ser::{HighZeroBytesDroppedBigSize, WithoutLength, Writeable, Writer}; use crate::util::string::PrintableString; @@ -832,13 +832,13 @@ mod tests { use core::convert::TryFrom; use core::num::NonZeroU64; use core::time::Duration; + use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::chain::keysinterface::KeyMaterial; use crate::ln::features::OfferFeatures; use crate::ln::inbound_payment::ExpandedKey; use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT}; use crate::offers::parse::{ParseError, SemanticError}; use crate::offers::test_utils::*; - use crate::onion_message::{BlindedHop, BlindedPath}; use crate::util::ser::{BigSize, Writeable}; use crate::util::string::PrintableString; diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index f677a2a9c..1aa36167b 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -32,7 +32,7 @@ //! use lightning::offers::refund::{Refund, RefundBuilder}; //! use lightning::util::ser::{Readable, Writeable}; //! -//! # use lightning::onion_message::BlindedPath; +//! # use lightning::blinded_path::BlindedPath; //! # #[cfg(feature = "std")] //! # use std::time::SystemTime; //! # @@ -80,6 +80,7 @@ use core::str::FromStr; use core::time::Duration; use crate::chain::keysinterface::EntropySource; use crate::io; +use crate::blinded_path::BlindedPath; use crate::ln::PaymentHash; use crate::ln::features::InvoiceRequestFeatures; use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce}; @@ -90,7 +91,6 @@ use crate::offers::offer::{OfferTlvStream, OfferTlvStreamRef}; use crate::offers::parse::{Bech32Encode, ParseError, ParsedMessage, SemanticError}; use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef}; use crate::offers::signer::{Metadata, MetadataMaterial, self}; -use crate::onion_message::BlindedPath; use crate::util::ser::{SeekReadable, WithoutLength, Writeable, Writer}; use crate::util::string::PrintableString; @@ -697,6 +697,7 @@ mod tests { use bitcoin::secp256k1::{KeyPair, Secp256k1, SecretKey}; use core::convert::TryFrom; use core::time::Duration; + use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::chain::keysinterface::KeyMaterial; use crate::ln::features::{InvoiceRequestFeatures, OfferFeatures}; use crate::ln::inbound_payment::ExpandedKey; @@ -706,7 +707,6 @@ mod tests { use crate::offers::parse::{ParseError, SemanticError}; use crate::offers::payer::PayerTlvStreamRef; use crate::offers::test_utils::*; - use crate::onion_message::{BlindedHop, BlindedPath}; use crate::util::ser::{BigSize, Writeable}; use crate::util::string::PrintableString; diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index 43664079d..8ded4a66e 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -13,11 +13,11 @@ use bitcoin::secp256k1::{KeyPair, Message, PublicKey, Secp256k1, SecretKey}; use bitcoin::secp256k1::schnorr::Signature; use core::convert::Infallible; use core::time::Duration; +use crate::blinded_path::{BlindedHop, BlindedPath}; use crate::chain::keysinterface::EntropySource; use crate::ln::PaymentHash; use crate::ln::features::BlindedHopFeatures; use crate::offers::invoice::BlindedPayInfo; -use crate::onion_message::{BlindedHop, BlindedPath}; pub(super) fn payer_keys() -> KeyPair { let secp_ctx = Secp256k1::new(); diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index 89582305c..df13aa2cb 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -9,10 +9,11 @@ //! Onion message testing and test utilities live here. +use crate::blinded_path::BlindedPath; use crate::chain::keysinterface::{NodeSigner, Recipient}; use crate::ln::features::InitFeatures; use crate::ln::msgs::{self, DecodeError, OnionMessageHandler}; -use super::{BlindedPath, CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError}; +use super::{CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError}; use crate::util::ser::{Writeable, Writer}; use crate::util::test_utils; diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index b9269c7cf..72b67dc92 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -15,16 +15,15 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey}; +use crate::blinded_path::{BlindedPath, ForwardTlvs, ReceiveTlvs, utils}; use crate::chain::keysinterface::{EntropySource, KeysManager, NodeSigner, Recipient}; use crate::events::OnionMessageProvider; use crate::ln::features::{InitFeatures, NodeFeatures}; use crate::ln::msgs::{self, OnionMessageHandler}; use crate::ln::onion_utils; use crate::ln::peer_handler::IgnoringMessageHandler; -use super::blinded_path::{BlindedPath, ForwardTlvs, ReceiveTlvs}; pub use super::packet::{CustomOnionMessageContents, OnionMessageContents}; use super::packet::{BIG_PACKET_HOP_DATA_LEN, ForwardControlTlvs, Packet, Payload, ReceiveControlTlvs, SMALL_PACKET_HOP_DATA_LEN}; -use super::utils; use crate::util::logger::Logger; use crate::util::ser::Writeable; @@ -43,9 +42,10 @@ use crate::prelude::*; /// # extern crate bitcoin; /// # use bitcoin::hashes::_export::_core::time::Duration; /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; +/// # use lightning::blinded_path::BlindedPath; /// # use lightning::chain::keysinterface::KeysManager; /// # use lightning::ln::peer_handler::IgnoringMessageHandler; -/// # use lightning::onion_message::{BlindedPath, CustomOnionMessageContents, Destination, OnionMessageContents, OnionMessenger}; +/// # use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents, OnionMessenger}; /// # use lightning::util::logger::{Logger, Record}; /// # use lightning::util::ser::{Writeable, Writer}; /// # use lightning::io; diff --git a/lightning/src/onion_message/mod.rs b/lightning/src/onion_message/mod.rs index e735b428e..713b83c62 100644 --- a/lightning/src/onion_message/mod.rs +++ b/lightning/src/onion_message/mod.rs @@ -18,16 +18,13 @@ //! information on its usage. //! //! [offers]: -//! [blinded paths]: crate::onion_message::BlindedPath +//! [blinded paths]: crate::blinded_path::BlindedPath -mod blinded_path; mod messenger; mod packet; -mod utils; #[cfg(test)] mod functional_tests; // Re-export structs so they can be imported with just the `onion_message::` module prefix. -pub use self::blinded_path::{BlindedPath, BlindedHop}; pub use self::messenger::{CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError, SimpleArcOnionMessenger, SimpleRefOnionMessenger}; -pub(crate) use self::packet::Packet; +pub(crate) use self::packet::{ControlTlvs, Packet}; diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index d22ff0682..2fb2407db 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -12,9 +12,9 @@ use bitcoin::secp256k1::PublicKey; use bitcoin::secp256k1::ecdh::SharedSecret; +use crate::blinded_path::{BlindedPath, ForwardTlvs, ReceiveTlvs}; use crate::ln::msgs::DecodeError; use crate::ln::onion_utils; -use super::blinded_path::{BlindedPath, ForwardTlvs, ReceiveTlvs}; use super::messenger::CustomOnionMessageHandler; use crate::util::chacha20poly1305rfc::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter}; use crate::util::ser::{BigSize, FixedLengthReader, LengthRead, LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer}; @@ -149,7 +149,7 @@ pub(super) enum ForwardControlTlvs { Blinded(Vec), /// If we're constructing an onion message hop through an intermediate unblinded node, we'll need /// to construct the intermediate hop's control TLVs in their unblinded state to avoid encoding - /// them into an intermediate Vec. See [`super::blinded_path::ForwardTlvs`] for more info. + /// them into an intermediate Vec. See [`crate::blinded_path::ForwardTlvs`] for more info. Unblinded(ForwardTlvs), } @@ -157,7 +157,7 @@ pub(super) enum ForwardControlTlvs { pub(super) enum ReceiveControlTlvs { /// See [`ForwardControlTlvs::Blinded`]. Blinded(Vec), - /// See [`ForwardControlTlvs::Unblinded`] and [`super::blinded_path::ReceiveTlvs`]. + /// See [`ForwardControlTlvs::Unblinded`] and [`crate::blinded_path::ReceiveTlvs`]. Unblinded(ReceiveTlvs), } @@ -255,7 +255,7 @@ impl ReadableArgs<(SharedSecret, &H)> for Payload< /// When reading a packet off the wire, we don't know a priori whether the packet is to be forwarded /// or received. Thus we read a ControlTlvs rather than reading a ForwardControlTlvs or /// ReceiveControlTlvs directly. -pub(super) enum ControlTlvs { +pub(crate) enum ControlTlvs { /// This onion message is intended to be forwarded. Forward(ForwardTlvs), /// This onion message is intended to be received. -- 2.39.5