@subwallet/extension-base 1.3.36-0 → 1.3.37-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.
@@ -98,6 +98,11 @@ export interface ResultResolver {
98
98
  result: boolean;
99
99
  accounts: string[];
100
100
  }
101
+ export interface RequestSwitchCurrentNetworkAuthorization {
102
+ url: string;
103
+ networkKey: string;
104
+ authSwitchNetworkType: AccountAuthType;
105
+ }
101
106
  export declare enum StakingType {
102
107
  NOMINATED = "nominated",
103
108
  POOLED = "pooled",
@@ -4,7 +4,7 @@ import type { KeyringPairs$Json } from '@subwallet/ui-keyring/types';
4
4
  import type { JsonRpcResponse } from '@polkadot/rpc-provider/types';
5
5
  import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
6
6
  import type { HexString } from '@polkadot/util/types';
7
- import { KoniRequestSignatures, NetworkJson } from '@subwallet/extension-base/background/KoniTypes';
7
+ import { KoniRequestSignatures, NetworkJson, RequestSwitchCurrentNetworkAuthorization } from '@subwallet/extension-base/background/KoniTypes';
8
8
  import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
9
9
  import { AccountJson } from '@subwallet/extension-base/types';
10
10
  import { TypeRegistry } from '@polkadot/types';
@@ -68,6 +68,7 @@ export interface RequestSignatures extends KoniRequestSignatures {
68
68
  'pri(authorize.reject)': [RequestAuthorizeReject, boolean];
69
69
  'pri(authorize.requests)': [RequestAuthorizeSubscribe, boolean, AuthorizeRequest[]];
70
70
  'pri(authorize.toggle)': [string, ResponseAuthorizeList];
71
+ 'pri(authorize.switchCurrentNetwork)': [RequestSwitchCurrentNetworkAuthorization, ResponseAuthorizeList];
71
72
  'pri(derivation.create)': [RequestDeriveCreate, boolean];
72
73
  'pri(derivation.validate)': [RequestDeriveValidate, ResponseDeriveValidate];
73
74
  'pri(json.batchRestore)': [RequestBatchRestore, void];
@@ -24,6 +24,7 @@ var _TransactionError = require("@subwallet/extension-base/background/errors/Tra
24
24
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
25
25
  var _types = require("@subwallet/extension-base/types");
26
26
  var _utils = require("@subwallet/extension-base/utils");
27
+ var _cardano = require("@subwallet/extension-base/utils/cardano");
27
28
  var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
28
29
  var _getId = require("@subwallet/extension-base/utils/getId");
29
30
  var _keyring = require("@subwallet/keyring");
@@ -567,8 +568,10 @@ function validationAuthWCMiddleware(koni, url, payload, topic) {
567
568
  async function validationCardanoSignDataMiddleware(koni, url, payload_) {
568
569
  const {
569
570
  address,
571
+ authInfo,
570
572
  errors,
571
- pair: pair_
573
+ pair: pair_,
574
+ type
572
575
  } = payload_;
573
576
  const payload = payload_.payloadAfterValidated;
574
577
  const {
@@ -590,6 +593,15 @@ async function validationCardanoSignDataMiddleware(koni, url, payload_) {
590
593
  if (!(0, _keyring.isCardanoAddress)(address)) {
591
594
  handleError('Not found cardano address');
592
595
  }
596
+ const currentCardanoNetwork = koni.requestService.getDAppChainInfo({
597
+ autoActive: true,
598
+ accessType: 'cardano',
599
+ defaultChain: authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap[type],
600
+ url
601
+ });
602
+ if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
603
+ handleError('Invalid address network');
604
+ }
593
605
  const pair = pair_ || _uiKeyring.keyring.getPair(address);
594
606
  if (!(pair !== null && pair !== void 0 && pair.meta.isExtneral)) {
595
607
  canSign = true;
@@ -682,6 +682,64 @@ class KoniExtension {
682
682
  });
683
683
  });
684
684
  }
685
+ async switchCurrentNetworkAuthorization(_ref19) {
686
+ let {
687
+ authSwitchNetworkType,
688
+ networkKey,
689
+ url
690
+ } = _ref19;
691
+ const authUrls = await this.#koniState.getAuthList();
692
+ const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
693
+ const chainState = this.#koniState.getChainStateByKey(networkKey);
694
+ const {
695
+ promise,
696
+ resolve
697
+ } = (0, _utils7.createPromiseHandler)();
698
+ const typeInfoMap = {
699
+ substrate: 'substrateInfo',
700
+ evm: 'evmInfo',
701
+ cardano: 'cardanoInfo',
702
+ ton: 'tonInfo'
703
+ };
704
+ const typeInfoKey = typeInfoMap[authSwitchNetworkType];
705
+ if (!typeInfoKey || !chainInfo[typeInfoKey]) {
706
+ throw new Error((0, _i18next.t)('Network {{networkKey}} is not {{authSwitchNetworkType}}', {
707
+ replace: {
708
+ networkKey,
709
+ authSwitchNetworkType
710
+ }
711
+ }));
712
+ }
713
+ const authUrl = authUrls[url];
714
+ if (!authUrl) {
715
+ throw new Error((0, _i18next.t)('Not found {{url}} in auth list', {
716
+ replace: {
717
+ url
718
+ }
719
+ }));
720
+ }
721
+ if (chainInfo && !(0, _utils5._isChainEnabled)(chainState)) {
722
+ await this.enableChainWithPriorityAssets({
723
+ chainSlug: networkKey,
724
+ enableTokens: true
725
+ });
726
+ }
727
+ if (!authUrl.accountAuthTypes.includes(authSwitchNetworkType)) {
728
+ throw new Error((0, _i18next.t)('Network {{networkKey}} is not supported by {{authSwitchNetworkType}}', {
729
+ replace: {
730
+ networkKey,
731
+ authSwitchNetworkType
732
+ }
733
+ }));
734
+ }
735
+ authUrl.currentNetworkMap[authSwitchNetworkType] = networkKey;
736
+ this.#koniState.setAuthorize(authUrls, () => {
737
+ resolve({
738
+ list: authUrls
739
+ });
740
+ });
741
+ return promise;
742
+ }
685
743
  changeAuthorization(data, id, port) {
686
744
  const cb = (0, _subscriptions.createSubscription)(id, port);
687
745
  this._changeAuthorization(data.url, data.connectValue, items => {
@@ -778,10 +836,10 @@ class KoniExtension {
778
836
  this.#koniState.updateSetting('theme', data);
779
837
  return true;
780
838
  }
781
- setCamera(_ref19) {
839
+ setCamera(_ref20) {
782
840
  let {
783
841
  camera
784
- } = _ref19;
842
+ } = _ref20;
785
843
  this.#koniState.updateSetting('camera', camera);
786
844
  return true;
787
845
  }
@@ -789,17 +847,17 @@ class KoniExtension {
789
847
  this.#koniState.updateSetting('browserConfirmationType', data);
790
848
  return true;
791
849
  }
792
- setAutoLockTime(_ref20) {
850
+ setAutoLockTime(_ref21) {
793
851
  let {
794
852
  autoLockTime
795
- } = _ref20;
853
+ } = _ref21;
796
854
  this.#koniState.updateSetting('timeAutoLock', autoLockTime);
797
855
  return true;
798
856
  }
799
- setUnlockType(_ref21) {
857
+ setUnlockType(_ref22) {
800
858
  let {
801
859
  unlockType
802
- } = _ref21;
860
+ } = _ref22;
803
861
  this.#koniState.updateSetting('unlockType', unlockType);
804
862
  return true;
805
863
  }
@@ -816,10 +874,10 @@ class KoniExtension {
816
874
  });
817
875
  return await this.getSettings();
818
876
  }
819
- setEnableChainPatrol(_ref22) {
877
+ setEnableChainPatrol(_ref23) {
820
878
  let {
821
879
  enable
822
- } = _ref22;
880
+ } = _ref23;
823
881
  this.#koniState.updateSetting('enableChainPatrol', enable);
824
882
  return true;
825
883
  }
@@ -827,17 +885,17 @@ class KoniExtension {
827
885
  this.#koniState.updateSetting('notificationSetup', request);
828
886
  return true;
829
887
  }
830
- saveMigrationAcknowledgedStatus(_ref23) {
888
+ saveMigrationAcknowledgedStatus(_ref24) {
831
889
  let {
832
890
  isAcknowledgedUnifiedAccountMigration
833
- } = _ref23;
891
+ } = _ref24;
834
892
  this.#koniState.updateSetting('isAcknowledgedUnifiedAccountMigration', isAcknowledgedUnifiedAccountMigration);
835
893
  return true;
836
894
  }
837
- saveUnifiedAccountMigrationInProgress(_ref24) {
895
+ saveUnifiedAccountMigrationInProgress(_ref25) {
838
896
  let {
839
897
  isUnifiedAccountMigrationInProgress
840
- } = _ref24;
898
+ } = _ref25;
841
899
  this.#koniState.updateSetting('isUnifiedAccountMigrationInProgress', isUnifiedAccountMigrationInProgress);
842
900
  return true;
843
901
  }
@@ -845,31 +903,31 @@ class KoniExtension {
845
903
  this.#koniState.updateSetting('isUnifiedAccountMigrationInProgress', false);
846
904
  return true;
847
905
  }
848
- setShowZeroBalance(_ref25) {
906
+ setShowZeroBalance(_ref26) {
849
907
  let {
850
908
  show
851
- } = _ref25;
909
+ } = _ref26;
852
910
  this.#koniState.updateSetting('isShowZeroBalance', show);
853
911
  return true;
854
912
  }
855
- setLanguage(_ref26) {
913
+ setLanguage(_ref27) {
856
914
  let {
857
915
  language
858
- } = _ref26;
916
+ } = _ref27;
859
917
  this.#koniState.updateSetting('language', language);
860
918
  return true;
861
919
  }
862
- setShowBalance(_ref27) {
920
+ setShowBalance(_ref28) {
863
921
  let {
864
922
  enable
865
- } = _ref27;
923
+ } = _ref28;
866
924
  this.#koniState.updateSetting('isShowBalance', enable);
867
925
  return true;
868
926
  }
869
- setAllowOneSign(_ref28) {
927
+ setAllowOneSign(_ref29) {
870
928
  let {
871
929
  allowOneSign
872
- } = _ref28;
930
+ } = _ref29;
873
931
  this.#koniState.updateSetting('allowOneSign', allowOneSign);
874
932
  return true;
875
933
  }
@@ -918,11 +976,11 @@ class KoniExtension {
918
976
  async getPrice() {
919
977
  return this.#koniState.priceService.getPrice();
920
978
  }
921
- async getHistoryTokenPrice(_ref29) {
979
+ async getHistoryTokenPrice(_ref30) {
922
980
  let {
923
981
  priceId,
924
982
  timeframe
925
- } = _ref29;
983
+ } = _ref30;
926
984
  return this.#koniState.priceService.getHistoryTokenPriceData(priceId, timeframe);
927
985
  }
928
986
  checkCoinGeckoPriceSupport(priceId) {
@@ -943,10 +1001,10 @@ class KoniExtension {
943
1001
  price: currentPrice
944
1002
  };
945
1003
  }
946
- async setPriceCurrency(_ref30) {
1004
+ async setPriceCurrency(_ref31) {
947
1005
  let {
948
1006
  currency
949
- } = _ref30;
1007
+ } = _ref31;
950
1008
  return await this.#koniState.priceService.setPriceCurrency(currency);
951
1009
  }
952
1010
  subscribePrice(id, port) {
@@ -1154,11 +1212,11 @@ class KoniExtension {
1154
1212
  // Re-filter
1155
1213
  return historySubject.getValue().filter(item => addresses.some(address => (0, _utils7.isSameAddress)(item.address, address)));
1156
1214
  }
1157
- subscribeHistoryByChainAndAddress(_ref31, id, port) {
1215
+ subscribeHistoryByChainAndAddress(_ref32, id, port) {
1158
1216
  let {
1159
1217
  address,
1160
1218
  chain
1161
- } = _ref31;
1219
+ } = _ref32;
1162
1220
  const cb = (0, _subscriptions.createSubscription)(id, port);
1163
1221
  const subscribeHistoriesResponse = this.#koniState.historyService.subscribeHistories(chain, address, cb);
1164
1222
  this.createUnsubscriptionHandle(id, subscribeHistoriesResponse.unsubscribe);
@@ -1726,28 +1784,28 @@ class KoniExtension {
1726
1784
  disableChain(networkKey) {
1727
1785
  return this.#koniState.disableChain(networkKey);
1728
1786
  }
1729
- async enableChain(_ref32) {
1787
+ async enableChain(_ref33) {
1730
1788
  let {
1731
1789
  chainSlug,
1732
1790
  enableTokens
1733
- } = _ref32;
1791
+ } = _ref33;
1734
1792
  return await this.#koniState.enableChain(chainSlug, enableTokens);
1735
1793
  }
1736
- async enableChainWithPriorityAssets(_ref33) {
1794
+ async enableChainWithPriorityAssets(_ref34) {
1737
1795
  let {
1738
1796
  chainSlug,
1739
1797
  enableTokens
1740
- } = _ref33;
1798
+ } = _ref34;
1741
1799
  return await this.#koniState.enableChainWithPriorityAssets(chainSlug, enableTokens);
1742
1800
  }
1743
1801
  async reconnectChain(chainSlug) {
1744
1802
  return this.#koniState.chainService.reconnectChain(chainSlug);
1745
1803
  }
1746
- async validateNetwork(_ref34) {
1804
+ async validateNetwork(_ref35) {
1747
1805
  let {
1748
1806
  existedChainSlug,
1749
1807
  provider
1750
- } = _ref34;
1808
+ } = _ref35;
1751
1809
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1752
1810
  }
1753
1811
  resetDefaultNetwork() {
@@ -1819,13 +1877,13 @@ class KoniExtension {
1819
1877
  async validateCustomAsset(data) {
1820
1878
  return await this.#koniState.validateCustomAsset(data);
1821
1879
  }
1822
- async getAddressTransferableBalance(_ref35) {
1880
+ async getAddressTransferableBalance(_ref36) {
1823
1881
  let {
1824
1882
  address,
1825
1883
  extrinsicType,
1826
1884
  networkKey,
1827
1885
  token
1828
- } = _ref35;
1886
+ } = _ref36;
1829
1887
  if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
1830
1888
  const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1831
1889
  if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
@@ -1834,13 +1892,13 @@ class KoniExtension {
1834
1892
  }
1835
1893
  return await this.#koniState.balanceService.getTransferableBalance(address, networkKey, token, extrinsicType);
1836
1894
  }
1837
- async getAddressTotalBalance(_ref36) {
1895
+ async getAddressTotalBalance(_ref37) {
1838
1896
  let {
1839
1897
  address,
1840
1898
  extrinsicType,
1841
1899
  networkKey,
1842
1900
  token
1843
- } = _ref36;
1901
+ } = _ref37;
1844
1902
  return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
1845
1903
  }
1846
1904
  async subscribeMaxTransferable(request, id, port) {
@@ -1892,11 +1950,11 @@ class KoniExtension {
1892
1950
  freeBalance: freeBalanceSubject,
1893
1951
  fee: feeSubject
1894
1952
  }).subscribe({
1895
- next: _ref37 => {
1953
+ next: _ref38 => {
1896
1954
  let {
1897
1955
  fee,
1898
1956
  freeBalance
1899
- } = _ref37;
1957
+ } = _ref38;
1900
1958
  (0, _utils7.calculateMaxTransferable)(id, _request, freeBalance, fee).then(cb).catch(console.error);
1901
1959
  }
1902
1960
  });
@@ -1930,13 +1988,13 @@ class KoniExtension {
1930
1988
  });
1931
1989
  return (0, _utils7.calculateMaxTransferable)(id, _request, freeBalance, fee);
1932
1990
  }
1933
- async subscribeAddressTransferableBalance(_ref38, id, port) {
1991
+ async subscribeAddressTransferableBalance(_ref39, id, port) {
1934
1992
  let {
1935
1993
  address,
1936
1994
  extrinsicType,
1937
1995
  networkKey,
1938
1996
  token
1939
- } = _ref38;
1997
+ } = _ref39;
1940
1998
  const cb = (0, _subscriptions.createSubscription)(id, port);
1941
1999
  const convertData = data => {
1942
2000
  return {
@@ -1987,11 +2045,11 @@ class KoniExtension {
1987
2045
  isSendingSelf
1988
2046
  };
1989
2047
  }
1990
- async enableChains(_ref39) {
2048
+ async enableChains(_ref40) {
1991
2049
  let {
1992
2050
  chainSlugs,
1993
2051
  enableTokens
1994
- } = _ref39;
2052
+ } = _ref40;
1995
2053
  try {
1996
2054
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
1997
2055
  chainSlug,
@@ -2124,30 +2182,30 @@ class KoniExtension {
2124
2182
 
2125
2183
  // Parse transaction
2126
2184
 
2127
- parseSubstrateTransaction(_ref40) {
2185
+ parseSubstrateTransaction(_ref41) {
2128
2186
  let {
2129
2187
  data,
2130
2188
  networkKey
2131
- } = _ref40;
2189
+ } = _ref41;
2132
2190
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2133
2191
  const apiPromise = apiProps.api;
2134
2192
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2135
2193
  }
2136
- async parseEVMRLP(_ref41) {
2194
+ async parseEVMRLP(_ref42) {
2137
2195
  let {
2138
2196
  data
2139
- } = _ref41;
2197
+ } = _ref42;
2140
2198
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2141
2199
  }
2142
2200
 
2143
2201
  // Sign
2144
2202
 
2145
- qrSignSubstrate(_ref42) {
2203
+ qrSignSubstrate(_ref43) {
2146
2204
  let {
2147
2205
  address,
2148
2206
  data,
2149
2207
  networkKey
2150
- } = _ref42;
2208
+ } = _ref43;
2151
2209
  const pair = _uiKeyring.keyring.getPair(address);
2152
2210
  (0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
2153
2211
  if (pair.isLocked) {
@@ -2164,13 +2222,13 @@ class KoniExtension {
2164
2222
  signature: signed
2165
2223
  };
2166
2224
  }
2167
- async qrSignEVM(_ref43) {
2225
+ async qrSignEVM(_ref44) {
2168
2226
  let {
2169
2227
  address,
2170
2228
  chainId,
2171
2229
  message,
2172
2230
  type
2173
- } = _ref43;
2231
+ } = _ref44;
2174
2232
  let signed;
2175
2233
  const network = this.getNetworkJsonByChainId(chainId);
2176
2234
  if (!network) {
@@ -2254,11 +2312,11 @@ class KoniExtension {
2254
2312
  });
2255
2313
  return this.#koniState.getNominatorMetadata();
2256
2314
  }
2257
- async getBondingOptions(_ref44) {
2315
+ async getBondingOptions(_ref45) {
2258
2316
  let {
2259
2317
  chain,
2260
2318
  type
2261
- } = _ref44;
2319
+ } = _ref45;
2262
2320
  const apiProps = this.#koniState.getSubstrateApi(chain);
2263
2321
  const chainInfo = this.#koniState.getChainInfo(chain);
2264
2322
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2448,12 +2506,12 @@ class KoniExtension {
2448
2506
  }
2449
2507
 
2450
2508
  // EVM Transaction
2451
- async parseContractInput(_ref45) {
2509
+ async parseContractInput(_ref46) {
2452
2510
  let {
2453
2511
  chainId,
2454
2512
  contract,
2455
2513
  data
2456
- } = _ref45;
2514
+ } = _ref46;
2457
2515
  const network = this.getNetworkJsonByChainId(chainId);
2458
2516
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2459
2517
  }
@@ -2553,10 +2611,10 @@ class KoniExtension {
2553
2611
 
2554
2612
  // Unlock wallet
2555
2613
 
2556
- keyringUnlock(_ref46) {
2614
+ keyringUnlock(_ref47) {
2557
2615
  let {
2558
2616
  password
2559
- } = _ref46;
2617
+ } = _ref47;
2560
2618
  try {
2561
2619
  _uiKeyring.keyring.unlockKeyring(password);
2562
2620
  // this.#koniState.initMantaPay(password)
@@ -2587,11 +2645,11 @@ class KoniExtension {
2587
2645
 
2588
2646
  // Export mnemonic
2589
2647
 
2590
- keyringExportMnemonic(_ref47) {
2648
+ keyringExportMnemonic(_ref48) {
2591
2649
  let {
2592
2650
  address,
2593
2651
  password
2594
- } = _ref47;
2652
+ } = _ref48;
2595
2653
  const pair = _uiKeyring.keyring.getPair(address);
2596
2654
  const result = pair.exportMnemonic(password);
2597
2655
  return {
@@ -2601,10 +2659,10 @@ class KoniExtension {
2601
2659
 
2602
2660
  // Reset wallet
2603
2661
 
2604
- async resetWallet(_ref48) {
2662
+ async resetWallet(_ref49) {
2605
2663
  let {
2606
2664
  resetAll
2607
- } = _ref48;
2665
+ } = _ref49;
2608
2666
  try {
2609
2667
  await this.#koniState.resetWallet(resetAll);
2610
2668
  return {
@@ -2620,10 +2678,10 @@ class KoniExtension {
2620
2678
  }
2621
2679
 
2622
2680
  // Signing substrate request
2623
- async signingApprovePasswordV2(_ref49) {
2681
+ async signingApprovePasswordV2(_ref50) {
2624
2682
  let {
2625
2683
  id
2626
- } = _ref49;
2684
+ } = _ref50;
2627
2685
  const queued = this.#koniState.getSignRequest(id);
2628
2686
  (0, _util.assert)(queued, (0, _i18next.t)('Unable to proceed. Please try again'));
2629
2687
  const {
@@ -2782,10 +2840,10 @@ class KoniExtension {
2782
2840
  getSupportedSmartContractTypes() {
2783
2841
  return this.#koniState.getSupportedSmartContractTypes();
2784
2842
  }
2785
- getTransaction(_ref50) {
2843
+ getTransaction(_ref51) {
2786
2844
  let {
2787
2845
  id
2788
- } = _ref50;
2846
+ } = _ref51;
2789
2847
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2790
2848
  const {
2791
2849
  transaction,
@@ -2796,8 +2854,8 @@ class KoniExtension {
2796
2854
  async subscribeTransactions(id, port) {
2797
2855
  const cb = (0, _subscriptions.createSubscription)(id, port);
2798
2856
  function convertRs(rs, processMap) {
2799
- return Object.fromEntries(Object.entries(rs).map(_ref51 => {
2800
- let [key, value] = _ref51;
2857
+ return Object.fromEntries(Object.entries(rs).map(_ref52 => {
2858
+ let [key, value] = _ref52;
2801
2859
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2802
2860
  const {
2803
2861
  additionalValidator,
@@ -2822,11 +2880,11 @@ class KoniExtension {
2822
2880
  const subscription = (0, _rxjs.combineLatest)({
2823
2881
  transactions: transactionsObservable,
2824
2882
  processMap: processTransactionObservable
2825
- }).subscribe(_ref52 => {
2883
+ }).subscribe(_ref53 => {
2826
2884
  let {
2827
2885
  processMap,
2828
2886
  transactions
2829
- } = _ref52;
2887
+ } = _ref53;
2830
2888
  cb(convertRs(transactions, processMap));
2831
2889
  });
2832
2890
  port.onDisconnect.addListener(() => {
@@ -2847,10 +2905,10 @@ class KoniExtension {
2847
2905
  });
2848
2906
  return notificationSubject.value;
2849
2907
  }
2850
- async reloadCron(_ref53) {
2908
+ async reloadCron(_ref54) {
2851
2909
  let {
2852
2910
  data
2853
- } = _ref53;
2911
+ } = _ref54;
2854
2912
  if (data === 'nft') {
2855
2913
  return await this.#koniState.reloadNft();
2856
2914
  } else if (data === 'staking') {
@@ -2893,10 +2951,10 @@ class KoniExtension {
2893
2951
  }
2894
2952
 
2895
2953
  // Phishing detect
2896
- async passPhishingPage(_ref54) {
2954
+ async passPhishingPage(_ref55) {
2897
2955
  let {
2898
2956
  url
2899
- } = _ref54;
2957
+ } = _ref55;
2900
2958
  return await this.#koniState.approvePassPhishingPage(url);
2901
2959
  }
2902
2960
 
@@ -2917,10 +2975,10 @@ class KoniExtension {
2917
2975
  /// Wallet connect
2918
2976
 
2919
2977
  // Connect
2920
- async connectWalletConnect(_ref55) {
2978
+ async connectWalletConnect(_ref56) {
2921
2979
  let {
2922
2980
  uri
2923
- } = _ref55;
2981
+ } = _ref56;
2924
2982
  await this.#koniState.walletConnectService.connect(uri);
2925
2983
  return true;
2926
2984
  }
@@ -2933,11 +2991,11 @@ class KoniExtension {
2933
2991
  });
2934
2992
  return this.#koniState.requestService.allConnectWCRequests;
2935
2993
  }
2936
- async approveWalletConnectSession(_ref56) {
2994
+ async approveWalletConnectSession(_ref57) {
2937
2995
  let {
2938
2996
  accounts: selectedAccounts,
2939
2997
  id
2940
- } = _ref56;
2998
+ } = _ref57;
2941
2999
  const request = this.#koniState.requestService.getConnectWCRequest(id);
2942
3000
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
2943
3001
  throw new Error('The proposal has been expired');
@@ -2949,8 +3007,8 @@ class KoniExtension {
2949
3007
  const availableNamespaces = {};
2950
3008
  const namespaces = {};
2951
3009
  const chainInfoMap = this.#koniState.getChainInfoMap();
2952
- Object.entries(requiredNamespaces).forEach(_ref57 => {
2953
- let [key, namespace] = _ref57;
3010
+ Object.entries(requiredNamespaces).forEach(_ref58 => {
3011
+ let [key, namespace] = _ref58;
2954
3012
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
2955
3013
  if (namespace.chains) {
2956
3014
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
@@ -2963,8 +3021,8 @@ class KoniExtension {
2963
3021
  throw new Error((0, _utils8.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
2964
3022
  }
2965
3023
  });
2966
- Object.entries(optionalNamespaces).forEach(_ref58 => {
2967
- let [key, namespace] = _ref58;
3024
+ Object.entries(optionalNamespaces).forEach(_ref59 => {
3025
+ let [key, namespace] = _ref59;
2968
3026
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
2969
3027
  if (namespace.chains) {
2970
3028
  const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
@@ -2988,8 +3046,8 @@ class KoniExtension {
2988
3046
  }
2989
3047
  }
2990
3048
  });
2991
- Object.entries(availableNamespaces).forEach(_ref59 => {
2992
- let [key, namespace] = _ref59;
3049
+ Object.entries(availableNamespaces).forEach(_ref60 => {
3050
+ let [key, namespace] = _ref60;
2993
3051
  if (namespace.chains) {
2994
3052
  const accounts = selectedAccounts.filter(address => {
2995
3053
  const [_namespace] = address.split(':');
@@ -3013,10 +3071,10 @@ class KoniExtension {
3013
3071
  request.resolve();
3014
3072
  return true;
3015
3073
  }
3016
- async rejectWalletConnectSession(_ref60) {
3074
+ async rejectWalletConnectSession(_ref61) {
3017
3075
  let {
3018
3076
  id
3019
- } = _ref60;
3077
+ } = _ref61;
3020
3078
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3021
3079
  const wcId = request.request.id;
3022
3080
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
@@ -3038,10 +3096,10 @@ class KoniExtension {
3038
3096
  });
3039
3097
  return this.#koniState.walletConnectService.sessions;
3040
3098
  }
3041
- async disconnectWalletConnectSession(_ref61) {
3099
+ async disconnectWalletConnectSession(_ref62) {
3042
3100
  let {
3043
3101
  topic
3044
- } = _ref61;
3102
+ } = _ref62;
3045
3103
  await this.#koniState.walletConnectService.disconnect(topic);
3046
3104
  return true;
3047
3105
  }
@@ -3054,18 +3112,18 @@ class KoniExtension {
3054
3112
  });
3055
3113
  return this.#koniState.requestService.allNotSupportWCRequests;
3056
3114
  }
3057
- approveWalletConnectNotSupport(_ref62) {
3115
+ approveWalletConnectNotSupport(_ref63) {
3058
3116
  let {
3059
3117
  id
3060
- } = _ref62;
3118
+ } = _ref63;
3061
3119
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3062
3120
  request.resolve();
3063
3121
  return true;
3064
3122
  }
3065
- rejectWalletConnectNotSupport(_ref63) {
3123
+ rejectWalletConnectNotSupport(_ref64) {
3066
3124
  let {
3067
3125
  id
3068
- } = _ref63;
3126
+ } = _ref64;
3069
3127
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3070
3128
  request.reject(new Error('USER_REJECTED'));
3071
3129
  return true;
@@ -3073,11 +3131,11 @@ class KoniExtension {
3073
3131
 
3074
3132
  /// Manta
3075
3133
 
3076
- async enableMantaPay(_ref64) {
3134
+ async enableMantaPay(_ref65) {
3077
3135
  let {
3078
3136
  address,
3079
3137
  password
3080
- } = _ref64;
3138
+ } = _ref65;
3081
3139
  // always takes the current account
3082
3140
  function timeout() {
3083
3141
  return new Promise(resolve => setTimeout(resolve, 1500));
@@ -3167,11 +3225,11 @@ class KoniExtension {
3167
3225
  async disableMantaPay(address) {
3168
3226
  return this.#koniState.disableMantaPay(address);
3169
3227
  }
3170
- async isTonBounceableAddress(_ref65) {
3228
+ async isTonBounceableAddress(_ref66) {
3171
3229
  let {
3172
3230
  address,
3173
3231
  chain
3174
- } = _ref65;
3232
+ } = _ref66;
3175
3233
  try {
3176
3234
  const tonApi = this.#koniState.getTonApi(chain);
3177
3235
  const state = await tonApi.getAccountState(address);
@@ -3217,10 +3275,10 @@ class KoniExtension {
3217
3275
 
3218
3276
  /* Metadata */
3219
3277
 
3220
- async findRawMetadata(_ref66) {
3278
+ async findRawMetadata(_ref67) {
3221
3279
  let {
3222
3280
  genesisHash
3223
- } = _ref66;
3281
+ } = _ref67;
3224
3282
  const {
3225
3283
  metadata,
3226
3284
  specVersion,
@@ -3234,20 +3292,20 @@ class KoniExtension {
3234
3292
  userExtensions
3235
3293
  };
3236
3294
  }
3237
- async calculateMetadataHash(_ref67) {
3295
+ async calculateMetadataHash(_ref68) {
3238
3296
  let {
3239
3297
  chain
3240
- } = _ref67;
3298
+ } = _ref68;
3241
3299
  const hash = await this.#koniState.calculateMetadataHash(chain);
3242
3300
  return {
3243
3301
  metadataHash: hash || ''
3244
3302
  };
3245
3303
  }
3246
- async shortenMetadata(_ref68) {
3304
+ async shortenMetadata(_ref69) {
3247
3305
  let {
3248
3306
  chain,
3249
3307
  txBlob
3250
- } = _ref68;
3308
+ } = _ref69;
3251
3309
  const shorten = await this.#koniState.shortenMetadata(chain, txBlob);
3252
3310
  return {
3253
3311
  txMetadata: shorten || ''
@@ -3600,18 +3658,18 @@ class KoniExtension {
3600
3658
 
3601
3659
  /* Campaign */
3602
3660
 
3603
- unlockDotCheckCanMint(_ref69) {
3661
+ unlockDotCheckCanMint(_ref70) {
3604
3662
  let {
3605
3663
  address,
3606
3664
  network,
3607
3665
  slug
3608
- } = _ref69;
3666
+ } = _ref70;
3609
3667
  return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
3610
3668
  }
3611
- unlockDotSubscribeMintedData(id, port, _ref70) {
3669
+ unlockDotSubscribeMintedData(id, port, _ref71) {
3612
3670
  let {
3613
3671
  transactionId
3614
- } = _ref70;
3672
+ } = _ref71;
3615
3673
  const cb = (0, _subscriptions.createSubscription)(id, port);
3616
3674
  const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
3617
3675
  this.createUnsubscriptionHandle(id, subscription.unsubscribe);
@@ -3643,10 +3701,10 @@ class KoniExtension {
3643
3701
  });
3644
3702
  return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3645
3703
  }
3646
- async completeCampaignBanner(_ref71) {
3704
+ async completeCampaignBanner(_ref72) {
3647
3705
  let {
3648
3706
  slug
3649
- } = _ref71;
3707
+ } = _ref72;
3650
3708
  const campaign = await this.#koniState.dbService.getCampaign(slug);
3651
3709
  if (campaign) {
3652
3710
  await this.#koniState.dbService.upsertCampaign({
@@ -4181,8 +4239,8 @@ class KoniExtension {
4181
4239
  resolve();
4182
4240
  }
4183
4241
  };
4184
- this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref72 => {
4185
- let [_unsub, rs] = _ref72;
4242
+ this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref73 => {
4243
+ let [_unsub, rs] = _ref73;
4186
4244
  unsub = _unsub;
4187
4245
  onRs(rs);
4188
4246
  }).catch(console.error);
@@ -4344,6 +4402,8 @@ class KoniExtension {
4344
4402
  return this.getAuthListV2();
4345
4403
  case 'pri(authorize.toggle)':
4346
4404
  return this.toggleAuthorization2(request);
4405
+ case 'pri(authorize.switchCurrentNetwork)':
4406
+ return this.switchCurrentNetworkAuthorization(request);
4347
4407
  case 'pri(settings.changeBalancesVisibility)':
4348
4408
  return await this.toggleBalancesVisibility();
4349
4409
 
@@ -1117,13 +1117,13 @@ class KoniState {
1117
1117
  if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
1118
1118
  autoActiveChain = true;
1119
1119
  }
1120
- const currentEvmNetwork = this.requestService.getDAppChainInfo({
1120
+ const currentCardanoNetwork = this.requestService.getDAppChainInfo({
1121
1121
  autoActive: autoActiveChain,
1122
1122
  accessType: 'cardano',
1123
1123
  defaultChain: networkKey,
1124
1124
  url
1125
1125
  });
1126
- networkKey = (currentEvmNetwork === null || currentEvmNetwork === void 0 ? void 0 : currentEvmNetwork.slug) || 'cardano';
1126
+ networkKey = (currentCardanoNetwork === null || currentCardanoNetwork === void 0 ? void 0 : currentCardanoNetwork.slug) || 'cardano';
1127
1127
  const allUtxos = await this.chainService.getUtxosByAddress(currentAddress, networkKey);
1128
1128
  const outputTransactionUnSpend = CardanoWasm.TransactionOutputs.new();
1129
1129
  inputs.to_js_value().forEach(input => {
@@ -1160,12 +1160,23 @@ class KoniState {
1160
1160
  values: (0, _helper.convertValueToAsset)(output)
1161
1161
  };
1162
1162
  if ((0, _utils3.isSameAddress)(currentAddress, address)) {
1163
+ if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
1164
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.ACCOUNT_CHANGED, (0, _i18next.t)('Current network is changed'));
1165
+ }
1163
1166
  transactionValue = transactionValue.checked_add(amount);
1164
1167
  addressInputAmountMap[address].isOwner = true;
1165
1168
  addressOutputAmountMap[address].isOwner = true;
1166
1169
  }
1170
+
1171
+ // Check if address is valid with current network
1172
+ if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
1173
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, (0, _i18next.t)('Current network is not match with input address'));
1174
+ }
1167
1175
  }
1168
1176
  for (const address in addressOutputMap) {
1177
+ if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
1178
+ throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, (0, _i18next.t)('Current network is not match with output address'));
1179
+ }
1169
1180
  if (!addressInputAmountMap[address] && !addressOutputMap[address].is_zero()) {
1170
1181
  addressOutputAmountMap[address] = {
1171
1182
  values: (0, _helper.convertValueToAsset)(addressOutputMap[address]),
@@ -1274,13 +1285,7 @@ class KoniState {
1274
1285
  async onMV3Update() {
1275
1286
  const migrationStatus = await _storage.SWStorage.instance.getItem('mv3_migration');
1276
1287
  if (!migrationStatus || migrationStatus !== 'done') {
1277
- if (_utils3.isManifestV3) {
1278
- // Open migration tab
1279
- const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
1280
- await (0, _PopupHandler.openPopup)(url);
1281
-
1282
- // migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
1283
- } else {
1288
+ if (!_utils3.isManifestV3) {
1284
1289
  this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
1285
1290
  }
1286
1291
  }
@@ -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.36-0'
16
+ version: '1.3.37-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -273,7 +273,10 @@ class AuthRequestHandler {
273
273
  origin,
274
274
  url,
275
275
  accountAuthTypes: [...new Set([...accountAuthTypes, ...((existed === null || existed === void 0 ? void 0 : existed.accountAuthTypes) || [])])],
276
- currentNetworkMap: existed ? existed.currentNetworkMap : defaultNetworkMap
276
+ currentNetworkMap: existed ? {
277
+ ...defaultNetworkMap,
278
+ ...existed.currentNetworkMap
279
+ } : defaultNetworkMap
277
280
  };
278
281
  this.setAuthorize(authorizeList, () => {
279
282
  cb();
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.convertCardanoHexToBech32 = exports.convertCardanoAddressToHex = void 0;
6
+ exports.validateAddressNetwork = exports.convertCardanoHexToBech32 = exports.convertCardanoAddressToHex = void 0;
7
7
  var _cardanoSerializationLibNodejs = require("@emurgo/cardano-serialization-lib-nodejs");
8
+ var _keyring = require("@subwallet/keyring");
8
9
  // Copyright 2019-2022 @polkadot/extension authors & contributors
9
10
  // SPDX-License-Identifier: Apache-2.0
10
11
 
@@ -17,4 +18,11 @@ const convertCardanoHexToBech32 = hexAddress => {
17
18
  const addr = _cardanoSerializationLibNodejs.Address.from_hex(hexAddress);
18
19
  return addr.to_bech32();
19
20
  };
20
- exports.convertCardanoHexToBech32 = convertCardanoHexToBech32;
21
+ exports.convertCardanoHexToBech32 = convertCardanoHexToBech32;
22
+ const validateAddressNetwork = (address, chainInfo) => {
23
+ if (!(chainInfo !== null && chainInfo !== void 0 && chainInfo.cardanoInfo) || !chainInfo.isTestnet) {
24
+ return (0, _keyring.isCardanoMainnetAddress)(address);
25
+ }
26
+ return (0, _keyring.isCardanoTestnetAddress)(address);
27
+ };
28
+ exports.validateAddressNetwork = validateAddressNetwork;
@@ -8,6 +8,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
8
8
  import { CardanoProviderErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
9
9
  import { BasicTxErrorType } from '@subwallet/extension-base/types';
10
10
  import { BN_ZERO, combineEthFee, createPromiseHandler, isSameAddress, stripUrl, wait } from '@subwallet/extension-base/utils';
11
+ import { validateAddressNetwork } from '@subwallet/extension-base/utils/cardano';
11
12
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
12
13
  import { getId } from '@subwallet/extension-base/utils/getId';
13
14
  import { isCardanoAddress, isSubstrateAddress } from '@subwallet/keyring';
@@ -547,8 +548,10 @@ export function validationAuthWCMiddleware(koni, url, payload, topic) {
547
548
  export async function validationCardanoSignDataMiddleware(koni, url, payload_) {
548
549
  const {
549
550
  address,
551
+ authInfo,
550
552
  errors,
551
- pair: pair_
553
+ pair: pair_,
554
+ type
552
555
  } = payload_;
553
556
  const payload = payload_.payloadAfterValidated;
554
557
  const {
@@ -570,6 +573,15 @@ export async function validationCardanoSignDataMiddleware(koni, url, payload_) {
570
573
  if (!isCardanoAddress(address)) {
571
574
  handleError('Not found cardano address');
572
575
  }
576
+ const currentCardanoNetwork = koni.requestService.getDAppChainInfo({
577
+ autoActive: true,
578
+ accessType: 'cardano',
579
+ defaultChain: authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap[type],
580
+ url
581
+ });
582
+ if (!validateAddressNetwork(address, currentCardanoNetwork)) {
583
+ handleError('Invalid address network');
584
+ }
573
585
  const pair = pair_ || keyring.getPair(address);
574
586
  if (!(pair !== null && pair !== void 0 && pair.meta.isExtneral)) {
575
587
  canSign = true;
@@ -59,6 +59,7 @@ export default class KoniExtension {
59
59
  private changeAuthorizationAll;
60
60
  private _changeAuthorization;
61
61
  toggleAuthorization2(url: string): Promise<ResponseAuthorizeList>;
62
+ private switchCurrentNetworkAuthorization;
62
63
  private changeAuthorization;
63
64
  private _changeAuthorizationPerAcc;
64
65
  private _changeAuthorizationBlock;
@@ -36,7 +36,7 @@ import { _isPolygonChainBridge, getClaimPolygonBridge, isClaimedPolygonBridge }
36
36
  import { _isPosChainBridge, getClaimPosBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
37
37
  import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
38
38
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
39
- import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _isAssetSmartContractNft, _isChainEvmCompatible, _isChainSubstrateCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isNativeTokenBySlug, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
39
+ import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _isAssetSmartContractNft, _isChainEnabled, _isChainEvmCompatible, _isChainSubstrateCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isNativeTokenBySlug, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
40
40
  import { calculateToAmountByReservePool } from '@subwallet/extension-base/services/fee-service/utils';
41
41
  import { batchExtrinsicSetFeeHydration, getAssetHubTokensCanPayFee, getHydrationTokensCanPayFee } from '@subwallet/extension-base/services/fee-service/utils/tokenPayFee';
42
42
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
@@ -45,7 +45,7 @@ import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectN
45
45
  import { SWStorage } from '@subwallet/extension-base/storage';
46
46
  import { AccountsStore } from '@subwallet/extension-base/stores';
47
47
  import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, CommonStepType, EarningProcessType, ProcessType, StakingTxErrorType, StepStatus, SwapFeeType, YieldPoolType, YieldStepType } from '@subwallet/extension-base/types';
48
- import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, createTransactionFromRLP, detectTransferTxType, getAccountSignMode, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
48
+ import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, createPromiseHandler, createTransactionFromRLP, detectTransferTxType, getAccountSignMode, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
49
49
  import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
50
50
  import { getId } from '@subwallet/extension-base/utils/getId';
51
51
  import { getKeypairTypeByAddress, isAddress, isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
@@ -648,6 +648,63 @@ export default class KoniExtension {
648
648
  });
649
649
  });
650
650
  }
651
+ async switchCurrentNetworkAuthorization({
652
+ authSwitchNetworkType,
653
+ networkKey,
654
+ url
655
+ }) {
656
+ const authUrls = await this.#koniState.getAuthList();
657
+ const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
658
+ const chainState = this.#koniState.getChainStateByKey(networkKey);
659
+ const {
660
+ promise,
661
+ resolve
662
+ } = createPromiseHandler();
663
+ const typeInfoMap = {
664
+ substrate: 'substrateInfo',
665
+ evm: 'evmInfo',
666
+ cardano: 'cardanoInfo',
667
+ ton: 'tonInfo'
668
+ };
669
+ const typeInfoKey = typeInfoMap[authSwitchNetworkType];
670
+ if (!typeInfoKey || !chainInfo[typeInfoKey]) {
671
+ throw new Error(t('Network {{networkKey}} is not {{authSwitchNetworkType}}', {
672
+ replace: {
673
+ networkKey,
674
+ authSwitchNetworkType
675
+ }
676
+ }));
677
+ }
678
+ const authUrl = authUrls[url];
679
+ if (!authUrl) {
680
+ throw new Error(t('Not found {{url}} in auth list', {
681
+ replace: {
682
+ url
683
+ }
684
+ }));
685
+ }
686
+ if (chainInfo && !_isChainEnabled(chainState)) {
687
+ await this.enableChainWithPriorityAssets({
688
+ chainSlug: networkKey,
689
+ enableTokens: true
690
+ });
691
+ }
692
+ if (!authUrl.accountAuthTypes.includes(authSwitchNetworkType)) {
693
+ throw new Error(t('Network {{networkKey}} is not supported by {{authSwitchNetworkType}}', {
694
+ replace: {
695
+ networkKey,
696
+ authSwitchNetworkType
697
+ }
698
+ }));
699
+ }
700
+ authUrl.currentNetworkMap[authSwitchNetworkType] = networkKey;
701
+ this.#koniState.setAuthorize(authUrls, () => {
702
+ resolve({
703
+ list: authUrls
704
+ });
705
+ });
706
+ return promise;
707
+ }
651
708
  changeAuthorization(data, id, port) {
652
709
  const cb = createSubscription(id, port);
653
710
  this._changeAuthorization(data.url, data.connectValue, items => {
@@ -4255,6 +4312,8 @@ export default class KoniExtension {
4255
4312
  return this.getAuthListV2();
4256
4313
  case 'pri(authorize.toggle)':
4257
4314
  return this.toggleAuthorization2(request);
4315
+ case 'pri(authorize.switchCurrentNetwork)':
4316
+ return this.switchCurrentNetworkAuthorization(request);
4258
4317
  case 'pri(settings.changeBalancesVisibility)':
4259
4318
  return await this.toggleBalancesVisibility();
4260
4319
 
@@ -41,7 +41,7 @@ import WalletConnectService from '@subwallet/extension-base/services/wallet-conn
41
41
  import { SWStorage } from '@subwallet/extension-base/storage';
42
42
  import { BasicTxErrorType } from '@subwallet/extension-base/types';
43
43
  import { addLazy, isManifestV3, isSameAddress, reformatAddress, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
44
- import { convertCardanoHexToBech32 } from '@subwallet/extension-base/utils/cardano';
44
+ import { convertCardanoHexToBech32, validateAddressNetwork } from '@subwallet/extension-base/utils/cardano';
45
45
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
46
46
  import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
47
47
  import { keyring } from '@subwallet/ui-keyring';
@@ -1094,13 +1094,13 @@ export default class KoniState {
1094
1094
  if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
1095
1095
  autoActiveChain = true;
1096
1096
  }
1097
- const currentEvmNetwork = this.requestService.getDAppChainInfo({
1097
+ const currentCardanoNetwork = this.requestService.getDAppChainInfo({
1098
1098
  autoActive: autoActiveChain,
1099
1099
  accessType: 'cardano',
1100
1100
  defaultChain: networkKey,
1101
1101
  url
1102
1102
  });
1103
- networkKey = (currentEvmNetwork === null || currentEvmNetwork === void 0 ? void 0 : currentEvmNetwork.slug) || 'cardano';
1103
+ networkKey = (currentCardanoNetwork === null || currentCardanoNetwork === void 0 ? void 0 : currentCardanoNetwork.slug) || 'cardano';
1104
1104
  const allUtxos = await this.chainService.getUtxosByAddress(currentAddress, networkKey);
1105
1105
  const outputTransactionUnSpend = CardanoWasm.TransactionOutputs.new();
1106
1106
  inputs.to_js_value().forEach(input => {
@@ -1137,12 +1137,23 @@ export default class KoniState {
1137
1137
  values: convertValueToAsset(output)
1138
1138
  };
1139
1139
  if (isSameAddress(currentAddress, address)) {
1140
+ if (!validateAddressNetwork(address, currentCardanoNetwork)) {
1141
+ throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED, t('Current network is changed'));
1142
+ }
1140
1143
  transactionValue = transactionValue.checked_add(amount);
1141
1144
  addressInputAmountMap[address].isOwner = true;
1142
1145
  addressOutputAmountMap[address].isOwner = true;
1143
1146
  }
1147
+
1148
+ // Check if address is valid with current network
1149
+ if (!validateAddressNetwork(address, currentCardanoNetwork)) {
1150
+ throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Current network is not match with input address'));
1151
+ }
1144
1152
  }
1145
1153
  for (const address in addressOutputMap) {
1154
+ if (!validateAddressNetwork(address, currentCardanoNetwork)) {
1155
+ throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Current network is not match with output address'));
1156
+ }
1146
1157
  if (!addressInputAmountMap[address] && !addressOutputMap[address].is_zero()) {
1147
1158
  addressOutputAmountMap[address] = {
1148
1159
  values: convertValueToAsset(addressOutputMap[address]),
@@ -1250,13 +1261,7 @@ export default class KoniState {
1250
1261
  async onMV3Update() {
1251
1262
  const migrationStatus = await SWStorage.instance.getItem('mv3_migration');
1252
1263
  if (!migrationStatus || migrationStatus !== 'done') {
1253
- if (isManifestV3) {
1254
- // Open migration tab
1255
- const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
1256
- await openPopup(url);
1257
-
1258
- // migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
1259
- } else {
1264
+ if (!isManifestV3) {
1260
1265
  this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
1261
1266
  }
1262
1267
  }
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.3.36-0",
20
+ "version": "1.3.37-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -2710,20 +2710,20 @@
2710
2710
  "@sora-substrate/type-definitions": "^1.17.7",
2711
2711
  "@substrate/connect": "^0.8.9",
2712
2712
  "@subwallet/chain-list": "0.2.104",
2713
- "@subwallet/extension-base": "^1.3.36-0",
2714
- "@subwallet/extension-chains": "^1.3.36-0",
2715
- "@subwallet/extension-dapp": "^1.3.36-0",
2716
- "@subwallet/extension-inject": "^1.3.36-0",
2713
+ "@subwallet/extension-base": "^1.3.37-0",
2714
+ "@subwallet/extension-chains": "^1.3.37-0",
2715
+ "@subwallet/extension-dapp": "^1.3.37-0",
2716
+ "@subwallet/extension-inject": "^1.3.37-0",
2717
2717
  "@subwallet/keyring": "^0.1.11",
2718
- "@subwallet/subwallet-api-sdk": "^1.3.36-0",
2718
+ "@subwallet/subwallet-api-sdk": "^1.3.37-0",
2719
2719
  "@subwallet/ui-keyring": "^0.1.11",
2720
2720
  "@ton/core": "^0.56.3",
2721
2721
  "@ton/crypto": "^3.2.0",
2722
2722
  "@ton/ton": "^15.0.0",
2723
2723
  "@walletconnect/keyvaluestorage": "^1.1.1",
2724
- "@walletconnect/sign-client": "^2.14.0",
2725
- "@walletconnect/types": "^2.14.0",
2726
- "@walletconnect/utils": "^2.14.0",
2724
+ "@walletconnect/sign-client": "^2.20.2",
2725
+ "@walletconnect/types": "^2.20.2",
2726
+ "@walletconnect/utils": "^2.20.2",
2727
2727
  "avail-js-sdk": "^0.2.12",
2728
2728
  "axios": "^1.6.2",
2729
2729
  "bignumber.js": "^9.1.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.3.36-0'
10
+ version: '1.3.37-0'
11
11
  };
@@ -15,8 +15,8 @@ import { ChainProperties, ChainType, RuntimeVersion } from '@polkadot/types/inte
15
15
  import { AnyJson, Registry } from '@polkadot/types/types';
16
16
  export interface _DataMap {
17
17
  chainInfoMap: Record<string, _ChainInfo>;
18
- chainStateMap: Record<string, _ChainState>;
19
18
  assetRegistry: Record<string, _ChainAsset>;
19
+ chainStateMap: Record<string, _ChainState>;
20
20
  assetRefMap: Record<string, _AssetRef>;
21
21
  }
22
22
  export declare enum _ChainConnectionStatus {
@@ -260,7 +260,10 @@ export default class AuthRequestHandler {
260
260
  origin,
261
261
  url,
262
262
  accountAuthTypes: [...new Set([...accountAuthTypes, ...((existed === null || existed === void 0 ? void 0 : existed.accountAuthTypes) || [])])],
263
- currentNetworkMap: existed ? existed.currentNetworkMap : defaultNetworkMap
263
+ currentNetworkMap: existed ? {
264
+ ...defaultNetworkMap,
265
+ ...existed.currentNetworkMap
266
+ } : defaultNetworkMap
264
267
  };
265
268
  this.setAuthorize(authorizeList, () => {
266
269
  cb();
@@ -1,2 +1,4 @@
1
+ import { _ChainInfo } from '@subwallet/chain-list/types';
1
2
  export declare const convertCardanoAddressToHex: (bech32Address: string) => string;
2
3
  export declare const convertCardanoHexToBech32: (hexAddress: string) => string;
4
+ export declare const validateAddressNetwork: (address: string, chainInfo?: _ChainInfo) => boolean;
package/utils/cardano.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Address } from '@emurgo/cardano-serialization-lib-nodejs';
5
+ import { isCardanoMainnetAddress, isCardanoTestnetAddress } from '@subwallet/keyring';
5
6
  export const convertCardanoAddressToHex = bech32Address => {
6
7
  const addr = Address.from_bech32(bech32Address);
7
8
  return addr.to_hex();
@@ -9,4 +10,10 @@ export const convertCardanoAddressToHex = bech32Address => {
9
10
  export const convertCardanoHexToBech32 = hexAddress => {
10
11
  const addr = Address.from_hex(hexAddress);
11
12
  return addr.to_bech32();
13
+ };
14
+ export const validateAddressNetwork = (address, chainInfo) => {
15
+ if (!(chainInfo !== null && chainInfo !== void 0 && chainInfo.cardanoInfo) || !chainInfo.isTestnet) {
16
+ return isCardanoMainnetAddress(address);
17
+ }
18
+ return isCardanoTestnetAddress(address);
12
19
  };