Use importPublic and isValidPublic from ethereumjs-util 4.4.0
This commit is contained in:
parent
08d2bfe3ed
commit
fc34f08181
9
index.js
9
index.js
|
@ -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) {
|
||||
|
@ -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')
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue