[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):""" Create new multi key wallet. Accounts must be imported. :param network: "Constellation" or "Ethereum" :param label: The wallet name. """self.deserialize(label=label,network=network)
[docs]defset_label(self,val:str):""" Set the name of the wallet. :param val: The wallet name. """ifnotval:raiseValueError("MultiKeyWallet :: No label set.")self.label=val
[docs]defget_label(self)->str:""" Get the name of the wallet. :return: The wallet name. """returnself.label
[docs]@staticmethoddefget_network():"""Not supported by MKW."""raiseNotImplementedError("MultiChainWallet :: Multi key wallets does not support this method.")
[docs]defimport_account(self,private_key:str,label:str)->Union[DagAccount,EthAccount]:""" Imports an account using private key, sets a label, creates a keyring and adds it to the list of keyrings. :param private_key: The private key of the account to import. :param label: Name of the account. :return: The account. """keyring=SimpleKeyring()valid=re.fullmatch(r"^[a-fA-F0-9]{64}$",private_key)ifnotvalid:ValueError("MultiAccountWallet :: Private key is invalid.")keyring.deserialize(network=self.network,accounts=[{"private_key":private_key,"label":label}],)self.keyrings.append(keyring)# Only one account at index 0 present for this wallet typereturnkeyring.get_accounts()[0]
[docs]defget_accounts(self)->List[Union[DagAccount,EthAccount]]:""" Get a list of all MKW accounts. :return: List of imported MKW accounts. """return[accountforkeyringinself.keyringsforaccountinkeyring.get_accounts()]
[docs]defget_account_by_address(self,address:str)->Union[DagAccount,EthAccount]:""" Get the account matching the specified address. :param address: The address matching the account. """account=Noneforkeyringinself.keyrings:account=keyring.get_account_by_address(address)ifaccount:breakreturnaccount
[docs]@staticmethoddefremove_account():"""Not supported by MKW."""raiseValueError("MultiKeyWallet :: Does not allow removing accounts.")
[docs]@staticmethoddefexport_secret_key():"""Not supported by MKW."""raiseValueError("MultiKeyWallet :: Does not allow exporting secrets.")