@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.
Files changed (124) hide show
  1. package/background/KoniTypes.d.ts +89 -0
  2. package/background/KoniTypes.js +18 -19
  3. package/background/handlers/Extension.js +17 -2
  4. package/background/handlers/State.d.ts +0 -1
  5. package/background/handlers/State.js +4 -8
  6. package/background/types.d.ts +6 -1
  7. package/cjs/background/KoniTypes.js +21 -11
  8. package/cjs/background/handlers/Extension.js +22 -6
  9. package/cjs/background/handlers/State.js +4 -8
  10. package/cjs/constants/index.js +7 -1
  11. package/cjs/defaults.js +1 -1
  12. package/cjs/koni/api/dotsama/balance.js +5 -0
  13. package/cjs/koni/api/dotsama/transfer.js +6 -0
  14. package/cjs/koni/api/nft/config.js +11 -6
  15. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  16. package/cjs/koni/api/xcm/xTokens.js +2 -2
  17. package/cjs/koni/background/cron.js +12 -1
  18. package/cjs/koni/background/handlers/Extension.js +457 -131
  19. package/cjs/koni/background/handlers/State.js +236 -53
  20. package/cjs/koni/background/handlers/Tabs.js +61 -9
  21. package/cjs/koni/background/subscription.js +3 -0
  22. package/cjs/packageInfo.js +1 -1
  23. package/cjs/page/Metadata.js +3 -0
  24. package/cjs/services/chain-service/constants.js +10 -4
  25. package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
  26. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
  27. package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
  28. package/cjs/services/chain-service/index.js +54 -5
  29. package/cjs/services/chain-service/utils.js +32 -0
  30. package/cjs/services/event-service/types.js +3 -1
  31. package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -9
  32. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +2 -2
  33. package/cjs/services/request-service/handler/WalletConnectRequestHandler.js +71 -0
  34. package/cjs/services/request-service/index.js +24 -6
  35. package/cjs/services/storage-service/DatabaseService.js +31 -1
  36. package/cjs/services/storage-service/databases/index.js +3 -0
  37. package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
  38. package/cjs/services/transaction-service/helpers/index.js +3 -2
  39. package/cjs/services/transaction-service/index.js +2 -1
  40. package/cjs/services/wallet-connect-service/constants.js +38 -0
  41. package/cjs/services/wallet-connect-service/handler/Eip155RequestHandler.js +113 -0
  42. package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +123 -0
  43. package/cjs/services/wallet-connect-service/helpers.js +81 -0
  44. package/cjs/services/wallet-connect-service/index.js +273 -0
  45. package/cjs/services/wallet-connect-service/types.js +27 -0
  46. package/cjs/utils/array.js +17 -0
  47. package/cjs/utils/environment.js +66 -0
  48. package/cjs/utils/index.js +78 -1
  49. package/cjs/utils/lazy.js +52 -0
  50. package/constants/index.d.ts +2 -0
  51. package/constants/index.js +2 -0
  52. package/defaults.d.ts +1 -1
  53. package/defaults.js +1 -1
  54. package/koni/api/dotsama/balance.js +6 -1
  55. package/koni/api/dotsama/transfer.js +7 -1
  56. package/koni/api/nft/config.js +11 -6
  57. package/koni/api/xcm/polkadotXcm.js +1 -1
  58. package/koni/api/xcm/xTokens.js +2 -2
  59. package/koni/background/cron.d.ts +1 -0
  60. package/koni/background/cron.js +13 -2
  61. package/koni/background/handlers/Extension.d.ts +11 -0
  62. package/koni/background/handlers/Extension.js +329 -12
  63. package/koni/background/handlers/State.d.ts +17 -3
  64. package/koni/background/handlers/State.js +238 -52
  65. package/koni/background/handlers/Tabs.d.ts +2 -0
  66. package/koni/background/handlers/Tabs.js +58 -7
  67. package/koni/background/subscription.js +3 -0
  68. package/package.json +72 -6
  69. package/packageInfo.js +1 -1
  70. package/page/Metadata.d.ts +2 -0
  71. package/page/Metadata.js +3 -0
  72. package/services/chain-service/constants.d.ts +3 -0
  73. package/services/chain-service/constants.js +5 -2
  74. package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
  75. package/services/chain-service/handler/SubstrateApi.js +2 -1
  76. package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
  77. package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
  78. package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
  79. package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
  80. package/services/chain-service/handler/types.d.ts +2 -0
  81. package/services/chain-service/index.d.ts +7 -3
  82. package/services/chain-service/index.js +56 -7
  83. package/services/chain-service/utils.d.ts +3 -0
  84. package/services/chain-service/utils.js +28 -0
  85. package/services/event-service/types.d.ts +3 -0
  86. package/services/event-service/types.js +3 -1
  87. package/services/request-service/handler/AuthRequestHandler.d.ts +0 -1
  88. package/services/request-service/handler/AuthRequestHandler.js +5 -10
  89. package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -1
  90. package/services/request-service/handler/SubstrateRequestHandler.js +2 -2
  91. package/services/request-service/handler/WalletConnectRequestHandler.d.ts +15 -0
  92. package/services/request-service/handler/WalletConnectRequestHandler.js +62 -0
  93. package/services/request-service/index.d.ts +7 -2
  94. package/services/request-service/index.js +24 -6
  95. package/services/storage-service/DatabaseService.d.ts +10 -1
  96. package/services/storage-service/DatabaseService.js +31 -1
  97. package/services/storage-service/databases/index.d.ts +2 -0
  98. package/services/storage-service/databases/index.js +3 -0
  99. package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
  100. package/services/storage-service/db-stores/MantaPay.js +32 -0
  101. package/services/transaction-service/helpers/index.d.ts +1 -1
  102. package/services/transaction-service/helpers/index.js +2 -2
  103. package/services/transaction-service/index.js +2 -1
  104. package/services/transaction-service/types.d.ts +2 -1
  105. package/services/wallet-connect-service/constants.d.ts +11 -0
  106. package/services/wallet-connect-service/constants.js +23 -0
  107. package/services/wallet-connect-service/handler/Eip155RequestHandler.d.ts +8 -0
  108. package/services/wallet-connect-service/handler/Eip155RequestHandler.js +106 -0
  109. package/services/wallet-connect-service/handler/PolkadotRequestHandler.d.ts +8 -0
  110. package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +114 -0
  111. package/services/wallet-connect-service/helpers.d.ts +12 -0
  112. package/services/wallet-connect-service/helpers.js +67 -0
  113. package/services/wallet-connect-service/index.d.ts +20 -0
  114. package/services/wallet-connect-service/index.js +265 -0
  115. package/services/wallet-connect-service/types.d.ts +46 -0
  116. package/services/wallet-connect-service/types.js +20 -0
  117. package/utils/array.d.ts +1 -0
  118. package/utils/array.js +10 -0
  119. package/utils/environment.d.ts +2 -0
  120. package/utils/environment.js +59 -0
  121. package/utils/index.d.ts +4 -0
  122. package/utils/index.js +10 -2
  123. package/utils/lazy.d.ts +2 -0
  124. package/utils/lazy.js +43 -0
@@ -24,9 +24,13 @@ var _relayChain = require("@subwallet/extension-base/koni/api/staking/bonding/re
24
24
  var _transfer3 = require("@subwallet/extension-base/koni/api/tokens/evm/transfer");
25
25
  var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
26
26
  var _xcm = require("@subwallet/extension-base/koni/api/xcm");
27
+ var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
28
+ var _types2 = require("@subwallet/extension-base/services/chain-service/types");
27
29
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
28
- var _constants2 = require("@subwallet/extension-base/services/request-service/constants");
29
- var _constants3 = require("@subwallet/extension-base/services/setting-service/constants");
30
+ var _constants3 = require("@subwallet/extension-base/services/request-service/constants");
31
+ var _constants4 = require("@subwallet/extension-base/services/setting-service/constants");
32
+ var _constants5 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
33
+ var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-service/helpers");
30
34
  var _utils2 = require("@subwallet/extension-base/utils");
31
35
  var _address2 = require("@subwallet/extension-base/utils/address");
32
36
  var _eth = require("@subwallet/extension-base/utils/eth");
@@ -34,9 +38,10 @@ var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTrans
34
38
  var _number = require("@subwallet/extension-base/utils/number");
35
39
  var _keyring = require("@subwallet/keyring");
36
40
  var _uiKeyring = require("@subwallet/ui-keyring");
41
+ var _utils3 = require("@walletconnect/utils");
37
42
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
38
43
  var _ethereumjsTx = require("ethereumjs-tx");
39
- var _types2 = require("@polkadot/types");
44
+ var _types3 = require("@polkadot/types");
40
45
  var _util = require("@polkadot/util");
41
46
  var _utilCrypto = require("@polkadot/util-crypto");
42
47
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
@@ -69,14 +74,17 @@ const ACCOUNT_ALL_JSON = {
69
74
  class KoniExtension {
70
75
  #lockTimeOut = undefined;
71
76
  #koniState;
72
- #timeAutoLock = _constants3.DEFAULT_AUTO_LOCK_TIME;
77
+ #timeAutoLock = _constants4.DEFAULT_AUTO_LOCK_TIME;
78
+ #skipAutoLock = false;
73
79
  constructor(state) {
74
80
  this.#koniState = state;
75
81
  const updateTimeAutoLock = rs => {
76
82
  this.#timeAutoLock = rs.timeAutoLock;
77
83
  clearTimeout(this.#lockTimeOut);
78
84
  this.#lockTimeOut = setTimeout(() => {
79
- this.keyringLock();
85
+ if (!this.#skipAutoLock) {
86
+ this.keyringLock();
87
+ }
80
88
  }, this.#timeAutoLock * 60 * 1000);
81
89
  };
82
90
  this.#koniState.settingService.getSettings(updateTimeAutoLock);
@@ -365,9 +373,26 @@ class KoniExtension {
365
373
  });
366
374
  return true;
367
375
  }
368
- windowOpen(path) {
369
- const url = `${chrome.extension.getURL('index.html')}#${path}`;
376
+ windowOpen(_ref18) {
377
+ let {
378
+ allowedPath: path,
379
+ params,
380
+ subPath
381
+ } = _ref18;
382
+ let paramString = '';
383
+ if (params) {
384
+ paramString += '?';
385
+ for (let i = 0; i < Object.keys(params).length; i++) {
386
+ const [key, value] = Object.entries(params)[i];
387
+ paramString += `${key}=${value}`;
388
+ if (i !== Object.keys(params).length - 1) {
389
+ paramString += '&';
390
+ }
391
+ }
392
+ }
393
+ const url = `${chrome.extension.getURL('index.html')}#${path}${subPath || ''}${paramString}`;
370
394
  if (!_defaults.ALLOWED_PATH.includes(path)) {
395
+ console.error('Not allowed to open the url:', url);
371
396
  return false;
372
397
  }
373
398
  (0, _helpers.withErrorLog)(() => chrome.tabs.create({
@@ -388,26 +413,26 @@ class KoniExtension {
388
413
  throw new Error(`"${suri}" is not a valid derivation path`);
389
414
  }
390
415
  }
391
- derivationValidate(_ref18) {
416
+ derivationValidate(_ref19) {
392
417
  let {
393
418
  parentAddress,
394
419
  parentPassword,
395
420
  suri
396
- } = _ref18;
421
+ } = _ref19;
397
422
  const childPair = this.derive(parentAddress, suri, parentPassword, {});
398
423
  return {
399
424
  address: childPair.address,
400
425
  suri
401
426
  };
402
427
  }
403
- derivationCreate(_ref19) {
428
+ derivationCreate(_ref20) {
404
429
  let {
405
430
  genesisHash,
406
431
  name,
407
432
  parentAddress,
408
433
  parentPassword,
409
434
  suri
410
- } = _ref19;
435
+ } = _ref20;
411
436
  const childPair = this.derive(parentAddress, suri, parentPassword, {
412
437
  genesisHash,
413
438
  name,
@@ -432,11 +457,11 @@ class KoniExtension {
432
457
  encodeAddress = (key, ss58Format) => {
433
458
  return _uiKeyring.keyring.encodeAddress(key, ss58Format);
434
459
  };
435
- accountExportPrivateKey(_ref20) {
460
+ accountExportPrivateKey(_ref21) {
436
461
  let {
437
462
  address,
438
463
  password
439
- } = _ref20;
464
+ } = _ref21;
440
465
  return this.#koniState.accountExportPrivateKey({
441
466
  address,
442
467
  password
@@ -510,27 +535,27 @@ class KoniExtension {
510
535
  addresses: (0, _address2.convertSubjectInfoToAddresses)(subjectInfo)
511
536
  };
512
537
  }
513
- saveRecentAccount(_ref21) {
538
+ saveRecentAccount(_ref22) {
514
539
  let {
515
540
  accountId
516
- } = _ref21;
541
+ } = _ref22;
517
542
  if ((0, _utilCrypto.isAddress)(accountId)) {
518
543
  const address = (0, _utils2.reformatAddress)(accountId);
519
544
  const account = _uiKeyring.keyring.getAccount(address);
520
545
  const contact = _uiKeyring.keyring.getAddress(address);
521
546
  return account || contact || {
522
- ..._uiKeyring.keyring.saveRecent(accountId).json,
547
+ ..._uiKeyring.keyring.saveRecent(address).json,
523
548
  publicKey: (0, _utilCrypto.decodeAddress)(address)
524
549
  };
525
550
  } else {
526
551
  throw Error('Invalid address');
527
552
  }
528
553
  }
529
- editContactAccount(_ref22) {
554
+ editContactAccount(_ref23) {
530
555
  let {
531
556
  address,
532
557
  meta
533
- } = _ref22;
558
+ } = _ref23;
534
559
  if ((0, _utilCrypto.isAddress)(address)) {
535
560
  const _address = (0, _utils2.reformatAddress)(address);
536
561
  _uiKeyring.keyring.saveAddress(_address, meta);
@@ -539,10 +564,10 @@ class KoniExtension {
539
564
  throw Error('Invalid address');
540
565
  }
541
566
  }
542
- deleteContactAccount(_ref23) {
567
+ deleteContactAccount(_ref24) {
543
568
  let {
544
569
  address
545
- } = _ref23;
570
+ } = _ref24;
546
571
  if ((0, _utilCrypto.isAddress)(address)) {
547
572
  const _address = (0, _utils2.reformatAddress)(address);
548
573
  _uiKeyring.keyring.forgetAddress(_address);
@@ -591,11 +616,11 @@ class KoniExtension {
591
616
  list: authList
592
617
  };
593
618
  }
594
- authorizeApproveV2(_ref24) {
619
+ authorizeApproveV2(_ref25) {
595
620
  let {
596
621
  accounts,
597
622
  id
598
- } = _ref24;
623
+ } = _ref25;
599
624
  const queued = this.#koniState.getAuthRequestV2(id);
600
625
  (0, _util.assert)(queued, 'Unable to find request');
601
626
  const {
@@ -607,10 +632,10 @@ class KoniExtension {
607
632
  });
608
633
  return true;
609
634
  }
610
- authorizeRejectV2(_ref25) {
635
+ authorizeRejectV2(_ref26) {
611
636
  let {
612
637
  id
613
- } = _ref25;
638
+ } = _ref26;
614
639
  const queued = this.#koniState.getAuthRequestV2(id);
615
640
  (0, _util.assert)(queued, 'Unable to find request');
616
641
  const {
@@ -619,10 +644,10 @@ class KoniExtension {
619
644
  reject(new Error('Rejected'));
620
645
  return true;
621
646
  }
622
- authorizeCancelV2(_ref26) {
647
+ authorizeCancelV2(_ref27) {
623
648
  let {
624
649
  id
625
- } = _ref26;
650
+ } = _ref27;
626
651
  const queued = this.#koniState.getAuthRequestV2(id);
627
652
  (0, _util.assert)(queued, 'Unable to find request');
628
653
  const {
@@ -847,10 +872,10 @@ class KoniExtension {
847
872
  });
848
873
  return true;
849
874
  }
850
- setCamera(_ref27) {
875
+ setCamera(_ref28) {
851
876
  let {
852
877
  camera
853
- } = _ref27;
878
+ } = _ref28;
854
879
  this.#koniState.setCamera(camera);
855
880
  return true;
856
881
  }
@@ -862,10 +887,10 @@ class KoniExtension {
862
887
  });
863
888
  return true;
864
889
  }
865
- setAutoLockTime(_ref28) {
890
+ setAutoLockTime(_ref29) {
866
891
  let {
867
892
  autoLockTime
868
- } = _ref28;
893
+ } = _ref29;
869
894
  this.#koniState.setAutoLockTime(autoLockTime);
870
895
  return true;
871
896
  }
@@ -882,10 +907,10 @@ class KoniExtension {
882
907
  });
883
908
  return await this.getSettings();
884
909
  }
885
- setEnableChainPatrol(_ref29) {
910
+ setEnableChainPatrol(_ref30) {
886
911
  let {
887
912
  enable
888
- } = _ref29;
913
+ } = _ref30;
889
914
  this.#koniState.setEnableChainPatrol(enable);
890
915
  return true;
891
916
  }
@@ -1061,7 +1086,7 @@ class KoniExtension {
1061
1086
  }
1062
1087
  });
1063
1088
  }
1064
- async accountsCreateSuriV2(_ref30) {
1089
+ async accountsCreateSuriV2(_ref31) {
1065
1090
  let {
1066
1091
  genesisHash,
1067
1092
  isAllowed,
@@ -1069,7 +1094,7 @@ class KoniExtension {
1069
1094
  password,
1070
1095
  suri: _suri,
1071
1096
  types
1072
- } = _ref30;
1097
+ } = _ref31;
1073
1098
  const addressDict = {};
1074
1099
  let changedAccount = false;
1075
1100
  const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
@@ -1117,10 +1142,10 @@ class KoniExtension {
1117
1142
  });
1118
1143
  return addressDict;
1119
1144
  }
1120
- async accountsForgetOverride(_ref31) {
1145
+ async accountsForgetOverride(_ref32) {
1121
1146
  let {
1122
1147
  address
1123
- } = _ref31;
1148
+ } = _ref32;
1124
1149
  _uiKeyring.keyring.forgetAccount(address);
1125
1150
  await new Promise(resolve => {
1126
1151
  this.#koniState.removeAccountRef(address, () => {
@@ -1150,14 +1175,15 @@ class KoniExtension {
1150
1175
  address: _constants.ALL_ACCOUNT_KEY
1151
1176
  }, resolve);
1152
1177
  });
1178
+ await this.#koniState.disableMantaPay(address);
1153
1179
  return true;
1154
1180
  }
1155
- seedCreateV2(_ref32) {
1181
+ seedCreateV2(_ref33) {
1156
1182
  let {
1157
1183
  length = _Extension.SEED_DEFAULT_LENGTH,
1158
1184
  seed: _seed,
1159
1185
  types
1160
- } = _ref32;
1186
+ } = _ref33;
1161
1187
  const seed = _seed || (0, _utilCrypto.mnemonicGenerate)(length);
1162
1188
  const rs = {
1163
1189
  seed: seed,
@@ -1168,11 +1194,11 @@ class KoniExtension {
1168
1194
  });
1169
1195
  return rs;
1170
1196
  }
1171
- seedValidateV2(_ref33) {
1197
+ seedValidateV2(_ref34) {
1172
1198
  let {
1173
1199
  suri,
1174
1200
  types
1175
- } = _ref33;
1201
+ } = _ref34;
1176
1202
  const {
1177
1203
  phrase
1178
1204
  } = (0, _utilCrypto.keyExtractSuri)(suri);
@@ -1192,11 +1218,11 @@ class KoniExtension {
1192
1218
  });
1193
1219
  return rs;
1194
1220
  }
1195
- _checkValidatePrivateKey(_ref34) {
1221
+ _checkValidatePrivateKey(_ref35) {
1196
1222
  let {
1197
1223
  suri,
1198
1224
  types
1199
- } = _ref34;
1225
+ } = _ref35;
1200
1226
  let autoAddPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1201
1227
  const {
1202
1228
  phrase
@@ -1219,11 +1245,11 @@ class KoniExtension {
1219
1245
  }
1220
1246
  return rs;
1221
1247
  }
1222
- metamaskPrivateKeyValidateV2(_ref35) {
1248
+ metamaskPrivateKeyValidateV2(_ref36) {
1223
1249
  let {
1224
1250
  suri,
1225
1251
  types
1226
- } = _ref35;
1252
+ } = _ref36;
1227
1253
  const isValidSuri = suri.startsWith('0x');
1228
1254
  if (isValidSuri) {
1229
1255
  return this._checkValidatePrivateKey({
@@ -1248,14 +1274,14 @@ class KoniExtension {
1248
1274
  throw new Error(`"${suri}" is not a valid derivation path`);
1249
1275
  }
1250
1276
  }
1251
- derivationCreateV2(_ref36) {
1277
+ derivationCreateV2(_ref37) {
1252
1278
  let {
1253
1279
  genesisHash,
1254
1280
  isAllowed,
1255
1281
  name,
1256
1282
  parentAddress,
1257
1283
  suri
1258
- } = _ref36;
1284
+ } = _ref37;
1259
1285
  const childPair = this.deriveV2(parentAddress, suri, {
1260
1286
  genesisHash,
1261
1287
  name,
@@ -1269,14 +1295,14 @@ class KoniExtension {
1269
1295
  });
1270
1296
  return true;
1271
1297
  }
1272
- jsonRestoreV2(_ref37) {
1298
+ jsonRestoreV2(_ref38) {
1273
1299
  let {
1274
1300
  address,
1275
1301
  file,
1276
1302
  isAllowed,
1277
1303
  password,
1278
1304
  withMasterPassword
1279
- } = _ref37;
1305
+ } = _ref38;
1280
1306
  const isPasswordValidated = this.validatePassword(file, password);
1281
1307
  if (isPasswordValidated) {
1282
1308
  try {
@@ -1291,13 +1317,13 @@ class KoniExtension {
1291
1317
  throw new Error('Unable to decode using the supplied passphrase');
1292
1318
  }
1293
1319
  }
1294
- batchRestoreV2(_ref38) {
1320
+ batchRestoreV2(_ref39) {
1295
1321
  let {
1296
1322
  accountsInfo,
1297
1323
  file,
1298
1324
  isAllowed,
1299
1325
  password
1300
- } = _ref38;
1326
+ } = _ref39;
1301
1327
  const addressList = accountsInfo.map(acc => acc.address);
1302
1328
  const isPasswordValidated = this.validatedAccountsPassword(file, password);
1303
1329
  if (isPasswordValidated) {
@@ -1452,7 +1478,11 @@ class KoniExtension {
1452
1478
  let transaction;
1453
1479
 
1454
1480
  // Get native token amount
1455
- const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1481
+ const freeBalance = await this.getAddressFreeBalance({
1482
+ address: from,
1483
+ networkKey,
1484
+ token: tokenSlug
1485
+ });
1456
1486
  try {
1457
1487
  if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0, _utils._isTokenTransferredByEvm)(tokenInfo)) {
1458
1488
  // TODO: review this
@@ -1465,6 +1495,10 @@ class KoniExtension {
1465
1495
  } else {
1466
1496
  [transaction, transferAmount.value] = await (0, _transfer3.getEVMTransactionObject)(chainInfo, to, txVal, !!transferAll, evmApiMap);
1467
1497
  }
1498
+ } else if ((0, _utils._isMantaZkAsset)(tokenInfo)) {
1499
+ // TODO
1500
+ transaction = undefined;
1501
+ transferAmount.value = '0';
1468
1502
  } else {
1469
1503
  const substrateApi = this.#koniState.getSubstrateApi(networkKey);
1470
1504
  [transaction, transferAmount.value] = await (0, _transfer.createTransferExtrinsic)({
@@ -1493,14 +1527,22 @@ class KoniExtension {
1493
1527
  if (!isTransferNativeToken) {
1494
1528
  const {
1495
1529
  value: balance
1496
- } = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1530
+ } = await this.getAddressFreeBalance({
1531
+ address: from,
1532
+ networkKey,
1533
+ token: tokenSlug
1534
+ });
1497
1535
  if (new _bignumber.default(balance).minus(transferAmount.value).lt(minAmount)) {
1498
1536
  inputTransaction.warnings.push(new _TransactionWarning.TransactionWarning(_KoniTypes.BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
1499
1537
  }
1500
1538
  }
1501
1539
  const {
1502
1540
  value: receiverBalance
1503
- } = await this.#koniState.balanceService.getTokenFreeBalance(to, networkKey, tokenSlug);
1541
+ } = await this.getAddressFreeBalance({
1542
+ address: from,
1543
+ networkKey,
1544
+ token: tokenSlug
1545
+ });
1504
1546
  if (new _bignumber.default(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
1505
1547
  const atLeast = new _bignumber.default(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
1506
1548
  const atLeastStr = (0, _number.formatNumber)(atLeast, tokenInfo.decimals || 0, _number.balanceFormatter);
@@ -1600,7 +1642,7 @@ class KoniExtension {
1600
1642
  // this.addContact(to);
1601
1643
 
1602
1644
  return await this.#koniState.transactionService.handleTransaction({
1603
- url: _constants2.EXTENSION_REQUEST_URL,
1645
+ url: _constants3.EXTENSION_REQUEST_URL,
1604
1646
  address: from,
1605
1647
  chain: originNetworkKey,
1606
1648
  transaction: extrinsic,
@@ -1635,7 +1677,7 @@ class KoniExtension {
1635
1677
  data: inputData,
1636
1678
  extrinsicType: _KoniTypes.ExtrinsicType.SEND_NFT,
1637
1679
  transaction,
1638
- url: _constants2.EXTENSION_REQUEST_URL
1680
+ url: _constants3.EXTENSION_REQUEST_URL
1639
1681
  });
1640
1682
  }
1641
1683
  async upsertChain(data) {
@@ -1652,18 +1694,18 @@ class KoniExtension {
1652
1694
  disableChain(networkKey) {
1653
1695
  return this.#koniState.disableChain(networkKey);
1654
1696
  }
1655
- async enableChain(_ref39) {
1697
+ async enableChain(_ref40) {
1656
1698
  let {
1657
1699
  chainSlug,
1658
1700
  enableTokens
1659
- } = _ref39;
1701
+ } = _ref40;
1660
1702
  return await this.#koniState.enableChain(chainSlug, enableTokens);
1661
1703
  }
1662
- async validateNetwork(_ref40) {
1704
+ async validateNetwork(_ref41) {
1663
1705
  let {
1664
1706
  existedChainSlug,
1665
1707
  provider
1666
- } = _ref40;
1708
+ } = _ref41;
1667
1709
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1668
1710
  }
1669
1711
  resetDefaultNetwork() {
@@ -1701,23 +1743,33 @@ class KoniExtension {
1701
1743
  async validateCustomAsset(data) {
1702
1744
  return await this.#koniState.validateCustomAsset(data);
1703
1745
  }
1704
- async getAddressFreeBalance(_ref41) {
1746
+ async getAddressFreeBalance(_ref42) {
1705
1747
  let {
1706
1748
  address,
1707
1749
  networkKey,
1708
1750
  token
1709
- } = _ref41;
1751
+ } = _ref42;
1752
+ if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
1753
+ const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1754
+ if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
1755
+ return await this.#koniState.getMantaPayZkBalance(address, tokenInfo);
1756
+ }
1757
+ }
1710
1758
  return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1711
1759
  }
1712
- async transferGetMaxTransferable(_ref42) {
1760
+ async transferGetMaxTransferable(_ref43) {
1713
1761
  let {
1714
1762
  address,
1715
1763
  destChain,
1716
1764
  isXcmTransfer,
1717
1765
  networkKey,
1718
1766
  token
1719
- } = _ref42;
1720
- const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1767
+ } = _ref43;
1768
+ const freeBalance = await this.getAddressFreeBalance({
1769
+ address,
1770
+ networkKey,
1771
+ token
1772
+ });
1721
1773
  const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
1722
1774
  if (!(0, _utils._isNativeToken)(tokenInfo)) {
1723
1775
  return freeBalance;
@@ -1787,12 +1839,12 @@ class KoniExtension {
1787
1839
  };
1788
1840
  }
1789
1841
  }
1790
- async subscribeAddressFreeBalance(_ref43, id, port) {
1842
+ async subscribeAddressFreeBalance(_ref44, id, port) {
1791
1843
  let {
1792
1844
  address,
1793
1845
  networkKey,
1794
1846
  token
1795
- } = _ref43;
1847
+ } = _ref44;
1796
1848
  const cb = (0, _subscriptions.createSubscription)(id, port);
1797
1849
  const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
1798
1850
  this.createUnsubscriptionHandle(id, unsub);
@@ -1801,26 +1853,26 @@ class KoniExtension {
1801
1853
  });
1802
1854
  return currentFreeBalance;
1803
1855
  }
1804
- async transferCheckReferenceCount(_ref44) {
1856
+ async transferCheckReferenceCount(_ref45) {
1805
1857
  let {
1806
1858
  address,
1807
1859
  networkKey
1808
- } = _ref44;
1860
+ } = _ref45;
1809
1861
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1810
1862
  return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1811
1863
  }
1812
- async transferCheckSupporting(_ref45) {
1864
+ async transferCheckSupporting(_ref46) {
1813
1865
  let {
1814
1866
  networkKey,
1815
1867
  tokenSlug
1816
- } = _ref45;
1868
+ } = _ref46;
1817
1869
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1818
1870
  return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1819
1871
  }
1820
- transferGetExistentialDeposit(_ref46) {
1872
+ transferGetExistentialDeposit(_ref47) {
1821
1873
  let {
1822
1874
  tokenSlug
1823
- } = _ref46;
1875
+ } = _ref47;
1824
1876
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1825
1877
  return (0, _utils._getTokenMinAmount)(tokenInfo);
1826
1878
  }
@@ -1856,11 +1908,11 @@ class KoniExtension {
1856
1908
  isSendingSelf
1857
1909
  };
1858
1910
  }
1859
- async enableChains(_ref47) {
1911
+ async enableChains(_ref48) {
1860
1912
  let {
1861
1913
  chainSlugs,
1862
1914
  enableTokens
1863
- } = _ref47;
1915
+ } = _ref48;
1864
1916
  try {
1865
1917
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
1866
1918
  chainSlug,
@@ -1871,24 +1923,24 @@ class KoniExtension {
1871
1923
  }
1872
1924
  return true;
1873
1925
  }
1874
- getAccountMeta(_ref48) {
1926
+ getAccountMeta(_ref49) {
1875
1927
  let {
1876
1928
  address
1877
- } = _ref48;
1929
+ } = _ref49;
1878
1930
  const pair = _uiKeyring.keyring.getPair(address);
1879
1931
  (0, _util.assert)(pair, 'Unable to find pair');
1880
1932
  return {
1881
1933
  meta: pair.meta
1882
1934
  };
1883
1935
  }
1884
- accountsTie2(_ref49) {
1936
+ accountsTie2(_ref50) {
1885
1937
  let {
1886
1938
  address,
1887
1939
  genesisHash
1888
- } = _ref49;
1940
+ } = _ref50;
1889
1941
  return this.#koniState.setAccountTie(address, genesisHash);
1890
1942
  }
1891
- async accountsCreateExternalV2(_ref50) {
1943
+ async accountsCreateExternalV2(_ref51) {
1892
1944
  let {
1893
1945
  address,
1894
1946
  genesisHash,
@@ -1896,7 +1948,7 @@ class KoniExtension {
1896
1948
  isEthereum,
1897
1949
  isReadOnly,
1898
1950
  name
1899
- } = _ref50;
1951
+ } = _ref51;
1900
1952
  try {
1901
1953
  let result;
1902
1954
  try {
@@ -1955,7 +2007,7 @@ class KoniExtension {
1955
2007
  }];
1956
2008
  }
1957
2009
  }
1958
- async accountsCreateHardwareV2(_ref51) {
2010
+ async accountsCreateHardwareV2(_ref52) {
1959
2011
  let {
1960
2012
  accountIndex,
1961
2013
  address,
@@ -1964,7 +2016,7 @@ class KoniExtension {
1964
2016
  hardwareType,
1965
2017
  isAllowed,
1966
2018
  name
1967
- } = _ref51;
2019
+ } = _ref52;
1968
2020
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
1969
2021
  accountIndex,
1970
2022
  addressOffset,
@@ -1987,10 +2039,10 @@ class KoniExtension {
1987
2039
  });
1988
2040
  return true;
1989
2041
  }
1990
- async accountsCreateHardwareMultiple(_ref52) {
2042
+ async accountsCreateHardwareMultiple(_ref53) {
1991
2043
  let {
1992
2044
  accounts
1993
- } = _ref52;
2045
+ } = _ref53;
1994
2046
  const addresses = [];
1995
2047
  if (!accounts.length) {
1996
2048
  throw new Error('No accounts to import');
@@ -2068,14 +2120,14 @@ class KoniExtension {
2068
2120
  }
2069
2121
  return true;
2070
2122
  }
2071
- async accountsCreateWithSecret(_ref53) {
2123
+ async accountsCreateWithSecret(_ref54) {
2072
2124
  let {
2073
2125
  isAllow,
2074
2126
  isEthereum,
2075
2127
  name,
2076
2128
  publicKey,
2077
2129
  secretKey
2078
- } = _ref53;
2130
+ } = _ref54;
2079
2131
  try {
2080
2132
  let keyringPair = null;
2081
2133
  if (isEthereum) {
@@ -2218,30 +2270,30 @@ class KoniExtension {
2218
2270
 
2219
2271
  // Parse transaction
2220
2272
 
2221
- parseSubstrateTransaction(_ref54) {
2273
+ parseSubstrateTransaction(_ref55) {
2222
2274
  let {
2223
2275
  data,
2224
2276
  networkKey
2225
- } = _ref54;
2277
+ } = _ref55;
2226
2278
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2227
2279
  const apiPromise = apiProps.api;
2228
2280
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2229
2281
  }
2230
- async parseEVMRLP(_ref55) {
2282
+ async parseEVMRLP(_ref56) {
2231
2283
  let {
2232
2284
  data
2233
- } = _ref55;
2285
+ } = _ref56;
2234
2286
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2235
2287
  }
2236
2288
 
2237
2289
  // Sign
2238
2290
 
2239
- qrSignSubstrate(_ref56) {
2291
+ qrSignSubstrate(_ref57) {
2240
2292
  let {
2241
2293
  address,
2242
2294
  data,
2243
2295
  networkKey
2244
- } = _ref56;
2296
+ } = _ref57;
2245
2297
  const pair = _uiKeyring.keyring.getPair(address);
2246
2298
  (0, _util.assert)(pair, 'Unable to find pair');
2247
2299
  if (pair.isLocked) {
@@ -2258,13 +2310,13 @@ class KoniExtension {
2258
2310
  signature: signed
2259
2311
  };
2260
2312
  }
2261
- async qrSignEVM(_ref57) {
2313
+ async qrSignEVM(_ref58) {
2262
2314
  let {
2263
2315
  address,
2264
2316
  chainId,
2265
2317
  message,
2266
2318
  type
2267
- } = _ref57;
2319
+ } = _ref58;
2268
2320
  let signed;
2269
2321
  const network = this.getNetworkJsonByChainId(chainId);
2270
2322
  if (!network) {
@@ -2345,11 +2397,11 @@ class KoniExtension {
2345
2397
  });
2346
2398
  return this.#koniState.getNominatorMetadata();
2347
2399
  }
2348
- async getBondingOptions(_ref58) {
2400
+ async getBondingOptions(_ref59) {
2349
2401
  let {
2350
2402
  chain,
2351
2403
  type
2352
- } = _ref58;
2404
+ } = _ref59;
2353
2405
  const apiProps = this.#koniState.getSubstrateApi(chain);
2354
2406
  const chainInfo = this.#koniState.getChainInfo(chain);
2355
2407
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2391,7 +2443,7 @@ class KoniExtension {
2391
2443
  data: inputData,
2392
2444
  extrinsicType: _KoniTypes.ExtrinsicType.STAKING_BOND,
2393
2445
  transaction: extrinsic,
2394
- url: _constants2.EXTENSION_REQUEST_URL,
2446
+ url: _constants3.EXTENSION_REQUEST_URL,
2395
2447
  transferNativeAmount: amount
2396
2448
  });
2397
2449
  }
@@ -2538,12 +2590,12 @@ class KoniExtension {
2538
2590
  }
2539
2591
 
2540
2592
  // EVM Transaction
2541
- async parseContractInput(_ref59) {
2593
+ async parseContractInput(_ref60) {
2542
2594
  let {
2543
2595
  chainId,
2544
2596
  contract,
2545
2597
  data
2546
- } = _ref59;
2598
+ } = _ref60;
2547
2599
  const network = this.getNetworkJsonByChainId(chainId);
2548
2600
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2549
2601
  }
@@ -2614,12 +2666,12 @@ class KoniExtension {
2614
2666
 
2615
2667
  // Change master password
2616
2668
 
2617
- keyringChangeMasterPassword(_ref60) {
2669
+ keyringChangeMasterPassword(_ref61) {
2618
2670
  let {
2619
2671
  createNew,
2620
2672
  newPassword,
2621
2673
  oldPassword
2622
- } = _ref60;
2674
+ } = _ref61;
2623
2675
  try {
2624
2676
  // Remove isMasterPassword meta if createNew
2625
2677
  if (createNew) {
@@ -2653,11 +2705,11 @@ class KoniExtension {
2653
2705
 
2654
2706
  // Migrate password
2655
2707
 
2656
- keyringMigrateMasterPassword(_ref61) {
2708
+ keyringMigrateMasterPassword(_ref62) {
2657
2709
  let {
2658
2710
  address,
2659
2711
  password
2660
- } = _ref61;
2712
+ } = _ref62;
2661
2713
  try {
2662
2714
  _uiKeyring.keyring.migrateWithMasterPassword(address, password);
2663
2715
  } catch (e) {
@@ -2675,12 +2727,13 @@ class KoniExtension {
2675
2727
 
2676
2728
  // Unlock wallet
2677
2729
 
2678
- keyringUnlock(_ref62) {
2730
+ keyringUnlock(_ref63) {
2679
2731
  let {
2680
2732
  password
2681
- } = _ref62;
2733
+ } = _ref63;
2682
2734
  try {
2683
2735
  _uiKeyring.keyring.unlockKeyring(password);
2736
+ this.#koniState.initMantaPay(password).catch(console.error);
2684
2737
  } catch (e) {
2685
2738
  return {
2686
2739
  errors: [e.message],
@@ -2704,11 +2757,11 @@ class KoniExtension {
2704
2757
 
2705
2758
  // Export mnemonic
2706
2759
 
2707
- keyringExportMnemonic(_ref63) {
2760
+ keyringExportMnemonic(_ref64) {
2708
2761
  let {
2709
2762
  address,
2710
2763
  password
2711
- } = _ref63;
2764
+ } = _ref64;
2712
2765
  const pair = _uiKeyring.keyring.getPair(address);
2713
2766
  const result = pair.exportMnemonic(password);
2714
2767
  return {
@@ -2718,10 +2771,10 @@ class KoniExtension {
2718
2771
 
2719
2772
  // Reset wallet
2720
2773
 
2721
- async resetWallet(_ref64) {
2774
+ async resetWallet(_ref65) {
2722
2775
  let {
2723
2776
  resetAll
2724
- } = _ref64;
2777
+ } = _ref65;
2725
2778
  try {
2726
2779
  await this.#koniState.resetWallet(resetAll);
2727
2780
  return {
@@ -2737,10 +2790,10 @@ class KoniExtension {
2737
2790
  }
2738
2791
 
2739
2792
  /// Signing external request
2740
- signingApprovePasswordV2(_ref65) {
2793
+ signingApprovePasswordV2(_ref66) {
2741
2794
  let {
2742
2795
  id
2743
- } = _ref65;
2796
+ } = _ref66;
2744
2797
  const queued = this.#koniState.getSignRequest(id);
2745
2798
  (0, _util.assert)(queued, 'Unable to find request');
2746
2799
  const {
@@ -2766,7 +2819,7 @@ class KoniExtension {
2766
2819
  const {
2767
2820
  payload
2768
2821
  } = request;
2769
- const registry = new _types2.TypeRegistry();
2822
+ const registry = new _types3.TypeRegistry();
2770
2823
  let isEvm = false;
2771
2824
  if ((0, _Extension.isJsonPayload)(payload)) {
2772
2825
  // Get the metadata for the genesisHash
@@ -2793,22 +2846,22 @@ class KoniExtension {
2793
2846
 
2794
2847
  /// Derive account
2795
2848
 
2796
- derivationCreateMultiple(_ref66) {
2849
+ derivationCreateMultiple(_ref67) {
2797
2850
  let {
2798
2851
  isAllowed,
2799
2852
  items,
2800
2853
  parentAddress
2801
- } = _ref66;
2854
+ } = _ref67;
2802
2855
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2803
2856
  const isEvm = parentPair.type === 'ethereum';
2804
2857
  if (parentPair.isLocked) {
2805
2858
  _uiKeyring.keyring.unlockPair(parentPair.address);
2806
2859
  }
2807
- const createChild = _ref67 => {
2860
+ const createChild = _ref68 => {
2808
2861
  let {
2809
2862
  name,
2810
2863
  suri
2811
- } = _ref67;
2864
+ } = _ref68;
2812
2865
  const meta = {
2813
2866
  name: name,
2814
2867
  parentAddress
@@ -2854,10 +2907,10 @@ class KoniExtension {
2854
2907
  }
2855
2908
  return true;
2856
2909
  }
2857
- derivationCreateV3(_ref68) {
2910
+ derivationCreateV3(_ref69) {
2858
2911
  let {
2859
2912
  address: parentAddress
2860
- } = _ref68;
2913
+ } = _ref69;
2861
2914
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2862
2915
  const isEvm = parentPair.type === 'ethereum';
2863
2916
  if (parentPair.isLocked) {
@@ -2889,11 +2942,11 @@ class KoniExtension {
2889
2942
  });
2890
2943
  return true;
2891
2944
  }
2892
- validateDerivePath(_ref69) {
2945
+ validateDerivePath(_ref70) {
2893
2946
  let {
2894
2947
  parentAddress,
2895
2948
  suri
2896
- } = _ref69;
2949
+ } = _ref70;
2897
2950
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2898
2951
  const isEvm = parentPair.type === 'ethereum';
2899
2952
  if (parentPair.isLocked) {
@@ -2926,12 +2979,12 @@ class KoniExtension {
2926
2979
  suri: meta.suri
2927
2980
  };
2928
2981
  }
2929
- getListDeriveAccounts(_ref70) {
2982
+ getListDeriveAccounts(_ref71) {
2930
2983
  let {
2931
2984
  limit,
2932
2985
  page,
2933
2986
  parentAddress
2934
- } = _ref70;
2987
+ } = _ref71;
2935
2988
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2936
2989
  const isEvm = parentPair.type === 'ethereum';
2937
2990
  if (parentPair.isLocked) {
@@ -3022,10 +3075,10 @@ class KoniExtension {
3022
3075
  getSupportedSmartContractTypes() {
3023
3076
  return this.#koniState.getSupportedSmartContractTypes();
3024
3077
  }
3025
- getTransaction(_ref71) {
3078
+ getTransaction(_ref72) {
3026
3079
  let {
3027
3080
  id
3028
- } = _ref71;
3081
+ } = _ref72;
3029
3082
  const {
3030
3083
  transaction,
3031
3084
  ...transactionResult
@@ -3035,8 +3088,8 @@ class KoniExtension {
3035
3088
  subscribeTransactions(id, port) {
3036
3089
  const cb = (0, _subscriptions.createSubscription)(id, port);
3037
3090
  function convertRs(rs) {
3038
- return Object.fromEntries(Object.entries(rs).map(_ref72 => {
3039
- let [key, value] = _ref72;
3091
+ return Object.fromEntries(Object.entries(rs).map(_ref73 => {
3092
+ let [key, value] = _ref73;
3040
3093
  const {
3041
3094
  additionalValidator,
3042
3095
  eventsHandler,
@@ -3068,10 +3121,10 @@ class KoniExtension {
3068
3121
  });
3069
3122
  return notificationSubject.value;
3070
3123
  }
3071
- async reloadCron(_ref73) {
3124
+ async reloadCron(_ref74) {
3072
3125
  let {
3073
3126
  data
3074
- } = _ref73;
3127
+ } = _ref74;
3075
3128
  if (data === 'nft') {
3076
3129
  return await this.#koniState.reloadNft();
3077
3130
  } else if (data === 'staking') {
@@ -3089,19 +3142,269 @@ class KoniExtension {
3089
3142
 
3090
3143
  // Phishing detect
3091
3144
 
3092
- async passPhishingPage(_ref74) {
3145
+ async passPhishingPage(_ref75) {
3093
3146
  let {
3094
3147
  url
3095
- } = _ref74;
3148
+ } = _ref75;
3096
3149
  return await this.#koniState.approvePassPhishingPage(url);
3097
3150
  }
3098
3151
 
3152
+ /// Wallet connect
3153
+
3154
+ // Connect
3155
+ async connectWalletConnect(_ref76) {
3156
+ let {
3157
+ uri
3158
+ } = _ref76;
3159
+ await this.#koniState.walletConnectService.connect(uri);
3160
+ return true;
3161
+ }
3162
+ connectWCSubscribe(id, port) {
3163
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3164
+ const subscription = this.#koniState.requestService.connectWCSubject.subscribe(requests => cb(requests));
3165
+ port.onDisconnect.addListener(() => {
3166
+ this.cancelSubscription(id);
3167
+ subscription.unsubscribe();
3168
+ });
3169
+ return this.#koniState.requestService.allConnectWCRequests;
3170
+ }
3171
+ async approveWalletConnectSession(_ref77) {
3172
+ let {
3173
+ accounts: selectedAccounts,
3174
+ id
3175
+ } = _ref77;
3176
+ const request = this.#koniState.requestService.getConnectWCRequest(id);
3177
+ if ((0, _helpers2.isProposalExpired)(request.request.params)) {
3178
+ throw new Error('The proposal has been expired');
3179
+ }
3180
+ const wcId = request.request.id;
3181
+ const params = request.request.params;
3182
+ const requiredNamespaces = params.requiredNamespaces;
3183
+ const optionalNamespaces = params.optionalNamespaces;
3184
+ const availableNamespaces = {};
3185
+ const namespaces = {};
3186
+ const chainInfoMap = this.#koniState.getChainInfoMap();
3187
+ Object.entries(requiredNamespaces).forEach(_ref78 => {
3188
+ let [key, namespace] = _ref78;
3189
+ if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3190
+ if (namespace.chains) {
3191
+ const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
3192
+ if (unSupportChains.length) {
3193
+ throw new Error((0, _utils3.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
3194
+ }
3195
+ availableNamespaces[key] = namespace;
3196
+ }
3197
+ } else {
3198
+ throw new Error((0, _utils3.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3199
+ }
3200
+ });
3201
+ Object.entries(optionalNamespaces).forEach(_ref79 => {
3202
+ let [key, namespace] = _ref79;
3203
+ if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3204
+ if (namespace.chains) {
3205
+ const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
3206
+ const requiredNameSpace = availableNamespaces[key];
3207
+ const defaultChains = [];
3208
+ if (requiredNameSpace) {
3209
+ availableNamespaces[key] = {
3210
+ chains: [...(requiredNameSpace.chains || defaultChains), ...(supportChains || defaultChains)],
3211
+ events: requiredNameSpace.events,
3212
+ methods: requiredNameSpace.methods
3213
+ };
3214
+ } else {
3215
+ if (supportChains.length) {
3216
+ availableNamespaces[key] = {
3217
+ chains: supportChains,
3218
+ events: namespace.events,
3219
+ methods: namespace.methods
3220
+ };
3221
+ }
3222
+ }
3223
+ }
3224
+ }
3225
+ });
3226
+ Object.entries(availableNamespaces).forEach(_ref80 => {
3227
+ let [key, namespace] = _ref80;
3228
+ if (namespace.chains) {
3229
+ const accounts = [];
3230
+ const chains = (0, _utils2.uniqueStringArray)(namespace.chains);
3231
+ chains.forEach(chain => {
3232
+ accounts.push(...selectedAccounts.filter(address => (0, _utilCrypto.isEthereumAddress)(address) === (key === _constants5.WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
3233
+ });
3234
+ namespaces[key] = {
3235
+ accounts,
3236
+ methods: namespace.methods,
3237
+ events: namespace.events,
3238
+ chains: chains
3239
+ };
3240
+ }
3241
+ });
3242
+ const result = {
3243
+ id: wcId,
3244
+ namespaces: namespaces,
3245
+ relayProtocol: params.relays[0].protocol
3246
+ };
3247
+ await this.#koniState.walletConnectService.approveSession(result);
3248
+ request.resolve();
3249
+ return true;
3250
+ }
3251
+ async rejectWalletConnectSession(_ref81) {
3252
+ let {
3253
+ id
3254
+ } = _ref81;
3255
+ const request = this.#koniState.requestService.getConnectWCRequest(id);
3256
+ const wcId = request.request.id;
3257
+ if ((0, _helpers2.isProposalExpired)(request.request.params)) {
3258
+ request.reject(new Error('The proposal has been expired'));
3259
+ return true;
3260
+ }
3261
+ await this.#koniState.walletConnectService.rejectSession(wcId);
3262
+ request.reject(new Error('USER_REJECTED'));
3263
+ return true;
3264
+ }
3265
+ subscribeWalletConnectSessions(id, port) {
3266
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3267
+ const subscription = this.#koniState.walletConnectService.sessionSubject.subscribe(rs => {
3268
+ cb(rs);
3269
+ });
3270
+ port.onDisconnect.addListener(() => {
3271
+ subscription.unsubscribe();
3272
+ this.cancelSubscription(id);
3273
+ });
3274
+ return this.#koniState.walletConnectService.sessions;
3275
+ }
3276
+ async disconnectWalletConnectSession(_ref82) {
3277
+ let {
3278
+ topic
3279
+ } = _ref82;
3280
+ await this.#koniState.walletConnectService.disconnect(topic);
3281
+ return true;
3282
+ }
3283
+ async enableMantaPay(_ref83) {
3284
+ let {
3285
+ address,
3286
+ password
3287
+ } = _ref83;
3288
+ // always takes the current account
3289
+ function timeout() {
3290
+ return new Promise(resolve => setTimeout(resolve, 1500));
3291
+ }
3292
+ try {
3293
+ await this.#koniState.chainService.enableChain(_constants2._DEFAULT_MANTA_ZK_CHAIN);
3294
+ this.#koniState.chainService.setMantaZkAssetSettings(true);
3295
+ const mnemonic = this.keyringExportMnemonic({
3296
+ address,
3297
+ password
3298
+ });
3299
+ const {
3300
+ connectionStatus
3301
+ } = this.#koniState.chainService.getChainStateByKey(_constants2._DEFAULT_MANTA_ZK_CHAIN);
3302
+ if (connectionStatus !== _types2._ChainConnectionStatus.CONNECTED) {
3303
+ // TODO: do better
3304
+ await timeout();
3305
+ }
3306
+ const result = await this.#koniState.enableMantaPay(true, address, password, mnemonic.result);
3307
+ this.#skipAutoLock = true;
3308
+ await this.saveCurrentAccountAddress({
3309
+ address
3310
+ });
3311
+ const unsubSyncProgress = await this.#koniState.chainService.mantaPay.subscribeSyncProgress();
3312
+ console.debug('Start initial sync for MantaPay');
3313
+ this.#koniState.initialSyncMantaPay(address).then(() => {
3314
+ console.debug('Finished initial sync for MantaPay');
3315
+ this.#skipAutoLock = false;
3316
+ unsubSyncProgress();
3317
+ }).catch(e => {
3318
+ console.error('Error syncing MantaPay', e);
3319
+ this.#skipAutoLock = false;
3320
+ unsubSyncProgress();
3321
+ });
3322
+ return {
3323
+ success: !!result,
3324
+ message: result ? _KoniTypes.MantaPayEnableMessage.SUCCESS : _KoniTypes.MantaPayEnableMessage.UNKNOWN_ERROR
3325
+ };
3326
+ } catch (e) {
3327
+ // @ts-ignore
3328
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
3329
+ if (e.toString() === 'Error: Unable to decode using the supplied passphrase') {
3330
+ return {
3331
+ success: false,
3332
+ message: _KoniTypes.MantaPayEnableMessage.WRONG_PASSWORD
3333
+ };
3334
+ }
3335
+ return {
3336
+ success: false,
3337
+ message: _KoniTypes.MantaPayEnableMessage.UNKNOWN_ERROR
3338
+ };
3339
+ }
3340
+ }
3341
+ async initSyncMantaPay(address) {
3342
+ if (this.#koniState.chainService.mantaPay.getSyncState().isSyncing) {
3343
+ return;
3344
+ }
3345
+ this.#skipAutoLock = true;
3346
+ await this.saveCurrentAccountAddress({
3347
+ address
3348
+ });
3349
+ const unsubSyncProgress = await this.#koniState.chainService.mantaPay.subscribeSyncProgress();
3350
+ console.debug('Start initial sync for MantaPay');
3351
+ this.#koniState.initialSyncMantaPay(address).then(() => {
3352
+ console.debug('Finished initial sync for MantaPay');
3353
+ this.#skipAutoLock = false;
3354
+ unsubSyncProgress();
3355
+ // make sure the sync state is set, just in case it gets unsubscribed
3356
+ this.#koniState.chainService.mantaPay.setSyncState({
3357
+ progress: 100,
3358
+ isSyncing: false
3359
+ });
3360
+ }).catch(e => {
3361
+ console.error('Error syncing MantaPay', e);
3362
+ this.#skipAutoLock = false;
3363
+ unsubSyncProgress();
3364
+ this.#koniState.chainService.mantaPay.setSyncState({
3365
+ progress: 0,
3366
+ isSyncing: false
3367
+ });
3368
+ });
3369
+ }
3370
+ async disableMantaPay(address) {
3371
+ return this.#koniState.disableMantaPay(address);
3372
+ }
3373
+ subscribeMantaPayConfig(id, port) {
3374
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3375
+ const mantaPayConfigSubscription = this.#koniState.subscribeMantaPayConfig().subscribe({
3376
+ next: rs => {
3377
+ cb(rs);
3378
+ }
3379
+ });
3380
+ this.createUnsubscriptionHandle(id, mantaPayConfigSubscription.unsubscribe);
3381
+ port.onDisconnect.addListener(() => {
3382
+ this.cancelSubscription(id);
3383
+ });
3384
+ return this.#koniState.getMantaPayConfig('calamari');
3385
+ }
3386
+ subscribeMantaPaySyncState(id, port) {
3387
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3388
+ const syncingStateSubscription = this.#koniState.subscribeMantaPaySyncState().subscribe({
3389
+ next: rs => {
3390
+ cb(rs);
3391
+ }
3392
+ });
3393
+ this.createUnsubscriptionHandle(id, syncingStateSubscription.unsubscribe);
3394
+ port.onDisconnect.addListener(() => {
3395
+ this.cancelSubscription(id);
3396
+ });
3397
+ return this.#koniState.chainService.mantaPay.getSyncState();
3398
+ }
3399
+
3099
3400
  // --------------------------------------------------------------
3100
3401
  // eslint-disable-next-line @typescript-eslint/require-await
3101
3402
  async handle(id, type, request, port) {
3102
3403
  clearTimeout(this.#lockTimeOut);
3103
3404
  this.#lockTimeOut = setTimeout(() => {
3104
- this.keyringLock();
3405
+ if (!this.#skipAutoLock) {
3406
+ this.keyringLock();
3407
+ }
3105
3408
  }, this.#timeAutoLock * 60 * 1000);
3106
3409
  switch (type) {
3107
3410
  /// Clone from PolkadotJs
@@ -3469,6 +3772,29 @@ class KoniExtension {
3469
3772
  case 'pri(settings.getLogoMaps)':
3470
3773
  return await this.getLogoMap();
3471
3774
 
3775
+ /// Wallet Connect
3776
+ case 'pri(walletConnect.connect)':
3777
+ return this.connectWalletConnect(request);
3778
+ case 'pri(walletConnect.requests.subscribe)':
3779
+ return this.connectWCSubscribe(id, port);
3780
+ case 'pri(walletConnect.session.approve)':
3781
+ return this.approveWalletConnectSession(request);
3782
+ case 'pri(walletConnect.session.reject)':
3783
+ return this.rejectWalletConnectSession(request);
3784
+ case 'pri(walletConnect.session.subscribe)':
3785
+ return this.subscribeWalletConnectSessions(id, port);
3786
+ case 'pri(walletConnect.session.disconnect)':
3787
+ return this.disconnectWalletConnectSession(request);
3788
+ case 'pri(mantaPay.enable)':
3789
+ return await this.enableMantaPay(request);
3790
+ case 'pri(mantaPay.initSyncMantaPay)':
3791
+ return await this.initSyncMantaPay(request);
3792
+ case 'pri(mantaPay.subscribeConfig)':
3793
+ return await this.subscribeMantaPayConfig(id, port);
3794
+ case 'pri(mantaPay.disable)':
3795
+ return await this.disableMantaPay(request);
3796
+ case 'pri(mantaPay.subscribeSyncingState)':
3797
+ return this.subscribeMantaPaySyncState(id, port);
3472
3798
  // Default
3473
3799
  default:
3474
3800
  throw new Error(`Unable to handle message of type ${type}`);