@exodus/web3-ethereum 2.7.0 → 2.8.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.
|
@@ -9,7 +9,7 @@ interface EthereumProviderEvents {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class EthereumProvider extends BaseProvider<EthereumProviderEvents> {
|
|
11
11
|
#private;
|
|
12
|
-
constructor({ accountsObservable, storage, supportedChainIds, transport, getDefaultChainId, }: Deps);
|
|
12
|
+
constructor({ accountsObservable, storage, supportedChainIds, transport, getDefaultChainId, walletProviderManager, }: Deps);
|
|
13
13
|
protected _callRpcMethod<Params, Response>(method: string, params: Params): Promise<Response>;
|
|
14
14
|
isConnected(): boolean;
|
|
15
15
|
request: (args: RequestArguments) => Promise<unknown>;
|
package/lib/provider/provider.js
CHANGED
|
@@ -5,18 +5,20 @@ export class EthereumProvider extends BaseProvider {
|
|
|
5
5
|
#storage;
|
|
6
6
|
#supportedChainIds = [];
|
|
7
7
|
#getDefaultChainId;
|
|
8
|
+
#walletProviderManager;
|
|
8
9
|
#initializePromise = null;
|
|
9
10
|
#initialized = false;
|
|
10
11
|
#isConnected = false;
|
|
11
12
|
#chainId = null;
|
|
12
13
|
#accounts = [];
|
|
13
14
|
#selectedAddress = null;
|
|
14
|
-
constructor({ accountsObservable, storage, supportedChainIds, transport, getDefaultChainId, }) {
|
|
15
|
+
constructor({ accountsObservable, storage, supportedChainIds, transport, getDefaultChainId, walletProviderManager, }) {
|
|
15
16
|
if (!supportedChainIds?.length) {
|
|
16
17
|
throw new Error('At least one supported chain must be provided');
|
|
17
18
|
}
|
|
18
19
|
super({ transport });
|
|
19
20
|
this.#storage = createStorageWrapper(storage);
|
|
21
|
+
this.#walletProviderManager = walletProviderManager;
|
|
20
22
|
this.#supportedChainIds = supportedChainIds
|
|
21
23
|
.map((chainId) => chainId.toLowerCase())
|
|
22
24
|
.sort();
|
|
@@ -105,7 +107,12 @@ export class EthereumProvider extends BaseProvider {
|
|
|
105
107
|
};
|
|
106
108
|
#requestAccounts = async () => {
|
|
107
109
|
const permissions = { eth_accounts: {} };
|
|
108
|
-
|
|
110
|
+
const availableWallets = [];
|
|
111
|
+
this.#walletProviderManager.getWalletProviders().forEach(({ name }) => {
|
|
112
|
+
availableWallets.push(name);
|
|
113
|
+
});
|
|
114
|
+
const { selectedWallet } = await this._callRpcMethod('wallet_requestPermissions', [permissions, availableWallets]);
|
|
115
|
+
this.#walletProviderManager.setDefaultWalletProvider(selectedWallet);
|
|
109
116
|
const accounts = await this._callRpcMethod('eth_accounts', []);
|
|
110
117
|
this.#handleAccountsChanged(accounts);
|
|
111
118
|
if (!(await this.#storage.getChainId())) {
|
package/lib/provider/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Deps as BaseProviderDeps } from '@exodus/web3-provider';
|
|
2
|
-
import type { Observable, Storage } from '@exodus/web3-types';
|
|
2
|
+
import type { Observable, Storage, WalletProviderManager } from '@exodus/web3-types';
|
|
3
3
|
export declare type ChainId = string;
|
|
4
4
|
export interface ProviderConnectInfo {
|
|
5
5
|
chainId: ChainId;
|
|
@@ -35,10 +35,11 @@ export declare type Deps = BaseProviderDeps & {
|
|
|
35
35
|
storage: Storage;
|
|
36
36
|
supportedChainIds: string[];
|
|
37
37
|
getDefaultChainId?: () => Promise<string | null>;
|
|
38
|
+
walletProviderManager: WalletProviderManager;
|
|
38
39
|
};
|
|
39
40
|
export interface ProviderStorage {
|
|
40
41
|
getChainId: () => Promise<ChainId | null>;
|
|
41
42
|
setChainId: (chainId: ChainId) => Promise<void>;
|
|
42
43
|
clearChainId: () => Promise<void>;
|
|
43
44
|
}
|
|
44
|
-
export {};
|
|
45
|
+
export { WalletProviderManager };
|
|
@@ -186,8 +186,9 @@ export function exposeHandlers(rpc, deps) {
|
|
|
186
186
|
}
|
|
187
187
|
return permissions;
|
|
188
188
|
});
|
|
189
|
-
exposeEvmFunction('wallet_requestPermissions', async (requestedPermissions) => {
|
|
189
|
+
exposeEvmFunction('wallet_requestPermissions', async (requestedPermissions, availableWallets) => {
|
|
190
190
|
const parentCapability = Object.keys(requestedPermissions)[0];
|
|
191
|
+
let selectedWallet = null;
|
|
191
192
|
if (parentCapability !== ETH_ACCOUNTS_PERMISSION) {
|
|
192
193
|
// `eth_accounts` is currently the only permission.
|
|
193
194
|
// See: https://docs.metamask.io/guide/rpc-api.html#restricted-methods.
|
|
@@ -199,13 +200,19 @@ export function exposeHandlers(rpc, deps) {
|
|
|
199
200
|
}
|
|
200
201
|
const trusted = await isTrusted();
|
|
201
202
|
if (!trusted) {
|
|
202
|
-
const
|
|
203
|
-
if (!approved) {
|
|
203
|
+
const response = (await approveConnection(network, availableWallets));
|
|
204
|
+
if (!response.approved) {
|
|
204
205
|
throw new UserRejectedRequestError();
|
|
205
206
|
}
|
|
206
|
-
|
|
207
|
+
selectedWallet = response.selectedWallet;
|
|
208
|
+
if (response.selectedWallet === 'exodus') {
|
|
209
|
+
await ensureTrusted();
|
|
210
|
+
}
|
|
207
211
|
}
|
|
208
|
-
return
|
|
212
|
+
return {
|
|
213
|
+
walletPermissions: [{ parentCapability: ETH_ACCOUNTS_PERMISSION }],
|
|
214
|
+
selectedWallet,
|
|
215
|
+
};
|
|
209
216
|
});
|
|
210
217
|
exposeEvmFunction('wallet_watchAsset', async (assetDetails) => {
|
|
211
218
|
await assertTrusted();
|
|
@@ -913,6 +913,12 @@ export function validateRequest(value) {
|
|
|
913
913
|
validate.errors = [{ keywordLocation: '#/type', instanceLocation: '#' }]
|
|
914
914
|
return false
|
|
915
915
|
}
|
|
916
|
+
if (data.length > 2) {
|
|
917
|
+
validate.errors = [
|
|
918
|
+
{ keywordLocation: '#/maxItems', instanceLocation: '#' },
|
|
919
|
+
]
|
|
920
|
+
return false
|
|
921
|
+
}
|
|
916
922
|
if (data.length < 1) {
|
|
917
923
|
validate.errors = [
|
|
918
924
|
{ keywordLocation: '#/minItems', instanceLocation: '#' },
|
|
@@ -929,7 +935,46 @@ export function validateRequest(value) {
|
|
|
929
935
|
return false
|
|
930
936
|
}
|
|
931
937
|
}
|
|
932
|
-
if (data
|
|
938
|
+
if (1 in data && hasOwn(data, 1)) {
|
|
939
|
+
if (!Array.isArray(data[1])) {
|
|
940
|
+
validate.errors = [
|
|
941
|
+
{ keywordLocation: '#/1/type', instanceLocation: '#/1' },
|
|
942
|
+
]
|
|
943
|
+
return false
|
|
944
|
+
}
|
|
945
|
+
for (let l = 0; l < data[1].length; l++) {
|
|
946
|
+
if (l in data[1] && hasOwn(data[1], l)) {
|
|
947
|
+
if (!(typeof data[1][l] === 'string')) {
|
|
948
|
+
validate.errors = [
|
|
949
|
+
{
|
|
950
|
+
keywordLocation: '#/1/items/type',
|
|
951
|
+
instanceLocation: '#/1/' + l,
|
|
952
|
+
},
|
|
953
|
+
]
|
|
954
|
+
return false
|
|
955
|
+
}
|
|
956
|
+
if (data[1][l].length > 20 && stringLength(data[1][l]) > 20) {
|
|
957
|
+
validate.errors = [
|
|
958
|
+
{
|
|
959
|
+
keywordLocation: '#/1/items/maxLength',
|
|
960
|
+
instanceLocation: '#/1/' + l,
|
|
961
|
+
},
|
|
962
|
+
]
|
|
963
|
+
return false
|
|
964
|
+
}
|
|
965
|
+
if (!format3.test(data[1][l])) {
|
|
966
|
+
validate.errors = [
|
|
967
|
+
{
|
|
968
|
+
keywordLocation: '#/1/items/format',
|
|
969
|
+
instanceLocation: '#/1/' + l,
|
|
970
|
+
},
|
|
971
|
+
]
|
|
972
|
+
return false
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (data.length > 2) {
|
|
933
978
|
validate.errors = [
|
|
934
979
|
{ keywordLocation: '#/items', instanceLocation: '#' },
|
|
935
980
|
]
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { EthTransaction, EthTransactionHash, EthWalletWatchAsset } from '@exodus/web3-ethereum-utils';
|
|
3
3
|
import type { CommonDeps } from '@exodus/web3-rpc-handlers';
|
|
4
|
-
import type { IAnalyticsModule, IActiveWalletAccountAtom, IAssetsModule, IBlockchainMetadataModule, IFeeDataModule, IWalletModule, IWalletAccountsModule } from '@exodus/web3-types';
|
|
4
|
+
import type { IAnalyticsModule, IActiveWalletAccountAtom, IAssetsModule, IBlockchainMetadataModule, IFeeDataModule, IWalletModule, IWalletAccountsModule, ApproveConnectionResponse } from '@exodus/web3-types';
|
|
5
5
|
/**
|
|
6
6
|
* EVM-compatible chains.
|
|
7
7
|
*/
|
|
@@ -38,3 +38,4 @@ export declare type EVMDeps = {
|
|
|
38
38
|
export declare type Dependencies = {
|
|
39
39
|
evms: EVMDeps[];
|
|
40
40
|
} & CommonDeps;
|
|
41
|
+
export { ApproveConnectionResponse };
|
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": "2.
|
|
4
|
+
"version": "2.8.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@exodus/currency": "^2.1.2",
|
|
35
35
|
"@exodus/ethereum-api": "^6.0.0",
|
|
36
|
-
"@exodus/web3-constants": "^1.
|
|
37
|
-
"@exodus/web3-ethereum-utils": "^1.
|
|
38
|
-
"@exodus/web3-provider": "^2.
|
|
39
|
-
"@exodus/web3-rpc-handlers": "^0.
|
|
36
|
+
"@exodus/web3-constants": "^1.21.0",
|
|
37
|
+
"@exodus/web3-ethereum-utils": "^1.11.0",
|
|
38
|
+
"@exodus/web3-provider": "^2.19.0",
|
|
39
|
+
"@exodus/web3-rpc-handlers": "^0.16.0",
|
|
40
40
|
"bn.js": "^5.2.0",
|
|
41
41
|
"eth-rpc-errors": "^4.0.3"
|
|
42
42
|
},
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"@exodus/assets": "^8.0.72",
|
|
45
45
|
"@exodus/json-rpc": "^1.11.0",
|
|
46
46
|
"@exodus/schemasafe": "^1.0.0",
|
|
47
|
-
"@exodus/web3-types": "^1.
|
|
47
|
+
"@exodus/web3-types": "^1.17.0",
|
|
48
48
|
"@exodus/web3-validation": "^1.34.0",
|
|
49
49
|
"@wallet-standard/base": "^1.0.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@exodus/assets": "^8.0.72"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a9cd4485d1f90608ba4e38dd0d9bd237768d6009"
|
|
55
55
|
}
|