Bitcoin Forum
May 13, 2024, 02:42:26 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: WIF to address?  (Read 1530 times)
kjj (OP)
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
April 10, 2012, 04:30:23 PM
 #1

So, what is the best way to turn a WIF privkey into a public key / address?

Should I convert the WIF to DER or PEM and let openssl make the public key?  Or does anyone have some code that can do it directly?

My target is PHP on Linux, or shell, but I can probably use (or translate) from perl or python.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
If you want to be a moderator, report many posts with accuracy. You will be noticed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
kjj (OP)
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
April 10, 2012, 06:13:34 PM
 #2

No, in that thread they are using openSSL to generate the private and public keys as a random pair.  I need to create a public key to match a premade private key.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
coretechs
Donator
Sr. Member
*
Offline Offline

Activity: 362
Merit: 250



View Profile
April 10, 2012, 06:16:31 PM
Last edit: April 10, 2012, 06:30:32 PM by coretechs
 #3

http://bitaddress.org

Wallet Details tab

It runs in the browser (javascript) so you can save a local copy and run it offline for added security.  It supports compressed pubkeys too.  Wink

I know you didn't mention java but bitcoinj is an option too - http://code.google.com/p/bitcoinj/

https://bitcoindoc.com - The Rise and Rise of Bitcoin | https://blocktap.io - Lightning powered crypto query engine
kjj (OP)
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
April 10, 2012, 06:39:54 PM
 #4

http://bitaddress.org

Wallet Details tab

It runs in the browser (javascript) so you can save a local copy and run it offline for added security.  It supports compressed pubkeys too.  Wink


Yeah, I've seen that.  Of course, my script doesn't have a browser to paste keys into.  I'm hoping that I don't need to translate that monstrosity myself, but that might just be my next step.

It seems odd that there aren't any command line utilities to package a hex or binary private key into a PEM or DER for openssl to use, and no RPC method to find an address to match an imported key.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
kjj (OP)
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
April 16, 2012, 04:54:02 AM
 #5

Woohoo.  I got it.  I started with this paper and software and patched it to support the secp256k1 curve.  It is slow as hell, so I think it is doing the multiplication the hard way, but it works.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
pointbiz
Sr. Member
****
Offline Offline

Activity: 437
Merit: 415

1ninja


View Profile
April 17, 2012, 04:06:26 AM
 #6

http://bitaddress.org

Wallet Details tab

It runs in the browser (javascript) so you can save a local copy and run it offline for added security.  It supports compressed pubkeys too.  Wink


Yeah, I've seen that.  Of course, my script doesn't have a browser to paste keys into.  I'm hoping that I don't need to translate that monstrosity myself, but that might just be my next step.

It seems odd that there aren't any command line utilities to package a hex or binary private key into a PEM or DER for openssl to use, and no RPC method to find an address to match an imported key.

I know you have found a PHP solution but in case others are interested in the javascript command line solution I have provided instructions.

Here is an article on running javascript on the command line:
http://ajaxian.com/archives/javascript-on-the-command-line-or-as-a-shell-scripting-language

You can create a new file called bitaddress.js by copying and pasting the contents of each <script> tag that is inside the <head> of the bitaddress.org HTML document. Only take the JavaScript from the <head> of the document as those are the libraries.

Then at the bottom of that file you can add this function (not tested):
Code:
function wifToAddress(wifKey){
  var bytes = Bitcoin.Base58.decode(wifKey);
  bytes.shift();
  bytes = bytes.slice(0, bytes.length - 4);
  if (bytes.length == 32) {
    var btcKey = new Bitcoin.ECKey(bytes);
    return btcKey.getBitcoinAddress();
  }
}

// call function like this
var myBitcoinAddress = wifToAddress('5ThisIsMyWifAddressLaLaLaLa');

Coder of: https://www.bitaddress.org      Thread
Open Source JavaScript Client-Side Bitcoin Wallet Generator
Donations: 1NiNja1bUmhSoTXozBRBEtR8LeF9TGbZBN   PGP
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!