Skip to content

Commit 18418e6

Browse files
committed
Update default args to keystores
1 parent c2a20ce commit 18418e6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

staking_deposit/key_handling/keystore.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
from py_ecc.bls import G2ProofOfPossession as bls
1010
from secrets import randbits
11-
from typing import Any, Dict, Union
11+
from typing import Any, Dict, Optional, Union
1212
from unicodedata import normalize
1313
from uuid import uuid4
1414

@@ -127,18 +127,20 @@ def _process_password(password: str) -> bytes:
127127

128128
@classmethod
129129
def encrypt(cls, *, secret: bytes, password: str, path: str='',
130-
kdf_salt: bytes=randbits(256).to_bytes(32, 'big'),
131-
aes_iv: bytes=randbits(128).to_bytes(16, 'big')) -> 'Keystore':
130+
kdf_salt: Optional[bytes]=None,
131+
aes_iv: Optional[bytes]=None) -> 'Keystore':
132132
"""
133133
Encrypt a secret (BLS SK) as an EIP 2335 Keystore.
134134
"""
135135
keystore = cls()
136136
keystore.uuid = str(uuid4())
137+
kdf_salt = kdf_salt if kdf_salt is not None else randbits(256).to_bytes(32, 'big')
137138
keystore.crypto.kdf.params['salt'] = kdf_salt
138139
decryption_key = keystore.kdf(
139140
password=cls._process_password(password),
140141
**keystore.crypto.kdf.params
141142
)
143+
aes_iv = aes_iv if aes_iv is not None else randbits(128).to_bytes(16, 'big')
142144
keystore.crypto.cipher.params['iv'] = aes_iv
143145
cipher = AES_128_CTR(key=decryption_key[:16], **keystore.crypto.cipher.params)
144146
keystore.crypto.cipher.message = cipher.encrypt(secret)

0 commit comments

Comments
 (0)