Skip to content

Commit

Permalink
Init web3-rpc-methods package (#5441)
Browse files Browse the repository at this point in the history
* Init web3-rpc-methods package

* Add web3-rpc-methods dependency to web3-eth

* Add web3-rpc-methods dependency to web3-eth-personal

* Add web3-rpc-methods to web3-net

* Move eth_execution_api to web3-types

* Move eth_personal_api to web3-types

* Update imports and code for web3-types and web3-rpc-methods refactors

* Add ^ to web3-rpc-methods version

* Update CHANGELOG.md for affected packages

* Update CHANGELOG.md for affected packages

* Fix linter errors

* Fix failing test

* Move rpc_methods tests from web3-eth to web3-rpc-methods

* Move rpc_methods test from web3-net to web3-rpc-methods

* Update added CHANGELOG header to [Unreleased]

* Update packages/web3-eth-ens/CHANGELOG.md

Co-authored-by: Alex  <alex.luu@mail.utoronto.ca>

Co-authored-by: Alex  <alex.luu@mail.utoronto.ca>
  • Loading branch information
spacesailor24 and Alex authored Sep 24, 2022
1 parent 58beddf commit 84766ae
Show file tree
Hide file tree
Showing 186 changed files with 2,465 additions and 526 deletions.
2 changes: 1 addition & 1 deletion packages/web3-errors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-errors",
"version": "0.1.1-alpha.0",
"version": "0.1.1-alpha.0",
"description": "This package has web3 error classes",
"main": "dist/index.js",
"repository": "https://github.com/ChainSafe/web3.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
@@ -1,6 +1,6 @@
{
"name": "web3-eth-abi",
"version": "4.0.1-alpha.0",
"version": "4.0.1-alpha.0",
"description": "Web3 module encode and decode EVM in/output.",
"main": "dist/index.js",
"repository": "https://github.com/ethereum/web3.js/tree/4.x/packages/web3-eth-abi",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth-accounts",
"version": "4.0.1-alpha.0",
"version": "4.0.1-alpha.0",
"description": "Package for managing Ethereum accounts and signing",
"main": "dist/index.js",
"repository": "https://github.com/ChainSafe/web3.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-eth-ens/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- I've improved the security in XY (#1000)
-->

## [Unreleased]

### Changed

- `Web3NetAPI` is now imported from `web3-types` instead of `web3-net` (#5441)
2 changes: 1 addition & 1 deletion packages/web3-eth-ens/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth-ens",
"version": "4.0.1-alpha.0",
"version": "4.0.1-alpha.0",
"description": "This package has ENS functions for interacting with Ethereum Name Service.",
"main": "dist/index.js",
"repository": "https://github.com/ChainSafe/web3.js",
Expand Down
11 changes: 9 additions & 2 deletions packages/web3-eth-ens/src/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ import {
ENSUnsupportedNetworkError,
} from 'web3-errors';
import { Web3Context, Web3ContextObject } from 'web3-core';
import { getId, Web3NetAPI } from 'web3-net';
import { Address, SupportedProviders, EthExecutionAPI, TransactionReceipt } from 'web3-types';
import { getId } from 'web3-net';
import {
Address,
SupportedProviders,
EthExecutionAPI,
TransactionReceipt,
Web3NetAPI,
} from 'web3-types';
import { DEFAULT_RETURN_FORMAT, FormatType, FMT_NUMBER, DataFormat } from 'web3-utils';
import { NonPayableCallOptions, Contract } from 'web3-eth-contract';

import { PublicResolverAbi } from './abi/ens/PublicResolver';
import { Registry } from './registry';
import { registryAddresses } from './config';
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-iban/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth-iban",
"version": "4.0.1-alpha.0",
"version": "4.0.1-alpha.0",
"description": "This package converts Ethereum addresses to IBAN addresses and vice versa.",
"main": "dist/index.js",
"repository": "https://github.com/ChainSafe/web3.js",
Expand Down
16 changes: 16 additions & 0 deletions packages/web3-eth-personal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- I've improved the security in XY (#1000)
-->

## [Unreleased]

### Added

- `web3-rpc-methods` dependency (#5441)

### Changed

- Import `EthPersonalAPI` from `web3-types` instead of local import (#5441)
- Replace the imported methods from `rcp_methods.ts` with `personalRpcMethods` imports from `web3-rpc-methods` (#5441)
- Replace use of `EthPersonalAPIManager` with `Web3RequestManager<EthPersonalAPI>` (#5441)

### Removed

- Exported type `EthPersonalAPIManager`, `EthPersonalAPI` is not exported via `web3-types` (#5441)
1 change: 1 addition & 0 deletions packages/web3-eth-personal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"web3-core": "^4.0.1-alpha.0",
"web3-eth": "^4.0.1-alpha.0",
"web3-rpc-methods": "^0.1.0-alpha.0",
"web3-types": "^0.1.1-alpha.0",
"web3-utils": "^4.0.1-alpha.0",
"web3-validator": "^0.1.1-alpha.0"
Expand Down
1 change: 0 additions & 1 deletion packages/web3-eth-personal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

import { Personal } from './personal';

export * from './types';
export * from './personal';

export default Personal;
4 changes: 2 additions & 2 deletions packages/web3-eth-personal/src/personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3Context } from 'web3-core';
import { Address, HexString, Transaction } from 'web3-types';
import { EthPersonalAPI } from './eth_personal_api';
import { Address, EthPersonalAPI, HexString, Transaction } from 'web3-types';

import * as rpcWrappers from './rpc_method_wrappers';

export class Personal extends Web3Context<EthPersonalAPI> {
Expand Down
61 changes: 28 additions & 33 deletions packages/web3-eth-personal/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,87 +14,82 @@ GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3RequestManager } from 'web3-core';
import { ETH_DATA_FORMAT, isHexStrict, toChecksumAddress, utf8ToHex } from 'web3-utils';
import { formatTransaction } from 'web3-eth';
import { Address, HexString, Transaction } from 'web3-types';
import { Address, EthPersonalAPI, HexString, Transaction } from 'web3-types';
import { validator } from 'web3-validator';
import {
getAccounts as rpcGetAccounts,
lockAccount as rpcLockAccount,
newAccount as rpcNewAccount,
unlockAccount as rpcUnlockAccount,
importRawKey as rpcImportRawKey,
sendTransaction as rpcSendTransaction,
signTransaction as rpcSignTransaction,
sign as rpcSign,
ecRecover as rpcEcRecover,
} from './rcp_methods';
import { EthPersonalAPIManager } from './types';

export const getAccounts = async (requestManager: EthPersonalAPIManager) => {
const result = await rpcGetAccounts(requestManager);
import { personalRpcMethods } from 'web3-rpc-methods';

export const getAccounts = async (requestManager: Web3RequestManager<EthPersonalAPI>) => {
const result = await personalRpcMethods.getAccounts(requestManager);

return result.map(toChecksumAddress);
};

export const newAccount = async (requestManager: EthPersonalAPIManager, password: string) => {
export const newAccount = async (
requestManager: Web3RequestManager<EthPersonalAPI>,
password: string,
) => {
validator.validate(['string'], [password]);

const result = await rpcNewAccount(requestManager, password);
const result = await personalRpcMethods.newAccount(requestManager, password);

return toChecksumAddress(result);
};

export const unlockAccount = async (
requestManager: EthPersonalAPIManager,
requestManager: Web3RequestManager<EthPersonalAPI>,
address: Address,
password: string,
unlockDuration: number,
) => {
validator.validate(['address', 'string', 'uint'], [address, password, unlockDuration]);

return rpcUnlockAccount(requestManager, address, password, unlockDuration);
return personalRpcMethods.unlockAccount(requestManager, address, password, unlockDuration);
};

export const lockAccount = async (requestManager: EthPersonalAPIManager, address: Address) => {
export const lockAccount = async (
requestManager: Web3RequestManager<EthPersonalAPI>,
address: Address,
) => {
validator.validate(['address'], [address]);

return rpcLockAccount(requestManager, address);
return personalRpcMethods.lockAccount(requestManager, address);
};

export const importRawKey = async (
requestManager: EthPersonalAPIManager,
requestManager: Web3RequestManager<EthPersonalAPI>,
keyData: HexString,
passphrase: string,
) => {
validator.validate(['string', 'string'], [keyData, passphrase]);

return rpcImportRawKey(requestManager, keyData, passphrase);
return personalRpcMethods.importRawKey(requestManager, keyData, passphrase);
};

export const sendTransaction = async (
requestManager: EthPersonalAPIManager,
requestManager: Web3RequestManager<EthPersonalAPI>,
tx: Transaction,
passphrase: string,
) => {
const formattedTx = formatTransaction(tx, ETH_DATA_FORMAT);

return rpcSendTransaction(requestManager, formattedTx, passphrase);
return personalRpcMethods.sendTransaction(requestManager, formattedTx, passphrase);
};

export const signTransaction = async (
requestManager: EthPersonalAPIManager,
requestManager: Web3RequestManager<EthPersonalAPI>,
tx: Transaction,
passphrase: string,
) => {
const formattedTx = formatTransaction(tx, ETH_DATA_FORMAT);

return rpcSignTransaction(requestManager, formattedTx, passphrase);
return personalRpcMethods.signTransaction(requestManager, formattedTx, passphrase);
};

export const sign = async (
requestManager: EthPersonalAPIManager,
requestManager: Web3RequestManager<EthPersonalAPI>,
data: HexString,
address: Address,
passphrase: string,
Expand All @@ -103,17 +98,17 @@ export const sign = async (

const dataToSign = isHexStrict(data) ? data : utf8ToHex(data);

return rpcSign(requestManager, dataToSign, address, passphrase);
return personalRpcMethods.sign(requestManager, dataToSign, address, passphrase);
};

export const ecRecover = async (
requestManager: EthPersonalAPIManager,
requestManager: Web3RequestManager<EthPersonalAPI>,
signedData: HexString,
signature: string,
) => {
validator.validate(['string', 'string'], [signedData, signature]);

const signedDataString = isHexStrict(signedData) ? signedData : utf8ToHex(signedData);

return rpcEcRecover(requestManager, signedDataString, signature);
return personalRpcMethods.ecRecover(requestManager, signedDataString, signature);
};
8 changes: 8 additions & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `web3-rpc-methods` dependency (#5441)

### Changed

- `Web3EthExecutionAPI` is now imported via `web3-types` instead of `web3_eth_execution_api.ts` (#5441)
- Replace the imported methods from `rpc_methods.ts` with `ethRpcMethods` imports from `web3-rpc-methods` (#5441)
- `Web3NetAPI` is now imported from `web3-types` instead of `web3-net` (#5441)
- Moved `rpc_methods` tests to `web3-rpc-methods` (#5441)
- [setimmediate](https://github.com/yuzujs/setImmediate) package to polyfill [setImmediate](https://nodejs.org/api/timers.html#setimmediatecallback-args) for browsers (#5450)
- Implemented the logic for `transactionBlockTimeout` (#5294)

Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web3-eth",
"version": "4.0.1-alpha.0",
"version": "4.0.1-alpha.0",
"description": "Web3 module to interact with the Ethereum blockchain and smart contracts.",
"main": "dist/index.js",
"repository": "https://github.com/ChainSafe/web3.js",
Expand Down Expand Up @@ -53,6 +53,7 @@
"web3-eth-accounts": "^4.0.1-alpha.0",
"web3-net": "^4.0.1-alpha.0",
"web3-providers-ws": "^4.0.1-alpha.0",
"web3-rpc-methods": "^0.1.0-alpha.0",
"web3-types": "^0.1.1-alpha.0",
"web3-utils": "^4.0.1-alpha.0",
"web3-validator": "^0.1.1-alpha.0"
Expand Down
Loading

0 comments on commit 84766ae

Please sign in to comment.