Skip to content

Commit

Permalink
Merge pull request #2937 from michaelsbradleyjr/2.x-node-12-support
Browse files Browse the repository at this point in the history
Node >= v8.0.0 support for web3 2.0.0-alpha
  • Loading branch information
nivida authored Jul 12, 2019
2 parents b7225f9 + c271d21 commit bcd1d88
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Ethereum JavaScript API wrapper repository",
"license": "LGPL-3.0",
"engines": {
"node": "<8.0.0 <12.0.0"
"node": ">=8.0.0"
},
"main": "./packages/web3/src/index.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-core-helpers",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-core-helpers.cjs.js",
"module": "dist/web3-core-helpers.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-method/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-core-method",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-core-method.cjs.js",
"module": "dist/web3-core-method.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core-subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-core-subscriptions",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-core-subscriptions.cjs.js",
"module": "dist/web3-core-subscriptions.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-core",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-core.cjs.js",
"module": "dist/web3-core.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-abi",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-abi.cjs.js",
"module": "dist/web3-eth-abi.esm.js",
Expand Down
48 changes: 14 additions & 34 deletions packages/web3-eth-accounts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-accounts",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-accounts.cjs.js",
"module": "dist/web3-eth-accounts.esm.js",
Expand All @@ -25,7 +25,8 @@
"lodash": "^4.17.11",
"pbkdf2": "^3.0.17",
"randombytes": "^2.1.0",
"scrypt.js": "0.3.0",
"semver": "6.2.0",
"scryptsy": "2.1.0",
"uuid": "3.3.2",
"web3-core": "1.0.0-beta.55",
"web3-core-helpers": "1.0.0-beta.55",
Expand Down
34 changes: 34 additions & 0 deletions packages/web3-eth-accounts/src/crypto/Scrypt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import scryptsy from 'scryptsy';

let scrypt;

const isNode = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
if (isNode) {
const NODE_MIN_VER_WITH_BUILTIN_SCRYPT = '10.5.0';
const semver = require('semver');
const useNodeBuiltin = isNode && semver.Range('>=' + NODE_MIN_VER_WITH_BUILTIN_SCRYPT).test(process.version);

if (useNodeBuiltin) {
const crypto = require('crypto');
scrypt = function (key, salt, N, r, p, dkLen) {
return crypto.scryptSync(key, salt, dkLen, {N, r, p});
};
} else {
let scryptPkg;
try {
scryptPkg = require('scrypt');
scrypt = function (key, salt, N, r, p, dkLen) {
return scryptPkg.hashSync(key, {N, r, p}, dkLen, salt);
};
} catch (e) {
console.warn(
'\x1b[33m%s\x1b[0m',
`You can improve web3's peformance when running Node.js versions older than ${NODE_MIN_VER_WITH_BUILTIN_SCRYPT} by installing the (deprecated) scrypt package in your project`
);
}
}
}

scrypt = scrypt || scryptsy;

export default scrypt;
6 changes: 3 additions & 3 deletions packages/web3-eth-accounts/src/models/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @date 2019
*/

import scryptsy from 'scrypt.js';
import scrypt from '../crypto/Scrypt';
import isString from 'lodash/isString';
import isObject from 'lodash/isObject';
import * as EthLibAccount from 'eth-lib/lib/account'; // TODO: Remove this dependency
Expand Down Expand Up @@ -157,7 +157,7 @@ export default class Account {
kdfparams.n = options.n || 8192; // 2048 4096 8192 16384
kdfparams.r = options.r || 8;
kdfparams.p = options.p || 1;
derivedKey = scryptsy(Buffer.from(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
derivedKey = scrypt(Buffer.from(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
} else {
throw new Error('Unsupported kdf');
}
Expand Down Expand Up @@ -227,7 +227,7 @@ export default class Account {
kdfparams = json.crypto.kdfparams;

// FIXME: support progress reporting callback
derivedKey = scryptsy(
derivedKey = scrypt(
Buffer.from(password),
Buffer.from(kdfparams.salt, 'hex'),
kdfparams.n,
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-eth-accounts/tests/src/models/AccountTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scryptsy from 'scrypt.js';
import scrypt from '../../../src/crypto/Scrypt';
import randomBytes from 'randombytes';
import {pbkdf2Sync} from 'pbkdf2';
import {createCipheriv, createDecipheriv} from 'browserify-cipher';
Expand All @@ -18,7 +18,7 @@ jest.mock('uuid');
jest.mock('randombytes');
jest.mock('pbkdf2');
jest.mock('browserify-cipher');
jest.mock('scrypt.js');
jest.mock('../../../src/crypto/Scrypt');
jest.mock('../../../src/Accounts');

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('AccountTest', () => {
privateKey: '0x0'
});

scryptsy.mockReturnValueOnce(Buffer.from('00000000000000000000000000000000'));
scrypt.mockReturnValueOnce(Buffer.from('00000000000000000000000000000000'));

keccak256.mockReturnValueOnce('0xmac');

Expand All @@ -164,7 +164,7 @@ describe('AccountTest', () => {
`0x${Buffer.concat([Buffer.from('0'), Buffer.from('0')]).toString('hex')}`
);

expect(scryptsy).toHaveBeenCalledWith(
expect(scrypt).toHaveBeenCalledWith(
Buffer.from('password'),
Buffer.from('salt', 'hex'),
'n',
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('AccountTest', () => {

createCipheriv.mockReturnValue(cipher);

scryptsy.mockReturnValueOnce(Buffer.from('0000000000000000'));
scrypt.mockReturnValueOnce(Buffer.from('0000000000000000'));

keccak256.mockReturnValueOnce('0xmac');

Expand Down Expand Up @@ -377,7 +377,7 @@ describe('AccountTest', () => {

expect(randomBytes).toHaveBeenNthCalledWith(3, 16);

expect(scryptsy).toHaveBeenCalledWith(Buffer.from('password'), Buffer.from('random'), 8192, 8, 1, 32);
expect(scrypt).toHaveBeenCalledWith(Buffer.from('password'), Buffer.from('random'), 8192, 8, 1, 32);

expect(createCipheriv).toHaveBeenCalledWith(
'aes-128-ctr',
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-admin",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-admin.cjs.js",
"module": "dist/web3-eth-admin.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-contract",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-contract.cjs.js",
"module": "dist/web3-eth-contract.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-debug",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-debug.cjs.js",
"module": "dist/web3-eth-debug.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-ens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-ens",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-ens.cjs.js",
"module": "dist/web3-eth-ens.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-iban/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-iban",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth-iban.cjs.js",
"module": "dist/web3-eth-iban.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-miner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.",
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-miner",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"license": "LGPL-3.0",
"main": "dist/web3-eth-miner.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-personal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.",
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-personal",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"license": "LGPL-3.0",
"main": "dist/web3-eth-personal.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-txpool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.",
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-txpool",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"license": "LGPL-3.0",
"main": "dist/web3-eth-txpool.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-eth.cjs.js",
"module": "dist/web3-eth.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-net/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Web3 module to interact with the Ethereum nodes networking properties.",
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-net",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"license": "LGPL-3.0",
"main": "dist/web3-net.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-providers",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-providers.cjs.js",
"module": "dist/web3-providers.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Web3 module to interact with the Whisper messaging protocol.",
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-shh",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"license": "LGPL-3.0",
"main": "dist/web3-shh.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-utils",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3-utils.cjs.js",
"module": "dist/web3-utils.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0 <=12.6.0"
"node": ">=8.0.0"
},
"main": "dist/web3.cjs.js",
"module": "dist/web3.esm.js",
Expand Down

0 comments on commit bcd1d88

Please sign in to comment.