mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2025-01-10 04:51:21 +00:00
353c40215f
* dev: (22 commits) Remove BLS incompatability warning Adds preproduction warning Adds typing & Moves global variables into pytest function args Linting fixes Test key_info != b'' import pytest into test_tree Apply suggestions from @hwwhww's code review Fix lint Add Altona setting Remove extra newline (lint) Update tests for new EIP2333 (bls v2 compliant HKDF_mod_r) Rename json file fields Create uuid at execution time instead of class attribute Add uuid test Fix key path Add Witti gitignore dist/ Revert to DepositMessage & DepositData as per spec Add fork_version adds build/ to .gitignore ...
59 lines
2.4 KiB
Python
59 lines
2.4 KiB
Python
import os
|
|
import json
|
|
|
|
from eth2deposit.key_handling.keystore import (
|
|
Keystore,
|
|
ScryptKeystore,
|
|
Pbkdf2Keystore,
|
|
)
|
|
|
|
test_vector_password = '𝔱𝔢𝔰𝔱𝔭𝔞𝔰𝔰𝔴𝔬𝔯𝔡🔑'
|
|
test_vector_secret = bytes.fromhex('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')
|
|
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]
|
|
|
|
|
|
def test_json_serialization() -> None:
|
|
for keystore, keystore_json_file in zip(test_vector_keystores, test_vector_files):
|
|
keystore_json_path = os.path.join(test_vector_folder, keystore_json_file)
|
|
with open(keystore_json_path) as f:
|
|
assert json.loads(keystore.as_json()) == json.load(f)
|
|
|
|
|
|
def test_encrypt_decrypt_test_vectors() -> None:
|
|
for tv in test_vector_keystores:
|
|
aes_iv = tv.crypto.cipher.params['iv']
|
|
kdf_salt = tv.crypto.kdf.params['salt']
|
|
keystore = Pbkdf2Keystore if 'pbkdf' in tv.crypto.kdf.function else ScryptKeystore
|
|
generated_keystore = keystore.encrypt(
|
|
secret=test_vector_secret,
|
|
password=test_vector_password,
|
|
aes_iv=aes_iv,
|
|
kdf_salt=kdf_salt)
|
|
assert generated_keystore.decrypt(test_vector_password) == test_vector_secret
|
|
|
|
|
|
def test_generated_keystores() -> None:
|
|
for tv in test_vector_keystores:
|
|
aes_iv = tv.crypto.cipher.params['iv']
|
|
kdf_salt = tv.crypto.kdf.params['salt']
|
|
keystore = Pbkdf2Keystore if 'pbkdf' in tv.crypto.kdf.function else ScryptKeystore
|
|
generated_keystore = keystore.encrypt(
|
|
secret=test_vector_secret,
|
|
password=test_vector_password,
|
|
aes_iv=aes_iv,
|
|
kdf_salt=kdf_salt)
|
|
assert generated_keystore.crypto == tv.crypto
|
|
|
|
|
|
def test_encrypt_decrypt_pbkdf2_random_iv() -> None:
|
|
generated_keystore = Pbkdf2Keystore.encrypt(secret=test_vector_secret, password=test_vector_password)
|
|
assert generated_keystore.decrypt(test_vector_password) == test_vector_secret
|
|
|
|
|
|
def test_encrypt_decrypt_scrypt_random_iv() -> None:
|
|
generated_keystore = ScryptKeystore.encrypt(secret=test_vector_secret, password=test_vector_password)
|
|
assert generated_keystore.decrypt(test_vector_password) == test_vector_secret
|