Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace jsbn.js #24

Closed
arasmussen opened this issue Feb 26, 2014 · 13 comments
Closed

Replace jsbn.js #24

arasmussen opened this issue Feb 26, 2014 · 13 comments

Comments

@arasmussen
Copy link

var eckey = new Bitcoin.ECKey(secretKey);
var curve = getSECCurveByName('secp256k1');
var g = curve.getG();
var curvePoint = g.multiply(eckey.priv);

This last line takes about 20 milliseconds on my computer, which is a bottleneck for the product I'm developing. Would love to see if we can make it faster.

@sidazhang
Copy link
Contributor

@arasmussen hey Andrew,

This repo is no longer maintained, a group of javascript bitcoin developers have come together and forked this so that we can maintain it. It is split into many modules and you can find them here.

https://github.com/cryptocoinjs/

@kyledrake
Copy link
Contributor

As of today, there is a building maintenance team for this repository so we can keep it in sync with bugfixes and changes from the community.

It might be impossible to improve the performance here, but keep in mind that JavaScript is pretty slow at cryptography in general. We don't get any assist from the browser, so this stuff is all implemented in pure JS at the moment.

I won't have time to improve this. Pull requests here are certainly welcome, but I wouldn't expect miracles here. You might be able to shave off 5-15%, but I would be surprised if someone could really speed this up. That said, I doubt the code's been optimized that heavily.

@kyledrake
Copy link
Contributor

One approach could be to implement some of this in Node.js, and then keep the pure JS version for the browser. If that works for you, you might want to take a look at Bitcore, which I believe has already done this.

@abrkn
Copy link
Contributor

abrkn commented Feb 27, 2014

Surely the performance problems must be from the use of jsbn? How about https://github.com/justmoon/node-bignum?

@kyledrake
Copy link
Contributor

Interesting thought.

If we were going to replace jsbn, my early candidate would be https://github.com/MikeMcl/bignumber.js

Also, he uses Bitcoin!

@kyledrake
Copy link
Contributor

Ah, I see what you mean now. That would be a good solution to drop in for node.js usage, falling back to jsbn or something better. My thought was bignumber.js or something similar might be faster than jsbn so it could potentially be considered if it supports the right functionality.

@abrkn
Copy link
Contributor

abrkn commented Feb 27, 2014

big.js and bignumber.js look really nice. an advantage of the one i linked is that it has C bindings.

@abrkn
Copy link
Contributor

abrkn commented Feb 27, 2014

You're right! He accepts bitcoin donations. We've certainly gone mainstream.

@jprichardson
Copy link
Member

We also have the same problem over at http://github.com/cryptocoinjs. We're currently using jsbn extracted into http://github.com/cryptocoinjs/bigi. We've discussed the issue here https://groups.google.com/forum/#!topic/bitcoinhackers/5IlDcTq51Y8 We're strongly considering modifying one of the existing libraries to use Node.js buffers, https://github.com/dominictarr/math-buffer is a good candidate and using Browserify for client compatibility.

big.js and bignumber.js look really nice. an advantage of the one i linked is that it has C bindings.

With this, you give up browser support.

@kyledrake
Copy link
Contributor

We should support browser and node.js. If we did have a node-specific option, we would need to provide a browser alternative as well.

@jprichardson if you come up with a solution here that works in the browser and is faster let us know, we will happily make sure it gets into the code base!

@tgerring
Copy link

Some other library suggestions and a whitepaper courtesy (thanks to Charles Hoskinson for the research!):
http://crypto.stanford.edu/sjcl/
https://clipperz.is/open_source/javascript_crypto_library/
http://eprint.iacr.org/2011/654.pdf

@weilu
Copy link
Contributor

weilu commented Mar 20, 2014

http://jsperf.com/bignumber-js-vs-big-js-vs-jsbn
http://jsperf.com/big-integer-library-test

jsbn still seems like the fastest on most browsers. If someone can wrap https://github.com/justmoon/node-bignum into the same interface as jsbn we can use the wrapped version for node. There will be a speed gain for server side for sure.

@weilu weilu closed this as completed Mar 20, 2014
@weilu weilu reopened this Mar 20, 2014
@hasanmehmood
Copy link

Hi everyone, I have a question ?

I am using bitcoinJS library and I want to create less compressed pub key via private key ?
any help would be appreciated, Please help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants