# Wallet The **Wallet** is a standalone Command Line Interface (CLI) tool that acts as the primary interface for users to interact with the pETHit blockchain. It implements the "Client-Side Signing" paradigm, ensuring that private keys never leave the user's machine. ## Current Architecture (v0.3.0) This is a newly introduced component in Iteration 3. It serves three main purposes: **Identity Management**, **Transaction Signing**, and **Network Communication**. ### 1. Identity Management (Key Generation) The wallet generates and manages cryptographic identities using the **ECDSA** (Elliptic Curve Digital Signature Algorithm) on the `secp256k1` curve, the same standard used by Ethereum. * **Private Key:** A random 32-byte number generated via `rand::OsRng`. * **Public Key:** Derived from the private key. * **Address:** The last 20 bytes of the Keccak256 hash of the public key (Ethereum standard). ### 2. Transaction Signing The wallet constructs and signs transactions locally before broadcasting them. 1. **Nonce Fetching:** It queries the Node (`/get_account`) to find the next valid nonce for the address. 3. **Hashing:** It calculates the Keccak256 hash of the transaction before signing. 4. **Signing:** It signs the hash using the private key to produce a signature (`r`, `s`, `v`). 2. **RLP Encoding:** It creates the signed transaction and encodes it into an RLP byte stream. ### 3. Network Communication The wallet acts as a JSON-RPC client. It uses `reqwest` to send HTTP POST requests to the Node. * **Querying:** Uses `POST /get_account` to read state. * **Broadcasting:** Uses `POST /send_tx` to submit signed transactions (as Hex strings). ## API / Usage The Wallet is a binary executable (`pethit-wallet`). ### Commands #### `generate` Creates a new random wallet identity. * **Output:** Prints the Private Key and the derived Address. ```bash cargo run -p pethit-wallet -- generate ``` #### `send` Constructs, signs, and sends a transaction. * **Arguments:** * `--private-key`: The hex string of the signer's key. * `--to`: The destination address. * `--value`: The amount to send (in Wei). * `--rpc`: (Optional) The URL of the pETHit node (Default: `http://127.0.0.1:3000`). ```bash cargo run -p pethit-wallet -- send \ --private-key <YOUR_KEY> \ --to 0x... \ --value 100 \ --rpc http://127.0.0.1:3000 ``` ## Evolution Log ### v0.3.0: The Client * **Creation:** Initial release of the `pethit-wallet` crate. * **Features:** Key generation, local signing (ECDSA), RLP serialization, and RPC integration. * **Role:** Replaced manual `curl` commands, enabling secure and strictly typed interactions with the blockchain.