staking-deposit-cli/staking_deposit/cli/new_mnemonic.py

64 lines
2.1 KiB
Python
Raw Normal View History

2020-08-24 11:55:06 +00:00
import click
from typing import (
Any,
2020-08-24 11:55:06 +00:00
)
2021-08-23 10:33:04 +00:00
from staking_deposit.key_handling.key_derivation.mnemonic import (
2020-08-24 11:55:06 +00:00
get_mnemonic,
)
2021-08-23 10:33:04 +00:00
from staking_deposit.utils.click import (
captive_prompt_callback,
choice_prompt_func,
jit_option,
)
2021-08-23 10:33:04 +00:00
from staking_deposit.utils.constants import (
MNEMONIC_LANG_OPTIONS,
WORD_LISTS_PATH,
)
2021-08-23 10:33:04 +00:00
from staking_deposit.utils.intl import (
fuzzy_reverse_dict_lookup,
load_text,
get_first_options,
)
from .generate_keys import (
generate_keys,
2020-09-28 15:20:08 +00:00
generate_keys_arguments_decorator,
2020-08-24 11:55:06 +00:00
)
languages = get_first_options(MNEMONIC_LANG_OPTIONS)
2020-08-24 11:55:06 +00:00
@click.command(
help=load_text(['arg_new_mnemonic', 'help'], func='new_mnemonic'),
)
@click.pass_context
@jit_option(
callback=captive_prompt_callback(
lambda mnemonic_language: fuzzy_reverse_dict_lookup(mnemonic_language, MNEMONIC_LANG_OPTIONS),
2021-05-04 13:46:32 +00:00
choice_prompt_func(lambda: load_text(['arg_mnemonic_language', 'prompt'], func='new_mnemonic'), languages),
),
default=lambda: load_text(['arg_mnemonic_language', 'default'], func='new_mnemonic'),
help=lambda: load_text(['arg_mnemonic_language', 'help'], func='new_mnemonic'),
param_decls='--mnemonic_language',
prompt=choice_prompt_func(lambda: load_text(['arg_mnemonic_language', 'prompt'], func='new_mnemonic'), languages),
2020-08-24 11:55:06 +00:00
)
2020-09-28 15:20:08 +00:00
@generate_keys_arguments_decorator
def new_mnemonic(ctx: click.Context, mnemonic_language: str, **kwargs: Any) -> None:
2020-08-24 11:55:06 +00:00
mnemonic = get_mnemonic(language=mnemonic_language, words_path=WORD_LISTS_PATH)
test_mnemonic = ''
while mnemonic != test_mnemonic:
click.clear()
click.echo(load_text(['msg_mnemonic_presentation']))
2020-08-24 11:55:06 +00:00
click.echo('\n\n%s\n\n' % mnemonic)
click.pause(load_text(['msg_press_any_key']))
2020-08-24 11:55:06 +00:00
click.clear()
test_mnemonic = click.prompt(load_text(['msg_mnemonic_retype_prompt']) + '\n\n')
2020-08-24 11:55:06 +00:00
test_mnemonic = test_mnemonic.lower()
click.clear()
# Do NOT use mnemonic_password.
ctx.obj = {'mnemonic': mnemonic, 'mnemonic_password': ''}
2020-09-29 14:24:18 +00:00
ctx.params['validator_start_index'] = 0
ctx.forward(generate_keys)