2020-08-24 11:55:06 +00:00
|
|
|
import click
|
|
|
|
from typing import (
|
2020-09-28 14:49:37 +00:00
|
|
|
Any,
|
2020-08-24 11:55:06 +00:00
|
|
|
)
|
|
|
|
|
2020-10-26 16:51:38 +00:00
|
|
|
from eth2deposit.exceptions import ValidationError
|
2021-02-12 16:55:39 +00:00
|
|
|
from eth2deposit.intl.utils import load_text
|
2020-09-28 14:49:37 +00:00
|
|
|
from eth2deposit.key_handling.key_derivation.mnemonic import (
|
2020-08-24 11:55:06 +00:00
|
|
|
verify_mnemonic,
|
|
|
|
)
|
2020-09-28 14:49:37 +00:00
|
|
|
from eth2deposit.utils.constants import (
|
2020-08-24 11:55:06 +00:00
|
|
|
WORD_LISTS_PATH,
|
|
|
|
)
|
2020-09-28 14:49:37 +00:00
|
|
|
from .generate_keys import (
|
|
|
|
generate_keys,
|
2020-09-28 15:20:08 +00:00
|
|
|
generate_keys_arguments_decorator,
|
2020-09-28 14:49:37 +00:00
|
|
|
)
|
2020-08-24 11:55:06 +00:00
|
|
|
|
|
|
|
|
2020-09-29 14:24:18 +00:00
|
|
|
def validate_mnemonic(cts: click.Context, param: Any, mnemonic: str) -> str:
|
2020-08-24 11:55:06 +00:00
|
|
|
if verify_mnemonic(mnemonic, WORD_LISTS_PATH):
|
|
|
|
return mnemonic
|
|
|
|
else:
|
2021-02-12 16:55:39 +00:00
|
|
|
raise ValidationError(load_text('en', ['err_invalid_mnemonic']))
|
2020-08-24 11:55:06 +00:00
|
|
|
|
|
|
|
|
2020-11-03 14:43:18 +00:00
|
|
|
@click.command(
|
2021-02-12 16:55:39 +00:00
|
|
|
help=load_text('en', ['arg_existing_mnemonic', 'help']),
|
2020-11-03 14:43:18 +00:00
|
|
|
)
|
2020-09-28 14:49:37 +00:00
|
|
|
@click.pass_context
|
2020-08-24 11:55:06 +00:00
|
|
|
@click.option(
|
2021-02-12 16:55:39 +00:00
|
|
|
load_text('en', ['arg_mnemonic', 'argument']),
|
2020-09-29 14:24:18 +00:00
|
|
|
callback=validate_mnemonic,
|
2021-02-12 16:55:39 +00:00
|
|
|
help=load_text('en', ['arg_mnemonic', 'help']),
|
|
|
|
prompt=load_text('en', ['arg_mnemonic', 'prompt']),
|
2020-08-24 11:55:06 +00:00
|
|
|
required=True,
|
|
|
|
type=str,
|
|
|
|
)
|
2020-09-29 14:24:18 +00:00
|
|
|
@click.password_option(
|
2021-02-12 16:55:39 +00:00
|
|
|
load_text('en', ['arg_mnemonic_password', 'argument']),
|
2020-09-28 14:49:37 +00:00
|
|
|
default='',
|
2021-02-12 16:55:39 +00:00
|
|
|
help=load_text('en', ['arg_mnemonic_password', 'help']),
|
2020-10-20 13:50:46 +00:00
|
|
|
prompt=False,
|
2020-08-24 11:55:06 +00:00
|
|
|
)
|
2020-09-29 14:24:18 +00:00
|
|
|
@click.option(
|
2021-02-12 16:55:39 +00:00
|
|
|
load_text('en', ['arg_validator_start_index', 'argument']),
|
2020-09-29 14:24:18 +00:00
|
|
|
confirmation_prompt=True,
|
|
|
|
default=0,
|
2021-02-12 16:55:39 +00:00
|
|
|
help=load_text('en', ['arg_validator_start_index', 'help']),
|
|
|
|
prompt=load_text('en', ['arg_validator_start_index', 'prompt']),
|
2020-11-03 11:29:47 +00:00
|
|
|
type=click.IntRange(0, 2**32 - 1),
|
2020-09-29 14:24:18 +00:00
|
|
|
)
|
|
|
|
@generate_keys_arguments_decorator
|
2020-09-28 14:49:37 +00:00
|
|
|
def existing_mnemonic(ctx: click.Context, mnemonic: str, mnemonic_password: str, **kwargs: Any) -> None:
|
2020-10-20 13:50:46 +00:00
|
|
|
if mnemonic_password != '':
|
|
|
|
click.clear()
|
2021-02-12 16:55:39 +00:00
|
|
|
click.confirm(load_text('en', ['msg_mnemonic_password_confirm']), abort=True)
|
2020-10-20 13:50:46 +00:00
|
|
|
|
2020-09-28 14:49:37 +00:00
|
|
|
ctx.obj = {'mnemonic': mnemonic, 'mnemonic_password': mnemonic_password}
|
|
|
|
ctx.forward(generate_keys)
|