From f289fb17cfc9eb8246c41a97755a3f5a40b0cc88 Mon Sep 17 00:00:00 2001 From: Jonathan Downing Date: Mon, 8 Jan 2024 17:02:09 -0600 Subject: [PATCH] Add back support for eth namespace --- .../chain/serial-fallback-provider.ts | 2 +- .../internal-ethereum-provider/index.ts | 43 +++++++++++++++++++ background/services/provider-bridge/index.ts | 7 +++ background/services/provider-bridge/utils.ts | 1 + .../wallet-connect/eip155-request-utils.ts | 6 +++ .../legacy-sign-client-helper.ts | 3 ++ manifest/manifest.json | 2 +- 7 files changed, 62 insertions(+), 2 deletions(-) diff --git a/background/services/chain/serial-fallback-provider.ts b/background/services/chain/serial-fallback-provider.ts index 98b9d3ec..16002432 100644 --- a/background/services/chain/serial-fallback-provider.ts +++ b/background/services/chain/serial-fallback-provider.ts @@ -529,7 +529,7 @@ export default class SerialFallbackProvider extends QuaisJsonRpcProvider { override async send(method: string, params: unknown[]): Promise { // Since we can reliably return the chainId with absolutely no communication with // the provider - we can return it without needing to worry about routing rpc calls - if (method === "quai_chainId") { + if (method === "quai_chainId" || method === "eth_chainId") { return this.cachedChainId } diff --git a/background/services/internal-ethereum-provider/index.ts b/background/services/internal-ethereum-provider/index.ts index b759f220..29d45ae6 100644 --- a/background/services/internal-ethereum-provider/index.ts +++ b/background/services/internal-ethereum-provider/index.ts @@ -180,6 +180,10 @@ export default class InternalEthereumProviderService extends BaseService case "quai_signTypedData_v1": case "quai_signTypedData_v3": case "quai_signTypedData_v4": + case "eth_signTypedData": + case "eth_signTypedData_v1": + case "eth_signTypedData_v3": + case "eth_signTypedData_v4": return this.signTypedData({ account: { address: params[0] as string, @@ -239,6 +243,42 @@ export default class InternalEthereumProviderService extends BaseService case "net_version": case "web3_clientVersion": case "web3_sha3": + case "eth_blockNumber": + case "eth_call": + case "eth_estimateGas": + case "eth_feeHistory": + case "eth_gasPrice": + case "eth_getBalance": + case "eth_getBlockByHash": + case "eth_getBlockByNumber": + case "eth_getBlockTransactionCountByHash": + case "eth_getBlockTransactionCountByNumber": + case "eth_getCode": + case "eth_getFilterChanges": + case "eth_getFilterLogs": + case "eth_getLogs": + case "eth_getProof": + case "eth_getStorageAt": + case "eth_getTransactionByBlockHashAndIndex": + case "eth_getTransactionByBlockNumberAndIndex": + case "eth_getTransactionByHash": + case "eth_getTransactionCount": + case "eth_getTransactionReceipt": + case "eth_getUncleByBlockHashAndIndex": + case "eth_getUncleByBlockNumberAndIndex": + case "eth_getUncleCountByBlockHash": + case "eth_getUncleCountByBlockNumber": + case "eth_maxPriorityFeePerGas": + case "eth_newBlockFilter": + case "eth_newFilter": + case "eth_newPendingTransactionFilter": + case "eth_nodeLocation": + case "eth_protocolVersion": + case "eth_sendRawTransaction": + case "eth_subscribe": + case "eth_syncing": + case "eth_uninstallFilter": + case "eth_unsubscribe": return this.chainService.send( method, params, @@ -250,6 +290,7 @@ export default class InternalEthereumProviderService extends BaseService const { address } = await this.preferenceService.getSelectedAccount() return [address] } + case "eth_sendTransaction": case "quai_sendTransaction": return this.signTransaction( { @@ -260,6 +301,7 @@ export default class InternalEthereumProviderService extends BaseService await this.chainService.broadcastSignedTransaction(signed) return signed.hash }) + case "eth_signTransaction": case "quai_signTransaction": return this.signTransaction( params[0] as JsonRpcTransactionRequest, @@ -274,6 +316,7 @@ export default class InternalEthereumProviderService extends BaseService } ) ) + case "eth_sign": case "quai_sign": // --- important wallet methods --- return this.signData( { diff --git a/background/services/provider-bridge/index.ts b/background/services/provider-bridge/index.ts index 58316a35..213e13cf 100644 --- a/background/services/provider-bridge/index.ts +++ b/background/services/provider-bridge/index.ts @@ -472,6 +472,10 @@ export default class ProviderBridgeService extends BaseService { case "quai_signTypedData_v1": case "quai_signTypedData_v3": case "quai_signTypedData_v4": + case "eth_signTypedData": + case "eth_signTypedData_v1": + case "eth_signTypedData_v3": + case "eth_signTypedData_v4": checkPermissionSignTypedData( params[0] as HexString, enablingPermission @@ -483,6 +487,7 @@ export default class ProviderBridgeService extends BaseService { origin, showExtensionPopup(AllowedQueryParamPage.signData) ) + case "eth_sign": case "quai_sign": checkPermissionSign(params[0] as HexString, enablingPermission) @@ -501,6 +506,8 @@ export default class ProviderBridgeService extends BaseService { origin, showExtensionPopup(AllowedQueryParamPage.personalSignData) ) + case "eth_signTransaction": + case "eth_sendTransaction": case "quai_signTransaction": case "quai_sendTransaction": checkPermissionSignTransaction( diff --git a/background/services/provider-bridge/utils.ts b/background/services/provider-bridge/utils.ts index afa8ebd8..1ebfec8b 100644 --- a/background/services/provider-bridge/utils.ts +++ b/background/services/provider-bridge/utils.ts @@ -158,6 +158,7 @@ export function parseRPCRequestParams( params: RPCRequest["params"] ): RPCRequest["params"] { switch (method) { + case "eth_sign": case "quai_sign": return sameEVMAddress( params[0] as HexString, diff --git a/background/services/wallet-connect/eip155-request-utils.ts b/background/services/wallet-connect/eip155-request-utils.ts index 2adffef3..4bd835e1 100644 --- a/background/services/wallet-connect/eip155-request-utils.ts +++ b/background/services/wallet-connect/eip155-request-utils.ts @@ -44,6 +44,9 @@ export function approveEIP155Request( case "personal_sign": case "quai_signTransaction": case "quai_sendTransaction": + case "eth_sign": + case "eth_sendTransaction": + case "eth_signTransaction": return formatJsonRpcResult(id, signedMessage) default: @@ -72,6 +75,9 @@ export function processRequestParams( case "personal_sign": case "quai_sendTransaction": case "quai_signTransaction": + case "eth_sign": + case "eth_sendTransaction": + case "eth_signTransaction": return { id, topic, diff --git a/background/services/wallet-connect/legacy-sign-client-helper.ts b/background/services/wallet-connect/legacy-sign-client-helper.ts index b150f31a..e7c9432f 100644 --- a/background/services/wallet-connect/legacy-sign-client-helper.ts +++ b/background/services/wallet-connect/legacy-sign-client-helper.ts @@ -127,6 +127,9 @@ export function processLegacyRequestParams( case "personal_sign": case "quai_sendTransaction": case "quai_signTransaction": + case "eth_signTypedData": + case "eth_sendTransaction": + case "eth_signTransaction": return payload default: return undefined diff --git a/manifest/manifest.json b/manifest/manifest.json index 862f22b2..8ba97c8e 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -16,7 +16,7 @@ ], "content_scripts": [ { - "matches": ["file://*/*", "http://localhost/*", "https://*/*"], + "matches": ["file://*/*", "http://localhost/*", "http://127.0.0.1/*", "http://0.0.0.0/*", "https://*/*"], "js": ["provider-bridge.js"], "run_at": "document_start", "all_frames": true