diff --git a/karma.conf.js b/karma.conf.js index d11df0c..f1a2b6a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -9,10 +9,6 @@ module.exports = function(config) { karmaTypescriptConfig: { bundlerOptions: { entrypoints: /\.spec\.ts$/, - acornOptions: { - ecmaVersion: 8, - }, - transforms: [require('karma-typescript-es6-transform')()], }, }, colors: true, diff --git a/package.json b/package.json index 55287be..97860eb 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/index.ts b/src/index.ts index 25c83d2..55be616 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) } @@ -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'))) { @@ -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])) @@ -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 @@ -572,7 +572,7 @@ export default class Wallet { kdfParams.r, kdfParams.p, kdfParams.dklen, - ) + ) as Buffer break default: throw new Error('Unsupported kdf') diff --git a/src/thirdparty.ts b/src/thirdparty.ts index 5afb1fe..e9c8509 100644 --- a/src/thirdparty.ts +++ b/src/thirdparty.ts @@ -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' @@ -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))) } /** @@ -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) @@ -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') ) { diff --git a/test/index.spec.ts b/test/index.spec.ts index abd1b85..c5328b2 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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') @@ -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$/) }) }) @@ -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) }) })