mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2025-01-10 21:11:21 +00:00
Merge pull request #151 from ethereum/vbuterin-patch-1
Proposed tweak to from_json and from_file
This commit is contained in:
commit
bd0a130f03
@ -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')
|
||||
|
||||
|
@ -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:
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user