Пример #1
0
def test_decoding_keyfile(keyfile_data):
    password = codecs.encode(keyfile_data['password'], 'utf8')
    keyfile_json = keyfile_data['json']
    private_key = keyfile_data['priv']

    derived_private_key = decode_keyfile_json(keyfile_json, password)
    assert decode_hex(private_key) == derived_private_key
def test_scrypt_keyfile_creation():
    keyfile_json = create_keyfile_json(
        PRIVATE_KEY,
        password=PASSWORD,
        kdf='scrypt',
        iterations=2,
    )
    derived_private_key = decode_keyfile_json(keyfile_json, PASSWORD)
    assert derived_private_key == PRIVATE_KEY
def test_pbkdf2_keyfile_salt32_creation():
    keyfile_json = create_keyfile_json(
        PRIVATE_KEY,
        password=PASSWORD,
        kdf='pbkdf2',
        iterations=1,
        salt_size=32,
    )
    assert len(keyfile_json['crypto']['kdfparams']['salt']) == 32 * 2
    derived_private_key = decode_keyfile_json(keyfile_json, PASSWORD)
    assert derived_private_key == PRIVATE_KEY
Пример #4
0
        "cipherparams": {"iv": "7a634a007f4b64abdc1da28a7fec09ca"},
        "kdf": "scrypt",
        "kdfparams": {
            "dklen": 32,
            "n": 262144,
            "p": 1,
            "r": 8,
            "salt": "1981e90b6d5295cb7495b394dcf577d984496a8b4798ec1bdbe40a81d9487c57",
        },
        "mac": "48f816de2d570bd813510af71f015d967750dc8ba305bf39b2876d16d28dda0a",
    },
    "id": "625f9239-07e7-42e0-8ab8-0516a7bd9d93",
    "version": 3,
}
PASSWORD = "******"
PRIVKEY = decode_keyfile_json(KEYSTORE, PASSWORD)


def test_account_from_keystore():
    keystore = dict(KEYSTORE)
    account = Account(keystore)
    assert account.locked
    assert account.privkey is None
    assert account.uuid == KEYSTORE["id"]
    assert account.address == decode_hex(KEYSTORE["address"])

    with pytest.raises(ValueError):
        account.unlock("wrong-password")
    assert account.locked

    account.unlock(PASSWORD)