diff --git a/lib/privatekey.js b/lib/privatekey.js index 01d5bb89b..6f4cae75b 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -1,5 +1,6 @@ 'use strict'; +var _ = require('lodash'); var Address = require('./address'); var base58check = require('./encoding/base58check'); var BN = require('./crypto/bn'); @@ -44,7 +45,7 @@ var PrivateKey = function PrivateKey(data, network, compressed) { }; // detect type of data - if (typeof(data) === 'undefined' || data === 'random'){ + if (_.isUndefined(data)){ info.bn = PrivateKey._getRandomBN(); } else if (data instanceof BN) { info.bn = data; diff --git a/test/privatekey.js b/test/privatekey.js index f3fde3f1a..586ef0d11 100644 --- a/test/privatekey.js +++ b/test/privatekey.js @@ -110,7 +110,7 @@ describe('PrivateKey', function() { it('should not be able to instantiate because compressed is non-boolean', function() { expect(function() { - var a = new PrivateKey('random', 'testnet', 'compressed'); + var a = new PrivateKey(BN(2), 'testnet', 'compressed'); }).to.throw('Must specify whether the corresponding public key is compressed or not (true or false)'); }); @@ -122,7 +122,7 @@ describe('PrivateKey', function() { it('should not be able to instantiate with unknown network', function() { expect(function() { - var a = new PrivateKey('random', 'unknown'); + var a = new PrivateKey(BN(2), 'unknown'); }).to.throw('Must specify the network ("livenet" or "testnet")'); });