wallet_manager
Ethereum Wallet Manager Module
Handles HD wallet creation, derivation, and encrypted storage in Redis.
Supports any EVM-compatible network through configurable RPC endpoints.
Uses BIP39 mnemonics and BIP44 derivation paths (m/44’/60’/0’/0/x).
-
class wallet_manager.WalletManager[source]
Bases: object
Manages Ethereum HD wallets with encrypted storage in Redis.
Features:
- BIP39 mnemonic generation and import
- BIP44 derivation (m/44’/60’/0’/0/x)
- AES-256-GCM encryption for private keys at rest
- Per-user wallet isolation
- Address caching for derived addresses
Unlike the v2 singleton, this class accepts an async Redis client
via its async methods so it can work with the v3 ToolContext.redis.
-
__init__()[source]
Initialize the instance.
-
static generate_mnemonic(strength=128)[source]
Generate mnemonic.
- Parameters:
strength (int) – The strength value.
- Returns:
Result string.
- Return type:
str
-
static validate_mnemonic(mnemonic)[source]
Validate the mnemonic.
- Parameters:
mnemonic (str) – The mnemonic value.
- Returns:
True on success, False otherwise.
- Return type:
bool
-
static derive_address_from_mnemonic(mnemonic, index=0)[source]
Derive address from mnemonic.
- Parameters:
-
- Returns:
The result.
- Return type:
Tuple[str, str]
-
static derive_address_from_private_key(private_key)[source]
Derive address from private key.
- Parameters:
private_key (str) – The private key value.
- Returns:
Result string.
- Return type:
str
-
static is_valid_private_key(private_key)[source]
Check whether is valid private key.
- Parameters:
private_key (str) – The private key value.
- Returns:
True on success, False otherwise.
- Return type:
bool
-
async create_wallet(user_id, wallet_name, redis_client, mnemonic=None, strength=128)[source]
Create a new wallet.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
redis_client – Redis connection client.
mnemonic (Optional[str]) – The mnemonic value.
strength (int) – The strength value.
- Returns:
The result.
- Return type:
Dict[str, Any]
-
async import_private_key(user_id, wallet_name, private_key, redis_client)[source]
Import private key.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
private_key (str) – The private key value.
redis_client – Redis connection client.
- Returns:
The result.
- Return type:
Dict[str, Any]
-
async wallet_exists(user_id, wallet_name, redis_client)[source]
Wallet exists.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
redis_client – Redis connection client.
- Returns:
True on success, False otherwise.
- Return type:
bool
-
async get_wallet(user_id, wallet_name, redis_client)[source]
Retrieve the wallet.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
redis_client – Redis connection client.
- Returns:
The result.
- Return type:
Optional[Dict[str, Any]]
-
async get_decrypted_seed(user_id, wallet_name, redis_client)[source]
Retrieve the decrypted seed.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
redis_client – Redis connection client.
- Returns:
The result.
- Return type:
Optional[str]
-
async derive_address(user_id, wallet_name, index, redis_client)[source]
Derive address.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
index (int) – The index value.
redis_client – Redis connection client.
- Returns:
The result.
- Return type:
Optional[str]
-
async get_private_key(user_id, wallet_name, redis_client, index=0)[source]
Retrieve the private key.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
redis_client – Redis connection client.
index (int) – The index value.
- Returns:
The result.
- Return type:
Optional[str]
-
async list_wallets(user_id, redis_client)[source]
List wallets.
- Parameters:
-
- Returns:
The result.
- Return type:
List[Dict[str, Any]]
-
async delete_wallet(user_id, wallet_name, redis_client)[source]
Delete the specified wallet.
- Parameters:
user_id (str) – Unique identifier for the user.
wallet_name (str) – The wallet name value.
redis_client – Redis connection client.
- Returns:
True on success, False otherwise.
- Return type:
bool