From d305a6502d979e90a54bd3e2d01b3fd84b643b02 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Sat, 2 May 2020 00:08:22 +0200 Subject: [PATCH 1/5] Bumped ethereumjs-util version to v7.0.1 in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55287be..3f6caa4 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", From 6a388e41e4a010bfabc668260857a5efa1e09422 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Sat, 2 May 2020 00:11:26 +0200 Subject: [PATCH 2/5] Added Buffer conversion for entropy in Thirdparty API fromKryptoKit(), some Buffer type assertions --- src/index.ts | 10 +++++----- src/thirdparty.ts | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) 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') ) { From 5ec875605d018e03d9284d6c82216e2898ac3d27 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Sat, 2 May 2020 00:12:09 +0200 Subject: [PATCH 3/5] Limited ethereumjs-util import scope in tests --- test/index.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/index.spec.ts b/test/index.spec.ts index abd1b85..f66206e 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') @@ -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) }) }) From 61487a16e1f870b4f1a3752e4ac7660f05c887e0 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Sat, 9 May 2020 10:52:31 +0200 Subject: [PATCH 4/5] Updated error msg in index.spec.ts .getPrivateKey() test to match with new msg from updated secp2561 v4 library --- test/index.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.spec.ts b/test/index.spec.ts index f66206e..c5328b2 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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$/) }) }) From 073319ce1876b24af6f15fa750afc48f965115ce Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Mon, 18 May 2020 11:46:09 -0700 Subject: [PATCH 5/5] upgrade karma-typescript to v5 (which supports es modules, reducing need for karma-typescript-es6-transform) --- karma.conf.js | 4 ---- package.json | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) 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 3f6caa4..97860eb 100644 --- a/package.json +++ b/package.json @@ -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",