From 8733c0661d770149cff43ddbb1e71b4b84ced09c Mon Sep 17 00:00:00 2001 From: vbuterin Date: Wed, 11 Sep 2024 12:17:09 +0800 Subject: [PATCH] Update keystore.py The current version doesn't work for me (relatively fresh Ubuntu 24.04 install). This fixes it. --- staking_deposit/key_handling/keystore.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/staking_deposit/key_handling/keystore.py b/staking_deposit/key_handling/keystore.py index 75bcddba..0aaaeca1 100644 --- a/staking_deposit/key_handling/keystore.py +++ b/staking_deposit/key_handling/keystore.py @@ -61,9 +61,9 @@ class KeystoreModule(BytesDataclass): @dataclass class KeystoreCrypto(BytesDataclass): - kdf: KeystoreModule = KeystoreModule() - checksum: KeystoreModule = KeystoreModule() - cipher: KeystoreModule = KeystoreModule() + kdf: KeystoreModule = dataclass_field(default_factory=KeystoreModule) + checksum: KeystoreModule = dataclass_field(default_factory=KeystoreModule) + cipher: KeystoreModule = dataclass_field(default_factory=KeystoreModule) @classmethod def from_json(cls, json_dict: Dict[Any, Any]) -> 'KeystoreCrypto': @@ -81,7 +81,7 @@ class Keystore(BytesDataclass): Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2335.md """ - crypto: KeystoreCrypto = KeystoreCrypto() + crypto: KeystoreCrypto = dataclass_field(default_factory=KeystoreCrypto) description: str = '' pubkey: str = '' path: str = '' @@ -161,10 +161,9 @@ def decrypt(self, password: str) -> bytes: cipher = AES_128_CTR(key=decryption_key[:16], **self.crypto.cipher.params) return cipher.decrypt(self.crypto.cipher.message) - @dataclass class Pbkdf2Keystore(Keystore): - crypto: KeystoreCrypto = KeystoreCrypto( + crypto: KeystoreCrypto = dataclass_field(default_factory=lambda: KeystoreCrypto( kdf=KeystoreModule( function='pbkdf2', params={ @@ -179,12 +178,11 @@ class Pbkdf2Keystore(Keystore): cipher=KeystoreModule( function='aes-128-ctr', ) - ) - + )) @dataclass class ScryptKeystore(Keystore): - crypto: KeystoreCrypto = KeystoreCrypto( + crypto: KeystoreCrypto = dataclass_field(default_factory=lambda: KeystoreCrypto( kdf=KeystoreModule( function='scrypt', params={ @@ -200,4 +198,4 @@ class ScryptKeystore(Keystore): cipher=KeystoreModule( function='aes-128-ctr', ) - ) + ))