diff --git a/Cargo.toml b/Cargo.toml index 0c62937..8e5a396 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,45 +11,42 @@ categories = ["os", "filesystem", "api-bindings"] readme = "README.md" [dependencies] -tera = "1.19.0" # Template engine for text rendering -# Cross-platform functionality -libc = "0.2" +anyhow = "1.0.98" +base64 = "0.21.0" # Base64 encoding/decoding cfg-if = "1.0" -thiserror = "1.0" # For error handling -redis = "0.22.0" # Redis client -postgres = "0.19.4" # PostgreSQL client -tokio-postgres = "0.7.8" # Async PostgreSQL client -postgres-types = "0.2.5" # PostgreSQL type conversions +chacha20poly1305 = "0.10.1" # ChaCha20Poly1305 AEAD cipher +clap = "2.33" # Command-line argument parsing +dirs = "5.0.1" # Directory paths +env_logger = "0.10.0" # Logger implementation +ethers = { version = "2.0.7", features = ["legacy"] } # Ethereum library +glob = "0.3.1" # For file pattern matching +jsonrpsee = "0.25.1" +k256 = { version = "0.13.1", features = ["ecdsa"] } # Elliptic curve cryptography lazy_static = "1.4.0" # For lazy initialization of static variables +libc = "0.2" +log = "0.4" # Logging facade +once_cell = "1.18.0" # Lazy static initialization +postgres = "0.19.4" # PostgreSQL client +postgres-types = "0.2.5" # PostgreSQL type conversions +r2d2 = "0.8.10" +r2d2_postgres = "0.18.2" +rand = "0.8.5" # Random number generation +redis = "0.22.0" # Redis client regex = "1.8.1" # For regex pattern matching +rhai = { version = "1.12.0", features = ["sync"] } # Embedded scripting language serde = { version = "1.0", features = [ "derive", ] } # For serialization/deserialization serde_json = "1.0" # For JSON handling -glob = "0.3.1" # For file pattern matching -tempfile = "3.5" # For temporary file operations -log = "0.4" # Logging facade -env_logger = "0.10.0" # Logger implementation -rhai = { version = "1.12.0", features = ["sync"] } # Embedded scripting language -rand = "0.8.5" # Random number generation -clap = "2.33" # Command-line argument parsing -r2d2 = "0.8.10" -r2d2_postgres = "0.18.2" - -# Crypto dependencies -base64 = "0.21.0" # Base64 encoding/decoding -k256 = { version = "0.13.1", features = ["ecdsa"] } # Elliptic curve cryptography -once_cell = "1.18.0" # Lazy static initialization sha2 = "0.10.7" # SHA-2 hash functions -chacha20poly1305 = "0.10.1" # ChaCha20Poly1305 AEAD cipher -ethers = { version = "2.0.7", features = ["legacy"] } # Ethereum library -dirs = "5.0.1" # Directory paths -uuid = { version = "1.16.0", features = ["v4"] } -tokio-test = "0.4.4" -zinit-client = { git = "https://github.com/threefoldtech/zinit", branch = "json_rpc", package = "zinit-client" } -anyhow = "1.0.98" -jsonrpsee = "0.25.1" +tempfile = "3.5" # For temporary file operations +tera = "1.19.0" # Template engine for text rendering +thiserror = "1.0" # For error handling tokio = "1.45.0" +tokio-postgres = "0.7.8" # Async PostgreSQL client +tokio-test = "0.4.4" +uuid = { version = "1.16.0", features = ["v4"] } +zinit-client = { git = "https://github.com/threefoldtech/zinit", branch = "json_rpc", package = "zinit-client" } # Optional features for specific OS functionality [target.'cfg(unix)'.dependencies] @@ -63,9 +60,9 @@ windows = { version = "0.48", features = [ ] } [dev-dependencies] +mockall = "0.11.4" # For mocking in tests tempfile = "3.5" # For tests that need temporary files/directories tokio = { version = "1.28", features = ["full", "test-util"] } # For async testing -mockall = "0.11.4" # For mocking in tests [[bin]] name = "herodo" diff --git a/src/lib.rs b/src/lib.rs index b922d9b..bc8cbdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,9 +46,7 @@ pub mod redisclient; pub mod rhai; pub mod text; pub mod virt; -pub mod hero_vault; -pub mod rhai; -pub mod cmd; +pub mod vault; pub mod zinit_client; // Version information diff --git a/src/rhai/hero_vault.rs b/src/rhai/hero_vault.rs index 7ccd9d4..66ffe26 100644 --- a/src/rhai/hero_vault.rs +++ b/src/rhai/hero_vault.rs @@ -11,8 +11,8 @@ use tokio::runtime::Runtime; use ethers::types::{Address, U256}; use std::str::FromStr; -use crate::hero_vault::{keypair, symmetric, ethereum}; -use crate::hero_vault::ethereum::{prepare_function_arguments, convert_token_to_rhai}; +use crate::vault::{keypair, symmetric, ethereum}; +use crate::vault::ethereum::{prepare_function_arguments, convert_token_to_rhai}; // Global Tokio runtime for blocking async operations static RUNTIME: Lazy> = Lazy::new(|| { diff --git a/src/hero_vault/README.md b/src/vault/README.md similarity index 100% rename from src/hero_vault/README.md rename to src/vault/README.md diff --git a/src/hero_vault/error.rs b/src/vault/error.rs similarity index 100% rename from src/hero_vault/error.rs rename to src/vault/error.rs diff --git a/src/hero_vault/ethereum/README.md b/src/vault/ethereum/README.md similarity index 100% rename from src/hero_vault/ethereum/README.md rename to src/vault/ethereum/README.md diff --git a/src/hero_vault/ethereum/contract.rs b/src/vault/ethereum/contract.rs similarity index 99% rename from src/hero_vault/ethereum/contract.rs rename to src/vault/ethereum/contract.rs index 7f0b224..5e8749e 100644 --- a/src/hero_vault/ethereum/contract.rs +++ b/src/vault/ethereum/contract.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use std::str::FromStr; use serde::{Serialize, Deserialize}; -use crate::hero_vault::error::CryptoError; +use crate::vault::error::CryptoError; use super::wallet::EthereumWallet; use super::networks::NetworkConfig; diff --git a/src/hero_vault/ethereum/contract_utils.rs b/src/vault/ethereum/contract_utils.rs similarity index 100% rename from src/hero_vault/ethereum/contract_utils.rs rename to src/vault/ethereum/contract_utils.rs diff --git a/src/hero_vault/ethereum/mod.rs b/src/vault/ethereum/mod.rs similarity index 100% rename from src/hero_vault/ethereum/mod.rs rename to src/vault/ethereum/mod.rs diff --git a/src/hero_vault/ethereum/networks.rs b/src/vault/ethereum/networks.rs similarity index 100% rename from src/hero_vault/ethereum/networks.rs rename to src/vault/ethereum/networks.rs diff --git a/src/hero_vault/ethereum/provider.rs b/src/vault/ethereum/provider.rs similarity index 95% rename from src/hero_vault/ethereum/provider.rs rename to src/vault/ethereum/provider.rs index fc7fcbd..145566a 100644 --- a/src/hero_vault/ethereum/provider.rs +++ b/src/vault/ethereum/provider.rs @@ -2,7 +2,7 @@ use ethers::prelude::*; -use crate::hero_vault::error::CryptoError; +use crate::vault::error::CryptoError; use super::networks::{self, NetworkConfig}; /// Creates a provider for a specific network. diff --git a/src/hero_vault/ethereum/storage.rs b/src/vault/ethereum/storage.rs similarity index 95% rename from src/hero_vault/ethereum/storage.rs rename to src/vault/ethereum/storage.rs index 52b6a8c..127d7b7 100644 --- a/src/hero_vault/ethereum/storage.rs +++ b/src/vault/ethereum/storage.rs @@ -4,7 +4,7 @@ use std::sync::Mutex; use std::collections::HashMap; use once_cell::sync::Lazy; -use crate::hero_vault::error::CryptoError; +use crate::vault::error::CryptoError; use super::wallet::EthereumWallet; use super::networks::{self, NetworkConfig}; @@ -16,7 +16,7 @@ static ETH_WALLETS: Lazy>>> = Lazy::ne /// Creates an Ethereum wallet from the currently selected keypair for a specific network. pub fn create_ethereum_wallet_for_network(network: NetworkConfig) -> Result { // Get the currently selected keypair - let keypair = crate::hero_vault::keypair::get_selected_keypair()?; + let keypair = crate::vault::keypair::get_selected_keypair()?; // Create an Ethereum wallet from the keypair let wallet = EthereumWallet::from_keypair(&keypair, network)?; @@ -77,7 +77,7 @@ pub fn clear_ethereum_wallets_for_network(network_name: &str) { /// Creates an Ethereum wallet from a name and the currently selected keypair for a specific network. pub fn create_ethereum_wallet_from_name_for_network(name: &str, network: NetworkConfig) -> Result { // Get the currently selected keypair - let keypair = crate::hero_vault::keypair::get_selected_keypair()?; + let keypair = crate::vault::keypair::get_selected_keypair()?; // Create an Ethereum wallet from the name and keypair let wallet = EthereumWallet::from_name_and_keypair(name, &keypair, network)?; diff --git a/src/hero_vault/ethereum/tests/contract_args_tests.rs b/src/vault/ethereum/tests/contract_args_tests.rs similarity index 97% rename from src/hero_vault/ethereum/tests/contract_args_tests.rs rename to src/vault/ethereum/tests/contract_args_tests.rs index a729b6f..b7cb76a 100644 --- a/src/hero_vault/ethereum/tests/contract_args_tests.rs +++ b/src/vault/ethereum/tests/contract_args_tests.rs @@ -3,7 +3,7 @@ use ethers::types::Address; use std::str::FromStr; -use crate::hero_vault::ethereum::*; +use crate::vault::ethereum::*; #[test] fn test_contract_creation() { diff --git a/src/hero_vault/ethereum/tests/contract_tests.rs b/src/vault/ethereum/tests/contract_tests.rs similarity index 98% rename from src/hero_vault/ethereum/tests/contract_tests.rs rename to src/vault/ethereum/tests/contract_tests.rs index 171e9e4..d37dde3 100644 --- a/src/hero_vault/ethereum/tests/contract_tests.rs +++ b/src/vault/ethereum/tests/contract_tests.rs @@ -3,7 +3,7 @@ use ethers::types::Address; use std::str::FromStr; -use crate::hero_vault::ethereum::*; +use crate::vault::ethereum::*; #[test] fn test_contract_creation() { diff --git a/src/hero_vault/ethereum/tests/mod.rs b/src/vault/ethereum/tests/mod.rs similarity index 100% rename from src/hero_vault/ethereum/tests/mod.rs rename to src/vault/ethereum/tests/mod.rs diff --git a/src/hero_vault/ethereum/tests/network_tests.rs b/src/vault/ethereum/tests/network_tests.rs similarity index 98% rename from src/hero_vault/ethereum/tests/network_tests.rs rename to src/vault/ethereum/tests/network_tests.rs index 9afab95..a66bd4a 100644 --- a/src/hero_vault/ethereum/tests/network_tests.rs +++ b/src/vault/ethereum/tests/network_tests.rs @@ -1,6 +1,6 @@ //! Tests for Ethereum network functionality. -use crate::hero_vault::ethereum::*; +use crate::vault::ethereum::*; #[test] fn test_network_config() { diff --git a/src/hero_vault/ethereum/tests/transaction_tests.rs b/src/vault/ethereum/tests/transaction_tests.rs similarity index 96% rename from src/hero_vault/ethereum/tests/transaction_tests.rs rename to src/vault/ethereum/tests/transaction_tests.rs index dd4dc1d..9202434 100644 --- a/src/hero_vault/ethereum/tests/transaction_tests.rs +++ b/src/vault/ethereum/tests/transaction_tests.rs @@ -1,7 +1,7 @@ //! Tests for Ethereum transaction functionality. -use crate::hero_vault::ethereum::*; -use crate::hero_vault::keypair::KeyPair; +use crate::vault::ethereum::*; +use crate::vault::keypair::KeyPair; use ethers::types::U256; use std::str::FromStr; diff --git a/src/hero_vault/ethereum/tests/wallet_tests.rs b/src/vault/ethereum/tests/wallet_tests.rs similarity index 96% rename from src/hero_vault/ethereum/tests/wallet_tests.rs rename to src/vault/ethereum/tests/wallet_tests.rs index 82e1f4b..44f9dd1 100644 --- a/src/hero_vault/ethereum/tests/wallet_tests.rs +++ b/src/vault/ethereum/tests/wallet_tests.rs @@ -1,7 +1,7 @@ //! Tests for Ethereum wallet functionality. -use crate::hero_vault::ethereum::*; -use crate::hero_vault::keypair::KeyPair; +use crate::vault::ethereum::*; +use crate::vault::keypair::KeyPair; use ethers::utils::hex; #[test] @@ -64,8 +64,8 @@ fn test_wallet_management() { clear_ethereum_wallets(); // Create a key space and keypair - crate::hero_vault::keypair::create_space("test_space").unwrap(); - crate::hero_vault::keypair::create_keypair("test_keypair3").unwrap(); + crate::vault::keypair::create_space("test_space").unwrap(); + crate::vault::keypair::create_keypair("test_keypair3").unwrap(); // Create wallets for different networks let gnosis_wallet = create_ethereum_wallet_for_network(networks::gnosis()).unwrap(); diff --git a/src/hero_vault/ethereum/transaction.rs b/src/vault/ethereum/transaction.rs similarity index 97% rename from src/hero_vault/ethereum/transaction.rs rename to src/vault/ethereum/transaction.rs index 7c1deb5..fd9deb6 100644 --- a/src/hero_vault/ethereum/transaction.rs +++ b/src/vault/ethereum/transaction.rs @@ -2,7 +2,7 @@ use ethers::prelude::*; -use crate::hero_vault::error::CryptoError; +use crate::vault::error::CryptoError; use super::wallet::EthereumWallet; use super::networks::NetworkConfig; diff --git a/src/hero_vault/ethereum/wallet.rs b/src/vault/ethereum/wallet.rs similarity index 97% rename from src/hero_vault/ethereum/wallet.rs rename to src/vault/ethereum/wallet.rs index ecb73eb..972a038 100644 --- a/src/hero_vault/ethereum/wallet.rs +++ b/src/vault/ethereum/wallet.rs @@ -7,8 +7,8 @@ use k256::ecdsa::SigningKey; use std::str::FromStr; use sha2::{Sha256, Digest}; -use crate::hero_vault::error::CryptoError; -use crate::hero_vault::keypair::KeyPair; +use crate::vault::error::CryptoError; +use crate::vault::keypair::KeyPair; use super::networks::NetworkConfig; /// An Ethereum wallet derived from a keypair. diff --git a/src/hero_vault/keypair/README.md b/src/vault/keypair/README.md similarity index 100% rename from src/hero_vault/keypair/README.md rename to src/vault/keypair/README.md diff --git a/src/hero_vault/keypair/implementation.rs b/src/vault/keypair/implementation.rs similarity index 98% rename from src/hero_vault/keypair/implementation.rs rename to src/vault/keypair/implementation.rs index edd35c6..ca118ca 100644 --- a/src/hero_vault/keypair/implementation.rs +++ b/src/vault/keypair/implementation.rs @@ -8,7 +8,7 @@ use once_cell::sync::Lazy; use std::sync::Mutex; use sha2::{Sha256, Digest}; -use crate::hero_vault::error::CryptoError; +use crate::vault::error::CryptoError; /// A keypair for signing and verifying messages. #[derive(Debug, Clone, Serialize, Deserialize)] @@ -226,7 +226,7 @@ impl KeyPair { }; // Encrypt the message using the derived key - let ciphertext = crate::hero_vault::symmetric::encrypt_with_key(&shared_secret, message) + let ciphertext = crate::vault::symmetric::encrypt_with_key(&shared_secret, message) .map_err(|e| CryptoError::EncryptionFailed(e.to_string()))?; // Format: ephemeral_public_key || ciphertext @@ -263,7 +263,7 @@ impl KeyPair { }; // Decrypt the message using the derived key - crate::hero_vault::symmetric::decrypt_with_key(&shared_secret, actual_ciphertext) + crate::vault::symmetric::decrypt_with_key(&shared_secret, actual_ciphertext) .map_err(|e| CryptoError::DecryptionFailed(e.to_string())) } } diff --git a/src/hero_vault/keypair/mod.rs b/src/vault/keypair/mod.rs similarity index 100% rename from src/hero_vault/keypair/mod.rs rename to src/vault/keypair/mod.rs diff --git a/src/hero_vault/kvs/README.md b/src/vault/kvs/README.md similarity index 100% rename from src/hero_vault/kvs/README.md rename to src/vault/kvs/README.md diff --git a/src/hero_vault/kvs/error.rs b/src/vault/kvs/error.rs similarity index 68% rename from src/hero_vault/kvs/error.rs rename to src/vault/kvs/error.rs index 039644e..5fcd15c 100644 --- a/src/hero_vault/kvs/error.rs +++ b/src/vault/kvs/error.rs @@ -45,18 +45,18 @@ impl From for KvsError { } } -impl From for crate::hero_vault::error::CryptoError { +impl From for crate::vault::error::CryptoError { fn from(err: KvsError) -> Self { - crate::hero_vault::error::CryptoError::SerializationError(err.to_string()) + crate::vault::error::CryptoError::SerializationError(err.to_string()) } } -impl From for KvsError { - fn from(err: crate::hero_vault::error::CryptoError) -> Self { +impl From for KvsError { + fn from(err: crate::vault::error::CryptoError) -> Self { match err { - crate::hero_vault::error::CryptoError::EncryptionFailed(msg) => KvsError::Encryption(msg), - crate::hero_vault::error::CryptoError::DecryptionFailed(msg) => KvsError::Decryption(msg), - crate::hero_vault::error::CryptoError::SerializationError(msg) => KvsError::Serialization(msg), + crate::vault::error::CryptoError::EncryptionFailed(msg) => KvsError::Encryption(msg), + crate::vault::error::CryptoError::DecryptionFailed(msg) => KvsError::Decryption(msg), + crate::vault::error::CryptoError::SerializationError(msg) => KvsError::Serialization(msg), _ => KvsError::Other(err.to_string()), } } diff --git a/src/hero_vault/kvs/mod.rs b/src/vault/kvs/mod.rs similarity index 100% rename from src/hero_vault/kvs/mod.rs rename to src/vault/kvs/mod.rs diff --git a/src/hero_vault/kvs/store.rs b/src/vault/kvs/store.rs similarity index 99% rename from src/hero_vault/kvs/store.rs rename to src/vault/kvs/store.rs index 6ea279f..2f8b8c6 100644 --- a/src/hero_vault/kvs/store.rs +++ b/src/vault/kvs/store.rs @@ -1,7 +1,7 @@ //! Implementation of a simple key-value store using the filesystem. -use crate::hero_vault::kvs::error::{KvsError, Result}; -use crate::hero_vault::symmetric; +use crate::vault::kvs::error::{KvsError, Result}; +use crate::vault::symmetric; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::collections::HashMap; use std::fs; diff --git a/src/hero_vault/mod.rs b/src/vault/mod.rs similarity index 100% rename from src/hero_vault/mod.rs rename to src/vault/mod.rs diff --git a/src/hero_vault/symmetric/README.md b/src/vault/symmetric/README.md similarity index 100% rename from src/hero_vault/symmetric/README.md rename to src/vault/symmetric/README.md diff --git a/src/hero_vault/symmetric/implementation.rs b/src/vault/symmetric/implementation.rs similarity index 98% rename from src/hero_vault/symmetric/implementation.rs rename to src/vault/symmetric/implementation.rs index 476470e..3b201d7 100644 --- a/src/hero_vault/symmetric/implementation.rs +++ b/src/vault/symmetric/implementation.rs @@ -6,8 +6,8 @@ use rand::{rngs::OsRng, RngCore}; use serde::{Serialize, Deserialize}; use sha2::{Sha256, Digest}; -use crate::hero_vault::error::CryptoError; -use crate::hero_vault::keypair::KeySpace; +use crate::vault::error::CryptoError; +use crate::vault::keypair::KeySpace; /// The size of the nonce in bytes. const NONCE_SIZE: usize = 12; diff --git a/src/hero_vault/symmetric/mod.rs b/src/vault/symmetric/mod.rs similarity index 100% rename from src/hero_vault/symmetric/mod.rs rename to src/vault/symmetric/mod.rs