https://github.com/calcuis/private-key-hex-wif-generator
https://github.com/calcuis/private-key-hex-wif-generator
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/calcuis/private-key-hex-wif-generator
- Owner: calcuis
- Created: 2023-08-27T01:22:46.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-27T01:38:50.000Z (almost 2 years ago)
- Last Synced: 2025-01-21T13:11:52.480Z (5 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## keygen (private-key-hex-wif-generator)
The provided Python code performs the following actions:
- It imports the `secrets` module to generate secure random values.
- The function `generate_private_key()` is defined to generate a random 256-bit private key (32 bytes) using the `secrets` module.
- The generated private key is then converted to its hexadecimal representation and printed as output.
- The code further imports the `base58` and `hashlib` modules.
- It defines the function `hex_to_wif(hex_private_key)` to convert a given hexadecimal private key to a Wallet Import Format (WIF) key.
- The function adds a prefix byte '80' to the hexadecimal private key, indicating a mainnet private key in the crypto context.
- The extended private key is double-hashed using the `SHA-256` hash function.
- The first 4 bytes of the second hash are taken as a checksum.
- The checksum is appended to the end of the extended private key.
- The extended private key with the checksum is `base58` encoded to obtain the WIF key.
- The WIF key is returned by the function.
- The previously generated private key is converted to its corresponding WIF key using the `hex_to_wif` function.
- The resulting WIF key is printed as output.
In summary, the code generates a random private key, converts it to hexadecimal format, and then converts the hexadecimal private key into a Wallet Import Format (WIF) key, which is commonly used in crypto systems for securely managing private keys.