aea.crypto.base
Abstract module wrapping the public and private key cryptography and ledger api.
Crypto Objects
Base class for a crypto object.
__init__
| __init__(private_key_path: Optional[str] = None, password: Optional[str] = None, **kwargs: Any, ,) -> None
Initialize the crypto object.
The actual behaviour of this constructor is determined by the abstract methods 'generate_private_key()' and 'load_private_key_from_path(). Either way, the entity object will be accessible as a property.
Arguments:
private_key_path: the path to the private key. If None, the key will be generated by 'generate_private_key()'. If not None, the path will be processed by 'load_private_key_from_path()'.password: the password to encrypt/decrypt the private key.kwargs: keyword arguments.
generate_private_key
Generate a private key.
Returns:
the entity object. Implementation dependent.
load_private_key_from_path
| @classmethod
| @abstractmethod
| load_private_key_from_path(cls, file_name: str, password: Optional[str] = None) -> EntityClass
Load a private key in hex format for raw private key and json format for encrypted private key from a file.
Arguments:
file_name: the path to the hex/json file.password: the password to encrypt/decrypt the private key.
Returns:
the entity object.
entity
Return an entity object.
Returns:
an entity object
private_key
Return a private key.
Returns:
a private key string
public_key
Return a public key.
Returns:
a public key string
address
Return the address.
Returns:
an address string
sign_message
Sign a message in bytes string form.
Arguments:
message: the message to be signedis_deprecated_mode: if the deprecated signing is used
Returns:
signature of the message in string form
sign_transaction
Sign a transaction in dict form.
Arguments:
transaction: the transaction to be signed
Returns:
signed transaction
load
Load private key from file.
Arguments:
private_key_file: the file where the key is stored.password: the password to encrypt/decrypt the private key.
Returns:
private_key in hex string format
dump
Dump private key to file.
Arguments:
private_key_file: the file where the key is stored.password: the password to encrypt/decrypt the private key.
encrypt
Encrypt the private key and return in json.
Arguments:
password: the password to decrypt.
Returns:
json string containing encrypted private key.
decrypt
Decrypt the private key and return in raw form.
Arguments:
keyfile_json: json string containing encrypted private key.password: the password to decrypt.
Returns:
the raw private key.
Helper Objects
Interface for helper class usable as Mixin for LedgerApi or as standalone class.
is_transaction_settled
Check whether a transaction is settled or not.
Arguments:
tx_receipt: the receipt associated to the transaction.
Returns:
True if the transaction has been settled, False o/w.
is_transaction_valid
| @staticmethod
| @abstractmethod
| is_transaction_valid(tx: JSONLike, seller: Address, client: Address, tx_nonce: str, amount: int) -> bool
Check whether a transaction is valid or not.
Arguments:
tx: the transaction.seller: the address of the seller.client: the address of the client.tx_nonce: the transaction nonce.amount: the amount we expect to get from the transaction.
Returns:
True if the random_message is equals to tx['input']
get_contract_address
Get the contract address from a transaction receipt.
Arguments:
tx_receipt: the transaction digest
Returns:
the contract address if successful
generate_tx_nonce
Generate a unique hash to distinguish transactions with the same terms.
Arguments:
seller: the address of the seller.client: the address of the client.
Returns:
return the hash in hex.
get_address_from_public_key
Get the address from the public key.
Arguments:
public_key: the public key
Returns:
str
recover_message
| @classmethod
| @abstractmethod
| recover_message(cls, message: bytes, signature: str, is_deprecated_mode: bool = False) -> Tuple[Address, ...]
Recover the addresses from the hash.
Arguments:
message: the message we expectsignature: the transaction signatureis_deprecated_mode: if the deprecated signing was used
Returns:
the recovered addresses
recover_public_keys_from_message
| @classmethod
| @abstractmethod
| recover_public_keys_from_message(cls, message: bytes, signature: str, is_deprecated_mode: bool = False) -> Tuple[str, ...]
Get the public key used to produce the signature of the message
Arguments:
message: raw bytes used to produce signaturesignature: signature of the messageis_deprecated_mode: if the deprecated signing was used
Returns:
the recovered public keys
get_hash
Get the hash of a message.
Arguments:
message: the message to be hashed.
Returns:
the hash of the message.
is_valid_address
Check if the address is valid.
Arguments:
address: the address to validate
load_contract_interface
Load contract interface.
Arguments:
file_path: the file path to the interface
Returns:
the interface
LedgerApi Objects
Interface for ledger APIs.
api
Get the underlying API object.
This can be used for low-level operations with the concrete ledger APIs. If there is no such object, return None.
get_balance
Get the balance of a given account.
This usually takes the form of a web request to be waited synchronously.
Arguments:
address: the address.
Returns:
the balance.
get_state
Call a specified function on the underlying ledger API.
This usually takes the form of a web request to be waited synchronously.
Arguments:
callable_name: the name of the API function to be called.args: the positional arguments for the API function.kwargs: the keyword arguments for the API function.
Returns:
the ledger API response.
get_transfer_transaction
| @abstractmethod
| get_transfer_transaction(sender_address: Address, destination_address: Address, amount: int, tx_fee: int, tx_nonce: str, **kwargs: Any, ,) -> Optional[JSONLike]
Submit a transfer transaction to the ledger.
Arguments:
sender_address: the sender address of the payer.destination_address: the destination address of the payee.amount: the amount of wealth to be transferred.tx_fee: the transaction fee.tx_nonce: verifies the authenticity of the txkwargs: the keyword arguments.
Returns:
the transfer transaction
send_signed_transaction
Send a signed transaction and wait for confirmation.
Use keyword arguments for the specifying the signed transaction payload.
Arguments:
tx_signed: the signed transaction
get_transaction_receipt
Get the transaction receipt for a transaction digest.
Arguments:
tx_digest: the digest associated to the transaction.
Returns:
the tx receipt, if present
get_transaction
Get the transaction for a transaction digest.
Arguments:
tx_digest: the digest associated to the transaction.
Returns:
the tx, if present
get_contract_instance
| @abstractmethod
| get_contract_instance(contract_interface: Dict[str, str], contract_address: Optional[str] = None) -> Any
Get the instance of a contract.
Arguments:
contract_interface: the contract interface.contract_address: the contract address.
Returns:
the contract instance
get_deploy_transaction
| @abstractmethod
| get_deploy_transaction(contract_interface: Dict[str, str], deployer_address: Address, **kwargs: Any, ,) -> Optional[JSONLike]
Get the transaction to deploy the smart contract.
Arguments:
contract_interface: the contract interface.deployer_address: The address that will deploy the contract.kwargs: the keyword arguments. :returns tx: the transaction dictionary.
update_with_gas_estimate
Attempts to update the transaction with a gas estimate
Arguments:
transaction: the transaction
Returns:
the updated transaction
FaucetApi Objects
Interface for testnet faucet APIs.
get_wealth
Get wealth from the faucet for the provided address.
Arguments:
address: the address.url: the url
Returns:
None