diff --git a/lib/address.js b/lib/address.js index 815efdea0..e56c429df 100644 --- a/lib/address.js +++ b/lib/address.js @@ -313,7 +313,7 @@ Address.fromString = function(str, network, type) { * @returns {Address} A new valid instance of an Address */ Address.fromJSON = function fromJSON(json) { - if (JSUtil.isValidJson(json)) { + if (JSUtil.isValidJSON(json)) { json = JSON.parse(json); } var hashBuffer = new Buffer(json.hash, 'hex'); diff --git a/lib/block.js b/lib/block.js index 142a1cac8..626672729 100644 --- a/lib/block.js +++ b/lib/block.js @@ -3,11 +3,11 @@ var _ = require('lodash'); var BlockHeader = require('./blockheader'); var BN = require('./crypto/bn'); -var bu = require('./util/buffer'); +var BufferUtil = require('./util/buffer'); var BufferReader = require('./encoding/bufferreader'); var BufferWriter = require('./encoding/bufferwriter'); var Hash = require('./crypto/hash'); -var ju = require('./util/js'); +var JSUtil = require('./util/js'); var Transaction = require('./transaction'); var Varint = require('./encoding/varint'); @@ -35,9 +35,9 @@ var Block = function Block(arg) { */ Block._from = function _from(arg) { var info = {}; - if (bu.isBuffer(arg)) { + if (BufferUtil.isBuffer(arg)) { info = Block._fromBufferReader(BufferReader(arg)); - } else if (ju.isValidJson(arg)) { + } else if (JSUtil.isValidJSON(arg)) { info = Block._fromJSON(arg); } else if (_.isObject(arg)) { info = { @@ -59,7 +59,7 @@ Block._from = function _from(arg) { * @private */ Block._fromJSON = function _fromJSON(data) { - if (ju.isValidJson(data)) { + if (JSUtil.isValidJSON(data)) { data = JSON.parse(data); } var txs = []; @@ -135,7 +135,7 @@ Block.fromString = function fromString(str) { * @returns {Block} - An instance of block */ Block.fromRawBlock = function fromRawBlock(data) { - if (!bu.isBuffer(data)) { + if (!BufferUtil.isBuffer(data)) { data = new Buffer(data, 'binary'); } var br = BufferReader(data); diff --git a/lib/blockheader.js b/lib/blockheader.js index 4b1093177..9300e2e92 100644 --- a/lib/blockheader.js +++ b/lib/blockheader.js @@ -2,11 +2,11 @@ var _ = require('lodash'); var BN = require('./crypto/bn'); -var bu = require('./util/buffer'); +var BufferUtil = require('./util/buffer'); var BufferReader = require('./encoding/bufferreader'); var BufferWriter = require('./encoding/bufferwriter'); var Hash = require('./crypto/hash'); -var ju = require('./util/js'); +var JSUtil = require('./util/js'); /** * Instantiate a BlockHeader from a Buffer, JSON object, or Object with @@ -32,9 +32,9 @@ var BlockHeader = function BlockHeader(arg) { */ BlockHeader._from = function _from(arg) { var info = {}; - if (bu.isBuffer(arg)) { + if (BufferUtil.isBuffer(arg)) { info = BlockHeader._fromBufferReader(BufferReader(arg)); - } else if (ju.isValidJson(arg)) { + } else if (JSUtil.isValidJSON(arg)) { info = BlockHeader._fromJSON(arg); } else if (_.isObject(arg)) { info = { @@ -57,7 +57,7 @@ BlockHeader._from = function _from(arg) { * @private */ BlockHeader._fromJSON = function _fromJSON(data) { - if (ju.isValidJson(data)) { + if (JSUtil.isValidJSON(data)) { data = JSON.parse(data); } var info = { @@ -85,7 +85,7 @@ BlockHeader.fromJSON = function fromJSON(json) { * @returns {BlockHeader} - An instance of block header */ BlockHeader.fromRawBlock = function fromRawBlock(data) { - if (!bu.isBuffer(data)) { + if (!BufferUtil.isBuffer(data)) { data = new Buffer(data, 'binary'); } var br = BufferReader(data); diff --git a/lib/hdprivatekey.js b/lib/hdprivatekey.js index 0d951d599..0145912c8 100644 --- a/lib/hdprivatekey.js +++ b/lib/hdprivatekey.js @@ -17,8 +17,8 @@ var Random = require('./crypto/random'); var errors = require('./errors'); var hdErrors = errors.HDPrivateKey; -var bufferUtil = require('./util/buffer'); -var jsUtil = require('./util/js'); +var BufferUtil = require('./util/buffer'); +var JSUtil = require('./util/js'); var MINIMUM_ENTROPY_BITS = 128; var BITS_TO_BYTES = 1/8; @@ -42,11 +42,11 @@ function HDPrivateKey(arg) { return new HDPrivateKey(arg); } if (arg) { - if (_.isString(arg) || bufferUtil.isBuffer(arg)) { + if (_.isString(arg) || BufferUtil.isBuffer(arg)) { if (HDPrivateKey.isValidSerialized(arg)) { this._buildFromSerialized(arg); - } else if (jsUtil.isValidJson(arg)) { - this._buildFromJson(arg); + } else if (JSUtil.isValidJSON(arg)) { + this._buildFromJSON(arg); } else { throw HDPrivateKey.getSerializedError(arg); } @@ -107,12 +107,12 @@ HDPrivateKey.prototype._deriveWithNumber = function(index, hardened) { return cached; } - var indexBuffer = bufferUtil.integerAsBuffer(index); + var indexBuffer = BufferUtil.integerAsBuffer(index); var data; if (hardened) { - data = bufferUtil.concat([new buffer.Buffer([0]), this.privateKey.toBuffer(), indexBuffer]); + data = BufferUtil.concat([new buffer.Buffer([0]), this.privateKey.toBuffer(), indexBuffer]); } else { - data = bufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]); + data = BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]); } var hash = Hash.sha512hmac(data, this._buffers.chainCode); var leftPart = BN().fromBuffer(hash.slice(0, 32), {size: 32}); @@ -177,7 +177,7 @@ HDPrivateKey.isValidSerialized = function(data, network) { */ HDPrivateKey.getSerializedError = function(data, network) { /* jshint maxcomplexity: 10 */ - if (!(_.isString(data) || bufferUtil.isBuffer(data))) { + if (!(_.isString(data) || BufferUtil.isBuffer(data))) { return new hdErrors.UnrecognizedArgument('Expected string or buffer'); } if (!Base58.validCharacters(data)) { @@ -206,13 +206,13 @@ HDPrivateKey._validateNetwork = function(data, networkArg) { return new errors.InvalidNetworkArgument(networkArg); } var version = data.slice(0, 4); - if (bufferUtil.integerFromBuffer(version) !== network.xprivkey) { + if (BufferUtil.integerFromBuffer(version) !== network.xprivkey) { return new errors.InvalidNetwork(version); } return null; }; -HDPrivateKey.prototype._buildFromJson = function(arg) { +HDPrivateKey.prototype._buildFromJSON = function(arg) { return this._buildFromObject(JSON.parse(arg)); }; @@ -220,13 +220,13 @@ HDPrivateKey.prototype._buildFromObject = function(arg) { /* jshint maxcomplexity: 12 */ // TODO: Type validation var buffers = { - version: arg.network ? bufferUtil.integerAsBuffer(Network.get(arg.network).xprivkey) : arg.version, - depth: bufferUtil.integerAsSingleByteBuffer(arg.depth), - parentFingerPrint: _.isNumber(arg.parentFingerPrint) ? bufferUtil.integerAsBuffer(arg.parentFingerPrint) : arg.parentFingerPrint, - childIndex: _.isNumber(arg.childIndex) ? bufferUtil.integerAsBuffer(arg.childIndex) : arg.childIndex, - chainCode: _.isString(arg.chainCode) ? bufferUtil.hexToBuffer(arg.chainCode) : arg.chainCode, - privateKey: (_.isString(arg.privateKey) && jsUtil.isHexa(arg.privateKey)) ? bufferUtil.hexToBuffer(arg.privateKey) : arg.privateKey, - checksum: arg.checksum ? (arg.checksum.length ? arg.checksum : bufferUtil.integerAsBuffer(arg.checksum)) : undefined + version: arg.network ? BufferUtil.integerAsBuffer(Network.get(arg.network).xprivkey) : arg.version, + depth: BufferUtil.integerAsSingleByteBuffer(arg.depth), + parentFingerPrint: _.isNumber(arg.parentFingerPrint) ? BufferUtil.integerAsBuffer(arg.parentFingerPrint) : arg.parentFingerPrint, + childIndex: _.isNumber(arg.childIndex) ? BufferUtil.integerAsBuffer(arg.childIndex) : arg.childIndex, + chainCode: _.isString(arg.chainCode) ? BufferUtil.hexToBuffer(arg.chainCode) : arg.chainCode, + privateKey: (_.isString(arg.privateKey) && JSUtil.isHexa(arg.privateKey)) ? BufferUtil.hexToBuffer(arg.privateKey) : arg.privateKey, + checksum: arg.checksum ? (arg.checksum.length ? arg.checksum : BufferUtil.integerAsBuffer(arg.checksum)) : undefined }; return this._buildFromBuffers(buffers); }; @@ -261,8 +261,8 @@ HDPrivateKey.prototype._generateRandomly = function(network) { HDPrivateKey.fromSeed = function(hexa, network) { /* jshint maxcomplexity: 8 */ - if (jsUtil.isHexaString(hexa)) { - hexa = bufferUtil.hexToBuffer(hexa); + if (JSUtil.isHexaString(hexa)) { + hexa = BufferUtil.hexToBuffer(hexa); } if (!Buffer.isBuffer(hexa)) { throw new hdErrors.InvalidEntropyArgument(hexa); @@ -313,7 +313,7 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { var sequence = [ arg.version, arg.depth, arg.parentFingerPrint, arg.childIndex, arg.chainCode, - bufferUtil.emptyBuffer(1), arg.privateKey + BufferUtil.emptyBuffer(1), arg.privateKey ]; var concat = buffer.Buffer.concat(sequence); if (!arg.checksum || !arg.checksum.length) { @@ -337,10 +337,10 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { var size = HDPrivateKey.ParentFingerPrintSize; var fingerPrint = Hash.sha256ripemd160(publicKey.toBuffer()).slice(0, size); - jsUtil.defineImmutable(this, { + JSUtil.defineImmutable(this, { xprivkey: xprivkey, - network: Network.get(bufferUtil.integerFromBuffer(arg.version)), - depth: bufferUtil.integerFromSingleByteBuffer(arg.depth), + network: Network.get(BufferUtil.integerFromBuffer(arg.version)), + depth: BufferUtil.integerFromSingleByteBuffer(arg.depth), privateKey: privateKey, publicKey: publicKey, fingerPrint: fingerPrint @@ -349,7 +349,7 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { var HDPublicKey = require('./hdpublickey'); var hdPublicKey = new HDPublicKey(this); - jsUtil.defineImmutable(this, { + JSUtil.defineImmutable(this, { hdPublicKey: hdPublicKey, xpubkey: hdPublicKey.xpubkey }); @@ -360,7 +360,7 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) { HDPrivateKey._validateBufferArguments = function(arg) { var checkBuffer = function(name, size) { var buff = arg[name]; - assert(bufferUtil.isBuffer(buff), name + ' argument is not a buffer'); + assert(BufferUtil.isBuffer(buff), name + ' argument is not a buffer'); assert( buff.length === size, name + ' has not the expected size: found ' + buff.length + ', expected ' + size @@ -406,30 +406,20 @@ HDPrivateKey.prototype.toString = function() { * * @return {Object} */ -HDPrivateKey.prototype.toObject = function() { +HDPrivateKey.prototype.toJSON = function() { return { - network: Network.get(bufferUtil.integerFromBuffer(this._buffers.version)).name, - depth: bufferUtil.integerFromSingleByteBuffer(this._buffers.depth), - fingerPrint: bufferUtil.integerFromBuffer(this.fingerPrint), - parentFingerPrint: bufferUtil.integerFromBuffer(this._buffers.parentFingerPrint), - childIndex: bufferUtil.integerFromBuffer(this._buffers.childIndex), - chainCode: bufferUtil.bufferToHex(this._buffers.chainCode), + network: Network.get(BufferUtil.integerFromBuffer(this._buffers.version)).name, + depth: BufferUtil.integerFromSingleByteBuffer(this._buffers.depth), + fingerPrint: BufferUtil.integerFromBuffer(this.fingerPrint), + parentFingerPrint: BufferUtil.integerFromBuffer(this._buffers.parentFingerPrint), + childIndex: BufferUtil.integerFromBuffer(this._buffers.childIndex), + chainCode: BufferUtil.bufferToHex(this._buffers.chainCode), privateKey: this.privateKey.toBuffer().toString('hex'), - checksum: bufferUtil.integerFromBuffer(this._buffers.checksum), + checksum: BufferUtil.integerFromBuffer(this._buffers.checksum), xprivkey: this.xprivkey }; }; -/** - * Returns a string with the results from toObject - * - * @see {HDPrivateKey#toObject} - * @return {string} - */ -HDPrivateKey.prototype.toJson = function() { - return JSON.stringify(this.toObject()); -}; - HDPrivateKey.DefaultDepth = 0; HDPrivateKey.DefaultFingerprint = 0; HDPrivateKey.DefaultChildIndex = 0; diff --git a/lib/hdpublickey.js b/lib/hdpublickey.js index 99ef1ad9a..7a64019d6 100644 --- a/lib/hdpublickey.js +++ b/lib/hdpublickey.js @@ -16,8 +16,8 @@ var errors = bitcoreErrors; var hdErrors = bitcoreErrors.HDPublicKey; var assert = require('assert'); -var jsUtil = require('./util/js'); -var bufferUtil = require('./util/buffer'); +var JSUtil = require('./util/js'); +var BufferUtil = require('./util/buffer'); /** * The representation of an hierarchically derived public key. @@ -37,12 +37,12 @@ function HDPublicKey(arg) { return new HDPublicKey(arg); } if (arg) { - if (_.isString(arg) || bufferUtil.isBuffer(arg)) { + if (_.isString(arg) || BufferUtil.isBuffer(arg)) { var error = HDPublicKey.getSerializedError(arg); if (!error) { return this._buildFromSerialized(arg); - } else if (jsUtil.isValidJson(arg)) { - return this._buildFromJson(arg); + } else if (JSUtil.isValidJSON(arg)) { + return this._buildFromJSON(arg); } else { if (error instanceof hdErrors.ArgumentIsPrivateExtended) { return new HDPrivateKey(arg).hdPublicKey; @@ -105,8 +105,8 @@ HDPublicKey.prototype._deriveWithNumber = function (index, hardened) { return cached; } - var indexBuffer = bufferUtil.integerAsBuffer(index); - var data = bufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]); + var indexBuffer = BufferUtil.integerAsBuffer(index); + var data = BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]); var hash = Hash.sha512hmac(data, this._buffers.chainCode); var leftPart = BN().fromBuffer(hash.slice(0, 32), {size: 32}); var chainCode = hash.slice(32, 64); @@ -172,7 +172,7 @@ HDPublicKey.isValidSerialized = function (data, network) { HDPublicKey.getSerializedError = function (data, network) { /* jshint maxcomplexity: 10 */ /* jshint maxstatements: 20 */ - if (!(_.isString(data) || bufferUtil.isBuffer(data))) { + if (!(_.isString(data) || BufferUtil.isBuffer(data))) { return new hdErrors.UnrecognizedArgument('expected buffer or string'); } if (!Base58.validCharacters(data)) { @@ -193,7 +193,7 @@ HDPublicKey.getSerializedError = function (data, network) { } } network = Network.get(network) || Network.defaultNetwork; - if (bufferUtil.integerFromBuffer(data.slice(0, 4)) === network.xprivkey) { + if (BufferUtil.integerFromBuffer(data.slice(0, 4)) === network.xprivkey) { return new hdErrors.ArgumentIsPrivateExtended(); } return null; @@ -205,13 +205,13 @@ HDPublicKey._validateNetwork = function (data, networkArg) { return new errors.InvalidNetworkArgument(networkArg); } var version = data.slice(HDPublicKey.VersionStart, HDPublicKey.VersionEnd); - if (bufferUtil.integerFromBuffer(version) !== network.xpubkey) { + if (BufferUtil.integerFromBuffer(version) !== network.xpubkey) { return new errors.InvalidNetwork(version); } return null; }; -HDPublicKey.prototype._buildFromJson = function (arg) { +HDPublicKey.prototype._buildFromJSON = function (arg) { return this._buildFromObject(JSON.parse(arg)); }; @@ -219,7 +219,7 @@ HDPublicKey.prototype._buildFromPrivate = function (arg) { var args = _.clone(arg._buffers); var point = Point.getG().mul(BN().fromBuffer(args.privateKey)); args.publicKey = Point.pointToCompressed(point); - args.version = bufferUtil.integerAsBuffer(Network.get(bufferUtil.integerFromBuffer(args.version)).xpubkey); + args.version = BufferUtil.integerAsBuffer(Network.get(BufferUtil.integerFromBuffer(args.version)).xpubkey); args.privateKey = undefined; args.checksum = undefined; args.xprivkey = undefined; @@ -230,14 +230,14 @@ HDPublicKey.prototype._buildFromObject = function (arg) { /* jshint maxcomplexity: 10 */ // TODO: Type validation var buffers = { - version: arg.network ? bufferUtil.integerAsBuffer(Network.get(arg.network).xpubkey) : arg.version, - depth: bufferUtil.integerAsSingleByteBuffer(arg.depth), - parentFingerPrint: _.isNumber(arg.parentFingerPrint) ? bufferUtil.integerAsBuffer(arg.parentFingerPrint) : arg.parentFingerPrint, - childIndex: bufferUtil.integerAsBuffer(arg.childIndex), - chainCode: _.isString(arg.chainCode) ? bufferUtil.hexToBuffer(arg.chainCode) : arg.chainCode, - publicKey: _.isString(arg.publicKey) ? bufferUtil.hexToBuffer(arg.publicKey) : - bufferUtil.isBuffer(arg.publicKey) ? arg.publicKey : arg.publicKey.toBuffer(), - checksum: _.isNumber(arg.checksum) ? bufferUtil.integerAsBuffer(arg.checksum) : arg.checksum + version: arg.network ? BufferUtil.integerAsBuffer(Network.get(arg.network).xpubkey) : arg.version, + depth: BufferUtil.integerAsSingleByteBuffer(arg.depth), + parentFingerPrint: _.isNumber(arg.parentFingerPrint) ? BufferUtil.integerAsBuffer(arg.parentFingerPrint) : arg.parentFingerPrint, + childIndex: BufferUtil.integerAsBuffer(arg.childIndex), + chainCode: _.isString(arg.chainCode) ? BufferUtil.hexToBuffer(arg.chainCode) : arg.chainCode, + publicKey: _.isString(arg.publicKey) ? BufferUtil.hexToBuffer(arg.publicKey) : + BufferUtil.isBuffer(arg.publicKey) ? arg.publicKey : arg.publicKey.toBuffer(), + checksum: _.isNumber(arg.checksum) ? BufferUtil.integerAsBuffer(arg.checksum) : arg.checksum }; return this._buildFromBuffers(buffers); }; @@ -289,7 +289,7 @@ HDPublicKey.prototype._buildFromBuffers = function (arg) { arg.version, arg.depth, arg.parentFingerPrint, arg.childIndex, arg.chainCode, arg.publicKey ]; - var concat = bufferUtil.concat(sequence); + var concat = BufferUtil.concat(sequence); var checksum = Base58Check.checksum(concat); if (!arg.checksum || !arg.checksum.length) { arg.checksum = checksum; @@ -302,7 +302,7 @@ HDPublicKey.prototype._buildFromBuffers = function (arg) { var xpubkey; if (!arg.xpubkey) { - xpubkey = Base58Check.encode(bufferUtil.concat(sequence)); + xpubkey = Base58Check.encode(BufferUtil.concat(sequence)); } else { xpubkey = arg.xpubkey; } @@ -311,10 +311,10 @@ HDPublicKey.prototype._buildFromBuffers = function (arg) { var size = HDPublicKey.ParentFingerPrintSize; var fingerPrint = Hash.sha256ripemd160(publicKey.toBuffer()).slice(0, size); - jsUtil.defineImmutable(this, { + JSUtil.defineImmutable(this, { xpubkey: xpubkey, - network: Network.get(bufferUtil.integerFromBuffer(arg.version)), - depth: bufferUtil.integerFromSingleByteBuffer(arg.depth), + network: Network.get(BufferUtil.integerFromBuffer(arg.version)), + depth: BufferUtil.integerFromSingleByteBuffer(arg.depth), publicKey: publicKey, fingerPrint: fingerPrint }); @@ -325,7 +325,7 @@ HDPublicKey.prototype._buildFromBuffers = function (arg) { HDPublicKey._validateBufferArguments = function (arg) { var checkBuffer = function(name, size) { var buff = arg[name]; - assert(bufferUtil.isBuffer(buff), name + ' argument is not a buffer, it\'s ' + typeof buff); + assert(BufferUtil.isBuffer(buff), name + ' argument is not a buffer, it\'s ' + typeof buff); assert( buff.length === size, name + ' has not the expected size: found ' + buff.length + ', expected ' + size @@ -362,34 +362,24 @@ HDPublicKey.prototype.toString = function () { * * childIndex: index with which this key was derived * * chainCode: string in hexa encoding used for derivation * * publicKey: string, hexa encoded, in compressed key format - * * checksum: bufferUtil.integerFromBuffer(this._buffers.checksum), + * * checksum: BufferUtil.integerFromBuffer(this._buffers.checksum), * * xpubkey: the string with the base58 representation of this extended key * * checksum: the base58 checksum of xpubkey */ -HDPublicKey.prototype.toObject = function () { +HDPublicKey.prototype.toJSON = function () { return { - network: Network.get(bufferUtil.integerFromBuffer(this._buffers.version)).name, - depth: bufferUtil.integerFromSingleByteBuffer(this._buffers.depth), - fingerPrint: bufferUtil.integerFromBuffer(this.fingerPrint), - parentFingerPrint: bufferUtil.integerFromBuffer(this._buffers.parentFingerPrint), - childIndex: bufferUtil.integerFromBuffer(this._buffers.childIndex), - chainCode: bufferUtil.bufferToHex(this._buffers.chainCode), + network: Network.get(BufferUtil.integerFromBuffer(this._buffers.version)).name, + depth: BufferUtil.integerFromSingleByteBuffer(this._buffers.depth), + fingerPrint: BufferUtil.integerFromBuffer(this.fingerPrint), + parentFingerPrint: BufferUtil.integerFromBuffer(this._buffers.parentFingerPrint), + childIndex: BufferUtil.integerFromBuffer(this._buffers.childIndex), + chainCode: BufferUtil.bufferToHex(this._buffers.chainCode), publicKey: this.publicKey.toString(), - checksum: bufferUtil.integerFromBuffer(this._buffers.checksum), + checksum: BufferUtil.integerFromBuffer(this._buffers.checksum), xpubkey: this.xpubkey }; }; -/** - * Returns the JSON representation of this key's toObject result - * - * @see {HDPublicKey#toObject} - * @return {string} - */ -HDPublicKey.prototype.toJson = function () { - return JSON.stringify(this.toObject()); -}; - HDPublicKey.Hardened = 0x80000000; HDPublicKey.RootElementAlias = ['m', 'M']; diff --git a/lib/unit.js b/lib/unit.js index daad5c876..dc6bb7433 100644 --- a/lib/unit.js +++ b/lib/unit.js @@ -63,7 +63,7 @@ Object.keys(UNITS).forEach(function(key) { * @returns {Unit} A Unit instance */ Unit.fromJSON = function fromJSON(json){ - if (JSUtil.isValidJson(json)) { + if (JSUtil.isValidJSON(json)) { json = JSON.parse(json); } return new Unit(json.amount, json.code); diff --git a/lib/uri.js b/lib/uri.js index 3219445ef..8013cf7f4 100644 --- a/lib/uri.js +++ b/lib/uri.js @@ -68,7 +68,7 @@ URI.fromString = function fromString(str) { * @returns {URI} A new instance of a URI */ URI.fromJSON = function fromJSON(json) { - if (JSUtil.isValidJson(json)) { + if (JSUtil.isValidJSON(json)) { json = JSON.parse(json); } return new URI(json); diff --git a/lib/util/js.js b/lib/util/js.js index 9b53732bb..689b0ac5c 100644 --- a/lib/util/js.js +++ b/lib/util/js.js @@ -23,7 +23,7 @@ module.exports = { * @param {string} arg * @return {Object|boolean} false if the argument is not a JSON string. */ - isValidJson: function isValidJson(arg) { + isValidJSON: function isValidJSON(arg) { try { return JSON.parse(arg); } catch (e) { diff --git a/test/hdprivatekey.js b/test/hdprivatekey.js index 2643ddca9..b55d1f08c 100644 --- a/test/hdprivatekey.js +++ b/test/hdprivatekey.js @@ -68,8 +68,8 @@ describe('HDPrivate key interface', function() { it('builds a json keeping the structure and same members', function() { assert(_.isEqual( - JSON.parse(new HDPrivateKey(json).toJson()), - JSON.parse(new HDPrivateKey(xprivkey).toJson()) + new HDPrivateKey(json).toJSON(), + new HDPrivateKey(xprivkey).toJSON() )); }); diff --git a/test/hdpublickey.js b/test/hdpublickey.js index 8f28b670a..3deb3db8e 100644 --- a/test/hdpublickey.js +++ b/test/hdpublickey.js @@ -106,8 +106,8 @@ describe('HDPublicKey interface', function() { it('can generate a json that has a particular structure', function() { assert(_.isEqual( - JSON.parse(new HDPublicKey(json).toJson()), - JSON.parse(new HDPublicKey(xpubkey).toJson()) + new HDPublicKey(json).toJSON(), + new HDPublicKey(xpubkey).toJSON() )); });