Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: 🏰 TradeFortress 🏰 on January 06, 2013, 09:19:09 AM



Title: Javascript ECDSA / Bitcoin address generation
Post by: 🏰 TradeFortress 🏰 on January 06, 2013, 09:19:09 AM
I really can't figure out how to get the ECDSA public key of a private key in Javascript. I looked in SJCL but it apparently does it in some non-standard way and isn't compatible with everything else ???


Title: Re: Javascript ECDSA / Bitcoin address generation
Post by: BkkCoins on January 06, 2013, 09:38:12 AM
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.


Title: Re: Javascript ECDSA / Bitcoin address generation
Post by: 🏰 TradeFortress 🏰 on January 06, 2013, 10:00:41 AM
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.
Thanks, did some testing but it's absolutely useless as an vanity address generator as it takes like 600ms to generate on a i7...


Title: Re: Javascript ECDSA / Bitcoin address generation
Post by: bluemeanie1 on November 26, 2013, 10:36:38 PM
Just curious, how did this turn out?  Interested in your experiences with SJCL.


Title: Re: Javascript ECDSA / Bitcoin address generation
Post by: Kouye on November 26, 2013, 11:34:56 PM
Just curious, how did this turn out?  Interested in your experiences with SJCL.

Err, you know TF ran away with thousands of coins and most likely won't come back just to reply to you, right?  ;D


Title: Re: Javascript ECDSA / Bitcoin address generation
Post by: jp on February 08, 2014, 08:29:03 AM
For anyone still looking at it, I wrote an article that may help you: http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript


Title: Re: Javascript ECDSA / Bitcoin address generation
Post by: minzie on February 09, 2014, 01:01:19 PM
@JP, I hate submitting one-line posts, but thanks for sharing that.