Bitcoin Forum
May 02, 2024, 07:34:50 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: simple python bitcoin public key to address  (Read 1357 times)
unknown9387 (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
May 27, 2016, 08:50:26 AM
 #1

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.
1714678490
Hero Member
*
Offline Offline

Posts: 1714678490

View Profile Personal Message (Offline)

Ignore
1714678490
Reply with quote  #2

1714678490
Report to moderator
Even in the event that an attacker gains more than 50% of the network's computational power, only transactions sent by the attacker could be reversed or double-spent. The network would not be destroyed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714678490
Hero Member
*
Offline Offline

Posts: 1714678490

View Profile Personal Message (Offline)

Ignore
1714678490
Reply with quote  #2

1714678490
Report to moderator
fbueller
Sr. Member
****
Offline Offline

Activity: 412
Merit: 266


View Profile
May 27, 2016, 05:54:12 PM
Merited by ABCbits (1)
 #2

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.

Bitwasp Developer.
dewildance
Full Member
***
Offline Offline

Activity: 546
Merit: 100



View Profile
June 08, 2016, 05:41:10 PM
 #3

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 ?
kn_b_y
Newbie
*
Offline Offline

Activity: 26
Merit: 3


View Profile
June 08, 2016, 10: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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!