@exodus/web3-ethereum 12.13.0 → 12.14.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/lib/provider/provider.js
CHANGED
|
@@ -119,11 +119,15 @@ export class EthereumProvider extends BaseProvider {
|
|
|
119
119
|
this.#handleAccountsChanged(accounts);
|
|
120
120
|
return accounts;
|
|
121
121
|
};
|
|
122
|
-
#addChain = async (
|
|
123
|
-
//
|
|
124
|
-
// If the requested chain is supported, the provider will switch to that chain.
|
|
122
|
+
#addChain = async (params) => {
|
|
123
|
+
// If the requested chain is supported, the provider will switch to that chain
|
|
125
124
|
// This matches MetaMask's behavior.
|
|
126
125
|
// See: https://github.com/MetaMask/metamask-extension/blob/d92936475a942fed060bb36f810ee6bfd901f4f4/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js#L167-L183.
|
|
126
|
+
// if not supported yet, add it
|
|
127
|
+
const chainId = this.#sanitizeChainId(params.chainId);
|
|
128
|
+
if (!this.#supportedChainIds.includes(chainId)) {
|
|
129
|
+
await this._callRpcMethod('wallet_addEthereumChain', [params]);
|
|
130
|
+
}
|
|
127
131
|
return this.#switchChain(chainId);
|
|
128
132
|
};
|
|
129
133
|
#switchChain = async (chainId) => {
|
|
@@ -138,6 +142,7 @@ export class EthereumProvider extends BaseProvider {
|
|
|
138
142
|
if (!didSwitch) {
|
|
139
143
|
throw err;
|
|
140
144
|
}
|
|
145
|
+
this.#supportedChainIds.push(chainId);
|
|
141
146
|
}
|
|
142
147
|
this.#handleChainChanged(chainId);
|
|
143
148
|
await this.#storage.setChainId(chainId);
|
|
@@ -180,8 +185,7 @@ export class EthereumProvider extends BaseProvider {
|
|
|
180
185
|
// EIP-3085
|
|
181
186
|
// See: https://eips.ethereum.org/EIPS/eip-3085.
|
|
182
187
|
if (method === 'wallet_addEthereumChain') {
|
|
183
|
-
|
|
184
|
-
return this.#addChain(this.#sanitizeChainId(chainId));
|
|
188
|
+
return this.#addChain(params[0]);
|
|
185
189
|
}
|
|
186
190
|
// EIP-3326.
|
|
187
191
|
// See: https://eips.ethereum.org/EIPS/eip-3326.
|
package/lib/provider/types.d.ts
CHANGED
|
@@ -7,6 +7,18 @@ export interface ProviderConnectInfo {
|
|
|
7
7
|
export interface ChainParameter {
|
|
8
8
|
chainId: ChainId;
|
|
9
9
|
}
|
|
10
|
+
export interface AddEthereumChainParameter {
|
|
11
|
+
chainId: ChainId;
|
|
12
|
+
chainName: string;
|
|
13
|
+
rpcUrls: string[];
|
|
14
|
+
iconUrls?: string[];
|
|
15
|
+
nativeCurrency: {
|
|
16
|
+
name?: string;
|
|
17
|
+
symbol: string;
|
|
18
|
+
decimals: number;
|
|
19
|
+
};
|
|
20
|
+
blockExplorerUrls?: string[];
|
|
21
|
+
}
|
|
10
22
|
export interface RequestArguments {
|
|
11
23
|
method: string;
|
|
12
24
|
params?: unknown[] | Record<string, unknown>;
|
|
@@ -63,7 +63,7 @@ const isValidGasLimitValue = (value) => {
|
|
|
63
63
|
return proposedGasLimit.lte(maximumBlockGasLimit);
|
|
64
64
|
};
|
|
65
65
|
export function exposeHandlers(rpc, deps) {
|
|
66
|
-
const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getSupportedChainIds = async () => [], getAddress, getEstimatedGas, getCustomFeeData, getFeeData, getNonce, sendRawTransaction, simulateEthereumTransactions, scanDomains, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = async () => true, getAsset, getOrigin, getPathname, getActiveWalletAccountData, transactionSigner, messageSigner, } = deps;
|
|
66
|
+
const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getSupportedChainIds = async () => [], getAddress, getEstimatedGas, getCustomFeeData, getFeeData, getNonce, sendRawTransaction, simulateEthereumTransactions, scanDomains, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = async () => true, getAsset, addEthereumChain, getOrigin, getPathname, getActiveWalletAccountData, transactionSigner, messageSigner, } = deps;
|
|
67
67
|
const network = `evm:${chainId}`;
|
|
68
68
|
async function assertTrusted() {
|
|
69
69
|
const trusted = await isTrusted();
|
|
@@ -277,6 +277,14 @@ export function exposeHandlers(rpc, deps) {
|
|
|
277
277
|
const supportedChainIds = await getSupportedChainIds();
|
|
278
278
|
return supportedChainIds.includes(chainId);
|
|
279
279
|
});
|
|
280
|
+
exposeEvmFunction('wallet_addEthereumChain', async (param) => {
|
|
281
|
+
await assertTrusted();
|
|
282
|
+
if (!addEthereumChain) {
|
|
283
|
+
// provide the right codes https://docs.metamask.io/wallet/reference/wallet_addethereumchain/
|
|
284
|
+
throw new UnsupportedMethodError();
|
|
285
|
+
}
|
|
286
|
+
return addEthereumChain(param);
|
|
287
|
+
});
|
|
280
288
|
exposeEvmFunction('wallet_watchAsset', async (param) => {
|
|
281
289
|
await assertTrusted();
|
|
282
290
|
const assetAdded = await onEthWalletWatchAssetRequest(param);
|
|
@@ -18,7 +18,11 @@ const validateEVMDeps = (evm) => {
|
|
|
18
18
|
'transactionSigner',
|
|
19
19
|
'messageSigner',
|
|
20
20
|
];
|
|
21
|
-
const optionalKeys = [
|
|
21
|
+
const optionalKeys = [
|
|
22
|
+
'getSupportedChainIds',
|
|
23
|
+
'onEthWalletWatchAssetRequest',
|
|
24
|
+
'addEthereumChain',
|
|
25
|
+
];
|
|
22
26
|
validateDeps(evm, requiredKeys, optionalKeys);
|
|
23
27
|
};
|
|
24
28
|
function validateEVMsDeps(evms) {
|
|
@@ -1009,9 +1009,432 @@ export function validateRequest(value) {
|
|
|
1009
1009
|
"^[a-z][a-z0-9+\\-.]*:(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\\/?(?:(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?)(?:\\?(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$",
|
|
1010
1010
|
'i',
|
|
1011
1011
|
)
|
|
1012
|
+
const ref15 = function validate(data) {
|
|
1013
|
+
validate.errors = null
|
|
1014
|
+
if (!Array.isArray(data)) {
|
|
1015
|
+
validate.errors = [{ keywordLocation: '#/type', instanceLocation: '#' }]
|
|
1016
|
+
return false
|
|
1017
|
+
}
|
|
1018
|
+
if (data.length < 1) {
|
|
1019
|
+
validate.errors = [
|
|
1020
|
+
{ keywordLocation: '#/minItems', instanceLocation: '#' },
|
|
1021
|
+
]
|
|
1022
|
+
return false
|
|
1023
|
+
}
|
|
1024
|
+
if (0 in data && hasOwn(data, 0)) {
|
|
1025
|
+
if (
|
|
1026
|
+
!(typeof data[0] === 'object' && data[0] && !Array.isArray(data[0]))
|
|
1027
|
+
) {
|
|
1028
|
+
validate.errors = [
|
|
1029
|
+
{ keywordLocation: '#/0/type', instanceLocation: '#/0' },
|
|
1030
|
+
]
|
|
1031
|
+
return false
|
|
1032
|
+
}
|
|
1033
|
+
if (!('chainId' in data[0] && hasOwn(data[0], 'chainId'))) {
|
|
1034
|
+
validate.errors = [
|
|
1035
|
+
{
|
|
1036
|
+
keywordLocation: '#/0/required',
|
|
1037
|
+
instanceLocation: '#/0/chainId',
|
|
1038
|
+
},
|
|
1039
|
+
]
|
|
1040
|
+
return false
|
|
1041
|
+
}
|
|
1042
|
+
if (!('chainName' in data[0] && hasOwn(data[0], 'chainName'))) {
|
|
1043
|
+
validate.errors = [
|
|
1044
|
+
{
|
|
1045
|
+
keywordLocation: '#/0/required',
|
|
1046
|
+
instanceLocation: '#/0/chainName',
|
|
1047
|
+
},
|
|
1048
|
+
]
|
|
1049
|
+
return false
|
|
1050
|
+
}
|
|
1051
|
+
if (!(typeof data[0].chainId === 'string')) {
|
|
1052
|
+
validate.errors = [
|
|
1053
|
+
{
|
|
1054
|
+
keywordLocation: '#/0/properties/chainId/type',
|
|
1055
|
+
instanceLocation: '#/0/chainId',
|
|
1056
|
+
},
|
|
1057
|
+
]
|
|
1058
|
+
return false
|
|
1059
|
+
}
|
|
1060
|
+
if (!format4.test(data[0].chainId)) {
|
|
1061
|
+
validate.errors = [
|
|
1062
|
+
{
|
|
1063
|
+
keywordLocation: '#/0/properties/chainId/format',
|
|
1064
|
+
instanceLocation: '#/0/chainId',
|
|
1065
|
+
},
|
|
1066
|
+
]
|
|
1067
|
+
return false
|
|
1068
|
+
}
|
|
1069
|
+
if (!(typeof data[0].chainName === 'string')) {
|
|
1070
|
+
validate.errors = [
|
|
1071
|
+
{
|
|
1072
|
+
keywordLocation: '#/0/properties/chainName/type',
|
|
1073
|
+
instanceLocation: '#/0/chainName',
|
|
1074
|
+
},
|
|
1075
|
+
]
|
|
1076
|
+
return false
|
|
1077
|
+
}
|
|
1078
|
+
if (
|
|
1079
|
+
data[0].chainName.length > 50 &&
|
|
1080
|
+
stringLength(data[0].chainName) > 50
|
|
1081
|
+
) {
|
|
1082
|
+
validate.errors = [
|
|
1083
|
+
{
|
|
1084
|
+
keywordLocation: '#/0/properties/chainName/maxLength',
|
|
1085
|
+
instanceLocation: '#/0/chainName',
|
|
1086
|
+
},
|
|
1087
|
+
]
|
|
1088
|
+
return false
|
|
1089
|
+
}
|
|
1090
|
+
if (!format5.test(data[0].chainName)) {
|
|
1091
|
+
validate.errors = [
|
|
1092
|
+
{
|
|
1093
|
+
keywordLocation: '#/0/properties/chainName/format',
|
|
1094
|
+
instanceLocation: '#/0/chainName',
|
|
1095
|
+
},
|
|
1096
|
+
]
|
|
1097
|
+
return false
|
|
1098
|
+
}
|
|
1099
|
+
if (
|
|
1100
|
+
'blockExplorerUrls' in data[0] &&
|
|
1101
|
+
hasOwn(data[0], 'blockExplorerUrls')
|
|
1102
|
+
) {
|
|
1103
|
+
if (!Array.isArray(data[0].blockExplorerUrls)) {
|
|
1104
|
+
validate.errors = [
|
|
1105
|
+
{
|
|
1106
|
+
keywordLocation: '#/0/properties/blockExplorerUrls/type',
|
|
1107
|
+
instanceLocation: '#/0/blockExplorerUrls',
|
|
1108
|
+
},
|
|
1109
|
+
]
|
|
1110
|
+
return false
|
|
1111
|
+
}
|
|
1112
|
+
if (data[0].blockExplorerUrls.length < 1) {
|
|
1113
|
+
validate.errors = [
|
|
1114
|
+
{
|
|
1115
|
+
keywordLocation: '#/0/properties/blockExplorerUrls/minItems',
|
|
1116
|
+
instanceLocation: '#/0/blockExplorerUrls',
|
|
1117
|
+
},
|
|
1118
|
+
]
|
|
1119
|
+
return false
|
|
1120
|
+
}
|
|
1121
|
+
for (let l = 0; l < data[0].blockExplorerUrls.length; l++) {
|
|
1122
|
+
if (
|
|
1123
|
+
l in data[0].blockExplorerUrls &&
|
|
1124
|
+
hasOwn(data[0].blockExplorerUrls, l)
|
|
1125
|
+
) {
|
|
1126
|
+
if (!(typeof data[0].blockExplorerUrls[l] === 'string')) {
|
|
1127
|
+
validate.errors = [
|
|
1128
|
+
{
|
|
1129
|
+
keywordLocation:
|
|
1130
|
+
'#/0/properties/blockExplorerUrls/items/type',
|
|
1131
|
+
instanceLocation: '#/blockExplorerUrls/' + l,
|
|
1132
|
+
},
|
|
1133
|
+
]
|
|
1134
|
+
return false
|
|
1135
|
+
}
|
|
1136
|
+
if (
|
|
1137
|
+
data[0].blockExplorerUrls[l].length > 100 &&
|
|
1138
|
+
stringLength(data[0].blockExplorerUrls[l]) > 100
|
|
1139
|
+
) {
|
|
1140
|
+
validate.errors = [
|
|
1141
|
+
{
|
|
1142
|
+
keywordLocation:
|
|
1143
|
+
'#/0/properties/blockExplorerUrls/items/maxLength',
|
|
1144
|
+
instanceLocation: '#/blockExplorerUrls/' + l,
|
|
1145
|
+
},
|
|
1146
|
+
]
|
|
1147
|
+
return false
|
|
1148
|
+
}
|
|
1149
|
+
if (!format6.test(data[0].blockExplorerUrls[l])) {
|
|
1150
|
+
validate.errors = [
|
|
1151
|
+
{
|
|
1152
|
+
keywordLocation:
|
|
1153
|
+
'#/0/properties/blockExplorerUrls/items/format',
|
|
1154
|
+
instanceLocation: '#/blockExplorerUrls/' + l,
|
|
1155
|
+
},
|
|
1156
|
+
]
|
|
1157
|
+
return false
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
if ('iconUrls' in data[0] && hasOwn(data[0], 'iconUrls')) {
|
|
1163
|
+
if (!Array.isArray(data[0].iconUrls)) {
|
|
1164
|
+
validate.errors = [
|
|
1165
|
+
{
|
|
1166
|
+
keywordLocation: '#/0/properties/iconUrls/type',
|
|
1167
|
+
instanceLocation: '#/0/iconUrls',
|
|
1168
|
+
},
|
|
1169
|
+
]
|
|
1170
|
+
return false
|
|
1171
|
+
}
|
|
1172
|
+
if (data[0].iconUrls.length < 0) {
|
|
1173
|
+
validate.errors = [
|
|
1174
|
+
{
|
|
1175
|
+
keywordLocation: '#/0/properties/iconUrls/minItems',
|
|
1176
|
+
instanceLocation: '#/0/iconUrls',
|
|
1177
|
+
},
|
|
1178
|
+
]
|
|
1179
|
+
return false
|
|
1180
|
+
}
|
|
1181
|
+
for (let m = 0; m < data[0].iconUrls.length; m++) {
|
|
1182
|
+
if (m in data[0].iconUrls && hasOwn(data[0].iconUrls, m)) {
|
|
1183
|
+
if (!(typeof data[0].iconUrls[m] === 'string')) {
|
|
1184
|
+
validate.errors = [
|
|
1185
|
+
{
|
|
1186
|
+
keywordLocation: '#/0/properties/iconUrls/items/type',
|
|
1187
|
+
instanceLocation: '#/iconUrls/' + m,
|
|
1188
|
+
},
|
|
1189
|
+
]
|
|
1190
|
+
return false
|
|
1191
|
+
}
|
|
1192
|
+
if (
|
|
1193
|
+
data[0].iconUrls[m].length > 100 &&
|
|
1194
|
+
stringLength(data[0].iconUrls[m]) > 100
|
|
1195
|
+
) {
|
|
1196
|
+
validate.errors = [
|
|
1197
|
+
{
|
|
1198
|
+
keywordLocation: '#/0/properties/iconUrls/items/maxLength',
|
|
1199
|
+
instanceLocation: '#/iconUrls/' + m,
|
|
1200
|
+
},
|
|
1201
|
+
]
|
|
1202
|
+
return false
|
|
1203
|
+
}
|
|
1204
|
+
if (!format6.test(data[0].iconUrls[m])) {
|
|
1205
|
+
validate.errors = [
|
|
1206
|
+
{
|
|
1207
|
+
keywordLocation: '#/0/properties/iconUrls/items/format',
|
|
1208
|
+
instanceLocation: '#/iconUrls/' + m,
|
|
1209
|
+
},
|
|
1210
|
+
]
|
|
1211
|
+
return false
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
if ('rpcUrls' in data[0] && hasOwn(data[0], 'rpcUrls')) {
|
|
1217
|
+
if (!Array.isArray(data[0].rpcUrls)) {
|
|
1218
|
+
validate.errors = [
|
|
1219
|
+
{
|
|
1220
|
+
keywordLocation: '#/0/properties/rpcUrls/type',
|
|
1221
|
+
instanceLocation: '#/0/rpcUrls',
|
|
1222
|
+
},
|
|
1223
|
+
]
|
|
1224
|
+
return false
|
|
1225
|
+
}
|
|
1226
|
+
if (data[0].rpcUrls.length < 1) {
|
|
1227
|
+
validate.errors = [
|
|
1228
|
+
{
|
|
1229
|
+
keywordLocation: '#/0/properties/rpcUrls/minItems',
|
|
1230
|
+
instanceLocation: '#/0/rpcUrls',
|
|
1231
|
+
},
|
|
1232
|
+
]
|
|
1233
|
+
return false
|
|
1234
|
+
}
|
|
1235
|
+
for (let n = 0; n < data[0].rpcUrls.length; n++) {
|
|
1236
|
+
if (n in data[0].rpcUrls && hasOwn(data[0].rpcUrls, n)) {
|
|
1237
|
+
if (!(typeof data[0].rpcUrls[n] === 'string')) {
|
|
1238
|
+
validate.errors = [
|
|
1239
|
+
{
|
|
1240
|
+
keywordLocation: '#/0/properties/rpcUrls/items/type',
|
|
1241
|
+
instanceLocation: '#/rpcUrls/' + n,
|
|
1242
|
+
},
|
|
1243
|
+
]
|
|
1244
|
+
return false
|
|
1245
|
+
}
|
|
1246
|
+
if (
|
|
1247
|
+
data[0].rpcUrls[n].length > 100 &&
|
|
1248
|
+
stringLength(data[0].rpcUrls[n]) > 100
|
|
1249
|
+
) {
|
|
1250
|
+
validate.errors = [
|
|
1251
|
+
{
|
|
1252
|
+
keywordLocation: '#/0/properties/rpcUrls/items/maxLength',
|
|
1253
|
+
instanceLocation: '#/rpcUrls/' + n,
|
|
1254
|
+
},
|
|
1255
|
+
]
|
|
1256
|
+
return false
|
|
1257
|
+
}
|
|
1258
|
+
if (!format6.test(data[0].rpcUrls[n])) {
|
|
1259
|
+
validate.errors = [
|
|
1260
|
+
{
|
|
1261
|
+
keywordLocation: '#/0/properties/rpcUrls/items/format',
|
|
1262
|
+
instanceLocation: '#/rpcUrls/' + n,
|
|
1263
|
+
},
|
|
1264
|
+
]
|
|
1265
|
+
return false
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
if ('nativeCurrency' in data[0] && hasOwn(data[0], 'nativeCurrency')) {
|
|
1271
|
+
if (
|
|
1272
|
+
!(
|
|
1273
|
+
typeof data[0].nativeCurrency === 'object' &&
|
|
1274
|
+
data[0].nativeCurrency &&
|
|
1275
|
+
!Array.isArray(data[0].nativeCurrency)
|
|
1276
|
+
)
|
|
1277
|
+
) {
|
|
1278
|
+
validate.errors = [
|
|
1279
|
+
{
|
|
1280
|
+
keywordLocation: '#/0/properties/nativeCurrency/type',
|
|
1281
|
+
instanceLocation: '#/0/nativeCurrency',
|
|
1282
|
+
},
|
|
1283
|
+
]
|
|
1284
|
+
return false
|
|
1285
|
+
}
|
|
1286
|
+
if (
|
|
1287
|
+
!(
|
|
1288
|
+
'decimals' in data[0].nativeCurrency &&
|
|
1289
|
+
hasOwn(data[0].nativeCurrency, 'decimals')
|
|
1290
|
+
)
|
|
1291
|
+
) {
|
|
1292
|
+
validate.errors = [
|
|
1293
|
+
{
|
|
1294
|
+
keywordLocation: '#/0/properties/nativeCurrency/required',
|
|
1295
|
+
instanceLocation: '#/0/nativeCurrency/decimals',
|
|
1296
|
+
},
|
|
1297
|
+
]
|
|
1298
|
+
return false
|
|
1299
|
+
}
|
|
1300
|
+
if (
|
|
1301
|
+
!(
|
|
1302
|
+
'symbol' in data[0].nativeCurrency &&
|
|
1303
|
+
hasOwn(data[0].nativeCurrency, 'symbol')
|
|
1304
|
+
)
|
|
1305
|
+
) {
|
|
1306
|
+
validate.errors = [
|
|
1307
|
+
{
|
|
1308
|
+
keywordLocation: '#/0/properties/nativeCurrency/required',
|
|
1309
|
+
instanceLocation: '#/0/nativeCurrency/symbol',
|
|
1310
|
+
},
|
|
1311
|
+
]
|
|
1312
|
+
return false
|
|
1313
|
+
}
|
|
1314
|
+
if (!(typeof data[0].nativeCurrency.decimals === 'number')) {
|
|
1315
|
+
validate.errors = [
|
|
1316
|
+
{
|
|
1317
|
+
keywordLocation:
|
|
1318
|
+
'#/0/properties/nativeCurrency/properties/decimals/type',
|
|
1319
|
+
instanceLocation: '#/0/nativeCurrency/decimals',
|
|
1320
|
+
},
|
|
1321
|
+
]
|
|
1322
|
+
return false
|
|
1323
|
+
}
|
|
1324
|
+
if (
|
|
1325
|
+
'name' in data[0].nativeCurrency &&
|
|
1326
|
+
hasOwn(data[0].nativeCurrency, 'name')
|
|
1327
|
+
) {
|
|
1328
|
+
if (!(typeof data[0].nativeCurrency.name === 'string')) {
|
|
1329
|
+
validate.errors = [
|
|
1330
|
+
{
|
|
1331
|
+
keywordLocation:
|
|
1332
|
+
'#/0/properties/nativeCurrency/properties/name/type',
|
|
1333
|
+
instanceLocation: '#/0/nativeCurrency/name',
|
|
1334
|
+
},
|
|
1335
|
+
]
|
|
1336
|
+
return false
|
|
1337
|
+
}
|
|
1338
|
+
if (
|
|
1339
|
+
data[0].nativeCurrency.name.length > 50 &&
|
|
1340
|
+
stringLength(data[0].nativeCurrency.name) > 50
|
|
1341
|
+
) {
|
|
1342
|
+
validate.errors = [
|
|
1343
|
+
{
|
|
1344
|
+
keywordLocation:
|
|
1345
|
+
'#/0/properties/nativeCurrency/properties/name/maxLength',
|
|
1346
|
+
instanceLocation: '#/0/nativeCurrency/name',
|
|
1347
|
+
},
|
|
1348
|
+
]
|
|
1349
|
+
return false
|
|
1350
|
+
}
|
|
1351
|
+
if (!format5.test(data[0].nativeCurrency.name)) {
|
|
1352
|
+
validate.errors = [
|
|
1353
|
+
{
|
|
1354
|
+
keywordLocation:
|
|
1355
|
+
'#/0/properties/nativeCurrency/properties/name/format',
|
|
1356
|
+
instanceLocation: '#/0/nativeCurrency/name',
|
|
1357
|
+
},
|
|
1358
|
+
]
|
|
1359
|
+
return false
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
if (!(typeof data[0].nativeCurrency.symbol === 'string')) {
|
|
1363
|
+
validate.errors = [
|
|
1364
|
+
{
|
|
1365
|
+
keywordLocation:
|
|
1366
|
+
'#/0/properties/nativeCurrency/properties/symbol/type',
|
|
1367
|
+
instanceLocation: '#/0/nativeCurrency/symbol',
|
|
1368
|
+
},
|
|
1369
|
+
]
|
|
1370
|
+
return false
|
|
1371
|
+
}
|
|
1372
|
+
if (
|
|
1373
|
+
data[0].nativeCurrency.symbol.length > 50 &&
|
|
1374
|
+
stringLength(data[0].nativeCurrency.symbol) > 50
|
|
1375
|
+
) {
|
|
1376
|
+
validate.errors = [
|
|
1377
|
+
{
|
|
1378
|
+
keywordLocation:
|
|
1379
|
+
'#/0/properties/nativeCurrency/properties/symbol/maxLength',
|
|
1380
|
+
instanceLocation: '#/0/nativeCurrency/symbol',
|
|
1381
|
+
},
|
|
1382
|
+
]
|
|
1383
|
+
return false
|
|
1384
|
+
}
|
|
1385
|
+
if (!format5.test(data[0].nativeCurrency.symbol)) {
|
|
1386
|
+
validate.errors = [
|
|
1387
|
+
{
|
|
1388
|
+
keywordLocation:
|
|
1389
|
+
'#/0/properties/nativeCurrency/properties/symbol/format',
|
|
1390
|
+
instanceLocation: '#/0/nativeCurrency/symbol',
|
|
1391
|
+
},
|
|
1392
|
+
]
|
|
1393
|
+
return false
|
|
1394
|
+
}
|
|
1395
|
+
for (const key7 of Object.keys(data[0].nativeCurrency)) {
|
|
1396
|
+
if (key7 !== 'decimals' && key7 !== 'name' && key7 !== 'symbol') {
|
|
1397
|
+
validate.errors = [
|
|
1398
|
+
{
|
|
1399
|
+
keywordLocation:
|
|
1400
|
+
'#/0/properties/nativeCurrency/additionalProperties',
|
|
1401
|
+
instanceLocation: '#/nativeCurrency/' + pointerPart(key7),
|
|
1402
|
+
},
|
|
1403
|
+
]
|
|
1404
|
+
return false
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
for (const key8 of Object.keys(data[0])) {
|
|
1409
|
+
if (
|
|
1410
|
+
key8 !== 'chainId' &&
|
|
1411
|
+
key8 !== 'chainName' &&
|
|
1412
|
+
key8 !== 'blockExplorerUrls' &&
|
|
1413
|
+
key8 !== 'iconUrls' &&
|
|
1414
|
+
key8 !== 'rpcUrls' &&
|
|
1415
|
+
key8 !== 'nativeCurrency'
|
|
1416
|
+
) {
|
|
1417
|
+
validate.errors = [
|
|
1418
|
+
{
|
|
1419
|
+
keywordLocation: '#/0/additionalProperties',
|
|
1420
|
+
instanceLocation: '#/' + pointerPart(key8),
|
|
1421
|
+
},
|
|
1422
|
+
]
|
|
1423
|
+
return false
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (data.length > 1) {
|
|
1428
|
+
validate.errors = [
|
|
1429
|
+
{ keywordLocation: '#/items', instanceLocation: '#' },
|
|
1430
|
+
]
|
|
1431
|
+
return false
|
|
1432
|
+
}
|
|
1433
|
+
return true
|
|
1434
|
+
}
|
|
1012
1435
|
const format7 = (input) =>
|
|
1013
1436
|
input.length % 4 === 0 && /^[a-z0-9+/]*={0,3}$/i.test(input)
|
|
1014
|
-
const
|
|
1437
|
+
const ref18 = function validate(data) {
|
|
1015
1438
|
validate.errors = null
|
|
1016
1439
|
if (!(typeof data === 'string')) {
|
|
1017
1440
|
validate.errors = [{ keywordLocation: '#/type', instanceLocation: '#' }]
|
|
@@ -1031,7 +1454,7 @@ export function validateRequest(value) {
|
|
|
1031
1454
|
}
|
|
1032
1455
|
return true
|
|
1033
1456
|
}
|
|
1034
|
-
const
|
|
1457
|
+
const ref17 = function validate(data) {
|
|
1035
1458
|
validate.errors = null
|
|
1036
1459
|
if (!(typeof data === 'object' && data && !Array.isArray(data))) {
|
|
1037
1460
|
validate.errors = [{ keywordLocation: '#/type', instanceLocation: '#' }]
|
|
@@ -1110,11 +1533,11 @@ export function validateRequest(value) {
|
|
|
1110
1533
|
})()
|
|
1111
1534
|
if (sub23) passes5++
|
|
1112
1535
|
const sub24 = (() => {
|
|
1113
|
-
const
|
|
1114
|
-
const
|
|
1115
|
-
const
|
|
1116
|
-
validate.errors =
|
|
1117
|
-
if (!
|
|
1536
|
+
const err40 = validate.errors
|
|
1537
|
+
const res40 = ref18(data.image)
|
|
1538
|
+
const suberr40 = ref18.errors
|
|
1539
|
+
validate.errors = err40
|
|
1540
|
+
if (!res40) return false
|
|
1118
1541
|
return true
|
|
1119
1542
|
})()
|
|
1120
1543
|
if (sub24) passes5++
|
|
@@ -1139,18 +1562,18 @@ export function validateRequest(value) {
|
|
|
1139
1562
|
return false
|
|
1140
1563
|
}
|
|
1141
1564
|
}
|
|
1142
|
-
for (const
|
|
1565
|
+
for (const key9 of Object.keys(data)) {
|
|
1143
1566
|
if (
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1567
|
+
key9 !== 'address' &&
|
|
1568
|
+
key9 !== 'symbol' &&
|
|
1569
|
+
key9 !== 'decimals' &&
|
|
1570
|
+
key9 !== 'image' &&
|
|
1571
|
+
key9 !== 'chainId'
|
|
1149
1572
|
) {
|
|
1150
1573
|
validate.errors = [
|
|
1151
1574
|
{
|
|
1152
1575
|
keywordLocation: '#/additionalProperties',
|
|
1153
|
-
instanceLocation: '#/' + pointerPart(
|
|
1576
|
+
instanceLocation: '#/' + pointerPart(key9),
|
|
1154
1577
|
},
|
|
1155
1578
|
]
|
|
1156
1579
|
return false
|
|
@@ -1158,7 +1581,7 @@ export function validateRequest(value) {
|
|
|
1158
1581
|
}
|
|
1159
1582
|
return true
|
|
1160
1583
|
}
|
|
1161
|
-
const
|
|
1584
|
+
const ref16 = function validate(data) {
|
|
1162
1585
|
validate.errors = null
|
|
1163
1586
|
if (!(typeof data === 'object' && data && !Array.isArray(data))) {
|
|
1164
1587
|
validate.errors = [{ keywordLocation: '#/type', instanceLocation: '#' }]
|
|
@@ -1203,22 +1626,22 @@ export function validateRequest(value) {
|
|
|
1203
1626
|
]
|
|
1204
1627
|
return false
|
|
1205
1628
|
}
|
|
1206
|
-
const
|
|
1207
|
-
const
|
|
1208
|
-
const
|
|
1209
|
-
validate.errors =
|
|
1210
|
-
if (!
|
|
1629
|
+
const err41 = validate.errors
|
|
1630
|
+
const res41 = ref17(data.options)
|
|
1631
|
+
const suberr41 = ref17.errors
|
|
1632
|
+
validate.errors = err41
|
|
1633
|
+
if (!res41) {
|
|
1211
1634
|
validate.errors = [
|
|
1212
|
-
errorMerge(
|
|
1635
|
+
errorMerge(suberr41[0], '#/properties/options/$ref', '#/options'),
|
|
1213
1636
|
]
|
|
1214
1637
|
return false
|
|
1215
1638
|
}
|
|
1216
|
-
for (const
|
|
1217
|
-
if (
|
|
1639
|
+
for (const key10 of Object.keys(data)) {
|
|
1640
|
+
if (key10 !== 'type' && key10 !== 'options') {
|
|
1218
1641
|
validate.errors = [
|
|
1219
1642
|
{
|
|
1220
1643
|
keywordLocation: '#/additionalProperties',
|
|
1221
|
-
instanceLocation: '#/' + pointerPart(
|
|
1644
|
+
instanceLocation: '#/' + pointerPart(key10),
|
|
1222
1645
|
},
|
|
1223
1646
|
]
|
|
1224
1647
|
return false
|
|
@@ -2384,7 +2807,7 @@ export function validateRequest(value) {
|
|
|
2384
2807
|
return false
|
|
2385
2808
|
}
|
|
2386
2809
|
break
|
|
2387
|
-
case '
|
|
2810
|
+
case 'wallet_addEthereumChain':
|
|
2388
2811
|
if (!('params' in data && hasOwn(data, 'params'))) {
|
|
2389
2812
|
validate.errors = [
|
|
2390
2813
|
{
|
|
@@ -2394,14 +2817,14 @@ export function validateRequest(value) {
|
|
|
2394
2817
|
]
|
|
2395
2818
|
return false
|
|
2396
2819
|
}
|
|
2397
|
-
const
|
|
2398
|
-
const
|
|
2399
|
-
const
|
|
2400
|
-
validate.errors =
|
|
2401
|
-
if (!
|
|
2820
|
+
const err39 = validate.errors
|
|
2821
|
+
const res39 = ref15(data.params)
|
|
2822
|
+
const suberr39 = ref15.errors
|
|
2823
|
+
validate.errors = err39
|
|
2824
|
+
if (!res39) {
|
|
2402
2825
|
validate.errors = [
|
|
2403
2826
|
errorMerge(
|
|
2404
|
-
|
|
2827
|
+
suberr39[0],
|
|
2405
2828
|
'#/oneOf/46/properties/params/$ref',
|
|
2406
2829
|
'#/params',
|
|
2407
2830
|
),
|
|
@@ -2409,7 +2832,7 @@ export function validateRequest(value) {
|
|
|
2409
2832
|
return false
|
|
2410
2833
|
}
|
|
2411
2834
|
break
|
|
2412
|
-
case '
|
|
2835
|
+
case 'wallet_watchAsset':
|
|
2413
2836
|
if (!('params' in data && hasOwn(data, 'params'))) {
|
|
2414
2837
|
validate.errors = [
|
|
2415
2838
|
{
|
|
@@ -2419,10 +2842,35 @@ export function validateRequest(value) {
|
|
|
2419
2842
|
]
|
|
2420
2843
|
return false
|
|
2421
2844
|
}
|
|
2845
|
+
const err42 = validate.errors
|
|
2846
|
+
const res42 = ref16(data.params)
|
|
2847
|
+
const suberr42 = ref16.errors
|
|
2848
|
+
validate.errors = err42
|
|
2849
|
+
if (!res42) {
|
|
2850
|
+
validate.errors = [
|
|
2851
|
+
errorMerge(
|
|
2852
|
+
suberr42[0],
|
|
2853
|
+
'#/oneOf/47/properties/params/$ref',
|
|
2854
|
+
'#/params',
|
|
2855
|
+
),
|
|
2856
|
+
]
|
|
2857
|
+
return false
|
|
2858
|
+
}
|
|
2859
|
+
break
|
|
2860
|
+
case 'web3_clientVersion':
|
|
2861
|
+
if (!('params' in data && hasOwn(data, 'params'))) {
|
|
2862
|
+
validate.errors = [
|
|
2863
|
+
{
|
|
2864
|
+
keywordLocation: '#/oneOf/48/required',
|
|
2865
|
+
instanceLocation: '#/params',
|
|
2866
|
+
},
|
|
2867
|
+
]
|
|
2868
|
+
return false
|
|
2869
|
+
}
|
|
2422
2870
|
if (!(Array.isArray(data.params) && data.params.length === 0)) {
|
|
2423
2871
|
validate.errors = [
|
|
2424
2872
|
{
|
|
2425
|
-
keywordLocation: '#/oneOf/
|
|
2873
|
+
keywordLocation: '#/oneOf/48/properties/params/const',
|
|
2426
2874
|
instanceLocation: '#/params',
|
|
2427
2875
|
},
|
|
2428
2876
|
]
|
|
@@ -2433,7 +2881,7 @@ export function validateRequest(value) {
|
|
|
2433
2881
|
if (!('params' in data && hasOwn(data, 'params'))) {
|
|
2434
2882
|
validate.errors = [
|
|
2435
2883
|
{
|
|
2436
|
-
keywordLocation: '#/oneOf/
|
|
2884
|
+
keywordLocation: '#/oneOf/49/required',
|
|
2437
2885
|
instanceLocation: '#/params',
|
|
2438
2886
|
},
|
|
2439
2887
|
]
|
|
@@ -2442,7 +2890,7 @@ export function validateRequest(value) {
|
|
|
2442
2890
|
if (!(Array.isArray(data.params) && data.params.length === 0)) {
|
|
2443
2891
|
validate.errors = [
|
|
2444
2892
|
{
|
|
2445
|
-
keywordLocation: '#/oneOf/
|
|
2893
|
+
keywordLocation: '#/oneOf/49/properties/params/const',
|
|
2446
2894
|
instanceLocation: '#/params',
|
|
2447
2895
|
},
|
|
2448
2896
|
]
|
|
@@ -2455,17 +2903,17 @@ export function validateRequest(value) {
|
|
|
2455
2903
|
]
|
|
2456
2904
|
return false
|
|
2457
2905
|
}
|
|
2458
|
-
for (const
|
|
2906
|
+
for (const key11 of Object.keys(data)) {
|
|
2459
2907
|
if (
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2908
|
+
key11 !== 'id' &&
|
|
2909
|
+
key11 !== 'jsonrpc' &&
|
|
2910
|
+
key11 !== 'method' &&
|
|
2911
|
+
key11 !== 'params'
|
|
2464
2912
|
) {
|
|
2465
2913
|
validate.errors = [
|
|
2466
2914
|
{
|
|
2467
2915
|
keywordLocation: '#/unevaluatedProperties',
|
|
2468
|
-
instanceLocation: '#/' + pointerPart(
|
|
2916
|
+
instanceLocation: '#/' + pointerPart(key11),
|
|
2469
2917
|
},
|
|
2470
2918
|
]
|
|
2471
2919
|
return false
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type { EthereumProvider } from './provider/index.js';
|
|
2
|
+
import type { AddEthereumChainParameter, EthereumProvider } from './provider/index.js';
|
|
3
3
|
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams, EthTransaction, EthTransactionHash, EthWalletWatchAsset } from '@exodus/web3-ethereum-utils';
|
|
4
4
|
import type { EthTransactionParams } from '@exodus/web3-ethereum-utils';
|
|
5
5
|
import type { WalletStandardCommonDeps } from '@exodus/web3-provider';
|
|
@@ -41,6 +41,7 @@ export interface CreateEvmDepsParams {
|
|
|
41
41
|
getActiveWalletAccountData: GetActiveWalletAccountData;
|
|
42
42
|
transactionSigner: EVMTransactionSignerModule;
|
|
43
43
|
getLedgerDevice?: GetLedgerDevice;
|
|
44
|
+
addEthereumChain?: (param: AddEthereumChainParameter) => Promise<null>;
|
|
44
45
|
}
|
|
45
46
|
export declare type EVMFactory = (params: CreateEvmDepsParams) => EVMDeps;
|
|
46
47
|
export declare type EVMTransactionSignerModule = ITransactionSignerModule<EVMUnsignedTransaction>;
|
|
@@ -59,6 +60,7 @@ export declare type EVMDeps = {
|
|
|
59
60
|
messageSigner: EVMMessageSigner;
|
|
60
61
|
onEthWalletWatchAssetRequest?: (param: EthWalletWatchAsset) => Promise<boolean>;
|
|
61
62
|
getActiveWalletAccountData: GetActiveWalletAccountData;
|
|
63
|
+
addEthereumChain?: (param: AddEthereumChainParameter) => Promise<null>;
|
|
62
64
|
};
|
|
63
65
|
export declare type Dependencies = {
|
|
64
66
|
evms: EVMDeps[];
|
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": "12.
|
|
4
|
+
"version": "12.14.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"@exodus/web3-validation": "^1.38.0",
|
|
52
52
|
"@wallet-standard/base": "^1.0.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "d66f8b3bab52a723efac7fa11e6bf2d72c1827ed"
|
|
55
55
|
}
|