BlackHatCoiner (OP)
Legendary
Offline
Activity: 1652
Merit: 8124
Bitcoin is a royal fork
|
|
July 07, 2020, 04:24:14 PM |
|
Hello, I'm trying to make an address from my custom private key, but I need some help.
This is my 64 length private key in hex: c89856dd1b8f867fedfbefaa95c340a086aaaf1b086ffa3772b37540b45912f9
What exactly happens next? Cause I think, I'm not doing it correctly. I want to reach that private key to a p2pkh address.
|
|
|
|
TheArchaeologist
|
|
July 07, 2020, 05:05:31 PM |
|
Since you didn't describe what steps you took I can't comment on what you did wrong. What I can tell you is the following: You got your private key: c89856dd1b8f867fedfbefaa95c340a086aaaf1b086ffa3772b37540b45912f9
Based on this private key you can generate either a compressed or uncompressed public key: Public keys: compressed: 039E8CFA0C5F56D61AA7ADC9CCE5963E9622C29AF2D61E82A2494B7051107B8720 uncompressed:049E8CFA0C5F56D61AA7ADC9CCE5963E9622C29AF2D61E82A2494B7051107B8720D2A18C74A3968A65860CCCAE2892A6A6B39001104B34D5E8D332598C06625A03
The public keys result in a different address but use the exact same algorithm and end up encoding a hash in base58 format. So both these addresses are "p2pkh", most newer ones are bases on a compressed public key: compressed: 1L1Z1V8WCQi5DEuQeF3GLR9LPWEUF2swtU uncompressed: 15hw8MaTFjJsdkpwGNoBZRjGoCNzUy3D37
|
Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
|
|
|
odolvlobo
Legendary
Offline
Activity: 4438
Merit: 3387
|
Hello, I'm trying to make an address from my custom private key, but I need some help.
This is my 64 length private key in hex: c89856dd1b8f867fedfbefaa95c340a086aaaf1b086ffa3772b37540b45912f9
What exactly happens next? Cause I think, I'm not doing it correctly. I want to reach that private key to a p2pkh address.
This page shows all of the steps. though is a out of date: http://gobittest.appspot.com/Address
|
Join an anti-signature campaign: Click ignore on the members of signature campaigns. PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
|
|
|
BTCW
Copper Member
Full Member
Offline
Activity: 193
Merit: 244
Click "+Merit" top-right corner
|
|
July 07, 2020, 05:41:59 PM |
|
I wrote a new python script for this (for my friends at https://btcleak.com/ - they will hopefully publish the source code soon; it's pretty neat, uses fastecdsa which is like a thousand times faster than the standard library, check back in a bit), the output is: ==============
Hex: c89856dd1b8f867fedfbefaa95c340a086aaaf1b086ffa3772b37540b45912f9
Uncompressed Private Key WIF: 5KLdWjcaX1983KPCE3diBD7gc11L5KVmEEsy8iEjYb7w6syygUH Uncompressed Legacy Address: 15hw8MaTFjJsdkpwGNoBZRjGoCNzUy3D37
Compressed Private Key WIF: L3weAF62wRcr5E8xYad2k4UVoV2TC4dxDSFxm31cnRbbncJiBGue Compressed Legacy Address: 1L1Z1V8WCQi5DEuQeF3GLR9LPWEUF2swtU Wrapped P2SH-P2WPKH Address: 3B5R1gaz9eH2Vh9NRUEkwL8fbD6fPXiyeY Wrapped P2WPKH Bech32 Address: bc1q6zz3hma6gzqk4uf5tfx8r907lsslc7uvepafx0
============== The link odolvlobo provided explains the steps well too.
|
|
|
|
BrewMaster
Legendary
Offline
Activity: 2114
Merit: 1293
There is trouble abrewing
|
|
July 07, 2020, 05:49:03 PM |
|
Wrapped P2WPKH Bech32 Address: bc1q6zz3hma6gzqk4uf5tfx8r907lsslc7uvepafx0
"wrapped" usually refers to a P2WPKH script that is "wrapped" inside a P2SH script. but the normal P2WPKH script that produces the bech32 address is called the "native" SegWit address.
|
There is a FOMO brewing...
|
|
|
BlackHatCoiner (OP)
Legendary
Offline
Activity: 1652
Merit: 8124
Bitcoin is a royal fork
|
|
July 07, 2020, 07:08:09 PM |
|
Hello, I'm trying to make an address from my custom private key, but I need some help.
This is my 64 length private key in hex: c89856dd1b8f867fedfbefaa95c340a086aaaf1b086ffa3772b37540b45912f9
What exactly happens next? Cause I think, I'm not doing it correctly. I want to reach that private key to a p2pkh address.
This page shows all of the steps. though is a out of date: http://gobittest.appspot.com/AddressI wonder if these files are open source on github. I would like to check them. In what lang they are written for example.
|
|
|
|
|
BTCW
Copper Member
Full Member
Offline
Activity: 193
Merit: 244
Click "+Merit" top-right corner
|
|
July 07, 2020, 08:55:23 PM Last edit: July 08, 2020, 09:53:51 AM by BTCW |
|
Here is a quick and dirty solution in Python3 (command line, not a saved script) I threw together. I don't have time to comment on each step, it just works. Feel free to ask me about it. >>> import hashlib, binascii, base58 >>> from fastecdsa import keys, curve, ecdsa >>> hexkey='c89856dd1b8f867fedfbefaa95c340a086aaaf1b086ffa3772b37540b45912f9' >>> base58.b58encode_check(binascii.a2b_hex('80'+hexkey+'01')).decode() 'L3weAF62wRcr5E8xYad2k4UVoV2TC4dxDSFxm31cnRbbncJiBGue' >>> curve = curve.secp256k1 >>> pub_key = keys.get_public_key(int(hexkey,16), curve) >>> uncompressed_public_key = '04'+str(hex(pub_key.x)[2:]).zfill(64)+str(hex(pub_key.y)[2:]).zfill(64) >>> if int(str(pub_key.y)) % 2 == 0: ... compressed_public_key = '02' ... else: ... compressed_public_key = '03' ... >>> compressed_public_key += str(uncompressed_public_key[2:66]) >>> compressed_hash160 = hashlib.new('ripemd160',hashlib.sha256(binascii.unhexlify(compressed_public_key)).digest()).hexdigest() >>> base58.b58encode_check(binascii.unhexlify('00'+compressed_hash160)).decode() '1L1Z1V8WCQi5DEuQeF3GLR9LPWEUF2swtU' It gives you the same result as my "real" script and the aforementioned link, which is proof it's working as intended.
|
|
|
|
TheArchaeologist
|
I wonder if these files are open source on github. I would like to check them. In what lang they are written for example.
This function is in python from my own software. It works with compressed/uncompressed keys: import binascii, base58, hashlib
def public_key_to_address(public_key): bin = binascii.unhexlify(public_key)
#Step 1: Create hash of public key: hash_of_public_key = hashlib.sha256(bin).digest()
#Step 2: Calculate RIPEMD-160 of the public key: r = hashlib.new('ripemd160') r.update(hash_of_public_key) r.hexdigest()
#Step 3: Adding network bytes (00) to RIPEMD-160 networked = binascii.unhexlify('00'+r.hexdigest())
#Step 4: Double hash the networked RIPEMD-160 sha4a = hashlib.sha256(networked).digest() sha4b = hashlib.sha256(sha4a).digest()
#Step 5: Get the first four bytes of sha4b: four_bytes = str(binascii.hexlify(sha4b).decode('utf-8'))[:8]
#Step 6: Adding the four_bytes to the end the RIPEMD-160 from step 3: address_hex = str(binascii.hexlify(networked).decode('utf-8')) + four_bytes
#Step 7: Convert the hex_address using base58 to bitcoin adres address_base58 = base58.b58encode(binascii.unhexlify(address_hex))
return str(address_base58.decode())
|
Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
|
|
|
TheArchaeologist
|
|
July 07, 2020, 09:19:32 PM |
|
What do you mean by the page is out of date? The process of generating legacy addresses from private keys hasn't changed. How can it be out of date?
Although the page itself still works it gives a warning the public key is of an invalid length when entered in compressed format. So it is kind of out-of-date for not recognizing compressed public keys as valid.
|
Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
|
|
|
|
o_e_l_e_o
In memoriam
Legendary
Offline
Activity: 2268
Merit: 18704
|
|
July 07, 2020, 09:56:38 PM |
|
You have to use elliptic curve multiplication to multiply the private key by the generator point (G) in the secp256k1 curve to obtain the public key. The compressed generator point for bitcoin is as follows: 02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798 Public key = Private key * G If you want to read more about how this is done, I would suggest starting here: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch04.asciidoc#public-keys
|
|
|
|
BTCW
Copper Member
Full Member
Offline
Activity: 193
Merit: 244
Click "+Merit" top-right corner
|
|
July 07, 2020, 11:16:01 PM |
|
You have to use elliptic curve multiplication to multiply the private key by the generator point (G) in the secp256k1 curve to obtain the public key. The compressed generator point for bitcoin is as follows: 02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798 Public key = Private key * G If you want to read more about how this is done, I would suggest starting here: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch04.asciidoc#public-keysElliptic-curve cryptography (ECC) is not trivial. This is one of the great ironies with Bitcoin, in my opinion, that calculating the public key (which is NOT the same thing as the public address) is by far the toughest part of the sequence. In my code in the previous post, I used this library (my warmest recommendations!) https://github.com/AntonKueltz/fastecdsa(I used "sudo python3 -m pip install fastecdsa" to install it, and I'm well aware that this particular method, even though it works like a charm, is often frowned upon.) And I showed how it can be used to derive what the OP wanted. Exact code (albeit poorly commented); what more do you need? Edit: The code TheArchaeologist share is pretty neat, but it doesn't include ECC, getting the public key to begin with, also the toughest part.)
|
|
|
|
pooya87
Legendary
Offline
Activity: 3584
Merit: 10876
|
|
July 08, 2020, 02:53:00 AM |
|
Elliptic-curve cryptography (ECC) is not trivial. This is one of the great ironies with Bitcoin, in my opinion, that calculating the public key (which is NOT the same thing as the public address) is by far the toughest part of the sequence.
it really isn't as tough as you think. it is like saying computing SHA256 is tough. you simply use a library (eg. hashlib) and call its Sha256.Compute function. similarly for computing public key from a private key, you simply use the ECC.GetPublicKey function. but since this is new and uncommon (unlike computing SHA256) it seems hard at first sight.
|
|
|
|
BlackHatCoiner (OP)
Legendary
Offline
Activity: 1652
Merit: 8124
Bitcoin is a royal fork
|
|
July 08, 2020, 06:08:47 AM |
|
Elliptic-curve cryptography (ECC) is not trivial. This is one of the great ironies with Bitcoin, in my opinion, that calculating the public key (which is NOT the same thing as the public address) is by far the toughest part of the sequence.
it really isn't as tough as you think. it is like saying computing SHA256 is tough. you simply use a library (eg. hashlib) and call its Sha256.Compute function. similarly for computing public key from a private key, you simply use the ECC.GetPublicKey function. but since this is new and uncommon (unlike computing SHA256) it seems hard at first sight. Yes, the difference is that SHA256 is more widespread. I don't think that you can use ECC(string) in PHP for example.
|
|
|
|
|
|
|