@exodus/web3-ethereum 13.1.1 → 13.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2024 Exodus Movement, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  import type { Deps as BaseProviderDeps } from '@exodus/web3-provider';
2
2
  import type { Observable, Storage } from '@exodus/web3-types';
3
- export declare type ChainId = string;
3
+ export type ChainId = string;
4
4
  export interface ProviderConnectInfo {
5
5
  chainId: ChainId;
6
6
  }
@@ -23,26 +23,26 @@ export interface RequestArguments {
23
23
  method: string;
24
24
  params?: unknown[] | Record<string, unknown>;
25
25
  }
26
- declare type JsonRpcId = string | undefined;
26
+ type JsonRpcId = string | undefined;
27
27
  export interface JsonRpcRequest {
28
28
  id: JsonRpcId;
29
29
  jsonrpc: '2.0';
30
30
  method: string;
31
31
  params?: unknown[];
32
32
  }
33
- declare type JsonRpcSuccess = {
33
+ type JsonRpcSuccess = {
34
34
  id: JsonRpcId;
35
35
  jsonrpc: '2.0';
36
36
  result: unknown;
37
37
  };
38
- declare type JsonRpcFailure = {
38
+ type JsonRpcFailure = {
39
39
  id: JsonRpcId;
40
40
  jsonrpc: '2.0';
41
41
  error: Error;
42
42
  };
43
- export declare type JsonRpcResult = JsonRpcSuccess | JsonRpcFailure;
44
- export declare type JsonRpcCallback = (error: Error | null, result?: JsonRpcResult) => unknown;
45
- export declare type Deps = BaseProviderDeps & {
43
+ export type JsonRpcResult = JsonRpcSuccess | JsonRpcFailure;
44
+ export type JsonRpcCallback = (error: Error | null, result?: JsonRpcResult) => unknown;
45
+ export type Deps = BaseProviderDeps & {
46
46
  accountsObservable: Observable;
47
47
  storage: Storage;
48
48
  storageKeyPrefix?: string;
@@ -1,12 +1,17 @@
1
1
  import type { EthereumProvider } from '../provider/provider.js';
2
2
  import type { ManagementProvider, WalletProviderManager } from '@exodus/web3-management';
3
- export declare type EthereumProviderProxyDeps = {
3
+ type EthereumProviderWithFlags = EthereumProvider & {
4
+ isMetaMask: boolean;
5
+ isExodus: boolean;
6
+ isPhantom: boolean;
7
+ };
8
+ export type EthereumProviderProxyDeps = {
4
9
  isWalletNameFlag: string;
5
10
  impersonateOtherWallets?: boolean;
6
11
  getDefaultChainId: () => number;
7
12
  walletProviderManager: WalletProviderManager;
8
13
  getManagementProvider: () => Promise<ManagementProvider>;
9
- getEthereumProvider: () => Promise<EthereumProvider>;
14
+ getEthereumProvider: () => Promise<EthereumProviderWithFlags>;
10
15
  };
11
16
  /**
12
17
  * createEthereumProviderProxy creates a light weight proxy that
@@ -18,3 +23,4 @@ export declare type EthereumProviderProxyDeps = {
18
23
  * @returns
19
24
  */
20
25
  export declare const createEthereumProviderProxy: ({ isWalletNameFlag, impersonateOtherWallets, getDefaultChainId, walletProviderManager, getManagementProvider, getEthereumProvider, }: EthereumProviderProxyDeps) => import("@exodus/web3-provider").BaseProvider<string | symbol>;
26
+ export {};
@@ -103,17 +103,17 @@ export const createEthereumProviderProxy = ({ isWalletNameFlag, impersonateOther
103
103
  }
104
104
  if (property === '_metamask') {
105
105
  return {
106
- isUnlocked: async (...args) => {
106
+ isUnlocked: async () => {
107
107
  if (!provider._metamask) {
108
108
  await initProvider();
109
109
  }
110
- return provider._metamask.isUnlocked(...args);
110
+ return provider._metamask.isUnlocked();
111
111
  },
112
112
  requestBatch: async (...args) => {
113
113
  if (!provider._metamask) {
114
114
  await initProvider();
115
115
  }
116
- return provider._metamask.requestBatch(...args);
116
+ return provider._metamask.requestBatch([...args]);
117
117
  },
118
118
  };
119
119
  }
@@ -121,6 +121,8 @@ export const createEthereumProviderProxy = ({ isWalletNameFlag, impersonateOther
121
121
  const set = (target, prop, value) => {
122
122
  // Allow setting these specific properties as the ecosystem relies on that.
123
123
  if (['autoRefreshOnNetworkChange', 'removeListener'].includes(prop)) {
124
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
125
+ // @ts-ignore
124
126
  target[prop] = value;
125
127
  return true;
126
128
  }
@@ -1,7 +1,6 @@
1
1
  export { default as createEVMDepsFactory } from './createEVMDeps.js';
2
- import type { Dependencies, EthRequestArguments } from '../types.js';
2
+ import type { Dependencies } from '../types.js';
3
3
  import type { RPC, Transport } from '@exodus/web3-types';
4
- export declare function validateRequestWithEVMPrefix(request: EthRequestArguments): unknown;
5
4
  export declare const registerRPCHandlers: ({ deps, RPC, transport, }: {
6
5
  deps: Dependencies;
7
6
  RPC: RPC;
@@ -1,7 +1,7 @@
1
1
  import { RPC_REQUEST_TIMEOUT } from '@exodus/web3-constants';
2
2
  import { validate as validateDeps, validateCommonDeps, } from '@exodus/web3-rpc-handlers';
3
3
  import { exposeHandlers } from './exposeHandlers.js';
4
- import { validateRequest } from './validator.js';
4
+ import { validateRequestWithEVMPrefix } from './validateRequestWithEVMPrefix.js';
5
5
  export { default as createEVMDepsFactory } from './createEVMDeps.js';
6
6
  const validateEVMDeps = (evm) => {
7
7
  const requiredKeys = [
@@ -33,25 +33,6 @@ function validateEVMsDeps(evms) {
33
33
  }
34
34
  evms.forEach(validateEVMDeps);
35
35
  }
36
- export function validateRequestWithEVMPrefix(request) {
37
- if (typeof request !== 'object') {
38
- return validateRequest(request);
39
- }
40
- const originalMethod = request?.method;
41
- if (!originalMethod || typeof originalMethod !== 'string') {
42
- return validateRequest(request);
43
- }
44
- const underscorePosition = originalMethod.indexOf('_');
45
- if (underscorePosition === -1) {
46
- return validateRequest(request);
47
- }
48
- // 0x1_eth_getAccounts -> eth_getAccounts
49
- const methodWithoutPrefix = originalMethod.slice(underscorePosition + 1);
50
- // NOTE: validateRequest can deeply mutate the argument, e.g. removing additional properties.
51
- // We should always use the result of validateRequest() call, and never use the original argument again.
52
- const validated = validateRequest({ ...request, method: methodWithoutPrefix });
53
- return { ...validated, method: originalMethod };
54
- }
55
36
  export const registerRPCHandlers = ({ deps, RPC, transport, }) => {
56
37
  validateCommonDeps(deps, ['evms']);
57
38
  validateEVMsDeps(deps.evms);
@@ -0,0 +1,2 @@
1
+ import type { EthRequestArguments } from '../types.js';
2
+ export declare function validateRequestWithEVMPrefix(request: EthRequestArguments): unknown;
@@ -0,0 +1,20 @@
1
+ import { validateRequest } from './validator.js';
2
+ export function validateRequestWithEVMPrefix(request) {
3
+ if (typeof request !== 'object') {
4
+ return validateRequest(request);
5
+ }
6
+ const originalMethod = request?.method;
7
+ if (!originalMethod || typeof originalMethod !== 'string') {
8
+ return validateRequest(request);
9
+ }
10
+ const underscorePosition = originalMethod.indexOf('_');
11
+ if (underscorePosition === -1) {
12
+ return validateRequest(request);
13
+ }
14
+ // 0x1_eth_getAccounts -> eth_getAccounts
15
+ const methodWithoutPrefix = originalMethod.slice(underscorePosition + 1);
16
+ // NOTE: validateRequest can deeply mutate the argument, e.g. removing additional properties.
17
+ // We should always use the result of validateRequest() call, and never use the original argument again.
18
+ const validated = validateRequest({ ...request, method: methodWithoutPrefix });
19
+ return { ...validated, method: originalMethod };
20
+ }
package/lib/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
2
3
  import type { AddEthereumChainParameter, EthereumProvider } from './provider/index.js';
3
4
  import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams, EthTransaction, EthTransactionHash, EthWalletWatchAsset } from '@exodus/web3-ethereum-utils';
4
5
  import type { EthTransactionParams } from '@exodus/web3-ethereum-utils';
@@ -24,7 +25,7 @@ export interface CreateEvmDepsFactoryParams {
24
25
  blockchainMetadata: IBlockchainMetadataModule;
25
26
  simulateTransactionConfig?: CreateSimulationServiceParams;
26
27
  }
27
- declare type SimulateTransactionsFn = (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
28
+ type SimulateTransactionsFn = (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
28
29
  export interface CreateEvmDepsParams {
29
30
  addEthereumChain?: (param: AddEthereumChainParameter) => Promise<null>;
30
31
  assetName: string;
@@ -42,9 +43,9 @@ export interface CreateEvmDepsParams {
42
43
  messageSigner: EVMMessageSigner;
43
44
  onEthWalletWatchAssetRequest?: (param: EthWalletWatchAsset) => Promise<boolean>;
44
45
  }
45
- export declare type EVMFactory = (params: CreateEvmDepsParams) => EVMDeps;
46
- export declare type EVMTransactionSignerModule = ITransactionSignerModule<EVMUnsignedTransaction>;
47
- export declare type EVMDeps = {
46
+ export type EVMFactory = (params: CreateEvmDepsParams) => EVMDeps;
47
+ export type EVMTransactionSignerModule = ITransactionSignerModule<EVMUnsignedTransaction>;
48
+ export type EVMDeps = {
48
49
  chainId: string;
49
50
  getSupportedChainIds?: () => Promise<string[]>;
50
51
  getAddress: () => Promise<string>;
@@ -61,7 +62,7 @@ export declare type EVMDeps = {
61
62
  getActiveWalletAccountData: GetActiveWalletAccountData;
62
63
  addEthereumChain?: (param: AddEthereumChainParameter) => Promise<null>;
63
64
  };
64
- export declare type Dependencies = {
65
+ export type Dependencies = {
65
66
  evms: EVMDeps[];
66
67
  } & CommonDeps;
67
68
  export interface WalletStandardDeps extends WalletStandardCommonDeps {
@@ -77,5 +78,5 @@ export interface EVMMesage {
77
78
  rawMessage?: Buffer;
78
79
  EIP712Message?: TypedDataV1 | TypedMessage<MessageTypes>;
79
80
  }
80
- export declare type EVMMessageSigner = IMessageSignerModule<EVMMesage>;
81
+ export type EVMMessageSigner = IMessageSignerModule<EVMMesage>;
81
82
  export {};
@@ -2,7 +2,7 @@ import { StandardWallet } from '@exodus/web3-provider';
2
2
  import type { EthereumProvider } from '../provider/provider.js';
3
3
  import type { WalletStandardDeps } from '../types.js';
4
4
  import type { Wallet } from '@wallet-standard/base';
5
- export declare type EthereumProviderFeature = {
5
+ export type EthereumProviderFeature = {
6
6
  'eip1193:provider': {
7
7
  provider: EthereumProvider;
8
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exodus/web3-ethereum",
3
3
  "description": "Apps connectivity library for EVM-compatible chains.",
4
- "version": "13.1.1",
4
+ "version": "13.2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -22,19 +22,26 @@
22
22
  "lib/**/*.js"
23
23
  ],
24
24
  "publishConfig": {
25
- "access": "restricted"
25
+ "access": "public"
26
26
  },
27
- "repository": "https://github.com/ExodusMovement/exodus-web3/tree/master/packages/ethereum",
28
- "license": "UNLICENSED",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/ExodusMovement/assets.git"
30
+ },
31
+ "license": "MIT",
29
32
  "scripts": {
30
33
  "clean": "run -T rimraf lib",
31
34
  "build": "yarn clean && run -T tsc && yarn build:schemas",
32
- "build:schemas": "node ../../scripts/build-schemas/index.mjs"
35
+ "build:schemas": "node ../scripts/build-schemas/index.mjs",
36
+ "lint": "run -T eslintc .",
37
+ "lint:fix": "yarn lint --fix",
38
+ "prepublishOnly": "yarn run -T build --scope @exodus/web3-ethereum",
39
+ "test": "run -T exodus-test --jest --esbuild"
33
40
  },
34
41
  "dependencies": {
35
- "@exodus/ethereum-api": "^8.1.5",
42
+ "@exodus/ethereum-api": "^8.31.0",
36
43
  "@exodus/web3-constants": "^1.30.0",
37
- "@exodus/web3-ethereum-utils": "^3.38.0",
44
+ "@exodus/web3-ethereum-utils": "^4.2.1",
38
45
  "@exodus/web3-provider": "^3.15.0",
39
46
  "@exodus/web3-rpc-handlers": "^2.25.0",
40
47
  "@exodus/web3-utils": "^1.48.2",
@@ -42,13 +49,19 @@
42
49
  "eth-rpc-errors": "^4.0.3"
43
50
  },
44
51
  "devDependencies": {
45
- "@exodus/assets": "^8.0.95",
52
+ "@exodus/assets": "^11.1.5",
53
+ "@exodus/ethereum-meta": "^2.2.1",
46
54
  "@exodus/json-rpc": "^1.11.0",
47
55
  "@exodus/schemasafe": "^1.0.0",
48
- "@exodus/web3-management": "0.35.1",
49
- "@exodus/web3-types": "1.52.0",
56
+ "@exodus/web3-management": "0.36.1",
57
+ "@exodus/web3-types": "1.53.2",
50
58
  "@exodus/web3-validation": "^1.38.0",
51
59
  "@wallet-standard/base": "^1.0.1"
52
60
  },
53
- "gitHead": "212dd8249e074525316708335355fda305aa691f"
61
+ "author": "Exodus Movement, Inc.",
62
+ "bugs": {
63
+ "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Aweb3-ethereum"
64
+ },
65
+ "homepage": "https://github.com/ExodusMovement/assets/tree/master/web3/web3-ethereum",
66
+ "gitHead": "7b31fb95b16ce5e7eb7e2e20325368da0b94d8c8"
54
67
  }