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

Update ethereumjs-util to v7.0.1 #121

Merged
merged 5 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ module.exports = function(config) {
karmaTypescriptConfig: {
bundlerOptions: {
entrypoints: /\.spec\.ts$/,
acornOptions: {
ecmaVersion: 8,
},
transforms: [require('karma-typescript-es6-transform')()],
},
},
colors: true,
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@web3-js/scrypt-shim": "^0.1.0",
"aes-js": "^3.1.1",
"bs58check": "^2.1.2",
"ethereumjs-util": "^6.0.0",
"ethereumjs-util": "^7.0.1",
"hdkey": "^1.1.1",
"randombytes": "^2.0.6",
"utf8": "^3.0.0",
Expand All @@ -67,8 +67,7 @@
"karma-chrome-launcher": "^2.0.0",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^2.0.0",
"karma-typescript": "^4.1.1",
"karma-typescript-es6-transform": "^5.0.2",
"karma-typescript": "^5.0.2",
"lodash.zip": "^4.2.0",
"mocha": "^7.1.2",
"nyc": "^15.0.1",
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default class Wallet {
if (icapDirect) {
const max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
while (true) {
const privateKey = randomBytes(32)
const privateKey = randomBytes(32) as Buffer
if (new ethUtil.BN(ethUtil.privateToAddress(privateKey)).lte(max)) {
return new Wallet(privateKey)
}
Expand All @@ -274,7 +274,7 @@ export default class Wallet {
}

while (true) {
const privateKey = randomBytes(32)
const privateKey = randomBytes(32) as Buffer
const address = ethUtil.privateToAddress(privateKey)

if (pattern.test(address.toString('hex'))) {
Expand Down Expand Up @@ -352,7 +352,7 @@ export default class Wallet {
kdfparams.R,
kdfparams.P,
kdfparams.DkLen,
)
) as Buffer

const ciphertext = Buffer.from(json.Crypto.CipherText, 'hex')
const mac = ethUtil.keccak256(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
Expand Down Expand Up @@ -399,7 +399,7 @@ export default class Wallet {
kdfparams.r,
kdfparams.p,
kdfparams.dklen,
)
) as Buffer
} else if (json.crypto.kdf === 'pbkdf2') {
kdfparams = json.crypto.kdfparams

Expand Down Expand Up @@ -572,7 +572,7 @@ export default class Wallet {
kdfParams.r,
kdfParams.p,
kdfParams.dklen,
)
) as Buffer
break
default:
throw new Error('Unsupported kdf')
Expand Down
11 changes: 5 additions & 6 deletions src/thirdparty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from 'crypto'
import * as ethUtil from 'ethereumjs-util'
import { keccak256, sha256, toBuffer } from 'ethereumjs-util'

import Wallet from './index'

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

/**
Expand Down Expand Up @@ -210,13 +210,13 @@ export function fromKryptoKit(entropy: string, password: string): Wallet {

let privateKey: Buffer
if (type === 'd') {
privateKey = ethUtil.sha256(entropy)
privateKey = sha256(toBuffer(entropy))
} else if (type === 'q') {
if (typeof password !== 'string') {
throw new Error('Password required')
}

const encryptedSeed = ethUtil.sha256(Buffer.from(entropy.slice(0, 30)))
const encryptedSeed = sha256(Buffer.from(entropy.slice(0, 30)))
const checksum = entropy.slice(30, 46)

const salt = kryptoKitBrokenScryptSeed(encryptedSeed)
Expand Down Expand Up @@ -244,8 +244,7 @@ export function fromKryptoKit(entropy: string, password: string): Wallet {
if (checksum.length > 0) {
if (
checksum !==
ethUtil
.sha256(ethUtil.sha256(privateKey))
sha256(sha256(privateKey))
.slice(0, 8)
.toString('hex')
) {
Expand Down
8 changes: 4 additions & 4 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* tslint:disable no-invalid-this */
import * as assert from 'assert'
import * as ethUtil from 'ethereumjs-util'
import { BN } from 'ethereumjs-util'
import { Wallet as ethersWallet } from 'ethers'

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

Expand Down Expand Up @@ -160,10 +160,10 @@ describe('.generate()', function() {
assert.strictEqual(Wallet.generate().getPrivateKey().length, 32)
})
it('should generate an account compatible with ICAP Direct', function() {
const max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
const max = new BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
const wallet = Wallet.generate(true)
assert.strictEqual(wallet.getPrivateKey().length, 32)
assert.strictEqual(new ethUtil.BN(wallet.getAddress()).lte(max), true)
assert.strictEqual(new BN(wallet.getAddress()).lte(max), true)
})
})

Expand Down