2
I'm looking for a simple, easy to use Bitcoin library for Python.
What I want to do is verify I can enter a hex private key that I want, and get the expected pubkey in compressed format, and the 1Btc... address.
I've looked at cryptotools on github which looked promising, and easy to use, but it would not accept a hex value that wasn't a multiple of 2. I know that sounds odd, but I want to be able to enter a hex value like c12 and have it work as expected (unless I have to enter 0c12 and that will work, with the leading zero discarded). I expect than when I enter 0cfa721d that this will be interpreted as big endian.
bitcoinlib looks promising, but I find it confusing and I've tried for a couple of hours but unsure of how to get what I want.
- Input private key in hex
- Get back pub key in hash160 format, compressed
- Get the 1Btc... address as well.
I wonder if this is a strict mathematical relationship. For instance could there be an arbitrary or infinite number of pub keys from the private key? Is there a way to ensure I get the pubkey I want from the private key? I want to test known private keys with the pubkey and BTC address generated that corresponds to known private keys and addresses, so I can try and figure out how whoever generated these addresses from choices of private keys I can try to replicate and do the same thing myself.
Thank you for any help or suggestions.
Hi, author of cryptotools here. The reason it wont accept odd digits hex is that it will store the private key inteternally as Python bytes object and the bytes.fromhex method requires full bytes. I'll have a look at it. As a workaround you can simply pad with a zero if it has odd amount of digits.0x0cfa721d is exactly the same as 0xcfa721d. The other functionality is there, just do
myprivatekey.to_public().to_address('P2PKH', compressed=True)– Mike D – 2018-11-18T16:51:14.843