Bitcoin Forum
November 23, 2017, 05:41:13 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: bitcoin address algorithm  (Read 2303 times)
Topazan
Sr. Member
****
Offline Offline

Activity: 354


View Profile
April 02, 2013, 07:32:19 AM
 #1

I'm hoping to write a small script to generate bitcoin addresses according to a deterministic algorithm and a password provided by the user.  This will serve as my "offline storage".

I know that I can generate a private key by using sha256 on anything.  My question is, how do I convert this key into an address?

I'm hoping it's a fairly simple formula.  If you could describe it in pseudocode, javascript, or bash, I would appreciate it.

Save the last bitcoin for me!
Join ICO Now A blockchain platform for effective freelancing
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Stephen Gornick
Legendary
*
Offline Offline

Activity: 2324



View Profile
April 02, 2013, 07:35:07 AM
 #2

I'm hoping to write a small script to generate bitcoin addresses according to a deterministic algorithm and a password provided by the user.  This will serve as my "offline storage".

I know that I can generate a private key by using sha256 on anything.  My question is, how do I convert this key into an address?

I'm hoping it's a fairly simple formula.  If you could describe it in pseudocode, javascript, or bash, I would appreciate it.

Javascript private key generator:
 - http://brainwallet.org/#generator

Topazan
Sr. Member
****
Offline Offline

Activity: 354


View Profile
April 02, 2013, 07:39:12 AM
 #3

Thanks.  I tried reverse engineering bitaddress.org, but their structure was a little too confusing for me.  I'll take a crack at that site.

EDIT: Actually, it looks like the same code.  Oh well, I'll keep trying.  I think I see the relevant section anyway.

Save the last bitcoin for me!
Stephen Gornick
Legendary
*
Offline Offline

Activity: 2324



View Profile
April 02, 2013, 08:01:12 AM
 #4

I tried reverse engineering bitaddress.org, but their structure was a little too confusing for me.

Brain Wallet:

Private key = sha256(passphrase)
 - http://en.bitcoin.it/wiki/Brainwallet

Then this:

How can I convert a SHA256 hash into a Bitcoin base58 private key?
 - http://bitcoin.stackexchange.com/a/8249/153

jackjack
Legendary
*
Offline Offline

Activity: 1120


May Bitcoin be touched by his Noodly Appendage


View Profile
April 02, 2013, 08:50:26 AM
 #5

Keep looking for it in the wiki, it's definitely there
Is something like sha256 then add a byte then ripemd160

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
DannyHamilton
Legendary
*
Online Online

Activity: 1988



View Profile
April 02, 2013, 03:09:12 PM
 #6

Keep looking for it in the wiki, it's definitely there
Is something like sha256 then add a byte then ripemd160

I suspect that the struggle isn't getting the address from the public key, but rather getting the public key from the private key.  This is where I've struggled so far.  Once you have the public key, the rest is simple.

Assuming that I'm not going to use Python, PHP, or javascript, how would I go about calculating the public key?  Are there standard OpenSSL programs already included in Mac OSX that I can use to calculate the public key?  Are there trusted libraries for PERL that I can use to calculate the public key?

deepceleron
Legendary
*
Offline Offline

Activity: 1512



View Profile WWW
April 02, 2013, 04:16:23 PM
 #7

The function you are looking for is valid private key -> ECDSA secp256k1 -> public key

You must also have Bitcoin's base58 encoding/decoding if you want to use or import the "5J" style private key.

Javascript:
Look at bitaddress.org source code. It's very easy to read. Near the end there is the wallet details tab. You'll see there which functions are called to get the public key. Search back for the function and see how it's done.

This code is also good as a template for writing in other languages.
eg. some bits chopped out,
Code:
var ecparams = EllipticCurve.getSECCurveByName("secp256k1");

ECKey.prototype.getPub = function () {
if (this.pub) return this.pub;
return this.pub = ecparams.getG().multiply(this.priv).getEncoded(0);
};

ECKey.prototype.getPubKeyHex = function () {
if (this.pubKeyHex) return this.pubKeyHex;
return this.pubKeyHex = Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase();
};
A bit more digging and should have it.

References:
Math: http://cs.ucsb.edu/~koc/ccs130h/notes/ecdsa.pdf
crypto++: http://www.cryptopp.com/wiki/Elliptic_Curve_Digital_Signature_Algorithm#Public_Key
openssl: http://www.ruby-forum.com/topic/4407216

Topazan
Sr. Member
****
Offline Offline

Activity: 354


View Profile
April 04, 2013, 06:04:37 AM
 #8

@Stephen - Thanks, but that's not what I'm looking for.  I want to convert it to an address, not to wallet import format.

Quote
Insert Quote
Keep looking for it in the wiki, it's definitely there
Is something like sha256 then add a byte then ripemd160
Thanks, searching for ripemd led me here.  Which brings me to...

Quote
I suspect that the struggle isn't getting the address from the public key, but rather getting the public key from the private key.  This is where I've struggled so far.  Once you have the public key, the rest is simple.
...here.  That seems to be the case based on the wiki.

@deepceleron- Thanks, I'll follow through on that when I have time.

Save the last bitcoin for me!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!