Skip to content

Commit

Permalink
Merge pull request #164 from ethereum/dev
Browse files Browse the repository at this point in the history
Release v1.1.0 to master
  • Loading branch information
CarlBeek committed Nov 17, 2020
2 parents 9310de0 + 0f5b2a2 commit ed5a6d3
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pip3 install -r requirements.txt

Run one of the following command to enter the interactive CLI:

``cmd
```cmd
python .\eth2deposit\deposit.py new-mnemonic
```

Expand Down
2 changes: 1 addition & 1 deletion eth2deposit/cli/existing_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def validate_mnemonic(cts: click.Context, param: Any, mnemonic: str) -> str:
@click.option(
'--mnemonic',
callback=validate_mnemonic,
help=('The mnemonic that you used to generate your keys. (It is reccomened not to use this argument, and wait for '
help=('The mnemonic that you used to generate your keys. (It is recommended 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='Please enter your mnemonic separated by spaces (" ")',
required=True,
Expand Down
6 changes: 3 additions & 3 deletions eth2deposit/cli/generate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from eth2deposit.settings import (
ALL_CHAINS,
MAINNET,
get_setting,
get_chain_setting,
)


Expand Down Expand Up @@ -105,7 +105,7 @@ def generate_keys(ctx: click.Context, validator_start_index: int,
mnemonic_password = ctx.obj['mnemonic_password']
amounts = [MAX_DEPOSIT_AMOUNT] * num_validators
folder = os.path.join(folder, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME)
setting = get_setting(chain)
chain_setting = get_chain_setting(chain)
if not os.path.exists(folder):
os.mkdir(folder)
click.clear()
Expand All @@ -116,7 +116,7 @@ def generate_keys(ctx: click.Context, validator_start_index: int,
mnemonic_password=mnemonic_password,
num_keys=num_validators,
amounts=amounts,
fork_version=setting.GENESIS_FORK_VERSION,
chain_setting=chain_setting,
start_index=validator_start_index,
)
keystore_filefolders = credentials.export_keystores(password=keystore_password, folder=folder)
Expand Down
18 changes: 10 additions & 8 deletions eth2deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Keystore,
ScryptKeystore,
)
from eth2deposit.settings import DEPOSIT_CLI_VERSION
from eth2deposit.settings import DEPOSIT_CLI_VERSION, BaseChainSetting
from eth2deposit.utils.constants import (
BLS_WITHDRAWAL_PREFIX,
ETH2GWEI,
Expand All @@ -32,7 +32,8 @@ class Credential:
A Credential object contains all of the information for a single validator and the corresponding functionality.
Once created, it is the only object that should be required to perform any processing for a validator.
"""
def __init__(self, *, mnemonic: str, mnemonic_password: str, index: int, amount: int, fork_version: bytes):
def __init__(self, *, mnemonic: str, mnemonic_password: str,
index: int, amount: int, chain_setting: BaseChainSetting):
# Set path as EIP-2334 format
# https://eips.ethereum.org/EIPS/eip-2334
purpose = '12381'
Expand All @@ -46,7 +47,7 @@ def __init__(self, *, mnemonic: str, mnemonic_password: str, index: int, amount:
self.signing_sk = mnemonic_and_path_to_key(
mnemonic=mnemonic, path=self.signing_key_path, password=mnemonic_password)
self.amount = amount
self.fork_version = fork_version
self.chain_setting = chain_setting

@property
def signing_pk(self) -> bytes:
Expand Down Expand Up @@ -74,7 +75,7 @@ def deposit_message(self) -> DepositMessage:

@property
def signed_deposit(self) -> DepositData:
domain = compute_deposit_domain(fork_version=self.fork_version)
domain = compute_deposit_domain(fork_version=self.chain_setting.GENESIS_FORK_VERSION)
signing_root = compute_signing_root(self.deposit_message, domain)
signed_deposit = DepositData(
**self.deposit_message.as_dict(),
Expand All @@ -92,7 +93,8 @@ def deposit_datum_dict(self) -> Dict[str, bytes]:
datum_dict = signed_deposit_datum.as_dict()
datum_dict.update({'deposit_message_root': self.deposit_message.hash_tree_root})
datum_dict.update({'deposit_data_root': signed_deposit_datum.hash_tree_root})
datum_dict.update({'fork_version': self.fork_version})
datum_dict.update({'fork_version': self.chain_setting.GENESIS_FORK_VERSION})
datum_dict.update({'eth2_network_name': self.chain_setting.ETH2_NETWORK_NAME})
datum_dict.update({'deposit_cli_version': DEPOSIT_CLI_VERSION})
return datum_dict

Expand All @@ -107,7 +109,7 @@ def save_signing_keystore(self, password: str, folder: str) -> str:
return filefolder

def verify_keystore(self, keystore_filefolder: str, password: str) -> bool:
saved_keystore = Keystore.from_json(keystore_filefolder)
saved_keystore = Keystore.from_file(keystore_filefolder)
secret_bytes = saved_keystore.decrypt(password)
return self.signing_sk == int.from_bytes(secret_bytes, 'big')

Expand All @@ -126,7 +128,7 @@ def from_mnemonic(cls,
mnemonic_password: str,
num_keys: int,
amounts: List[int],
fork_version: bytes,
chain_setting: BaseChainSetting,
start_index: int) -> 'CredentialList':
if len(amounts) != num_keys:
raise ValueError(
Expand All @@ -136,7 +138,7 @@ def from_mnemonic(cls,
with click.progressbar(key_indices, label='Creating your keys:\t\t',
show_percent=False, show_pos=True) as indices:
return cls([Credential(mnemonic=mnemonic, mnemonic_password=mnemonic_password,
index=index, amount=amounts[index - start_index], fork_version=fork_version)
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]:
Expand Down
9 changes: 6 additions & 3 deletions eth2deposit/key_handling/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def save(self, file: str) -> None:
f.write(self.as_json())

@classmethod
def from_json(cls, path: str) -> 'Keystore':
with open(path, 'r') as f:
json_dict = json.load(f)
def from_json(cls, json_dict: Dict[Any, Any]) -> 'Keystore':
crypto = KeystoreCrypto.from_json(json_dict['crypto'])
path = json_dict['path']
uuid = json_dict['uuid']
Expand All @@ -109,6 +107,11 @@ def from_json(cls, path: str) -> 'Keystore':
pubkey = json_dict.get('pubkey', '')
return cls(crypto=crypto, description=description, pubkey=pubkey, path=path, uuid=uuid, version=version)

@classmethod
def from_file(cls, path: str) -> 'Keystore':
with open(path, 'r') as f:
return cls.from_json(json.load(f))

@staticmethod
def _process_password(password: str) -> bytes:
"""
Expand Down
35 changes: 21 additions & 14 deletions eth2deposit/settings.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
from typing import Dict, NamedTuple


DEPOSIT_CLI_VERSION = '1.0.0'
DEPOSIT_CLI_VERSION = '1.1.0'


class BaseChainSetting(NamedTuple):
ETH2_NETWORK_NAME: str
GENESIS_FORK_VERSION: bytes


MAINNET = 'mainnet'
WITTI = 'witti'
ALTONA = 'altona'
MEDALLA = 'medalla'
SPADINA = 'spadina'
ZINKEN = 'zinken'
PYRMONT = 'pyrmont'


# Eth2 Mainnet setting
MainnetSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000000'))
MainnetSetting = BaseChainSetting(ETH2_NETWORK_NAME=MAINNET, GENESIS_FORK_VERSION=bytes.fromhex('00000000'))
# Eth2 spec v0.11.3 testnet
WittiSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000113'))
WittiSetting = BaseChainSetting(ETH2_NETWORK_NAME=WITTI, GENESIS_FORK_VERSION=bytes.fromhex('00000113'))
# Eth2 spec v0.12.1 testnet
AltonaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000121'))
AltonaSetting = BaseChainSetting(ETH2_NETWORK_NAME=ALTONA, GENESIS_FORK_VERSION=bytes.fromhex('00000121'))
# Eth2 "official" public testnet (spec v0.12.2)
MedallaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000001'))
MedallaSetting = BaseChainSetting(ETH2_NETWORK_NAME=MEDALLA, GENESIS_FORK_VERSION=bytes.fromhex('00000001'))
# Eth2 "dress rehearsal" testnet (spec v0.12.3)
SpadinaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000002'))
SpadinaSetting = BaseChainSetting(ETH2_NETWORK_NAME=SPADINA, GENESIS_FORK_VERSION=bytes.fromhex('00000002'))
# Eth2 "dress rehearsal" testnet (spec v0.12.3)
ZinkenSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000003'))
ZinkenSetting = BaseChainSetting(ETH2_NETWORK_NAME=ZINKEN, GENESIS_FORK_VERSION=bytes.fromhex('00000003'))
# Eth2 pre-launch testnet (spec v1.0.0)
PyrmontSetting = BaseChainSetting(ETH2_NETWORK_NAME=PYRMONT, GENESIS_FORK_VERSION=bytes.fromhex('00002009'))


MAINNET = 'mainnet'
WITTI = 'witti'
ALTONA = 'altona'
MEDALLA = 'medalla'
SPADINA = 'spadina'
ZINKEN = 'zinken'
ALL_CHAINS: Dict[str, BaseChainSetting] = {
MAINNET: MainnetSetting,
WITTI: WittiSetting,
ALTONA: AltonaSetting,
MEDALLA: MedallaSetting,
SPADINA: SpadinaSetting,
ZINKEN: ZinkenSetting,
PYRMONT: PyrmontSetting,
}


def get_setting(chain_name: str = MAINNET) -> BaseChainSetting:
def get_chain_setting(chain_name: str = MAINNET) -> BaseChainSetting:
return ALL_CHAINS[chain_name]
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
py-ecc==5.0.0 \
--hash=sha256:67a6b944722408c75bb630617dfbd8062c45b72d154ed3a6891c833717c87638 \
--hash=sha256:9d3c7ba607ef36d7f8af9944d702799014b27fc77b385d14024f96f9f610ad0a
py_ecc==5.1.0 \
--hash=sha256:1ba0453d39887cdb63e0855ba317b67f8bd571371bb3cafefae3e2e5206e45c5 \
--hash=sha256:934d6506f8b9487cc669562eb11beaf9b0a9ca408ffd94d0961c9cdde71336f2
pycryptodome==3.9.8 \
--hash=sha256:02e51e1d5828d58f154896ddfd003e2e7584869c275e5acbe290443575370fba \
--hash=sha256:03d5cca8618620f45fd40f827423f82b86b3a202c8d44108601b0f5f56b04299 \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="eth2deposit",
version='1.0.0',
version='1.1.0',
py_modules=["eth2deposit"],
packages=find_packages(exclude=('tests', 'docs')),
python_requires=">=3.7,<4",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def clean_key_folder(my_folder_path: str) -> None:


def get_uuid(key_file: str) -> str:
keystore = Keystore.from_json(key_file)
keystore = Keystore.from_file(key_file)
return keystore.uuid
3 changes: 2 additions & 1 deletion tests/test_credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from eth2deposit.credentials import CredentialList
from eth2deposit.settings import MedallaSetting


def test_from_mnemonic() -> None:
Expand All @@ -10,6 +11,6 @@ def test_from_mnemonic() -> None:
mnemonic_password="",
num_keys=1,
amounts=[32, 32],
fork_version=bytes.fromhex('00000000'),
chain_setting=MedallaSetting,
start_index=1,
)
2 changes: 1 addition & 1 deletion tests/test_key_handling/test_keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
test_vector_folder = os.path.join(os.getcwd(), 'tests', 'test_key_handling', 'keystore_test_vectors')
_, _, test_vector_files = next(os.walk(test_vector_folder)) # type: ignore

test_vector_keystores = [Keystore.from_json(os.path.join(test_vector_folder, f)) for f in test_vector_files]
test_vector_keystores = [Keystore.from_file(os.path.join(test_vector_folder, f)) for f in test_vector_files]


def test_json_serialization() -> None:
Expand Down

0 comments on commit ed5a6d3

Please sign in to comment.