Skip to content
Snippets Groups Projects
Commit 1b0ec710 authored by Mateusz Żebrak's avatar Mateusz Żebrak
Browse files

Make keys stored in profile (and not account)

parent 6f7c0f3b
No related branches found
No related tags found
2 merge requests!412V1.27.5.13 release,!408Make keys stored in profile (and not account)
Showing
with 22 additions and 23 deletions
......@@ -85,7 +85,7 @@ class PerformActionsOnTransactionCommand(WorldBasedCommand, ABC):
return None
try:
return self.world.profile_data.working_account.keys.get(self.sign)
return self.world.profile_data.keys.get(self.sign)
except KeyNotFoundError:
raise CLIPrettyError(
f"Key `{self.sign}` was not found in the working account keys.", errno.ENOENT
......
......@@ -52,7 +52,7 @@ class AddKey(WorldBasedCommand):
if not profile_data.is_working_account_set():
raise CLIWorkingAccountIsNotSetError(profile_data)
key_manager = profile_data.working_account.keys
key_manager = profile_data.keys
alias_result = PublicKeyAliasValidator(key_manager, validate_like_adding_new=True).validate(
self.get_actual_alias()
)
......@@ -68,7 +68,7 @@ class AddKey(WorldBasedCommand):
profile_data = self.world.profile_data
typer.echo("Importing key...")
profile_data.working_account.keys.add_to_import(self.private_key_aliased)
profile_data.keys.add_to_import(self.private_key_aliased)
try:
await self.world.commands.activate(password=self.password)
......@@ -99,7 +99,7 @@ class RemoveKey(WorldBasedCommand):
typer.echo(f"Removing a key aliased with `{self.alias}`...")
public_key = profile_data.working_account.keys.get(self.alias)
public_key = profile_data.keys.get(self.alias)
self.__remove_key_association_from_the_profile(public_key)
......@@ -114,7 +114,7 @@ class RemoveKey(WorldBasedCommand):
typer.echo(message)
def __remove_key_association_from_the_profile(self, key: PublicKeyAliased) -> None:
self.world.profile_data.working_account.keys.remove(key)
self.world.profile_data.keys.remove(key)
async def __remove_key_from_the_beekeeper(self, key: PublicKeyAliased) -> None:
activate_wrapper = await self.world.commands.activate(password=self.password)
......
......@@ -14,5 +14,5 @@ class ShowKeys(ProfileBasedCommand):
if not self.profile_data.is_working_account_set():
raise CLIWorkingAccountIsNotSetError(self.profile_data)
public_keys = list(self.profile_data.working_account.keys)
public_keys = list(self.profile_data.keys)
typer.echo(f"{profile_name}, your keys are:\n{public_keys}")
......@@ -33,4 +33,4 @@ class SyncDataWithBeekeeper(CommandInActive, Command):
beekeeper=self.beekeeper,
).execute_with_result()
await self.profile_data.working_account.keys.import_pending_to_beekeeper(import_key)
await self.profile_data.keys.import_pending_to_beekeeper(import_key)
......@@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Any, Final
from clive.__private import config
from clive.__private.config import settings
from clive.__private.core.clive_import import get_clive
from clive.__private.core.keys import KeyManager
from clive.__private.core.validate_schema_field import is_schema_field_valid
from clive.__private.logger import logger
from clive.__private.storage.accounts import Account, WorkingAccount
......@@ -118,6 +119,7 @@ class ProfileData(Context):
self.__chain_id = self.__default_chain_id()
self.cart = Cart()
self.keys = KeyManager()
if address := self.__get_secret_node_address():
self.__backup_node_addresses = [address]
......
......@@ -7,7 +7,6 @@ from typing import TYPE_CHECKING
from pydantic import ValidationError
from clive.__private.core.alarms.alarms_storage import AlarmsStorage
from clive.__private.core.keys import KeyManager
from clive.__private.core.validate_schema_field import validate_schema_field
from clive.exceptions import CliveError
from clive.models.aliased import AccountName
......@@ -116,7 +115,5 @@ class Account:
@dataclass
class WorkingAccount(Account):
keys: KeyManager = field(init=False, default_factory=KeyManager, compare=False)
def __hash__(self) -> int:
return super().__hash__()
......@@ -47,7 +47,7 @@ class EditKeyAlias(KeyAliasForm):
old_alias = self.public_key.alias
new_alias = self._key_alias_input.value_or_error
self.app.world.profile_data.working_account.keys.rename(old_alias, new_alias)
self.app.world.profile_data.keys.rename(old_alias, new_alias)
self.app.trigger_profile_data_watchers()
self.app.post_message_to_screen("ManageKeyAliases", self.Changed())
......
......@@ -65,7 +65,7 @@ class KeyAlias(CliveCheckerboardTableRow, CliveWidget):
if not result:
return
self.app.world.profile_data.working_account.keys.remove(self.__public_key)
self.app.world.profile_data.keys.remove(self.__public_key)
self.notify(f"Key alias `{self.__public_key.alias}` was removed.")
self.app.post_message_to_screen(ManageKeyAliases, self.Changed())
......@@ -91,7 +91,7 @@ class ManageKeyAliasesTable(CliveCheckerboardTable):
def create_static_rows(self) -> list[KeyAlias]:
key_aliases = []
for idx, key in enumerate(self.app.world.profile_data.working_account.keys):
for idx, key in enumerate(self.app.world.profile_data.keys):
key_aliases.append(KeyAlias(idx, key))
return key_aliases
......
......@@ -161,7 +161,7 @@ class NewKeyAlias(NewKeyAliasBase):
@CliveScreen.try_again_after_activation
@on(NewKeyAliasBase.Saved)
async def new_key_alias_base_saved(self, event: NewKeyAliasBase.Saved) -> None:
self.context.working_account.keys.set_to_import([event.private_key])
self.context.keys.set_to_import([event.private_key])
await self.app.world.commands.sync_data_with_beekeeper()
self.app.trigger_profile_data_watchers()
......@@ -201,7 +201,7 @@ class NewKeyAliasForm(NewKeyAliasBase, FormScreen[ProfileData]):
@on(NewKeyAliasBase.Saved)
def new_key_alias_base_saved(self, event: NewKeyAliasBase.Saved) -> None:
self.context.working_account.keys.set_to_import([event.private_key])
self.context.keys.set_to_import([event.private_key])
logger.debug("New private key is waiting to be imported...")
async def apply_and_validate(self) -> None:
......
......@@ -38,7 +38,7 @@ class KeyAliasForm(BaseScreen, Contextual[ProfileData], ABC):
self._key_alias_input = PublicKeyAliasInput(
value=self._default_key_alias_name(),
setting_key_alias=True,
key_manager=self.context.working_account.keys,
key_manager=self.context.keys,
required=self.IS_KEY_ALIAS_REQUIRED,
)
self._public_key_input = LabelizedInput(
......
......@@ -132,7 +132,7 @@ class OperationActionBindings(CliveWidget, AbstractClassMessagePump):
async def __fast_broadcast(self) -> None:
def get_key() -> PublicKeyAliased | None:
try:
return self.app.world.profile_data.working_account.keys.first
return self.app.world.profile_data.keys.first
except KeyNotFoundError:
self.notify("No keys found for the working account.", severity="error")
return None
......
......@@ -70,12 +70,12 @@ class SelectKey(SafeSelect[PublicKey], CliveWidget):
def __init__(self) -> None:
try:
first_value: PublicKey | NoSelection = self.app.world.profile_data.working_account.keys.first
first_value: PublicKey | NoSelection = self.app.world.profile_data.keys.first
except KeyNotFoundError:
first_value = Select.BLANK
super().__init__(
[(key.alias, key) for key in self.app.world.profile_data.working_account.keys],
[(key.alias, key) for key in self.app.world.profile_data.keys],
value=first_value,
empty_string="no private key found",
)
......
......@@ -43,7 +43,7 @@ class PublicKeyAliasInput(TextInput):
setting_key_alias: Whether setting public key alias or just getting key alias for other purpose.
key_manager: Key manager to use for validation. If not provided, the key manager from the world will be used.
"""
key_manager = key_manager if key_manager is not None else self.app.world.profile_data.working_account.keys
key_manager = key_manager if key_manager is not None else self.app.world.profile_data.keys
super().__init__(
title=title,
......
......@@ -78,7 +78,7 @@ async def prepare_profile(node: tt.RawNode) -> None:
).execute_with_result()
tt.logger.info(f"password for {WORKING_ACCOUNT_DATA.account.name} is: `{password}`")
world.profile_data.working_account.keys.add_to_import(
world.profile_data.keys.add_to_import(
PrivateKeyAliased(
value=WORKING_ACCOUNT_DATA.account.private_key, alias=f"{WORKING_ACCOUNT_DATA.account.name}_key"
)
......
......@@ -38,7 +38,7 @@ async def prepare_beekeeper_wallet(world: World) -> None:
password = (await world.commands.create_wallet(password=WORKING_ACCOUNT_PASSWORD)).result_or_raise
tt.logger.info(f"password for {WORKING_ACCOUNT_DATA.account.name} is: `{password}`")
world.profile_data.working_account.keys.add_to_import(
world.profile_data.keys.add_to_import(
PrivateKeyAliased(value=WORKING_ACCOUNT_DATA.account.private_key, alias=f"{WORKING_ACCOUNT_KEY_ALIAS}")
)
await world.commands.sync_data_with_beekeeper()
......
......@@ -57,7 +57,7 @@ async def prepare_beekeeper_wallet(prepare_profile: ProfileData, world: World) -
password = (await world.commands.create_wallet(password=WORKING_ACCOUNT_PASSWORD)).result_or_raise
tt.logger.info(f"password for {WORKING_ACCOUNT_DATA.account.name} is: `{password}`")
world.profile_data.working_account.keys.add_to_import(
world.profile_data.keys.add_to_import(
PrivateKeyAliased(value=WORKING_ACCOUNT_DATA.account.private_key, alias=WORKING_ACCOUNT_KEY_ALIAS)
)
await world.commands.sync_data_with_beekeeper()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment