Merge pull request #330 from olalonde/fix/329
Use browser field in package.json instead of process.verions tests
This commit is contained in:
commit
5f064cddec
|
@ -10,10 +10,10 @@ var requireWhenAccessed = function(name, file) {
|
|||
Object.defineProperty(module.exports, name, {get: function() {return require(file)}});
|
||||
};
|
||||
|
||||
requireWhenAccessed('Bignum', './lib/Bignum');
|
||||
requireWhenAccessed('Bignum', 'bignum');
|
||||
Object.defineProperty(module.exports, 'bignum', {get: function() {
|
||||
console.log('bignum (with a lower-case "b") is deprecated. Use bitcore.Bignum (capital "B") instead.');
|
||||
return require('./lib/Bignum');
|
||||
return require('bignum');
|
||||
}});
|
||||
requireWhenAccessed('Base58', './lib/Base58');
|
||||
Object.defineProperty(module.exports, 'base58', {get: function() {
|
||||
|
|
|
@ -25,7 +25,6 @@ var pack = function (params) {
|
|||
var modules = [
|
||||
'lib/Address',
|
||||
'lib/Base58',
|
||||
'lib/Bignum',
|
||||
'lib/BIP32',
|
||||
'lib/Block',
|
||||
'lib/Bloom',
|
||||
|
|
|
@ -4,7 +4,7 @@ var coinUtil = imports.coinUtil || require('../util');
|
|||
var Key = imports.Key || require('./Key');
|
||||
var Point = imports.Point || require('./Point');
|
||||
var SecureRandom = imports.SecureRandom || require('./SecureRandom');
|
||||
var bignum = imports.bignum || require('./Bignum');
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var networks = require('../networks');
|
||||
|
||||
var secp256k1_n = new bignum('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 16);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var crypto = require('crypto');
|
||||
var bignum = require('./Bignum');
|
||||
var bignum = require('bignum');
|
||||
|
||||
var globalBuffer = new Buffer(1024);
|
||||
var zerobuf = new Buffer(0);
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
if (process.versions) {
|
||||
module.exports = require('bignum');
|
||||
return;
|
||||
}
|
||||
module.exports = require('./browser/Bignum');
|
|
@ -3,7 +3,7 @@ var imports = require('soop').imports();
|
|||
var util = imports.util || require('../util');
|
||||
var Debug1 = imports.Debug1 || function() {};
|
||||
var Script = imports.Script || require('./Script');
|
||||
var Bignum = imports.Bignum || require('./Bignum');
|
||||
var Bignum = imports.Bignum || require('bignum');
|
||||
var Binary = imports.Binary || require('binary');
|
||||
var Step = imports.Step || require('step');
|
||||
var buffertools = imports.buffertools || require('buffertools');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
var imports = require('soop');
|
||||
var bignum = imports.bignum || require('./Bignum');
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var Point = imports.Point || require('./Point');
|
||||
|
||||
var n = bignum.fromBuffer(new Buffer("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 'hex'), {size: 32});
|
||||
|
|
|
@ -2,7 +2,7 @@ var Key = require('./Key'),
|
|||
Point = require('./Point'),
|
||||
twoSha256 = require('../util').twoSha256,
|
||||
buffertools = require('buffertools'),
|
||||
bignum = require('./Bignum');
|
||||
bignum = require('bignum');
|
||||
|
||||
/**
|
||||
* Pre-BIP32 Electrum public key derivation (electrum <2.0)
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
if (process.versions) {
|
||||
module.exports = require('./node/Key');
|
||||
return;
|
||||
}
|
||||
module.exports = require('./browser/Key');
|
||||
module.exports = require('bindings')('KeyModule').Key;
|
||||
|
|
44
lib/Point.js
44
lib/Point.js
|
@ -1,5 +1,39 @@
|
|||
if (process.versions) {
|
||||
module.exports = require('./node/Point');
|
||||
return;
|
||||
}
|
||||
module.exports = require('./browser/Point');
|
||||
"use strict";
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var CPPKey = imports.CPPKey || require('bindings')('KeyModule').Key;
|
||||
var assert = require('assert');
|
||||
|
||||
//a point on the secp256k1 curve
|
||||
//x and y are bignums
|
||||
var Point = function(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
|
||||
Point.add = function(p1, p2) {
|
||||
var u1 = p1.toUncompressedPubKey();
|
||||
var u2 = p2.toUncompressedPubKey();
|
||||
var pubKey = CPPKey.addUncompressed(u1, u2);
|
||||
return Point.fromUncompressedPubKey(pubKey);
|
||||
};
|
||||
|
||||
//convert the public key of a Key into a Point
|
||||
Point.fromUncompressedPubKey = function(pubkey) {
|
||||
var point = new Point();
|
||||
point.x = bignum.fromBuffer(pubkey.slice(1, 33), {size: 32});
|
||||
point.y = bignum.fromBuffer(pubkey.slice(33, 65), {size: 32});
|
||||
return point;
|
||||
};
|
||||
|
||||
//convert the Point into the Key containing a compressed public key
|
||||
Point.prototype.toUncompressedPubKey = function() {
|
||||
var xbuf = this.x.toBuffer({size: 32});
|
||||
var ybuf = this.y.toBuffer({size: 32});
|
||||
var prefix = new Buffer([0x04]);
|
||||
var pubkey = Buffer.concat([prefix, xbuf, ybuf]);
|
||||
return pubkey;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Point);
|
||||
|
|
|
@ -4,7 +4,7 @@ var log = imports.log || require('../util/log');
|
|||
var util = imports.util || require('../util');
|
||||
var Opcode = imports.Opcode || require('./Opcode');
|
||||
var buffertools = imports.buffertools || require('buffertools');
|
||||
var bignum = imports.bignum || require('./Bignum');
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var Util = imports.Util || require('../util');
|
||||
var Script = require('./Script');
|
||||
var Key = require('./Key');
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
if (process.versions) {
|
||||
module.exports = require('./node/SecureRandom');
|
||||
return;
|
||||
var imports = require('soop');
|
||||
var crypto = imports.crypto || require('crypto');
|
||||
|
||||
var SecureRandom = require('./common/SecureRandom');
|
||||
|
||||
SecureRandom.getRandomBuffer = function(size) {
|
||||
return crypto.randomBytes(size);
|
||||
}
|
||||
module.exports = require('./browser/SecureRandom');
|
||||
|
||||
module.exports = require('soop')(SecureRandom);
|
||||
|
|
|
@ -5,7 +5,7 @@ var Address = imports.Address || require('./Address');
|
|||
var Script = imports.Script || require('./Script');
|
||||
var ScriptInterpreter = imports.ScriptInterpreter || require('./ScriptInterpreter');
|
||||
var util = imports.util || require('../util');
|
||||
var bignum = imports.bignum || require('./Bignum');
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var Put = imports.Put || require('bufferput');
|
||||
var Parser = imports.Parser || require('../util/BinaryParser');
|
||||
var Step = imports.Step || require('step');
|
||||
|
|
|
@ -54,7 +54,7 @@ var imports = require('soop').imports();
|
|||
var Address = imports.Address || require('./Address');
|
||||
var Script = imports.Script || require('./Script');
|
||||
var util = imports.util || require('../util');
|
||||
var bignum = imports.bignum || require('./Bignum');
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var buffertools = imports.buffertools || require('buffertools');
|
||||
var networks = imports.networks || require('../networks');
|
||||
var WalletKey = imports.WalletKey || require('./WalletKey');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var ECKey = require('../../browser/vendor-bundle.js').ECKey;
|
||||
var SecureRandom = require('../SecureRandom');
|
||||
var Curve = require('../Curve');
|
||||
var bignum = require('../Bignum');
|
||||
var bignum = require('bignum');
|
||||
|
||||
var Key = function() {
|
||||
this._pub = null;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
var imports = require('soop').imports();
|
||||
var Key = imports.Key || require('./Key');
|
||||
var bignum = imports.bignum || require('../Bignum');
|
||||
var bignum = imports.bignum || require('bignum');
|
||||
var assert = require('assert');
|
||||
var ECPointFp = require('../../browser/vendor-bundle.js').ECPointFp;
|
||||
var ECFieldElementFp = require('../../browser/vendor-bundle.js').ECFieldElementFp;
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
var Key = require('bindings')('KeyModule').Key;
|
||||
|
||||
module.exports = Key;
|
|
@ -1,39 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var bignum = imports.bignum || require('../Bignum');
|
||||
var CPPKey = imports.CPPKey || require('bindings')('KeyModule').Key;
|
||||
var assert = require('assert');
|
||||
|
||||
//a point on the secp256k1 curve
|
||||
//x and y are bignums
|
||||
var Point = function(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
|
||||
Point.add = function(p1, p2) {
|
||||
var u1 = p1.toUncompressedPubKey();
|
||||
var u2 = p2.toUncompressedPubKey();
|
||||
var pubKey = CPPKey.addUncompressed(u1, u2);
|
||||
return Point.fromUncompressedPubKey(pubKey);
|
||||
};
|
||||
|
||||
//convert the public key of a Key into a Point
|
||||
Point.fromUncompressedPubKey = function(pubkey) {
|
||||
var point = new Point();
|
||||
point.x = bignum.fromBuffer(pubkey.slice(1, 33), {size: 32});
|
||||
point.y = bignum.fromBuffer(pubkey.slice(33, 65), {size: 32});
|
||||
return point;
|
||||
};
|
||||
|
||||
//convert the Point into the Key containing a compressed public key
|
||||
Point.prototype.toUncompressedPubKey = function() {
|
||||
var xbuf = this.x.toBuffer({size: 32});
|
||||
var ybuf = this.y.toBuffer({size: 32});
|
||||
var prefix = new Buffer([0x04]);
|
||||
var pubkey = Buffer.concat([prefix, xbuf, ybuf]);
|
||||
return pubkey;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Point);
|
|
@ -1,10 +0,0 @@
|
|||
var imports = require('soop');
|
||||
var crypto = imports.crypto || require('crypto');
|
||||
|
||||
var SecureRandom = require('../common/SecureRandom');
|
||||
|
||||
SecureRandom.getRandomBuffer = function(size) {
|
||||
return crypto.randomBytes(size);
|
||||
}
|
||||
|
||||
module.exports = require('soop')(SecureRandom);
|
|
@ -98,6 +98,12 @@
|
|||
"android-browser/latest"
|
||||
]
|
||||
},
|
||||
"browser": {
|
||||
"bignum": "./lib/browser/Bignum.js",
|
||||
"./lib/Key.js": "./lib/browser/Key.js",
|
||||
"./lib/Point.js": "./lib/browser/Point.js",
|
||||
"./lib/SecureRandom.js": "./lib/browser/SecureRandom.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
var crypto = require('crypto');
|
||||
var bignum = require('../lib/Bignum');
|
||||
var bignum = require('bignum');
|
||||
var Binary = require('binary');
|
||||
var Put = require('bufferput');
|
||||
var buffertools = require('buffertools');
|
||||
|
|
Loading…
Reference in New Issue