The svmai CLI tool will be a Rust application designed to help users manage Solana wallets. It will feature multi-threaded search for wallet files, validation of Solana private keys, secure storage of these keys using system keychain services, and a Text-based User Interface (TUI) for displaying balances and managing wallets. The tool will also support batch operations and token mixing functionalities.
The application will be structured into several core modules:
- Parses command-line arguments (e.g., search path, operation to perform).
- Initializes other modules.
- Launches the TUI or executes direct commands.
- Handles top-level error management and logging.
- Responsibility: Locates potential Solana wallet files (
.json). - Functionality:
- Takes a directory path as input.
- Recursively searches for
.jsonfiles. - Implements multi-threading for efficient searching in large directories.
- Returns a list of found file paths.
- Dependencies: Rust standard library for file system operations (
std::fs,std::path), potentiallyrayonfor easy parallelism.
- Responsibility: Validates if a given JSON file contains a Solana private key.
- Functionality:
- Takes a file path as input.
- Reads and parses the JSON content (using
serde_json). - Checks if the JSON structure matches the expected format for a Solana private key (an array of 64 numbers, typically u8).
- Optionally, attempts to derive a public key to confirm validity (using
solana-sdk).
- Dependencies:
serde_json,solana-sdk.
- Responsibility: Manages the encrypted storage of validated private keys.
- Functionality:
- Uses the system's keychain (e.g., macOS Keychain, GNOME Keyring, Windows Credential Manager) via the
keyring-rscrate. - Encrypts the collection of private keys before storing them in a local configuration file (e.g.,
~/.config/svmai/config.enc). The master key for this file encryption will be stored in the system keychain. - Provides functions to add, retrieve, update, and delete private keys from the secure store.
- Handles keychain access permissions and errors gracefully.
- Uses the system's keychain (e.g., macOS Keychain, GNOME Keyring, Windows Credential Manager) via the
- Dependencies:
keyring-rs, cryptographic libraries (e.g.,aes-gcmor similar fromrust-cryptoorring) for file encryption ifkeyring-rsonly stores a master key.
- Responsibility: Provides high-level functions for managing wallets.
- Functionality:
- Interacts with
secure_storageto access private keys. - Interacts with
solana_clientto fetch balances (SOL and SPL tokens). - Implements logic for batch sending of tokens.
- Implements logic for token mixing operations (details to be further defined based on user needs for privacy/rebalancing).
- Manages wallet metadata (e.g., user-defined aliases for wallets).
- Interacts with
- Dependencies:
secure_storagemodule,solana-sdk,solana-client(or Moralis API via HTTP client if chosen for balance/token data).
- Responsibility: Provides the Text-based User Interface.
- Functionality:
- Uses a TUI library like
ratatui. - Displays a list of managed wallets and their balances.
- Allows users to navigate and select operations (e.g., view details, send, mix).
- Handles user input and updates the display accordingly.
- Interacts with
wallet_managerto perform actions and retrieve data.
- Uses a TUI library like
- Dependencies:
ratatui,wallet_managermodule.
- Responsibility: Manages application configuration (excluding sensitive private keys).
- Functionality:
- Handles settings like default search paths, TUI preferences, RPC endpoint for Solana.
- Stores configuration in a plain text file (e.g.,
~/.config/svmai/settings.toml).
- Dependencies:
serde(for serialization/deserialization),toml.
- Responsibility: Handles all direct communication with the Solana blockchain.
- Functionality:
- Connecting to a Solana RPC node (configurable).
- Fetching SOL and SPL token balances for a given public key.
- Constructing and sending transactions (e.g., for token transfers, batch sends).
- Querying token metadata if needed.
- Dependencies:
solana-sdk,solana-client,spl-token.
public_key: String(Base58 encoded Solana public key)private_key_ref: String(Identifier or path to retrieve the actual private key fromsecure_storage- the private key itself is not stored here in plain text if this structure is persisted outside secure storage)alias: Option<String>(User-defined name for the wallet)balance_sol: Option<u64>(Lamports)token_balances: Option<Vec<TokenBalance>>
mint_address: Stringtoken_symbol: Stringbalance: u64(Raw amount, considering decimals)decimals: u8ui_balance: f64(User-friendly balance)
rpc_url: String(e.g., "https://api.mainnet-beta.solana.com")default_search_path: Option<String>tui_theme: Option<String>
- A collection (e.g., a
HashMap<PublicKeyString, EncryptedPrivateKeyString>) of private keys, where each private key is encrypted. This entire collection would then be encrypted by a master key stored in the system keychain before being written to a file.
- User runs
svmai find /path/to/wallets. maincallsfile_searcherto get all.jsonfiles.- For each file,
maincallskey_validator. - If valid,
main(orwallet_manager) prompts user if they want to add it tosvmai. - If yes,
maincallssecure_storageto encrypt and save the private key, associating it with its public key.
- User runs
svmai(no arguments, defaults to TUI). mainlaunchestui_interface.tui_interfacecallswallet_managerto get a list ofWalletInfo(public keys and aliases).- For each wallet,
wallet_manager(usingsolana_interaction) fetches balances. tui_interfacedisplays the wallets and balances.
- User selects "Batch Send" in TUI or uses a command like
svmai batch-send --from <wallet_alias_or_pubkey> --config <batch_send_config_file.csv>. tui_interfaceormaincollects parameters and callswallet_manager.wallet_managerretrieves the private key for the source wallet fromsecure_storage.wallet_manager(usingsolana_interaction) constructs and sends the batch transactions.
- Each module will return
Result<T, E>for fallible operations. - Custom error types will be defined for different modules (e.g.,
FileSearchError,KeyValidationError,SecureStorageError,SolanaRpcError). - The
mainmodule andtui_interfacewill be responsible for presenting user-friendly error messages. - Logging (e.g., using the
logcrate withenv_loggeror similar) will be implemented for debugging.
- Private Key Handling: Private keys are the most sensitive data. They should only be held in memory in decrypted form for the shortest time necessary to sign a transaction. The
secure_storagemodule is critical. - Keychain Access: The tool must clearly inform the user when it needs to access the keychain and why.
- Dependencies: Audit third-party crates for security vulnerabilities, especially those dealing with cryptography and blockchain interactions.
- Input Validation: All user inputs (paths, addresses, amounts) must be rigorously validated.
This architectural design provides a high-level overview. Details for each module and their interactions will be further refined during the implementation phase.