@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
@@ -1,6 +1,6 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
3
- import { AccountChainType } from '@subwallet/extension-base/types';
3
+ import { AccountChainType, AccountJson } from '@subwallet/extension-base/types';
4
4
  import { KeypairType } from '@subwallet/keyring/types';
5
5
  export declare function isAccountAll(address?: string): boolean;
6
6
  export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean, ignoreError?: boolean): string;
@@ -17,4 +17,16 @@ export declare function getAddressesByChainTypeMap(addresses: string[], chainInf
17
17
  export declare function quickFormatAddressToCompare(address?: string): string | undefined;
18
18
  /** @deprecated */
19
19
  export declare const modifyAccountName: (type: KeypairType, name: string, modify: boolean) => string;
20
+ /**
21
+ * @function getAccountJsonByAddress
22
+ * @desc Get account info by address
23
+ * <p>
24
+ * Note: Use on the background only
25
+ * </p>
26
+ * @param {string} address - Address
27
+ * @returns {AccountJson|null} - Account info or null if not found
28
+ */
29
+ export declare const getAccountJsonByAddress: (address: string) => AccountJson | null;
30
+ /** Filter addresses to subscribe by chain info */
31
+ export declare const filterAddressByChainInfo: (addresses: string[], chainInfo: _ChainInfo) => [string[], string[]];
20
32
  export {};
@@ -2,11 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
- import { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { _chainInfoToChainType, _getChainSubstrateAddressPrefix, _getSubstrateGenesisHash, _isChainBitcoinCompatible, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { AccountChainType } from '@subwallet/extension-base/types';
7
- import { getAccountChainTypeFromKeypairType } from '@subwallet/extension-base/utils';
7
+ import { getAccountChainTypeFromKeypairType, pairToAccount } from '@subwallet/extension-base/utils';
8
8
  import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isCardanoAddress, isTonAddress } from '@subwallet/keyring';
9
9
  import { getBitcoinAddressInfo } from '@subwallet/keyring/utils/address/validate';
10
+ import { keyring } from '@subwallet/ui-keyring';
10
11
  import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
11
12
  export function isAccountAll(address) {
12
13
  return address === ALL_ACCOUNT_KEY;
@@ -123,4 +124,92 @@ export const modifyAccountName = (type, name, modify) => {
123
124
  break;
124
125
  }
125
126
  return network ? [name, network].join(' - ') : name;
127
+ };
128
+
129
+ /**
130
+ * @function getAccountJsonByAddress
131
+ * @desc Get account info by address
132
+ * <p>
133
+ * Note: Use on the background only
134
+ * </p>
135
+ * @param {string} address - Address
136
+ * @returns {AccountJson|null} - Account info or null if not found
137
+ */
138
+ export const getAccountJsonByAddress = address => {
139
+ try {
140
+ const pair = keyring.getPair(address);
141
+ if (pair) {
142
+ return pairToAccount(pair);
143
+ } else {
144
+ return null;
145
+ }
146
+ } catch (e) {
147
+ console.warn(e);
148
+ return null;
149
+ }
150
+ };
151
+
152
+ /** Filter addresses to subscribe by chain info */
153
+ export const filterAddressByChainInfo = (addresses, chainInfo) => {
154
+ const {
155
+ _bitcoin,
156
+ bitcoin,
157
+ cardano,
158
+ evm,
159
+ substrate,
160
+ ton
161
+ } = getAddressesByChainTypeMap(addresses, chainInfo);
162
+ if (_isChainEvmCompatible(chainInfo)) {
163
+ const [fetchList, unFetchList] = processEvmAndSubstrateAddresses(evm, chainInfo);
164
+ return [fetchList, [...unFetchList, ...bitcoin, ...ton, ...substrate, ...cardano, ..._bitcoin].flat()];
165
+ } else if (_isChainBitcoinCompatible(chainInfo)) {
166
+ return [bitcoin, [...evm, ...substrate, ...ton, ...cardano, ..._bitcoin].flat()];
167
+ } else if (_isChainTonCompatible(chainInfo)) {
168
+ return [ton, [...bitcoin, ...evm, ...substrate, ...cardano, ..._bitcoin].flat()];
169
+ } else if (_isChainCardanoCompatible(chainInfo)) {
170
+ return [cardano, [...bitcoin, ...evm, ...substrate, ...ton, ..._bitcoin].flat()];
171
+ } else {
172
+ const [fetchList, unFetchList] = processEvmAndSubstrateAddresses(substrate, chainInfo);
173
+ return [fetchList, [...unFetchList, ...bitcoin, ...evm, ...ton, ...cardano, ..._bitcoin].flat()];
174
+ }
175
+ };
176
+ const processEvmAndSubstrateAddresses = (addressList, chainInfo) => {
177
+ const fetchList = [];
178
+ const unFetchList = [];
179
+ const isEvm = isEthereumAddress(addressList[0]);
180
+ addressList.forEach(address => {
181
+ const account = getAccountJsonByAddress(address);
182
+ if (account) {
183
+ if (account.isHardware) {
184
+ if (isEvm) {
185
+ if (account.isGeneric && account.isSubstrateECDSA) {
186
+ if (_isSubstrateEvmCompatibleChain(chainInfo)) {
187
+ fetchList.push(address);
188
+ } else {
189
+ unFetchList.push(address);
190
+ }
191
+ } else {
192
+ fetchList.push(address);
193
+ }
194
+ } else {
195
+ if (account.isGeneric) {
196
+ fetchList.push(address);
197
+ } else {
198
+ const availGen = account.availableGenesisHashes || [];
199
+ const gen = _getSubstrateGenesisHash(chainInfo);
200
+ if (availGen.includes(gen)) {
201
+ fetchList.push(address);
202
+ } else {
203
+ unFetchList.push(address);
204
+ }
205
+ }
206
+ }
207
+ } else {
208
+ fetchList.push(address);
209
+ }
210
+ } else {
211
+ fetchList.push(address);
212
+ }
213
+ });
214
+ return [fetchList, unFetchList];
126
215
  };
@@ -62,6 +62,9 @@ export const getAccountSignMode = (address, _meta) => {
62
62
  if (meta.isExternal) {
63
63
  if (meta.isHardware) {
64
64
  if (meta.isGeneric) {
65
+ if (meta.isSubstrateECDSA) {
66
+ return AccountSignMode.ECDSA_SUBSTRATE_LEDGER;
67
+ }
65
68
  return AccountSignMode.GENERIC_LEDGER;
66
69
  } else {
67
70
  return AccountSignMode.LEGACY_LEDGER;
@@ -233,6 +236,11 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
233
236
  result.push(...CLAIM_AVAIL_BRIDGE);
234
237
  }
235
238
  return result;
239
+ } else if (signMode === AccountSignMode.ECDSA_SUBSTRATE_LEDGER) {
240
+ // Only for account substrate with ECDSA scheme format
241
+ const result = [];
242
+ result.push(...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ExtrinsicType.TRANSFER_XCM, ExtrinsicType.SWAP, ExtrinsicType.CROWDLOAN);
243
+ return result;
236
244
  }
237
245
  return [];
238
246
  };
@@ -352,6 +360,7 @@ export const convertAccountProxyType = accountSignMode => {
352
360
  switch (accountSignMode) {
353
361
  case AccountSignMode.GENERIC_LEDGER:
354
362
  case AccountSignMode.LEGACY_LEDGER:
363
+ case AccountSignMode.ECDSA_SUBSTRATE_LEDGER:
355
364
  return AccountProxyType.LEDGER;
356
365
  case AccountSignMode.QR:
357
366
  return AccountProxyType.QR;
@@ -460,6 +469,7 @@ export const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
460
469
  switch (account.signMode) {
461
470
  case AccountSignMode.GENERIC_LEDGER:
462
471
  case AccountSignMode.LEGACY_LEDGER:
472
+ case AccountSignMode.ECDSA_SUBSTRATE_LEDGER:
463
473
  specialChain = account.specialChain;
464
474
  break;
465
475
  }
package/utils/asset.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { _AssetType, _ChainAsset } from '@subwallet/chain-list/types';
1
+ import { _AssetType, _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
2
  export declare const filterAssetsByChainAndType: (chainAssetMap: Record<string, _ChainAsset>, chain: string, assetTypes: _AssetType[]) => Record<string, _ChainAsset>;
3
3
  export declare const filterAlphaAssetsByChain: (chainAssetMap: Record<string, _ChainAsset>, chain: string) => Record<string, _ChainAsset>;
4
+ export declare const isSubstrateEcdsaLedgerAssetSupported: (chainsAsset: _ChainAsset, chainInfo: _ChainInfo) => boolean;
package/utils/asset.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { _AssetType } from '@subwallet/chain-list/types';
5
- import { _getAssetNetuid } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { _getAssetNetuid, _getContractAddressOfToken, _isNativeToken, _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  export const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) => {
7
7
  const result = {};
8
8
  Object.values(chainAssetMap).forEach(assetInfo => {
@@ -23,4 +23,10 @@ export const filterAlphaAssetsByChain = (chainAssetMap, chain) => {
23
23
  }
24
24
  });
25
25
  return result;
26
+ };
27
+ export const isSubstrateEcdsaLedgerAssetSupported = (chainsAsset, chainInfo) => {
28
+ if (!_isSubstrateEvmCompatibleChain(chainInfo)) {
29
+ return false;
30
+ }
31
+ return _isNativeToken(chainsAsset) || !_getContractAddressOfToken(chainsAsset);
26
32
  };
@@ -0,0 +1 @@
1
+ {}
@@ -11,6 +11,7 @@ export declare const remindNotificationTime: Record<NotificationActionType, numb
11
11
  export declare const blockedActions: Record<string, EnvConfig>;
12
12
  export declare const oldChainPrefix: Record<string, EnvConfig>;
13
13
  export declare const paraSpellChainMap: Record<string, EnvConfig>;
14
+ export declare const assetHubStakingMap: Record<string, EnvConfig>;
14
15
  export declare enum StaticKey {
15
16
  BUY_SERVICE_INFOS = "buy-service-infos",
16
17
  CHAINS = "chains",
@@ -23,7 +24,8 @@ export declare enum StaticKey {
23
24
  REMIND_NOTIFICATION_TIME = "remind-notification-time",
24
25
  BLOCKED_ACTIONS = "blocked-actions",
25
26
  OLD_CHAIN_PREFIX = "old-chain-prefix",
26
- PARASPELL_CHAIN_MAP = "paraspell-chain-map"
27
+ PARASPELL_CHAIN_MAP = "paraspell-chain-map",
28
+ ASSET_HUB_STAKING_MAP = "asset-hub-staking-map"
27
29
  }
28
30
  export declare const staticData: {
29
31
  chains: import("@subwallet/chain-list/types")._ChainInfo[];
@@ -38,4 +40,5 @@ export declare const staticData: {
38
40
  "blocked-actions": Record<string, EnvConfig>;
39
41
  "old-chain-prefix": Record<string, EnvConfig>;
40
42
  "paraspell-chain-map": Record<string, EnvConfig>;
43
+ "asset-hub-staking-map": Record<string, EnvConfig>;
41
44
  };
@@ -25,6 +25,8 @@ export const blockedActions = require("./blockedActions.json");
25
25
  export const oldChainPrefix = require("./oldChainPrefix.json");
26
26
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
27
27
  export const paraSpellChainMap = require("./paraSpellChainMap.json");
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
29
+ export const assetHubStakingMap = require("./assetHubStaking.json");
28
30
  export let StaticKey;
29
31
  (function (StaticKey) {
30
32
  StaticKey["BUY_SERVICE_INFOS"] = "buy-service-infos";
@@ -39,6 +41,7 @@ export let StaticKey;
39
41
  StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
40
42
  StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
41
43
  StaticKey["PARASPELL_CHAIN_MAP"] = "paraspell-chain-map";
44
+ StaticKey["ASSET_HUB_STAKING_MAP"] = "asset-hub-staking-map";
42
45
  })(StaticKey || (StaticKey = {}));
43
46
  export const staticData = {
44
47
  [StaticKey.CHAINS]: Object.values(ChainInfoMap),
@@ -52,5 +55,6 @@ export const staticData = {
52
55
  [StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
53
56
  [StaticKey.BLOCKED_ACTIONS]: blockedActions,
54
57
  [StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix,
55
- [StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap
58
+ [StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap,
59
+ [StaticKey.ASSET_HUB_STAKING_MAP]: assetHubStakingMap
56
60
  };