1
1
I have created a new Electrum wallet, and here is an address:
1JkZLnmFfpVFLT2ZMtKzc6BuXMdmY41EHA
By right-clicking on it, I choose "Private key" which gives:
Kzuucz58MiTbbedeVuqBaPYwG1TQrV3n2NYU2dJRZ7HEHnHsUXWx
Now I want to be able (to learn how it works) to go from this private key to the address, via elliptic curve multiplication.
Here is what I tried:
import bitcoin #pybitcointools
import base58
import binascii
pvt = 'Kzuucz58MiTbbedeVuqBaPYwG1TQrV3n2NYU2dJRZ7HEHnHsUXWx'
pvtdecoded = base58.b58decode(pvt)
pvthex = binascii.hexlify(pvtdecoded)[2:-8] # remove the first initial byte for version and 4 final bytes for checksum
pvt2 = bitcoin.decode_privkey(pvthex, 'hex') # decode as a decimal
# generate pubkey from pvtkey with elliptic curve multiplication
public_key = bitcoin.fast_multiply(bitcoin.G, pvt2)
addr = bitcoin.pubkey_to_address(public_key)
print addr
which gives: 1LNSuE4NKHTyHygeKwnU1equ7MjPMhayxB which is not the original address.
What's wrong? How to recover the original address (1JkZLnmFfpVFLT2ZMtKzc6BuXMdmY41EHA) from the Private key by using elliptic curve multiplication?
Edit: As Kz....Wx private key looks like a WIF-compressed one, I tried to replace:
pvt2 = bitcoin.decode_privkey(pvthex, 'hex') # decode as a decimal
by
pvt2 = bitcoin.decode_privkey('Kzuucz58MiTbbedeVuqBaPYwG1TQrV3n2NYU2dJRZ7HEHnHsUXWx', 'wif')
but then after elliptic curve multiplication, it gives another address, which is still not the good one! (18dFF3EQoPxR44TygdGxHPMe3LSLFeQe4U)
Note: I have read https://en.bitcoin.it/wiki/Wallet_import_format, and
– Basj – 2018-01-01T17:44:33.277WIF to private key, but I'm still stuck.