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

Init web3-rpc-methods package #5441

Merged
merged 20 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d385aa2
Init web3-rpc-methods package
spacesailor24 Sep 14, 2022
f1b0da9
Add web3-rpc-methods dependency to web3-eth
spacesailor24 Sep 15, 2022
9f342b2
Add web3-rpc-methods dependency to web3-eth-personal
spacesailor24 Sep 15, 2022
25fbcd3
Add web3-rpc-methods to web3-net
spacesailor24 Sep 15, 2022
fb17704
Move eth_execution_api to web3-types
spacesailor24 Sep 15, 2022
e200f08
Move eth_personal_api to web3-types
spacesailor24 Sep 15, 2022
ce0c683
Update imports and code for web3-types and web3-rpc-methods refactors
spacesailor24 Sep 15, 2022
a44a1ef
Add ^ to web3-rpc-methods version
spacesailor24 Sep 15, 2022
6bab085
Update CHANGELOG.md for affected packages
spacesailor24 Sep 15, 2022
98b38fa
Update CHANGELOG.md for affected packages
spacesailor24 Sep 15, 2022
2f156d8
Fix linter errors
spacesailor24 Sep 15, 2022
3d066ed
Fix failing test
spacesailor24 Sep 15, 2022
40a6c95
Move rpc_methods tests from web3-eth to web3-rpc-methods
spacesailor24 Sep 16, 2022
510a0ac
Merge branch '4.x' into wyatt/4.x/init-web3-rpc-methods
spacesailor24 Sep 16, 2022
a71faa0
Move rpc_methods test from web3-net to web3-rpc-methods
spacesailor24 Sep 16, 2022
f3facdc
Update added CHANGELOG header to [Unreleased]
spacesailor24 Sep 16, 2022
2531cc3
Merge branch '4.x' into wyatt/4.x/init-web3-rpc-methods
spacesailor24 Sep 16, 2022
a53bd4e
Update packages/web3-eth-ens/CHANGELOG.md
spacesailor24 Sep 20, 2022
a08de94
Merge branch '4.x' into wyatt/4.x/init-web3-rpc-methods
spacesailor24 Sep 20, 2022
f99ee21
Solve merge conflicts
spacesailor24 Sep 24, 2022
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
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)
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
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,4 +39,12 @@ 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)
1 change: 1 addition & 0 deletions packages/web3-eth/package.json
Original file line number Diff line number Diff line change
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