Author

Topic: simple python bitcoin public key to address (Read 1381 times)

newbie
Activity: 26
Merit: 3
June 08, 2016, 05:23:38 PM
#4
I think this code should work. You'll need python-bitcoinlib - https://github.com/petertodd/python-bitcoinlib

Code:
from bitcoin.wallet import CBitcoinSecret, P2PKHBitcoinAddress
from bitcoin.core import x
privkey = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
secret = CBitcoinSecret.from_secret_bytes(x(privkey))
address = P2PKHBitcoinAddress.from_pubkey(secret.pub)
a = str(address)

-- edit --

Apologies, I just read the title of the thread properly. The above code is for private key to address.

Public keys might be trickier to deal with, depending on whether they are compressed or not.
full member
Activity: 546
Merit: 100
I've been doing some weird piecing together of python code but I totally understand what I have (I'm not the best at it).  Now, the only piece i'm missing is how to convert a public key (x,y) coordinates in decimal form, to an address.  That's all I need, and I can't figure it out.  I tried https://github.com/weex/addrgen but its broken up into so many pieces I can't make sense of it.  Hell, I can't even find out where the freaking variable is that designates the original private key (in decimal format) in that code.  I could actually work with that too (i think), but I can't find that part in the code.  I'm looking to spit out a bunch of addresses, but specific to certain private keys and it would be too laborious to do manually in a program one by one or on a website one by one. Any help would be greatly appreciated.  thanks.
do you have sample for java ?
sr. member
Activity: 412
Merit: 287
Why not go for python-bitcoinlib, or pybitcointools? They include functions to do this.

The procedure you need is:
 - Serialize the public key, paying attention to whether the private key requires compression for public keys.
 - Hash the serialized public key with RIPEMD160(SHA256(X))
 - Base58_check encode the hash, using \x00 as the version byte.
newbie
Activity: 2
Merit: 0
I've been doing some weird piecing together of python code but I totally understand what I have (I'm not the best at it).  Now, the only piece i'm missing is how to convert a public key (x,y) coordinates in decimal form, to an address.  That's all I need, and I can't figure it out.  I tried https://github.com/weex/addrgen but its broken up into so many pieces I can't make sense of it.  Hell, I can't even find out where the freaking variable is that designates the original private key (in decimal format) in that code.  I could actually work with that too (i think), but I can't find that part in the code.  I'm looking to spit out a bunch of addresses, but specific to certain private keys and it would be too laborious to do manually in a program one by one or on a website one by one. Any help would be greatly appreciated.  thanks.
Jump to: