add network detection in private key and tests
This commit is contained in:
parent
5bf652dcb6
commit
807a72666c
|
@ -1,6 +1,7 @@
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
|
|
||||||
var parent = imports.parent || require('./util/VersionedData');
|
var parent = imports.parent || require('./util/VersionedData');
|
||||||
|
var networks= imports.networks || require('./networks');
|
||||||
|
|
||||||
//compressed is true if public key is compressed; false otherwise
|
//compressed is true if public key is compressed; false otherwise
|
||||||
function PrivateKey(version, buf, compressed) {
|
function PrivateKey(version, buf, compressed) {
|
||||||
|
@ -61,4 +62,19 @@ PrivateKey.prototype.compressed = function(compressed) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PrivateKey.prototype.network = function() {
|
||||||
|
var version = this.version();
|
||||||
|
|
||||||
|
var livenet = networks.livenet;
|
||||||
|
var testnet = networks.testnet;
|
||||||
|
|
||||||
|
var answer;
|
||||||
|
if (version === livenet.keySecret)
|
||||||
|
answer = livenet;
|
||||||
|
else if (version === testnet.keySecret)
|
||||||
|
answer = testnet;
|
||||||
|
|
||||||
|
return answer;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = require('soop')(PrivateKey);
|
module.exports = require('soop')(PrivateKey);
|
||||||
|
|
|
@ -29,4 +29,24 @@ describe('PrivateKey', function() {
|
||||||
|
|
||||||
privkey.as('base58').should.equal('cTpB4YiyKiBcPxnefsDpbnDxFDffjqJob8wGCEDXxgQ7zQoMXJdH');
|
privkey.as('base58').should.equal('cTpB4YiyKiBcPxnefsDpbnDxFDffjqJob8wGCEDXxgQ7zQoMXJdH');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to detect network from privatekey', function() {
|
||||||
|
var a = new PrivateKey('cMu64LfQqrPC83SjJqde4mZ5jzC48zyeKbUZbTjQdh6pa1h48TdM');
|
||||||
|
a.network().name.should.equal('testnet');
|
||||||
|
var a = new PrivateKey('cS62Ej4SobZnpFQYN1PEEBr2KWf5sgRYYnELtumcG6WVCfxno39V');
|
||||||
|
a.network().name.should.equal('testnet');
|
||||||
|
|
||||||
|
//compress flag = on
|
||||||
|
var a = new PrivateKey('KwHXRTLNWKzxy2NUnnhFtxricC3Dod4Dd3D7RKzVkKDtWrZhuDHs');
|
||||||
|
a.network().name.should.equal('livenet');
|
||||||
|
var a = new PrivateKey('KwaLX8oyJNNCL9tcyYakQHJDTnrPAmZ2M1YK7NhEcT9j55LWqMZz');
|
||||||
|
a.network().name.should.equal('livenet');
|
||||||
|
|
||||||
|
//compress flag = off
|
||||||
|
var a = new PrivateKey('5KS4jw2kT3VoEFUfzgSpX3GVi7qRYkTfwTBU7qxPKyvbGuiVj33');
|
||||||
|
a.network().name.should.equal('livenet');
|
||||||
|
var a = new PrivateKey('5JZsbYcnYN8Dz2YeSLZr6aswrVevedMUSFWxpie6SPpYRb2E4Gi');
|
||||||
|
a.network().name.should.equal('livenet');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue