Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ethereumjs-util with @ethereumjs/util #6283

Merged
merged 32 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,7 @@ Released with 1.0.0-beta.37 code base.

- Builds fixed by updating all typescript versions to 4.9.5 (#6238)
- ABI encoding for large negative `int`s (#6239)
- Updated type file for `submitWork` parameters, accepts 3 parameters instead of an array (#5200)
- Updated type file for `submitWork` parameters, accepts 3 parameters instead of an array (#5200)

### Changed
- Replace ethereumjs-util with @ethereumjs/util (#6283)
512 changes: 283 additions & 229 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"bignumber.js": "^9.0.1",
"bn.js": "^5.2.1",
"browserify": "^16.5.2",
"browserify-zlib": "^0.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this lib is added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this Polyfill otherwise build fails by error

"buffer": "^4.9.2",
"bundlesize": "^0.18.1",
"chai": "^4.2.0",
Expand All @@ -127,8 +128,8 @@
"karma-firefox-launcher": "^1.3.0",
"karma-mocha": "^2.0.1",
"karma-spec-reporter": "0.0.32",
"mocha": "^10.1.0",
"lerna": "^6.1.0",
"mocha": "^10.1.0",
"nx": "^15.3.0",
"nyc": "^14.1.1",
"process": "^0.11.10",
Expand Down
6,262 changes: 6,253 additions & 9 deletions packages/web3-eth-accounts/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"dependencies": {
"@ethereumjs/common": "2.5.0",
"@ethereumjs/tx": "3.3.2",
"@ethereumjs/util": "^8.1.0",
"eth-lib": "0.2.8",
"ethereumjs-util": "^7.1.5",
"scrypt-js": "^3.0.1",
"uuid": "^9.0.0",
"web3-core": "1.10.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-eth-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var helpers = require('web3-core-helpers');
var {TransactionFactory} = require('@ethereumjs/tx');
var Common = require('@ethereumjs/common').default;
var HardForks = require('@ethereumjs/common').Hardfork;
var ethereumjsUtil = require('ethereumjs-util');
var ethereumjsUtil = require('@ethereumjs/util');

var isNot = function(value) {
return (typeof value === 'undefined') || value === null;
Expand Down Expand Up @@ -397,7 +397,7 @@ function _handleTxPricing(_this, tx) {
) {
// Legacy transaction, return provided gasPrice
resolve({ gasPrice: tx.gasPrice })
}
}
else if (tx.type === '0x2' && tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
// EIP-1559 transaction, return provided maxFeePerGas and maxPriorityFeePerGas
resolve({ maxFeePerGas: tx.maxFeePerGas, maxPriorityFeePerGas: tx.maxPriorityFeePerGas })
Expand Down Expand Up @@ -465,7 +465,7 @@ Accounts.prototype.hashMessage = function hashMessage(data) {
var preamble = '\x19Ethereum Signed Message:\n' + messageBytes.length;
var preambleBuffer = Buffer.from(preamble);
var ethMessage = Buffer.concat([preambleBuffer, messageBuffer]);
return ethereumjsUtil.bufferToHex(ethereumjsUtil.keccak256(ethMessage));
return ethereumjsUtil.bufferToHex(utils.keccak256(ethMessage));
};

Accounts.prototype.sign = function sign(data, privateKey) {
Expand Down
4,788 changes: 4,161 additions & 627 deletions packages/web3-utils/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/web3-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
},
"main": "lib/index.js",
"dependencies": {
"@ethereumjs/util": "^8.1.0",
"bn.js": "^5.2.1",
"ethereum-bloom-filters": "^1.0.6",
"ethereumjs-util": "^7.1.0",
"ethereum-cryptography": "^2.1.2",
"ethjs-unit": "0.1.6",
"number-to-bn": "1.7.0",
"randombytes": "^2.1.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/web3-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
var BN = require('bn.js');
var numberToBN = require('number-to-bn');
var utf8 = require('utf8');
var ethereumjsUtil = require('ethereumjs-util');
var ethereumjsUtil = require('@ethereumjs/util');
var ethereumBloomFilters = require('ethereum-bloom-filters');
var {keccak256} = require('ethereum-cryptography/keccak.js');

/**
* Returns true if object is BN, otherwise false
Expand Down Expand Up @@ -500,7 +501,7 @@ var sha3 = function (value) {
value = Buffer.from(value, 'utf-8');
}

var returnValue = ethereumjsUtil.bufferToHex(ethereumjsUtil.keccak256(value));
var returnValue = ethereumjsUtil.bufferToHex(keccak256(value));

if(returnValue === SHA3_NULL_S) {
return null;
Expand All @@ -509,7 +510,7 @@ var sha3 = function (value) {
}
};
// expose the under the hood keccak256
sha3._Hash = ethereumjsUtil.keccak256;
sha3._Hash = keccak256;

/**
* @method sha3Raw
Expand Down Expand Up @@ -550,7 +551,7 @@ var BNwrapped = function (value) {
}
else {
return new BN(value);
}
}
};
Object.setPrototypeOf(BNwrapped, BN);
Object.setPrototypeOf(BNwrapped.prototype, BN.prototype);
Expand Down
10 changes: 4 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ module.exports = {
],
resolve: {
alias: {
// To avoid blotting up the `bn.js` library all over the packages
// use single library instance.
// To avoid blotting up the `bn.js` library all over the packages
// use single library instance.
"bn.js": path.resolve(__dirname, 'node_modules/bn.js'),
'ethereumjs-util': path.resolve(__dirname, 'node_modules/ethereumjs-util'),
"buffer": path.resolve(__dirname, 'node_modules/buffer'),


"zlib": require.resolve('browserify-zlib'),
},
fallback: {
https: require.resolve('https-browserify'),
http: require.resolve("stream-http"),
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify")
},

},

module: {
rules: [
{
Expand Down
Loading