@subwallet/extension-base 1.3.45-1 → 1.3.46-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 (73) hide show
  1. package/background/KoniTypes.d.ts +5 -0
  2. package/background/KoniTypes.js +5 -0
  3. package/background/types.d.ts +2 -0
  4. package/cjs/background/KoniTypes.js +7 -1
  5. package/cjs/core/logic-validation/request.js +55 -28
  6. package/cjs/core/utils.js +22 -0
  7. package/cjs/koni/background/handlers/Extension.js +84 -61
  8. package/cjs/koni/background/handlers/Tabs.js +11 -3
  9. package/cjs/packageInfo.js +1 -1
  10. package/cjs/page/evm/index.js +64 -105
  11. package/cjs/page/index.js +5 -3
  12. package/cjs/page/substrate/Accounts.js +2 -1
  13. package/cjs/services/balance-service/helpers/subscribe/index.js +3 -76
  14. package/cjs/services/chain-service/index.js +3 -0
  15. package/cjs/services/chain-service/utils/index.js +31 -1
  16. package/cjs/services/earning-service/constants/chains.js +2 -1
  17. package/cjs/services/earning-service/handlers/native-staking/base.js +3 -0
  18. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +9 -2
  19. package/cjs/services/earning-service/handlers/nomination-pool/index.js +6 -3
  20. package/cjs/services/earning-service/service.js +39 -17
  21. package/cjs/services/keyring-service/context/handlers/Json.js +2 -1
  22. package/cjs/services/keyring-service/context/handlers/Ledger.js +7 -2
  23. package/cjs/services/request-service/handler/AuthRequestHandler.js +30 -6
  24. package/cjs/types/account/info/keyring.js +1 -0
  25. package/cjs/utils/account/analyze.js +5 -2
  26. package/cjs/utils/account/common.js +93 -2
  27. package/cjs/utils/account/transform.js +10 -0
  28. package/cjs/utils/asset.js +9 -2
  29. package/cjs/utils/staticData/index.js +7 -2
  30. package/core/logic-validation/request.js +31 -4
  31. package/core/types.d.ts +3 -2
  32. package/core/utils.js +24 -2
  33. package/koni/background/handlers/Extension.js +31 -8
  34. package/koni/background/handlers/Tabs.js +11 -4
  35. package/package.json +7 -6
  36. package/packageInfo.js +1 -1
  37. package/page/evm/index.d.ts +9 -18
  38. package/page/evm/index.js +62 -101
  39. package/page/index.js +5 -3
  40. package/page/substrate/Accounts.js +2 -1
  41. package/services/balance-service/helpers/subscribe/index.d.ts +1 -11
  42. package/services/balance-service/helpers/subscribe/index.js +3 -74
  43. package/services/chain-service/index.d.ts +1 -0
  44. package/services/chain-service/index.js +3 -0
  45. package/services/chain-service/utils/index.d.ts +10 -2
  46. package/services/chain-service/utils/index.js +26 -2
  47. package/services/earning-service/constants/chains.d.ts +1 -0
  48. package/services/earning-service/constants/chains.js +2 -1
  49. package/services/earning-service/handlers/native-staking/base.d.ts +1 -0
  50. package/services/earning-service/handlers/native-staking/base.js +3 -0
  51. package/services/earning-service/handlers/native-staking/relay-chain.js +9 -2
  52. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -0
  53. package/services/earning-service/handlers/nomination-pool/index.js +6 -3
  54. package/services/earning-service/service.d.ts +2 -0
  55. package/services/earning-service/service.js +42 -20
  56. package/services/keyring-service/context/handlers/Json.js +2 -1
  57. package/services/keyring-service/context/handlers/Ledger.js +7 -2
  58. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  59. package/services/request-service/handler/AuthRequestHandler.js +30 -6
  60. package/services/request-service/types.d.ts +1 -0
  61. package/types/account/action/subscribe.d.ts +3 -0
  62. package/types/account/info/keyring.d.ts +3 -0
  63. package/types/account/info/keyring.js +1 -0
  64. package/types/balance/transfer.d.ts +1 -0
  65. package/utils/account/analyze.js +5 -2
  66. package/utils/account/common.d.ts +13 -1
  67. package/utils/account/common.js +91 -2
  68. package/utils/account/transform.js +10 -0
  69. package/utils/asset.d.ts +2 -1
  70. package/utils/asset.js +7 -1
  71. package/utils/staticData/assetHubStaking.json +1 -0
  72. package/utils/staticData/index.d.ts +4 -1
  73. package/utils/staticData/index.js +5 -1
@@ -30,6 +30,7 @@ const fetchPoolsData = async () => {
30
30
  class EarningService {
31
31
  handlers = {};
32
32
  handlerCache = new Map();
33
+ inactivePoolSlug = new Set();
33
34
  earningRewardSubject = new _rxjs.BehaviorSubject({
34
35
  ready: false,
35
36
  data: {}
@@ -43,6 +44,7 @@ class EarningService {
43
44
  yieldPositionListSubject = new _rxjs.BehaviorSubject([]); // virtual list of yieldPositionSubject with filter values
44
45
 
45
46
  useOnlineCacheOnly = true;
47
+ inactivePoolReady = (0, _utils2.createPromiseHandler)();
46
48
  constructor(state) {
47
49
  this.state = state;
48
50
  this.dbService = state.dbService;
@@ -60,10 +62,23 @@ class EarningService {
60
62
  }
61
63
  }
62
64
  const minAmountPercent = {};
65
+ const ahMapChain = await this.state.chainService.fetchAhMapChain();
63
66
  for (const chain of chains) {
64
67
  const handlers = [];
68
+ const chainInfo = this.state.getChainInfo(chain);
69
+ const symbol = (0, _utils._getChainSubstrateTokenSymbol)(chainInfo);
65
70
  if (_constants2._STAKING_CHAIN_GROUP.relay.includes(chain)) {
66
- handlers.push(new _handlers.RelayNativeStakingPoolHandler(this.state, chain));
71
+ if (_constants2._STAKING_CHAIN_GROUP.assetHub.includes(chain)) {
72
+ continue;
73
+ }
74
+ const ahChain = ahMapChain[chain];
75
+ if (ahChain) {
76
+ handlers.push(new _handlers.RelayNativeStakingPoolHandler(this.state, ahChain));
77
+ const relaySlug = _handlers.RelayNativeStakingPoolHandler.generateSlug(symbol, chain);
78
+ this.inactivePoolSlug.add(relaySlug);
79
+ } else {
80
+ handlers.push(new _handlers.RelayNativeStakingPoolHandler(this.state, chain));
81
+ }
67
82
  }
68
83
  if (_constants2._STAKING_CHAIN_GROUP.para.includes(chain)) {
69
84
  handlers.push(new _handlers.ParaNativeStakingPoolHandler(this.state, chain));
@@ -84,7 +99,14 @@ class EarningService {
84
99
  handlers.push(new _mythos.default(this.state, chain));
85
100
  }
86
101
  if (_constants2._STAKING_CHAIN_GROUP.nominationPool.includes(chain)) {
87
- handlers.push(new _handlers.NominationPoolHandler(this.state, chain));
102
+ const ahChain = ahMapChain[chain];
103
+ if (ahChain) {
104
+ handlers.push(new _handlers.NominationPoolHandler(this.state, ahChain));
105
+ const relaySlug = _handlers.NominationPoolHandler.generateSlug(symbol, chain);
106
+ this.inactivePoolSlug.add(relaySlug);
107
+ } else {
108
+ handlers.push(new _handlers.NominationPoolHandler(this.state, chain));
109
+ }
88
110
  }
89
111
  if (_constants2._STAKING_CHAIN_GROUP.liquidStaking.includes(chain)) {
90
112
  if (chain === 'bifrost_dot') {
@@ -117,6 +139,7 @@ class EarningService {
117
139
  }
118
140
  minAmountPercent.default = _base.default.defaultMinAmountPercent;
119
141
  this.minAmountPercentSubject.next(minAmountPercent);
142
+ this.inactivePoolReady.resolve();
120
143
 
121
144
  // Emit earning ready
122
145
  this.eventService.emit('earning.ready', true);
@@ -136,7 +159,7 @@ class EarningService {
136
159
  next: data => {
137
160
  const activeMap = this.state.getActiveChainInfoMap();
138
161
  const activePositions = Object.values(data).filter(item => {
139
- return !!activeMap[item.chain];
162
+ return !!activeMap[item.chain] && !this.inactivePoolSlug.has(item.slug);
140
163
  });
141
164
  this.yieldPositionListSubject.next(Object.values(activePositions));
142
165
  }
@@ -319,7 +342,9 @@ class EarningService {
319
342
  const yieldPoolInfo = {};
320
343
  const existedYieldPoolInfo = await this.dbService.getYieldPools();
321
344
  existedYieldPoolInfo.forEach(info => {
322
- yieldPoolInfo[info.slug] = info;
345
+ if (!this.inactivePoolSlug.has(info.slug)) {
346
+ yieldPoolInfo[info.slug] = info;
347
+ }
323
348
  });
324
349
  this.yieldPoolInfoSubject.next(yieldPoolInfo);
325
350
  }
@@ -354,6 +379,10 @@ class EarningService {
354
379
  }
355
380
  async fetchingPoolsInfoOnline() {
356
381
  const onlineData = await fetchPoolsData();
382
+ await this.inactivePoolReady.promise;
383
+ for (const inactiveSlug of this.inactivePoolSlug) {
384
+ delete onlineData[inactiveSlug];
385
+ }
357
386
  Object.values(onlineData).forEach(item => {
358
387
  this.updateYieldPoolInfo(item);
359
388
  });
@@ -396,14 +425,11 @@ class EarningService {
396
425
  async subscribePoolPositions(addresses, callback) {
397
426
  let cancel = false;
398
427
  await this.eventService.waitChainReady;
399
- const evmAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
400
- const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
401
428
  const activeChains = this.state.activeChainSlugs;
402
429
  const unsubList = [];
403
430
  for (const handler of Object.values(this.handlers)) {
404
431
  if (activeChains.includes(handler.chain)) {
405
- const chainInfo = handler.chainInfo;
406
- const useAddresses = (0, _utils._isChainEvmCompatible)(chainInfo) ? evmAddresses : substrateAddresses;
432
+ const [useAddresses] = (0, _utils2.filterAddressByChainInfo)(addresses, handler.chainInfo);
407
433
  handler.subscribePoolPosition(useAddresses, callback).then(unsub => {
408
434
  if (cancel) {
409
435
  unsub();
@@ -451,7 +477,9 @@ class EarningService {
451
477
  const existedYieldPosition = await this.dbService.getYieldNominationPoolPosition(addresses, this.state.activeChainSlugs);
452
478
  const yieldPositionInfo = this.yieldPositionSubject.getValue();
453
479
  existedYieldPosition.forEach(item => {
454
- yieldPositionInfo[this._getYieldPositionKey(item.slug, item.address)] = item;
480
+ if (!this.inactivePoolSlug.has(item.slug)) {
481
+ yieldPositionInfo[this._getYieldPositionKey(item.slug, item.address)] = item;
482
+ }
455
483
  });
456
484
  this.yieldPositionSubject.next(yieldPositionInfo);
457
485
  }
@@ -543,14 +571,11 @@ class EarningService {
543
571
  async getPoolReward(addresses, callback) {
544
572
  let cancel = false;
545
573
  await this.eventService.waitChainReady;
546
- const evmAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
547
- const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
548
574
  const activeChains = this.state.activeChainSlugs;
549
575
  const unsubList = [];
550
576
  for (const handler of Object.values(this.handlers)) {
551
577
  if (activeChains.includes(handler.chain)) {
552
- const chainInfo = handler.chainInfo;
553
- const useAddresses = (0, _utils._isChainEvmCompatible)(chainInfo) ? evmAddresses : substrateAddresses;
578
+ const [useAddresses] = (0, _utils2.filterAddressByChainInfo)(addresses, handler.chainInfo);
554
579
  handler.getPoolReward(useAddresses, callback).then(unsub => {
555
580
  if (cancel) {
556
581
  unsub();
@@ -599,14 +624,11 @@ class EarningService {
599
624
  async fetchPoolRewardHistory(addresses, callback) {
600
625
  let cancel = false;
601
626
  await this.eventService.waitChainReady;
602
- const evmAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
603
- const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
604
627
  const activeChains = this.state.activeChainSlugs;
605
628
  const unsubList = [];
606
629
  for (const handler of Object.values(this.handlers)) {
607
630
  if (activeChains.includes(handler.chain)) {
608
- const chainInfo = handler.chainInfo;
609
- const useAddresses = (0, _utils._isChainEvmCompatible)(chainInfo) ? evmAddresses : substrateAddresses;
631
+ const [useAddresses] = (0, _utils2.filterAddressByChainInfo)(addresses, handler.chainInfo);
610
632
  handler.getPoolRewardHistory(useAddresses, callback).then(unsub => {
611
633
  if (cancel) {
612
634
  unsub();
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.AccountJsonHandler = void 0;
7
7
  var _constants = require("@subwallet/extension-base/constants");
8
+ var _types = require("@subwallet/extension-base/types");
8
9
  var _utils = require("@subwallet/extension-base/utils");
9
10
  var _getId = require("@subwallet/extension-base/utils/getId");
10
11
  var _keyring = require("@subwallet/keyring");
@@ -326,7 +327,7 @@ class AccountJsonHandler extends _Base.AccountBaseHandler {
326
327
  let [, proxy] = _ref8;
327
328
  return _proxyIds.includes(proxy.id);
328
329
  }));
329
- const addresses = Object.values(_account).filter(account => _proxyIds.includes(account.id)).flatMap(proxy => proxy.accounts.map(account => account.address));
330
+ const addresses = Object.values(_account).filter(account => _proxyIds.includes(account.id) && account.accountType !== _types.AccountProxyType.LEDGER).flatMap(proxy => proxy.accounts.map(account => account.address));
330
331
  const rs = await _uiKeyring.keyring.backupAccounts(password, addresses);
331
332
  if (Object.keys(modifyPairs).length && Object.keys(accountProxies).length) {
332
333
  rs.accountProxies = accountProxies;
@@ -101,6 +101,7 @@ class AccountLedgerHandler extends _Base.AccountBaseHandler {
101
101
  isEthereum,
102
102
  isGeneric,
103
103
  isLedgerRecovery,
104
+ isSubstrateECDSA,
104
105
  name,
105
106
  originGenesisHash
106
107
  } = account;
@@ -112,9 +113,13 @@ class AccountLedgerHandler extends _Base.AccountBaseHandler {
112
113
  genesisHash,
113
114
  originGenesisHash,
114
115
  isGeneric,
115
- isLedgerRecovery
116
+ isLedgerRecovery,
117
+ isSubstrateECDSA
116
118
  };
117
- const type = isEthereum ? 'ethereum' : 'sr25519';
119
+ let type = 'sr25519';
120
+ if (isEthereum || isSubstrateECDSA) {
121
+ type = 'ethereum';
122
+ }
118
123
  const pair = _uiKeyring.keyring.keyring.createFromAddress(address, {
119
124
  ...baseMeta,
120
125
  isExternal: true,
@@ -55,6 +55,9 @@ class AuthRequestHandler {
55
55
  } else if (!value.currentNetworkMap) {
56
56
  value.currentNetworkMap = {};
57
57
  }
58
+ if (existKeyBothConnectAuthType) {
59
+ value.canConnectSubstrateEcdsa = true;
60
+ }
58
61
  acc[key] = {
59
62
  ...value
60
63
  };
@@ -91,6 +94,18 @@ class AuthRequestHandler {
91
94
  [v]: value
92
95
  }), {});
93
96
  }
97
+ getEcdsaAddressList() {
98
+ const addressList = Object.keys(this.keyringService.context.pairs);
99
+ const pairs = this.keyringService.context.pairs;
100
+ const ecdsaAddressList = new Set();
101
+ addressList.forEach(address => {
102
+ const pair = pairs[address];
103
+ if (pair && pair.json.meta.isSubstrateECDSA) {
104
+ ecdsaAddressList.add(address);
105
+ }
106
+ });
107
+ return ecdsaAddressList;
108
+ }
94
109
  get numAuthRequestsV2() {
95
110
  return Object.keys(this.#authRequestsV2).length;
96
111
  }
@@ -201,6 +216,7 @@ class AuthRequestHandler {
201
216
  }
202
217
  authCompleteV2 = (id, url, resolve, reject) => {
203
218
  const isAllowedMap = this.getAddressList();
219
+ const ecdsaAddressList = this.getEcdsaAddressList();
204
220
  const complete = (result, cb, accounts) => {
205
221
  const isAllowed = result === true;
206
222
  let isCancelled = false;
@@ -221,6 +237,7 @@ class AuthRequestHandler {
221
237
  idStr,
222
238
  request: {
223
239
  allowedAccounts,
240
+ canConnectSubstrateEcdsa,
224
241
  origin
225
242
  },
226
243
  url
@@ -228,10 +245,9 @@ class AuthRequestHandler {
228
245
 
229
246
  // Note: accountAuthTypes represents the accountAuthType of this request
230
247
  // allowedAccounts is a list of connected accounts that exist for this origin during this request.
231
-
232
248
  if (accountAuthTypes.length !== _constants.ALL_ACCOUNT_AUTH_TYPES.length) {
233
249
  const backupAllowed = (allowedAccounts || []).filter(a => {
234
- if ((0, _utilCrypto.isEthereumAddress)(a) && !accountAuthTypes.includes('evm')) {
250
+ if ((0, _utilCrypto.isEthereumAddress)(a) && (canConnectSubstrateEcdsa || !ecdsaAddressList.has(a)) && !accountAuthTypes.includes('evm')) {
235
251
  return true;
236
252
  }
237
253
  if ((0, _keyring.isSubstrateAddress)(a) && !accountAuthTypes.includes('substrate')) {
@@ -294,7 +310,8 @@ class AuthRequestHandler {
294
310
  currentNetworkMap: existed ? {
295
311
  ...defaultNetworkMap,
296
312
  ...existed.currentNetworkMap
297
- } : defaultNetworkMap
313
+ } : defaultNetworkMap,
314
+ canConnectSubstrateEcdsa: canConnectSubstrateEcdsa || (existed === null || existed === void 0 ? void 0 : existed.canConnectSubstrateEcdsa)
298
315
  };
299
316
  this.setAuthorize(authorizeList, () => {
300
317
  cb();
@@ -326,6 +343,7 @@ class AuthRequestHandler {
326
343
  const idStr = (0, _utils2.stripUrl)(url);
327
344
  const isAllowedDappConnectBothType = !!_constants2.DAPP_CONNECT_BOTH_TYPE_ACCOUNT_URL.find(url_ => url.includes(url_));
328
345
  let accountAuthTypes = [...new Set(isAllowedDappConnectBothType ? ['evm', 'substrate'] : request.accountAuthTypes || ['substrate'])];
346
+ let canConnectSubstrateEcdsa = !!request.canConnectSubstrateEcdsa || isAllowedDappConnectBothType;
329
347
  if (!authList) {
330
348
  authList = {};
331
349
  }
@@ -360,6 +378,9 @@ class AuthRequestHandler {
360
378
  if (accountAuthTypes && _request.accountAuthTypes) {
361
379
  const filteredAccountAuthTypes = new Set([..._request.accountAuthTypes, ...accountAuthTypes]);
362
380
  accountAuthTypes = [...filteredAccountAuthTypes];
381
+ if (_request.request.canConnectSubstrateEcdsa) {
382
+ canConnectSubstrateEcdsa = true;
383
+ }
363
384
  }
364
385
  mergeKeys.push(key);
365
386
  }
@@ -391,9 +412,10 @@ class AuthRequestHandler {
391
412
  return allowed ? address : '';
392
413
  }).filter(item => item !== '');
393
414
  let allowedListByRequestType = [...request.allowedAccounts];
415
+ const ecdsaAddressList = this.getEcdsaAddressList();
394
416
  allowedListByRequestType = accountAuthTypes.reduce((list, accountAuthType) => {
395
417
  if (accountAuthType === 'evm') {
396
- list.push(...allowedListByRequestType.filter(a => (0, _utilCrypto.isEthereumAddress)(a)));
418
+ list.push(...allowedListByRequestType.filter(a => (0, _utilCrypto.isEthereumAddress)(a) && (canConnectSubstrateEcdsa || !ecdsaAddressList.has(a))));
397
419
  } else if (accountAuthType === 'substrate') {
398
420
  list.push(...allowedListByRequestType.filter(a => (0, _keyring.isSubstrateAddress)(a)));
399
421
  } else if (accountAuthType === 'ton') {
@@ -424,7 +446,8 @@ class AuthRequestHandler {
424
446
  origin,
425
447
  url,
426
448
  accountAuthTypes: _constants.ALL_ACCOUNT_AUTH_TYPES,
427
- currentNetworkMap: {}
449
+ currentNetworkMap: {},
450
+ canConnectSubstrateEcdsa
428
451
  };
429
452
  this.setAuthorize(authList);
430
453
  return true;
@@ -436,7 +459,8 @@ class AuthRequestHandler {
436
459
  idStr,
437
460
  request: {
438
461
  ...request,
439
- accountAuthTypes
462
+ accountAuthTypes,
463
+ canConnectSubstrateEcdsa
440
464
  },
441
465
  url,
442
466
  accountAuthTypes: accountAuthTypes || ['substrate']
@@ -55,6 +55,7 @@ exports.AccountSignMode = AccountSignMode;
55
55
  AccountSignMode["QR"] = "qr";
56
56
  AccountSignMode["LEGACY_LEDGER"] = "legacy-ledger";
57
57
  AccountSignMode["GENERIC_LEDGER"] = "generic-ledger";
58
+ AccountSignMode["ECDSA_SUBSTRATE_LEDGER"] = "ecdsa-substrate-ledger";
58
59
  AccountSignMode["READ_ONLY"] = "readonly";
59
60
  AccountSignMode["ALL_ACCOUNT"] = "all";
60
61
  AccountSignMode["INJECTED"] = "injected";
@@ -64,7 +64,7 @@ const _analyzeAddress = async (data, accountProxies, contacts, chainInfo, substr
64
64
  for (const accountProxy of accountProxies) {
65
65
  const _name = accountProxy.name.trim().toLowerCase();
66
66
  const nameCondition = isNameValid(_data, _name);
67
- const filterAccounts = accountProxy.accounts.filter(account => (0, _utils._isChainInfoCompatibleWithAccountInfo)(chainInfo, account.chainType, account.type));
67
+ const filterAccounts = accountProxy.accounts.filter(account => (0, _utils._isChainInfoCompatibleWithAccountInfo)(chainInfo, account));
68
68
  for (const account of filterAccounts) {
69
69
  const addressCondition = isStrValidWithAddress(_data, account, chainInfo);
70
70
  const condition = nameCondition !== 'invalid' ? nameCondition : addressCondition;
@@ -92,7 +92,10 @@ const _analyzeAddress = async (data, accountProxies, contacts, chainInfo, substr
92
92
  }
93
93
  }
94
94
  }
95
- const filterContacts = contacts.filter(contact => (0, _utils._isChainInfoCompatibleWithAccountInfo)(chainInfo, contact.chainType, (0, _keyring.getKeypairTypeByAddress)(contact.address)));
95
+ const filterContacts = contacts.filter(contact => (0, _utils._isChainInfoCompatibleWithAccountInfo)(chainInfo, {
96
+ chainType: contact.chainType,
97
+ type: (0, _keyring.getKeypairTypeByAddress)(contact.address)
98
+ }));
96
99
 
97
100
  // Filter address book addresses
98
101
  for (const contact of filterContacts) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getAccountChainTypeForAddress = exports._reformatAddressWithChain = void 0;
6
+ exports.getAccountJsonByAddress = exports.getAccountChainTypeForAddress = exports.filterAddressByChainInfo = exports._reformatAddressWithChain = void 0;
7
7
  exports.getAddressesByChainType = getAddressesByChainType;
8
8
  exports.getAddressesByChainTypeMap = getAddressesByChainTypeMap;
9
9
  exports.isAccountAll = isAccountAll;
@@ -16,6 +16,7 @@ var _types = require("@subwallet/extension-base/types");
16
16
  var _utils2 = require("@subwallet/extension-base/utils");
17
17
  var _keyring = require("@subwallet/keyring");
18
18
  var _validate = require("@subwallet/keyring/utils/address/validate");
19
+ var _uiKeyring = require("@subwallet/ui-keyring");
19
20
  var _utilCrypto = require("@polkadot/util-crypto");
20
21
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
21
22
  // SPDX-License-Identifier: Apache-2.0
@@ -141,4 +142,94 @@ const modifyAccountName = (type, name, modify) => {
141
142
  }
142
143
  return network ? [name, network].join(' - ') : name;
143
144
  };
144
- exports.modifyAccountName = modifyAccountName;
145
+
146
+ /**
147
+ * @function getAccountJsonByAddress
148
+ * @desc Get account info by address
149
+ * <p>
150
+ * Note: Use on the background only
151
+ * </p>
152
+ * @param {string} address - Address
153
+ * @returns {AccountJson|null} - Account info or null if not found
154
+ */
155
+ exports.modifyAccountName = modifyAccountName;
156
+ const getAccountJsonByAddress = address => {
157
+ try {
158
+ const pair = _uiKeyring.keyring.getPair(address);
159
+ if (pair) {
160
+ return (0, _utils2.pairToAccount)(pair);
161
+ } else {
162
+ return null;
163
+ }
164
+ } catch (e) {
165
+ console.warn(e);
166
+ return null;
167
+ }
168
+ };
169
+
170
+ /** Filter addresses to subscribe by chain info */
171
+ exports.getAccountJsonByAddress = getAccountJsonByAddress;
172
+ const filterAddressByChainInfo = (addresses, chainInfo) => {
173
+ const {
174
+ _bitcoin,
175
+ bitcoin,
176
+ cardano,
177
+ evm,
178
+ substrate,
179
+ ton
180
+ } = getAddressesByChainTypeMap(addresses, chainInfo);
181
+ if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
182
+ const [fetchList, unFetchList] = processEvmAndSubstrateAddresses(evm, chainInfo);
183
+ return [fetchList, [...unFetchList, ...bitcoin, ...ton, ...substrate, ...cardano, ..._bitcoin].flat()];
184
+ } else if ((0, _utils._isChainBitcoinCompatible)(chainInfo)) {
185
+ return [bitcoin, [...evm, ...substrate, ...ton, ...cardano, ..._bitcoin].flat()];
186
+ } else if ((0, _utils._isChainTonCompatible)(chainInfo)) {
187
+ return [ton, [...bitcoin, ...evm, ...substrate, ...cardano, ..._bitcoin].flat()];
188
+ } else if ((0, _utils._isChainCardanoCompatible)(chainInfo)) {
189
+ return [cardano, [...bitcoin, ...evm, ...substrate, ...ton, ..._bitcoin].flat()];
190
+ } else {
191
+ const [fetchList, unFetchList] = processEvmAndSubstrateAddresses(substrate, chainInfo);
192
+ return [fetchList, [...unFetchList, ...bitcoin, ...evm, ...ton, ...cardano, ..._bitcoin].flat()];
193
+ }
194
+ };
195
+ exports.filterAddressByChainInfo = filterAddressByChainInfo;
196
+ const processEvmAndSubstrateAddresses = (addressList, chainInfo) => {
197
+ const fetchList = [];
198
+ const unFetchList = [];
199
+ const isEvm = (0, _utilCrypto.isEthereumAddress)(addressList[0]);
200
+ addressList.forEach(address => {
201
+ const account = getAccountJsonByAddress(address);
202
+ if (account) {
203
+ if (account.isHardware) {
204
+ if (isEvm) {
205
+ if (account.isGeneric && account.isSubstrateECDSA) {
206
+ if ((0, _utils._isSubstrateEvmCompatibleChain)(chainInfo)) {
207
+ fetchList.push(address);
208
+ } else {
209
+ unFetchList.push(address);
210
+ }
211
+ } else {
212
+ fetchList.push(address);
213
+ }
214
+ } else {
215
+ if (account.isGeneric) {
216
+ fetchList.push(address);
217
+ } else {
218
+ const availGen = account.availableGenesisHashes || [];
219
+ const gen = (0, _utils._getSubstrateGenesisHash)(chainInfo);
220
+ if (availGen.includes(gen)) {
221
+ fetchList.push(address);
222
+ } else {
223
+ unFetchList.push(address);
224
+ }
225
+ }
226
+ }
227
+ } else {
228
+ fetchList.push(address);
229
+ }
230
+ } else {
231
+ fetchList.push(address);
232
+ }
233
+ });
234
+ return [fetchList, unFetchList];
235
+ };
@@ -71,6 +71,9 @@ const getAccountSignMode = (address, _meta) => {
71
71
  if (meta.isExternal) {
72
72
  if (meta.isHardware) {
73
73
  if (meta.isGeneric) {
74
+ if (meta.isSubstrateECDSA) {
75
+ return _types2.AccountSignMode.ECDSA_SUBSTRATE_LEDGER;
76
+ }
74
77
  return _types2.AccountSignMode.GENERIC_LEDGER;
75
78
  } else {
76
79
  return _types2.AccountSignMode.LEGACY_LEDGER;
@@ -244,6 +247,11 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
244
247
  result.push(...CLAIM_AVAIL_BRIDGE);
245
248
  }
246
249
  return result;
250
+ } else if (signMode === _types2.AccountSignMode.ECDSA_SUBSTRATE_LEDGER) {
251
+ // Only for account substrate with ECDSA scheme format
252
+ const result = [];
253
+ result.push(...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, _KoniTypes.ExtrinsicType.TRANSFER_XCM, _KoniTypes.ExtrinsicType.SWAP, _KoniTypes.ExtrinsicType.CROWDLOAN);
254
+ return result;
247
255
  }
248
256
  return [];
249
257
  };
@@ -380,6 +388,7 @@ const convertAccountProxyType = accountSignMode => {
380
388
  switch (accountSignMode) {
381
389
  case _types2.AccountSignMode.GENERIC_LEDGER:
382
390
  case _types2.AccountSignMode.LEGACY_LEDGER:
391
+ case _types2.AccountSignMode.ECDSA_SUBSTRATE_LEDGER:
383
392
  return _types2.AccountProxyType.LEDGER;
384
393
  case _types2.AccountSignMode.QR:
385
394
  return _types2.AccountProxyType.QR;
@@ -490,6 +499,7 @@ const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
490
499
  switch (account.signMode) {
491
500
  case _types2.AccountSignMode.GENERIC_LEDGER:
492
501
  case _types2.AccountSignMode.LEGACY_LEDGER:
502
+ case _types2.AccountSignMode.ECDSA_SUBSTRATE_LEDGER:
493
503
  specialChain = account.specialChain;
494
504
  break;
495
505
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.filterAssetsByChainAndType = exports.filterAlphaAssetsByChain = void 0;
6
+ exports.isSubstrateEcdsaLedgerAssetSupported = exports.filterAssetsByChainAndType = exports.filterAlphaAssetsByChain = void 0;
7
7
  var _types = require("@subwallet/chain-list/types");
8
8
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
9
9
  // Copyright 2019-2022 @subwallet/extension-base
@@ -31,4 +31,11 @@ const filterAlphaAssetsByChain = (chainAssetMap, chain) => {
31
31
  });
32
32
  return result;
33
33
  };
34
- exports.filterAlphaAssetsByChain = filterAlphaAssetsByChain;
34
+ exports.filterAlphaAssetsByChain = filterAlphaAssetsByChain;
35
+ const isSubstrateEcdsaLedgerAssetSupported = (chainsAsset, chainInfo) => {
36
+ if (!(0, _utils._isSubstrateEvmCompatibleChain)(chainInfo)) {
37
+ return false;
38
+ }
39
+ return (0, _utils._isNativeToken)(chainsAsset) || !(0, _utils._getContractAddressOfToken)(chainsAsset);
40
+ };
41
+ exports.isSubstrateEcdsaLedgerAssetSupported = isSubstrateEcdsaLedgerAssetSupported;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.paraSpellChainMap = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
6
+ exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.paraSpellChainMap = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.assetHubStakingMap = exports.StaticKey = void 0;
7
7
  var _chainList = require("@subwallet/chain-list");
8
8
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
9
9
  // SPDX-License-Identifier: Apache-2.0
@@ -42,7 +42,10 @@ const oldChainPrefix = require('./oldChainPrefix.json');
42
42
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
43
43
  exports.oldChainPrefix = oldChainPrefix;
44
44
  const paraSpellChainMap = require('./paraSpellChainMap.json');
45
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
45
46
  exports.paraSpellChainMap = paraSpellChainMap;
47
+ const assetHubStakingMap = require('./assetHubStaking.json');
48
+ exports.assetHubStakingMap = assetHubStakingMap;
46
49
  let StaticKey;
47
50
  exports.StaticKey = StaticKey;
48
51
  (function (StaticKey) {
@@ -58,6 +61,7 @@ exports.StaticKey = StaticKey;
58
61
  StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
59
62
  StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
60
63
  StaticKey["PARASPELL_CHAIN_MAP"] = "paraspell-chain-map";
64
+ StaticKey["ASSET_HUB_STAKING_MAP"] = "asset-hub-staking-map";
61
65
  })(StaticKey || (exports.StaticKey = StaticKey = {}));
62
66
  const staticData = {
63
67
  [StaticKey.CHAINS]: Object.values(_chainList.ChainInfoMap),
@@ -71,6 +75,7 @@ const staticData = {
71
75
  [StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
72
76
  [StaticKey.BLOCKED_ACTIONS]: blockedActions,
73
77
  [StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix,
74
- [StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap
78
+ [StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap,
79
+ [StaticKey.ASSET_HUB_STAKING_MAP]: assetHubStakingMap
75
80
  };
76
81
  exports.staticData = staticData;
@@ -7,6 +7,7 @@ import { CardanoProviderError } from '@subwallet/extension-base/background/error
7
7
  import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
8
8
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
9
9
  import { BitcoinProviderErrorType, CardanoProviderErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
10
+ import { _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
10
11
  import { BasicTxErrorType } from '@subwallet/extension-base/types';
11
12
  import { BN_ZERO, combineEthFee, createPromiseHandler, isSameAddress, reformatAddress, stripUrl, wait } from '@subwallet/extension-base/utils';
12
13
  import { validateAddressNetwork } from '@subwallet/extension-base/utils/cardano';
@@ -247,7 +248,8 @@ export async function validationEvmDataTransactionMiddleware(koni, url, payload)
247
248
  const transactionParams = payload.payloadAfterValidated;
248
249
  const {
249
250
  address: fromAddress,
250
- networkKey
251
+ networkKey,
252
+ pair: pair_
251
253
  } = payload;
252
254
  const evmApi = koni.getEvmApi(networkKey || '');
253
255
  const web3 = evmApi === null || evmApi === void 0 ? void 0 : evmApi.api;
@@ -285,8 +287,25 @@ export async function validationEvmDataTransactionMiddleware(koni, url, payload)
285
287
  if (!fromAddress || !isEthereumAddress(fromAddress)) {
286
288
  handleError('the sender address must be the ethereum address type');
287
289
  }
288
- if (transaction.to && !isEthereumAddress(transaction.to)) {
289
- handleError('invalid recipient address');
290
+ const pair = pair_ || keyring.getPair(fromAddress);
291
+ if (!pair) {
292
+ handleError('Not found address to sign');
293
+ }
294
+ if (pair_ !== null && pair_ !== void 0 && pair_.meta.isSubstrateECDSA) {
295
+ handleError('Substrate account can not send this transaction');
296
+ }
297
+ const evmNetwork = koni.getChainInfo(networkKey || '');
298
+ if (transaction.to) {
299
+ if (!isEthereumAddress(transaction.to)) {
300
+ handleError('invalid recipient address');
301
+ } else {
302
+ try {
303
+ const pairTo = keyring.getPair(transaction.to);
304
+ if (pairTo && pairTo.meta.isSubstrateECDSA && !_isSubstrateEvmCompatibleChain(evmNetwork)) {
305
+ handleError('substrate account cannot receive this token');
306
+ }
307
+ } catch (e) {}
308
+ }
290
309
  }
291
310
  if (fromAddress === transaction.to) {
292
311
  handleError('receiving address must be different from sending address');
@@ -382,7 +401,6 @@ export async function validationEvmDataTransactionMiddleware(koni, url, payload)
382
401
  handleError(e.message);
383
402
  }
384
403
  const hasError = errors && errors.length > 0 || !networkKey;
385
- const evmNetwork = koni.getChainInfo(networkKey || '');
386
404
  let isToContract = false;
387
405
  let hashPayload = '';
388
406
  let parseData = '';
@@ -433,6 +451,12 @@ export async function validationEvmSignMessageMiddleware(koni, url, payload_) {
433
451
  handleError('Not found address or payload to sign');
434
452
  }
435
453
  const pair = pair_ || keyring.getPair(address);
454
+ if (!pair) {
455
+ handleError('Not found address to sign');
456
+ }
457
+ if (pair_ !== null && pair_ !== void 0 && pair_.meta.isSubstrateECDSA) {
458
+ handleError('Substrate account can not sign this message');
459
+ }
436
460
  if (method) {
437
461
  if (['eth_sign', 'personal_sign', 'eth_signTypedData', 'eth_signTypedData_v1', 'eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) < 0) {
438
462
  handleError('Unsupported action');
@@ -984,6 +1008,9 @@ export function convertErrorMessage(message_, name) {
984
1008
  if (message.includes('insufficient balance') || message.includes('insufficient funds')) {
985
1009
  return [t('Insufficient balance on the sender address. Top up your balance and try again'), t('Unable to sign transaction')];
986
1010
  }
1011
+ if (message.includes('substrate') && message.includes('receive this token')) {
1012
+ return [t('The recipient account is a Ledger Polkadot (EVM) account, which is not supported for this transaction. Change recipient account and try again'), t('Invalid account type')];
1013
+ }
987
1014
 
988
1015
  // Sign Message
989
1016
  if (message.includes('not found address or payload to sign')) {
package/core/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { _ChainInfo } from '@subwallet/chain-list/types';
1
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { AccountJson } from '@subwallet/extension-base/types';
3
- export declare type LedgerMustCheckType = 'polkadot' | 'migration' | 'unnecessary';
3
+ export declare type LedgerMustCheckType = 'polkadot' | 'migration' | 'polkadot_ecdsa' | 'unnecessary';
4
4
  export declare enum ValidationCondition {
5
5
  IS_NOT_NULL = "IS_NOT_NULL",
6
6
  IS_ADDRESS = "IS_ADDRESS",
@@ -20,6 +20,7 @@ export declare enum ActionType {
20
20
  export interface ValidateRecipientParams {
21
21
  srcChain: string;
22
22
  destChainInfo: _ChainInfo;
23
+ assetInfo?: _ChainAsset;
23
24
  fromAddress: string;
24
25
  toAddress: string;
25
26
  account: AccountJson | null;