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

Commit 59eb071

Browse files
authored
Merge pull request #121 from ethereumjs/update-ethereumjs-util-to-v700
Update ethereumjs-util to v7.0.1
2 parents b7574b1 + 073319c commit 59eb071

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

karma.conf.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ module.exports = function(config) {
99
karmaTypescriptConfig: {
1010
bundlerOptions: {
1111
entrypoints: /\.spec\.ts$/,
12-
acornOptions: {
13-
ecmaVersion: 8,
14-
},
15-
transforms: [require('karma-typescript-es6-transform')()],
1612
},
1713
},
1814
colors: true,

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@web3-js/scrypt-shim": "^0.1.0",
4747
"aes-js": "^3.1.1",
4848
"bs58check": "^2.1.2",
49-
"ethereumjs-util": "^6.0.0",
49+
"ethereumjs-util": "^7.0.1",
5050
"hdkey": "^1.1.1",
5151
"randombytes": "^2.0.6",
5252
"utf8": "^3.0.0",
@@ -67,8 +67,7 @@
6767
"karma-chrome-launcher": "^2.0.0",
6868
"karma-firefox-launcher": "^1.0.0",
6969
"karma-mocha": "^2.0.0",
70-
"karma-typescript": "^4.1.1",
71-
"karma-typescript-es6-transform": "^5.0.2",
70+
"karma-typescript": "^5.0.2",
7271
"lodash.zip": "^4.2.0",
7372
"mocha": "^7.1.2",
7473
"nyc": "^15.0.1",

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export default class Wallet {
255255
if (icapDirect) {
256256
const max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
257257
while (true) {
258-
const privateKey = randomBytes(32)
258+
const privateKey = randomBytes(32) as Buffer
259259
if (new ethUtil.BN(ethUtil.privateToAddress(privateKey)).lte(max)) {
260260
return new Wallet(privateKey)
261261
}
@@ -274,7 +274,7 @@ export default class Wallet {
274274
}
275275

276276
while (true) {
277-
const privateKey = randomBytes(32)
277+
const privateKey = randomBytes(32) as Buffer
278278
const address = ethUtil.privateToAddress(privateKey)
279279

280280
if (pattern.test(address.toString('hex'))) {
@@ -352,7 +352,7 @@ export default class Wallet {
352352
kdfparams.R,
353353
kdfparams.P,
354354
kdfparams.DkLen,
355-
)
355+
) as Buffer
356356

357357
const ciphertext = Buffer.from(json.Crypto.CipherText, 'hex')
358358
const mac = ethUtil.keccak256(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
@@ -399,7 +399,7 @@ export default class Wallet {
399399
kdfparams.r,
400400
kdfparams.p,
401401
kdfparams.dklen,
402-
)
402+
) as Buffer
403403
} else if (json.crypto.kdf === 'pbkdf2') {
404404
kdfparams = json.crypto.kdfparams
405405

@@ -572,7 +572,7 @@ export default class Wallet {
572572
kdfParams.r,
573573
kdfParams.p,
574574
kdfParams.dklen,
575-
)
575+
) as Buffer
576576
break
577577
default:
578578
throw new Error('Unsupported kdf')

src/thirdparty.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as crypto from 'crypto'
2-
import * as ethUtil from 'ethereumjs-util'
2+
import { keccak256, sha256, toBuffer } from 'ethereumjs-util'
33

44
import Wallet from './index'
55

@@ -167,7 +167,7 @@ export function fromEtherWallet(input: string | EtherWalletOptions, password: st
167167
* Third Party API: Import a brain wallet used by Ether.Camp
168168
*/
169169
export function fromEtherCamp(passphrase: string): Wallet {
170-
return new Wallet(ethUtil.keccak256(Buffer.from(passphrase)))
170+
return new Wallet(keccak256(Buffer.from(passphrase)))
171171
}
172172

173173
/**
@@ -210,13 +210,13 @@ export function fromKryptoKit(entropy: string, password: string): Wallet {
210210

211211
let privateKey: Buffer
212212
if (type === 'd') {
213-
privateKey = ethUtil.sha256(entropy)
213+
privateKey = sha256(toBuffer(entropy))
214214
} else if (type === 'q') {
215215
if (typeof password !== 'string') {
216216
throw new Error('Password required')
217217
}
218218

219-
const encryptedSeed = ethUtil.sha256(Buffer.from(entropy.slice(0, 30)))
219+
const encryptedSeed = sha256(Buffer.from(entropy.slice(0, 30)))
220220
const checksum = entropy.slice(30, 46)
221221

222222
const salt = kryptoKitBrokenScryptSeed(encryptedSeed)
@@ -244,8 +244,7 @@ export function fromKryptoKit(entropy: string, password: string): Wallet {
244244
if (checksum.length > 0) {
245245
if (
246246
checksum !==
247-
ethUtil
248-
.sha256(ethUtil.sha256(privateKey))
247+
sha256(sha256(privateKey))
249248
.slice(0, 8)
250249
.toString('hex')
251250
) {

test/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* tslint:disable no-invalid-this */
22
import * as assert from 'assert'
3-
import * as ethUtil from 'ethereumjs-util'
3+
import { BN } from 'ethereumjs-util'
44
import { Wallet as ethersWallet } from 'ethers'
55

66
const zip = require('lodash.zip')
@@ -35,7 +35,7 @@ describe('.getPrivateKey()', function() {
3535
it('should fail', function() {
3636
assert.throws(function() {
3737
Wallet.fromPrivateKey(Buffer.from('001122', 'hex'))
38-
}, /^Error: Private key does not satisfy the curve requirements \(ie. it is invalid\)$/)
38+
}, /^Error: Expected private key to be an Uint8Array with length 32$/)
3939
})
4040
})
4141

@@ -160,10 +160,10 @@ describe('.generate()', function() {
160160
assert.strictEqual(Wallet.generate().getPrivateKey().length, 32)
161161
})
162162
it('should generate an account compatible with ICAP Direct', function() {
163-
const max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
163+
const max = new BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
164164
const wallet = Wallet.generate(true)
165165
assert.strictEqual(wallet.getPrivateKey().length, 32)
166-
assert.strictEqual(new ethUtil.BN(wallet.getAddress()).lte(max), true)
166+
assert.strictEqual(new BN(wallet.getAddress()).lte(max), true)
167167
})
168168
})
169169

0 commit comments

Comments
 (0)