A command-line cryptocurrency wallet application built in Rust that provides fundamental wallet operations using the secp256k1 elliptic curve cryptography (commonly used in Bitcoin and Ethereum).
- Key Generation: Generate secure secp256k1 private/public key pairs
- Address Creation: Create wallet addresses from public keys using SHA-256 hashing
- Message Signing: Sign messages with your private key for authentication
- Signature Verification: Verify message signatures to confirm authenticity
- User-Friendly CLI: Intuitive command-line interface with comprehensive help
- Rust 1.70 or later
- Cargo (comes with Rust)
git clone <repository-url>
cd cli-wallet
cargo build --releaseThe compiled binary will be available at target/release/cli-wallet.
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test module
cargo test wallet::testsThe CLI wallet supports four main operations:
Generate a new private/public key pair and wallet address:
cli-wallet generateExample Output:
π New wallet generated successfully!
Private Key: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Public Key: 02a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a
Address: 1a2b3c4d5e6f7890abcdef1234567890abcdef12
β οΈ IMPORTANT: Keep your private key secure and never share it!
π‘ Your address can be shared publicly to receive transactions.
Sign a message using your private key:
cli-wallet sign --message "Hello, world!" --private-key <your-private-key>Example:
cli-wallet sign --message "Hello, world!" --private-key e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855Example Output:
β
Message signed successfully!
Message: Hello, world!
Signature: 3045022100a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a02201b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab
π‘ Share this signature along with your public key to prove message authenticity.
Verify that a signature is valid for a given message and public key:
cli-wallet verify --message "Hello, world!" --signature <signature> --public-key <public-key>Example:
cli-wallet verify \
--message "Hello, world!" \
--signature 3045022100a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a02201b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab \
--public-key 02a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789aExample Output:
β
Signature verification successful!
Message: Hello, world!
Public Key: 02a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a
Signature: 3045022100a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a02201b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab
Result: VALID β
π‘ This signature was created by the holder of the corresponding private key.
Display help information:
cli-wallet --help
cli-wallet <command> --helpHere's a complete example showing how to generate a wallet, sign a message, and verify the signature:
# 1. Generate a new wallet
$ cli-wallet generate
π New wallet generated successfully!
Private Key: a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab
Public Key: 02b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789abc
Address: 2b3c4d5e6f7890abcdef1234567890abcdef1234
# 2. Sign a message (use the private key from step 1)
$ cli-wallet sign --message "I own this wallet" --private-key a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab
β
Message signed successfully!
Signature: 304502210098a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a022019b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab
# 3. Verify the signature (use public key and signature from above)
$ cli-wallet verify \
--message "I own this wallet" \
--signature 304502210098a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789a022019b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789ab \
--public-key 02b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789abc
β
Signature verification successful!
Result: VALID β
Generate a new wallet with private key, public key, and address.
Usage: cli-wallet generate
Options: None
Output: Displays the generated private key, public key, and wallet address.
Sign a message using a private key.
Usage: cli-wallet sign --message <MESSAGE> --private-key <PRIVATE_KEY>
Options:
--message, -m <MESSAGE>: The message to sign (required)--private-key, -k <PRIVATE_KEY>: The private key in hex format (64 characters, required)
Output: Displays the message and its signature in hex format.
Verify a message signature using a public key.
Usage: cli-wallet verify --message <MESSAGE> --signature <SIGNATURE> --public-key <PUBLIC_KEY>
Options:
--message, -m <MESSAGE>: The original message that was signed (required)--signature, -s <SIGNATURE>: The signature in hex format (required)--public-key, -p <PUBLIC_KEY>: The public key in hex format (66 or 130 characters, required)
Output: Displays verification result (VALID or INVALID) with details.
--help, -h: Show help information--version, -V: Show version information
- Never share your private key: Anyone with access to your private key can sign messages on your behalf
- Store securely: Keep private keys in secure, encrypted storage
- Use strong randomness: This application uses cryptographically secure random number generation
- No persistent storage: Private keys are only held in memory during operation
- Generate keys offline: For maximum security, generate keys on an air-gapped machine
- Verify signatures: Always verify signatures before trusting signed messages
- Use unique keys: Generate separate key pairs for different purposes
- Regular backups: Securely backup your private keys (encrypted)
- Test first: Test with small amounts or test networks before using with valuable assets
- Elliptic Curve: secp256k1 (same as Bitcoin and Ethereum)
- Hashing Algorithm: SHA-256 for message hashing and address generation
- Signature Scheme: ECDSA (Elliptic Curve Digital Signature Algorithm)
- Key Format: Private keys are 32 bytes (64 hex chars), public keys are 33 bytes compressed (66 hex chars)
- Address Format: 20 bytes (40 hex chars) derived from SHA-256 hash of public key
- Educational Purpose: This is a simplified wallet for learning - not suitable for production use with real cryptocurrency
- No Key Storage: Keys are not persistently stored - you must manage them externally
- Basic Address Format: Uses simplified address generation (not Bitcoin/Ethereum compatible)
- No Network Features: This is an offline tool - no blockchain interaction
The application provides clear error messages for common issues:
β Invalid Input: Private key hex string must be 64 characters, got 62
π‘ Private keys must be exactly 64 hexadecimal characters (32 bytes)β Cryptographic Error: Invalid private key format
π‘ Ensure your private key is a valid secp256k1 private keyβ Verification Error: Signature does not match message and public key
π‘ Check that the signature, message, and public key are all correctsrc/
βββ main.rs # Application entry point
βββ lib.rs # Library exports
βββ cli/ # Command-line interface
β βββ mod.rs # CLI module exports
β βββ commands.rs # Command handlers
β βββ parser.rs # Argument parsing
βββ crypto/ # Cryptographic operations
β βββ mod.rs # Crypto module exports
β βββ keys.rs # Key generation and formatting
β βββ signing.rs # Message signing and verification
β βββ hashing.rs # SHA-256 hashing utilities
βββ wallet.rs # Core wallet functionality
βββ error.rs # Error types and handling
βββ utils/ # Utility functions
βββ mod.rs # Utils module exports
βββ formatting.rs # Display formatting
βββ validation.rs # Input validation
- secp256k1: Elliptic curve cryptography
- sha2: SHA-256 hashing
- rand: Secure random number generation
- clap: Command-line argument parsing
- hex: Hexadecimal encoding/decoding
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run
cargo testto ensure all tests pass - Run
cargo fmtto format code - Run
cargo clippyto check for issues - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is provided for educational purposes only. It is not intended for use with real cryptocurrency or in production environments. The authors are not responsible for any loss of funds or security breaches resulting from the use of this software.