@exodus/web3-ethereum 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,10 +29,9 @@ export class EthereumProvider extends BaseProvider {
29
29
  this.#isConnected = true;
30
30
  });
31
31
  this.#initializePromise = this.#initialize();
32
- this.#getDefaultChainId =
33
- typeof getDefaultChainId === 'function'
34
- ? getDefaultChainId
35
- : async () => null;
32
+ this.#getDefaultChainId = getDefaultChainId
33
+ ? getDefaultChainId
34
+ : async () => null;
36
35
  }
37
36
  _callRpcMethod(method, params) {
38
37
  const prefix = this.#chainId;
@@ -4,6 +4,7 @@ import type { Transport } from '@exodus/web3-types';
4
4
  interface RpcConstructor {
5
5
  new (...options: unknown[]): typeof RPC;
6
6
  }
7
+ export declare function parseAndValidateRequestWithEVMPrefix(stringifiedValue: string): any;
7
8
  export declare const registerRPCHandlers: ({ deps, RPC, transport, }: {
8
9
  deps: Dependencies;
9
10
  RPC: RpcConstructor;
@@ -24,6 +24,21 @@ function validateEVMsDeps(evms) {
24
24
  }
25
25
  evms.forEach(validateEVMDeps);
26
26
  }
27
+ export function parseAndValidateRequestWithEVMPrefix(stringifiedValue) {
28
+ const value = JSON.parse(stringifiedValue);
29
+ const originalMethod = value.method;
30
+ if (!originalMethod) {
31
+ return validateRequest(value);
32
+ }
33
+ const underscorePosition = originalMethod.indexOf('_');
34
+ if (underscorePosition === -1) {
35
+ return validateRequest(value);
36
+ }
37
+ // 0x1_eth_getAccounts -> eth_getAccounts
38
+ const methodWithoutPrefix = originalMethod.slice(underscorePosition + 1);
39
+ validateRequest({ ...value, method: methodWithoutPrefix });
40
+ return value;
41
+ }
27
42
  export const registerRPCHandlers = ({ deps, RPC, transport, }) => {
28
43
  validateCommonDeps(deps, ['evms']);
29
44
  validateEVMsDeps(deps.evms);
@@ -33,13 +48,13 @@ export const registerRPCHandlers = ({ deps, RPC, transport, }) => {
33
48
  if (!transport) {
34
49
  throw new Error('"transport" parameter is required');
35
50
  }
51
+ const { app, evms = [], wallet } = deps;
36
52
  const rpc = new RPC({
37
53
  transport,
38
- parse: validateRequest,
54
+ parse: parseAndValidateRequestWithEVMPrefix,
39
55
  getIsDevelopmentMode: () => app.isDevelopmentEnvironment?.() ?? false,
40
56
  requestTimeout: RPC_REQUEST_TIMEOUT,
41
57
  });
42
- const { app, evms = [], wallet } = deps;
43
58
  for (const evm of evms) {
44
59
  const evmDeps = { ...app, ...evm, ...wallet };
45
60
  exposeHandlers(rpc, evmDeps);
@@ -1,5 +1,5 @@
1
- import { validateAndParseEthereumTypedData } from '@exodus/web3-validation';
2
1
  import { InvalidInputError } from '@exodus/web3-errors';
2
+ import { parseAndValidateTypedData as _parseAndValidateTypedData } from './validator.js';
3
3
  export function convertChainIdToHex(chainId) {
4
4
  if (typeof chainId !== 'string') {
5
5
  throw new Error(`'chainId' should be a string, got: ${typeof chainId}`);
@@ -15,12 +15,12 @@ export function convertChainIdToHex(chainId) {
15
15
  export function parseAndValidateTypedData(typedData, { chainId: activeChainId }) {
16
16
  let parsedTypedData;
17
17
  try {
18
- parsedTypedData = validateAndParseEthereumTypedData(typedData);
18
+ parsedTypedData = _parseAndValidateTypedData(typedData);
19
19
  }
20
20
  catch (e) {
21
21
  throw new InvalidInputError();
22
22
  }
23
- if (parsedTypedData.domain?.chainId) {
23
+ if (parsedTypedData?.domain?.chainId) {
24
24
  const suppliedChainIdHex = convertChainIdToHex(`${parsedTypedData.domain.chainId}`);
25
25
  if (activeChainId.toLowerCase() !== suppliedChainIdHex) {
26
26
  throw new InvalidInputError();
@@ -1 +1,4 @@
1
- export declare const validateRequest: () => never;
1
+ declare type UnknownFunction = (...args: unknown[]) => unknown | never;
2
+ export declare const validateRequest: UnknownFunction;
3
+ export declare const parseAndValidateTypedData: UnknownFunction;
4
+ export {};