Skip to content

Commit

Permalink
Add strict checks to the constructor (preferable it shouldn't be publ…
Browse files Browse the repository at this point in the history
…icly available, but this is JS)
  • Loading branch information
axic committed Mar 23, 2016
1 parent 5635068 commit 99d3cb5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 99d3cb5

Please sign in to comment.