ไธไธชๅฎๅ จใไธไธ็บง็ Web3 ้ฑๅ ๅฝไปค่กๅทฅๅ ท๏ผๆฏๆ BIP39/BIP44 ๆ ๅๅ MetaMask ๅ ผๅฎนๆงใ
- ๐ ้ซ็บงๅฎๅ จๆง: ไฝฟ็จ AES-256-GCM ๅ ๅฏๅ Argon2id ๅฏ้ฅๆดพ็
- ๐ BIP39/BIP44 ๅ ผๅฎน: ๅฎๅ จๆฏๆ่กไธๆ ๅๅฉ่ฎฐ่ฏๅๅๅฑ็กฎๅฎๆง้ฑๅ
- ๐ฆ MetaMask ๅ ผๅฎน: ็ๆไธ MetaMask ๅฎๅ จๅ ผๅฎน็ๅฐๅ
- ๐ ๅค็ฝ็ปๆฏๆ: ๆฏๆไธป็ฝใSepoliaใGoerliใHolesky ๆต่ฏ็ฝ
- ๐พ ๅฎๅ จๅญๅจ: ๅฏ็ ไฟๆค็ๅ ๅฏ้ฑๅ ๆไปถ
- โก ๆน้ๅฐๅ็ๆ: ไป HD ้ฑๅ ๆน้ๆดพ็ๅคไธชๅฐๅ
- ๐ ๅค็ง่พๅบๆ ผๅผ: ๆฏๆ่กจๆ ผๅ JSON ๆ ผๅผ่พๅบ
- ๐ ้ฑๅ ็ฎก็: ๅๅบใๅ ่ฝฝๅ็ฎก็ไฟๅญ็้ฑๅ
| ๅ็ฑป | ๆๆฏ | ็ๆฌ | ็จ้ |
|---|---|---|---|
| ็ผ็จ่ฏญ่จ | Rust | 2021 Edition | ็ณป็ป็บงๆง่ฝๅๅ ๅญๅฎๅ จ |
| CLI ๆกๆถ | Clap | 4.0 | ๅฝไปค่กๅๆฐ่งฃๆๅๅธฎๅฉ |
| ๅ ๅฏๆๆฏ | AES-GCM, Argon2, PBKDF2 | - | AES-256-GCM ๅ ๅฏๅๅฎๅ จๅฏ้ฅๆดพ็ |
| ๅบๅ้พ | Ethers, BIP39 | 2.0 | ไปฅๅคชๅๅฐๅ็ๆๅ BIP39 ๅฉ่ฎฐ่ฏ |
| ๅผๆญฅ่ฟ่กๆถ | Tokio | 1.0 | ๅผๆญฅๆไปถ I/O ๆไฝ |
| ๅบๅๅ | Serde | - | JSON ๅบๅๅๅๅฏ้ฅๅบๆ ผๅผ |
| ๅฎๅ จๆง | Zeroize | - | ๆๆๆฐๆฎๅ ๅญๅฎๅ จๆธ ้ค |
web3wallet-cli/
โโโ src/
โ โโโ main.rs # CLI ๅ
ฅๅฃ็นๅๅฝไปคๅค็ๅจ
โ โโโ lib.rs # ๅบๅฏผๅบๅ WalletConfig
โ โโโ config.rs # ้
็ฝฎๅธธ้ๅ่ฎพ็ฝฎ
โ โโโ errors.rs # ๅ
จ้ข็้่ฏฏ็ฑปๅๅฎไน
โ โโโ utils.rs # ้ช่ฏๅทฅๅ
ทๅฝๆฐ
โ โโโ models/ # ๆฐๆฎๆจกๅ
โ โ โโโ wallet.rs # ้ฑๅ
็ปๆๅๆไฝ
โ โ โโโ address.rs # ๅฐๅๆจกๅ
โ โ โโโ keystore.rs # ๅ ๅฏ้ฑๅ
ๅญๅจๆ ผๅผ
โ โ โโโ command.rs # ๅฝไปค็ปๆ
โ โโโ services/ # ไธๅก้ป่พๅฑ
โ โโโ walletmanager.rs # ้ซ็บง้ฑๅ
ๆไฝ
โ โโโ crypto.rs # ๅ ๅฏ/่งฃๅฏๆไฝ
โ โโโ mnemonic.rs # BIP39 ๅฉ่ฎฐ่ฏ็ๆๅ้ช่ฏ
โโโ tests/ # ้ๆๆต่ฏ
โ โโโ test_create_command.rs
โ โโโ test_import_command.rs
โ โโโ test_derive_command.rs
โ โโโ test_list_command.rs
โโโ Cargo.toml # ้กน็ฎ้
็ฝฎ
- Rust 1.70+ ๅ Cargo
- Git (ๅฏ้๏ผ็จไบๆบ็ ๅฎ่ฃ )
# ๅ
้ไปๅบ
git clone <repository-url>
cd web3wallet-cli
# ็ผ่ฏ้กน็ฎ
cargo build --release
# ๅฎ่ฃ
ๅฐ็ณป็ป่ทฏๅพ
cargo install --path .web3wallet --helpweb3wallet [OPTIONS] <COMMAND>
้้กน:
-v, --verbose ๅฏ็จ่ฏฆ็ปๆฅๅฟ่ฎฐๅฝ
-o, --output <FORMAT> ่พๅบๆ ผๅผ [table, json]
-c, --config <PATH> ่ชๅฎไน้
็ฝฎๆไปถ่ทฏๅพ
-h, --help ๆพ็คบๅธฎๅฉไฟกๆฏ
-V, --version ๆพ็คบ็ๆฌไฟกๆฏ็ๆไธไธชๆฐ็ BIP39/BIP44 ๅ ผๅฎน้ฑๅ ๏ผ
# ๅๅปบ 12 ่ฏๅฉ่ฎฐ่ฏ้ฑๅ
๏ผ้ป่ฎค๏ผ
web3wallet create
# ๅๅปบ 24 ่ฏๅฉ่ฎฐ่ฏ้ฑๅ
web3wallet create --words 24
# ๅๅปบ้ฑๅ
ๅนถไฟๅญๅฐๆไปถ
web3wallet create --words 12 --save my-wallet --network mainnet
# JSON ๆ ผๅผ่พๅบ
web3wallet create --output json็คบไพ่พๅบ:
๐ ้ฑๅ
ๅๅปบๆๅ๏ผ
ๅฉ่ฎฐ่ฏ: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
ๅฐๅ: 0x9858EfFD232B4033E47d90003D41EC34EcaEda94
็ฝ็ป: mainnet
็ฑปๅ: HD ้ฑๅ
(BIP44)
่ทฏๅพ: m/44'/60'/0'/0/0
โ ๏ธ ่ฏทๅฎๅ
จไฟๅญๆจ็ๅฉ่ฎฐ่ฏ๏ผๅฎๆฏๆขๅค้ฑๅ
็ๅฏไธๆนๅผใ
ไปๅฉ่ฎฐ่ฏๆ็ง้ฅๅฏผๅ ฅ้ฑๅ ๏ผ
# ไปๅฉ่ฎฐ่ฏๅฏผๅ
ฅ
web3wallet import --mnemonic "your twelve word mnemonic phrase here..."
# ไป็ง้ฅๅฏผๅ
ฅ
web3wallet import --private-key 0x1234567890abcdef...
# ๅฏผๅ
ฅๅนถไฟๅญ
web3wallet import --mnemonic "..." --save imported-wallet --network sepolia่งฃๅฏๅนถๆพ็คบไนๅไฟๅญ็้ฑๅ ๏ผ
# ๅ ่ฝฝ้ฑๅ
๏ผ้่ฆๅฏ็ ๏ผ
web3wallet load my-wallet.json
# ๅชๆพ็คบๅฐๅ๏ผๆ ้ๅฏ็ ๏ผ
web3wallet load my-wallet.json --address-only
# ไป HD ้ฑๅ
ๆดพ็็นๅฎๅฐๅ
web3wallet load my-wallet.json --derive 5ๆพ็คบ้ฑๅ ็ฎๅฝไธญ็ๆๆไฟๅญ็้ฑๅ ๏ผ
# ๅๅบๆๆ้ฑๅ
web3wallet list
# JSON ๆ ผๅผ่พๅบ
web3wallet list --output json
# ๆๅฎ่ชๅฎไน้ฑๅ
็ฎๅฝ
web3wallet list --path /custom/wallet/pathไป HD ้ฑๅ ็ๆๅคไธชๅฐๅ๏ผ
# ไปไฟๅญ็้ฑๅ
ๆไปถๆดพ็ๅฐๅ
web3wallet derive --from-file my-wallet.json --count 10
# ไปๅฉ่ฎฐ่ฏ็ดๆฅๆดพ็
web3wallet derive --mnemonic "your mnemonic..." --count 5 --start-index 0
# ไฝฟ็จ่ชๅฎไนๆดพ็่ทฏๅพ
web3wallet derive --from-file wallet.json --path "m/44'/60'/0'/0" --count 3- ้ฑๅ
็ฎๅฝ:
~/.web3wallet/wallets/ - ้ป่ฎค็ฝ็ป:
mainnet - ๆดพ็่ทฏๅพ:
m/44'/60'/0'/0(ไปฅๅคชๅ BIP44 ๆ ๅ) - ๅ ๅฏ็ฎๆณ: AES-256-GCM
- ๅฏ้ฅๆดพ็: Argon2id (ๅ ๅญ: 47,104 KB, ่ฟญไปฃ: 1)
| ็ฝ็ป | ๆ่ฟฐ | Chain ID |
|---|---|---|
mainnet |
ไปฅๅคชๅไธป็ฝ | 1 |
sepolia |
Sepolia ๆต่ฏ็ฝ | 11155111 |
goerli |
Goerli ๆต่ฏ็ฝ | 5 |
holesky |
Holesky ๆต่ฏ็ฝ | 17000 |
ไฟๅญ้ฑๅ ๆถ็ๅฏ็ ๅฟ ้กปๆปก่ถณ๏ผ
- ้ฟๅบฆ 8-1024 ๅญ็ฌฆ
- ๅ ๅซๅฐๅๅญๆฏ
- ๅ ๅซๅคงๅๅญๆฏ
- ๅ ๅซๆฐๅญ
- ๅ ๅซ็นๆฎๅญ็ฌฆ
- ๅฏน็งฐๅ ๅฏ: AES-256-GCM
- ๅฏ้ฅๆดพ็: Argon2id (ๆจ่) ๆ PBKDF2 (ๅ ผๅฎนๆจกๅผ)
- MAC ้ช่ฏ: HMAC-SHA256
- ้ๆบๆง: ๅ ๅฏๅฎๅ จ็้ๆบๆฐ็ๆๅจ
- ๅ
ๅญๅฎๅ
จ: ไฝฟ็จ
zeroizeๆธ ้คๆๆๆฐๆฎ
้ฑๅ ไปฅ JSON ๆ ผๅผๅ ๅฏๅญๅจ๏ผ
{
"version": "1.0.0",
"metadata": {
"alias": "my-wallet",
"address": "0x...",
"created_at": "2024-01-01T00:00:00Z",
"network": "mainnet",
"wallet_type": "HDWallet"
},
"crypto": {
"cipher": "aes-256-gcm",
"ciphertext": "...",
"iv": "...",
"kdf": {
"type": "argon2id",
"params": {...}
},
"mac": "..."
}
}่ฟ่กๅฎๆด็ๆต่ฏๅฅไปถ๏ผ
# ่ฟ่กๆๆๆต่ฏ
cargo test
# ่ฟ่ก็นๅฎๅฝไปคๆต่ฏ
cargo test test_create_command
cargo test test_import_command
cargo test test_derive_command
cargo test test_list_command
# ่ฟ่กๆต่ฏๅนถๆพ็คบ่พๅบ
cargo test -- --nocapture
# ไฝฟ็จๆต่ฏๅฏ็ ็ฏๅขๅ้
TEST_WALLET_PASSWORD=test cargo testๆต่ฏ่ฆ็็: 27+ ้ๆๆต่ฏ่ฆ็ๆๆๅฝไปคๅ่พน็ๆ ๅต
# 1. ไธบๅผๅๅๅปบๆฐ้ฑๅ
web3wallet create --words 12 --save dev-wallet --network sepolia
# 2. ๆดพ็ๅคไธชๆต่ฏๅฐๅ
web3wallet derive --from-file dev-wallet.json --count 10
# 3. ๅฏผๅ
ฅ็ฐๆ็ MetaMask ้ฑๅ
web3wallet import --mnemonic "your metamask mnemonic" --save metamask-backup
# 4. ๅๅบๆๆ็ฎก็็้ฑๅ
web3wallet list --output json# 1. ๅๅปบไธป้ฑๅ
web3wallet create --words 24 --save master-wallet
# 2. ้ช่ฏ้ฑๅ
ๅฏไปฅๆญฃ็กฎๅ ่ฝฝ
web3wallet load master-wallet.json --address-only
# 3. ๅฏผๅบๅคไธชๅฐๅ็จไบ็ๆง
web3wallet derive --from-file master-wallet.json --count 20 --output json > addresses.json-
ๅฉ่ฎฐ่ฏๅฎๅ จ:
- ๆฐธ่ฟไธ่ฆไธไปไบบๅไบซๆจ็ๅฉ่ฎฐ่ฏ
- ๅฐๅฉ่ฎฐ่ฏๅญๅจๅจๅฎๅ จ็็ฆป็บฟไฝ็ฝฎ
- ่่ไฝฟ็จ็กฌไปถ้ฑๅ ่ฟ่ก้ฟๆๅญๅจ
-
ๅฏ็ ๅฎๅ จ:
- ไฝฟ็จๅผบๅฏ็ ไฟๆคไฟๅญ็้ฑๅ
- ไธ่ฆ้ๅคไฝฟ็จๅฏ็
- ่่ไฝฟ็จๅฏ็ ็ฎก็ๅจ
-
ๆไปถๅฎๅ จ:
- ๅฎๆๅคไปฝ้ฑๅ ๆไปถ
- ็กฎไฟ้ฑๅ ็ฎๅฝๆ้ๆญฃ็กฎ
- ๅจๅ ้ค้ฑๅ ๆไปถๅไธๆ
-
็ฝ็ปๅฎๅ จ:
- ๅจๆต่ฏ็ฝไธ้ช่ฏๆไฝๅๅๅจไธป็ฝไฝฟ็จ
- ้ช่ฏ็ฝ็ป้ ็ฝฎ็ๆญฃ็กฎๆง
ๆฌข่ฟ่ดก็ฎ๏ผ่ฏท้ตๅพชไปฅไธๆญฅ้ชค๏ผ
- Fork ๆญคไปๅบ
- ๅๅปบๅ่ฝๅๆฏ (
git checkout -b feature/amazing-feature) - ๆไบคๆดๆน (
git commit -m 'Add some amazing feature') - ๆจ้ๅฐๅๆฏ (
git push origin feature/amazing-feature) - ๆๅผ Pull Request
ๆญค้กน็ฎๅบไบ MIT ่ฎธๅฏ่ฏ - ๆฅ็ LICENSE ๆไปถไบ่งฃ่ฏฆๆ ใ
ๅฆๆๆจๅ็ฐ้่ฏฏๆๆๅ่ฝ่ฏทๆฑ๏ผ่ฏทๅจ GitHub Issues ไธญๆไบคใ
- ๆๆกฃ: ๆฅ็ๆญค README ๅๅ
็ฝฎๅธฎๅฉ (
web3wallet --help) - ้ฎ้ข: GitHub Issues
- ่ฎจ่ฎบ: GitHub Discussions
- ๐ Advanced Security: AES-256-GCM encryption with Argon2id key derivation
- ๐ BIP39/BIP44 Compliant: Full support for industry-standard mnemonics and HD wallets
- ๐ฆ MetaMask Compatible: Generates addresses fully compatible with MetaMask
- ๐ Multi-Network Support: Mainnet, Sepolia, Goerli, Holesky testnets
- ๐พ Secure Storage: Password-protected encrypted wallet files
- โก Batch Address Generation: Derive multiple addresses from HD wallets
- ๐ Multiple Output Formats: Table and JSON output support
- ๐ Wallet Management: List, load, and manage saved wallets
| Category | Technology | Version | Purpose |
|---|---|---|---|
| Language | Rust | 2021 Edition | Systems-level performance and memory safety |
| CLI Framework | Clap | 4.0 | Command-line argument parsing and help |
| Cryptography | AES-GCM, Argon2, PBKDF2 | - | AES-256-GCM encryption with secure key derivation |
| Blockchain | Ethers, BIP39 | 2.0 | Ethereum address generation and BIP39 mnemonics |
| Async Runtime | Tokio | 1.0 | Async file I/O operations |
| Serialization | Serde | - | JSON serialization and keystore format |
| Security | Zeroize | - | Secure memory clearing for sensitive data |
web3wallet-cli/
โโโ src/
โ โโโ main.rs # CLI entry point and command handlers
โ โโโ lib.rs # Library exports and WalletConfig
โ โโโ config.rs # Configuration constants and settings
โ โโโ errors.rs # Comprehensive error type definitions
โ โโโ utils.rs # Validation utility functions
โ โโโ models/ # Data models
โ โ โโโ wallet.rs # Wallet structure and operations
โ โ โโโ address.rs # Address model
โ โ โโโ keystore.rs # Encrypted wallet storage format
โ โ โโโ command.rs # Command structures
โ โโโ services/ # Business logic layer
โ โโโ walletmanager.rs # High-level wallet operations
โ โโโ crypto.rs # Encryption/decryption operations
โ โโโ mnemonic.rs # BIP39 mnemonic generation and validation
โโโ tests/ # Integration tests
โ โโโ test_create_command.rs
โ โโโ test_import_command.rs
โ โโโ test_derive_command.rs
โ โโโ test_list_command.rs
โโโ Cargo.toml # Project configuration
- Rust 1.70+ and Cargo
- Git (optional, for source installation)
# Clone the repository
git clone <repository-url>
cd web3wallet-cli
# Build the project
cargo build --release
# Install to system path
cargo install --path .web3wallet --helpweb3wallet [OPTIONS] <COMMAND>
Options:
-v, --verbose Enable verbose logging
-o, --output <FORMAT> Output format [table, json]
-c, --config <PATH> Custom configuration file path
-h, --help Show help information
-V, --version Show version informationGenerate a new BIP39/BIP44 compliant wallet:
# Create 12-word mnemonic wallet (default)
web3wallet create
# Create 24-word mnemonic wallet
web3wallet create --words 24
# Create wallet and save to file
web3wallet create --words 12 --save my-wallet --network mainnet
# JSON output format
web3wallet create --output jsonExample Output:
๐ Wallet created successfully!
Mnemonic: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
Address: 0x9858EfFD232B4033E47d90003D41EC34EcaEda94
Network: mainnet
Type: HD Wallet (BIP44)
Path: m/44'/60'/0'/0/0
โ ๏ธ Please save your mnemonic phrase securely! It's the only way to recover your wallet.
Import wallet from mnemonic or private key:
# Import from mnemonic
web3wallet import --mnemonic "your twelve word mnemonic phrase here..."
# Import from private key
web3wallet import --private-key 0x1234567890abcdef...
# Import and save
web3wallet import --mnemonic "..." --save imported-wallet --network sepoliaDecrypt and display previously saved wallet:
# Load wallet (requires password)
web3wallet load my-wallet.json
# Address-only mode (no password required)
web3wallet load my-wallet.json --address-only
# Derive specific address from HD wallet
web3wallet load my-wallet.json --derive 5Display all saved wallets in the wallet directory:
# List all wallets
web3wallet list
# JSON output format
web3wallet list --output json
# Specify custom wallet directory
web3wallet list --path /custom/wallet/pathGenerate multiple addresses from HD wallet:
# Derive addresses from saved wallet file
web3wallet derive --from-file my-wallet.json --count 10
# Derive directly from mnemonic
web3wallet derive --mnemonic "your mnemonic..." --count 5 --start-index 0
# Use custom derivation path
web3wallet derive --from-file wallet.json --path "m/44'/60'/0'/0" --count 3- Wallet Directory:
~/.web3wallet/wallets/ - Default Network:
mainnet - Derivation Path:
m/44'/60'/0'/0(Ethereum BIP44 standard) - Encryption: AES-256-GCM
- Key Derivation: Argon2id (Memory: 47,104 KB, Iterations: 1)
| Network | Description | Chain ID |
|---|---|---|
mainnet |
Ethereum Mainnet | 1 |
sepolia |
Sepolia Testnet | 11155111 |
goerli |
Goerli Testnet | 5 |
holesky |
Holesky Testnet | 17000 |
Passwords for saving wallets must have:
- Length: 8-1024 characters
- Lowercase letter
- Uppercase letter
- Digit
- Special character
- Symmetric Encryption: AES-256-GCM
- Key Derivation: Argon2id (recommended) or PBKDF2 (legacy compatibility)
- MAC Verification: HMAC-SHA256
- Randomness: Cryptographically secure random number generation
- Memory Safety: Uses
zeroizeto clear sensitive data
Wallets are stored encrypted in JSON format:
{
"version": "1.0.0",
"metadata": {
"alias": "my-wallet",
"address": "0x...",
"created_at": "2024-01-01T00:00:00Z",
"network": "mainnet",
"wallet_type": "HDWallet"
},
"crypto": {
"cipher": "aes-256-gcm",
"ciphertext": "...",
"iv": "...",
"kdf": {
"type": "argon2id",
"params": {...}
},
"mac": "..."
}
}Run the complete test suite:
# Run all tests
cargo test
# Run specific command tests
cargo test test_create_command
cargo test test_import_command
cargo test test_derive_command
cargo test test_list_command
# Run tests with output
cargo test -- --nocapture
# Use test password environment variable
TEST_WALLET_PASSWORD=test cargo testTest Coverage: 27+ integration tests covering all commands and edge cases
# 1. Create new wallet for development
web3wallet create --words 12 --save dev-wallet --network sepolia
# 2. Derive multiple test addresses
web3wallet derive --from-file dev-wallet.json --count 10
# 3. Import existing MetaMask wallet
web3wallet import --mnemonic "your metamask mnemonic" --save metamask-backup
# 4. List all managed wallets
web3wallet list --output json# 1. Create master wallet
web3wallet create --words 24 --save master-wallet
# 2. Verify wallet can be loaded correctly
web3wallet load master-wallet.json --address-only
# 3. Export multiple addresses for monitoring
web3wallet derive --from-file master-wallet.json --count 20 --output json > addresses.json-
Mnemonic Security:
- Never share your mnemonic phrase with anyone
- Store mnemonic phrases in secure, offline locations
- Consider using hardware wallets for long-term storage
-
Password Security:
- Use strong passwords to protect saved wallets
- Don't reuse passwords
- Consider using a password manager
-
File Security:
- Regularly backup wallet files
- Ensure proper permissions on wallet directory
- Think twice before deleting wallet files
-
Network Security:
- Test operations on testnets before mainnet use
- Verify network configuration correctness
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you find a bug or have a feature request, please submit an issue at GitHub Issues.
- Documentation: See this README and built-in help (
web3wallet --help) - Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with โค๏ธ by Frank | Version: 0.1.0 | License: MIT