FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
, which is pretty big: almost any 32-byte number will be smaller than it.secrets
module. Let’s modify the code above to make the private key generation secure!Quick note: bitaddress.org gives you the private key in a compressed WIF format, which is close to the WIF format that we discussed before. For our purposes, we will make the algorithm return a hex string so that we can use it later for a public key generation.
__seed_int
and __seed_byte
are two helper methods that insert the entropy into our pool array. Notice that we use secrets
.random
object and use it only for the key generation. Instead, there is a shared object that is used by any code that is running in one script.random.seed(0)
can destroy all our collected entropy. We don’t want that. Thankfully, Python provides getstate
and setstate
methods. So, to save our entropy each time we generate a key, we remember the state we stopped at and set it next time we want to make a key.CURVE_ORDER
). This is a requirement for all ECDSA private keys. The CURVE_ORDER
is the order of the secp256k1 curve, which is FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
.