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

Update keystore.py #416

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
18 changes: 8 additions & 10 deletions staking_deposit/key_handling/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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 = ''
Expand Down Expand Up @@ -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={
Expand All @@ -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={
Expand All @@ -200,4 +198,4 @@ class ScryptKeystore(Keystore):
cipher=KeystoreModule(
function='aes-128-ctr',
)
)
))