[docs]@model_validator(mode="after")defcompute_id(self):"""Automatically computes the id based on injected SID value."""self.id=sid_manager.next_sid(self.type)returnself
[docs]defcreate(self,network:str,label:str,private_key:str=None):""" Initiates the creation of a new single key wallet. :param network: "Constellation" or "Ethereum". :param private_key: Optional, the private key to create account for. Leaving empty will create a new account from new private key. :param label: The name of the wallet. """private_key=(private_keyorec.generate_private_key(curve=ec.SECP256K1(),backend=default_backend()).private_numbers().private_value.to_bytes(32,byteorder="big").hex())valid=re.fullmatch(r"^[a-fA-F0-9]{64}$",private_key)ifnotvalid:ValueError("SingleAccountWallet :: Private key is invalid.")self.deserialize(label=label,network=network,secret=private_key)
[docs]defset_label(self,label:str):""" Set the name of the wallet. :param label: The wallet name. """ifnotlabel:raiseValueError("SingleAccountWallet :: No label set.")self.label=label
[docs]defget_label(self)->str:""" Get the name of the wallet. :return: The wallet name. """returnself.label
[docs]@staticmethoddefimport_account():"""Not supported for SingleAccountWallet."""raiseValueError("SingleAccountWallet :: does not support importing of account.")
[docs]defget_account_by_address(self,address:str)->Union[DagAccount,EthAccount]:""" Get the account matching a specific address. :param address: The account address. :return: The account matching the address. """returnself.keyring.get_account_by_address(address)
[docs]defremove_account(self,account):"""Not supported by SAW."""raiseValueError("SingleChainWallet :: Does not allow removing accounts.")
[docs]defexport_secret_key(self)->str:""" Get the privat key. :return: Private key in hexadecimal string format. """return(self.keyring.get_accounts()[0].wallet.private_numbers().private_value.to_bytes(32,"big").hex())