Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Proposed tweak to from_json and from_file
This feels to me like it would be more intuitive behavior; the `from_json` behaves the same way for Keystore and KeystoreCrypto, and it exposes a way for people to use the library with json that is not saved in a file anywhere.
  • Loading branch information
vbuterin authored Nov 5, 2020
commit 0bfb657894c550cdfaf8eed0233c18275e67934b
10 changes: 7 additions & 3 deletions eth2deposit/key_handling/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,20 @@ 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']
version = json_dict['version']
description = json_dict.get('description', '')
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