raiden-network / raiden-contracts

Raiden Network Smart Contracts
MIT License
53 stars 45 forks source link

Handle keys conforming to older web3 secret storage definition versions #1223

Open offerm opened 5 years ago

offerm commented 5 years ago

My account file, created 2 years back (I think with mist) has this inside:

{"version":3,"id":"xxxxx","address":"xxxxxx","Crypto":{"ciphertext":"xxxxx","cipherparams":{"iv":"82f61664c6c941937ed44c306a22a4bb"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"xxxxxx","n":1024,"r":8,"p":1},"mac":"xxxxx"}}

Contract deployment fails when using this file since the code is looking for lower case "crypto".

I made a local change here to solve it, but you may like to have a more generic solution.

diff --git a/raiden_contracts/utils/private_key.py b/raiden_contracts/utils/private_key.py
index 708b76a..6a8e1b0 100644
--- a/raiden_contracts/utils/private_key.py
+++ b/raiden_contracts/utils/private_key.py
@@ -63,7 +63,7 @@ def get_private_key(key_path: Path, password_path: Optional[Path] = None) -> Opt
                         password = password_file.readline().strip()
                 else:
                     password = getpass.getpass("Enter the private key password: ")
-                if json_data["crypto"]["kdf"] == "pbkdf2":
+                if json_data["Crypto"]["kdf"] == "pbkdf2":
                     password = password.encode()  # type: ignore
                 private_key = encode_hex(decode_keyfile_json(json_data, password))
             except ValueError:
LefterisJP commented 5 years ago

Hey @offerm good point. Your keyfile is (probably) still in v1 of the Web3 secret storage format. The latest one is v3. The one you have could be v1 even though it looks a bit different

I also have accounts from the launch of ethereum but somehow (perhaps geth auto-updated them) they seem to conform to the v3 version of the web3 secret storage.

We could try to handle all versions of the secret storage format I suppose.

pirapira commented 5 years ago

Is there a library for reading keyfiles?

LefterisJP commented 5 years ago

web3 should do it: https://web3py.readthedocs.io/en/stable/web3.eth.account.html