@toruslabs/ethereum-controllers 4.5.2 → 4.7.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/dist/ethereumControllers.cjs.js +390 -13
- package/dist/ethereumControllers.cjs.js.map +1 -1
- package/dist/ethereumControllers.esm.js +368 -15
- package/dist/ethereumControllers.esm.js.map +1 -1
- package/dist/ethereumControllers.umd.min.js +1 -1
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +0 -2
- package/dist/ethereumControllers.umd.min.js.map +1 -1
- package/dist/types/Message/AddChainController.d.ts +20 -0
- package/dist/types/Message/DecryptMessageController.d.ts +2 -2
- package/dist/types/Message/EncryptionPublicKeyController.d.ts +2 -2
- package/dist/types/Message/MessageController.d.ts +2 -2
- package/dist/types/Message/PersonalMessageController.d.ts +2 -2
- package/dist/types/Message/SwitchChainController.d.ts +20 -0
- package/dist/types/Message/TypedMessageController.d.ts +2 -2
- package/dist/types/Message/utils.d.ts +3 -1
- package/dist/types/Network/createEthereumMiddleware.d.ts +23 -15
- package/dist/types/Preferences/PreferencesController.d.ts +9 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/constants.d.ts +2 -0
- package/dist/types/utils/interfaces.d.ts +22 -1
- package/package.json +10 -10
- package/src/Message/AddChainController.ts +73 -0
- package/src/Message/DecryptMessageController.ts +2 -5
- package/src/Message/EncryptionPublicKeyController.ts +2 -8
- package/src/Message/MessageController.ts +2 -2
- package/src/Message/PersonalMessageController.ts +3 -3
- package/src/Message/SwitchChainController.ts +74 -0
- package/src/Message/TypedMessageController.ts +2 -2
- package/src/Message/utils.ts +49 -1
- package/src/Network/createEthereumMiddleware.ts +190 -26
- package/src/Preferences/PreferencesController.ts +66 -1
- package/src/index.ts +2 -0
- package/src/utils/constants.ts +2 -0
- package/src/utils/interfaces.ts +26 -1
|
@@ -56,6 +56,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
56
56
|
AVALANCHE_MAINNET_CHAIN_ID: () => (/* reexport */ AVALANCHE_MAINNET_CHAIN_ID),
|
|
57
57
|
AVALANCHE_TESTNET_CHAIN_ID: () => (/* reexport */ AVALANCHE_TESTNET_CHAIN_ID),
|
|
58
58
|
AccountTrackerController: () => (/* reexport */ Account_AccountTrackerController),
|
|
59
|
+
AddChainController: () => (/* reexport */ AddChainController),
|
|
59
60
|
BSC_MAINNET_CHAIN_ID: () => (/* reexport */ BSC_MAINNET_CHAIN_ID),
|
|
60
61
|
BSC_TESTNET_CHAIN_ID: () => (/* reexport */ BSC_TESTNET_CHAIN_ID),
|
|
61
62
|
CELO_MAINNET_CHAIN_ID: () => (/* reexport */ CELO_MAINNET_CHAIN_ID),
|
|
@@ -102,6 +103,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
102
103
|
SEPOLIA_CHAIN_ID: () => (/* reexport */ SEPOLIA_CHAIN_ID),
|
|
103
104
|
SIMPLEHASH_SUPPORTED_CHAINS: () => (/* reexport */ SIMPLEHASH_SUPPORTED_CHAINS),
|
|
104
105
|
SUPPORTED_NETWORKS: () => (/* reexport */ SUPPORTED_NETWORKS),
|
|
106
|
+
SwitchChainController: () => (/* reexport */ SwitchChainController),
|
|
105
107
|
TEST_CHAINS: () => (/* reexport */ TEST_CHAINS),
|
|
106
108
|
TRANSACTION_ENVELOPE_TYPES: () => (/* reexport */ TRANSACTION_ENVELOPE_TYPES),
|
|
107
109
|
TokenHandler: () => (/* reexport */ TokenHandler),
|
|
@@ -119,10 +121,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
119
121
|
createJsonRpcClient: () => (/* reexport */ createJsonRpcClient),
|
|
120
122
|
createPendingNonceMiddleware: () => (/* reexport */ createPendingNonceMiddleware),
|
|
121
123
|
createPendingTxMiddleware: () => (/* reexport */ createPendingTxMiddleware),
|
|
124
|
+
createProcessAddEthereumChain: () => (/* reexport */ createProcessAddEthereumChain),
|
|
122
125
|
createProcessDecryptMessageMiddleware: () => (/* reexport */ createProcessDecryptMessageMiddleware),
|
|
123
126
|
createProcessEncryptionPublicKeyMiddleware: () => (/* reexport */ createProcessEncryptionPublicKeyMiddleware),
|
|
124
127
|
createProcessEthSignMessage: () => (/* reexport */ createProcessEthSignMessage),
|
|
125
128
|
createProcessPersonalMessage: () => (/* reexport */ createProcessPersonalMessage),
|
|
129
|
+
createProcessSwitchEthereumChain: () => (/* reexport */ createProcessSwitchEthereumChain),
|
|
126
130
|
createProcessTransactionMiddleware: () => (/* reexport */ createProcessTransactionMiddleware),
|
|
127
131
|
createProcessTypedMessage: () => (/* reexport */ createProcessTypedMessage),
|
|
128
132
|
createProcessTypedMessageV3: () => (/* reexport */ createProcessTypedMessageV3),
|
|
@@ -157,12 +161,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
157
161
|
snapshotFromTxMeta: () => (/* reexport */ snapshotFromTxMeta),
|
|
158
162
|
toChecksumAddressByChainId: () => (/* reexport */ toChecksumAddressByChainId),
|
|
159
163
|
transactionMatchesNetwork: () => (/* reexport */ transactionMatchesNetwork),
|
|
164
|
+
validateAddChainData: () => (/* reexport */ validateAddChainData),
|
|
160
165
|
validateAddress: () => (/* reexport */ validateAddress),
|
|
161
166
|
validateDecryptedMessageData: () => (/* reexport */ validateDecryptedMessageData),
|
|
162
167
|
validateEncryptionPublicKeyMessageData: () => (/* reexport */ validateEncryptionPublicKeyMessageData),
|
|
163
168
|
validateFrom: () => (/* reexport */ validateFrom),
|
|
164
169
|
validateRecipient: () => (/* reexport */ validateRecipient),
|
|
165
170
|
validateSignMessageData: () => (/* reexport */ validateSignMessageData),
|
|
171
|
+
validateSwitchChainData: () => (/* reexport */ validateSwitchChainData),
|
|
166
172
|
validateTxParameters: () => (/* reexport */ validateTxParameters),
|
|
167
173
|
validateTypedSignMessageDataV1: () => (/* reexport */ validateTypedSignMessageDataV1),
|
|
168
174
|
validateTypedSignMessageDataV3V4: () => (/* reexport */ validateTypedSignMessageDataV3V4)
|
|
@@ -874,7 +880,9 @@ const METHOD_TYPES = {
|
|
|
874
880
|
WATCH_ASSET: "wallet_watchAsset",
|
|
875
881
|
ETH_GET_BLOCK_BY_HASH: "eth_getBlockByHash",
|
|
876
882
|
ETH_GET_CODE: "eth_getCode",
|
|
877
|
-
ETH_GET_GAS_PRICE: "eth_gasPrice"
|
|
883
|
+
ETH_GET_GAS_PRICE: "eth_gasPrice",
|
|
884
|
+
SWITCH_CHAIN: "wallet_switchEthereumChain",
|
|
885
|
+
ADD_CHAIN: "wallet_addEthereumChain"
|
|
878
886
|
};
|
|
879
887
|
const TRANSACTION_ENVELOPE_TYPES = {
|
|
880
888
|
LEGACY: "0x0",
|
|
@@ -2299,6 +2307,7 @@ const external_jsonschema_namespaceObject = require("jsonschema");
|
|
|
2299
2307
|
|
|
2300
2308
|
|
|
2301
2309
|
|
|
2310
|
+
|
|
2302
2311
|
const hexRe = /^[0-9A-Fa-f]+$/gu;
|
|
2303
2312
|
function validateAddress(address, propertyName) {
|
|
2304
2313
|
if (!address || typeof address !== "string" || !(0,util_namespaceObject.isValidAddress)(address)) {
|
|
@@ -2391,6 +2400,113 @@ function parseDecryptMessageData(data) {
|
|
|
2391
2400
|
const buffer = Buffer.from(stripped, "hex");
|
|
2392
2401
|
return JSON.parse(buffer.toString("utf8"));
|
|
2393
2402
|
}
|
|
2403
|
+
async function validateAddChainData(data) {
|
|
2404
|
+
const {
|
|
2405
|
+
chainId,
|
|
2406
|
+
rpcUrls,
|
|
2407
|
+
nativeCurrency
|
|
2408
|
+
} = data || {};
|
|
2409
|
+
if (!chainId) {
|
|
2410
|
+
throw new Error("Invalid add chain params: please pass chainId in params");
|
|
2411
|
+
}
|
|
2412
|
+
if (!(0,external_ethers_namespaceObject.isHexString)(chainId)) {
|
|
2413
|
+
throw new Error("Invalid add chain params: please pass a valid hex chainId in params, for: ex: 0x1");
|
|
2414
|
+
}
|
|
2415
|
+
if (!rpcUrls || rpcUrls.length === 0) throw new Error("params.rpcUrls not provided");
|
|
2416
|
+
if (!nativeCurrency) throw new Error("params.nativeCurrency not provided");
|
|
2417
|
+
const {
|
|
2418
|
+
name,
|
|
2419
|
+
symbol,
|
|
2420
|
+
decimals
|
|
2421
|
+
} = nativeCurrency;
|
|
2422
|
+
if (!name) throw new Error("params.nativeCurrency.name not provided");
|
|
2423
|
+
if (!symbol) throw new Error("params.nativeCurrency.symbol not provided");
|
|
2424
|
+
if (decimals === undefined) throw new Error("params.nativeCurrency.decimals not provided");
|
|
2425
|
+
const _web3 = new external_ethers_namespaceObject.JsonRpcProvider(rpcUrls[0], "any");
|
|
2426
|
+
const {
|
|
2427
|
+
chainId: networkChainID
|
|
2428
|
+
} = await _web3.getNetwork();
|
|
2429
|
+
if (Number.parseInt(networkChainID.toString()) !== Number.parseInt(chainId, 16)) {
|
|
2430
|
+
throw new Error(`Provided rpc url's chainId version is not matching with provided chainId, expected: ${(0,external_ethers_namespaceObject.toQuantity)(networkChainID)}, received: ${chainId}`);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
function validateSwitchChainData(data) {
|
|
2434
|
+
const {
|
|
2435
|
+
chainId
|
|
2436
|
+
} = data || {};
|
|
2437
|
+
if (!chainId) {
|
|
2438
|
+
throw new Error("Invalid switch chain params: please pass chainId in params");
|
|
2439
|
+
}
|
|
2440
|
+
if (!(0,external_ethers_namespaceObject.isHexString)(chainId)) {
|
|
2441
|
+
throw new Error("Invalid switch chain params: please pass a valid hex chainId in params, for: ex: 0x1");
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
;// CONCATENATED MODULE: ./src/Message/AddChainController.ts
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
|
|
2452
|
+
class AddChainController extends AbstractMessageController {
|
|
2453
|
+
constructor(_ref) {
|
|
2454
|
+
let {
|
|
2455
|
+
config,
|
|
2456
|
+
state,
|
|
2457
|
+
getNetworkIdentifier,
|
|
2458
|
+
addChain
|
|
2459
|
+
} = _ref;
|
|
2460
|
+
super({
|
|
2461
|
+
config,
|
|
2462
|
+
state,
|
|
2463
|
+
getNetworkIdentifier
|
|
2464
|
+
});
|
|
2465
|
+
defineProperty_default()(this, "name", "AddChainController");
|
|
2466
|
+
defineProperty_default()(this, "addChain", void 0);
|
|
2467
|
+
this.addChain = addChain;
|
|
2468
|
+
this.initialize();
|
|
2469
|
+
}
|
|
2470
|
+
async processAddChain(messageId) {
|
|
2471
|
+
try {
|
|
2472
|
+
const msgObject = this.getMessage(messageId);
|
|
2473
|
+
await this.approveMessage(messageId, msgObject.messageParams);
|
|
2474
|
+
this.addChain(msgObject.messageParams);
|
|
2475
|
+
this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
|
|
2476
|
+
rawSig: JSON.stringify(msgObject.messageParams)
|
|
2477
|
+
}));
|
|
2478
|
+
this.setMessageStatus(messageId, MessageStatus.SIGNED);
|
|
2479
|
+
return null;
|
|
2480
|
+
} catch (error) {
|
|
2481
|
+
external_loglevel_default().error(error);
|
|
2482
|
+
this.setMessageStatus(messageId, MessageStatus.FAILED);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
async addNewUnapprovedMessage(messageParams, req) {
|
|
2486
|
+
await this.addUnapprovedMessage(messageParams, req);
|
|
2487
|
+
return this.waitForFinishStatus(messageParams, this.name);
|
|
2488
|
+
}
|
|
2489
|
+
async addUnapprovedMessage(messageParams, req) {
|
|
2490
|
+
validateAddChainData(messageParams);
|
|
2491
|
+
if (req) {
|
|
2492
|
+
messageParams.origin = req.origin;
|
|
2493
|
+
}
|
|
2494
|
+
const messageId = messageParams.id || (0,base_controllers_namespaceObject.randomId)();
|
|
2495
|
+
const messageData = {
|
|
2496
|
+
id: messageId,
|
|
2497
|
+
messageParams,
|
|
2498
|
+
status: MessageStatus.UNAPPROVED,
|
|
2499
|
+
time: Date.now(),
|
|
2500
|
+
type: METHOD_TYPES.ADD_CHAIN
|
|
2501
|
+
};
|
|
2502
|
+
await this.addMessage(messageData);
|
|
2503
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
2504
|
+
return messageId;
|
|
2505
|
+
}
|
|
2506
|
+
prepMessageForSigning(messageParams) {
|
|
2507
|
+
return Promise.resolve(messageParams);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2394
2510
|
;// CONCATENATED MODULE: ./src/Message/DecryptMessageController.ts
|
|
2395
2511
|
|
|
2396
2512
|
|
|
@@ -2657,6 +2773,77 @@ class PersonalMessageController extends AbstractMessageController {
|
|
|
2657
2773
|
type: METHOD_TYPES.PERSONAL_SIGN
|
|
2658
2774
|
};
|
|
2659
2775
|
await this.addMessage(messageData);
|
|
2776
|
+
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, {
|
|
2777
|
+
messageData,
|
|
2778
|
+
req
|
|
2779
|
+
});
|
|
2780
|
+
return messageId;
|
|
2781
|
+
}
|
|
2782
|
+
prepMessageForSigning(messageParams) {
|
|
2783
|
+
return Promise.resolve(messageParams);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
;// CONCATENATED MODULE: ./src/Message/SwitchChainController.ts
|
|
2787
|
+
|
|
2788
|
+
|
|
2789
|
+
|
|
2790
|
+
|
|
2791
|
+
|
|
2792
|
+
|
|
2793
|
+
|
|
2794
|
+
class SwitchChainController extends AbstractMessageController {
|
|
2795
|
+
constructor(_ref) {
|
|
2796
|
+
let {
|
|
2797
|
+
config,
|
|
2798
|
+
state,
|
|
2799
|
+
getNetworkIdentifier,
|
|
2800
|
+
switchChain
|
|
2801
|
+
} = _ref;
|
|
2802
|
+
super({
|
|
2803
|
+
config,
|
|
2804
|
+
state,
|
|
2805
|
+
getNetworkIdentifier
|
|
2806
|
+
});
|
|
2807
|
+
defineProperty_default()(this, "name", "SwitchChainController");
|
|
2808
|
+
defineProperty_default()(this, "switchChain", void 0);
|
|
2809
|
+
this.switchChain = switchChain;
|
|
2810
|
+
this.initialize();
|
|
2811
|
+
}
|
|
2812
|
+
async processSwitchChain(messageId) {
|
|
2813
|
+
try {
|
|
2814
|
+
const msgObject = this.getMessage(messageId);
|
|
2815
|
+
await this.approveMessage(messageId, msgObject.messageParams);
|
|
2816
|
+
this.switchChain({
|
|
2817
|
+
chainId: msgObject.messageParams.chainId
|
|
2818
|
+
});
|
|
2819
|
+
this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
|
|
2820
|
+
rawSig: JSON.stringify(msgObject.messageParams)
|
|
2821
|
+
}));
|
|
2822
|
+
this.setMessageStatus(messageId, MessageStatus.SIGNED);
|
|
2823
|
+
return null;
|
|
2824
|
+
} catch (error) {
|
|
2825
|
+
external_loglevel_default().error(error);
|
|
2826
|
+
this.setMessageStatus(messageId, MessageStatus.FAILED);
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
async addNewUnapprovedMessage(messageParams, req) {
|
|
2830
|
+
await this.addUnapprovedMessage(messageParams, req);
|
|
2831
|
+
return this.waitForFinishStatus(messageParams, this.name);
|
|
2832
|
+
}
|
|
2833
|
+
async addUnapprovedMessage(messageParams, req) {
|
|
2834
|
+
validateSwitchChainData(messageParams);
|
|
2835
|
+
if (req) {
|
|
2836
|
+
messageParams.origin = req.origin;
|
|
2837
|
+
}
|
|
2838
|
+
const messageId = messageParams.id || (0,base_controllers_namespaceObject.randomId)();
|
|
2839
|
+
const messageData = {
|
|
2840
|
+
id: messageId,
|
|
2841
|
+
messageParams,
|
|
2842
|
+
status: MessageStatus.UNAPPROVED,
|
|
2843
|
+
time: Date.now(),
|
|
2844
|
+
type: METHOD_TYPES.SWITCH_CHAIN
|
|
2845
|
+
};
|
|
2846
|
+
await this.addMessage(messageData);
|
|
2660
2847
|
this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
|
|
2661
2848
|
return messageId;
|
|
2662
2849
|
}
|
|
@@ -2760,6 +2947,7 @@ const openlogin_jrpc_namespaceObject = require("@toruslabs/openlogin-jrpc");
|
|
|
2760
2947
|
|
|
2761
2948
|
|
|
2762
2949
|
|
|
2950
|
+
|
|
2763
2951
|
function createGetAccountsMiddleware(_ref) {
|
|
2764
2952
|
let {
|
|
2765
2953
|
getAccounts
|
|
@@ -2797,7 +2985,19 @@ function createProcessEthSignMessage(_ref3) {
|
|
|
2797
2985
|
} = request;
|
|
2798
2986
|
if (method !== METHOD_TYPES.ETH_SIGN) return next();
|
|
2799
2987
|
if (!processEthSignMessage) throw new Error("WalletMiddleware - opts.processEthSignMessage not provided");
|
|
2800
|
-
|
|
2988
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
2989
|
+
let msgParams = request.params;
|
|
2990
|
+
if (Array.isArray(request.params)) {
|
|
2991
|
+
if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [address, message]`);
|
|
2992
|
+
const params = request.params;
|
|
2993
|
+
const address = params[0];
|
|
2994
|
+
const message = params[1];
|
|
2995
|
+
msgParams = {
|
|
2996
|
+
from: address,
|
|
2997
|
+
data: message
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
response.result = await processEthSignMessage(msgParams, request);
|
|
2801
3001
|
});
|
|
2802
3002
|
}
|
|
2803
3003
|
function createProcessTypedMessage(_ref4) {
|
|
@@ -2810,7 +3010,20 @@ function createProcessTypedMessage(_ref4) {
|
|
|
2810
3010
|
} = request;
|
|
2811
3011
|
if (method !== METHOD_TYPES.ETH_SIGN_TYPED_DATA) return next();
|
|
2812
3012
|
if (!processTypedMessage) throw new Error("WalletMiddleware - opts.processTypedMessage not provided");
|
|
2813
|
-
|
|
3013
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3014
|
+
let msgParams = request.params;
|
|
3015
|
+
if (Array.isArray(request.params)) {
|
|
3016
|
+
if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [typedData, address]`);
|
|
3017
|
+
const params = request.params;
|
|
3018
|
+
const message = params[0];
|
|
3019
|
+
const address = params[1];
|
|
3020
|
+
msgParams = {
|
|
3021
|
+
from: address,
|
|
3022
|
+
data: message,
|
|
3023
|
+
version: eth_sig_util_namespaceObject.SignTypedDataVersion.V1
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
response.result = await processTypedMessage(msgParams, request);
|
|
2814
3027
|
});
|
|
2815
3028
|
}
|
|
2816
3029
|
function createProcessTypedMessageV3(_ref5) {
|
|
@@ -2823,7 +3036,20 @@ function createProcessTypedMessageV3(_ref5) {
|
|
|
2823
3036
|
} = request;
|
|
2824
3037
|
if (method !== METHOD_TYPES.ETH_SIGN_TYPED_DATA_V3) return next();
|
|
2825
3038
|
if (!processTypedMessageV3) throw new Error("WalletMiddleware - opts.processTypedMessageV3 is not provided");
|
|
2826
|
-
|
|
3039
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3040
|
+
let msgParams = request.params;
|
|
3041
|
+
if (Array.isArray(request.params)) {
|
|
3042
|
+
if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [address, typedData]`);
|
|
3043
|
+
const params = request.params;
|
|
3044
|
+
const address = params[0];
|
|
3045
|
+
const message = JSON.parse(params[1]);
|
|
3046
|
+
msgParams = {
|
|
3047
|
+
from: address,
|
|
3048
|
+
data: message,
|
|
3049
|
+
version: eth_sig_util_namespaceObject.SignTypedDataVersion.V3
|
|
3050
|
+
};
|
|
3051
|
+
}
|
|
3052
|
+
response.result = await processTypedMessageV3(msgParams, request);
|
|
2827
3053
|
});
|
|
2828
3054
|
}
|
|
2829
3055
|
function createProcessTypedMessageV4(_ref6) {
|
|
@@ -2836,7 +3062,20 @@ function createProcessTypedMessageV4(_ref6) {
|
|
|
2836
3062
|
} = request;
|
|
2837
3063
|
if (method !== METHOD_TYPES.ETH_SIGN_TYPED_DATA_V4) return next();
|
|
2838
3064
|
if (!processTypedMessageV4) throw new Error("WalletMiddleware - opts.processTypedMessageV4 is not provided");
|
|
2839
|
-
|
|
3065
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3066
|
+
let msgParams = request.params;
|
|
3067
|
+
if (Array.isArray(request.params)) {
|
|
3068
|
+
if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [address, typedData]`);
|
|
3069
|
+
const params = request.params;
|
|
3070
|
+
const address = params[0];
|
|
3071
|
+
const message = JSON.parse(params[1]);
|
|
3072
|
+
msgParams = {
|
|
3073
|
+
from: address,
|
|
3074
|
+
data: message,
|
|
3075
|
+
version: eth_sig_util_namespaceObject.SignTypedDataVersion.V4
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
response.result = await processTypedMessageV4(msgParams, request);
|
|
2840
3079
|
});
|
|
2841
3080
|
}
|
|
2842
3081
|
function createProcessPersonalMessage(_ref7) {
|
|
@@ -2849,7 +3088,19 @@ function createProcessPersonalMessage(_ref7) {
|
|
|
2849
3088
|
} = request;
|
|
2850
3089
|
if (method !== METHOD_TYPES.PERSONAL_SIGN) return next();
|
|
2851
3090
|
if (!processPersonalMessage) throw new Error("WalletMiddleware - opts.processPersonalMessage is not provided");
|
|
2852
|
-
|
|
3091
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3092
|
+
let msgParams = request.params;
|
|
3093
|
+
if (Array.isArray(request.params)) {
|
|
3094
|
+
if (!(request.params.length >= 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [message, address]`);
|
|
3095
|
+
const params = request.params;
|
|
3096
|
+
const message = params[0];
|
|
3097
|
+
const address = params[1];
|
|
3098
|
+
msgParams = {
|
|
3099
|
+
from: address,
|
|
3100
|
+
data: message
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
response.result = await processPersonalMessage(msgParams, request);
|
|
2853
3104
|
});
|
|
2854
3105
|
}
|
|
2855
3106
|
function createPendingNonceMiddleware(_ref8) {
|
|
@@ -2942,12 +3193,21 @@ function createProcessEncryptionPublicKeyMiddleware(_ref10) {
|
|
|
2942
3193
|
} = _ref10;
|
|
2943
3194
|
return (0,openlogin_jrpc_namespaceObject.createAsyncMiddleware)(async (request, response, next) => {
|
|
2944
3195
|
const {
|
|
2945
|
-
params,
|
|
2946
3196
|
method
|
|
2947
3197
|
} = request;
|
|
2948
3198
|
if (method !== METHOD_TYPES.ETH_GET_ENCRYPTION_PUBLIC_KEY) return next();
|
|
2949
3199
|
if (!processEncryptionPublicKey) throw new Error("WalletMiddleware - opts.processEncryptionPublicKey not provided");
|
|
2950
|
-
|
|
3200
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3201
|
+
let msgParams = request.params;
|
|
3202
|
+
if (Array.isArray(request.params)) {
|
|
3203
|
+
if (!(request.params.length === 1)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [address]`);
|
|
3204
|
+
const [address] = request.params;
|
|
3205
|
+
msgParams = {
|
|
3206
|
+
data: address,
|
|
3207
|
+
from: address
|
|
3208
|
+
};
|
|
3209
|
+
}
|
|
3210
|
+
response.result = await processEncryptionPublicKey(msgParams, request);
|
|
2951
3211
|
});
|
|
2952
3212
|
}
|
|
2953
3213
|
function createProcessDecryptMessageMiddleware(_ref11) {
|
|
@@ -2956,18 +3216,67 @@ function createProcessDecryptMessageMiddleware(_ref11) {
|
|
|
2956
3216
|
} = _ref11;
|
|
2957
3217
|
return (0,openlogin_jrpc_namespaceObject.createAsyncMiddleware)(async (request, response, next) => {
|
|
2958
3218
|
const {
|
|
2959
|
-
params,
|
|
2960
3219
|
method
|
|
2961
3220
|
} = request;
|
|
2962
3221
|
if (method !== METHOD_TYPES.ETH_DECRYPT) return next();
|
|
2963
3222
|
if (!processDecryptMessage) throw new Error("WalletMiddleware - opts.processDecryptMessage not provided");
|
|
2964
|
-
|
|
3223
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3224
|
+
let msgParams = request.params;
|
|
3225
|
+
if (Array.isArray(request.params)) {
|
|
3226
|
+
if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [message, address]`);
|
|
3227
|
+
const [message, address] = request.params;
|
|
3228
|
+
msgParams = {
|
|
3229
|
+
data: message,
|
|
3230
|
+
from: address
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
response.result = await processDecryptMessage(msgParams, request);
|
|
2965
3234
|
});
|
|
2966
3235
|
}
|
|
2967
|
-
function
|
|
3236
|
+
function createProcessSwitchEthereumChain(_ref12) {
|
|
2968
3237
|
let {
|
|
2969
|
-
|
|
3238
|
+
processSwitchEthereumChain
|
|
2970
3239
|
} = _ref12;
|
|
3240
|
+
return (0,openlogin_jrpc_namespaceObject.createAsyncMiddleware)(async (request, response, next) => {
|
|
3241
|
+
const {
|
|
3242
|
+
method
|
|
3243
|
+
} = request;
|
|
3244
|
+
if (method !== METHOD_TYPES.SWITCH_CHAIN) return next();
|
|
3245
|
+
if (!processSwitchEthereumChain) throw new Error("WalletMiddleware - opts.processSwitchEthereumChain not provided");
|
|
3246
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3247
|
+
let msgParams = request.params;
|
|
3248
|
+
if (Array.isArray(request.params)) {
|
|
3249
|
+
if (!(request.params.length === 1)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [data]`);
|
|
3250
|
+
const [message] = request.params;
|
|
3251
|
+
msgParams = message;
|
|
3252
|
+
}
|
|
3253
|
+
response.result = await processSwitchEthereumChain(msgParams, request);
|
|
3254
|
+
});
|
|
3255
|
+
}
|
|
3256
|
+
function createProcessAddEthereumChain(_ref13) {
|
|
3257
|
+
let {
|
|
3258
|
+
processAddEthereumChain
|
|
3259
|
+
} = _ref13;
|
|
3260
|
+
return (0,openlogin_jrpc_namespaceObject.createAsyncMiddleware)(async (request, response, next) => {
|
|
3261
|
+
const {
|
|
3262
|
+
method
|
|
3263
|
+
} = request;
|
|
3264
|
+
if (method !== METHOD_TYPES.ADD_CHAIN) return next();
|
|
3265
|
+
if (!processAddEthereumChain) throw new Error("WalletMiddleware - opts.processAddEthereumChain not provided");
|
|
3266
|
+
if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
|
|
3267
|
+
let msgParams = request.params;
|
|
3268
|
+
if (Array.isArray(request.params)) {
|
|
3269
|
+
if (!(request.params.length === 1)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [data]`);
|
|
3270
|
+
const [message] = request.params;
|
|
3271
|
+
msgParams = message;
|
|
3272
|
+
}
|
|
3273
|
+
response.result = await processAddEthereumChain(msgParams, request);
|
|
3274
|
+
});
|
|
3275
|
+
}
|
|
3276
|
+
function createRequestAccountsMiddleware(_ref14) {
|
|
3277
|
+
let {
|
|
3278
|
+
requestAccounts
|
|
3279
|
+
} = _ref14;
|
|
2971
3280
|
return (0,openlogin_jrpc_namespaceObject.createAsyncMiddleware)(async (request, response, next) => {
|
|
2972
3281
|
const {
|
|
2973
3282
|
method
|
|
@@ -2994,6 +3303,8 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
2994
3303
|
getPendingTransactionByHash,
|
|
2995
3304
|
processEncryptionPublicKey,
|
|
2996
3305
|
processDecryptMessage,
|
|
3306
|
+
processSwitchEthereumChain,
|
|
3307
|
+
processAddEthereumChain,
|
|
2997
3308
|
getProviderState,
|
|
2998
3309
|
version
|
|
2999
3310
|
} = providerHandlers;
|
|
@@ -3024,6 +3335,10 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
3024
3335
|
processEncryptionPublicKey
|
|
3025
3336
|
}), createProcessDecryptMessageMiddleware({
|
|
3026
3337
|
processDecryptMessage
|
|
3338
|
+
}), createProcessSwitchEthereumChain({
|
|
3339
|
+
processSwitchEthereumChain
|
|
3340
|
+
}), createProcessAddEthereumChain({
|
|
3341
|
+
processAddEthereumChain
|
|
3027
3342
|
})]);
|
|
3028
3343
|
}
|
|
3029
3344
|
;// CONCATENATED MODULE: ./src/Network/createJsonRpcClient.ts
|
|
@@ -3684,7 +3999,8 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
3684
3999
|
provider,
|
|
3685
4000
|
blockTracker,
|
|
3686
4001
|
signAuthMessage,
|
|
3687
|
-
getProviderConfig
|
|
4002
|
+
getProviderConfig,
|
|
4003
|
+
setProviderConfig
|
|
3688
4004
|
} = _ref;
|
|
3689
4005
|
super({
|
|
3690
4006
|
config,
|
|
@@ -3699,10 +4015,12 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
3699
4015
|
defineProperty_default()(this, "_handle", void 0);
|
|
3700
4016
|
defineProperty_default()(this, "_mutex", new external_async_mutex_namespaceObject.Mutex());
|
|
3701
4017
|
defineProperty_default()(this, "getProviderConfig", void 0);
|
|
4018
|
+
defineProperty_default()(this, "setProviderConfig", void 0);
|
|
3702
4019
|
defineProperty_default()(this, "provider", void 0);
|
|
3703
4020
|
defineProperty_default()(this, "blockTracker", void 0);
|
|
3704
4021
|
this.provider = provider;
|
|
3705
4022
|
this.getProviderConfig = getProviderConfig;
|
|
4023
|
+
this.setProviderConfig = setProviderConfig;
|
|
3706
4024
|
this.blockTracker = blockTracker;
|
|
3707
4025
|
external_loglevel_default().info(this.blockTracker);
|
|
3708
4026
|
}
|
|
@@ -3909,6 +4227,34 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
3909
4227
|
var _this$getAddressState6, _this$getAddressState7;
|
|
3910
4228
|
return (_this$getAddressState6 = (_this$getAddressState7 = this.getAddressState(address)) === null || _this$getAddressState7 === void 0 ? void 0 : _this$getAddressState7.customNfts) !== null && _this$getAddressState6 !== void 0 ? _this$getAddressState6 : [];
|
|
3911
4229
|
}
|
|
4230
|
+
async addChain(network) {
|
|
4231
|
+
const approveChainOptions = this.getChainOptions();
|
|
4232
|
+
const providerConfig = approveChainOptions.find(x => x.chainId === network.chainId);
|
|
4233
|
+
if (providerConfig) {
|
|
4234
|
+
throw new Error(`chainId ${network.chainId} already exists`);
|
|
4235
|
+
}
|
|
4236
|
+
const newNetwork = {
|
|
4237
|
+
displayName: network.chainName,
|
|
4238
|
+
rpcTarget: network.rpcUrls[0],
|
|
4239
|
+
ticker: network.nativeCurrency.symbol,
|
|
4240
|
+
chainId: network.chainId,
|
|
4241
|
+
blockExplorerUrl: network.blockExplorerUrls[0]
|
|
4242
|
+
};
|
|
4243
|
+
const isSuccess = await this.addCustomNetwork({
|
|
4244
|
+
type: "rpc",
|
|
4245
|
+
network: newNetwork
|
|
4246
|
+
});
|
|
4247
|
+
if (!isSuccess) throw new Error("unable to add custom network");
|
|
4248
|
+
}
|
|
4249
|
+
switchChain(data) {
|
|
4250
|
+
const chainOptions = this.getChainOptions();
|
|
4251
|
+
const providerConfig = chainOptions.find(x => x.chainId === data.chainId);
|
|
4252
|
+
if (providerConfig) {
|
|
4253
|
+
this.setProviderConfig(providerConfig);
|
|
4254
|
+
} else {
|
|
4255
|
+
throw new Error(`chainId ${data.chainId} is not supported`);
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
3912
4258
|
|
|
3913
4259
|
// Custom Network methods
|
|
3914
4260
|
async addCustomNetwork(_ref2) {
|
|
@@ -4016,6 +4362,35 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
|
|
|
4016
4362
|
paymentTx: accumulator
|
|
4017
4363
|
}, address);
|
|
4018
4364
|
}
|
|
4365
|
+
getChainOptions() {
|
|
4366
|
+
var _identities$selectedA, _identities$selectedA2;
|
|
4367
|
+
const {
|
|
4368
|
+
selectedAddress,
|
|
4369
|
+
identities
|
|
4370
|
+
} = this.state;
|
|
4371
|
+
const customNetworks = (_identities$selectedA = (_identities$selectedA2 = identities[selectedAddress]) === null || _identities$selectedA2 === void 0 ? void 0 : _identities$selectedA2.customNetworks) !== null && _identities$selectedA !== void 0 ? _identities$selectedA : [];
|
|
4372
|
+
const custom = Object.values(customNetworks).reduce((chains, network) => {
|
|
4373
|
+
const networkItem = {
|
|
4374
|
+
blockExplorerUrl: network.block_explorer_url,
|
|
4375
|
+
chainId: network.chain_id,
|
|
4376
|
+
displayName: network.network_name,
|
|
4377
|
+
logo: "eth.svg",
|
|
4378
|
+
rpcTarget: network.rpc_url,
|
|
4379
|
+
ticker: network.symbol,
|
|
4380
|
+
tickerName: network.symbol.toUpperCase(),
|
|
4381
|
+
isCustom: true,
|
|
4382
|
+
id: network.id
|
|
4383
|
+
};
|
|
4384
|
+
if (Object.keys(SUPPORTED_NETWORKS).includes(networkItem.chainId)) return chains;
|
|
4385
|
+
chains.push(networkItem);
|
|
4386
|
+
return chains;
|
|
4387
|
+
}, []);
|
|
4388
|
+
const supported = Object.values(SUPPORTED_NETWORKS).reduce((chains, network) => {
|
|
4389
|
+
chains.push(network);
|
|
4390
|
+
return chains;
|
|
4391
|
+
}, []);
|
|
4392
|
+
return [...supported, ...custom];
|
|
4393
|
+
}
|
|
4019
4394
|
async calculatePastTx(txs, address) {
|
|
4020
4395
|
const pastTx = [];
|
|
4021
4396
|
const pendingTx = [];
|
|
@@ -6152,6 +6527,8 @@ class TransactionController extends TransactionStateManager {
|
|
|
6152
6527
|
|
|
6153
6528
|
|
|
6154
6529
|
|
|
6530
|
+
|
|
6531
|
+
|
|
6155
6532
|
|
|
6156
6533
|
|
|
6157
6534
|
|