diff --git a/index.js b/index.js index d80ec69..a6ab75c 100644 --- a/index.js +++ b/index.js @@ -2,18 +2,20 @@ var bitcore = module.exports; // crypto -bitcore.BN = require('./lib/crypto/bn'); -bitcore.ECDSA = require('./lib/crypto/ecdsa'); -bitcore.Hash = require('./lib/crypto/hash'); -bitcore.Random = require('./lib/crypto/random'); -bitcore.Point = require('./lib/crypto/point'); +bitcore.crypto = {}; +bitcore.crypto.BN = require('./lib/crypto/bn'); +bitcore.crypto.ECDSA = require('./lib/crypto/ecdsa'); +bitcore.crypto.Hash = require('./lib/crypto/hash'); +bitcore.crypto.Random = require('./lib/crypto/random'); +bitcore.crypto.Point = require('./lib/crypto/point'); // encoding -bitcore.Base58 = require('./lib/encoding/base58'); -bitcore.Base58Check = require('./lib/encoding/base58check'); -bitcore.BufferReader = require('./lib/encoding/bufferreader'); -bitcore.BufferWriter = require('./lib/encoding/bufferwriter'); -bitcore.Varint = require('./lib/encoding/varint'); +bitcore.encoding = {}; +bitcore.encoding.Base58 = require('./lib/encoding/base58'); +bitcore.encoding.Base58Check = require('./lib/encoding/base58check'); +bitcore.encoding.BufferReader = require('./lib/encoding/bufferreader'); +bitcore.encoding.BufferWriter = require('./lib/encoding/bufferwriter'); +bitcore.encoding.Varint = require('./lib/encoding/varint'); // main bitcoin library bitcore.Address = require('./lib/address'); @@ -21,7 +23,7 @@ bitcore.BIP32 = require('./lib/bip32'); bitcore.Block = require('./lib/block'); bitcore.Blockheader = require('./lib/blockheader'); bitcore.Keypair = require('./lib/keypair'); -bitcore.networks = require('./lib/networks'); +bitcore.Networks = require('./lib/networks'); bitcore.Opcode = require('./lib/opcode'); bitcore.Privkey = require('./lib/privkey'); bitcore.Pubkey = require('./lib/pubkey'); diff --git a/test/block.js b/test/block.js index 6daeccf..39332bd 100644 --- a/test/block.js +++ b/test/block.js @@ -2,10 +2,10 @@ var should = require('chai').should(); var bitcore = require('..'); +var Varint = bitcore.encoding.Varint; +var BufferReader = bitcore.encoding.BufferReader; var Blockheader = bitcore.Blockheader; var Block = bitcore.Block; -var BufferReader = bitcore.BufferReader; -var Varint = bitcore.Varint; var Transaction = bitcore.Transaction; describe('Block', function() { diff --git a/test/blockheader.js b/test/blockheader.js index 6647f0e..b675807 100644 --- a/test/blockheader.js +++ b/test/blockheader.js @@ -2,8 +2,8 @@ var should = require('chai').should(); var bitcore = require('..'); +var BufferReader = bitcore.encoding.BufferReader; var Blockheader = bitcore.Blockheader; -var BufferReader = bitcore.BufferReader; describe('Blockheader', function() { diff --git a/test/keypair.js b/test/keypair.js index 0d9c23f..0804e51 100644 --- a/test/keypair.js +++ b/test/keypair.js @@ -2,7 +2,7 @@ var should = require('chai').should(); var bitcore = require('..'); -var bn = bitcore.BN; +var bn = bitcore.crypto.BN; var Privkey = bitcore.Privkey; var Pubkey = bitcore.Pubkey; var Keypair = bitcore.Keypair; diff --git a/test/networks.js b/test/networks.js index bbacbee..fefd335 100644 --- a/test/networks.js +++ b/test/networks.js @@ -2,20 +2,20 @@ var should = require('chai').should(); var bitcore = require('..'); -var networks = bitcore.networks; +var Networks = bitcore.Networks; -describe('networks', function() { +describe('Networks', function() { - it('should contain all networks', function() { - should.exist(networks.livenet); - should.exist(networks.testnet); - should.exist(networks.mainnet); + it('should contain all Networks', function() { + should.exist(Networks.livenet); + should.exist(Networks.testnet); + should.exist(Networks.mainnet); }); describe('contain all constants for livenet and testnet', function() { - for (var key in networks.livenet) { - if (networks.livenet.hasOwnProperty(key)) { + for (var key in Networks.livenet) { + if (Networks.livenet.hasOwnProperty(key)) { it('all should contain '+key, function() { - networks.testnet.hasOwnProperty(key).should.equal(true); + Networks.testnet.hasOwnProperty(key).should.equal(true); }); } } diff --git a/test/privkey.js b/test/privkey.js index d972687..fc8bd71 100644 --- a/test/privkey.js +++ b/test/privkey.js @@ -2,9 +2,9 @@ var should = require('chai').should(); var bitcore = require('..'); +var BN = bitcore.crypto.BN; +var Point = bitcore.crypto.Point; var Privkey = bitcore.Privkey; -var BN = bitcore.BN; -var Point = bitcore.Point; describe('Privkey', function() { var hex = '96c132224121b509b7d0a16245e957d9192609c5637c6228311287b1be21627a'; diff --git a/test/pubkey.js b/test/pubkey.js index 3feb58e..be96a16 100644 --- a/test/pubkey.js +++ b/test/pubkey.js @@ -2,9 +2,9 @@ var should = require('chai').should(); var bitcore = require('..'); +var Point = bitcore.crypto.Point; +var BN = bitcore.crypto.BN; var Pubkey = bitcore.Pubkey; -var Point = bitcore.Point; -var Bn = bitcore.BN; var Privkey = bitcore.Privkey; describe('Pubkey', function() { @@ -128,7 +128,7 @@ describe('Pubkey', function() { describe('#fromX', function() { it('should create this known public key', function() { - var x = Bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); + var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); var pk = new Pubkey(); pk.fromX(true, x); pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'); @@ -140,7 +140,7 @@ describe('Pubkey', function() { describe('#toBuffer', function() { it('should return this compressed DER format', function() { - var x = Bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); + var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); var pk = new Pubkey(); pk.fromX(true, x); pk.toBuffer().toString('hex').should.equal('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'); @@ -151,14 +151,14 @@ describe('Pubkey', function() { describe('#toDER', function() { it('should return this compressed DER format', function() { - var x = Bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); + var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); var pk = new Pubkey(); pk.fromX(true, x); pk.toDER(true).toString('hex').should.equal('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a'); }); it('should return this uncompressed DER format', function() { - var x = Bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); + var x = BN.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex')); var pk = new Pubkey(); pk.fromX(true, x); pk.toDER(false).toString('hex').should.equal('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341'); diff --git a/test/signature.js b/test/signature.js index 9bf32f5..87ddd7a 100644 --- a/test/signature.js +++ b/test/signature.js @@ -2,7 +2,7 @@ var should = require('chai').should(); var bitcore = require('..'); -var BN = bitcore.BN; +var BN = bitcore.crypto.BN; var Signature = bitcore.Signature; describe('Signature', function() { diff --git a/test/transaction.js b/test/transaction.js index f797e06..41ca481 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -2,11 +2,11 @@ var should = require('chai').should(); var bitcore = require('..'); -var Varint = bitcore.Varint; +var Varint = bitcore.encoding.Varint; +var BufferReader = bitcore.encoding.BufferReader; var Transaction = bitcore.Transaction; var Txin = bitcore.Txin; var Txout = bitcore.Txout; -var BufferReader = bitcore.BufferReader; describe('Transaction', function() { diff --git a/test/txin.js b/test/txin.js index e9738e9..7641f14 100644 --- a/test/txin.js +++ b/test/txin.js @@ -2,10 +2,10 @@ var should = require('chai').should(); var bitcore = require('..'); +var Varint = bitcore.encoding.Varint; +var BufferReader = bitcore.encoding.BufferReader; var Script = bitcore.Script; var Txin = bitcore.Txin; -var Varint = bitcore.Varint; -var BufferReader = bitcore.BufferReader; describe('Txin', function() { diff --git a/test/txout.js b/test/txout.js index 5af9028..0d1f13b 100644 --- a/test/txout.js +++ b/test/txout.js @@ -2,11 +2,11 @@ var should = require('chai').should(); var bitcore = require('..'); -var BN = bitcore.BN; +var BN = bitcore.crypto.BN; +var Varint = bitcore.encoding.Varint; +var BufferReader = bitcore.encoding.BufferReader; var Txout = bitcore.Txout; var Script = bitcore.Script; -var Varint = bitcore.Varint; -var BufferReader = bitcore.BufferReader; describe('Txout', function() {