Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit fc34f08

Browse files
committed
Use importPublic and isValidPublic from ethereumjs-util 4.4.0
1 parent 08d2bfe commit fc34f08

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var ethUtil = require('ethereumjs-util')
22
var crypto = require('crypto')
33
var scryptsy = require('scrypt.js')
44
var uuid = require('uuid')
5-
var secp256k1 = require('secp256k1')
65
var bs58check = require('bs58check')
76

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

27-
if (pub && pub.length !== 64) {
26+
if (pub && !ethUtil.isValidPublic(pub)) {
2827
throw new Error('Invalid public key')
2928
}
3029

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

173172
Wallet.fromPublicKey = function (pub, nonStrict) {
174-
// FIXME: duplicate from ethUtil.publicToAddress(), maybe it could be factored out?
175-
if ((pub.length !== 64) && nonStrict) {
176-
pub = secp256k1.publicKeyConvert(pub, false).slice(1)
173+
if (nonStrict) {
174+
pub = ethUtil.importPublic(pub)
177175
}
178-
assert(pub.length === 64, 'Invalid public key')
179176
return new Wallet(null, pub)
180177
}
181178

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
"dependencies": {
2929
"aes-js": "^0.2.3",
3030
"bs58check": "^1.0.8",
31-
"ethereumjs-util": "^4.3.0",
31+
"ethereumjs-util": "^4.4.0",
3232
"hdkey": "^0.7.0",
3333
"scrypt.js": "^0.2.0",
34-
"secp256k1": "^3.0.1",
3534
"uuid": "^2.0.1",
3635
"utf8": "^2.1.1"
3736
},

0 commit comments

Comments
 (0)