@subwallet/extension-base 1.3.31-1 → 1.3.33-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/background/KoniTypes.d.ts +94 -3
  2. package/background/KoniTypes.js +14 -0
  3. package/background/errors/CardanoProviderError.d.ts +6 -0
  4. package/background/errors/CardanoProviderError.js +61 -0
  5. package/background/types.d.ts +2 -2
  6. package/cjs/background/KoniTypes.js +16 -1
  7. package/cjs/background/errors/CardanoProviderError.js +67 -0
  8. package/cjs/constants/environment.js +4 -2
  9. package/cjs/constants/index.js +4 -1
  10. package/cjs/core/logic-validation/request.js +50 -3
  11. package/cjs/koni/api/contract-handler/evm/web3.js +21 -0
  12. package/cjs/koni/api/staking/bonding/utils.js +24 -3
  13. package/cjs/koni/background/handlers/Extension.js +141 -107
  14. package/cjs/koni/background/handlers/State.js +232 -6
  15. package/cjs/koni/background/handlers/Tabs.js +277 -55
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/page/cardano/cips/cip30.js +63 -0
  18. package/cjs/page/cardano/cips/index.js +20 -0
  19. package/cjs/page/cardano/index.js +41 -0
  20. package/cjs/page/{SubWalleEvmProvider.js → evm/index.js} +2 -2
  21. package/cjs/page/index.js +9 -4
  22. package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +6 -2
  23. package/cjs/services/balance-service/transfer/xcm/index.js +2 -0
  24. package/cjs/services/chain-service/handler/CardanoApi.js +33 -0
  25. package/cjs/services/chain-service/index.js +31 -0
  26. package/cjs/services/chain-service/utils/patch.js +1 -1
  27. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +3 -3
  28. package/cjs/services/earning-service/handlers/native-staking/dtao.js +2 -2
  29. package/cjs/services/earning-service/handlers/native-staking/mythos.js +42 -8
  30. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +1 -1
  31. package/cjs/services/earning-service/handlers/native-staking/tao.js +13 -13
  32. package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -1
  33. package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +1 -1
  34. package/cjs/services/price-service/coingecko.js +22 -3
  35. package/cjs/services/price-service/index.js +75 -2
  36. package/cjs/services/request-service/constants.js +3 -1
  37. package/cjs/services/request-service/handler/AuthRequestHandler.js +38 -5
  38. package/cjs/services/request-service/handler/CardanoRequestHandler.js +45 -3
  39. package/cjs/services/request-service/helper/index.js +419 -1
  40. package/cjs/services/swap-service/handler/asset-hub/handler.js +1 -1
  41. package/cjs/services/swap-service/handler/base-handler.js +81 -21
  42. package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
  43. package/cjs/services/swap-service/handler/uniswap-handler.js +274 -45
  44. package/cjs/services/swap-service/index.js +33 -11
  45. package/cjs/services/swap-service/utils.js +15 -2
  46. package/cjs/utils/auth.js +2 -1
  47. package/cjs/utils/cardano.js +20 -0
  48. package/cjs/utils/index.js +16 -4
  49. package/cjs/utils/price.js +28 -0
  50. package/constants/environment.d.ts +1 -0
  51. package/constants/environment.js +2 -1
  52. package/constants/index.d.ts +1 -0
  53. package/constants/index.js +1 -0
  54. package/core/logic-validation/request.d.ts +6 -2
  55. package/core/logic-validation/request.js +51 -5
  56. package/koni/api/contract-handler/evm/web3.d.ts +2 -0
  57. package/koni/api/contract-handler/evm/web3.js +19 -0
  58. package/koni/api/staking/bonding/utils.d.ts +2 -1
  59. package/koni/api/staking/bonding/utils.js +23 -3
  60. package/koni/background/handlers/Extension.d.ts +2 -0
  61. package/koni/background/handlers/Extension.js +32 -2
  62. package/koni/background/handlers/State.d.ts +6 -1
  63. package/koni/background/handlers/State.js +228 -6
  64. package/koni/background/handlers/Tabs.d.ts +11 -1
  65. package/koni/background/handlers/Tabs.js +242 -19
  66. package/package.json +67 -42
  67. package/packageInfo.js +1 -1
  68. package/page/cardano/cips/cip30.d.ts +22 -0
  69. package/page/cardano/cips/cip30.js +55 -0
  70. package/page/cardano/cips/index.d.ts +3 -0
  71. package/page/cardano/cips/index.js +7 -0
  72. package/page/cardano/index.d.ts +13 -0
  73. package/page/cardano/index.js +34 -0
  74. package/page/{SubWalleEvmProvider.d.ts → evm/index.d.ts} +3 -2
  75. package/page/{SubWalleEvmProvider.js → evm/index.js} +1 -1
  76. package/page/index.d.ts +3 -2
  77. package/page/index.js +6 -2
  78. package/page/{Accounts.d.ts → substrate/Accounts.d.ts} +1 -1
  79. package/page/{Metadata.d.ts → substrate/Metadata.d.ts} +1 -1
  80. package/page/{PostMessageProvider.d.ts → substrate/PostMessageProvider.d.ts} +1 -1
  81. package/page/{Signer.d.ts → substrate/Signer.d.ts} +1 -1
  82. package/page/{Injected.d.ts → substrate/index.d.ts} +1 -1
  83. package/services/balance-service/helpers/subscribe/cardano/types.d.ts +14 -0
  84. package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +4 -0
  85. package/services/balance-service/transfer/xcm/acrossBridge/index.js +4 -1
  86. package/services/balance-service/transfer/xcm/index.js +2 -0
  87. package/services/chain-service/handler/CardanoApi.d.ts +3 -1
  88. package/services/chain-service/handler/CardanoApi.js +33 -0
  89. package/services/chain-service/index.d.ts +5 -1
  90. package/services/chain-service/index.js +32 -1
  91. package/services/chain-service/utils/patch.js +1 -1
  92. package/services/earning-service/handlers/liquid-staking/stella-swap.js +3 -3
  93. package/services/earning-service/handlers/native-staking/dtao.js +2 -2
  94. package/services/earning-service/handlers/native-staking/mythos.js +42 -8
  95. package/services/earning-service/handlers/native-staking/relay-chain.js +1 -1
  96. package/services/earning-service/handlers/native-staking/tao.js +14 -14
  97. package/services/earning-service/handlers/nomination-pool/index.js +1 -1
  98. package/services/migration-service/scripts/MigrateAuthUrls.js +1 -1
  99. package/services/price-service/coingecko.d.ts +2 -1
  100. package/services/price-service/coingecko.js +19 -1
  101. package/services/price-service/index.d.ts +11 -1
  102. package/services/price-service/index.js +78 -5
  103. package/services/request-service/constants.js +3 -1
  104. package/services/request-service/handler/AuthRequestHandler.js +40 -7
  105. package/services/request-service/handler/CardanoRequestHandler.d.ts +2 -0
  106. package/services/request-service/handler/CardanoRequestHandler.js +45 -3
  107. package/services/request-service/helper/index.d.ts +54 -0
  108. package/services/request-service/helper/index.js +406 -1
  109. package/services/request-service/types.d.ts +3 -1
  110. package/services/swap-service/handler/asset-hub/handler.js +1 -1
  111. package/services/swap-service/handler/base-handler.d.ts +3 -1
  112. package/services/swap-service/handler/base-handler.js +82 -22
  113. package/services/swap-service/handler/hydradx-handler.js +1 -1
  114. package/services/swap-service/handler/uniswap-handler.d.ts +5 -0
  115. package/services/swap-service/handler/uniswap-handler.js +275 -46
  116. package/services/swap-service/index.js +34 -12
  117. package/services/swap-service/utils.d.ts +3 -2
  118. package/services/swap-service/utils.js +13 -1
  119. package/types/swap/index.d.ts +1 -0
  120. package/types/transaction/process.d.ts +2 -0
  121. package/utils/auth.js +3 -2
  122. package/utils/cardano.d.ts +2 -0
  123. package/utils/cardano.js +12 -0
  124. package/utils/index.d.ts +2 -1
  125. package/utils/index.js +2 -1
  126. package/utils/price.d.ts +3 -0
  127. package/utils/price.js +20 -0
  128. package/cjs/utils/canDerive.js +0 -12
  129. package/utils/canDerive.d.ts +0 -2
  130. package/utils/canDerive.js +0 -6
  131. /package/cjs/page/{Accounts.js → substrate/Accounts.js} +0 -0
  132. /package/cjs/page/{Metadata.js → substrate/Metadata.js} +0 -0
  133. /package/cjs/page/{PostMessageProvider.js → substrate/PostMessageProvider.js} +0 -0
  134. /package/cjs/page/{Signer.js → substrate/Signer.js} +0 -0
  135. /package/cjs/page/{Injected.js → substrate/index.js} +0 -0
  136. /package/page/{Accounts.js → substrate/Accounts.js} +0 -0
  137. /package/page/{Metadata.js → substrate/Metadata.js} +0 -0
  138. /package/page/{PostMessageProvider.js → substrate/PostMessageProvider.js} +0 -0
  139. /package/page/{Signer.js → substrate/Signer.js} +0 -0
  140. /package/page/{Injected.js → substrate/index.js} +0 -0
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.chainPatrolCheckUrl = void 0;
8
+ var CardanoWasm = _interopRequireWildcard(require("@emurgo/cardano-serialization-lib-nodejs"));
8
9
  var _types = require("@subwallet/chain-list/types");
10
+ var _CardanoProviderError = require("@subwallet/extension-base/background/errors/CardanoProviderError");
9
11
  var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
10
12
  var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
11
13
  var _subscriptions = require("@subwallet/extension-base/background/handlers/subscriptions");
@@ -17,13 +19,17 @@ var _logicValidation = require("@subwallet/extension-base/core/logic-validation"
17
19
  var _defaults = require("@subwallet/extension-base/defaults");
18
20
  var _types2 = require("@subwallet/extension-base/services/chain-service/handler/types");
19
21
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
22
+ var _helper = require("@subwallet/extension-base/services/request-service/helper");
20
23
  var _constants2 = require("@subwallet/extension-base/services/setting-service/constants");
21
24
  var _utils2 = require("@subwallet/extension-base/utils");
22
25
  var _types3 = require("@subwallet/keyring/types");
26
+ var _uiKeyring = require("@subwallet/ui-keyring");
23
27
  var _web = _interopRequireDefault(require("web3"));
24
28
  var _phishing = require("@polkadot/phishing");
25
29
  var _util = require("@polkadot/util");
26
30
  var _utilCrypto = require("@polkadot/util-crypto");
31
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
32
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
33
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
28
34
  // SPDX-License-Identifier: Apache-2.0
29
35
 
@@ -43,7 +49,8 @@ function transformAccountsV2(accounts) {
43
49
  const validTypes = {
44
50
  evm: _types3.EthereumKeypairTypes,
45
51
  substrate: _types3.SubstrateKeypairTypes,
46
- ton: _types3.TonKeypairTypes
52
+ ton: _types3.TonKeypairTypes,
53
+ cardano: _types3.CardanoKeypairTypes
47
54
  };
48
55
  return accountAuthTypes.some(authType => {
49
56
  var _validTypes$authType;
@@ -62,19 +69,14 @@ function transformAccountsV2(accounts) {
62
69
  }
63
70
  } = _ref2;
64
71
  return !isHidden;
65
- }).filter(_ref3 => {
66
- let {
67
- type
68
- } = _ref3;
69
- return anyType ? true : (0, _utils2.canDerive)(type);
70
- }).filter(authTypeFilter).filter(_ref4 => {
72
+ }).filter(authTypeFilter).filter(_ref3 => {
71
73
  let {
72
74
  json: {
73
75
  address
74
76
  }
75
- } = _ref4;
77
+ } = _ref3;
76
78
  return accountSelected.includes(address);
77
- }).sort((a, b) => (a.json.meta.whenCreated || 0) - (b.json.meta.whenCreated || 0)).map(_ref5 => {
79
+ }).sort((a, b) => (a.json.meta.whenCreated || 0) - (b.json.meta.whenCreated || 0)).map(_ref4 => {
78
80
  let {
79
81
  json: {
80
82
  address,
@@ -84,7 +86,7 @@ function transformAccountsV2(accounts) {
84
86
  }
85
87
  },
86
88
  type
87
- } = _ref5;
89
+ } = _ref4;
88
90
  return {
89
91
  address,
90
92
  genesisHash,
@@ -140,6 +142,7 @@ class KoniTabs {
140
142
  const payloadValidate = {
141
143
  address,
142
144
  networkKey: '',
145
+ type: 'substrate',
143
146
  errors: [],
144
147
  payloadAfterValidated: request
145
148
  };
@@ -156,6 +159,7 @@ class KoniTabs {
156
159
  const address = request.address;
157
160
  const payloadValidate = {
158
161
  address,
162
+ type: 'substrate',
159
163
  networkKey: '',
160
164
  errors: [],
161
165
  payloadAfterValidated: request
@@ -176,11 +180,11 @@ class KoniTabs {
176
180
 
177
181
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
178
182
  metadataList(url) {
179
- return this.#koniState.knownMetadata.map(_ref6 => {
183
+ return this.#koniState.knownMetadata.map(_ref5 => {
180
184
  let {
181
185
  genesisHash,
182
186
  specVersion
183
- } = _ref6;
187
+ } = _ref5;
184
188
  return {
185
189
  genesisHash,
186
190
  specVersion
@@ -228,10 +232,10 @@ class KoniTabs {
228
232
  chrome.tabs.query({
229
233
  url: nonFragment
230
234
  }, tabs => {
231
- tabs.map(_ref7 => {
235
+ tabs.map(_ref6 => {
232
236
  let {
233
237
  id
234
- } = _ref7;
238
+ } = _ref6;
235
239
  return id;
236
240
  }).filter(id => (0, _util.isNumber)(id)).forEach(id => (0, _helpers.withErrorLog)(() => chrome.tabs.update(id, {
237
241
  url
@@ -277,11 +281,11 @@ class KoniTabs {
277
281
  const shortenUrl = (0, _utils2.stripUrl)(url);
278
282
  return authList[shortenUrl];
279
283
  }
280
- async accountsListV2(url, _ref8) {
284
+ async accountsListV2(url, _ref7) {
281
285
  let {
282
286
  accountAuthType,
283
287
  anyType
284
- } = _ref8;
288
+ } = _ref7;
285
289
  const authInfo = await this.getAuthInfo(url);
286
290
  const accountAuthTypes = [];
287
291
  if (accountAuthType) {
@@ -293,15 +297,21 @@ class KoniTabs {
293
297
  if (authInfo.accountAuthTypes.includes('evm')) {
294
298
  accountAuthTypes.push('evm');
295
299
  }
300
+ if (authInfo.accountAuthTypes.includes('ton')) {
301
+ accountAuthTypes.push('ton');
302
+ }
303
+ if (authInfo.accountAuthTypes.includes('cardano')) {
304
+ accountAuthTypes.push('cardano');
305
+ }
296
306
  }
297
307
  return transformAccountsV2(this.#koniState.keyringService.context.pairs, anyType, authInfo, accountAuthTypes);
298
308
  }
299
309
 
300
310
  // TODO: Update logic
301
- accountsSubstrateSubscribeV2(url, _ref9, id, port) {
311
+ accountsSubstrateSubscribeV2(url, _ref8, id, port) {
302
312
  let {
303
313
  accountAuthType
304
- } = _ref9;
314
+ } = _ref8;
305
315
  const cb = (0, _subscriptions.createSubscription)(id, port);
306
316
  const authInfoSubject = this.#koniState.requestService.subscribeAuthorizeUrlSubject;
307
317
  this.#accountSubs[id] = {
@@ -333,10 +343,10 @@ class KoniTabs {
333
343
  });
334
344
  return id;
335
345
  }
336
- accountsUnsubscribe(url, _ref10) {
346
+ accountsUnsubscribe(url, _ref9) {
337
347
  let {
338
348
  id
339
- } = _ref10;
349
+ } = _ref9;
340
350
  const sub = this.#accountSubs[id];
341
351
  if (!sub || sub.url !== url) {
342
352
  return false;
@@ -347,25 +357,32 @@ class KoniTabs {
347
357
  return true;
348
358
  }
349
359
  authorizeV2(url, request) {
350
- var _request$accountAuthT, _request$accountAuthT2;
360
+ var _request$accountAuthT, _request$accountAuthT2, _request$accountAuthT3, _request$accountAuthT4;
351
361
  const isConnectOnlyEvmAccountType = ((_request$accountAuthT = request.accountAuthTypes) === null || _request$accountAuthT === void 0 ? void 0 : _request$accountAuthT.length) === 1 && ((_request$accountAuthT2 = request.accountAuthTypes) === null || _request$accountAuthT2 === void 0 ? void 0 : _request$accountAuthT2.includes('evm'));
362
+ const isConnectOnlyCardanoAccountType = ((_request$accountAuthT3 = request.accountAuthTypes) === null || _request$accountAuthT3 === void 0 ? void 0 : _request$accountAuthT3.length) === 1 && ((_request$accountAuthT4 = request.accountAuthTypes) === null || _request$accountAuthT4 === void 0 ? void 0 : _request$accountAuthT4.includes('cardano'));
352
363
  if (isConnectOnlyEvmAccountType) {
353
364
  return new Promise((resolve, reject) => {
354
365
  this.#koniState.authorizeUrlV2(url, request).then(resolve).catch(e => {
355
366
  reject(new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.USER_REJECTED_REQUEST));
356
367
  });
357
368
  });
369
+ } else if (isConnectOnlyCardanoAccountType) {
370
+ return new Promise((resolve, reject) => {
371
+ this.#koniState.authorizeUrlV2(url, request).then(resolve).catch(e => {
372
+ reject(new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.REFUSED_REQUEST));
373
+ });
374
+ });
358
375
  } else {
359
376
  return this.#koniState.authorizeUrlV2(url, request);
360
377
  }
361
378
  }
362
379
 
363
380
  // TODO: Update logic
364
- async getEvmCurrentAccount(url) {
381
+ async getCurrentAccount(url, authType) {
365
382
  return await new Promise(resolve => {
366
383
  this.getAuthInfo(url).then(authInfo => {
367
384
  const allAccounts = this.#koniState.keyringService.context.pairs;
368
- const accountList = transformAccountsV2(allAccounts, false, authInfo, ['evm']).map(a => a.address);
385
+ const accountList = transformAccountsV2(allAccounts, false, authInfo, [authType]).map(a => a.address);
369
386
  let accounts = [];
370
387
  const proxyId = this.#koniState.keyringService.context.currentAccount.proxyId;
371
388
  if (proxyId === _constants.ALL_ACCOUNT_KEY || !proxyId) {
@@ -393,8 +410,8 @@ class KoniTabs {
393
410
  let autoActiveChain = false;
394
411
  if (url) {
395
412
  const authInfo = await this.getAuthInfo(url);
396
- if (authInfo !== null && authInfo !== void 0 && authInfo.currentEvmNetworkKey) {
397
- currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentEvmNetworkKey;
413
+ if (authInfo !== null && authInfo !== void 0 && authInfo.currentNetworkMap.evm) {
414
+ currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.evm;
398
415
  }
399
416
  if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
400
417
  autoActiveChain = true;
@@ -446,7 +463,7 @@ class KoniTabs {
446
463
  }
447
464
  }
448
465
  async getEvmPermission(url, id) {
449
- const accounts = await this.getEvmCurrentAccount(url);
466
+ const accounts = await this.getCurrentAccount(url, 'evm');
450
467
  return [{
451
468
  id: id,
452
469
  invoker: url,
@@ -458,10 +475,10 @@ class KoniTabs {
458
475
  date: new Date().getTime()
459
476
  }];
460
477
  }
461
- async revokePermissions(url, id, _ref11) {
478
+ async revokePermissions(url, id, _ref10) {
462
479
  let {
463
480
  params
464
- } = _ref11;
481
+ } = _ref10;
465
482
  if (!params || !(0, _util.isArray)(params) || params.length === 0) {
466
483
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'No list of permissions found to revoke in the parameters.');
467
484
  }
@@ -497,8 +514,8 @@ class KoniTabs {
497
514
  if (accountAuthTypes.length === 1) {
498
515
  delete value[urlStripped];
499
516
  } else {
500
- value[urlStripped].isAllowedMap = Object.entries(isAllowedMap).reduce((allowedMap, _ref12) => {
501
- let [address, value] = _ref12;
517
+ value[urlStripped].isAllowedMap = Object.entries(isAllowedMap).reduce((allowedMap, _ref11) => {
518
+ let [address, value] = _ref11;
502
519
  if ((0, _utilCrypto.isEthereumAddress)(address)) {
503
520
  allowedMap[address] = false;
504
521
  } else {
@@ -524,10 +541,10 @@ class KoniTabs {
524
541
  await Promise.all(Array.from(permissions).map(permissionPromise));
525
542
  return null;
526
543
  }
527
- async switchEvmChain(id, url, _ref13) {
544
+ async switchEvmChain(id, url, _ref12) {
528
545
  let {
529
546
  params
530
- } = _ref13;
547
+ } = _ref12;
531
548
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
532
549
  const chainId = params[0].chainId;
533
550
  const chainIdDec = parseInt(chainId, 16);
@@ -560,11 +577,11 @@ class KoniTabs {
560
577
  }
561
578
  return null;
562
579
  }
563
- async addEvmToken(id, url, _ref14) {
580
+ async addEvmToken(id, url, _ref13) {
564
581
  var _input$type, _input$options, _input$options2, _input$options3, _input$options4, _input$options5;
565
582
  let {
566
583
  params
567
- } = _ref14;
584
+ } = _ref13;
568
585
  const input = params;
569
586
  const _tokenType = (input === null || input === void 0 ? void 0 : (_input$type = input.type) === null || _input$type === void 0 ? void 0 : _input$type.toLowerCase()) || '';
570
587
  if (_tokenType !== 'erc20' && _tokenType !== 'erc721') {
@@ -617,10 +634,10 @@ class KoniTabs {
617
634
 
618
635
  return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
619
636
  }
620
- async addEvmChain(id, url, _ref15) {
637
+ async addEvmChain(id, url, _ref14) {
621
638
  let {
622
639
  params
623
- } = _ref15;
640
+ } = _ref14;
624
641
  const input = params;
625
642
  if (input && input.length > 0) {
626
643
  const {
@@ -764,9 +781,9 @@ class KoniTabs {
764
781
  };
765
782
 
766
783
  // Detect accounts changed
767
- let currentAccountList = await this.getEvmCurrentAccount(url);
784
+ let currentAccountList = await this.getCurrentAccount(url, 'evm');
768
785
  const onCurrentAccountChanged = async () => {
769
- const newAccountList = await this.getEvmCurrentAccount(url);
786
+ const newAccountList = await this.getCurrentAccount(url, 'evm');
770
787
 
771
788
  // Compare to void looping reload
772
789
  if (JSON.stringify(currentAccountList) !== JSON.stringify(newAccountList)) {
@@ -793,7 +810,7 @@ class KoniTabs {
793
810
  }
794
811
 
795
812
  // Detect account
796
- const newAccountList = await this.getEvmCurrentAccount(url);
813
+ const newAccountList = await this.getCurrentAccount(url, 'evm');
797
814
 
798
815
  // Compare to void looping reload
799
816
  if (JSON.stringify(currentAccountList) !== JSON.stringify(newAccountList)) {
@@ -825,11 +842,11 @@ class KoniTabs {
825
842
  const networkCheckInterval = setInterval(networkCheck, _constants.CRON_GET_API_MAP_STATUS);
826
843
  const provider = await this.getEvmProvider(url);
827
844
  const eventMap = {};
828
- eventMap.data = _ref16 => {
845
+ eventMap.data = _ref15 => {
829
846
  let {
830
847
  method,
831
848
  params
832
- } = _ref16;
849
+ } = _ref15;
833
850
  emitEvent('message', {
834
851
  type: method,
835
852
  data: params
@@ -838,8 +855,8 @@ class KoniTabs {
838
855
  eventMap.error = rs => {
839
856
  emitEvent('error', rs);
840
857
  };
841
- Object.entries(eventMap).forEach(_ref17 => {
842
- let [event, callback] = _ref17;
858
+ Object.entries(eventMap).forEach(_ref16 => {
859
+ let [event, callback] = _ref16;
843
860
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
844
861
  (provider === null || provider === void 0 ? void 0 : provider.on) && (provider === null || provider === void 0 ? void 0 : provider.on(event, callback));
845
862
  });
@@ -853,8 +870,8 @@ class KoniTabs {
853
870
  if (this.evmEventEmitterMap[url][id]) {
854
871
  delete this.evmEventEmitterMap[url][id];
855
872
  }
856
- Object.entries(eventMap).forEach(_ref18 => {
857
- let [event, callback] = _ref18;
873
+ Object.entries(eventMap).forEach(_ref17 => {
874
+ let [event, callback] = _ref17;
858
875
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
859
876
  (provider === null || provider === void 0 ? void 0 : provider.removeListener) && (provider === null || provider === void 0 ? void 0 : provider.removeListener(event, callback));
860
877
  });
@@ -889,11 +906,11 @@ class KoniTabs {
889
906
  }
890
907
  return provider;
891
908
  }
892
- async performWeb3Method(id, url, _ref19, callback) {
909
+ async performWeb3Method(id, url, _ref18, callback) {
893
910
  let {
894
911
  method,
895
912
  params
896
- } = _ref19;
913
+ } = _ref18;
897
914
  const provider = await this.getEvmProvider(url);
898
915
  this.checkAndHandleProviderStatus(provider);
899
916
  return new Promise((resolve, reject) => {
@@ -926,14 +943,14 @@ class KoniTabs {
926
943
  });
927
944
  }
928
945
  async canUseAccount(address, url) {
929
- const allowedAccounts = await this.getEvmCurrentAccount(url);
946
+ const allowedAccounts = await this.getCurrentAccount(url, 'evm');
930
947
  return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
931
948
  }
932
- async evmSign(id, url, _ref20) {
949
+ async evmSign(id, url, _ref19) {
933
950
  let {
934
951
  method,
935
952
  params
936
- } = _ref20;
953
+ } = _ref19;
937
954
  const signResult = await this.#koniState.evmSign(id, url, method, params);
938
955
  if (signResult) {
939
956
  return signResult;
@@ -943,10 +960,10 @@ class KoniTabs {
943
960
  }
944
961
 
945
962
  // TODO: Update logic
946
- async evmSendTransaction(id, url, _ref21) {
963
+ async evmSendTransaction(id, url, _ref20) {
947
964
  let {
948
965
  params
949
- } = _ref21;
966
+ } = _ref20;
950
967
  const transactionParams = params[0];
951
968
  const transactionHash = await this.#koniState.evmSendTransaction(id, url, transactionParams);
952
969
  if (!transactionHash) {
@@ -965,7 +982,7 @@ class KoniTabs {
965
982
  case 'net_version':
966
983
  return parseInt(await this.getEvmCurrentChainId(url), 16);
967
984
  case 'eth_accounts':
968
- return await this.getEvmCurrentAccount(url);
985
+ return await this.getCurrentAccount(url, 'evm');
969
986
  case 'eth_sendTransaction':
970
987
  return await this.evmSendTransaction(id, url, request);
971
988
  case 'eth_sign':
@@ -1032,11 +1049,11 @@ class KoniTabs {
1032
1049
  isEvmPublicRequest(type, request) {
1033
1050
  return type === 'evm(request)' && ['eth_chainId', 'net_version', 'wallet_requestPermissions', 'wallet_getPermissions'].includes(request === null || request === void 0 ? void 0 : request.method) || type === 'evm(events.subscribe)';
1034
1051
  }
1035
- async addPspToken(id, url, _ref22) {
1052
+ async addPspToken(id, url, _ref21) {
1036
1053
  let {
1037
1054
  genesisHash,
1038
1055
  tokenInfo: input
1039
- } = _ref22;
1056
+ } = _ref21;
1040
1057
  const _tokenType = input.type;
1041
1058
  if (_tokenType !== 'psp22' && _tokenType !== 'psp34') {
1042
1059
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Assets type {{tokenType}} is not supported'.replace('{{tokenType}}', _tokenType));
@@ -1087,6 +1104,191 @@ class KoniTabs {
1087
1104
  });
1088
1105
  return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
1089
1106
  }
1107
+
1108
+ // Cardano
1109
+
1110
+ async getCurrentInformationCardanoDapp(url) {
1111
+ const authInfo = await this.getAuthInfo(url);
1112
+ if (!authInfo || !authInfo.isAllowedMap || !authInfo.isAllowed) {
1113
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
1114
+ }
1115
+ const cardanoAddress = authInfo.currentAccount;
1116
+ if (!cardanoAddress || !authInfo.isAllowedMap[cardanoAddress]) {
1117
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.ACCOUNT_CHANGED, 'No Cardano address found');
1118
+ }
1119
+ const keypair = _uiKeyring.keyring.getPair(cardanoAddress);
1120
+ if (!keypair) {
1121
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.ACCOUNT_CHANGED, 'No Cardano address found');
1122
+ }
1123
+ const network = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano;
1124
+ if (!network) {
1125
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INTERNAL_ERROR, 'No network key found');
1126
+ }
1127
+ return {
1128
+ address: cardanoAddress,
1129
+ network
1130
+ };
1131
+ }
1132
+ async cardanoGetAccountList(id, url) {
1133
+ const authList = await this.#koniState.getAuthList();
1134
+ const urlStripped = (0, _utils2.stripUrl)(url);
1135
+ const authInfo = authList[urlStripped];
1136
+ if (!authInfo || !authInfo.isAllowedMap) {
1137
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
1138
+ }
1139
+ const accountList = await this.getCurrentAccount(url, 'cardano');
1140
+ const currentCardanoAccount = authInfo.currentAccount;
1141
+ if (currentCardanoAccount !== accountList[0]) {
1142
+ authList[urlStripped].currentAccount = accountList[0];
1143
+ this.#koniState.setAuthorize(authList);
1144
+ }
1145
+ return accountList.map(address => {
1146
+ const isTestnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
1147
+ const addressChainFormat = (0, _utils2.reformatAddress)(address, +isTestnet);
1148
+ return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
1149
+ });
1150
+ }
1151
+ async cardanoGetAccountBalance(id, url) {
1152
+ const {
1153
+ address
1154
+ } = await this.getCurrentInformationCardanoDapp(url);
1155
+ const balanceValue = await this.#koniState.cardanoGetBalance(id, url, address);
1156
+ return balanceValue.to_hex();
1157
+ }
1158
+ async cardanoGetChangeAddress(id, url) {
1159
+ const authList = await this.#koniState.getAuthList();
1160
+ const urlStripped = (0, _utils2.stripUrl)(url);
1161
+ const authInfo = authList[urlStripped];
1162
+ if (!authInfo || !authInfo.isAllowedMap) {
1163
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
1164
+ }
1165
+ const accountList = await this.getCurrentAccount(url, 'cardano');
1166
+ const currentCardanoAccount = authInfo.currentAccount;
1167
+ if (currentCardanoAccount !== accountList[0]) {
1168
+ authList[urlStripped].currentAccount = accountList[0];
1169
+ this.#koniState.setAuthorize(authList);
1170
+ }
1171
+ const {
1172
+ address,
1173
+ network
1174
+ } = await this.getCurrentInformationCardanoDapp(url);
1175
+ const isTestnet = network !== 'cardano_preproduction';
1176
+ const addressChainFormat = (0, _utils2.reformatAddress)(address, +isTestnet);
1177
+ return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
1178
+ }
1179
+ async cardanoGetCurrentNetworkId(id, url) {
1180
+ let currentChain;
1181
+ let autoActiveChain = false;
1182
+ if (url) {
1183
+ const authInfo = await this.getAuthInfo(url);
1184
+ if (authInfo !== null && authInfo !== void 0 && authInfo.currentNetworkMap.cardano) {
1185
+ currentChain = authInfo.currentNetworkMap.cardano;
1186
+ }
1187
+ if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
1188
+ autoActiveChain = true;
1189
+ }
1190
+ }
1191
+ const currentNetwork = this.#koniState.requestService.getDAppChainInfo({
1192
+ autoActive: autoActiveChain,
1193
+ accessType: 'cardano',
1194
+ defaultChain: currentChain,
1195
+ url
1196
+ });
1197
+ if (!(currentNetwork !== null && currentNetwork !== void 0 && currentNetwork.cardanoInfo)) {
1198
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INTERNAL_ERROR, 'Can\'t get current network');
1199
+ }
1200
+ return +!(currentNetwork !== null && currentNetwork !== void 0 && currentNetwork.isTestnet);
1201
+ }
1202
+ async cardanoGetUtxo(id, url, params) {
1203
+ const {
1204
+ address,
1205
+ network
1206
+ } = await this.getCurrentInformationCardanoDapp(url);
1207
+ const utxos = await this.#koniState.chainService.getUtxosByAddress(address, network, params === null || params === void 0 ? void 0 : params.paginate);
1208
+ if (!(params !== null && params !== void 0 && params.amount)) {
1209
+ return utxos.map(utxo => utxo.to_hex());
1210
+ }
1211
+ let expectedValue = CardanoWasm.Value.zero();
1212
+ try {
1213
+ expectedValue = CardanoWasm.Value.from_hex(params === null || params === void 0 ? void 0 : params.amount);
1214
+ } catch (e) {
1215
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, 'Amount is invalid');
1216
+ }
1217
+ let currentTotalUtxoValue = CardanoWasm.Value.zero();
1218
+ const utxosFiltered = [];
1219
+ for (const utxo of utxos) {
1220
+ currentTotalUtxoValue = currentTotalUtxoValue.checked_add(utxo.output().amount());
1221
+ utxosFiltered.push(utxo);
1222
+ if ((0, _helper.hasSufficientCardanoValue)(currentTotalUtxoValue, expectedValue)) {
1223
+ return utxosFiltered.map(utxo => utxo.to_hex());
1224
+ }
1225
+ }
1226
+ return null;
1227
+ }
1228
+ async cardanoGetCollateral(id, url, params) {
1229
+ const {
1230
+ address,
1231
+ network
1232
+ } = await this.getCurrentInformationCardanoDapp(url);
1233
+ const utxos = await this.#koniState.chainService.getUtxosByAddress(address, network);
1234
+ let expectedValue = CardanoWasm.Value.zero();
1235
+ try {
1236
+ if (params !== null && params !== void 0 && params.amount) {
1237
+ expectedValue = CardanoWasm.Value.from_hex(params === null || params === void 0 ? void 0 : params.amount);
1238
+ } else {
1239
+ expectedValue = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(_constants.MAX_COLLATERAL_AMOUNT));
1240
+ }
1241
+ } catch (e) {
1242
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, 'Amount is invalid');
1243
+ }
1244
+ if (expectedValue.multiasset() || expectedValue.coin().compare(CardanoWasm.BigNum.from_str(_constants.MAX_COLLATERAL_AMOUNT)) > 0) {
1245
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, 'Amount is invalid');
1246
+ }
1247
+ let currentTotalUtxoValue = CardanoWasm.Value.zero();
1248
+ const utxosFinal = [];
1249
+ for (const utxo of utxos) {
1250
+ const amount = utxo.output().amount();
1251
+ if (amount.multiasset()) {
1252
+ continue;
1253
+ }
1254
+ currentTotalUtxoValue = currentTotalUtxoValue.checked_add(amount);
1255
+ utxosFinal.push(utxo);
1256
+ if ((0, _helper.hasSufficientCardanoValue)(currentTotalUtxoValue, expectedValue)) {
1257
+ break;
1258
+ }
1259
+ }
1260
+ return utxosFinal.length ? utxosFinal.map(utxo => utxo.to_hex()) : null;
1261
+ }
1262
+ async cardanoSignData(id, url, params) {
1263
+ const {
1264
+ address
1265
+ } = await this.getCurrentInformationCardanoDapp(url);
1266
+ const signResult = await this.#koniState.cardanoSignData(id, url, params, address);
1267
+ if (signResult) {
1268
+ return signResult;
1269
+ } else {
1270
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INTERNAL_ERROR, 'Failed to sign data');
1271
+ }
1272
+ }
1273
+ async cardanoSignTransaction(id, url, params) {
1274
+ const {
1275
+ address
1276
+ } = await this.getCurrentInformationCardanoDapp(url);
1277
+ const signResult = await this.#koniState.cardanoSignTx(id, url, params, address);
1278
+ if (signResult) {
1279
+ return signResult;
1280
+ } else {
1281
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Failed to sign message');
1282
+ }
1283
+ }
1284
+ async cardanoSubmitTransaction(id, url, params) {
1285
+ const txHash = await this.#koniState.cardanoSubmitTx(id, url, params);
1286
+ if (txHash) {
1287
+ return txHash;
1288
+ } else {
1289
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INTERNAL_ERROR, 'Failed to submit transaction');
1290
+ }
1291
+ }
1090
1292
  async handle(id, type, request, url, port) {
1091
1293
  if (type === 'pub(phishing.redirectIfDenied)') {
1092
1294
  return this.redirectIfPhishing(url);
@@ -1146,6 +1348,26 @@ class KoniTabs {
1146
1348
  return await this.handleEvmRequest(id, url, request);
1147
1349
  case 'evm(provider.send)':
1148
1350
  return await this.handleEvmSend(id, url, port, request);
1351
+
1352
+ // Cardano
1353
+ case 'cardano(account.get.address)':
1354
+ return await this.cardanoGetAccountList(id, url);
1355
+ case 'cardano(account.get.balance)':
1356
+ return await this.cardanoGetAccountBalance(id, url);
1357
+ case 'cardano(account.get.change.address)':
1358
+ return await this.cardanoGetChangeAddress(id, url);
1359
+ case 'cardano(account.get.collateral)':
1360
+ return await this.cardanoGetCollateral(id, url, request);
1361
+ case 'cardano(account.get.utxos)':
1362
+ return await this.cardanoGetUtxo(id, url, request);
1363
+ case 'cardano(network.get.current)':
1364
+ return await this.cardanoGetCurrentNetworkId(id, url);
1365
+ case 'cardano(data.sign)':
1366
+ return await this.cardanoSignData(id, url, request);
1367
+ case 'cardano(transaction.sign)':
1368
+ return await this.cardanoSignTransaction(id, url, request);
1369
+ case 'cardano(transaction.submit)':
1370
+ return await this.cardanoSubmitTransaction(id, url, request);
1149
1371
  default:
1150
1372
  throw new Error(`Unable to handle message of type ${type}`);
1151
1373
  }
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.3.31-1'
16
+ version: '1.3.33-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;