Skip to content

Commit

Permalink
Move remainder of messages into json files
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlBeek committed Feb 22, 2021
1 parent 3924b16 commit 5fceda2
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 19 deletions.
16 changes: 9 additions & 7 deletions eth2deposit/cli/new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Any,
)

from eth2deposit.intl.utils import load_text
from eth2deposit.key_handling.key_derivation.mnemonic import (
get_languages,
get_mnemonic,
Expand All @@ -18,14 +19,14 @@


@click.command(
help='Generate a new mnemonic and keys',
help=load_text('en', ['arg_new_mnemonic', 'help']),
)
@click.pass_context
@click.option(
'--mnemonic_language',
default='english',
help='The language that your mnemonic is in.',
prompt='Please choose your mnemonic language',
load_text('en', ['arg_mnemonic_language', 'argument']),
default=load_text('en', ['arg_mnemonic_language', 'default']),
help=load_text('en', ['arg_mnemonic_language', 'help']),
prompt=load_text('en', ['arg_mnemonic_language', 'prompt']),
type=click.Choice(languages, case_sensitive=False),
)
@generate_keys_arguments_decorator
Expand All @@ -34,12 +35,13 @@ def new_mnemonic(ctx: click.Context, mnemonic_language: str, **kwargs: Any) -> N
test_mnemonic = ''
while mnemonic != test_mnemonic:
click.clear()
# ToDo: Figure out why changing this line causes pytest to get stuck collecting.
click.echo('This is your seed phrase. Write it down and store it safely, it is the ONLY way to retrieve your deposit.') # noqa: E501
click.echo('\n\n%s\n\n' % mnemonic)
click.pause('Press any key when you have written down your mnemonic.')
click.pause(load_text('en', ['msg_press_any_key']))

click.clear()
test_mnemonic = click.prompt('Please type your mnemonic (separated by spaces) to confirm you have written it down\n\n') # noqa: E501
test_mnemonic = click.prompt(load_text('en', ['msg_mnemonic_retype_prompt']))
test_mnemonic = test_mnemonic.lower()
click.clear()
# Do NOT use mnemonic_password.
Expand Down
10 changes: 6 additions & 4 deletions eth2deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Dict, List
from py_ecc.bls import G2ProofOfPossession as bls

from eth2deposit.intl.utils import load_text
from eth2deposit.exceptions import ValidationError
from eth2deposit.key_handling.key_derivation.path import mnemonic_and_path_to_key
from eth2deposit.key_handling.keystore import (
Expand Down Expand Up @@ -135,19 +136,19 @@ def from_mnemonic(cls,
f"The number of keys ({num_keys}) doesn't equal to the corresponding deposit amounts ({len(amounts)})."
)
key_indices = range(start_index, start_index + num_keys)
with click.progressbar(key_indices, label='Creating your keys:\t\t',
with click.progressbar(key_indices, label=load_text('en', ['msg_key_creation']),
show_percent=False, show_pos=True) as indices:
return cls([Credential(mnemonic=mnemonic, mnemonic_password=mnemonic_password,
index=index, amount=amounts[index - start_index], chain_setting=chain_setting)
for index in indices])

def export_keystores(self, password: str, folder: str) -> List[str]:
with click.progressbar(self.credentials, label='Creating your keystores:\t',
with click.progressbar(self.credentials, label=load_text('en', ['msg_keystore_creation']),
show_percent=False, show_pos=True) as credentials:
return [credential.save_signing_keystore(password=password, folder=folder) for credential in credentials]

def export_deposit_data_json(self, folder: str) -> str:
with click.progressbar(self.credentials, label='Creating your depositdata:\t',
with click.progressbar(self.credentials, label=load_text('en', ['msg_depositdata_creation']),
show_percent=False, show_pos=True) as credentials:
deposit_data = [cred.deposit_datum_dict for cred in credentials]
filefolder = os.path.join(folder, 'deposit_data-%i.json' % time.time())
Expand All @@ -158,7 +159,8 @@ def export_deposit_data_json(self, folder: str) -> str:
return filefolder

def verify_keystores(self, keystore_filefolders: List[str], password: str) -> bool:
with click.progressbar(zip(self.credentials, keystore_filefolders), label='Verifying your keystores:\t',
with click.progressbar(zip(self.credentials, keystore_filefolders),
label=load_text('en', ['msg_keystore_verification']),
length=len(self.credentials), show_percent=False, show_pos=True) as items:
return all(credential.verify_keystore(keystore_filefolder=filefolder, password=password)
for credential, filefolder in items)
3 changes: 2 additions & 1 deletion eth2deposit/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from eth2deposit.cli.existing_mnemonic import existing_mnemonic
from eth2deposit.cli.new_mnemonic import new_mnemonic
from eth2deposit.intl.utils import load_text


def check_python_version() -> None:
'''
Checks that the python version running is sufficient and exits if not.
'''
if sys.version_info < (3, 7):
click.pause('Your python version is insufficient, please install version 3.7 or greater.')
click.pause(load_text('en', ['err_python_version']))
sys.exit()


Expand Down
2 changes: 1 addition & 1 deletion eth2deposit/intl/en/cli/existing_mnemonic.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"existing_mnemonic": {
"msg_mnemonic_password_confirm": "Are you absolutely certain that you used a mnemonic password? (This is different from a keystore password!) Using one when you are not supposed to can result in loss of funds!"
}
}
}
6 changes: 3 additions & 3 deletions eth2deposit/intl/en/cli/generate_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"keystore_password": {
"argument": "--keystore_password",
"help": "The version of eth2 you are targeting. Use \"mainnet\" if you are depositing ETH",
"prompt": "The password that will secure your keystores. You will need to re-enter this to decrypt them when you setup your eth2 validators. (It is reccomened not to use this argument, and wait for the CLI to ask you for your mnemonic as otherwise it will appear in your shell history.)"
"help": "The password that will secure your keystores. You will need to re-enter this to decrypt them when you setup your eth2 validators. (It is reccomened not to use this argument, and wait for the CLI to ask you for your mnemonic as otherwise it will appear in your shell history.)",
"prompt": "The password that will secure your keystores. You will need to re-enter this to decrypt them when you setup your eth2 validators."
}
},
"generate_keys": {
Expand All @@ -32,4 +32,4 @@
"err_verify_keystores": "Failed to verify the keystores.",
"err_verify_deposit": "Failed to verify the deposit data JSON files."
}
}
}
18 changes: 18 additions & 0 deletions eth2deposit/intl/en/cli/new_mnemonic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"<module>": {
"arg_new_mnemonic": {
"help": "Generate a new mnemonic and keys"
},
"arg_mnemonic_language": {
"argument": "--mnemonic_language",
"default": "english",
"help": "The language that your mnemonic is in",
"prompt": "Please choose your mnemonic language"
}
},
"new_mnemonic": {
"msg_mnemonic_presentation": "This is your mnemonic (seed phrase). Write it down and store it safely, it is the ONLY way to retrieve your deposit.",
"msg_press_any_key": "Press any key when you have written down your mnemonic.",
"msg_mnemonic_retype_prompt": "Please type your mnemonic (separated by spaces) to confirm you have written it down\n\n"
}
}
14 changes: 14 additions & 0 deletions eth2deposit/intl/en/credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"from_mnemonic": {
"msg_key_creation": "Creating your keys:\t\t"
},
"export_keystores": {
"msg_keystore_creation": "Creating your keystores:\t"
},
"export_deposit_data_json": {
"msg_depositdata_creation": "Creating your depositdata:\t"
},
"verify_keystores": {
"msg_keystore_verification": "Verifying your keystores:\t"
}
}
5 changes: 5 additions & 0 deletions eth2deposit/intl/en/deposit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"check_python_version": {
"err_python_version": "Your python version is insufficient, please install version 3.7 or greater."
}
}
8 changes: 8 additions & 0 deletions eth2deposit/intl/en/utils/validation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"verify_deposit_data_json": {
"msg_deposit_verification": "Verifying your deposits:\t"
},
"validate_password_strength": {
"msg_password_length": "The password length should be at least 8. Please retype"
}
}
2 changes: 1 addition & 1 deletion eth2deposit/intl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def _get_from_dict(dataDict: Dict[str, Any], mapList: List[str]) -> str:
'''
Iterate nested dictionary
Iterate nested dictionaries
'''
return reduce(dict.get, mapList, dataDict) # type: ignore

Expand Down
5 changes: 3 additions & 2 deletions eth2deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from py_ecc.bls import G2ProofOfPossession as bls

from eth2deposit.exceptions import ValidationError
from eth2deposit.intl.utils import load_text
from eth2deposit.utils.ssz import (
compute_deposit_domain,
compute_signing_root,
Expand All @@ -27,7 +28,7 @@ def verify_deposit_data_json(filefolder: str) -> bool:
"""
with open(filefolder, 'r') as f:
deposit_json = json.load(f)
with click.progressbar(deposit_json, label='Verifying your deposits:\t',
with click.progressbar(deposit_json, label=load_text('en', ['msg_deposit_verification']),
show_percent=False, show_pos=True) as deposits:
return all([validate_deposit(deposit) for deposit in deposits])
return False
Expand Down Expand Up @@ -68,4 +69,4 @@ def validate_deposit(deposit_data_dict: Dict[str, Any]) -> bool:

def validate_password_strength(password: str) -> None:
if len(password) < 8:
raise ValidationError(f"The password length should be at least 8. Got {len(password)}. Please retype")
raise ValidationError(load_text('en', ['msg_password_length']))

0 comments on commit 5fceda2

Please sign in to comment.