Add strict checks to the constructor (preferable it shouldn't be publicly available, but this is JS)

This commit is contained in:
Alex Beregszaszi 2016-03-23 14:20:14 +00:00
parent 5635068fff
commit 99d3cb52eb
1 changed files with 9 additions and 0 deletions

View File

@ -16,9 +16,18 @@ function decipherBuffer (decipher, data) {
}
var Wallet = function (priv, pub) {
if (priv && pub) {
throw new Error('Cannot supply both a private and a public key to the constructor')
}
if (priv && !ethUtil.isValidPrivate(priv)) {
throw new Error('Private key does not satisfy the curve requirements (ie. it is invalid)')
}
if (pub && pub.length !== 64) {
throw new Error('Invalid public key')
}
this._privKey = priv
this._pubKey = pub
}