Package: eth-keyfile
eth-keyfileA library for handling the encrypted keyfiles used to store ethereum private keysThis library and repository was previously located athttps://github.com/pipermerriam/ethereum-keyfile.  It was transferred to the Ethereum foundation github in November 2017 and renamed toeth-keyfile.  The PyPi package was also renamed fromethereum-keyfiletoeth-keyfile.Read more in the documentation below.View the change log.Quickstartpython-mpipinstalleth-keyfileDocumentationeth_keyfile.load_keyfile(path_or_file_obj) --> keyfile_jsonTakes either a filesystem path represented as a string or a file object and
returns the parsed keyfile json as a python dictionary.>>>frometh_keyfileimportload_keyfile>>>load_keyfile('path/to-my-keystore/keystore.json'){"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}eth_keyfile.create_keyfile_json(private_key, password, kdf="pbkdf2", work_factor=None, salt_size=16) --> keyfile_jsonTakes the following parameters:private_key: A bytestring of length 32password: A bytestring which will be the password that can be used to decrypt the resulting keyfile.kdf: The key derivation function.  Allowed values arepbkdf2andscrypt.  By default,pbkdf2will be used.work_factor: The work factor which will be used for the given key derivation function.  By default1000000will be used forpbkdf2and262144forscrypt.salt_size: Salt size in bytes.Returns the keyfile json as a python dictionary.>>>private_key=b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'>>>create_keyfile_json(private_key,b'foo'){"address":"1a642f0e3c3af545e7acbd38b07251b3990914f1","crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}eth_keyfile.decode_keyfile_json(keyfile_json, password) --> private_keyTakes the keyfile json as a python dictionary and the password for the keyfile,
returning the decoded private key.>>>keyfile_json={..."crypto":{..."cipher":"aes-128-ctr",..."cipherparams":{..."iv":"6087dab2f9fdbbfaddc31a909735c1e6"...},..."ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46",..."kdf":"pbkdf2",..."kdfparams":{..."c":262144,..."dklen":32,..."prf":"hmac-sha256",..."salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"...},..."mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"...},..."id":"3198bc9c-6672-5ab3-d995-4942343ae5b6",..."version":3...}>>>decode_keyfile_json(keyfile_json,b'foo')b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'eth_keyfile.extract_key_from_keyfile(path_or_file_obj, password) --> private_keyTakes a filesystem path represented by a string or a file object and the
password for the keyfile.  Returns the private key as a bytestring.>>>extract_key_from_keyfile('path/to-my-keystore/keyfile.json',b'foo')b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'Developer SetupIf you would like to hack on eth-keyfile, please check out theSnake Charmers
Tactical Manualfor information on how we do:TestingPull RequestsDocumentationWe usepre-committo maintain consistent code style. Once
installed, it will run automatically with every commit. You can also run it manually
withmake lint. If you need to make a commit that skips thepre-commitchecks, you
can do so withgit commit --no-verify.Development Environment SetupYou can set up your dev environment with:gitclonegit@github.com:ethereum/eth-keyfile.gitcdeth-keyfile
virtualenv-ppython3venv
.venv/bin/activate
python-mpipinstall-e".[dev]"pre-commitinstallRelease setupTo release a new version:makereleasebump=$$VERSION_PART_TO_BUMP$$How to bumpversionThe version format for this repo is{major}.{minor}.{patch}for stable, and{major}.{minor}.{patch}-{stage}.{devnum}for unstable (stagecan be alpha or beta).To issue the next version in line, specify which part to bump,
likemake release bump=minorormake release bump=devnum. This is typically done from the
main branch, except when releasing a beta (in which case the beta is released from main,
and the previous stable branch is released from said branch).If you are in a beta version,make release bump=stagewill switch to a stable.To issue an unstable version when the current version is stable, specify the
new version explicitly, likemake release bump="--new-version 4.0.0-alpha.1 devnum"