Skip to content

Commit

Permalink
Use importPublic and isValidPublic from ethereumjs-util 4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 26, 2016
1 parent 08d2bfe commit fc34f08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var ethUtil = require('ethereumjs-util')
var crypto = require('crypto')
var scryptsy = require('scrypt.js')
var uuid = require('uuid')
var secp256k1 = require('secp256k1')
var bs58check = require('bs58check')

function assert (val, msg) {
Expand All @@ -24,7 +23,7 @@ var Wallet = function (priv, pub) {
throw new Error('Private key does not satisfy the curve requirements (ie. it is invalid)')
}

if (pub && pub.length !== 64) {
if (pub && !ethUtil.isValidPublic(pub)) {
throw new Error('Invalid public key')
}

Expand Down Expand Up @@ -171,11 +170,9 @@ Wallet.prototype.toV3String = function (password, opts) {
}

Wallet.fromPublicKey = function (pub, nonStrict) {
// FIXME: duplicate from ethUtil.publicToAddress(), maybe it could be factored out?
if ((pub.length !== 64) && nonStrict) {
pub = secp256k1.publicKeyConvert(pub, false).slice(1)
if (nonStrict) {
pub = ethUtil.importPublic(pub)
}
assert(pub.length === 64, 'Invalid public key')
return new Wallet(null, pub)
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
"dependencies": {
"aes-js": "^0.2.3",
"bs58check": "^1.0.8",
"ethereumjs-util": "^4.3.0",
"ethereumjs-util": "^4.4.0",
"hdkey": "^0.7.0",
"scrypt.js": "^0.2.0",
"secp256k1": "^3.0.1",
"uuid": "^2.0.1",
"utf8": "^2.1.1"
},
Expand Down

0 comments on commit fc34f08

Please sign in to comment.