Wallet module¶
The wallet module provides cryptographic functionality for creating accounts, importing from mnemonics, and signing transactions for the Akash blockchain using secp256k1 cryptography.
AkashWallet Class¶
from akash import AkashWallet
wallet = AkashWallet.generate()
address = wallet.address
mnemonic = wallet.mnemonic
Constructor parameters¶
Parameter | Type | Default | Description |
---|---|---|---|
private_key |
SigningKey |
Required | The secp256k1 private key |
mnemonic |
Optional[str] |
None |
The mnemonic phrase (if created from mnemonic) |
Creation methods¶
generate()¶
Generate a new random wallet with proper BIP39 mnemonic.
@classmethod
def generate(strength: int = 128, passphrase: str = "", derivation_path: str = None) -> AkashWallet
Parameters:
strength
(int
): Entropy strength in bits (128, 160, 192, 224, 256)passphrase
(str
): Optional BIP39 passphrase for additional securityderivation_path
(str
): Optional custom derivation path (e.g., "m/44'/118'/0'/0/1"). Defaults to "m/44'/118'/0'/0/0"
Returns: AkashWallet
- New wallet instance
Example:
from akash import AkashWallet
wallet = AkashWallet.generate()
print(f"Address: {wallet.address}")
print(f"Mnemonic: {wallet.mnemonic}")
secure_wallet = AkashWallet.generate(256)
print(f"Secure mnemonic: {secure_wallet.mnemonic}")
wallet_custom = AkashWallet.generate(derivation_path="m/44'/118'/0'/0/1")
print(f"Custom path address: {wallet_custom.address}")
from_mnemonic()¶
Create wallet from BIP39 mnemonic phrase using proper BIP44 derivation.
@classmethod
def from_mnemonic(mnemonic: str, passphrase: str = "", derivation_path: str = None) -> AkashWallet
Parameters:
mnemonic
(str
): BIP39 mnemonic phrase (12, 15, 18, 21, or 24 words)passphrase
(str
): Optional BIP39 passphrase for additional securityderivation_path
(str
): Optional custom derivation path (e.g., "m/44'/118'/0'/0/1"). Defaults to "m/44'/118'/0'/0/0" (Cosmos standard)
Returns: AkashWallet
- Wallet instance derived from mnemonic
Example:
from akash import AkashWallet
mnemonic = ("poverty torch street hybrid estate message increase play negative "
"vibrant transfer six police tiny garment congress survey tired used "
"audit dolphin focus abstract appear")
wallet1 = AkashWallet.from_mnemonic(mnemonic)
print(f"Default path: {wallet1.address}")
wallet2 = AkashWallet.from_mnemonic(mnemonic, derivation_path="m/44'/118'/0'/0/1")
print(f"Custom path: {wallet2.address}")
from_private_key()¶
Create wallet from raw private key bytes.
Parameters:
private_key_bytes
(bytes
): 32-byte private key
Returns: AkashWallet
- Wallet instance
Example:
from akash import AkashWallet
import secrets
private_key = secrets.token_bytes(32)
wallet = AkashWallet.from_private_key(private_key)
print(f"Address: {wallet.address}")
Properties¶
address¶
Get the Akash address (bech32 format).
Returns: str
- Bech32 address with 'akash' prefix
Example:
mnemonic¶
Get the mnemonic phrase (if available).
Returns: Optional[str]
- Mnemonic phrase or None
Example:
from akash import AkashWallet
import secrets
wallet = AkashWallet.generate()
print(f"Mnemonic: {wallet.mnemonic}")
private_key = secrets.token_bytes(32)
wallet2 = AkashWallet.from_private_key(private_key)
print(f"Mnemonic: {wallet2.mnemonic}")
public_key¶
Get the public key.
Returns: VerifyingKey
- The public key object
Example:
from akash import AkashWallet
wallet = AkashWallet.generate()
pub_key = wallet.public_key
print(f"Public key type: {type(pub_key)}")
public_key_bytes¶
Get compressed public key bytes.
Returns: bytes
- 33-byte compressed public key
Example:
from akash import AkashWallet
wallet = AkashWallet.generate()
pub_bytes = wallet.public_key_bytes
print(f"Public key: {pub_bytes.hex()}")
print(f"Length: {len(pub_bytes)} bytes")
Signing methods¶
sign_transaction()¶
Sign transaction data for Akash blockchain.
Parameters:
tx_data
(Dict[str, Any]
): Transaction data to sign with the following fields:chain_id
(str
): Blockchain chain IDaccount_number
(str
): Account numbersequence
(str
): Transaction sequence numberfee
(Dict
): Transaction fee informationamount
(List[Dict]
): Fee amountsdenom
(str
): Token denominationamount
(str
): Fee amount
gas
(str
): Gas limit
msgs
(List[Dict]
): Transaction messagestype
(str
): Message typevalue
(Dict
): Message value[fields]
: Message type-specific fields (varies by message type)
memo
(str
): Transaction memo
Returns: Dict[str, Any]
- Signed transaction with signature and the following fields:
tx
(Dict
): Transaction datasignature
(Dict
): Transaction signaturesignature
(str
): Signature bytes (hex)pub_key
(Dict
): Public key informationtype
(str
): Public key type ("tendermint/PubKeySecp256k1")value
(str
): Public key value (hex)
mode
(str
): Broadcast mode ("sync")
Example:
from akash import AkashWallet
wallet = AkashWallet.from_mnemonic("your mnemonic here")
tx_data = {
"chain_id": "akashnet-2",
"account_number": "123",
"sequence": "1",
"fee": {"amount": [{"denom": "uakt", "amount": "5000"}], "gas": "200000"},
"msgs": [{"type": "akash/deployment-create", "value": {}}],
"memo": ""
}
signed_tx = wallet.sign_transaction(tx_data)
print(f"Signature: {signed_tx['signature']}")
sign_message()¶
Sign an arbitrary message.
Parameters:
message
(str
): Message to sign
Returns: str
- Hex-encoded signature
Example:
from akash import AkashWallet
wallet = AkashWallet.generate()
message = "Hello Akash Network"
signature = wallet.sign_message(message)
print(f"Message signature: {signature}")
is_valid = wallet.verify_signature(message, signature)
print(f"Signature valid: {is_valid}")
verify_signature()¶
Verify a signature against a message.
Parameters:
message
(str
): Original messagesignature_hex
(str
): Hex-encoded signature
Returns: bool
- True if signature is valid
Example:
from akash import AkashWallet
wallet = AkashWallet.generate()
message = "Test message"
signature = wallet.sign_message(message)
is_valid = wallet.verify_signature(message, signature)
print(f"Signature valid: {is_valid}")
is_invalid = wallet.verify_signature("Wrong message", signature)
print(f"Wrong message valid: {is_invalid}")
sign_raw()¶
Sign raw bytes with this wallet's private key.
Parameters:
data
(bytes
): Raw data to sign
Returns: bytes
- Signature bytes
Example:
from akash import AkashWallet
wallet = AkashWallet.generate()
data = b"raw data to sign"
signature = wallet.sign_raw(data)
print(f"Raw signature: {signature.hex()}")
Utility methods¶
validate_mnemonic()¶
Validate a BIP39 mnemonic phrase.
Parameters:
mnemonic
(str
): Mnemonic phrase to validate
Returns: bool
- True if mnemonic is valid
Example:
from akash import AkashWallet
valid = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
print(f"Valid: {AkashWallet.validate_mnemonic(valid)}")
invalid = "invalid mnemonic phrase"
print(f"Invalid: {AkashWallet.validate_mnemonic(invalid)}")
validate_address()¶
Validate an Akash bech32 address.
Parameters:
address
(str
): Address to validate
Returns: bool
- True if address is valid
Example:
from akash import AkashWallet
valid_addr = "akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4"
print(f"Valid: {AkashWallet.validate_address(valid_addr)}")
print(f"Invalid: {AkashWallet.validate_address('not_an_address')}")
print(f"Wrong prefix: {AkashWallet.validate_address('cosmos1...')}")
Usage examples¶
Basic wallet creation¶
from akash import AkashWallet
wallet1 = AkashWallet.generate()
print(f"New wallet: {wallet1.address}")
print(f"Mnemonic: {wallet1.mnemonic}")
mnemonic = "poverty torch street hybrid estate message increase play negative vibrant transfer six police tiny garment congress survey tired used audit dolphin focus abstract appear"
wallet2 = AkashWallet.from_mnemonic(mnemonic)
print(f"Imported wallet: {wallet2.address}")
import secrets
private_key = secrets.token_bytes(32)
wallet3 = AkashWallet.from_private_key(private_key)
print(f"Private key wallet: {wallet3.address}")
Message signing workflow¶
from akash import AkashWallet
wallet = AkashWallet.generate()
messages = ["Message 1", "Message 2", "Message 3"]
signatures = []
for message in messages:
signature = wallet.sign_message(message)
signatures.append(signature)
print(f"Signed: {message}")
for message, signature in zip(messages, signatures):
is_valid = wallet.verify_signature(message, signature)
print(f"'{message}' valid: {is_valid}")
Address validation¶
from akash import AkashWallet
addresses_to_test = [
"akash1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4",
"akash1invalidaddress",
"cosmos1qnnhhgzxj24f2kld5yhy4v4h4s9r295ak5gjw4",
"not_an_address"
]
for addr in addresses_to_test:
is_valid = AkashWallet.validate_address(addr)
print(f"{addr}: {'Valid' if is_valid else 'Invalid'}")