From c0ac2a6c073fd12c713bea2867799b0b14a82e17 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 26 Jan 2023 18:17:29 -0330 Subject: [PATCH] Refactor RPC `getAccounts` usage The `getAccounts` function is defined and used in two different places in the RPC pipeline: `RPCMethodMiddleware.ts` and `web3-provider-engine`. The second one has been removed, so now all usage is in `RPCMethodMiddleware.ts`. `getAccounts` is passed into `web3-provider-engine` and used in the `HookedWalletSubprovider`: https://github.com/MetaMask/web3-provider-engine/blob/cf612f898002833c36730d23972fe4c4dd483c76/subproviders/hooked-wallet.js It is used in these methods: * `eth_coinbase` * `eth_accounts` * `parity_defaultAccount` It's also called to validate the sender, for the following methods: * `eth_signTypedData` * `eth_signTypedData_v3` * `eth_signTypedData_v4` * `encryption_public_key` * `eth_decryptMessage` * `personal_sign` * `eth_sign` * `eth_signTransaction` * `eth_sendTransaction` Of these methods, most of them are intercepted in `RPCMethodMiddleware.ts`, so the requests never make it to `web3-provider-engine`. These three methods will make their way there: `parity_defaultAccount`, `encryption_public_key`, and `eth_decryptMessage`. The decryption- related messages rely on constructor parameters that mobile does not pass in, so those always throw an error. The only method this hook is used for in practice is `parity_defaultAccount`. The `parity_defaultAccount` method was added to `RPCMethodMiddleware.ts, so now that method won't make it to `web3-provider-engine` either. Functionally it is the same as `eth_coinbase`, so the same implementation has been used. This relates to #5513 --- app/core/Engine.ts | 15 --------------- app/core/RPCMethods/RPCMethodMiddleware.ts | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 8e455640fab..e9c13ad2938 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -134,21 +134,6 @@ class Engine { } }, }, - getAccounts: ( - end: (arg0: null, arg1: any[]) => void, - payload: { hostname: string | number }, - ) => { - const { approvedHosts } = store.getState(); - const isEnabled = approvedHosts[payload.hostname]; - const { KeyringController } = this.context; - const isUnlocked = KeyringController.isUnlocked(); - const selectedAddress = - this.context.PreferencesController.state.selectedAddress; - end( - null, - isUnlocked && isEnabled && selectedAddress ? [selectedAddress] : [], - ); - }, }; const assetsContractController = new AssetsContractController({ onPreferencesStateChange: (listener) => diff --git a/app/core/RPCMethods/RPCMethodMiddleware.ts b/app/core/RPCMethods/RPCMethodMiddleware.ts index 644bcc1525f..944e18d8e3d 100644 --- a/app/core/RPCMethods/RPCMethodMiddleware.ts +++ b/app/core/RPCMethods/RPCMethodMiddleware.ts @@ -324,6 +324,7 @@ export const getRpcMethodMiddleware = ({ }, eth_accounts: getEthAccounts, eth_coinbase: getEthAccounts, + parity_defaultAccount: getEthAccounts, eth_sendTransaction: async () => { checkTabActive(); return RPCMethods.eth_sendTransaction({