Author

Topic: WIF key to Bitcoin Address PHP Script Required (Read 1004 times)

full member
Activity: 182
Merit: 107
January 20, 2016, 01:37:30 AM
#4
https://bitcoin.librelamp.com/address.phps

Doesn't go from WIF but does go from ECSDA HEX to address.
legendary
Activity: 3472
Merit: 4801
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.
staff
Activity: 3458
Merit: 6793
Just writing some code
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
newbie
Activity: 30
Merit: 0
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.
Jump to: