Skip to content

Commit

Permalink
Ensure private keys are valid according to the curve
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Mar 23, 2016
1 parent 60c9eba commit 155513d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function decipherBuffer (decipher, data) {
}

var Wallet = function (priv) {
if (!ethUtil.isValidPrivate(priv)) {
throw new Error('Private key does not satisfy the curve requirements (ie. it is invalid)')
}
this.privKey = priv
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://github.com/axic/ethereumjs-wallet",
"dependencies": {
"aes-js": "^0.2.3",
"ethereumjs-util": "^4.2.0",
"ethereumjs-util": "^4.3.0",
"scrypt.js": "^0.1.0",
"uuid": "^2.0.1",
"utf8": "^2.1.1"
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ describe('.getPrivateKey()', function () {
it('should work', function () {
assert.equal(fixturewallet.getPrivateKey().toString('hex'), 'efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378')
})
it('should fail', function () {
assert.throws(function () {
Wallet.fromPrivateKey(new Buffer('001122', 'hex'))
})
})
})

describe('.getPrivateKeyString()', function () {
Expand Down

0 comments on commit 155513d

Please sign in to comment.