@subwallet/extension-base 1.0.13-0 → 1.1.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.
Files changed (67) hide show
  1. package/background/KoniTypes.d.ts +37 -0
  2. package/background/KoniTypes.js +8 -1
  3. package/background/handlers/Extension.js +17 -2
  4. package/background/types.d.ts +6 -1
  5. package/cjs/background/KoniTypes.js +10 -2
  6. package/cjs/background/handlers/Extension.js +22 -6
  7. package/cjs/constants/index.js +7 -1
  8. package/cjs/defaults.js +1 -1
  9. package/cjs/koni/api/dotsama/balance.js +5 -0
  10. package/cjs/koni/api/dotsama/transfer.js +6 -0
  11. package/cjs/koni/background/cron.js +12 -1
  12. package/cjs/koni/background/handlers/Extension.js +324 -147
  13. package/cjs/koni/background/handlers/State.js +222 -50
  14. package/cjs/koni/background/subscription.js +3 -0
  15. package/cjs/packageInfo.js +1 -1
  16. package/cjs/services/chain-service/constants.js +10 -4
  17. package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
  18. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
  19. package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
  20. package/cjs/services/chain-service/index.js +54 -5
  21. package/cjs/services/chain-service/utils.js +6 -1
  22. package/cjs/services/event-service/types.js +3 -1
  23. package/cjs/services/storage-service/DatabaseService.js +31 -1
  24. package/cjs/services/storage-service/databases/index.js +3 -0
  25. package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
  26. package/cjs/utils/index.js +12 -0
  27. package/cjs/utils/lazy.js +52 -0
  28. package/constants/index.d.ts +2 -0
  29. package/constants/index.js +2 -0
  30. package/defaults.d.ts +1 -1
  31. package/defaults.js +1 -1
  32. package/koni/api/dotsama/balance.js +6 -1
  33. package/koni/api/dotsama/transfer.js +7 -1
  34. package/koni/background/cron.d.ts +1 -0
  35. package/koni/background/cron.js +13 -2
  36. package/koni/background/handlers/Extension.d.ts +5 -0
  37. package/koni/background/handlers/Extension.js +186 -11
  38. package/koni/background/handlers/State.d.ts +15 -3
  39. package/koni/background/handlers/State.js +224 -49
  40. package/koni/background/subscription.js +3 -0
  41. package/package.json +22 -5
  42. package/packageInfo.js +1 -1
  43. package/services/chain-service/constants.d.ts +3 -0
  44. package/services/chain-service/constants.js +5 -2
  45. package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
  46. package/services/chain-service/handler/SubstrateApi.js +2 -1
  47. package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
  48. package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
  49. package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
  50. package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
  51. package/services/chain-service/handler/types.d.ts +2 -0
  52. package/services/chain-service/index.d.ts +7 -3
  53. package/services/chain-service/index.js +56 -7
  54. package/services/chain-service/utils.d.ts +1 -0
  55. package/services/chain-service/utils.js +5 -1
  56. package/services/event-service/types.d.ts +3 -0
  57. package/services/event-service/types.js +3 -1
  58. package/services/storage-service/DatabaseService.d.ts +10 -1
  59. package/services/storage-service/DatabaseService.js +31 -1
  60. package/services/storage-service/databases/index.d.ts +2 -0
  61. package/services/storage-service/databases/index.js +3 -0
  62. package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
  63. package/services/storage-service/db-stores/MantaPay.js +32 -0
  64. package/utils/index.d.ts +1 -0
  65. package/utils/index.js +2 -1
  66. package/utils/lazy.d.ts +2 -0
  67. 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';
@@ -37,6 +37,9 @@ import { assert, BN, hexStripPrefix, hexToU8a, isHex, logger as createLogger, u8
37
37
  import { base64Decode, isEthereumAddress, keyExtractSuri } from '@polkadot/util-crypto';
38
38
  import { KoniCron } from "../cron.js";
39
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');
40
43
  const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
41
44
 
42
45
  // List of providers passed into constructor. This is the list of providers
@@ -67,6 +70,8 @@ export default class KoniState {
67
70
  crowdloanMap = generateDefaultCrowdloanMap();
68
71
  crowdloanSubject = new Subject();
69
72
  nftSubject = new Subject();
73
+ mantaPayConfigSubject = new Subject();
74
+ isMantaPayEnabled = false;
70
75
  stakingSubject = new Subject();
71
76
  chainStakingMetadataSubject = new Subject();
72
77
  stakingNominatorMetadataSubject = new Subject();
@@ -207,11 +212,25 @@ export default class KoniState {
207
212
  this.onAccountRemove();
208
213
  await this.startSubscription();
209
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
+ }
210
226
  async startSubscription() {
211
227
  await this.eventService.waitKeyringReady;
212
228
  this.dbService.subscribeChainStakingMetadata([], data => {
213
229
  this.chainStakingMetadataSubject.next(data);
214
230
  });
231
+ this.dbService.subscribeMantaPayConfig(_DEFAULT_MANTA_ZK_CHAIN, data => {
232
+ this.mantaPayConfigSubject.next(data);
233
+ });
215
234
  let unsub;
216
235
  this.keyringService.accountSubject.subscribe(accounts => {
217
236
  // TODO: improve this
@@ -284,6 +303,10 @@ export default class KoniState {
284
303
  async getNominatorMetadata() {
285
304
  return this.dbService.getNominatorMetadata();
286
305
  }
306
+ async getMantaPayConfig(chain) {
307
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
308
+ return this.dbService.getMantaPayConfig(chain);
309
+ }
287
310
  async getStaking() {
288
311
  const addresses = this.getDecodedAddresses();
289
312
  const stakings = await this.dbService.getStakings(addresses, this.activeChainSlugs);
@@ -305,6 +328,9 @@ export default class KoniState {
305
328
  async getPooledStakingRecordsByAddress(addresses) {
306
329
  return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
307
330
  }
331
+ subscribeMantaPayConfig() {
332
+ return this.mantaPayConfigSubject;
333
+ }
308
334
  subscribeStaking() {
309
335
  return this.stakingSubject;
310
336
  }
@@ -874,8 +900,13 @@ export default class KoniState {
874
900
  return result;
875
901
  };
876
902
  async disableChain(chainSlug) {
877
- // const defaultChains = this.getDefaultNetworkKeys();
878
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
+ }
879
910
  return this.chainService.disableChain(chainSlug);
880
911
  }
881
912
  async enableChain(chainSlug, enableTokens = true) {
@@ -1302,48 +1333,51 @@ export default class KoniState {
1302
1333
  return await this.requestService.completeConfirmation(request);
1303
1334
  }
1304
1335
  onInstall() {
1305
- const singleModes = Object.values(_PREDEFINED_SINGLE_MODES);
1306
- try {
1307
- // Open expand page
1308
- const url = `${chrome.extension.getURL('index.html')}#/`;
1309
- withErrorLog(() => chrome.tabs.create({
1310
- url
1311
- }));
1312
- } catch (e) {
1313
- console.error(e);
1314
- }
1315
- const setUpSingleMode = ({
1316
- networkKeys,
1317
- theme
1318
- }) => {
1319
- networkKeys.forEach(key => {
1320
- this.enableChain(key).catch(console.error);
1321
- });
1322
- const chainInfo = this.chainService.getChainInfoByKey(networkKeys[0]);
1323
- const genesisHash = _getSubstrateGenesisHash(chainInfo);
1324
- this.setCurrentAccount({
1325
- address: ALL_ACCOUNT_KEY,
1326
- currentGenesisHash: genesisHash.length > 0 ? genesisHash : null
1327
- });
1328
- this.setTheme(theme);
1329
- };
1330
- chrome.tabs.query({}, function (tabs) {
1331
- const openingUrls = tabs.map(t => t.url);
1332
- const singleMode = singleModes.find(({
1333
- autoTriggerDomain
1334
- }) => {
1335
- const urlRegex = new RegExp(autoTriggerDomain);
1336
- return Boolean(openingUrls.find(url => {
1337
- return url && urlRegex.test(url);
1338
- }));
1339
- });
1340
- if (singleMode) {
1341
- // Wait for everything is ready before enable single mode
1342
- setTimeout(() => {
1343
- setUpSingleMode(singleMode);
1344
- }, 999);
1345
- }
1346
- });
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
+ // });
1347
1381
  }
1348
1382
  get activeNetworks() {
1349
1383
  return this.chainService.getActiveChainInfos();
@@ -1430,9 +1464,6 @@ export default class KoniState {
1430
1464
  createUnsubscriptionHandle(id, unsubscribe) {
1431
1465
  this.unsubscriptionMap[id] = unsubscribe;
1432
1466
  }
1433
- updateChainConnectionStatus(chain, status) {
1434
- this.chainService.setChainConnectionStatus(chain, status);
1435
- }
1436
1467
  async autoEnableChains(addresses) {
1437
1468
  const assetMap = this.chainService.getAssetRegistry();
1438
1469
  const promiseList = addresses.map(address => {
@@ -1538,4 +1569,148 @@ export default class KoniState {
1538
1569
  await this.walletConnectService.resetWallet(resetAll);
1539
1570
  await this.chainService.init();
1540
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
+ }
1541
1716
  }
@@ -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) {
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.13-0",
20
+ "version": "1.1.1",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -530,6 +530,11 @@
530
530
  "require": "./cjs/services/chain-service/handler/light-client/index.js",
531
531
  "default": "./services/chain-service/handler/light-client/index.js"
532
532
  },
533
+ "./services/chain-service/handler/manta/MantaPrivateHandler": {
534
+ "types": "./services/chain-service/handler/manta/MantaPrivateHandler.d.ts",
535
+ "require": "./cjs/services/chain-service/handler/manta/MantaPrivateHandler.js",
536
+ "default": "./services/chain-service/handler/manta/MantaPrivateHandler.js"
537
+ },
533
538
  "./services/chain-service/handler/SubstrateApi": {
534
539
  "types": "./services/chain-service/handler/SubstrateApi.d.ts",
535
540
  "require": "./cjs/services/chain-service/handler/SubstrateApi.js",
@@ -820,6 +825,11 @@
820
825
  "require": "./cjs/services/storage-service/db-stores/Crowdloan.js",
821
826
  "default": "./services/storage-service/db-stores/Crowdloan.js"
822
827
  },
828
+ "./services/storage-service/db-stores/MantaPay": {
829
+ "types": "./services/storage-service/db-stores/MantaPay.d.ts",
830
+ "require": "./cjs/services/storage-service/db-stores/MantaPay.js",
831
+ "default": "./services/storage-service/db-stores/MantaPay.js"
832
+ },
823
833
  "./services/storage-service/db-stores/Metadata": {
824
834
  "types": "./services/storage-service/db-stores/Metadata.d.ts",
825
835
  "require": "./cjs/services/storage-service/db-stores/Metadata.js",
@@ -1100,6 +1110,11 @@
1100
1110
  "require": "./cjs/utils/keyring.js",
1101
1111
  "default": "./utils/keyring.js"
1102
1112
  },
1113
+ "./utils/lazy": {
1114
+ "types": "./utils/lazy.d.ts",
1115
+ "require": "./cjs/utils/lazy.js",
1116
+ "default": "./utils/lazy.js"
1117
+ },
1103
1118
  "./utils/number": {
1104
1119
  "types": "./utils/number.d.ts",
1105
1120
  "require": "./cjs/utils/number.js",
@@ -1144,10 +1159,10 @@
1144
1159
  "@sora-substrate/type-definitions": "^1.17.7",
1145
1160
  "@substrate/connect": "^0.7.26",
1146
1161
  "@subwallet/chain-list": "^0.2.4",
1147
- "@subwallet/extension-base": "^1.0.13-0",
1148
- "@subwallet/extension-chains": "^1.0.13-0",
1149
- "@subwallet/extension-dapp": "^1.0.13-0",
1150
- "@subwallet/extension-inject": "^1.0.13-0",
1162
+ "@subwallet/extension-base": "^1.1.1",
1163
+ "@subwallet/extension-chains": "^1.1.1",
1164
+ "@subwallet/extension-dapp": "^1.1.1",
1165
+ "@subwallet/extension-inject": "^1.1.1",
1151
1166
  "@subwallet/keyring": "^0.0.10",
1152
1167
  "@subwallet/ui-keyring": "^0.0.10",
1153
1168
  "@walletconnect/sign-client": "^2.8.4",
@@ -1156,6 +1171,7 @@
1156
1171
  "axios": "^1.2.1",
1157
1172
  "bignumber.js": "^9.1.1",
1158
1173
  "bn.js": "^5.2.1",
1174
+ "browser-passworder": "^2.0.3",
1159
1175
  "buffer": "^6.0.3",
1160
1176
  "cross-fetch": "^3.1.5",
1161
1177
  "dexie": "^3.2.2",
@@ -1168,6 +1184,7 @@
1168
1184
  "i18next": "^21.9.2",
1169
1185
  "is-buffer": "^2.0.5",
1170
1186
  "json-rpc-engine": "^6.1.0",
1187
+ "manta-extension-sdk": "^1.1.0",
1171
1188
  "moment": "^2.29.4",
1172
1189
  "protobufjs": "^7.1.2",
1173
1190
  "rxjs": "^7.8.1",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.0.13-0'
10
+ version: '1.1.1'
11
11
  };
@@ -70,6 +70,9 @@ export declare const _TRANSFER_CHAIN_GROUP: {
70
70
  export declare const _BALANCE_PARSING_CHAIN_GROUP: {
71
71
  bobabeam: string[];
72
72
  };
73
+ export declare const _MANTA_ZK_CHAIN_GROUP: string[];
74
+ export declare const _ZK_ASSET_PREFIX = "zk";
75
+ export declare const _DEFAULT_MANTA_ZK_CHAIN = "calamari";
73
76
  export declare const _XCM_CHAIN_GROUP: {
74
77
  polkadotXcm: string[];
75
78
  xcmPallet: string[];
@@ -27,7 +27,7 @@ export const _BALANCE_CHAIN_GROUP = {
27
27
  genshiro: ['genshiro_testnet', 'genshiro'],
28
28
  equilibrium_parachain: ['equilibrium_parachain'],
29
29
  bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main'],
30
- statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel'],
30
+ statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari'],
31
31
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'] // perhaps there are some runtime updates
32
32
  };
33
33
 
@@ -189,6 +189,9 @@ export const _TRANSFER_CHAIN_GROUP = {
189
189
  export const _BALANCE_PARSING_CHAIN_GROUP = {
190
190
  bobabeam: ['bobabeam', 'bobabase']
191
191
  };
192
+ export const _MANTA_ZK_CHAIN_GROUP = ['calamari'];
193
+ export const _ZK_ASSET_PREFIX = 'zk';
194
+ export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
192
195
 
193
196
  // XCM------------------------------------------------------------------------------------------------------------------
194
197
 
@@ -209,7 +212,7 @@ export const _XCM_TYPE = {
209
212
  export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS];
210
213
 
211
214
  // TODO: review
212
- const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
215
+ const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni/dev/issue-15' : 'master';
213
216
  export const _CHAIN_INFO_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainInfo.json`;
214
217
  export const _CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainAsset.json`;
215
218
  export const _ASSET_REF_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetRef.json`;
@@ -33,7 +33,7 @@ export declare class SubstrateApi implements _SubstrateApi {
33
33
  systemVersion: string;
34
34
  private createProvider;
35
35
  private createApi;
36
- constructor(chainSlug: string, apiUrl: string, { metadata, providerName }?: _ApiOptions);
36
+ constructor(chainSlug: string, apiUrl: string, { externalApiPromise, metadata, providerName }?: _ApiOptions);
37
37
  get isReady(): Promise<_SubstrateApi>;
38
38
  updateApiUrl(apiUrl: string): Promise<void>;
39
39
  connect(): void;
@@ -68,6 +68,7 @@ export class SubstrateApi {
68
68
  }
69
69
  }
70
70
  constructor(chainSlug, apiUrl, {
71
+ externalApiPromise,
71
72
  metadata,
72
73
  providerName
73
74
  } = {}) {
@@ -77,7 +78,7 @@ export class SubstrateApi {
77
78
  this.registry = new TypeRegistry();
78
79
  this.metadata = metadata;
79
80
  this.provider = this.createProvider(apiUrl);
80
- this.api = this.createApi(this.provider);
81
+ this.api = externalApiPromise || this.createApi(this.provider);
81
82
  this.handleApiReady = createPromiseHandler();
82
83
  this.api.on('ready', this.onReady.bind(this));
83
84
  this.api.on('connected', this.onConnect.bind(this));
@@ -19,5 +19,5 @@ export declare class SubstrateChainHandler extends AbstractChainHandler {
19
19
  getSmartContractTokenInfo(contractAddress: string, tokenType: _AssetType, originChain: string, contractCaller?: string): Promise<_SmartContractTokenInfo>;
20
20
  setSubstrateApi(chainSlug: string, substrateApi: SubstrateApi): void;
21
21
  destroySubstrateApi(chainSlug: string): void;
22
- initApi(chainSlug: string, apiUrl: string, { onUpdateStatus, providerName }?: Omit<_ApiOptions, 'metadata'>): Promise<_SubstrateApi>;
22
+ initApi(chainSlug: string, apiUrl: string, { externalApiPromise, onUpdateStatus, providerName }?: Omit<_ApiOptions, 'metadata'>): Promise<SubstrateApi>;
23
23
  }
@@ -173,6 +173,7 @@ export class SubstrateChainHandler extends AbstractChainHandler {
173
173
  substrateAPI === null || substrateAPI === void 0 ? void 0 : substrateAPI.destroy().catch(console.error);
174
174
  }
175
175
  async initApi(chainSlug, apiUrl, {
176
+ externalApiPromise,
176
177
  onUpdateStatus,
177
178
  providerName
178
179
  } = {}) {
@@ -190,7 +191,8 @@ export class SubstrateChainHandler extends AbstractChainHandler {
190
191
  const metadata = await ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.getMetadata(chainSlug));
191
192
  const apiObject = new SubstrateApi(chainSlug, apiUrl, {
192
193
  providerName,
193
- metadata
194
+ metadata,
195
+ externalApiPromise
194
196
  });
195
197
  apiObject.isApiConnectedSubject.subscribe(this.handleConnect.bind(this, chainSlug));
196
198
  onUpdateStatus && apiObject.isApiConnectedSubject.subscribe(onUpdateStatus);
@@ -0,0 +1,30 @@
1
+ import { MantaAuthorizationContext, MantaPayConfig, MantaPaySyncState } from '@subwallet/extension-base/background/KoniTypes';
2
+ import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
3
+ import { MantaPayWallet } from 'manta-extension-sdk';
4
+ import { Subject } from 'rxjs';
5
+ export declare class MantaPrivateHandler {
6
+ private dbService;
7
+ private _privateWallet;
8
+ private currentAddress;
9
+ private syncStateSubject;
10
+ private syncState;
11
+ constructor(dbService: DatabaseService);
12
+ setCurrentAddress(address: string): void;
13
+ getSyncState(): MantaPaySyncState;
14
+ get privateWallet(): MantaPayWallet | undefined;
15
+ subscribeSyncState(): Subject<MantaPaySyncState>;
16
+ updateMantaPayConfig(address: string, chain: string, changes: Record<string, any>): Promise<void>;
17
+ saveMantaPayConfig(config: MantaPayConfig): Promise<void>;
18
+ getMantaPayConfig(address: string, chain: string): Promise<any>;
19
+ getMantaPayFirstConfig(chain: string): Promise<any>;
20
+ deleteMantaPayConfig(address: string, chain: string): Promise<any>;
21
+ saveMantaAuthContext(context: MantaAuthorizationContext): Promise<void>;
22
+ getMantaAuthContext(address: string, chain: string): Promise<any>;
23
+ deleteMantaAuthContext(address: string, chain: string): Promise<number>;
24
+ private saveLedgerState;
25
+ private getLedgerState;
26
+ initMantaPay(providerUrl: string, network: string): Promise<import("@polkadot/api").ApiPromise>;
27
+ getCurrentLedgerState(): Promise<number>;
28
+ setSyncState(data: MantaPaySyncState): void;
29
+ subscribeSyncProgress(): Promise<() => void>;
30
+ }