Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: btcto on April 03, 2013, 11:06:37 PM



Title: How can I get a public bitcoin address from a WIF (Wallet Import Format)
Post by: btcto on April 03, 2013, 11:06:37 PM
As the subject says: How can I get a public bitcoin address from a WIF (Wallet Import Format)

I'm using PHP, if anyone could point me the right way, that would be great!


Title: Re: How can I get a public bitcoin address from a WIF (Wallet Import Format)
Post by: kjj on April 04, 2013, 02:45:06 AM
You need an ECDSA library for PHP.  There is one available, but it doesn't have the curve we use.  The constants are in the NIST guide.

Once you decode and verify the base58check encoding, you'll be left with 256 bits and an optional 8 bit flag.

The public key is made my multiplying he base point of the curve, g by the 256 bit private key.  The public key is a point, two 256 bit numbers.

If the optional flag was not found while decoding, the public key encoding is chr(4) . $x . $y.  If the flag was found, it is chr(2+($y%2)).$x.

From there, you hash the public key encoding, first with SHA256, and then with RIPEMD-160.  Run that through a base58check encoder, and you have the address.