METADATA 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. Metadata-Version: 2.1
  2. Name: eth-keyfile
  3. Version: 0.8.1
  4. Summary: eth-keyfile: A library for handling the encrypted keyfiles used to store ethereum private keys
  5. Home-page: https://github.com/ethereum/eth-keyfile
  6. Author: The Ethereum Foundation
  7. Author-email: snakecharmers@ethereum.org
  8. License: MIT
  9. Keywords: ethereum
  10. Classifier: Development Status :: 2 - Pre-Alpha
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Natural Language :: English
  14. Classifier: Programming Language :: Python :: 3
  15. Classifier: Programming Language :: Python :: 3.8
  16. Classifier: Programming Language :: Python :: 3.9
  17. Classifier: Programming Language :: Python :: 3.10
  18. Classifier: Programming Language :: Python :: 3.11
  19. Classifier: Programming Language :: Python :: 3.12
  20. Requires-Python: >=3.8, <4
  21. Description-Content-Type: text/markdown
  22. License-File: LICENSE
  23. Requires-Dist: eth-utils >=2
  24. Requires-Dist: eth-keys >=0.4.0
  25. Requires-Dist: pycryptodome <4,>=3.6.6
  26. Provides-Extra: dev
  27. Requires-Dist: build >=0.9.0 ; extra == 'dev'
  28. Requires-Dist: bumpversion >=0.5.3 ; extra == 'dev'
  29. Requires-Dist: ipython ; extra == 'dev'
  30. Requires-Dist: pre-commit >=3.4.0 ; extra == 'dev'
  31. Requires-Dist: tox >=4.0.0 ; extra == 'dev'
  32. Requires-Dist: twine ; extra == 'dev'
  33. Requires-Dist: wheel ; extra == 'dev'
  34. Requires-Dist: towncrier <22,>=21 ; extra == 'dev'
  35. Requires-Dist: pytest >=7.0.0 ; extra == 'dev'
  36. Requires-Dist: pytest-xdist >=2.4.0 ; extra == 'dev'
  37. Provides-Extra: docs
  38. Requires-Dist: towncrier <22,>=21 ; extra == 'docs'
  39. Provides-Extra: test
  40. Requires-Dist: pytest >=7.0.0 ; extra == 'test'
  41. Requires-Dist: pytest-xdist >=2.4.0 ; extra == 'test'
  42. # eth-keyfile
  43. [![Join the conversation on Discord](https://img.shields.io/discord/809793915578089484?color=blue&label=chat&logo=discord&logoColor=white)](https://discord.gg/GHryRvPB84) [![Build Status](https://circleci.com/gh/ethereum/eth-keyfile.svg?style=shield)](https://circleci.com/gh/ethereum/eth-keyfile)
  44. [![PyPI version](https://badge.fury.io/py/eth-keyfile.svg)](https://badge.fury.io/py/eth-keyfile)
  45. [![Python versions](https://img.shields.io/pypi/pyversions/eth-keyfile.svg)](https://pypi.python.org/pypi/eth-keyfile)
  46. A library for handling the encrypted keyfiles used to store ethereum private keys
  47. > This library and repository was previously located at https://github.com/pipermerriam/ethereum-keyfile. It was transferred to the Ethereum foundation github in November 2017 and renamed to `eth-keyfile`. The PyPi package was also renamed from `ethereum-keyfile` to `eth-keyfile`.
  48. Read more in the documentation below. [View the change log](https://github.com/ethereum/eth-keyfile/blob/main/CHANGELOG.rst).
  49. ## Quickstart
  50. ```sh
  51. python -m pip install eth-keyfile
  52. ```
  53. ## Documentation
  54. ### `eth_keyfile.load_keyfile(path_or_file_obj) --> keyfile_json`
  55. Takes either a filesystem path represented as a string or a file object and
  56. returns the parsed keyfile json as a python dictionary.
  57. ```python
  58. >>> from eth_keyfile import load_keyfile
  59. >>> load_keyfile('path/to-my-keystore/keystore.json')
  60. {
  61. "crypto" : {
  62. "cipher" : "aes-128-ctr",
  63. "cipherparams" : {
  64. "iv" : "6087dab2f9fdbbfaddc31a909735c1e6"
  65. },
  66. "ciphertext" : "5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46",
  67. "kdf" : "pbkdf2",
  68. "kdfparams" : {
  69. "c" : 262144,
  70. "dklen" : 32,
  71. "prf" : "hmac-sha256",
  72. "salt" : "ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"
  73. },
  74. "mac" : "517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"
  75. },
  76. "id" : "3198bc9c-6672-5ab3-d995-4942343ae5b6",
  77. "version" : 3
  78. }
  79. ```
  80. ### `eth_keyfile.create_keyfile_json(private_key, password, kdf="pbkdf2", work_factor=None, salt_size=16) --> keyfile_json`
  81. Takes the following parameters:
  82. - `private_key`: A bytestring of length 32
  83. - `password`: A bytestring which will be the password that can be used to decrypt the resulting keyfile.
  84. - `kdf`: The key derivation function. Allowed values are `pbkdf2` and `scrypt`. By default, `pbkdf2` will be used.
  85. - `work_factor`: The work factor which will be used for the given key derivation function. By default `1000000` will be used for `pbkdf2` and `262144` for `scrypt`.
  86. - `salt_size`: Salt size in bytes.
  87. Returns the keyfile json as a python dictionary.
  88. ```python
  89. >>> 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'
  90. >>> create_keyfile_json(private_key, b'foo')
  91. {
  92. "address" : "1a642f0e3c3af545e7acbd38b07251b3990914f1",
  93. "crypto" : {
  94. "cipher" : "aes-128-ctr",
  95. "cipherparams" : {
  96. "iv" : "6087dab2f9fdbbfaddc31a909735c1e6"
  97. },
  98. "ciphertext" : "5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46",
  99. "kdf" : "pbkdf2",
  100. "kdfparams" : {
  101. "c" : 262144,
  102. "dklen" : 32,
  103. "prf" : "hmac-sha256",
  104. "salt" : "ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"
  105. },
  106. "mac" : "517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"
  107. },
  108. "id" : "3198bc9c-6672-5ab3-d995-4942343ae5b6",
  109. "version" : 3
  110. }
  111. ```
  112. ### `eth_keyfile.decode_keyfile_json(keyfile_json, password) --> private_key`
  113. Takes the keyfile json as a python dictionary and the password for the keyfile,
  114. returning the decoded private key.
  115. ```python
  116. >>> keyfile_json = {
  117. ... "crypto" : {
  118. ... "cipher" : "aes-128-ctr",
  119. ... "cipherparams" : {
  120. ... "iv" : "6087dab2f9fdbbfaddc31a909735c1e6"
  121. ... },
  122. ... "ciphertext" : "5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46",
  123. ... "kdf" : "pbkdf2",
  124. ... "kdfparams" : {
  125. ... "c" : 262144,
  126. ... "dklen" : 32,
  127. ... "prf" : "hmac-sha256",
  128. ... "salt" : "ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"
  129. ... },
  130. ... "mac" : "517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"
  131. ... },
  132. ... "id" : "3198bc9c-6672-5ab3-d995-4942343ae5b6",
  133. ... "version" : 3
  134. ... }
  135. >>> decode_keyfile_json(keyfile_json, b'foo')
  136. 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'
  137. ```
  138. ### `eth_keyfile.extract_key_from_keyfile(path_or_file_obj, password) --> private_key`
  139. Takes a filesystem path represented by a string or a file object and the
  140. password for the keyfile. Returns the private key as a bytestring.
  141. ```python
  142. >>> extract_key_from_keyfile('path/to-my-keystore/keyfile.json', b'foo')
  143. 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'
  144. ```
  145. ## Developer Setup
  146. If you would like to hack on eth-keyfile, please check out the [Snake Charmers
  147. Tactical Manual](https://github.com/ethereum/snake-charmers-tactical-manual)
  148. for information on how we do:
  149. - Testing
  150. - Pull Requests
  151. - Documentation
  152. We use [pre-commit](https://pre-commit.com/) to maintain consistent code style. Once
  153. installed, it will run automatically with every commit. You can also run it manually
  154. with `make lint`. If you need to make a commit that skips the `pre-commit` checks, you
  155. can do so with `git commit --no-verify`.
  156. ### Development Environment Setup
  157. You can set up your dev environment with:
  158. ```sh
  159. git clone git@github.com:ethereum/eth-keyfile.git
  160. cd eth-keyfile
  161. virtualenv -p python3 venv
  162. . venv/bin/activate
  163. python -m pip install -e ".[dev]"
  164. pre-commit install
  165. ```
  166. ### Release setup
  167. To release a new version:
  168. ```sh
  169. make release bump=$$VERSION_PART_TO_BUMP$$
  170. ```
  171. #### How to bumpversion
  172. The version format for this repo is `{major}.{minor}.{patch}` for stable, and
  173. `{major}.{minor}.{patch}-{stage}.{devnum}` for unstable (`stage` can be alpha or beta).
  174. To issue the next version in line, specify which part to bump,
  175. like `make release bump=minor` or `make release bump=devnum`. This is typically done from the
  176. main branch, except when releasing a beta (in which case the beta is released from main,
  177. and the previous stable branch is released from said branch).
  178. If you are in a beta version, `make release bump=stage` will switch to a stable.
  179. To issue an unstable version when the current version is stable, specify the
  180. new version explicitly, like `make release bump="--new-version 4.0.0-alpha.1 devnum"`