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-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:
|
2020-09-29 14:24:18 +00:00
|
|
|
raise click.BadParameter('That is not a valid mnemonic, please check for typos')
|
2020-08-24 11:55:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
2020-09-28 14:49:37 +00:00
|
|
|
@click.pass_context
|
2020-08-24 11:55:06 +00:00
|
|
|
@click.option(
|
|
|
|
'--mnemonic',
|
2020-09-29 14:24:18 +00:00
|
|
|
callback=validate_mnemonic,
|
|
|
|
prompt='Please enter your mnemonic separated by spaces (" ")',
|
2020-08-24 11:55:06 +00:00
|
|
|
required=True,
|
|
|
|
type=str,
|
|
|
|
)
|
2020-09-29 14:24:18 +00:00
|
|
|
@click.password_option(
|
2020-08-24 11:55:06 +00:00
|
|
|
'--mnemonic-password',
|
2020-09-28 14:49:37 +00:00
|
|
|
default='',
|
2020-08-24 11:55:06 +00:00
|
|
|
)
|
2020-09-29 14:24:18 +00:00
|
|
|
@click.option(
|
|
|
|
'--validator_start_index',
|
|
|
|
confirmation_prompt=True,
|
|
|
|
default=0,
|
|
|
|
prompt='Enter the index (key number) you wish to start generating more keys from. \
|
|
|
|
For example, if you\'ve generated 4 keys in the past, you\'d enter 4 here,',
|
|
|
|
type=click.IntRange(0, 2**32),
|
|
|
|
)
|
|
|
|
@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:
|
|
|
|
ctx.obj = {'mnemonic': mnemonic, 'mnemonic_password': mnemonic_password}
|
|
|
|
ctx.forward(generate_keys)
|