btc_wallet_manager

Bitcoin Wallet Manager Module

Handles HD wallet creation, derivation, and encrypted storage in Redis. Supports BIP39 mnemonics and BIP84 derivation paths (m/84’/0’/0’/0/x) for Native SegWit.

class btc_wallet_manager.BTCWalletManager[source]

Bases: object

Manages Bitcoin HD wallets with encrypted storage in Redis.

Features: - BIP39 mnemonic generation and import - BIP84 derivation (m/84’/0’/0’/0/x) for Native SegWit - AES-256-GCM encryption for seeds at rest - Per-user wallet isolation - Address caching for derived addresses

Accepts an async Redis client via method parameters for v3 compatibility.

__init__()[source]

Initialize the instance.

generate_mnemonic(strength=128)[source]

Generate mnemonic.

Parameters:

strength (int) – The strength value.

Returns:

Result string.

Return type:

str

validate_mnemonic(mnemonic)[source]

Validate the mnemonic.

Parameters:

mnemonic (str) – The mnemonic value.

Returns:

True on success, False otherwise.

Return type:

bool

async create_wallet(user_id, wallet_name, mnemonic, redis_client, network='bitcoin')[source]

Create a new wallet.

Parameters:
  • user_id (str) – Unique identifier for the user.

  • wallet_name (str) – The wallet name value.

  • mnemonic (str) – The mnemonic value.

  • redis_client – Redis connection client.

  • network (str) – The network value.

Returns:

The result.

Return type:

Dict[str, Any]

async import_wif(user_id, wallet_name, wif, redis_client, network='bitcoin')[source]

Import wif.

Parameters:
  • user_id (str) – Unique identifier for the user.

  • wallet_name (str) – The wallet name value.

  • wif (str) – The wif value.

  • redis_client – Redis connection client.

  • network (str) – The network value.

Returns:

The result.

Return type:

Dict[str, Any]

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 list_wallets(user_id, redis_client)[source]

List wallets.

Parameters:
  • user_id (str) – Unique identifier for the user.

  • redis_client – Redis connection client.

Returns:

The result.

Return type:

List[Dict[str, Any]]

async derive_address(user_id, wallet_name, index, redis_client, address_type='bech32')[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.

  • address_type (str) – The address type value.

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