agentconnect.utils.wallet_manager module

Wallet persistence utilities for the AgentConnect framework.

This module provides utility functions to manage wallet data persistence for individual agents within the AgentConnect framework. It specifically facilitates the storage and retrieval of wallet state to enable consistent wallet access across agent restarts.

set_default_data_dir(data_dir)

Set the default directory for wallet data storage globally.

Parameters:

data_dir (Union[str, Path]) – Path to the directory where wallet data will be stored Can be a string or Path object

Return type:

Path

Returns:

Path object pointing to the created directory

Raises:

IOError – If the directory can’t be created

set_wallet_data_dir(data_dir)

Set a custom directory for wallet data storage.

Parameters:

data_dir (Union[str, Path]) – Path to the directory where wallet data will be stored Can be a string or Path object

Return type:

Path

Returns:

Path object pointing to the created directory

Raises:

IOError – If the directory can’t be created

save_wallet_data(agent_id, wallet_data, data_dir=None)

Persists the exported wallet data for an agent, allowing the agent to retain access to the same wallet across restarts.

SECURITY NOTE: This default implementation stores wallet data unencrypted on disk, which is suitable for testing/demo but NOT secure for production environments holding real assets. Real-world applications should encrypt this data.

Parameters:
  • agent_id (str) – String identifier for the agent.

  • wallet_data (Union[WalletData, str, Dict]) – The wallet data to save. Can be a cdp.WalletData object, a Dict representation, or a JSON string.

  • data_dir (Union[str, Path, None]) – Optional custom directory for wallet data storage. If None, uses the DEFAULT_DATA_DIR.

Raises:

IOError – If the data directory can’t be created or the file can’t be written.

Return type:

None

load_wallet_data(agent_id, data_dir=None)

Loads previously persisted wallet data for an agent.

Parameters:
  • agent_id (str) – String identifier for the agent.

  • data_dir (Union[str, Path, None]) – Optional custom directory for wallet data storage. If None, uses the DEFAULT_DATA_DIR.

Return type:

Optional[str]

Returns:

The loaded wallet data as a JSON string if the file exists, otherwise None.

Raises:

IOError – If the file exists but can’t be read properly.

wallet_exists(agent_id, data_dir=None)

Check if wallet data exists for a specific agent.

Parameters:
  • agent_id (str) – String identifier for the agent.

  • data_dir (Union[str, Path, None]) – Optional custom directory for wallet data storage. If None, uses the DEFAULT_DATA_DIR.

Return type:

bool

Returns:

True if wallet data exists, False otherwise.

get_all_wallets(data_dir=None)

Get information about all wallet files in the specified directory.

Parameters:

data_dir (Union[str, Path, None]) – Optional custom directory for wallet data storage. If None, uses the DEFAULT_DATA_DIR.

Return type:

List[Dict]

Returns:

List of dictionaries with wallet information (agent_id, file_path, etc.)

delete_wallet_data(agent_id, data_dir=None)

Delete wallet data for a specific agent.

Parameters:
  • agent_id (str) – String identifier for the agent.

  • data_dir (Union[str, Path, None]) – Optional custom directory for wallet data storage. If None, uses the DEFAULT_DATA_DIR.

Return type:

bool

Returns:

True if wallet data was successfully deleted, False otherwise.