Bitcoin Forum
May 11, 2024, 01:42:00 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: WIF key to Bitcoin Address PHP Script Required  (Read 981 times)
WAHXTIPL (OP)
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile WWW
January 13, 2016, 01:39:15 PM
 #1

Hi All,

I am looking for little technical support. I am looking for easy and handy PHP Script for converting WIF key to Bitcoin address.

E.g. $PublicAddress = hash("sha256", $WIFKey, false);
Echo $PublicAddress;

I was thinking Bitcoin works on SHA256. I tried above code its not working. It's not giving desired outcome.

Can anyone help noon here?

Please note that I don't want to generate any new private key or verify any key. Just conversion

E.g. private key "5Hpcd....." = Public Address "1dfy...."

Please post only conversion part. Bored with ECDSA studying. Does not make any sense.
1715434920
Hero Member
*
Offline Offline

Posts: 1715434920

View Profile Personal Message (Offline)

Ignore
1715434920
Reply with quote  #2

1715434920
Report to moderator
I HATE TABLES I HATE TABLES I HA(╯°□°)╯︵ ┻━┻ TABLES I HATE TABLES I HATE TABLES
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715434920
Hero Member
*
Offline Offline

Posts: 1715434920

View Profile Personal Message (Offline)

Ignore
1715434920
Reply with quote  #2

1715434920
Report to moderator
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
January 13, 2016, 01:51:54 PM
 #2

I can't help you with php but this is how the whole process works.

First WIF must be converted to the raw private key encoded on hex. See https://en.bitcoin.it/wiki/Wallet_import_format on how that is done.

Then you get the public key and convert that to an address. How that is done is here: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses

DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
January 13, 2016, 03:19:23 PM
 #3

I was thinking Bitcoin works on SHA256.

You thought incorrectly.

I tried above code its not working. It's not giving desired outcome.

That's because your code is calculating a SHA256 hash of the WIF private key.  You are missing nearly a dozen necessary steps.

Can anyone help noon here?

Sure, I'll do what I can.

Bored with ECDSA studying. Does not make any sense.

I can explain the process, but I'm not sure what php tools you have available to complete that process. I'm not a php developer.

WIF contains 3 pieces of information embedded in it (version, private key, checksum).

So the first thing you'll need to do is convert from base58 to binary and then throw away the first byte (this is the version) and the last 4 bytes (these are the checksum).  What you'll have left is a binary representation of the private key.

Next you'll need to perform the point multiplication on the secp256k1 curve using the private key as the multiplier.  The resulting point on the curve is the public key.

Like a WIF private key, a bitcoin address also contains 3 pieces of information embedded in it (version, RIPEMD160 hash, checksum)

I'll assume that you are trying to calculate the compressed key address?

If so, you'll check to see if the Y value of public key point is odd or even.  If it is odd, you'll set a leading byte in front of the X value to 03, otherwise you'll set the leading byte in front of the X value to 02.  Then you can discard the Y value.

Next you'll calculate the SHA256 hash of the leading byte concatenated with the X value.

Next you'll calculate the RIPEMD-160 hash of the result of the SHA256 hash.

You'll then place a 00 byte in front of the RIPEMD-160 hash result (this is the address version byte).

Now you'll need to calculate a SHA256 hash of the leading 00 concatenated with the RIPEMD-160 hash result.

Now you'll need to calculate the SHA256 hash of the SHA256 hash that you just calculated.

The first 4 bytes of this most recent SHA256 hash is the checksum for the bitcoin address.  Concatenate this checksum onto the end of the earlier 00 byte concatenated with the RIPEMD-160 result.

So you should now have a 00 byte followed by the earlier calculated RIPEMD-160 followed by a 4 byte checksum.

Convert this value to base58 and you'll have your bitcoin address.
AliceWonderMiscreations
Full Member
***
Offline Offline

Activity: 182
Merit: 107


View Profile WWW
January 20, 2016, 06:37:30 AM
 #4

https://bitcoin.librelamp.com/address.phps

Doesn't go from WIF but does go from ECSDA HEX to address.

I hereby reserve the right to sometimes be wrong
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!