diff --git a/eth2deposit/credentials.py b/eth2deposit/credentials.py index d9a4a0b..f8a98a7 100644 --- a/eth2deposit/credentials.py +++ b/eth2deposit/credentials.py @@ -107,7 +107,7 @@ class Credential: 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') diff --git a/eth2deposit/key_handling/keystore.py b/eth2deposit/key_handling/keystore.py index a11052f..8075bba 100644 --- a/eth2deposit/key_handling/keystore.py +++ b/eth2deposit/key_handling/keystore.py @@ -98,9 +98,7 @@ class Keystore(BytesDataclass): 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'] @@ -109,6 +107,11 @@ class Keystore(BytesDataclass): 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: """ diff --git a/tests/test_cli/helpers.py b/tests/test_cli/helpers.py index c199c75..01f9204 100644 --- a/tests/test_cli/helpers.py +++ b/tests/test_cli/helpers.py @@ -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 diff --git a/tests/test_key_handling/test_keystore.py b/tests/test_key_handling/test_keystore.py index e15463d..add35b8 100644 --- a/tests/test_key_handling/test_keystore.py +++ b/tests/test_key_handling/test_keystore.py @@ -13,7 +13,7 @@ test_vector_secret = bytes.fromhex('000000000019d6689c085ae165831e934ff763ae46a2 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: