Browse Source

Merge pull request #134 from maraoz/feature/configurable-bundle

browser files refactor and name changes
patch-2
Ryan X. Charles 11 years ago
parent
commit
55d236741d
  1. 1
      .gitignore
  2. 7
      Key.js
  3. 2
      browser/bitcoin.js
  4. 2865
      browser/bitcoinjs-lib.js
  5. 1
      browser/browser.js
  6. 11
      browser/browserify.js
  7. 6
      browser/concat.sh
  8. 5
      browser/vendor/browser-adapter.js
  9. 0
      browser/vendor/crypto.js
  10. 0
      browser/vendor/ec.js
  11. 34
      browser/vendor/ecdsa.js
  12. 0
      browser/vendor/eckey.js
  13. 0
      browser/vendor/jsbn.js
  14. 0
      browser/vendor/jsbn2.js
  15. 0
      browser/vendor/prng4.js
  16. 0
      browser/vendor/ripemd160.js
  17. 0
      browser/vendor/rng.js
  18. 0
      browser/vendor/sec.js
  19. 0
      browser/vendor/util.js
  20. 8
      util/util.js

1
.gitignore

@ -1,5 +1,6 @@
build/ build/
browser/bundle.js browser/bundle.js
browser/vendor-bundle.js
browser/testdata.js browser/testdata.js
node_modules/ node_modules/
*.swp *.swp

7
Key.js

@ -5,7 +5,7 @@ if (process.versions) {
module.exports = require('bindings')('KeyModule'); module.exports = require('bindings')('KeyModule');
} else { } else {
// pure js version // pure js version
var ECKey = require('./browser/bitcoinjs-lib.js').ECKey; var ECKey = require('./browser/vendor-bundle.js').ECKey;
var buffertools = require('buffertools'); var buffertools = require('buffertools');
var bufferToArray = function(buffer) { var bufferToArray = function(buffer) {
@ -89,10 +89,11 @@ if (process.versions) {
} }
var eck = new ECKey(); var eck = new ECKey();
eck.setPub( bufferToArray(self.public)); eck.setPub(bufferToArray(self.public));
eck.setCompressed(self.compressed); eck.setCompressed(self.compressed);
var sigA = bufferToArray(sig); var sigA = bufferToArray(sig);
return eck.verify(hash,sigA); var ret = eck.verify(hash,sigA);
return ret;
}; };

2
browser/bitcoin.js

@ -1,2 +0,0 @@
Bitcoin = {};

2865
browser/bitcoinjs-lib.js

File diff suppressed because it is too large

1
browser/browser.js

@ -1 +0,0 @@
if ('undefined' === typeof window) window = this;

11
browser/browserify.js

@ -11,6 +11,17 @@ var fs = require('fs');
var browserify = require('browserify'); var browserify = require('browserify');
var browserPack = require('browser-pack'); var browserPack = require('browser-pack');
// concat browser vendor files
var exec = require('child_process').exec;
var sys = require('sys');
var puts = function(error, stdout, stderr) {
if (error) console.log(error);
sys.puts(stdout);
sys.puts(stderr);
};
exec('cd browser; sh concat.sh', puts);
var pack = function (params) { var pack = function (params) {
var preludePath = 'node_modules/soop/example/custom_prelude.js'; var preludePath = 'node_modules/soop/example/custom_prelude.js';

6
browser/concat.sh

@ -1,3 +1,7 @@
#! /bin/bash #! /bin/bash
cat browser.js crypto.js ripemd160.js bitcoin.js navigator-adapter.js jsbn.js jsbn2.js prng4.js util.js rng.js ec.js sec.js ecdsa.js eckey.js > bitcoinjs-lib.js cd vendor/
cat browser-adapter.js crypto.js ripemd160.js jsbn.js jsbn2.js prng4.js util.js rng.js ec.js sec.js ecdsa.js eckey.js > vendor-bundle.js
mv vendor-bundle.js ../
cd ../

5
browser/navigator-adapter.js → browser/vendor/browser-adapter.js

@ -1,7 +1,6 @@
if ('undefined' === typeof window) window = this;
Bitcoin = {};
if (typeof navigator === 'undefined') { if (typeof navigator === 'undefined') {
var navigator = {}; var navigator = {};
navigator.appName = 'NodeJS'; navigator.appName = 'NodeJS';
} }

0
browser/crypto.js → browser/vendor/crypto.js

0
browser/ec.js → browser/vendor/ec.js

34
browser/ecdsa.js → browser/vendor/ecdsa.js

@ -41,24 +41,34 @@ ECPointFp.prototype.getEncoded = function (compressed) {
return enc; return enc;
}; };
ECPointFp.decodeFrom = function (curve, enc) { ECPointFp.decodeFrom = function (ecparams, enc) {
var type = enc[0]; var type = enc[0];
var dataLen = enc.length-1; var dataLen = enc.length-1;
// Extract x and y as byte arrays // Extract x and y as byte arrays
var xBa = enc.slice(1, 1 + dataLen/2); if (type === 4) {
var yBa = enc.slice(1 + dataLen/2, 1 + dataLen); var xBa = enc.slice(1, 1 + dataLen/2),
yBa = enc.slice(1 + dataLen/2, 1 + dataLen),
// Prepend zero byte to prevent interpretation as negative integer x = BigInteger.fromByteArrayUnsigned(xBa),
xBa.unshift(0); y = BigInteger.fromByteArrayUnsigned(yBa);
yBa.unshift(0); }
else {
// Convert to BigIntegers var xBa = enc.slice(1),
var x = new BigInteger(xBa); x = BigInteger.fromByteArrayUnsigned(xBa),
var y = new BigInteger(yBa); p = ecparams.getQ(),
xCubedPlus7 = x.multiply(x).multiply(x).add(new BigInteger('7')).mod(p),
pPlus1Over4 = p.add(new BigInteger('1'))
.divide(new BigInteger('4')),
y = xCubedPlus7.modPow(pPlus1Over4,p);
if (y.mod(new BigInteger('2')).toString() != ''+(type % 2)) {
y = p.subtract(y)
}
}
// Return point // Return point
return new ECPointFp(curve, curve.fromBigInteger(x), curve.fromBigInteger(y)); return new ECPointFp(ecparams,
ecparams.fromBigInteger(x),
ecparams.fromBigInteger(y));
}; };
ECPointFp.prototype.add2D = function (b) { ECPointFp.prototype.add2D = function (b) {

0
browser/eckey.js → browser/vendor/eckey.js

0
browser/jsbn.js → browser/vendor/jsbn.js

0
browser/jsbn2.js → browser/vendor/jsbn2.js

0
browser/prng4.js → browser/vendor/prng4.js

0
browser/ripemd160.js → browser/vendor/ripemd160.js

0
browser/rng.js → browser/vendor/rng.js

0
browser/sec.js → browser/vendor/sec.js

0
browser/util.js → browser/vendor/util.js

8
util/util.js

@ -4,10 +4,10 @@ var bignum = require('bignum');
var Binary = require('binary'); var Binary = require('binary');
var Put = require('bufferput'); var Put = require('bufferput');
var buffertools = require('buffertools'); var buffertools = require('buffertools');
var bjs; var browser;
if (!process.versions) { if (!process.versions) {
// browser version // browser version
bjs = require('../browser/bitcoinjs-lib.js'); browser = require('../browser/vendor-bundle.js');
} }
@ -17,8 +17,8 @@ var sha256 = exports.sha256 = function (data) {
var ripe160 = exports.ripe160 = function (data) { var ripe160 = exports.ripe160 = function (data) {
if (!process.versions) { if (!process.versions) {
var RIPEMD160 = bjs.RIPEMD160; var RIPEMD160 = browser.RIPEMD160;
var WordArray = bjs.WordArray; var WordArray = browser.WordArray;
data = data.toString(); data = data.toString();
var result = RIPEMD160(data) + ''; var result = RIPEMD160(data) + '';
return new Buffer(result, 'hex'); return new Buffer(result, 'hex');

Loading…
Cancel
Save