diff --git a/CONTRIBUTIONS.md b/CONTRIBUTIONS.md index 048fdb5918d..243e89e27f4 100644 --- a/CONTRIBUTIONS.md +++ b/CONTRIBUTIONS.md @@ -1,7 +1,7 @@ -## Guidelines for Pull Requests and Releases (Web3 1.x) +## Guidelines for Pull Requests and Releases (Web3 4.x) This document provides some ground rules for contributors (including the maintainer(s) of -the project) about how to make, review and publish changes to 1.x. The most basic requirement is +the project) about how to make, review and publish changes to 4.x. The most basic requirement is that **Web3 not break**. ### Pull Requests for substantive changes (e.g. everything except comments and docs) diff --git a/README.md b/README.md index 49b44a96aa4..e4c1fc4bd39 100644 --- a/README.md +++ b/README.md @@ -17,16 +17,45 @@ yarn add web3 ## Getting Started -- :writing_hand: If you have questions [submit an issue](https://github.com/ChainSafe/web3.js/issues/new/choose) or join us on [Discord](https://discord.gg/yjyvFRP) -![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord) +- :writing_hand: If you have questions [submit an issue](https://github.com/ChainSafe/web3.js/issues/new/choose) or join us on [Discord](https://discord.gg/yjyvFRP) + ![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord) ## Prerequisites -- :gear: [NodeJS](https://nodejs.org/) (LTS/Fermium) -- :toolbox: [Yarn](https://yarnpkg.com/)/[Lerna](https://lerna.js.org/) +- :gear: [NodeJS](https://nodejs.org/) (LTS/Fermium) +- :toolbox: [Yarn](https://yarnpkg.com/)/[Lerna](https://lerna.js.org/) ## Architecture Overview -| Package | Version | License | Docs | Description | -| --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------- | -| [web3](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/@chainsafe/lodestar) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io/en/v1.5.2/) | :rotating_light: Entire Web3.js offering (includes all packages) | +| Package | Version | License | Docs | Description | +| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | +| [web3](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | :rotating_light: Entire Web3.js offering (includes all packages) | +| [web3-common](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-common) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-common) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Common data structures and interfaces | +| [web3-core](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-core) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-core) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Core functions for web3.js packages | +| [web3-eth](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Modules to interact with the Ethereum blockchain and smart contracts | +| [web3-eth-abi](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-abi) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-abi) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Functions for encoding and decoding EVM in/output | +| [web3-eth-accounts](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-accounts) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-accounts) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Functions for managing Ethereum accounts and signing | +| [web3-eth-contract](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-contract) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-contract) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | The contract pacakge contained in [web3-eth](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth) | +| [web3-eth-ens](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-ens) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-ens) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Functions for interacting with the Ethereum Name Service | +| [web3-eth-iban](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-iban) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-iban) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Functionality for converting Ethereum addressed to IBAN addressed and vice versa | +| [web3-eth-personal](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-personal) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-personal) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Module to interact with the Ethereum blockchain accounts stored in the node | +| [web3-eth-tx](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-tx) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-eth-tx) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | [@ethereumjs/tx](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx) wrapper class | +| [web3-net](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-net) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-net) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Functions to interact with an Ethereum node's network properties | +| [web3-providers-http](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-providers-http) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-providers-http) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Web3.js provider for the HTTP protocol | +| [web3-providers-ipc](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-providers-ipc) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-providers-ipc) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Web3.js provider for IPC | +| [web3-providers-ws](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-providers-ws) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-providers-ws) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Web3.js provider for the Websocket protocol | +| [web3-utils](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-utils) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-utils) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Useful utility functions for Dapp developers | +| [web3-validator](https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-validator) | [![npm](https://img.shields.io/npm/v/web3)](https://www.npmjs.com/package/web3-validator) | [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0) | [![documentation](https://img.shields.io/badge/typedoc-blue)](https://web3js.readthedocs.io) | Utilities for validating objects | + +## Package.json Scripts + +| Script | Description | +| ---------------- | ------------------------------------------------------------------ | +| clean | Uses `rimraf` to remove `dist/` | +| build | Uses `tsc` to build all packages | +| lint | Uses `eslint` to lint all packages | +| lint:fix | Uses `eslint` to check and fix any warnings | +| format | Uses `prettier` to format the code | +| test | Uses `jest` to run unit tests in each package | +| test:integration | Uses `jest` to run tests under `/test/integration` in each package | +| test:unit | Uses `jest` to run tests under `/test/unit` in each package | diff --git a/REVIEW.md b/REVIEW.md new file mode 100644 index 00000000000..60078bc6121 --- /dev/null +++ b/REVIEW.md @@ -0,0 +1,27 @@ +# Review Guidelines + +Our review guidelines are intended to provide clear steps for PR proposers and reviewers. + +Only published PRs will be considered for review. Draft PRs will be considered in-progress and not yet ready for review. + +## Rules + +- [ ] PR follows the provided [template](.github/PULL_REQUEST_TEMPLATE.md). +- [ ] PR doesn't contain unnecessary changes. +- [ ] The changed code preserves the conventions and stylistic consistency of the project. +- [ ] PR uses labels accordingly. (new labels may be suggested) +- [ ] PR includes unit and e2e tests if related to any logic changes. + - [ ] The code coverage rate did not decrease. + - [ ] The error case is always tested. + - [ ] The description of the test case is self-describing. + - [ ] Test cases are grouped for clarity. +- [ ] A PR may only be merged if the following conditions are fulfilled: + - [ ] The correct base branch is selected. + - [ ] Any new files contain the web3.js file header. + - [ ] The documentation was updated (if applicable). + - [ ] The CHANGELOG was updated accordingly. + - [ ] The CI with QA passes successfully. + - [ ] The CI logs were manually checked to ensure false positives were not reported. + - [ ] All comments have been addressed. + - [ ] Doesn't add undue maintenance burden. + - [ ] Doesn't increase the bundle size or is clearly explained why. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000000..8a185527d3d --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,18 @@ +# Security Policy + +## Supported Versions + +Legacy-compatibility `v1.x`: + +- :hourglass_flowing_sand: Web3.js was the previous implementation of the library, written in JavaScript. + +Current-implementation `v4.x`: + +- :hourglass: Web3.js has undergone a complete refactoring and rewrite. +- :stop_sign: We encourage **not** using these releases until official stable releases will be announced. +- :globe_with_meridians: We encourage using the [most recently released version](https://github.com/ChainSafe/web3.js/releases/latest) from the `v1.x` release track before reporting an issue. + +## Reporting a Vulnerability + +- :rotating_light: Please, send vulnerability reports to `security@chainsafe.io`. +- :warning: **Please do not file a public ticket** mentioning the vulnerability, as doing so could increase the likelihood of the vulnerability being exploited before a fix has been created, released and installed on the network. diff --git a/packages/web3-common/src/eth_execution_api.ts b/packages/web3-common/src/eth_execution_api.ts index b95d9d5e689..bf779ac9f2c 100644 --- a/packages/web3-common/src/eth_execution_api.ts +++ b/packages/web3-common/src/eth_execution_api.ts @@ -141,7 +141,7 @@ export interface Log { readonly blockNumber?: Uint | null; readonly address?: Address; readonly data?: HexStringBytes; - readonly topics?: Topic[]; + readonly topics?: null | Topic | Topic[]; } // https://github.com/ethereum/execution-apis/blob/main/src/schemas/receipt.json#L44 @@ -255,8 +255,8 @@ export type EthExecutionAPI = { eth_getWork: () => [HexString32Bytes, HexString32Bytes, HexString32Bytes]; eth_submitWork: ( nonce: HexString8Bytes, - seedHash: HexString32Bytes, - difficulty: HexString32Bytes, + hash: HexString32Bytes, + digest: HexString32Bytes, ) => boolean; eth_submitHashrate: (hashRate: HexString32Bytes, id: HexString32Bytes) => boolean; diff --git a/packages/web3-common/src/formatter.ts b/packages/web3-common/src/formatter.ts index 603cce47755..79b19438df2 100644 --- a/packages/web3-common/src/formatter.ts +++ b/packages/web3-common/src/formatter.ts @@ -117,7 +117,8 @@ export const convertScalarValue = (value: unknown, ethType: string, format: Data } } } catch (error) { - // TODO: Add debugging to verify the error is thrown by the correct function + // If someone did't used `eth` keyword we can return original value + // as the scope of this code is formatting not validation return value; } diff --git a/packages/web3-core/README.md b/packages/web3-core/README.md index 0a8c8d7bf90..7ebe3889a77 100644 --- a/packages/web3-core/README.md +++ b/packages/web3-core/README.md @@ -44,10 +44,10 @@ yarn add web3-core | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-core [npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[npm-url]: https://npmjs.com/package/web3-core +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-core +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-core +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-core +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-core diff --git a/packages/web3-eth-abi/README.md b/packages/web3-eth-abi/README.md index d96ab4eb249..c3d0513e512 100644 --- a/packages/web3-eth-abi/README.md +++ b/packages/web3-eth-abi/README.md @@ -44,10 +44,10 @@ yarn add web3-eth-abi | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js -[npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-abi +[npm-image]: https://img.shields.io/npm/v/web3-eth-abi-method.svg +[npm-url]: https://npmjs.com/package/web3-eth-abi +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-eth-abi +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-eth-abi +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-eth-abi +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-eth-abi diff --git a/packages/web3-eth-abi/src/api/parameters_api.ts b/packages/web3-eth-abi/src/api/parameters_api.ts index 71783c31344..8efc277ae8d 100644 --- a/packages/web3-eth-abi/src/api/parameters_api.ts +++ b/packages/web3-eth-abi/src/api/parameters_api.ts @@ -37,7 +37,6 @@ export const encodeParameters = (abi: ReadonlyArray, params: unknown[] Array.isArray(abi) ? (abi as AbiInput[]) : ([abi] as unknown as AbiInput[]), ); const modifiedParams: Array = []; - for (const [index, param] of params.entries()) { const item = modifiedTypes[index]; let type: string; @@ -58,7 +57,6 @@ export const encodeParameters = (abi: ReadonlyArray, params: unknown[] modifiedParams.push(newParam); } - return ethersAbiCoder.encode( modifiedTypes.map(p => ParamType.from(p)), modifiedParams, diff --git a/packages/web3-eth-abi/src/utils.ts b/packages/web3-eth-abi/src/utils.ts index 20cce30a41a..0e83e59e752 100644 --- a/packages/web3-eth-abi/src/utils.ts +++ b/packages/web3-eth-abi/src/utils.ts @@ -123,12 +123,26 @@ export const mapTypes = ( return mappedTypes; }; +/** + * returns true if input is a hexstring and is odd-lengthed + */ +export const isOddHexstring = (param: unknown): boolean => + typeof param === 'string' && /^(-)?0x[0-9a-f]*$/i.test(param) && param.length % 2 === 1; + +/** + * format odd-length bytes to even-length + */ +export const formatOddHexstrings = (param: string): string => + isOddHexstring(param) ? `0x0${param.substring(2)}` : param; + /** * Handle some formatting of params for backwards compatibility with Ethers V4 */ export const formatParam = (type: string, _param: unknown): unknown => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - let param = _param; + + // clone if _param is an object + const param = typeof _param === 'object' && !Array.isArray(_param) ? { ..._param } : _param; const paramTypeBytes = /^bytes([0-9]*)$/; const paramTypeBytesArray = /^bytes([0-9]*)\[\]$/; const paramTypeNumber = /^(u?int)([0-9]*)$/; @@ -141,7 +155,8 @@ export const formatParam = (type: string, _param: unknown): unknown => { if (paramTypeBytesArray.exec(type) || paramTypeNumberArray.exec(type)) { // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return (param as Array).map(p => formatParam(type.replace('[]', ''), p)); + const paramClone = [...(param as Array)]; + return paramClone.map(p => formatParam(type.replace('[]', ''), p)); } // Format correct width for u?int[0-9]* @@ -150,16 +165,14 @@ export const formatParam = (type: string, _param: unknown): unknown => { const size = parseInt(match[2] ?? '256', 10); if (size / 8 < (param as { length: number }).length) { // pad to correct bit width - param = leftPad(param as string, size); + return leftPad(param as string, size); } } // Format correct length for bytes[0-9]+ match = paramTypeBytes.exec(type); if (match) { - if (Buffer.isBuffer(param)) { - param = toHex(param); - } + const hexParam = Buffer.isBuffer(param) ? toHex(param) : param; // format to correct length const size = parseInt(match[1], 10); @@ -169,18 +182,16 @@ export const formatParam = (type: string, _param: unknown): unknown => { if ((param as string).startsWith('0x')) { maxSize += 2; } - if ((param as string).length < maxSize) { - // pad to correct length - param = rightPad(param as string, size * 2); - } + // pad to correct length + const paddedParam = + (hexParam as string).length < maxSize + ? rightPad(param as string, size * 2) + : hexParam; + return formatOddHexstrings(paddedParam as string); } - // format odd-length bytes to even-length - if ((param as string).length % 2 === 1) { - param = `0x0${(param as string).substring(2)}`; - } + return formatOddHexstrings(hexParam as string); } - return param; }; diff --git a/packages/web3-eth-abi/test/fixtures/data.ts b/packages/web3-eth-abi/test/fixtures/data.ts index 6d1f603fc46..58bdb1fef0b 100644 --- a/packages/web3-eth-abi/test/fixtures/data.ts +++ b/packages/web3-eth-abi/test/fixtures/data.ts @@ -346,6 +346,54 @@ export const validEncodeDecodeParametersData: { }, ]; +export const validEncodeDoesNotMutateData: { + expectedInput: unknown[]; + input: Parameters; + output: ReturnType; +}[] = [ + { + expectedInput: [ + ['34', '255'], + { + propertyOne: ['78', '124'], + propertyTwo: '56', + ChildStruct: { + propertyOne: ['16'], + propertyTwo: '78', + }, + }, + ], + + input: [ + [ + 'uint8[]', + { + ParentStruct: { + propertyOne: 'uint8[]', + propertyTwo: 'uint256', + ChildStruct: { + propertyOne: 'uint8[]', + propertyTwo: 'uint256', + }, + }, + }, + ], + [ + ['34', '255'], + { + propertyOne: ['78', '124'], + propertyTwo: '56', + ChildStruct: { + propertyOne: ['16'], + propertyTwo: '78', + }, + }, + ], + ], + output: '0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000ff0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000007c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004e00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000010', + }, +]; + export const validEncodeParametersData: { input: Parameters; output: ReturnType; diff --git a/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts b/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts index 80956958e33..4d2a1b35149 100644 --- a/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts +++ b/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts @@ -5,6 +5,7 @@ import { validDecodeParametersData, validEncodeParametersData, validEncodeDecodeParametersData, + validEncodeDoesNotMutateData, } from '../../fixtures/data'; import { AbiInput } from '../../../src/types'; @@ -29,6 +30,21 @@ describe('parameters_api', () => { }); }); + describe('encodeParametersDoesNotMutate', () => { + describe('valid data', () => { + it.each(validEncodeDoesNotMutateData)( + '%#: should pass for valid values: %j', + ({ input: [abi, params], output, expectedInput }) => { + expect(encodeParameters(abi, params)).toEqual(output); + // check that params has not been mutated + expect(JSON.parse(JSON.stringify(params))).toEqual( + JSON.parse(JSON.stringify(expectedInput)), + ); + }, + ); + }); + }); + describe('decodeParameters', () => { describe('valid data', () => { it.each(validDecodeParametersData)( diff --git a/packages/web3-eth-accounts/README.md b/packages/web3-eth-accounts/README.md index 19fd7f395cf..ddb5973d4c5 100644 --- a/packages/web3-eth-accounts/README.md +++ b/packages/web3-eth-accounts/README.md @@ -44,10 +44,10 @@ yarn add web3-eth-accounts | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js -[npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth-accounts +[npm-image]: https://img.shields.io/npm/v/web3-eth-accounts-method.svg +[npm-url]: https://npmjs.com/package/web3-eth-accounts +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-eth-accounts +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-eth-accounts +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-eth-accounts +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-eth-accounts diff --git a/packages/web3-eth/README.md b/packages/web3-eth/README.md index c5a8ae1885c..721eb75e794 100644 --- a/packages/web3-eth/README.md +++ b/packages/web3-eth/README.md @@ -44,10 +44,10 @@ yarn add web3-eth | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js -[npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-eth +[npm-image]: https://img.shields.io/npm/v/web3-eth-method.svg +[npm-url]: https://npmjs.com/package/web3-eth +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-eth +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-eth +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-eth +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-eth diff --git a/packages/web3-eth/src/rpc_methods.ts b/packages/web3-eth/src/rpc_methods.ts index f9425ea7e28..6542ebdfa34 100644 --- a/packages/web3-eth/src/rpc_methods.ts +++ b/packages/web3-eth/src/rpc_methods.ts @@ -457,14 +457,14 @@ export async function getWork(requestManager: Web3RequestManager) { export async function submitWork( requestManager: Web3RequestManager, nonce: HexString8Bytes, - seedHash: HexString32Bytes, - difficulty: HexString32Bytes, + hash: HexString32Bytes, + digest: HexString32Bytes, ) { - validator.validate(['bytes8', 'bytes32', 'bytes32'], [nonce, seedHash, difficulty]); + validator.validate(['bytes8', 'bytes32', 'bytes32'], [nonce, hash, digest]); return requestManager.send({ method: 'eth_submitWork', - params: [nonce, seedHash, difficulty], + params: [nonce, hash, digest], }); } diff --git a/packages/web3-eth/src/utils/detect_transaction_type.ts b/packages/web3-eth/src/utils/detect_transaction_type.ts index df6cb874526..a00b0419820 100644 --- a/packages/web3-eth/src/utils/detect_transaction_type.ts +++ b/packages/web3-eth/src/utils/detect_transaction_type.ts @@ -1,6 +1,6 @@ -import { EthExecutionAPI, DEFAULT_RETURN_FORMAT, FormatType, format } from 'web3-common'; +import { EthExecutionAPI, DEFAULT_RETURN_FORMAT, format } from 'web3-common'; import { TransactionTypeParser, Web3Context } from 'web3-core'; -import { Transaction } from '../types'; +import { InternalTransaction, Transaction } from '../types'; export const defaultTransactionTypeParser: TransactionTypeParser = transaction => { const tx = transaction as unknown as Transaction; @@ -22,7 +22,7 @@ export const defaultTransactionTypeParser: TransactionTypeParser = transaction = }; export const detectTransactionType = ( - transaction: FormatType, + transaction: InternalTransaction, web3Context?: Web3Context, ) => (web3Context?.transactionTypeParser ?? defaultTransactionTypeParser)( diff --git a/packages/web3-eth/src/utils/format_transaction.ts b/packages/web3-eth/src/utils/format_transaction.ts index 8d630884afa..39178219987 100644 --- a/packages/web3-eth/src/utils/format_transaction.ts +++ b/packages/web3-eth/src/utils/format_transaction.ts @@ -11,17 +11,14 @@ export function formatTransaction< transaction: TransactionType, returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat, ): FormatType { - const formattedTransaction = mergeDeep( - {}, - transaction as Record, - ) as Transaction; + let formattedTransaction = mergeDeep({}, transaction as Record) as Transaction; if (transaction.common !== undefined) { formattedTransaction.common = { ...transaction.common }; if (transaction.common.customChain !== undefined) formattedTransaction.common.customChain = { ...transaction.common.customChain }; } - const result = format(transactionSchema, formattedTransaction, returnFormat); + formattedTransaction = format(transactionSchema, formattedTransaction, returnFormat); if (formattedTransaction.data !== undefined && formattedTransaction.input !== undefined) throw new TransactionDataAndInputError({ @@ -33,5 +30,5 @@ export function formatTransaction< delete formattedTransaction.input; } - return result as FormatType; + return formattedTransaction as FormatType; } diff --git a/packages/web3-eth/src/web3_eth.ts b/packages/web3-eth/src/web3_eth.ts index 21bb45eef1b..e688568728b 100644 --- a/packages/web3-eth/src/web3_eth.ts +++ b/packages/web3-eth/src/web3_eth.ts @@ -211,10 +211,10 @@ export class Web3Eth extends Web3Context { public async submitWork( nonce: HexString8Bytes, - seedHash: HexString32Bytes, - difficulty: HexString32Bytes, + hash: HexString32Bytes, + digest: HexString32Bytes, ) { - return rpcMethods.submitWork(this.requestManager, nonce, seedHash, difficulty); + return rpcMethods.submitWork(this.requestManager, nonce, hash, digest); } // TODO - Format addresses diff --git a/packages/web3-eth/test/unit/rpc_methods_with_parameters.test.ts b/packages/web3-eth/test/unit/rpc_methods_with_parameters.test.ts index 4ea522daaf2..256b45af715 100644 --- a/packages/web3-eth/test/unit/rpc_methods_with_parameters.test.ts +++ b/packages/web3-eth/test/unit/rpc_methods_with_parameters.test.ts @@ -387,11 +387,11 @@ describe('rpc_methods_with_parameters', () => { }); describe('submitWork', () => { - it.each(submitWorkValidData)('%s', async (nonce, seedHash, difficulty) => { - await submitWork(requestManager, nonce, seedHash, difficulty); + it.each(submitWorkValidData)('%s', async (nonce, hash, digest) => { + await submitWork(requestManager, nonce, hash, digest); expect(requestManagerSendSpy).toHaveBeenCalledWith({ method: 'eth_submitWork', - params: [nonce, seedHash, difficulty], + params: [nonce, hash, digest], }); }); }); diff --git a/packages/web3-net/README.md b/packages/web3-net/README.md index e4643ff728a..70a31f87624 100644 --- a/packages/web3-net/README.md +++ b/packages/web3-net/README.md @@ -44,10 +44,10 @@ yarn add web3-net | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js -[npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-net +[npm-image]: https://img.shields.io/npm/v/web3-net-method.svg +[npm-url]: https://npmjs.com/package/web3-net +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-net +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-net +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-net +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-net diff --git a/packages/web3-providers-ipc/README.md b/packages/web3-providers-ipc/README.md index bf508e15977..e792b9b7b45 100644 --- a/packages/web3-providers-ipc/README.md +++ b/packages/web3-providers-ipc/README.md @@ -12,7 +12,7 @@ This is a sub-package of [web3.js][repo]. -`web3-providers-ipc` contains the ideal setup for a Web3.js package. +`web3-providers-ipc` contains the Web3.js provider for Inter Process Communication (IPC). ###### Get it from the NPM Registry diff --git a/packages/web3-providers-ws/README.md b/packages/web3-providers-ws/README.md index e15d8370877..8065354b5d8 100644 --- a/packages/web3-providers-ws/README.md +++ b/packages/web3-providers-ws/README.md @@ -44,10 +44,10 @@ yarn add web3-providers-ws | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js -[npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-providers-ws +[npm-image]: https://img.shields.io/npm/v/web3-providers-ws-method.svg +[npm-url]: https://npmjs.com/package/web3-providers-ws +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-providers-ws +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-providers-ws +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-providers-ws +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-providers-ws diff --git a/packages/web3-validator/README.md b/packages/web3-validator/README.md index 4d145b35e50..ea07daf7e69 100644 --- a/packages/web3-validator/README.md +++ b/packages/web3-validator/README.md @@ -12,7 +12,7 @@ This is a sub-package of [web3.js][repo]. -`web3-validator` contains the ideal setup for a Web3.js package. +`web3-validator` contains functions for validating objects. ###### Get it from the NPM Registry @@ -83,10 +83,10 @@ The implementation of the validator is extension of [JSON-Schema-Draft07](https: | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: http://web3js.readthedocs.io/en/4.0/ -[repo]: https://github.com/ethereum/web3.js +[repo]: https://github.com/ChainSafe/web3.js/tree/4.x/packages/web3-validator [npm-image]: https://img.shields.io/npm/v/web3-core-method.svg -[npm-url]: https://npmjs.org/packages/web3-package-tempalte -[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-package-tempalte -[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-package-tempalte -[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-package-tempalte -[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-package-tempalte +[npm-url]: https://npmjs.com/package/web3-validator +[deps-image]: https://david-dm.org/ethereum/web3.js/4.x/status.svg?path=tools/web3-validator +[deps-url]: https://david-dm.org/ethereum/web3.js/4.x?path=tools/web3-validator +[deps-dev-image]: https://david-dm.org/ethereum/web3.js/4.x/dev-status.svg?path=tools/web3-validator +[deps-dev-url]: https://david-dm.org/ethereum/web3.js/4.x?type=dev&path=tools/web3-validator