Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed tweak to from_json and from_file #151

Merged
merged 4 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth2deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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 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
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
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