Browse Source

Merge pull request #867 from yemel/fix/testnet-private

Fix creation of a randomn testnet private key
patch-2
Braydon Fuller 10 years ago
parent
commit
e4a8fe4d95
  1. 5
      lib/privatekey.js
  2. 12
      test/privatekey.js

5
lib/privatekey.js

@ -97,7 +97,7 @@ PrivateKey.prototype._classifyArguments = function(data, network) {
};
// detect type of data
if (_.isUndefined(data)){
if (_.isUndefined(data) || _.isNull(data)){
info.bn = PrivateKey._getRandomBN();
} else if (data instanceof BN) {
info.bn = data;
@ -105,6 +105,9 @@ PrivateKey.prototype._classifyArguments = function(data, network) {
info = PrivateKey._transformBuffer(data, network);
} else if (PrivateKey._isJSON(data)){
info = PrivateKey._transformJSON(data);
} else if (!network && Networks.get(data)) {
info.bn = PrivateKey._getRandomBN();
info.network = Networks.get(data);
} else if (typeof(data) === 'string'){
if (JSUtil.isHexa(data)) {
info.bn = BN(new Buffer(data, 'hex'));

12
test/privatekey.js

@ -31,6 +31,18 @@ describe('PrivateKey', function() {
should.exist(b.bn);
});
it('should create a new random testnet private key with only one argument', function() {
var a = new PrivateKey(Networks.testnet);
should.exist(a);
should.exist(a.bn);
});
it('should create a new random testnet private key with empty data', function() {
var a = new PrivateKey(null, Networks.testnet);
should.exist(a);
should.exist(a.bn);
});
it('should create a private key from WIF string', function() {
var a = new PrivateKey('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
should.exist(a);

Loading…
Cancel
Save