diff --git a/api/src/owner.rs b/api/src/owner.rs index 2c5215c7..d8e69e72 100644 --- a/api/src/owner.rs +++ b/api/src/owner.rs @@ -31,7 +31,7 @@ use crate::libwallet::api_impl::{owner, owner_updater}; use crate::libwallet::contract::types::{ ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI, }; -use crate::libwallet::mwmixnet::types::{MixnetReqCreationParams, SwapReq}; +use crate::libwallet::mwixnet::types::{MixnetReqCreationParams, SwapReq}; use crate::libwallet::{ AcctPathMapping, BuiltOutput, Error, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeHeightResult, OutputCommitMapping, PaymentProof, Slate, Slatepack, SlatepackAddress, @@ -831,7 +831,7 @@ where } /// Create MXMixnet request - pub fn create_mwmixnet_req( + pub fn create_mwixnet_req( &self, keychain_mask: Option<&SecretKey>, params: &MixnetReqCreationParams, @@ -840,7 +840,7 @@ where ) -> Result { let mut w_lock = self.wallet_inst.lock(); let w = w_lock.lc_provider()?.wallet_inst()?; - owner::create_mwmixnet_req(&mut **w, keychain_mask, params, slate) + owner::create_mwixnet_req(&mut **w, keychain_mask, params, slate) } /// Processes an invoice tranaction created by another party, essentially diff --git a/controller/tests/contract_srs_mwmixnet.rs b/controller/tests/contract_srs_mwmixnet.rs index 8643eb10..fb66a759 100644 --- a/controller/tests/contract_srs_mwmixnet.rs +++ b/controller/tests/contract_srs_mwmixnet.rs @@ -22,8 +22,8 @@ use grin_wallet_libwallet as libwallet; use impls::test_framework::{self}; use libwallet::contract::my_fee_contribution; use libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI}; -use libwallet::mwmixnet::onion::crypto::secp; -use libwallet::mwmixnet::types::MixnetReqCreationParams; +use libwallet::mwixnet::onion::crypto::secp; +use libwallet::mwixnet::types::MixnetReqCreationParams; use libwallet::{Slate, SlateState, TxLogEntryType}; use std::sync::atomic::Ordering; use std::thread; @@ -33,8 +33,8 @@ use std::time::Duration; mod common; use common::{clean_output_dir, create_wallets, setup}; -/// contract SRS flow - just creating an mwmixnet tx at the moment -fn contract_srs_mwmixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { +/// contract SRS flow - just creating an mwixnet tx at the moment +fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // create two wallets and mine 4 blocks in each (we want both to have balance to get a payjoin) let (wallets, chain, stopper, mut bh) = create_wallets(vec![vec![("default", 4)], vec![("default", 4)]], test_dir).unwrap(); @@ -89,7 +89,7 @@ fn contract_srs_mwmixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet server_keys: vec![server_key_1, server_key_2], fee_per_hop: 50_000_000, }; - //api.create_mwmixnet_req(send_mask, ¶ms, &slate)?; + //api.create_mwixnet_req(send_mask, ¶ms, &slate)?; Ok(()) })?; @@ -147,10 +147,10 @@ fn contract_srs_mwmixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet } #[test] -fn wallet_contract_srs_mwmixnet_tx() -> Result<(), libwallet::Error> { - let test_dir = "test_output/contract_srs_mwmixnet_tx"; +fn wallet_contract_srs_mwixnet_tx() -> Result<(), libwallet::Error> { + let test_dir = "test_output/contract_srs_mwixnet_tx"; setup(test_dir); - contract_srs_mwmixnet_tx_impl(test_dir)?; + contract_srs_mwixnet_tx_impl(test_dir)?; clean_output_dir(test_dir); Ok(()) } diff --git a/libwallet/Cargo.toml b/libwallet/Cargo.toml index b5251292..31390caa 100644 --- a/libwallet/Cargo.toml +++ b/libwallet/Cargo.toml @@ -42,7 +42,7 @@ grin_wallet_config = { path = "../config", version = "5.4.0-contracts.0" } grin_secp256k1zkp = { version = "0.7.12", features = ["bullet-proof-sizing"]} -#mwmixnet onion +#mwixnet onion chacha20 = "0.8.1" hmac = { version = "0.12.0", features = ["std"]} diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index baaf6bef..5f9f743e 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -30,8 +30,8 @@ use crate::util::{OnionV3Address, OnionV3AddressError}; use crate::api_impl::owner_updater::StatusMessage; use crate::contract::types::{ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI}; use crate::grin_keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmentType}; -use crate::mwmixnet::onion::create_onion; -use crate::mwmixnet::types::{ +use crate::mwixnet::onion::create_onion; +use crate::mwixnet::types::{ add_excess, new_hop, random_secret, ComSignature, Hop, MixnetReqCreationParams, SwapReq, }; @@ -1604,7 +1604,7 @@ where } /// Create MXMixnet request -pub fn create_mwmixnet_req<'a, T: ?Sized, C, K>( +pub fn create_mwixnet_req<'a, T: ?Sized, C, K>( w: &mut T, keychain_mask: Option<&SecretKey>, params: &MixnetReqCreationParams, diff --git a/libwallet/src/error.rs b/libwallet/src/error.rs index 4c33c056..a3bc15ca 100644 --- a/libwallet/src/error.rs +++ b/libwallet/src/error.rs @@ -67,11 +67,11 @@ pub enum Error { /// Comsig error #[error("Comsig error: {0}")] - ComSig(#[from] crate::mwmixnet::onion::crypto::comsig::ComSigError), + ComSig(#[from] crate::mwixnet::onion::crypto::comsig::ComSigError), - /// MwMixnet Onion error + /// mwixnet Onion error #[error("Onion error: {0}")] - Onion(#[from] crate::mwmixnet::onion::onion::OnionError), + Onion(#[from] crate::mwixnet::onion::onion::OnionError), /// Callback implementation error conversion #[error("Trait Implementation error")] diff --git a/libwallet/src/lib.rs b/libwallet/src/lib.rs index de17e05f..eeff7058 100644 --- a/libwallet/src/lib.rs +++ b/libwallet/src/lib.rs @@ -52,7 +52,7 @@ mod slate; pub mod slate_versions; pub mod slatepack; -pub mod mwmixnet; +pub mod mwixnet; mod types; pub use crate::error::Error; diff --git a/libwallet/src/mwmixnet/mod.rs b/libwallet/src/mwixnet/mod.rs similarity index 100% rename from libwallet/src/mwmixnet/mod.rs rename to libwallet/src/mwixnet/mod.rs diff --git a/libwallet/src/mwmixnet/onion/crypto/comsig.rs b/libwallet/src/mwixnet/onion/crypto/comsig.rs similarity index 97% rename from libwallet/src/mwmixnet/onion/crypto/comsig.rs rename to libwallet/src/mwixnet/onion/crypto/comsig.rs index 69b3d31d..50736129 100644 --- a/libwallet/src/mwmixnet/onion/crypto/comsig.rs +++ b/libwallet/src/mwixnet/onion/crypto/comsig.rs @@ -33,10 +33,8 @@ pub struct ComSignature { /// Error types for Commitment Signatures #[derive(Error, Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] pub enum ComSigError { - /// Invalid com sig #[error("Commitment signature is invalid")] InvalidSig, - /// SECP Error Wrapper #[error("Secp256k1zkp error: {0:?}")] Secp256k1zkp(secp256k1zkp::Error), } @@ -48,7 +46,6 @@ impl From for ComSigError { } impl ComSignature { - /// Create new Com signature from commit and keys pub fn new(pub_nonce: &Commitment, s: &SecretKey, t: &SecretKey) -> ComSignature { ComSignature { pub_nonce: pub_nonce.to_owned(), @@ -58,7 +55,6 @@ impl ComSignature { } #[allow(dead_code)] - /// Sign com signature with kernel values pub fn sign( amount: u64, blind: &SecretKey, @@ -92,7 +88,6 @@ impl ComSignature { } #[allow(non_snake_case)] - /// Verify a com sig pub fn verify(&self, commit: &Commitment, msg: &Vec) -> Result<(), ComSigError> { let secp = Secp256k1::with_caps(ContextFlag::Commit); diff --git a/libwallet/src/mwmixnet/onion/crypto/dalek.rs b/libwallet/src/mwixnet/onion/crypto/dalek.rs similarity index 98% rename from libwallet/src/mwmixnet/onion/crypto/dalek.rs rename to libwallet/src/mwixnet/onion/crypto/dalek.rs index a8b4f588..8988157d 100644 --- a/libwallet/src/mwmixnet/onion/crypto/dalek.rs +++ b/libwallet/src/mwixnet/onion/crypto/dalek.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Dalek key wrapper for mwmixnet primitives +//! Dalek key wrapper for mwixnet primitives use super::secp::SecretKey; @@ -183,7 +183,7 @@ pub fn sign(sk: &SecretKey, message: &[u8]) -> Result; -/// Wrap u8 vec +/// Raw bytes alias pub type RawBytes = Vec; const CURRENT_ONION_VERSION: u8 = 0; @@ -75,24 +76,24 @@ impl Hash for Onion { /// A single, decrypted/peeled layer of an Onion. #[derive(Debug, Clone)] pub struct Payload { - /// next ephemeral pk + /// PK of next server pub next_ephemeral_pk: xPublicKey, - /// excess + /// Excess calculation pub excess: SecretKey, - /// fee + /// Fee pub fee: FeeFields, - /// proof + /// Rangeproof pub rangeproof: Option, } impl Payload { - /// Deser a payload + /// Deserialize pub fn deserialize(bytes: &Vec) -> Result { let payload: Payload = ser::deserialize_default(&mut &bytes[..])?; Ok(payload) } - /// Serialize a payload + /// Serialize pub fn serialize(&self) -> Result, ser::Error> { let mut vec = vec![]; ser::serialize_default(&mut vec, &self)?; @@ -142,7 +143,7 @@ pub struct PeeledOnion { } impl Onion { - /// Serialize onion + /// Serialize to binary pub fn serialize(&self) -> Result, ser::Error> { let mut vec = vec![]; ser::serialize_default(&mut vec, &self)?; @@ -189,7 +190,7 @@ impl Onion { } } -/// Create new stream cypher from shared secret +/// Create a new stream cipher pub fn new_stream_cipher(shared_secret: &SharedSecret) -> Result { let mut mu_hmac = HmacSha256::new_from_slice(b"MWIXNET")?; mu_hmac.update(shared_secret.as_bytes()); @@ -329,19 +330,19 @@ pub enum OnionError { /// Invalid Key Length #[error("Invalid key length for MAC initialization")] InvalidKeyLength, - /// Serialization error + /// Serialization Error #[error("Serialization error occurred: {0:?}")] SerializationError(ser::Error), - /// Deserialization error + /// Deserialization Error #[error("Deserialization error occurred: {0:?}")] DeserializationError(ser::Error), /// Error calculating blinding factor #[error("Error calculating blinding factor: {0:?}")] CalcBlindError(secp256k1zkp::Error), - /// Error calculating ephemeral key + /// Error calculating ephemeral pubkey #[error("Error calculating ephemeral pubkey: {0:?}")] CalcPubKeyError(secp256k1zkp::Error), - /// Error calculating commitment + /// Error calculating commit #[error("Error calculating commitment: {0:?}")] CalcCommitError(secp256k1zkp::Error), } @@ -361,8 +362,8 @@ impl From for OnionError { #[cfg(test)] pub mod tests { use super::*; - use crate::mwmixnet::onion::crypto::secp::random_secret; - use crate::mwmixnet::onion::{new_hop, Hop}; + use crate::mwixnet::onion::crypto::secp::random_secret; + use crate::mwixnet::onion::{new_hop, Hop}; use grin_core::core::FeeFields; @@ -408,12 +409,12 @@ pub mod tests { hops.push(hop); } - let mut onion_packet = crate::mwmixnet::onion::create_onion(&commitment, &hops).unwrap(); + let mut onion_packet = crate::mwixnet::onion::create_onion(&commitment, &hops).unwrap(); let mut payload = Payload { next_ephemeral_pk: onion_packet.ephemeral_pubkey.clone(), excess: random_secret(), - fee: FeeFields::from(fee_per_hop as u32), + fee: FeeFields::from(fee_per_hop), rangeproof: None, }; for i in 0..5 { @@ -425,6 +426,6 @@ pub mod tests { assert!(payload.rangeproof.is_some()); assert_eq!(payload.rangeproof.unwrap(), hops[4].rangeproof.unwrap()); assert_eq!(secp::commit(out_value, &final_blind).unwrap(), final_commit); - assert_eq!(payload.fee, FeeFields::from(fee_per_hop as u32)); + assert_eq!(payload.fee, FeeFields::from(fee_per_hop)); } } diff --git a/libwallet/src/mwmixnet/onion/util.rs b/libwallet/src/mwixnet/onion/util.rs similarity index 95% rename from libwallet/src/mwmixnet/onion/util.rs rename to libwallet/src/mwixnet/onion/util.rs index 31495dd9..d5bbff07 100644 --- a/libwallet/src/mwmixnet/onion/util.rs +++ b/libwallet/src/mwixnet/onion/util.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Util fns for mwmixnet +//! Util fns for mwixnet //! TODO: possibly redundant, check or move elsewhere use grin_core::ser::{self, Readable, Reader, Writeable, Writer}; @@ -37,7 +37,7 @@ use std::convert::TryInto; /// # Example /// /// ``` -/// use grin_wallet_libwallet::mwmixnet::onion::util::write_optional; +/// use grin_wallet_libwallet::mwixnet::onion::util::write_optional; /// let mut writer:Vec = vec![]; /// let optional_value: Option = Some(10); /// //write_optional(&mut writer, &optional_value); @@ -75,7 +75,7 @@ pub fn write_optional( /// # Example /// /// ``` -/// use grin_wallet_libwallet::mwmixnet::onion::util::read_optional; +/// use grin_wallet_libwallet::mwixnet::onion::util::read_optional; /// use grin_core::ser::{BinReader, ProtocolVersion, DeserializationMode}; /// let mut buf: &[u8] = &[1, 0, 0, 0, 10]; /// let mut reader = BinReader::new(&mut buf, ProtocolVersion::local(), DeserializationMode::default()); @@ -106,7 +106,7 @@ pub fn read_optional(reader: &mut R) -> Result /// # Example /// /// ``` -/// use grin_wallet_libwallet::mwmixnet::onion::util::vec_to_array; +/// use grin_wallet_libwallet::mwixnet::onion::util::vec_to_array; /// let v = vec![0, 1, 2, 3, 4, 5]; /// let a = vec_to_array::<4>(&v).unwrap(); /// assert_eq!(a, [0, 1, 2, 3]); diff --git a/libwallet/src/mwmixnet/types.rs b/libwallet/src/mwixnet/types.rs similarity index 91% rename from libwallet/src/mwmixnet/types.rs rename to libwallet/src/mwixnet/types.rs index 7e62ed88..2339fa30 100644 --- a/libwallet/src/mwmixnet/types.rs +++ b/libwallet/src/mwixnet/types.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Types related to mwmixnet requests required by rest of lib crate apis +//! Types related to mwixnet requests required by rest of lib crate apis //! Should rexport all needed types here pub use super::onion::crypto::comsig::{self, ComSignature}; @@ -32,7 +32,7 @@ pub struct SwapReq { pub onion: Onion, } -/// MWMixnetRequest Creation Params +/// mwixnetRequest Creation Params pub struct MixnetReqCreationParams { /// List of all the server keys diff --git a/libwallet/src/types.rs b/libwallet/src/types.rs index 8b396259..27597da3 100644 --- a/libwallet/src/types.rs +++ b/libwallet/src/types.rs @@ -791,7 +791,7 @@ pub enum TxLogEntryType { TxReceivedCancelled, /// Sent transaction that was rolled back by user TxSentCancelled, - /// Self spend, as per contracts and mwmixnet + /// Self spend, as per contracts and mwixnet TxSelfSpend, /// Self Spend Cancelled (has to happen before sent to chain, flag rather than delete) TxSelfSpendCancelled,