Ensure private keys are valid according to the curve

This commit is contained in:
Alex Beregszaszi 2016-03-23 12:20:55 +00:00
parent 60c9ebaaf7
commit 155513d8e9
3 changed files with 9 additions and 1 deletions

View File

@ -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
}

View File

@ -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"

View File

@ -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 () {