diff --git a/README.md b/README.md index ae980034..f4d25a69 100644 --- a/README.md +++ b/README.md @@ -521,13 +521,13 @@ Scripts are array-like objects with some helper functions. ``` js var bcoin = require('bcoin'); var assert = require('assert'); -var bn = bcoin.bn; +var BN = bcoin.bn; var opcodes = bcoin.script.opcodes; var output = new bcoin.script(); output.push(opcodes.OP_DROP); output.push(opcodes.OP_ADD); -output.push(new bn(7)); +output.push(new BN(7)); output.push(opcodes.OP_NUMEQUAL); // Compile the script to its binary representation // (you must do this if you change something!). @@ -536,8 +536,8 @@ assert(output.getSmall(2) === 7); // compiled as OP_7 var input = new bcoin.script(); input.set(0, 'hello world'); // add some metadata -input.push(new bn(2)); -input.push(new bn(5)); +input.push(new BN(2)); +input.push(new BN(5)); input.push(input.shift()); assert(input.getString(2) === 'hello world'); input.compile(); @@ -558,8 +558,8 @@ Stack object (an array-like object containing Buffers). ``` js var witness = new bcoin.witness(); -witness.push(new bn(2)); -witness.push(new bn(5)); +witness.push(new BN(2)); +witness.push(new BN(5)); witness.push('hello world'); var stack = witness.toStack(); diff --git a/bench/coin.js b/bench/coin.js index f2305104..dcd128be 100644 --- a/bench/coin.js +++ b/bench/coin.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var constants = require('../lib/protocol/constants'); var utils = require('../lib/utils/utils'); var assert = require('assert'); diff --git a/bench/mnemonic.js b/bench/mnemonic.js index 6d0ee898..35b6a4cc 100644 --- a/bench/mnemonic.js +++ b/bench/mnemonic.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var constants = bcoin.constants; var utils = bcoin.utils; diff --git a/bench/tx.js b/bench/tx.js index d2333af4..cd2f3720 100644 --- a/bench/tx.js +++ b/bench/tx.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var constants = bcoin.constants; var utils = bcoin.utils; diff --git a/bench/walletdb.js b/bench/walletdb.js index 07b3ed28..a067fe85 100644 --- a/bench/walletdb.js +++ b/bench/walletdb.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var constants = bcoin.constants; var utils = bcoin.utils; @@ -74,7 +74,7 @@ var runBench = co(function* runBench() { // TX jobs = []; - nonce = new bn(0); + nonce = new BN(0); for (i = 0; i < 10000; i++) { tx = bcoin.mtx() .addOutput(addrs[(i + 0) % addrs.length], 50460) diff --git a/lib/bip70/pk.js b/lib/bip70/pk.js index 0890f955..241e0359 100644 --- a/lib/bip70/pk.js +++ b/lib/bip70/pk.js @@ -6,7 +6,7 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var asn1 = require('./asn1'); var elliptic = require('elliptic'); var crypto = require('../crypto/crypto'); @@ -43,8 +43,8 @@ rsa.verify = function verify(hashAlg, msg, sig, key) { var prefix = rsa.prefixes[hashAlg]; var len = prefix.length + hash.length; var pub = asn1.parseRSAPublic(key); - var N = new bn(pub.modulus); - var e = new bn(pub.publicExponent); + var N = new BN(pub.modulus); + var e = new BN(pub.publicExponent); var k = Math.ceil(N.bitLength() / 8); var m, em, ok, i; @@ -71,8 +71,8 @@ rsa.sign = function sign(hashAlg, msg, key) { var prefix = rsa.prefixes[hashAlg]; var len = prefix.length + hash.length; var priv = asn1.parseRSAPrivate(key); - var N = new bn(priv.modulus); - var D = new bn(priv.privateExponent); + var N = new BN(priv.modulus); + var D = new BN(priv.privateExponent); var k = Math.ceil(N.bitLength() / 8); var i, em; @@ -93,7 +93,7 @@ rsa.sign = function sign(hashAlg, msg, key) { }; rsa.decrypt = function decrypt(N, D, m) { - var c = new bn(m); + var c = new BN(m); if (c.cmp(N) > 0) throw new Error('Cannot decrypt.'); @@ -106,7 +106,7 @@ rsa.decrypt = function decrypt(N, D, m) { }; rsa.encrypt = function encrypt(N, e, m) { - return new bn(m) + return new BN(m) .toRed(bn.red(N)) .redPow(e) .fromRed() diff --git a/lib/chain/chainentry.js b/lib/chain/chainentry.js index 455955a2..bc76349d 100644 --- a/lib/chain/chainentry.js +++ b/lib/chain/chainentry.js @@ -7,7 +7,7 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var Network = require('../protocol/network'); var constants = require('../protocol/constants'); var utils = require('../utils/utils'); @@ -81,7 +81,7 @@ ChainEntry.prototype.fromOptions = function fromOptions(options, prev) { assert(utils.isNumber(options.ts)); assert(utils.isNumber(options.bits)); assert(utils.isNumber(options.nonce)); - assert(!options.chainwork || bn.isBN(options.chainwork)); + assert(!options.chainwork || BN.isBN(options.chainwork)); this.hash = options.hash; this.version = options.version; @@ -116,7 +116,7 @@ ChainEntry.fromOptions = function fromOptions(chain, options, prev) { * @const {BN} */ -ChainEntry.MAX_CHAINWORK = new bn(1).ushln(256); +ChainEntry.MAX_CHAINWORK = new BN(1).ushln(256); /** * Calculate the proof: (1 << 256) / (target + 1) @@ -126,7 +126,7 @@ ChainEntry.MAX_CHAINWORK = new bn(1).ushln(256); ChainEntry.prototype.getProof = function getProof() { var target = utils.fromCompact(this.bits); if (target.isNeg() || target.cmpn(0) === 0) - return new bn(0); + return new BN(0); return ChainEntry.MAX_CHAINWORK.div(target.iaddn(1)); }; @@ -526,7 +526,7 @@ ChainEntry.prototype.fromRaw = function fromRaw(data) { this.bits = p.readU32(); this.nonce = p.readU32(); this.height = p.readU32(); - this.chainwork = new bn(p.readBytes(32), 'le'); + this.chainwork = new BN(p.readBytes(32), 'le'); return this; }; @@ -587,7 +587,7 @@ ChainEntry.prototype.fromJSON = function fromJSON(json) { this.bits = json.bits; this.nonce = json.nonce; this.height = json.height; - this.chainwork = new bn(json.chainwork, 10); + this.chainwork = new BN(json.chainwork, 10); return this; }; diff --git a/lib/crypto/ec.js b/lib/crypto/ec.js index 2727b303..98f4c32d 100644 --- a/lib/crypto/ec.js +++ b/lib/crypto/ec.js @@ -8,7 +8,7 @@ 'use strict'; var elliptic = require('elliptic'); -var bn = require('bn.js'); +var BN = require('bn.js'); var utils = require('../utils/utils'); var crypto = require('./crypto'); var assert = require('assert'); @@ -139,8 +139,8 @@ ec.privateKeyTweakAdd = function privateKeyTweakAdd(privateKey, tweak) { if (secp256k1) return secp256k1.privateKeyTweakAdd(privateKey, tweak); - key = new bn(tweak) - .add(new bn(privateKey)) + key = new BN(tweak) + .add(new BN(privateKey)) .mod(ec.curve.n) .toArrayLike(Buffer, 'be', 32); @@ -165,7 +165,7 @@ ec.publicKeyTweakAdd = function publicKeyTweakAdd(publicKey, tweak, compressed) return secp256k1.publicKeyTweakAdd(publicKey, tweak, compressed); point = ec.curve.decodePoint(publicKey); - point = ec.curve.g.mul(new bn(tweak)).add(point); + point = ec.curve.g.mul(new BN(tweak)).add(point); key = new Buffer(point.encode('array', compressed !== false)); if (!ec.publicKeyVerify(key)) @@ -335,7 +335,7 @@ ec.privateKeyVerify = function privateKeyVerify(key) { if (key.length !== 32) return false; - key = new bn(key); + key = new BN(key); return key.cmpn(0) !== 0 && key.cmp(ec.curve.n) < 0; }; @@ -411,8 +411,8 @@ ec.toDER = function toDER(sig) { return secp256k1.signatureExport(sig); out = new ec.signature({ - r: new bn(sig.slice(0, 32), 'be'), - s: new bn(sig.slice(32, 64), 'be') + r: new BN(sig.slice(0, 32), 'be'), + s: new BN(sig.slice(32, 64), 'be') }); return new Buffer(out.toDER()); diff --git a/lib/crypto/schnorr.js b/lib/crypto/schnorr.js index a91cf120..8814cc0b 100644 --- a/lib/crypto/schnorr.js +++ b/lib/crypto/schnorr.js @@ -6,7 +6,7 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var elliptic = require('elliptic'); var Signature = require('elliptic/lib/elliptic/ec/signature'); var hmacDRBG = require('elliptic/lib/elliptic/hmac-drbg'); @@ -40,7 +40,7 @@ schnorr.hash = function _hash(msg, r, hash) { msg.copy(B, 32); H = hash(B); - return new bn(H); + return new BN(H); }; /** @@ -99,7 +99,7 @@ schnorr._sign = function _sign(msg, prv, k, hash, pubnonce) { */ schnorr.sign = function sign(msg, key, hash, pubnonce) { - var prv = new bn(key); + var prv = new BN(key); var k, sig; if (prv.cmpn(0) === 0) @@ -109,7 +109,7 @@ schnorr.sign = function sign(msg, key, hash, pubnonce) { throw new Error('Bad private key.'); while (!sig) { - k = new bn(crypto.randomBytes(32)); + k = new BN(crypto.randomBytes(32)); sig = schnorr._sign(msg, prv, k, hash, pubnonce); } @@ -213,7 +213,7 @@ schnorr.recover = function recover(signature, msg, hash) { */ schnorr.combineSigs = function combineSigs(sigs) { - var s = new bn(0); + var s = new BN(0); var i, r, sig, last; for (i = 0; i < sigs.length; i++) { @@ -279,7 +279,7 @@ schnorr.combineKeys = function combineKeys(keys) { */ schnorr.partialSign = function partialSign(msg, priv, privnonce, pubs, hash) { - var prv = new bn(priv); + var prv = new BN(priv); var sig; if (prv.cmpn(0) === 0) @@ -288,7 +288,7 @@ schnorr.partialSign = function partialSign(msg, priv, privnonce, pubs, hash) { if (prv.cmp(curve.n) >= 0) throw new Error('Bad private key.'); - sig = schnorr._sign(msg, prv, new bn(privnonce), hash, pubs); + sig = schnorr._sign(msg, prv, new BN(privnonce), hash, pubs); if (!sig) throw new Error('Bad K value.'); @@ -358,7 +358,7 @@ schnorr.nonce = function nonce(msg, priv, data, ncb) { pubnonce = ncb(msg, priv, data); - return new bn(pubnonce); + return new BN(pubnonce); }; /** diff --git a/lib/miner/minerblock.js b/lib/miner/minerblock.js index baf85ae8..8ff2e0db 100644 --- a/lib/miner/minerblock.js +++ b/lib/miner/minerblock.js @@ -13,7 +13,7 @@ var crypto = require('../crypto/crypto'); var assert = require('assert'); var constants = require('../protocol/constants'); var Network = require('../protocol/network'); -var bn = require('bn.js'); +var BN = require('bn.js'); var EventEmitter = require('events').EventEmitter; var TX = require('../primitives/tx'); var Block = require('../primitives/block'); @@ -54,7 +54,7 @@ function MinerBlock(options) { this.bits = options.bits; this.target = utils.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32); this.flags = options.flags; - this.extraNonce = new bn(0); + this.extraNonce = new BN(0); this.iterations = 0; this.coinbaseFlags = options.coinbaseFlags; this.witness = options.witness; @@ -106,7 +106,7 @@ MinerBlock.prototype._init = function _init() { input = new Input(); // Height (required in v2+ blocks) - input.script.set(0, new bn(this.height)); + input.script.set(0, new BN(this.height)); // extraNonce - incremented when // the nonce overflows. diff --git a/lib/net/packets.js b/lib/net/packets.js index 2bbd3c33..c2564e28 100644 --- a/lib/net/packets.js +++ b/lib/net/packets.js @@ -7,7 +7,7 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var constants = require('../protocol/constants'); var utils = require('../utils/utils'); var assert = require('assert'); @@ -122,7 +122,7 @@ function VersionPacket(options) { this.ts = time.now(); this.recv = new NetworkAddress(); this.from = new NetworkAddress(); - this.nonce = new bn(0); + this.nonce = new BN(0); this.agent = constants.USER_AGENT; this.height = 0; this.relay = true; @@ -440,7 +440,7 @@ function PongPacket(nonce) { Packet.call(this); - this.nonce = nonce || new bn(0); + this.nonce = nonce || new BN(0); } utils.inherits(PongPacket, Packet); diff --git a/lib/protocol/networks.js b/lib/protocol/networks.js index 67660013..c3e8f713 100644 --- a/lib/protocol/networks.js +++ b/lib/protocol/networks.js @@ -7,7 +7,7 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); /** * @module network @@ -167,7 +167,7 @@ main.pow = { * @const {Buffer} */ - limit: new bn( + limit: new BN( '00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), @@ -498,7 +498,7 @@ testnet.genesisBlock = + 'ac00000000'; testnet.pow = { - limit: new bn( + limit: new BN( '00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), @@ -641,7 +641,7 @@ regtest.genesisBlock = + 'ac00000000'; regtest.pow = { - limit: new bn( + limit: new BN( '7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), @@ -781,7 +781,7 @@ segnet3.genesisBlock = + 'ac00000000'; segnet3.pow = { - limit: new bn( + limit: new BN( '00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), @@ -897,7 +897,7 @@ segnet4.genesisBlock = segnet4.pow = { // 512x lower min difficulty than mainnet - limit: new bn( + limit: new BN( '000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), @@ -1034,7 +1034,7 @@ simnet.genesisBlock = + 'ac00000000'; simnet.pow = { - limit: new bn( + limit: new BN( // High target of 0x207fffff (545259519) '7fffff0000000000000000000000000000000000000000000000000000000000', 'hex' diff --git a/lib/script/opcode.js b/lib/script/opcode.js index 4db6c9a5..b3ce76e7 100644 --- a/lib/script/opcode.js +++ b/lib/script/opcode.js @@ -9,7 +9,7 @@ module.exports = Opcode; -var bn = require('bn.js'); +var BN = require('bn.js'); var constants = require('../protocol/constants'); var utils = require('../utils/utils'); var Script = require('./script'); @@ -153,7 +153,7 @@ Opcode.from = function from(data) { if (typeof data === 'string') return Opcode.fromString(data, 'utf8'); - if (bn.isBN(data)) + if (BN.isBN(data)) return Opcode.fromNumber(data); assert(false, 'Bad data for opcode.'); diff --git a/lib/script/script.js b/lib/script/script.js index 0fbb1505..54341c48 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -9,7 +9,7 @@ module.exports = Script; -var bn = require('bn.js'); +var BN = require('bn.js'); var constants = require('../protocol/constants'); var utils = require('../utils/utils'); var crypto = require('../crypto/crypto'); @@ -777,11 +777,11 @@ Script.prototype.execute = function execute(stack, flags, tx, index, version) { break; case opcodes.OP_NOT: num = num.cmpn(0) === 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_0NOTEQUAL: num = num.cmpn(0) !== 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; default: assert(false, 'Fatal script error.'); @@ -847,39 +847,39 @@ Script.prototype.execute = function execute(stack, flags, tx, index, version) { break; case opcodes.OP_BOOLAND: num = n1.cmpn(0) !== 0 && n2.cmpn(0) !== 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_BOOLOR: num = n1.cmpn(0) !== 0 || n2.cmpn(0) !== 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_NUMEQUAL: num = n1.cmp(n2) === 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_NUMEQUALVERIFY: num = n1.cmp(n2) === 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_NUMNOTEQUAL: num = n1.cmp(n2) !== 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_LESSTHAN: num = n1.cmp(n2) < 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_GREATERTHAN: num = n1.cmp(n2) > 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_LESSTHANOREQUAL: num = n1.cmp(n2) <= 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_GREATERTHANOREQUAL: num = n1.cmp(n2) >= 0; - num = new bn(num ? 1 : 0); + num = new BN(num ? 1 : 0); break; case opcodes.OP_MIN: num = n1.cmp(n2) < 0 ? n1 : n2; @@ -1364,9 +1364,9 @@ Script.num = function num(value, flags, size) { } if (value.length === 0) - return new bn(0); + return new BN(0); - result = new bn(value, 'le'); + result = new BN(value, 'le'); // If the input vector's most significant byte is // 0x80, remove it from the result's msb and return @@ -1386,8 +1386,8 @@ Script.num = function num(value, flags, size) { * @example * assert.deepEqual(Script.array(0), new Buffer(0)); * assert.deepEqual(Script.array(0xffee), new Buffer('eeff00', 'hex')); - * assert.deepEqual(Script.array(new bn(0xffee)), new Buffer('eeff00', 'hex')); - * assert.deepEqual(Script.array(new bn(0x1e).ineg()), new Buffer('9e', 'hex')); + * assert.deepEqual(Script.array(new BN(0xffee)), new Buffer('eeff00', 'hex')); + * assert.deepEqual(Script.array(new BN(0x1e).ineg()), new Buffer('9e', 'hex')); * @param {Number|BN} value * @returns {Buffer} */ @@ -1396,9 +1396,9 @@ Script.array = function(value) { var neg, result; if (utils.isNumber(value)) - value = new bn(value); + value = new BN(value); - assert(bn.isBN(value)); + assert(BN.isBN(value)); if (value.cmpn(0) === 0) return STACK_FALSE; @@ -2623,7 +2623,7 @@ Script.prototype.getNumber = function getNumber(i) { var op = this.code[i]; if (small !== -1) - return new bn(small); + return new BN(small); if (!op || !op.data || op.data.length > 5) return; @@ -3234,7 +3234,7 @@ Script.prototype.fromString = function fromString(code) { continue; } if (/^-?\d+$/.test(op)) { - op = new bn(op, 10); + op = new BN(op, 10); op = Opcode.fromNumber(op); p.writeBytes(op.toRaw()); continue; diff --git a/lib/script/witness.js b/lib/script/witness.js index 8b096ef8..2ca39de0 100644 --- a/lib/script/witness.js +++ b/lib/script/witness.js @@ -9,7 +9,7 @@ module.exports = Witness; -var bn = require('bn.js'); +var BN = require('bn.js'); var constants = require('../protocol/constants'); var utils = require('../utils/utils'); var assert = require('assert'); @@ -504,7 +504,7 @@ Witness.encodeItem = function encodeItem(data) { throw new Error('Non-push opcode in witness.'); } - if (bn.isBN(data)) + if (BN.isBN(data)) return Script.array(data); if (typeof data === 'string') diff --git a/lib/utils/utils.js b/lib/utils/utils.js index b27ba3ac..dd335fb8 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -17,7 +17,7 @@ var utils = exports; var assert = require('assert'); var base58 = require('./base58'); -var bn = require('bn.js'); +var BN = require('bn.js'); var util = require('util'); var Number, Math, Date; var fs, lazy; @@ -641,15 +641,15 @@ utils.fromCompact = function fromCompact(compact) { var num; if (compact === 0) - return new bn(0); + return new BN(0); // Logic ported from btcd since // the bitcoind code is a nightmare. if (exponent <= 3) { mantissa >>>= 8 * (3 - exponent); - num = new bn(mantissa); + num = new BN(mantissa); } else { - num = new bn(mantissa); + num = new BN(mantissa); num.iushln(8 * (exponent - 3)); } @@ -715,7 +715,7 @@ utils.testTarget = function testTarget(hash, target) { if (target.isNeg() || target.cmpn(0) === 0) return false; - hash = new bn(hash, 'le'); + hash = new BN(hash, 'le'); if (hash.cmp(target) > 0) return false; @@ -774,14 +774,14 @@ utils.time = function time(date) { * @const {BN} */ -utils.U32 = new bn(0xffffffff); +utils.U32 = new BN(0xffffffff); /** * UINT64_MAX * @const {BN} */ -utils.U64 = new bn('ffffffffffffffff', 'hex'); +utils.U64 = new BN('ffffffffffffffff', 'hex'); /** * Create a 64 bit nonce. @@ -797,7 +797,7 @@ utils.nonce = function _nonce(buffer) { if (buffer) return nonce; - return new bn(nonce); + return new BN(nonce); }; /** @@ -811,7 +811,7 @@ utils.readU64 = function readU64(data, off) { var num; off = off >>> 0; num = data.slice(off, off + 8); - return new bn(num, 'le'); + return new BN(num, 'le'); }; /** @@ -825,7 +825,7 @@ utils.readU64BE = function readU64BE(data, off) { var num; off = off >>> 0; num = data.slice(off, off + 8); - return new bn(num, 'be'); + return new BN(num, 'be'); }; /** @@ -843,9 +843,9 @@ utils.read64 = function read64(data, off) { num = data.slice(off, off + 8); if (num[num.length - 1] & 0x80) - return new bn(num, 'le').notn(64).addn(1).neg(); + return new BN(num, 'le').notn(64).addn(1).neg(); - return new bn(num, 'le'); + return new BN(num, 'le'); }; /** @@ -863,9 +863,9 @@ utils.read64BE = function read64BE(data, off) { num = data.slice(off, off + 8); if (num[0] & 0x80) - return new bn(num, 'be').notn(64).addn(1).neg(); + return new BN(num, 'be').notn(64).addn(1).neg(); - return new bn(num, 'be'); + return new BN(num, 'be'); }; /** @@ -1177,7 +1177,7 @@ utils.readVarint = function readVarint(data, off, big) { value = data.readUInt32LE(off + 1, true); assert(value > 0xffff); if (big) - value = new bn(value); + value = new BN(value); break; case 0xfd: size = 3; @@ -1185,13 +1185,13 @@ utils.readVarint = function readVarint(data, off, big) { value = data[off + 1] | (data[off + 2] << 8); assert(value >= 0xfd); if (big) - value = new bn(value); + value = new BN(value); break; default: size = 1; value = data[off]; if (big) - value = new bn(value); + value = new BN(value); break; } @@ -1209,7 +1209,7 @@ utils.readVarint = function readVarint(data, off, big) { utils.writeVarint = function writeVarint(dst, num, off) { off = off >>> 0; - if (bn.isBN(num)) { + if (BN.isBN(num)) { if (num.bitLength() > 32) { dst[off] = 0xff; utils.writeU64(dst, num, off + 1); @@ -1254,7 +1254,7 @@ utils.writeVarint = function writeVarint(dst, num, off) { */ utils.sizeVarint = function sizeVarint(num) { - if (bn.isBN(num)) { + if (BN.isBN(num)) { if (num.bitLength() > 32) return 9; num = num.toNumber(); @@ -1295,7 +1295,7 @@ utils.readVarint2 = function readVarint2(data, off, big) { if (num >= 0x3fffffffffff) { assert(big, 'Number exceeds 2^53-1.'); - bnum = new bn(num); + bnum = new BN(num); num = 0; } @@ -1318,7 +1318,7 @@ utils.readVarint2 = function readVarint2(data, off, big) { return { size: size, value: bnum }; if (big) - num = new bn(num); + num = new BN(num); return { size: size, value: num }; }; @@ -1335,7 +1335,7 @@ utils.writeVarint2 = function writeVarint2(dst, num, off) { var tmp = []; var len = 0; - if (bn.isBN(num)) { + if (BN.isBN(num)) { if (num.bitLength() > 53) { for (;;) { tmp[len] = (num.words[0] & 0x7f) | (len ? 0x80 : 0x00); @@ -1386,7 +1386,7 @@ utils.writeVarint2 = function writeVarint2(dst, num, off) { utils.sizeVarint2 = function sizeVarint2(num) { var size = 0; - if (bn.isBN(num)) { + if (BN.isBN(num)) { if (num.bitLength() > 53) { num = num.clone(); diff --git a/lib/workers/framer.js b/lib/workers/framer.js index 1e5f18d3..e58b8eb8 100644 --- a/lib/workers/framer.js +++ b/lib/workers/framer.js @@ -8,7 +8,7 @@ 'use strict'; var EventEmitter = require('events').EventEmitter; -var bn = require('bn.js'); +var BN = require('bn.js'); var utils = require('../utils/utils'); var assert = require('assert'); var BufferWriter = require('../utils/writer'); @@ -97,7 +97,7 @@ Framer.item = function _item(item, writer) { } else if (item instanceof KeyRing) { p.writeU8(44); item.toRaw(p); - } else if (bn.isBN(item)) { + } else if (BN.isBN(item)) { p.writeU8(10); p.writeVarBytes(item.toArrayLike(Buffer)); } else if (Buffer.isBuffer(item)) { diff --git a/lib/workers/parser.js b/lib/workers/parser.js index 9f449e1d..d67f17fd 100644 --- a/lib/workers/parser.js +++ b/lib/workers/parser.js @@ -8,7 +8,7 @@ 'use strict'; var EventEmitter = require('events').EventEmitter; -var bn = require('bn.js'); +var BN = require('bn.js'); var utils = require('../utils/utils'); var assert = require('assert'); var BufferReader = require('../utils/reader'); @@ -180,7 +180,7 @@ Parser.parseItem = function parseItem(data) { items[p.readVarString('utf8')] = Parser.parseItem(p); return items; case 10: - return new bn(p.readVarBytes()); + return new BN(p.readVarBytes()); case 40: return Script.fromRaw(p.readVarBytes()); case 41: diff --git a/scripts/gen.js b/scripts/gen.js index 8f8a31dc..2ec4d033 100644 --- a/scripts/gen.js +++ b/scripts/gen.js @@ -4,7 +4,7 @@ var bcoin = require('bcoin'); var constants = bcoin.constants; var opcodes = constants.opcodes; var utils = bcoin.utils; -var bn = require('bn.js'); +var BN = require('bn.js'); function createGenesisBlock(options) { var flags = options.flags; @@ -39,7 +39,7 @@ function createGenesisBlock(options) { index: 0xffffffff }, script: [ - bcoin.opcode.fromNumber(new bn(486604799)), + bcoin.opcode.fromNumber(new BN(486604799)), bcoin.opcode.fromPush(new Buffer([4])), bcoin.opcode.fromData(flags) ], diff --git a/test/aes-test.js b/test/aes-test.js index d4617102..71f452aa 100644 --- a/test/aes-test.js +++ b/test/aes-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var utils = require('../lib/utils/utils'); var crypto = require('../lib/crypto/crypto'); var assert = require('assert'); diff --git a/test/bip150-test.js b/test/bip150-test.js index 151806cf..017714bb 100644 --- a/test/bip150-test.js +++ b/test/bip150-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var utils = bcoin.utils; var crypto = require('../lib/crypto/crypto'); diff --git a/test/bip151-test.js b/test/bip151-test.js index 39ac2746..1135ec98 100644 --- a/test/bip151-test.js +++ b/test/bip151-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var utils = bcoin.utils; var crypto = require('../lib/crypto/crypto'); diff --git a/test/bip70-test.js b/test/bip70-test.js index 0af9ec60..23af3079 100644 --- a/test/bip70-test.js +++ b/test/bip70-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var utils = bcoin.utils; var crypto = require('../lib/crypto/crypto'); diff --git a/test/block-test.js b/test/block-test.js index 0769311e..5e4f2111 100644 --- a/test/block-test.js +++ b/test/block-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var utils = bcoin.utils; var crypto = require('../lib/crypto/crypto'); diff --git a/test/chain-test.js b/test/chain-test.js index 61826ac5..938745d5 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('regtest'); var constants = bcoin.constants; var utils = bcoin.utils; diff --git a/test/hd-test.js b/test/hd-test.js index 8b3f6bcb..afbb10dc 100644 --- a/test/hd-test.js +++ b/test/hd-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var utils = bcoin.utils; var crypto = require('../lib/crypto/crypto'); diff --git a/test/http-test.js b/test/http-test.js index 05d8a311..b115f878 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('regtest'); var constants = bcoin.constants; var network = bcoin.networks; diff --git a/test/mempool-test.js b/test/mempool-test.js index 73fdb002..8452c9cb 100644 --- a/test/mempool-test.js +++ b/test/mempool-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var constants = bcoin.constants; var utils = bcoin.utils; diff --git a/test/mnemonic-test.js b/test/mnemonic-test.js index 8d2720cb..b2feb382 100644 --- a/test/mnemonic-test.js +++ b/test/mnemonic-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var utils = bcoin.utils; var crypto = require('../lib/crypto/crypto'); diff --git a/test/script-test.js b/test/script-test.js index 06b1ae22..3b49dd20 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -9,7 +9,7 @@ var crypto = require('../lib/crypto/crypto'); var constants = bcoin.constants; var opcodes = bcoin.constants.opcodes; var scripts = require('./data/script_tests'); -var bn = require('bn.js'); +var BN = require('bn.js'); describe('Script', function() { it('should encode/decode script', function() { diff --git a/test/tx-test.js b/test/tx-test.js index a0f0071c..eb0c4648 100644 --- a/test/tx-test.js +++ b/test/tx-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var assert = require('assert'); var utils = bcoin.utils; @@ -499,14 +499,14 @@ describe('TX', function() { }], locktime: 0 }); - tx.outputs[0].value = new bn('00ffffffffffffff', 'hex'); + tx.outputs[0].value = new BN('00ffffffffffffff', 'hex'); assert(tx.outputs[0].value.bitLength() === 56); var raw = tx.toRaw() assert.throws(function() { bcoin.tx.fromRaw(raw); }); delete tx._raw; - tx.outputs[0].value = new bn('00ffffffffffffff', 'hex').ineg(); + tx.outputs[0].value = new BN('00ffffffffffffff', 'hex').ineg(); assert(tx.outputs[0].value.bitLength() === 56); var raw = tx.toRaw() assert.throws(function() { diff --git a/test/utils-test.js b/test/utils-test.js index 6742d604..7061d9f1 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var assert = require('assert'); var utils = bcoin.utils; @@ -161,27 +161,27 @@ describe('Utils', function() { }); var unsigned = [ - new bn('ffeeffee'), - new bn('001fffeeffeeffee'), - new bn('eeffeeff'), - new bn('001feeffeeffeeff'), - new bn(0), - new bn(1) + new BN('ffeeffee'), + new BN('001fffeeffeeffee'), + new BN('eeffeeff'), + new BN('001feeffeeffeeff'), + new BN(0), + new BN(1) ]; var signed = [ - new bn('ffeeffee'), - new bn('001fffeeffeeffee'), - new bn('eeffeeff'), - new bn('001feeffeeffeeff'), - new bn(0), - new bn(1), - new bn('ffeeffee').ineg(), - new bn('001fffeeffeeffee').ineg(), - new bn('eeffeeff').ineg(), - new bn('001feeffeeffeeff').ineg(), - new bn(0).ineg(), - new bn(1).ineg() + new BN('ffeeffee'), + new BN('001fffeeffeeffee'), + new BN('eeffeeff'), + new BN('001feeffeeffeeff'), + new BN(0), + new BN(1), + new BN('ffeeffee').ineg(), + new BN('001fffeeffeeffee').ineg(), + new BN('eeffeeff').ineg(), + new BN('001feeffeeffeeff').ineg(), + new BN(0).ineg(), + new BN(1).ineg() ]; unsigned.forEach(function(num) { diff --git a/test/wallet-test.js b/test/wallet-test.js index 3178ccbe..a410c1db 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -1,6 +1,6 @@ 'use strict'; -var bn = require('bn.js'); +var BN = require('bn.js'); var bcoin = require('../').set('main'); var constants = bcoin.constants; var network = bcoin.networks;