@subwallet/extension-base 1.0.12-0 → 1.0.13-1
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/background/KoniTypes.d.ts +89 -0
- package/background/KoniTypes.js +18 -19
- package/background/handlers/Extension.js +17 -2
- package/background/handlers/State.d.ts +0 -1
- package/background/handlers/State.js +4 -8
- package/background/types.d.ts +6 -1
- package/cjs/background/KoniTypes.js +21 -11
- package/cjs/background/handlers/Extension.js +22 -6
- package/cjs/background/handlers/State.js +4 -8
- package/cjs/constants/index.js +7 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +5 -0
- package/cjs/koni/api/dotsama/transfer.js +6 -0
- package/cjs/koni/api/nft/config.js +11 -6
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +2 -2
- package/cjs/koni/background/cron.js +12 -1
- package/cjs/koni/background/handlers/Extension.js +457 -131
- package/cjs/koni/background/handlers/State.js +236 -53
- package/cjs/koni/background/handlers/Tabs.js +61 -9
- package/cjs/koni/background/subscription.js +3 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/Metadata.js +3 -0
- package/cjs/services/chain-service/constants.js +10 -4
- package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
- package/cjs/services/chain-service/index.js +54 -5
- package/cjs/services/chain-service/utils.js +32 -0
- package/cjs/services/event-service/types.js +3 -1
- package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -9
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +2 -2
- package/cjs/services/request-service/handler/WalletConnectRequestHandler.js +71 -0
- package/cjs/services/request-service/index.js +24 -6
- package/cjs/services/storage-service/DatabaseService.js +31 -1
- package/cjs/services/storage-service/databases/index.js +3 -0
- package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -2
- package/cjs/services/transaction-service/index.js +2 -1
- package/cjs/services/wallet-connect-service/constants.js +38 -0
- package/cjs/services/wallet-connect-service/handler/Eip155RequestHandler.js +113 -0
- package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +123 -0
- package/cjs/services/wallet-connect-service/helpers.js +81 -0
- package/cjs/services/wallet-connect-service/index.js +273 -0
- package/cjs/services/wallet-connect-service/types.js +27 -0
- package/cjs/utils/array.js +17 -0
- package/cjs/utils/environment.js +66 -0
- package/cjs/utils/index.js +78 -1
- package/cjs/utils/lazy.js +52 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/balance.js +6 -1
- package/koni/api/dotsama/transfer.js +7 -1
- package/koni/api/nft/config.js +11 -6
- package/koni/api/xcm/polkadotXcm.js +1 -1
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/background/cron.d.ts +1 -0
- package/koni/background/cron.js +13 -2
- package/koni/background/handlers/Extension.d.ts +11 -0
- package/koni/background/handlers/Extension.js +329 -12
- package/koni/background/handlers/State.d.ts +17 -3
- package/koni/background/handlers/State.js +238 -52
- package/koni/background/handlers/Tabs.d.ts +2 -0
- package/koni/background/handlers/Tabs.js +58 -7
- package/koni/background/subscription.js +3 -0
- package/package.json +72 -6
- package/packageInfo.js +1 -1
- package/page/Metadata.d.ts +2 -0
- package/page/Metadata.js +3 -0
- package/services/chain-service/constants.d.ts +3 -0
- package/services/chain-service/constants.js +5 -2
- package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
- package/services/chain-service/handler/SubstrateApi.js +2 -1
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
- package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
- package/services/chain-service/handler/types.d.ts +2 -0
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +56 -7
- package/services/chain-service/utils.d.ts +3 -0
- package/services/chain-service/utils.js +28 -0
- package/services/event-service/types.d.ts +3 -0
- package/services/event-service/types.js +3 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +0 -1
- package/services/request-service/handler/AuthRequestHandler.js +5 -10
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -1
- package/services/request-service/handler/SubstrateRequestHandler.js +2 -2
- package/services/request-service/handler/WalletConnectRequestHandler.d.ts +15 -0
- package/services/request-service/handler/WalletConnectRequestHandler.js +62 -0
- package/services/request-service/index.d.ts +7 -2
- package/services/request-service/index.js +24 -6
- package/services/storage-service/DatabaseService.d.ts +10 -1
- package/services/storage-service/DatabaseService.js +31 -1
- package/services/storage-service/databases/index.d.ts +2 -0
- package/services/storage-service/databases/index.js +3 -0
- package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
- package/services/storage-service/db-stores/MantaPay.js +32 -0
- package/services/transaction-service/helpers/index.d.ts +1 -1
- package/services/transaction-service/helpers/index.js +2 -2
- package/services/transaction-service/index.js +2 -1
- package/services/transaction-service/types.d.ts +2 -1
- package/services/wallet-connect-service/constants.d.ts +11 -0
- package/services/wallet-connect-service/constants.js +23 -0
- package/services/wallet-connect-service/handler/Eip155RequestHandler.d.ts +8 -0
- package/services/wallet-connect-service/handler/Eip155RequestHandler.js +106 -0
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.d.ts +8 -0
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +114 -0
- package/services/wallet-connect-service/helpers.d.ts +12 -0
- package/services/wallet-connect-service/helpers.js +67 -0
- package/services/wallet-connect-service/index.d.ts +20 -0
- package/services/wallet-connect-service/index.js +265 -0
- package/services/wallet-connect-service/types.d.ts +46 -0
- package/services/wallet-connect-service/types.js +20 -0
- package/utils/array.d.ts +1 -0
- package/utils/array.js +10 -0
- package/utils/environment.d.ts +2 -0
- package/utils/environment.js +59 -0
- package/utils/index.d.ts +4 -0
- package/utils/index.js +10 -2
- package/utils/lazy.d.ts +2 -0
- package/utils/lazy.js +43 -0
|
@@ -6,12 +6,12 @@ import { EvmProviderError } from '@subwallet/extension-base/background/errors/Ev
|
|
|
6
6
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
7
7
|
import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
8
8
|
import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
9
|
-
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH } from '@subwallet/extension-base/constants';
|
|
9
|
+
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
10
10
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
11
11
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
12
12
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
13
|
-
import { _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
|
|
14
|
-
import { _getEvmChainId, _getSubstrateGenesisHash, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _isSubstrateParaChain, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
|
+
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
|
|
14
|
+
import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _isSubstrateParaChain, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
|
|
15
15
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
16
16
|
import { HistoryService } from '@subwallet/extension-base/services/history-service';
|
|
17
17
|
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
@@ -24,7 +24,9 @@ import DatabaseService from '@subwallet/extension-base/services/storage-service/
|
|
|
24
24
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
25
25
|
import { SUBSCAN_CHAIN_MAP_REVERSE } from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
|
|
26
26
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
27
|
+
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
27
28
|
import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
|
|
29
|
+
import { stripUrl } from '@subwallet/extension-base/utils';
|
|
28
30
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
29
31
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
30
32
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
@@ -35,6 +37,9 @@ import { assert, BN, hexStripPrefix, hexToU8a, isHex, logger as createLogger, u8
|
|
|
35
37
|
import { base64Decode, isEthereumAddress, keyExtractSuri } from '@polkadot/util-crypto';
|
|
36
38
|
import { KoniCron } from "../cron.js";
|
|
37
39
|
import { KoniSubscription } from "../subscription.js";
|
|
40
|
+
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
42
|
+
const passworder = require('browser-passworder');
|
|
38
43
|
const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
|
|
39
44
|
|
|
40
45
|
// List of providers passed into constructor. This is the list of providers
|
|
@@ -65,6 +70,8 @@ export default class KoniState {
|
|
|
65
70
|
crowdloanMap = generateDefaultCrowdloanMap();
|
|
66
71
|
crowdloanSubject = new Subject();
|
|
67
72
|
nftSubject = new Subject();
|
|
73
|
+
mantaPayConfigSubject = new Subject();
|
|
74
|
+
isMantaPayEnabled = false;
|
|
68
75
|
stakingSubject = new Subject();
|
|
69
76
|
chainStakingMetadataSubject = new Subject();
|
|
70
77
|
stakingNominatorMetadataSubject = new Subject();
|
|
@@ -92,6 +99,7 @@ export default class KoniState {
|
|
|
92
99
|
this.balanceService = new BalanceService(this.chainService);
|
|
93
100
|
this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
|
|
94
101
|
this.transactionService = new TransactionService(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
|
|
102
|
+
this.walletConnectService = new WalletConnectService(this, this.requestService);
|
|
95
103
|
this.migrationService = new MigrationService(this);
|
|
96
104
|
this.subscription = new KoniSubscription(this, this.dbService);
|
|
97
105
|
this.cron = new KoniCron(this, this.subscription, this.dbService);
|
|
@@ -204,11 +212,25 @@ export default class KoniState {
|
|
|
204
212
|
this.onAccountRemove();
|
|
205
213
|
await this.startSubscription();
|
|
206
214
|
}
|
|
215
|
+
async initMantaPay(password) {
|
|
216
|
+
const mantaPayConfig = await this.chainService.mantaPay.getMantaPayFirstConfig(_DEFAULT_MANTA_ZK_CHAIN);
|
|
217
|
+
if (mantaPayConfig && mantaPayConfig.enabled && !this.isMantaPayEnabled) {
|
|
218
|
+
// only init the first login
|
|
219
|
+
console.debug('Initiating MantaPay for', mantaPayConfig.address);
|
|
220
|
+
await this.enableMantaPay(false, mantaPayConfig.address, password);
|
|
221
|
+
console.debug('Initiated MantaPay for', mantaPayConfig.address);
|
|
222
|
+
this.isMantaPayEnabled = true;
|
|
223
|
+
this.eventService.emit('mantaPay.enable', mantaPayConfig.address);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
207
226
|
async startSubscription() {
|
|
208
227
|
await this.eventService.waitKeyringReady;
|
|
209
228
|
this.dbService.subscribeChainStakingMetadata([], data => {
|
|
210
229
|
this.chainStakingMetadataSubject.next(data);
|
|
211
230
|
});
|
|
231
|
+
this.dbService.subscribeMantaPayConfig(_DEFAULT_MANTA_ZK_CHAIN, data => {
|
|
232
|
+
this.mantaPayConfigSubject.next(data);
|
|
233
|
+
});
|
|
212
234
|
let unsub;
|
|
213
235
|
this.keyringService.accountSubject.subscribe(accounts => {
|
|
214
236
|
// TODO: improve this
|
|
@@ -281,6 +303,10 @@ export default class KoniState {
|
|
|
281
303
|
async getNominatorMetadata() {
|
|
282
304
|
return this.dbService.getNominatorMetadata();
|
|
283
305
|
}
|
|
306
|
+
async getMantaPayConfig(chain) {
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
308
|
+
return this.dbService.getMantaPayConfig(chain);
|
|
309
|
+
}
|
|
284
310
|
async getStaking() {
|
|
285
311
|
const addresses = this.getDecodedAddresses();
|
|
286
312
|
const stakings = await this.dbService.getStakings(addresses, this.activeChainSlugs);
|
|
@@ -302,6 +328,9 @@ export default class KoniState {
|
|
|
302
328
|
async getPooledStakingRecordsByAddress(addresses) {
|
|
303
329
|
return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
|
|
304
330
|
}
|
|
331
|
+
subscribeMantaPayConfig() {
|
|
332
|
+
return this.mantaPayConfigSubject;
|
|
333
|
+
}
|
|
305
334
|
subscribeStaking() {
|
|
306
335
|
return this.stakingSubject;
|
|
307
336
|
}
|
|
@@ -871,8 +900,13 @@ export default class KoniState {
|
|
|
871
900
|
return result;
|
|
872
901
|
};
|
|
873
902
|
async disableChain(chainSlug) {
|
|
874
|
-
// const defaultChains = this.getDefaultNetworkKeys();
|
|
875
903
|
await this.chainService.updateAssetSettingByChain(chainSlug, false);
|
|
904
|
+
if (_MANTA_ZK_CHAIN_GROUP.includes(chainSlug)) {
|
|
905
|
+
const mantaPayConfig = await this.chainService.mantaPay.getMantaPayFirstConfig(_DEFAULT_MANTA_ZK_CHAIN);
|
|
906
|
+
if (mantaPayConfig && mantaPayConfig.enabled && this.isMantaPayEnabled) {
|
|
907
|
+
await this.disableMantaPay(mantaPayConfig.address);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
876
910
|
return this.chainService.disableChain(chainSlug);
|
|
877
911
|
}
|
|
878
912
|
async enableChain(chainSlug, enableTokens = true) {
|
|
@@ -1248,9 +1282,10 @@ export default class KoniState {
|
|
|
1248
1282
|
const transactionData = {
|
|
1249
1283
|
...transaction
|
|
1250
1284
|
};
|
|
1285
|
+
const token = this.chainService.getNativeTokenInfo(networkKey);
|
|
1251
1286
|
if (eType === ExtrinsicType.TRANSFER_BALANCE) {
|
|
1252
1287
|
// @ts-ignore
|
|
1253
|
-
transactionData.tokenSlug =
|
|
1288
|
+
transactionData.tokenSlug = token.slug;
|
|
1254
1289
|
}
|
|
1255
1290
|
|
|
1256
1291
|
// Custom handle this instead of general handler transaction
|
|
@@ -1261,7 +1296,13 @@ export default class KoniState {
|
|
|
1261
1296
|
url,
|
|
1262
1297
|
data: transactionData,
|
|
1263
1298
|
extrinsicType: eType,
|
|
1264
|
-
chainType: ChainType.EVM
|
|
1299
|
+
chainType: ChainType.EVM,
|
|
1300
|
+
estimateFee: {
|
|
1301
|
+
value: estimateGas,
|
|
1302
|
+
symbol: token.symbol,
|
|
1303
|
+
decimals: token.decimals || 18
|
|
1304
|
+
},
|
|
1305
|
+
id
|
|
1265
1306
|
});
|
|
1266
1307
|
|
|
1267
1308
|
// Wait extrinsic hash
|
|
@@ -1292,48 +1333,51 @@ export default class KoniState {
|
|
|
1292
1333
|
return await this.requestService.completeConfirmation(request);
|
|
1293
1334
|
}
|
|
1294
1335
|
onInstall() {
|
|
1295
|
-
const singleModes = Object.values(_PREDEFINED_SINGLE_MODES);
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1336
|
+
// const singleModes = Object.values(_PREDEFINED_SINGLE_MODES);
|
|
1337
|
+
|
|
1338
|
+
// This logic is moved to installation.ts
|
|
1339
|
+
// try {
|
|
1340
|
+
// // Open expand page
|
|
1341
|
+
// const url = `${chrome.extension.getURL('index.html')}#/`;
|
|
1342
|
+
//
|
|
1343
|
+
// withErrorLog(() => chrome.tabs.create({ url }));
|
|
1344
|
+
// } catch (e) {
|
|
1345
|
+
// console.error(e);
|
|
1346
|
+
// }
|
|
1347
|
+
|
|
1348
|
+
// const setUpSingleMode = ({ networkKeys, theme }: SingleModeJson) => {
|
|
1349
|
+
// networkKeys.forEach((key) => {
|
|
1350
|
+
// this.enableChain(key).catch(console.error);
|
|
1351
|
+
// });
|
|
1352
|
+
//
|
|
1353
|
+
// const chainInfo = this.chainService.getChainInfoByKey(networkKeys[0]);
|
|
1354
|
+
// const genesisHash = _getSubstrateGenesisHash(chainInfo);
|
|
1355
|
+
//
|
|
1356
|
+
// this.setCurrentAccount({
|
|
1357
|
+
// address: ALL_ACCOUNT_KEY,
|
|
1358
|
+
// currentGenesisHash: genesisHash.length > 0 ? genesisHash : null
|
|
1359
|
+
// });
|
|
1360
|
+
// this.setTheme(theme);
|
|
1361
|
+
// };
|
|
1362
|
+
//
|
|
1363
|
+
// chrome.tabs.query({}, function (tabs) {
|
|
1364
|
+
// const openingUrls = tabs.map((t) => t.url);
|
|
1365
|
+
//
|
|
1366
|
+
// const singleMode = singleModes.find(({ autoTriggerDomain }) => {
|
|
1367
|
+
// const urlRegex = new RegExp(autoTriggerDomain);
|
|
1368
|
+
//
|
|
1369
|
+
// return Boolean(openingUrls.find((url) => {
|
|
1370
|
+
// return url && urlRegex.test(url);
|
|
1371
|
+
// }));
|
|
1372
|
+
// });
|
|
1373
|
+
//
|
|
1374
|
+
// if (singleMode) {
|
|
1375
|
+
// // Wait for everything is ready before enable single mode
|
|
1376
|
+
// setTimeout(() => {
|
|
1377
|
+
// setUpSingleMode(singleMode);
|
|
1378
|
+
// }, 999);
|
|
1379
|
+
// }
|
|
1380
|
+
// });
|
|
1337
1381
|
}
|
|
1338
1382
|
get activeNetworks() {
|
|
1339
1383
|
return this.chainService.getActiveChainInfos();
|
|
@@ -1420,9 +1464,6 @@ export default class KoniState {
|
|
|
1420
1464
|
createUnsubscriptionHandle(id, unsubscribe) {
|
|
1421
1465
|
this.unsubscriptionMap[id] = unsubscribe;
|
|
1422
1466
|
}
|
|
1423
|
-
updateChainConnectionStatus(chain, status) {
|
|
1424
|
-
this.chainService.setChainConnectionStatus(chain, status);
|
|
1425
|
-
}
|
|
1426
1467
|
async autoEnableChains(addresses) {
|
|
1427
1468
|
const assetMap = this.chainService.getAssetRegistry();
|
|
1428
1469
|
const promiseList = addresses.map(address => {
|
|
@@ -1505,7 +1546,7 @@ export default class KoniState {
|
|
|
1505
1546
|
const result = {
|
|
1506
1547
|
...value
|
|
1507
1548
|
};
|
|
1508
|
-
const url =
|
|
1549
|
+
const url = stripUrl(_url);
|
|
1509
1550
|
result[url] = {
|
|
1510
1551
|
pass: true
|
|
1511
1552
|
};
|
|
@@ -1525,6 +1566,151 @@ export default class KoniState {
|
|
|
1525
1566
|
this.settingService.resetWallet();
|
|
1526
1567
|
}
|
|
1527
1568
|
this.chainService.resetWallet(resetAll);
|
|
1569
|
+
await this.walletConnectService.resetWallet(resetAll);
|
|
1528
1570
|
await this.chainService.init();
|
|
1529
1571
|
}
|
|
1572
|
+
async enableMantaPay(updateStore, address, password, seedPhrase) {
|
|
1573
|
+
var _this$chainService$ma, _this$chainService$ma6;
|
|
1574
|
+
if (!address || isEthereumAddress(address)) {
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
this.chainService.mantaPay.setCurrentAddress(address);
|
|
1578
|
+
await ((_this$chainService$ma = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma === void 0 ? void 0 : _this$chainService$ma.initialSigner());
|
|
1579
|
+
if (updateStore && seedPhrase) {
|
|
1580
|
+
var _this$chainService$ma2, _this$chainService$ma3, _this$chainService$ma4;
|
|
1581
|
+
// first time initiation
|
|
1582
|
+
await ((_this$chainService$ma2 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma2 === void 0 ? void 0 : _this$chainService$ma2.loadUserSeedPhrase(seedPhrase));
|
|
1583
|
+
const authContext = await ((_this$chainService$ma3 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma3 === void 0 ? void 0 : _this$chainService$ma3.getAuthorizationContext());
|
|
1584
|
+
await ((_this$chainService$ma4 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma4 === void 0 ? void 0 : _this$chainService$ma4.loadAuthorizationContext(authContext));
|
|
1585
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
1586
|
+
const encryptedData = await passworder.encrypt(password, authContext);
|
|
1587
|
+
await this.chainService.mantaPay.saveMantaAuthContext({
|
|
1588
|
+
chain: _DEFAULT_MANTA_ZK_CHAIN,
|
|
1589
|
+
address,
|
|
1590
|
+
data: encryptedData
|
|
1591
|
+
});
|
|
1592
|
+
} else {
|
|
1593
|
+
var _this$chainService$ma5;
|
|
1594
|
+
const authContext = await this.chainService.mantaPay.getMantaAuthContext(address, _DEFAULT_MANTA_ZK_CHAIN);
|
|
1595
|
+
|
|
1596
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
1597
|
+
const decryptedData = await passworder.decrypt(password, authContext.data);
|
|
1598
|
+
|
|
1599
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
1600
|
+
const proofAuthKey = new Uint8Array(Object.values(decryptedData.proof_authorization_key));
|
|
1601
|
+
await ((_this$chainService$ma5 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma5 === void 0 ? void 0 : _this$chainService$ma5.loadAuthorizationContext({
|
|
1602
|
+
proof_authorization_key: proofAuthKey
|
|
1603
|
+
}));
|
|
1604
|
+
}
|
|
1605
|
+
const zkAddress = await ((_this$chainService$ma6 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma6 === void 0 ? void 0 : _this$chainService$ma6.getZkAddress());
|
|
1606
|
+
if (updateStore) {
|
|
1607
|
+
var _this$chainService$ma7, _this$chainService$ma8;
|
|
1608
|
+
await this.chainService.mantaPay.saveMantaPayConfig({
|
|
1609
|
+
address,
|
|
1610
|
+
zkAddress: zkAddress,
|
|
1611
|
+
enabled: true,
|
|
1612
|
+
chain: (_this$chainService$ma7 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma7 === void 0 ? void 0 : (_this$chainService$ma8 = _this$chainService$ma7.network) === null || _this$chainService$ma8 === void 0 ? void 0 : _this$chainService$ma8.toLowerCase(),
|
|
1613
|
+
isInitialSync: false
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
this.isMantaPayEnabled = true;
|
|
1617
|
+
return zkAddress;
|
|
1618
|
+
}
|
|
1619
|
+
async disableMantaPay(address) {
|
|
1620
|
+
var _this$chainService$ma9, _this$chainService$ma10;
|
|
1621
|
+
const config = await this.chainService.mantaPay.getMantaPayConfig(address, _DEFAULT_MANTA_ZK_CHAIN);
|
|
1622
|
+
if (!config) {
|
|
1623
|
+
return false;
|
|
1624
|
+
}
|
|
1625
|
+
await ((_this$chainService$ma9 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma9 === void 0 ? void 0 : _this$chainService$ma9.dropAuthorizationContext());
|
|
1626
|
+
await ((_this$chainService$ma10 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma10 === void 0 ? void 0 : _this$chainService$ma10.dropUserSeedPhrase());
|
|
1627
|
+
// await this.chainService.mantaPay.privateWallet?.resetState();
|
|
1628
|
+
await this.chainService.mantaPay.deleteMantaPayConfig(address, _DEFAULT_MANTA_ZK_CHAIN);
|
|
1629
|
+
await this.chainService.mantaPay.deleteMantaAuthContext(address, _DEFAULT_MANTA_ZK_CHAIN);
|
|
1630
|
+
this.chainService.setMantaZkAssetSettings(false);
|
|
1631
|
+
this.isMantaPayEnabled = false;
|
|
1632
|
+
return true;
|
|
1633
|
+
}
|
|
1634
|
+
async initialSyncMantaPay(address) {
|
|
1635
|
+
var _this$chainService$ma11, _this$chainService$ma12, _this$chainService$ma13;
|
|
1636
|
+
if (!address || isEthereumAddress(address)) {
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
this.chainService.mantaPay.setCurrentAddress(address);
|
|
1640
|
+
await ((_this$chainService$ma11 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma11 === void 0 ? void 0 : (_this$chainService$ma12 = _this$chainService$ma11.baseWallet) === null || _this$chainService$ma12 === void 0 ? void 0 : _this$chainService$ma12.isApiReady());
|
|
1641
|
+
const syncResult = await ((_this$chainService$ma13 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma13 === void 0 ? void 0 : _this$chainService$ma13.initialWalletSync());
|
|
1642
|
+
await this.chainService.mantaPay.updateMantaPayConfig(address, _DEFAULT_MANTA_ZK_CHAIN, {
|
|
1643
|
+
isInitialSync: true
|
|
1644
|
+
});
|
|
1645
|
+
this.eventService.emit('mantaPay.initSync', undefined);
|
|
1646
|
+
return syncResult;
|
|
1647
|
+
}
|
|
1648
|
+
getMantaZkBalance() {
|
|
1649
|
+
var _this$chainService, _this$chainService$ma14, _this$chainService$ma15, _this$chainService2, _this$chainService2$m, _this$chainService$ma16;
|
|
1650
|
+
if (!this.chainService || !this.chainService.mantaPay) {
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
if (!((_this$chainService = this.chainService) !== null && _this$chainService !== void 0 && (_this$chainService$ma14 = _this$chainService.mantaPay) !== null && _this$chainService$ma14 !== void 0 && (_this$chainService$ma15 = _this$chainService$ma14.privateWallet) !== null && _this$chainService$ma15 !== void 0 && _this$chainService$ma15.initialSyncIsFinished)) {
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
const chain = (_this$chainService2 = this.chainService) === null || _this$chainService2 === void 0 ? void 0 : (_this$chainService2$m = _this$chainService2.mantaPay.privateWallet) === null || _this$chainService2$m === void 0 ? void 0 : _this$chainService2$m.network;
|
|
1657
|
+
if (!chain) {
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
const assetMap = this.chainService.getMantaZkAssets(chain === null || chain === void 0 ? void 0 : chain.toLowerCase());
|
|
1661
|
+
(_this$chainService$ma16 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma16 === void 0 ? void 0 : _this$chainService$ma16.getMultiZkBalance(Object.values(assetMap).map(tokenInfo => new BN(_getTokenOnChainAssetId(tokenInfo)))).then(zkBalances => {
|
|
1662
|
+
const assetList = Object.values(assetMap);
|
|
1663
|
+
for (let i = 0; i < assetList.length; i++) {
|
|
1664
|
+
var _zkBalances$i;
|
|
1665
|
+
const balanceItem = {
|
|
1666
|
+
tokenSlug: assetList[i].slug,
|
|
1667
|
+
state: APIItemState.PENDING,
|
|
1668
|
+
free: '0',
|
|
1669
|
+
locked: '0'
|
|
1670
|
+
};
|
|
1671
|
+
balanceItem.free = ((_zkBalances$i = zkBalances[i]) === null || _zkBalances$i === void 0 ? void 0 : _zkBalances$i.toString()) || '0';
|
|
1672
|
+
balanceItem.state = APIItemState.READY;
|
|
1673
|
+
this.setBalanceItem(balanceItem.tokenSlug, balanceItem);
|
|
1674
|
+
}
|
|
1675
|
+
}).catch(console.warn);
|
|
1676
|
+
}
|
|
1677
|
+
subscribeMantaPayBalance() {
|
|
1678
|
+
let interval;
|
|
1679
|
+
this.chainService.mantaPay.getMantaPayConfig(this.keyringService.currentAccount.address, _DEFAULT_MANTA_ZK_CHAIN).then(config => {
|
|
1680
|
+
if (config && config.enabled && config.isInitialSync) {
|
|
1681
|
+
this.getMantaZkBalance();
|
|
1682
|
+
interval = setInterval(this.getMantaZkBalance, MANTA_PAY_BALANCE_INTERVAL);
|
|
1683
|
+
}
|
|
1684
|
+
}).catch(console.warn);
|
|
1685
|
+
return () => {
|
|
1686
|
+
interval && clearInterval(interval);
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
async syncMantaPay() {
|
|
1690
|
+
var _this$chainService3, _this$chainService3$m, _this$chainService3$m2;
|
|
1691
|
+
const config = await this.chainService.mantaPay.getMantaPayFirstConfig(_DEFAULT_MANTA_ZK_CHAIN);
|
|
1692
|
+
if (!config.isInitialSync) {
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
if ((_this$chainService3 = this.chainService) !== null && _this$chainService3 !== void 0 && (_this$chainService3$m = _this$chainService3.mantaPay) !== null && _this$chainService3$m !== void 0 && (_this$chainService3$m2 = _this$chainService3$m.privateWallet) !== null && _this$chainService3$m2 !== void 0 && _this$chainService3$m2.initialSyncIsFinished) {
|
|
1696
|
+
var _this$chainService4, _this$chainService4$m, _this$chainService4$m2;
|
|
1697
|
+
await ((_this$chainService4 = this.chainService) === null || _this$chainService4 === void 0 ? void 0 : (_this$chainService4$m = _this$chainService4.mantaPay) === null || _this$chainService4$m === void 0 ? void 0 : (_this$chainService4$m2 = _this$chainService4$m.privateWallet) === null || _this$chainService4$m2 === void 0 ? void 0 : _this$chainService4$m2.walletSync());
|
|
1698
|
+
} else {
|
|
1699
|
+
var _this$chainService5, _this$chainService5$m, _this$chainService5$m2;
|
|
1700
|
+
await ((_this$chainService5 = this.chainService) === null || _this$chainService5 === void 0 ? void 0 : (_this$chainService5$m = _this$chainService5.mantaPay) === null || _this$chainService5$m === void 0 ? void 0 : (_this$chainService5$m2 = _this$chainService5$m.privateWallet) === null || _this$chainService5$m2 === void 0 ? void 0 : _this$chainService5$m2.initialWalletSync());
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
async getMantaPayZkBalance(address, tokenInfo) {
|
|
1704
|
+
var _this$chainService$ma17;
|
|
1705
|
+
const bnAssetId = new BN(_getTokenOnChainAssetId(tokenInfo));
|
|
1706
|
+
const balance = await ((_this$chainService$ma17 = this.chainService.mantaPay.privateWallet) === null || _this$chainService$ma17 === void 0 ? void 0 : _this$chainService$ma17.getZkBalance(bnAssetId));
|
|
1707
|
+
return {
|
|
1708
|
+
decimals: tokenInfo.decimals || 0,
|
|
1709
|
+
symbol: tokenInfo.symbol,
|
|
1710
|
+
value: (balance === null || balance === void 0 ? void 0 : balance.toString()) || '0'
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
subscribeMantaPaySyncState() {
|
|
1714
|
+
return this.chainService.mantaPay.subscribeSyncState();
|
|
1715
|
+
}
|
|
1530
1716
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
2
|
import { AuthUrlInfo } from '@subwallet/extension-base/background/handlers/State';
|
|
3
|
+
import { RequestAddPspToken } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
4
|
import { MessageTypes, RequestTypes, ResponseTypes } from '@subwallet/extension-base/background/types';
|
|
4
5
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
6
|
import { RequestArguments } from 'web3-core';
|
|
@@ -46,5 +47,6 @@ export default class KoniTabs {
|
|
|
46
47
|
private handleEvmRequest;
|
|
47
48
|
private handleEvmSend;
|
|
48
49
|
isEvmPublicRequest(type: string, request: RequestArguments): boolean;
|
|
50
|
+
addPspToken(id: string, url: string, { genesisHash, tokenInfo: input }: RequestAddPspToken): Promise<true>;
|
|
49
51
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], url: string, port: chrome.runtime.Port): Promise<ResponseTypes[keyof ResponseTypes]>;
|
|
50
52
|
}
|
|
@@ -13,16 +13,11 @@ import { PHISHING_PAGE_REDIRECT } from '@subwallet/extension-base/defaults';
|
|
|
13
13
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
14
14
|
import { _generateCustomProviderKey } from '@subwallet/extension-base/services/chain-service/utils';
|
|
15
15
|
import { DEFAULT_CHAIN_PATROL_ENABLE } from '@subwallet/extension-base/services/setting-service/constants';
|
|
16
|
-
import { canDerive } from '@subwallet/extension-base/utils';
|
|
16
|
+
import { canDerive, stripUrl } from '@subwallet/extension-base/utils';
|
|
17
17
|
import keyring from '@subwallet/ui-keyring';
|
|
18
18
|
import Web3 from 'web3';
|
|
19
19
|
import { checkIfDenied } from '@polkadot/phishing';
|
|
20
20
|
import { assert, isNumber } from '@polkadot/util';
|
|
21
|
-
function stripUrl(url) {
|
|
22
|
-
assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
|
|
23
|
-
const parts = url.split('/');
|
|
24
|
-
return parts[2];
|
|
25
|
-
}
|
|
26
21
|
function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthType) {
|
|
27
22
|
const accountSelected = authInfo ? authInfo.isAllowed ? Object.keys(authInfo.isAllowedMap).filter(address => authInfo.isAllowedMap[address]) : [] : [];
|
|
28
23
|
let authTypeFilter = ({
|
|
@@ -401,7 +396,7 @@ export default class KoniTabs {
|
|
|
401
396
|
tokenInfo.contractError = true;
|
|
402
397
|
} else {
|
|
403
398
|
tokenInfo.slug = validate === null || validate === void 0 ? void 0 : validate.existedSlug;
|
|
404
|
-
tokenInfo.name = validate.name;
|
|
399
|
+
tokenInfo.name = validate.name || tokenInfo.name;
|
|
405
400
|
tokenInfo.symbol = validate.symbol;
|
|
406
401
|
tokenInfo.decimals = validate.decimals;
|
|
407
402
|
}
|
|
@@ -825,6 +820,60 @@ export default class KoniTabs {
|
|
|
825
820
|
return false;
|
|
826
821
|
}
|
|
827
822
|
}
|
|
823
|
+
async addPspToken(id, url, {
|
|
824
|
+
genesisHash,
|
|
825
|
+
tokenInfo: input
|
|
826
|
+
}) {
|
|
827
|
+
const _tokenType = input.type;
|
|
828
|
+
if (_tokenType !== 'psp22' && _tokenType !== 'psp34') {
|
|
829
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, `Assets type ${_tokenType} is not supported`);
|
|
830
|
+
}
|
|
831
|
+
if (!input.address || !input.symbol) {
|
|
832
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Assets params require address and symbol');
|
|
833
|
+
}
|
|
834
|
+
const [chain] = this.#koniState.findNetworkKeyByGenesisHash(genesisHash);
|
|
835
|
+
if (!chain) {
|
|
836
|
+
throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, 'Current chain is not available');
|
|
837
|
+
}
|
|
838
|
+
const state = this.#koniState.getChainStateByKey(chain);
|
|
839
|
+
if (!state.active) {
|
|
840
|
+
await this.#koniState.enableChain(chain, false);
|
|
841
|
+
const api = this.#koniState.getSubstrateApi(chain);
|
|
842
|
+
await api.isReady;
|
|
843
|
+
}
|
|
844
|
+
const tokenType = _tokenType === 'psp22' ? _AssetType.PSP22 : _AssetType.PSP34;
|
|
845
|
+
const tokenInfo = {
|
|
846
|
+
slug: '',
|
|
847
|
+
type: tokenType,
|
|
848
|
+
name: input.symbol || '',
|
|
849
|
+
contractAddress: input.address,
|
|
850
|
+
symbol: input.symbol || '',
|
|
851
|
+
decimals: input.decimals || 0,
|
|
852
|
+
originChain: chain,
|
|
853
|
+
contractError: false,
|
|
854
|
+
validated: false
|
|
855
|
+
};
|
|
856
|
+
this.#koniState.validateCustomAsset({
|
|
857
|
+
type: tokenType,
|
|
858
|
+
contractAddress: input.address,
|
|
859
|
+
originChain: chain
|
|
860
|
+
}).then(validate => {
|
|
861
|
+
if (validate.contractError) {
|
|
862
|
+
tokenInfo.contractError = true;
|
|
863
|
+
} else {
|
|
864
|
+
tokenInfo.slug = validate === null || validate === void 0 ? void 0 : validate.existedSlug;
|
|
865
|
+
tokenInfo.name = validate.name || tokenInfo.name;
|
|
866
|
+
tokenInfo.symbol = validate.symbol;
|
|
867
|
+
tokenInfo.decimals = validate.decimals;
|
|
868
|
+
}
|
|
869
|
+
}).catch(() => {
|
|
870
|
+
tokenInfo.contractError = true;
|
|
871
|
+
}).finally(() => {
|
|
872
|
+
tokenInfo.validated = true;
|
|
873
|
+
this.#koniState.requestService.updateConfirmation(id, 'addTokenRequest', tokenInfo);
|
|
874
|
+
});
|
|
875
|
+
return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
|
|
876
|
+
}
|
|
828
877
|
async handle(id, type, request, url, port) {
|
|
829
878
|
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
830
879
|
return this.redirectIfPhishing(url);
|
|
@@ -860,6 +909,8 @@ export default class KoniTabs {
|
|
|
860
909
|
return this.rpcSubscribeConnected(request, id, port);
|
|
861
910
|
case 'pub(rpc.unsubscribe)':
|
|
862
911
|
return this.rpcUnsubscribe(request, port);
|
|
912
|
+
case 'pub(token.add)':
|
|
913
|
+
return this.addPspToken(id, url, request);
|
|
863
914
|
|
|
864
915
|
///
|
|
865
916
|
case 'pub(authorize.tabV2)':
|
|
@@ -151,12 +151,15 @@ export class KoniSubscription {
|
|
|
151
151
|
const unsub = subscribeBalance(addresses, filteredChainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
152
152
|
this.state.setBalanceItem(result.tokenSlug, result);
|
|
153
153
|
});
|
|
154
|
+
const unsub2 = this.state.subscribeMantaPayBalance();
|
|
154
155
|
if (onlyRunOnFirstTime) {
|
|
155
156
|
unsub && unsub();
|
|
157
|
+
unsub2 && unsub2();
|
|
156
158
|
return;
|
|
157
159
|
}
|
|
158
160
|
return () => {
|
|
159
161
|
unsub && unsub();
|
|
162
|
+
unsub2 && unsub2();
|
|
160
163
|
};
|
|
161
164
|
}
|
|
162
165
|
initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime) {
|