fix private key validation and base58 invalid tests
This commit is contained in:
parent
3cd4e31c31
commit
150a943447
|
@ -19,6 +19,7 @@ PrivateKey.prototype.validate = function() {
|
|||
if (this.data.length < 32 || (this.data.length > 1+32 && !this.compressed()) || (this.data.length==1+32+1 && this.data[1+32+1-1]!=1) || this.data.length>1+32+1)
|
||||
throw new Error('invalid data length');
|
||||
});
|
||||
if (typeof this.network() === 'undefined') throw new Error('invalid network');
|
||||
};
|
||||
|
||||
// get or set the payload data (as a Buffer object)
|
||||
|
|
|
@ -42,6 +42,7 @@ WalletKey.prototype.fromObj = function(obj) {
|
|||
this.privKey.compressed = typeof obj.compressed === 'undefined'? true: obj.compressed;
|
||||
} else {
|
||||
var priv = new PrivateKey(obj.priv);
|
||||
priv.validate();
|
||||
this.privKey.private = new Buffer(priv.payload());
|
||||
this.privKey.compressed = priv.compressed();
|
||||
}
|
||||
|
|
|
@ -131,11 +131,31 @@ describe('Miscelaneous stuff', function() {
|
|||
});
|
||||
testdata.dataBase58KeysInvalid.forEach(function(datum) {
|
||||
var b58 = datum[0];
|
||||
it('shouldnt be able to create Address nor WalletKey with ' + b58, function() {
|
||||
it('shouldnt be able to create Address with ' + b58, function() {
|
||||
var a = new Address(b58);
|
||||
var invalidAddress = (!a.isValid());
|
||||
invalidAddress.should.equal(true);
|
||||
});
|
||||
it('shouldnt be able to create WalletKey with ' + b58, function() {
|
||||
var kl = new WalletKey({
|
||||
network: networks.livenet
|
||||
});
|
||||
var kt = new WalletKey({
|
||||
network: networks.livenet
|
||||
});
|
||||
var createLivenet = function() {
|
||||
kl.fromObj({
|
||||
priv: b58
|
||||
});
|
||||
};
|
||||
var createTestnet = function() {
|
||||
kt.fromObj({
|
||||
priv: b58
|
||||
});
|
||||
};
|
||||
createLivenet.should.throw();
|
||||
createTestnet.should.throw();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue