Skip to content

Latest commit

ย 

History

History
709 lines (518 loc) ยท 18.3 KB

File metadata and controls

709 lines (518 loc) ยท 18.3 KB

Web3 Wallet CLI

ไธ€ไธชๅฎ‰ๅ…จใ€ไธ“ไธš็บง็š„ Web3 ้’ฑๅŒ…ๅ‘ฝไปค่กŒๅทฅๅ…ท๏ผŒๆ”ฏๆŒ BIP39/BIP44 ๆ ‡ๅ‡†ๅ’Œ MetaMask ๅ…ผๅฎนๆ€งใ€‚

English | ไธญๆ–‡

ไธญๆ–‡

๐Ÿš€ ๅŠŸ่ƒฝ็‰นๆ€ง

  • ๐Ÿ” ้ซ˜็บงๅฎ‰ๅ…จๆ€ง: ไฝฟ็”จ 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 --help

๐Ÿ“– ไฝฟ็”จๆ–นๆณ•

ๅ…จๅฑ€้€‰้กน

web3wallet [OPTIONS] <COMMAND>

้€‰้กน:
  -v, --verbose              ๅฏ็”จ่ฏฆ็ป†ๆ—ฅๅฟ—่ฎฐๅฝ•
  -o, --output <FORMAT>      ่พ“ๅ‡บๆ ผๅผ [table, json]
  -c, --config <PATH>        ่‡ชๅฎšไน‰้…็ฝฎๆ–‡ไปถ่ทฏๅพ„
  -h, --help                 ๆ˜พ็คบๅธฎๅŠฉไฟกๆฏ
  -V, --version              ๆ˜พ็คบ็‰ˆๆœฌไฟกๆฏ

1. ๅˆ›ๅปบๆ–ฐ้’ฑๅŒ…

็”Ÿๆˆไธ€ไธชๆ–ฐ็š„ 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

โš ๏ธ  ่ฏทๅฎ‰ๅ…จไฟๅญ˜ๆ‚จ็š„ๅŠฉ่ฎฐ่ฏ๏ผๅฎƒๆ˜ฏๆขๅค้’ฑๅŒ…็š„ๅ”ฏไธ€ๆ–นๅผใ€‚

2. ๅฏผๅ…ฅ็Žฐๆœ‰้’ฑๅŒ…

ไปŽๅŠฉ่ฎฐ่ฏๆˆ–็ง้’ฅๅฏผๅ…ฅ้’ฑๅŒ…๏ผš

# ไปŽๅŠฉ่ฎฐ่ฏๅฏผๅ…ฅ
web3wallet import --mnemonic "your twelve word mnemonic phrase here..."

# ไปŽ็ง้’ฅๅฏผๅ…ฅ
web3wallet import --private-key 0x1234567890abcdef...

# ๅฏผๅ…ฅๅนถไฟๅญ˜
web3wallet import --mnemonic "..." --save imported-wallet --network sepolia

3. ๅŠ ่ฝฝไฟๅญ˜็š„้’ฑๅŒ…

่งฃๅฏ†ๅนถๆ˜พ็คบไน‹ๅ‰ไฟๅญ˜็š„้’ฑๅŒ…๏ผš

# ๅŠ ่ฝฝ้’ฑๅŒ…๏ผˆ้œ€่ฆๅฏ†็ ๏ผ‰
web3wallet load my-wallet.json

# ๅชๆ˜พ็คบๅœฐๅ€๏ผˆๆ— ้œ€ๅฏ†็ ๏ผ‰
web3wallet load my-wallet.json --address-only

# ไปŽ HD ้’ฑๅŒ…ๆดพ็”Ÿ็‰นๅฎšๅœฐๅ€
web3wallet load my-wallet.json --derive 5

4. ๅˆ—ๅ‡บๆ‰€ๆœ‰้’ฑๅŒ…

ๆ˜พ็คบ้’ฑๅŒ…็›ฎๅฝ•ไธญ็š„ๆ‰€ๆœ‰ไฟๅญ˜็š„้’ฑๅŒ…๏ผš

# ๅˆ—ๅ‡บๆ‰€ๆœ‰้’ฑๅŒ…
web3wallet list

# JSON ๆ ผๅผ่พ“ๅ‡บ
web3wallet list --output json

# ๆŒ‡ๅฎš่‡ชๅฎšไน‰้’ฑๅŒ…็›ฎๅฝ•
web3wallet list --path /custom/wallet/path

5. ๆ‰น้‡ๅœฐๅ€ๆดพ็”Ÿ

ไปŽ 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

๐Ÿšจ ๅฎ‰ๅ…จๆณจๆ„ไบ‹้กน

  1. ๅŠฉ่ฎฐ่ฏๅฎ‰ๅ…จ:

    • ๆฐธ่ฟœไธ่ฆไธŽไป–ไบบๅˆ†ไบซๆ‚จ็š„ๅŠฉ่ฎฐ่ฏ
    • ๅฐ†ๅŠฉ่ฎฐ่ฏๅญ˜ๅ‚จๅœจๅฎ‰ๅ…จ็š„็ฆป็บฟไฝ็ฝฎ
    • ่€ƒ่™‘ไฝฟ็”จ็กฌไปถ้’ฑๅŒ…่ฟ›่กŒ้•ฟๆœŸๅญ˜ๅ‚จ
  2. ๅฏ†็ ๅฎ‰ๅ…จ:

    • ไฝฟ็”จๅผบๅฏ†็ ไฟๆŠคไฟๅญ˜็š„้’ฑๅŒ…
    • ไธ่ฆ้‡ๅคไฝฟ็”จๅฏ†็ 
    • ่€ƒ่™‘ไฝฟ็”จๅฏ†็ ็ฎก็†ๅ™จ
  3. ๆ–‡ไปถๅฎ‰ๅ…จ:

    • ๅฎšๆœŸๅค‡ไปฝ้’ฑๅŒ…ๆ–‡ไปถ
    • ็กฎไฟ้’ฑๅŒ…็›ฎๅฝ•ๆƒ้™ๆญฃ็กฎ
    • ๅœจๅˆ ้™ค้’ฑๅŒ…ๆ–‡ไปถๅ‰ไธ‰ๆ€
  4. ็ฝ‘็ปœๅฎ‰ๅ…จ:

    • ๅœจๆต‹่ฏ•็ฝ‘ไธŠ้ชŒ่ฏๆ“ไฝœๅŽๅ†ๅœจไธป็ฝ‘ไฝฟ็”จ
    • ้ชŒ่ฏ็ฝ‘็ปœ้…็ฝฎ็š„ๆญฃ็กฎๆ€ง

๐Ÿค ่ดก็Œฎ

ๆฌข่ฟŽ่ดก็Œฎ๏ผ่ฏท้ตๅพชไปฅไธ‹ๆญฅ้ชค๏ผš

  1. Fork ๆญคไป“ๅบ“
  2. ๅˆ›ๅปบๅŠŸ่ƒฝๅˆ†ๆ”ฏ (git checkout -b feature/amazing-feature)
  3. ๆไบคๆ›ดๆ”น (git commit -m 'Add some amazing feature')
  4. ๆŽจ้€ๅˆฐๅˆ†ๆ”ฏ (git push origin feature/amazing-feature)
  5. ๆ‰“ๅผ€ Pull Request

๐Ÿ“„ ่ฎธๅฏ่ฏ

ๆญค้กน็›ฎๅŸบไบŽ MIT ่ฎธๅฏ่ฏ - ๆŸฅ็œ‹ LICENSE ๆ–‡ไปถไบ†่งฃ่ฏฆๆƒ…ใ€‚

๐Ÿ› ้—ฎ้ข˜ๆŠฅๅ‘Š

ๅฆ‚ๆžœๆ‚จๅ‘็Žฐ้”™่ฏฏๆˆ–ๆœ‰ๅŠŸ่ƒฝ่ฏทๆฑ‚๏ผŒ่ฏทๅœจ GitHub Issues ไธญๆไบคใ€‚

๐Ÿ“ž ๆ”ฏๆŒ

  • ๆ–‡ๆกฃ: ๆŸฅ็œ‹ๆญค README ๅ’Œๅ†…็ฝฎๅธฎๅŠฉ (web3wallet --help)
  • ้—ฎ้ข˜: GitHub Issues
  • ่ฎจ่ฎบ: GitHub Discussions

English

๐Ÿš€ Features

  • ๐Ÿ” 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

๐Ÿ›  Technology Stack

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

๐Ÿ“ Project Architecture

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

๐Ÿ”ง Installation

Prerequisites

  • Rust 1.70+ and Cargo
  • Git (optional, for source installation)

Build from Source

# Clone the repository
git clone <repository-url>
cd web3wallet-cli

# Build the project
cargo build --release

# Install to system path
cargo install --path .

Verify Installation

web3wallet --help

๐Ÿ“– Usage

Global Options

web3wallet [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 information

1. Create New Wallet

Generate 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 json

Example 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.

2. Import Existing 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 sepolia

3. Load Saved Wallet

Decrypt 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 5

4. List All Wallets

Display 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/path

5. Batch Address Derivation

Generate 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

โš™๏ธ Configuration

Default Settings

  • 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)

Supported Networks

Network Description Chain ID
mainnet Ethereum Mainnet 1
sepolia Sepolia Testnet 11155111
goerli Goerli Testnet 5
holesky Holesky Testnet 17000

Password Requirements

Passwords for saving wallets must have:

  • Length: 8-1024 characters
  • Lowercase letter
  • Uppercase letter
  • Digit
  • Special character

๐Ÿ”’ Security Features

Encryption Specifications

  • 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 zeroize to clear sensitive data

Keystore Format

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": "..."
  }
}

๐Ÿงช Testing

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 test

Test Coverage: 27+ integration tests covering all commands and edge cases

๐Ÿ“ Example Use Cases

Developer Workflow

# 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

Secure Backup Process

# 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

๐Ÿšจ Security Considerations

  1. Mnemonic Security:

    • Never share your mnemonic phrase with anyone
    • Store mnemonic phrases in secure, offline locations
    • Consider using hardware wallets for long-term storage
  2. Password Security:

    • Use strong passwords to protect saved wallets
    • Don't reuse passwords
    • Consider using a password manager
  3. File Security:

    • Regularly backup wallet files
    • Ensure proper permissions on wallet directory
    • Think twice before deleting wallet files
  4. Network Security:

    • Test operations on testnets before mainnet use
    • Verify network configuration correctness

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ› Bug Reports

If you find a bug or have a feature request, please submit an issue at GitHub Issues.

๐Ÿ“ž Support

  • 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