Use importPublic and isValidPublic from ethereumjs-util 4.4.0

This commit is contained in:
Alex Beregszaszi 2016-04-26 15:14:37 +01:00
parent 08d2bfe3ed
commit fc34f08181
2 changed files with 4 additions and 8 deletions

View File

@ -2,7 +2,6 @@ var ethUtil = require('ethereumjs-util')
var crypto = require('crypto') var crypto = require('crypto')
var scryptsy = require('scrypt.js') var scryptsy = require('scrypt.js')
var uuid = require('uuid') var uuid = require('uuid')
var secp256k1 = require('secp256k1')
var bs58check = require('bs58check') var bs58check = require('bs58check')
function assert (val, msg) { function assert (val, msg) {
@ -24,7 +23,7 @@ var Wallet = function (priv, pub) {
throw new Error('Private key does not satisfy the curve requirements (ie. it is invalid)') 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') throw new Error('Invalid public key')
} }
@ -171,11 +170,9 @@ Wallet.prototype.toV3String = function (password, opts) {
} }
Wallet.fromPublicKey = function (pub, nonStrict) { Wallet.fromPublicKey = function (pub, nonStrict) {
// FIXME: duplicate from ethUtil.publicToAddress(), maybe it could be factored out? if (nonStrict) {
if ((pub.length !== 64) && nonStrict) { pub = ethUtil.importPublic(pub)
pub = secp256k1.publicKeyConvert(pub, false).slice(1)
} }
assert(pub.length === 64, 'Invalid public key')
return new Wallet(null, pub) return new Wallet(null, pub)
} }

View File

@ -28,10 +28,9 @@
"dependencies": { "dependencies": {
"aes-js": "^0.2.3", "aes-js": "^0.2.3",
"bs58check": "^1.0.8", "bs58check": "^1.0.8",
"ethereumjs-util": "^4.3.0", "ethereumjs-util": "^4.4.0",
"hdkey": "^0.7.0", "hdkey": "^0.7.0",
"scrypt.js": "^0.2.0", "scrypt.js": "^0.2.0",
"secp256k1": "^3.0.1",
"uuid": "^2.0.1", "uuid": "^2.0.1",
"utf8": "^2.1.1" "utf8": "^2.1.1"
}, },