The Wallet module API provides programmatic access to self-custody wallet management, message signing, key rotation, encrypted backups, and Natural Ritual recovery. All operations are available as Python library functions.
Primary interface for wallet lifecycle operations.
- Description: Initialize the wallet manager with optional key storage path.
- Parameters:
storage_path(Optional[Path]): Directory for key file storage. Defaults to system temp directory.
- Description: Create a new wallet with generated address and private key.
- Parameters:
user_id(str): Unique identifier for the wallet owner.
- Returns:
str- Wallet address (0x-prefixed hex string). - Raises:
WalletError: If user already has a wallet.WalletKeyError: If key storage fails.
- Description: Retrieve wallet address for a user.
- Parameters:
user_id(str): User identifier.
- Returns:
Optional[str]- Wallet address or None.
- Description: Check if a user has a wallet.
- Parameters:
user_id(str): User identifier.
- Returns:
bool
- Description: Sign a message using HMAC-SHA256 with the user's private key.
- Parameters:
user_id(str): User identifier.message(bytes): Message to sign.
- Returns:
bytes- HMAC-SHA256 signature (32 bytes). - Raises:
WalletNotFoundError: If wallet or key not found.
- Description: Verify a message signature using constant-time comparison.
- Parameters:
user_id(str): User identifier.message(bytes): Original message.signature(bytes): Signature to verify.
- Returns:
bool- True if valid. - Raises:
WalletNotFoundError: If wallet or key not found.
- Description: Generate new key material and wallet address, replacing the old ones.
- Parameters:
user_id(str): User identifier.reason(str): Reason for rotation (logged for audit trail).
- Returns:
str- New wallet address. - Raises:
WalletNotFoundError: If user has no wallet.WalletKeyError: If key storage fails.
- Description: Generate backup metadata (never includes raw keys).
- Parameters:
user_id(str): User identifier.
- Returns:
dictwith keys:user_id,wallet_id,key_hash,created_at,backup_ts. - Raises:
WalletNotFoundError: If user has no wallet.
- Description: Delete wallet and associated key file.
- Parameters:
user_id(str): User identifier.
- Returns:
bool- True on success. - Raises:
WalletNotFoundError: If user has no wallet.
- Description: List all registered wallets.
- Returns:
Dict[str, str]- Mapping of user_id to wallet_address.
Multi-factor knowledge-based key recovery system.
- Description: Initialize with empty ritual store and default lockout of 5 attempts.
- Description: Register a recovery ritual for a user.
- Parameters:
user_id(str): User identifier.steps(List[RitualStep]): Ordered recovery steps.
- Raises:
RitualError: If steps list is empty.
- Description: Attempt recovery by providing responses to all ritual steps.
- Parameters:
user_id(str): User identifier.responses(List[str]): Response strings, one per step.
- Returns:
bool- True if all responses match. - Raises:
RitualError: If user is locked out.
- Returns:
bool- True if ritual registered.
- Returns:
List[str]- Ritual prompt strings. - Raises:
RitualErrorif no ritual registered.
- Returns:
int- Remaining attempts before lockout.
- Returns:
bool- True if locked out.
- Description: Admin operation to reset attempt counter.
- Returns:
bool- True if a ritual was removed.
Encrypted wallet backup management.
- Parameters:
backup_dir(Optional[Path]): Backup storage directory.key_manager(Optional[KeyManager]): KeyManager instance.
- Returns:
dict- Backup record withbackup_id,user_id,wallet_id,key_hash,timestamp,metadata. - Raises:
WalletNotFoundErrorif key not found.
- Returns:
List[dict]- Backups sorted newest first.
- Returns:
bool- True if backup key hash matches current key. - Raises:
WalletNotFoundErrorif backup or key not found.
- Returns:
bool- True on success.
Policy-driven key rotation with audit trail.
- Parameters:
policy(Optional[RotationPolicy]): Rotation policy. Default: 90 days / 10000 sigs.
- Description: Register a wallet for rotation tracking.
- Description: Increment the signature counter for a user.
- Returns:
bool- True if rotation is recommended by policy.
- Returns:
RotationRecord- Audit record of the rotation.
- Returns:
List[RotationRecord]- Full rotation history. - Raises:
WalletNotFoundErrorif no history exists.
Simplified unified interface combining WalletManager and NaturalRitualRecovery.
- Parameters:
user_id(str): Owner's unique identifier.storage_path(Optional[Path]): Key storage directory.
Methods: create(), sign(message), verify(message, signature), rotate(reason), setup_recovery(steps), recover(responses), backup(), delete()
prompt(str): Challenge question.expected_response_hash(str): SHA-256 hex digest of expected answer.
user_id(str): User identifier.old_wallet_id(str): Previous wallet address.new_wallet_id(str): New wallet address.timestamp(str): ISO 8601 timestamp.reason(str): Rotation reason.
max_age_days(int): Maximum key age in days. Default: 90.max_signatures(int): Maximum signatures before rotation. Default: 10000.auto_rotate(bool): Enable automatic rotation. Default: False.
create_wallet(user_id, storage_path=None) -> str: Quick wallet creation.get_wallet_manager(storage_path=None) -> WalletManager: Get manager instance.hash_response(response: str) -> str: Hash a ritual response.
Current version: 0.1.0 (accessible via codomyrmex.wallet.__version__).