@subwallet/extension-base 1.3.21-0 → 1.3.23-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 (223) hide show
  1. package/background/KoniTypes.d.ts +75 -2
  2. package/background/KoniTypes.js +2 -0
  3. package/cjs/background/KoniTypes.js +2 -0
  4. package/cjs/constants/environment.js +4 -2
  5. package/cjs/constants/signing.js +6 -2
  6. package/cjs/core/logic-validation/recipientAddress.js +9 -1
  7. package/cjs/core/logic-validation/transfer.js +35 -29
  8. package/cjs/core/types.js +1 -0
  9. package/cjs/core/utils.js +12 -1
  10. package/cjs/defaults.js +1 -1
  11. package/cjs/koni/api/dotsama/crowdloan.js +1 -1
  12. package/cjs/koni/api/nft/index.js +9 -16
  13. package/cjs/koni/api/staking/index.js +3 -4
  14. package/cjs/koni/background/handlers/Extension.js +234 -96
  15. package/cjs/koni/background/handlers/State.js +15 -0
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
  18. package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
  19. package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
  20. package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
  21. package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
  22. package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
  23. package/cjs/services/balance-service/index.js +4 -2
  24. package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
  25. package/cjs/services/balance-service/transfer/token.js +4 -4
  26. package/cjs/services/chain-service/constants.js +8 -3
  27. package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
  28. package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
  29. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -2
  30. package/cjs/services/chain-service/handler/TonApi.js +2 -5
  31. package/cjs/services/chain-service/index.js +38 -7
  32. package/cjs/services/chain-service/utils/index.js +40 -11
  33. package/cjs/services/chain-service/utils/patch.js +1 -1
  34. package/cjs/services/earning-service/constants/chains.js +2 -1
  35. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
  36. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
  37. package/cjs/services/earning-service/handlers/native-staking/mythos.js +337 -0
  38. package/cjs/services/earning-service/service.js +10 -12
  39. package/cjs/services/earning-service/utils/index.js +2 -0
  40. package/cjs/services/fee-service/service.js +19 -8
  41. package/cjs/services/history-service/index.js +4 -6
  42. package/cjs/services/inapp-notification-service/index.js +12 -4
  43. package/cjs/services/keyring-service/context/account-context.js +17 -2
  44. package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
  45. package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
  46. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
  47. package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
  48. package/cjs/services/keyring-service/utils.js +18 -0
  49. package/cjs/services/migration-service/scripts/databases/ClearMetadataDatabase.js +3 -23
  50. package/cjs/services/migration-service/scripts/databases/ClearMetadataForChains.js +40 -0
  51. package/cjs/services/migration-service/scripts/databases/ClearMetadataForMythos.js +15 -0
  52. package/cjs/services/migration-service/scripts/index.js +6 -2
  53. package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
  54. package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
  55. package/cjs/services/request-service/index.js +20 -2
  56. package/cjs/services/setting-service/constants.js +10 -1
  57. package/cjs/services/storage-service/DatabaseService.js +6 -0
  58. package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
  59. package/cjs/services/storage-service/db-stores/Metadata.js +3 -0
  60. package/cjs/services/storage-service/db-stores/Migration.js +6 -1
  61. package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
  62. package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
  63. package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
  64. package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
  65. package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
  66. package/cjs/services/swap-service/index.js +31 -22
  67. package/cjs/services/swap-service/utils.js +21 -38
  68. package/cjs/services/transaction-service/helpers/index.js +6 -1
  69. package/cjs/services/transaction-service/index.js +278 -21
  70. package/cjs/services/transaction-service/utils.js +5 -1
  71. package/cjs/types/account/info/keyring.js +12 -1
  72. package/cjs/types/fee/cardano.js +1 -0
  73. package/cjs/types/swap/index.js +7 -2
  74. package/cjs/utils/account/analyze.js +2 -1
  75. package/cjs/utils/account/common.js +29 -20
  76. package/cjs/utils/account/derive/info/solo.js +9 -4
  77. package/cjs/utils/account/derive/validate.js +36 -2
  78. package/cjs/utils/account/transform.js +38 -13
  79. package/cjs/utils/fee/transfer.js +40 -7
  80. package/cjs/utils/index.js +2 -2
  81. package/cjs/utils/staticData/index.js +7 -2
  82. package/constants/environment.d.ts +1 -0
  83. package/constants/environment.js +2 -1
  84. package/constants/signing.js +6 -2
  85. package/core/logic-validation/recipientAddress.js +11 -3
  86. package/core/logic-validation/transfer.js +9 -3
  87. package/core/substrate/xcm-parser.d.ts +1 -1
  88. package/core/types.d.ts +1 -0
  89. package/core/types.js +1 -0
  90. package/core/utils.d.ts +1 -0
  91. package/core/utils.js +13 -3
  92. package/defaults.d.ts +1 -1
  93. package/defaults.js +1 -1
  94. package/koni/api/dotsama/crowdloan.js +3 -3
  95. package/koni/api/nft/index.js +10 -16
  96. package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
  97. package/koni/api/staking/index.js +4 -5
  98. package/koni/background/handlers/Extension.d.ts +9 -0
  99. package/koni/background/handlers/Extension.js +144 -8
  100. package/koni/background/handlers/State.d.ts +5 -1
  101. package/koni/background/handlers/State.js +16 -1
  102. package/package.json +102 -25
  103. package/packageInfo.js +1 -1
  104. package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
  105. package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
  106. package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
  107. package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
  108. package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
  109. package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
  110. package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
  111. package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
  112. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  113. package/services/balance-service/helpers/subscribe/index.js +23 -9
  114. package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
  115. package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
  116. package/services/balance-service/index.js +4 -2
  117. package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
  118. package/services/balance-service/transfer/cardano-transfer.js +114 -0
  119. package/services/balance-service/transfer/token.d.ts +1 -1
  120. package/services/balance-service/transfer/token.js +2 -2
  121. package/services/chain-service/constants.js +8 -3
  122. package/services/chain-service/handler/CardanoApi.d.ts +38 -0
  123. package/services/chain-service/handler/CardanoApi.js +167 -0
  124. package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
  125. package/services/chain-service/handler/CardanoChainHandler.js +75 -0
  126. package/services/chain-service/handler/SubstrateChainHandler.js +3 -2
  127. package/services/chain-service/handler/TonApi.js +3 -6
  128. package/services/chain-service/handler/types.d.ts +1 -0
  129. package/services/chain-service/index.d.ts +4 -1
  130. package/services/chain-service/index.js +38 -7
  131. package/services/chain-service/types.d.ts +9 -1
  132. package/services/chain-service/utils/index.d.ts +4 -0
  133. package/services/chain-service/utils/index.js +32 -11
  134. package/services/chain-service/utils/patch.js +1 -1
  135. package/services/earning-service/constants/chains.d.ts +1 -0
  136. package/services/earning-service/constants/chains.js +2 -1
  137. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
  138. package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
  139. package/services/earning-service/handlers/native-staking/mythos.d.ts +35 -0
  140. package/services/earning-service/handlers/native-staking/mythos.js +329 -0
  141. package/services/earning-service/service.js +12 -14
  142. package/services/earning-service/utils/index.js +2 -0
  143. package/services/fee-service/service.js +19 -8
  144. package/services/history-service/index.js +6 -8
  145. package/services/inapp-notification-service/index.d.ts +3 -4
  146. package/services/inapp-notification-service/index.js +14 -6
  147. package/services/keyring-service/context/account-context.d.ts +6 -2
  148. package/services/keyring-service/context/account-context.js +17 -2
  149. package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
  150. package/services/keyring-service/context/handlers/Derive.js +10 -8
  151. package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
  152. package/services/keyring-service/context/handlers/Migration.js +258 -0
  153. package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
  154. package/services/keyring-service/context/handlers/Secret.js +2 -2
  155. package/services/keyring-service/utils.d.ts +2 -0
  156. package/services/keyring-service/utils.js +11 -0
  157. package/services/migration-service/scripts/databases/ClearMetadataDatabase.d.ts +3 -3
  158. package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +3 -23
  159. package/services/migration-service/scripts/databases/ClearMetadataForChains.d.ts +5 -0
  160. package/services/migration-service/scripts/databases/ClearMetadataForChains.js +32 -0
  161. package/services/migration-service/scripts/databases/ClearMetadataForMythos.d.ts +4 -0
  162. package/services/migration-service/scripts/databases/ClearMetadataForMythos.js +7 -0
  163. package/services/migration-service/scripts/index.d.ts +1 -0
  164. package/services/migration-service/scripts/index.js +4 -1
  165. package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
  166. package/services/request-service/handler/CardanoRequestHandler.js +163 -0
  167. package/services/request-service/handler/EvmRequestHandler.js +1 -1
  168. package/services/request-service/index.d.ts +6 -3
  169. package/services/request-service/index.js +19 -5
  170. package/services/setting-service/constants.d.ts +3 -0
  171. package/services/setting-service/constants.js +6 -0
  172. package/services/storage-service/DatabaseService.d.ts +2 -0
  173. package/services/storage-service/DatabaseService.js +6 -0
  174. package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
  175. package/services/storage-service/db-stores/InappNotification.js +6 -0
  176. package/services/storage-service/db-stores/Metadata.d.ts +1 -0
  177. package/services/storage-service/db-stores/Metadata.js +3 -0
  178. package/services/storage-service/db-stores/Migration.d.ts +1 -0
  179. package/services/storage-service/db-stores/Migration.js +6 -1
  180. package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
  181. package/services/swap-service/handler/asset-hub/handler.js +2 -61
  182. package/services/swap-service/handler/base-handler.d.ts +1 -4
  183. package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
  184. package/services/swap-service/handler/chainflip-handler.js +31 -280
  185. package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
  186. package/services/swap-service/handler/hydradx-handler.js +13 -180
  187. package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
  188. package/services/swap-service/handler/simpleswap-handler.js +5 -226
  189. package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
  190. package/services/swap-service/handler/uniswap-handler.js +323 -0
  191. package/services/swap-service/index.js +30 -22
  192. package/services/swap-service/utils.d.ts +1 -5
  193. package/services/swap-service/utils.js +7 -21
  194. package/services/transaction-service/helpers/index.d.ts +2 -0
  195. package/services/transaction-service/helpers/index.js +4 -0
  196. package/services/transaction-service/index.d.ts +8 -2
  197. package/services/transaction-service/index.js +263 -10
  198. package/services/transaction-service/types.d.ts +7 -0
  199. package/services/transaction-service/utils.js +7 -2
  200. package/types/account/info/keyring.d.ts +4 -1
  201. package/types/account/info/keyring.js +9 -0
  202. package/types/account/info/proxy.d.ts +2 -0
  203. package/types/balance/index.d.ts +4 -1
  204. package/types/fee/base.d.ts +1 -1
  205. package/types/fee/cardano.d.ts +18 -0
  206. package/types/fee/cardano.js +1 -0
  207. package/types/fee/subscription.d.ts +4 -3
  208. package/types/swap/index.d.ts +11 -3
  209. package/types/swap/index.js +7 -2
  210. package/utils/account/analyze.js +2 -1
  211. package/utils/account/common.d.ts +11 -6
  212. package/utils/account/common.js +28 -19
  213. package/utils/account/derive/info/solo.js +10 -5
  214. package/utils/account/derive/validate.d.ts +1 -0
  215. package/utils/account/derive/validate.js +34 -1
  216. package/utils/account/transform.d.ts +2 -1
  217. package/utils/account/transform.js +37 -13
  218. package/utils/fee/transfer.d.ts +2 -1
  219. package/utils/fee/transfer.js +44 -11
  220. package/utils/index.js +4 -4
  221. package/utils/staticData/index.d.ts +4 -1
  222. package/utils/staticData/index.js +5 -1
  223. package/utils/staticData/oldChainPrefix.json +1 -0
@@ -9,7 +9,7 @@ import { keyring } from '@subwallet/ui-keyring';
9
9
  import { t } from 'i18next';
10
10
  import { assert } from '@polkadot/util';
11
11
  import { AccountBaseHandler } from "./Base.js";
12
- const validDeriveKeypairTypes = [...SubstrateKeypairTypes, ...EthereumKeypairTypes, 'ton'];
12
+ const validDeriveKeypairTypes = [...SubstrateKeypairTypes, ...EthereumKeypairTypes, 'ton', 'cardano'];
13
13
 
14
14
  /**
15
15
  * @class AccountDeriveHandler
@@ -208,7 +208,7 @@ export class AccountDeriveHandler extends AccountBaseHandler {
208
208
  /**
209
209
  * Derive account proxy
210
210
  * */
211
- derivationAccountProxyCreate(request) {
211
+ derivationAccountProxyCreate(request, isMigration = false) {
212
212
  const {
213
213
  name,
214
214
  proxyId: deriveId,
@@ -219,7 +219,7 @@ export class AccountDeriveHandler extends AccountBaseHandler {
219
219
  const rootId = this.state.value.accounts[parentProxyId].parentId || parentProxyId;
220
220
  const rootProxyId = this.state.belongUnifiedAccount(rootId) || rootId;
221
221
  const nameExists = this.state.checkNameExists(name);
222
- if (nameExists) {
222
+ if (nameExists && !isMigration) {
223
223
  throw new SWCommonAccountError(CommonAccountErrorType.ACCOUNT_NAME_EXISTED);
224
224
  }
225
225
  const validateRs = this.validateDerivePath({
@@ -343,11 +343,13 @@ export class AccountDeriveHandler extends AccountBaseHandler {
343
343
  }
344
344
  const addresses = pairs.map(pair => pair.address);
345
345
  const exists = this.state.checkAddressExists(addresses);
346
- assert(!exists, t('Account already exists under the name "{{name}}"', {
347
- replace: {
348
- name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || ''
349
- }
350
- }));
346
+ if (!isMigration) {
347
+ assert(!exists, t('Account already exists under the name "{{name}}"', {
348
+ replace: {
349
+ name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || ''
350
+ }
351
+ }));
352
+ }
351
353
  childAccountProxy && this.state.upsertAccountProxyByKey(childAccountProxy);
352
354
  this.state.upsertModifyPairs(modifyPairs);
353
355
  for (const childPair of pairs) {
@@ -0,0 +1,17 @@
1
+ import { RequestMigrateSoloAccount, RequestMigrateUnifiedAndFetchEligibleSoloAccounts, RequestPingSession, ResponseMigrateSoloAccount, ResponseMigrateUnifiedAndFetchEligibleSoloAccounts, SoloAccountToBeMigrated } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { AccountBaseHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Base';
3
+ import { AccountProxy } from '@subwallet/extension-base/types';
4
+ export declare const SESSION_TIMEOUT = 10000;
5
+ export declare class AccountMigrationHandler extends AccountBaseHandler {
6
+ private sessionIdToPassword;
7
+ pingSession({ sessionId }: RequestPingSession): boolean;
8
+ migrateUnifiedAndFetchEligibleSoloAccounts(request: RequestMigrateUnifiedAndFetchEligibleSoloAccounts, setMigratingModeFn: () => void): Promise<ResponseMigrateUnifiedAndFetchEligibleSoloAccounts>;
9
+ migrateUnifiedToUnifiedAccount(password: string, accountProxies: AccountProxy[], setMigratingModeFn: () => void): Promise<string[]>;
10
+ getUACanBeMigrated(accountProxies: AccountProxy[]): AccountProxy[];
11
+ getSoloAccountsNeedToBeMigrated(accountProxies: AccountProxy[]): AccountProxy[];
12
+ groupSoloAccountByMnemonic(password: string, accountProxies: AccountProxy[]): Record<string, AccountProxy[]>;
13
+ accountProxiesToEligibleSoloAccountMap(accountProxyMap: Record<string, AccountProxy[]>): Record<string, SoloAccountToBeMigrated[]>;
14
+ sortUAByParent(accountProxies: AccountProxy[]): AccountProxy[];
15
+ migrateSoloToUnifiedAccount(request: RequestMigrateSoloAccount): ResponseMigrateSoloAccount;
16
+ migrateDerivedSoloAccountRelationship(soloAccounts: SoloAccountToBeMigrated[]): void;
17
+ }
@@ -0,0 +1,258 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AccountBaseHandler } from '@subwallet/extension-base/services/keyring-service/context/handlers/Base';
5
+ import { AccountChainType, SUPPORTED_ACCOUNT_CHAIN_TYPES } from '@subwallet/extension-base/types';
6
+ import { createAccountProxyId, getDefaultKeypairTypeFromAccountChainType, getSuri } from '@subwallet/extension-base/utils';
7
+ import { generateRandomString } from '@subwallet/extension-base/utils/getId';
8
+ import { keyring } from '@subwallet/ui-keyring';
9
+ import { keyExtractSuri } from '@polkadot/util-crypto';
10
+ export const SESSION_TIMEOUT = 10000;
11
+ export class AccountMigrationHandler extends AccountBaseHandler {
12
+ sessionIdToPassword = {};
13
+ pingSession({
14
+ sessionId
15
+ }) {
16
+ if (!this.sessionIdToPassword[sessionId]) {
17
+ // todo: if no persistent sessionId, should we jump to enter password again?
18
+ throw Error(`Session ID ${sessionId} not found.`);
19
+ }
20
+ clearTimeout(this.sessionIdToPassword[sessionId].timeoutId);
21
+ this.sessionIdToPassword[sessionId].timeoutId = setTimeout(() => {
22
+ delete this.sessionIdToPassword[sessionId];
23
+ }, SESSION_TIMEOUT);
24
+ return true;
25
+ }
26
+ async migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn) {
27
+ // Migrate unified -> unified
28
+ const password = request.password;
29
+ const allAccountProxies = Object.values(this.state.accounts);
30
+ const UACanBeMigrated = this.getUACanBeMigrated(allAccountProxies);
31
+ const UACanBeMigratedSortedByParent = this.sortUAByParent(UACanBeMigrated); // master account must be migrated before derived account
32
+ const migratedUnifiedAccountIds = await this.migrateUnifiedToUnifiedAccount(password, UACanBeMigratedSortedByParent, setMigratingModeFn);
33
+
34
+ // Get solo accounts can be migrated
35
+ const soloAccountsNeedToBeMigrated = this.getSoloAccountsNeedToBeMigrated(allAccountProxies);
36
+ const soloAccountsNeedToBeMigratedGroup = this.groupSoloAccountByMnemonic(password, soloAccountsNeedToBeMigrated);
37
+ const eligibleSoloAccountMap = this.accountProxiesToEligibleSoloAccountMap(soloAccountsNeedToBeMigratedGroup);
38
+
39
+ // Create persistent mapping sessionId <-> password
40
+ const uniqueId = Date.now().toString();
41
+ const timeoutId = setTimeout(() => delete this.sessionIdToPassword[uniqueId], SESSION_TIMEOUT * 2);
42
+ this.sessionIdToPassword[uniqueId] = {
43
+ password,
44
+ timeoutId
45
+ };
46
+ return {
47
+ migratedUnifiedAccountIds,
48
+ soloAccounts: eligibleSoloAccountMap,
49
+ sessionId: uniqueId
50
+ };
51
+ }
52
+ async migrateUnifiedToUnifiedAccount(password, accountProxies, setMigratingModeFn) {
53
+ keyring.unlockKeyring(password);
54
+ this.parentService.updateKeyringState();
55
+ setMigratingModeFn();
56
+ const unifiedAccountIds = [];
57
+ const modifiedPairs = structuredClone(this.state.modifyPairs);
58
+ const {
59
+ derivedUnifiedAccounts,
60
+ masterUnifiedAccounts
61
+ } = accountProxies.reduce((accountInfo, account) => {
62
+ const isDerivedAccount = !!account.parentId;
63
+ isDerivedAccount ? accountInfo.derivedUnifiedAccounts.push(account) : accountInfo.masterUnifiedAccounts.push(account);
64
+ return accountInfo;
65
+ }, {
66
+ derivedUnifiedAccounts: [],
67
+ masterUnifiedAccounts: []
68
+ });
69
+ try {
70
+ for (const unifiedAccount of masterUnifiedAccounts) {
71
+ const proxyId = unifiedAccount.id;
72
+ const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
73
+ password,
74
+ proxyId
75
+ }).result;
76
+ const newChainTypes = Object.values(AccountChainType).filter(type => !unifiedAccount.chainTypes.includes(type) && SUPPORTED_ACCOUNT_CHAIN_TYPES.includes(type));
77
+ const keypairTypes = newChainTypes.map(chainType => getDefaultKeypairTypeFromAccountChainType(chainType));
78
+ keypairTypes.forEach(type => {
79
+ const suri = getSuri(mnemonic, type);
80
+ const pair = keyring.createFromUri(suri, {}, type);
81
+ const address = pair.address;
82
+ modifiedPairs[address] = {
83
+ accountProxyId: proxyId,
84
+ migrated: true,
85
+ key: address
86
+ };
87
+ });
88
+ keypairTypes.forEach(type => {
89
+ const suri = getSuri(mnemonic, type);
90
+ const {
91
+ derivePath
92
+ } = keyExtractSuri(suri);
93
+ const metadata = {
94
+ name: unifiedAccount.name,
95
+ derivationPath: derivePath ? derivePath.substring(1) : undefined
96
+ };
97
+ const rs = keyring.addUri(suri, metadata, type);
98
+ const address = rs.pair.address;
99
+ this.state._addAddressToAuthList(address, true);
100
+ });
101
+ this.state.upsertModifyPairs(modifiedPairs);
102
+ unifiedAccountIds.push(proxyId);
103
+ }
104
+ await new Promise(resolve => setTimeout(resolve, 1800)); // Wait last master unified account migrated. // todo: can be optimized later by await a promise resolve if master account is migrating
105
+
106
+ for (const unifiedAccount of derivedUnifiedAccounts) {
107
+ this.parentService.context.derivationAccountProxyCreate({
108
+ name: unifiedAccount.name,
109
+ suri: unifiedAccount.suri || '',
110
+ proxyId: unifiedAccount.parentId || ''
111
+ }, true);
112
+ unifiedAccountIds.push(unifiedAccount.id);
113
+ }
114
+ } catch (error) {
115
+ console.error('Migration unified account failed with error:', error);
116
+ } finally {
117
+ keyring.lockAll(false);
118
+ this.parentService.updateKeyringState();
119
+ }
120
+ return unifiedAccountIds;
121
+ }
122
+ getUACanBeMigrated(accountProxies) {
123
+ return accountProxies.filter(account => this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
124
+ }
125
+ getSoloAccountsNeedToBeMigrated(accountProxies) {
126
+ return accountProxies.filter(account => !this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
127
+ }
128
+ groupSoloAccountByMnemonic(password, accountProxies) {
129
+ const parentService = this.parentService;
130
+ return accountProxies.reduce(function (rs, item) {
131
+ const oldProxyId = item.id;
132
+ const mnemonic = parentService.context.exportAccountProxyMnemonic({
133
+ password,
134
+ proxyId: oldProxyId
135
+ }).result;
136
+ const upcomingProxyId = createAccountProxyId(mnemonic);
137
+ if (!rs[upcomingProxyId]) {
138
+ rs[upcomingProxyId] = [];
139
+ }
140
+ rs[upcomingProxyId].push(item);
141
+ return rs;
142
+ }, {});
143
+ }
144
+ accountProxiesToEligibleSoloAccountMap(accountProxyMap) {
145
+ const eligibleSoloAccountMap = {};
146
+ Object.entries(accountProxyMap).forEach(([upcomingProxyId, accounts]) => {
147
+ eligibleSoloAccountMap[upcomingProxyId] = accounts.map(account => {
148
+ return {
149
+ upcomingProxyId,
150
+ proxyId: account.accounts[0].proxyId,
151
+ address: account.accounts[0].address,
152
+ name: account.name,
153
+ chainType: account.chainTypes[0]
154
+ };
155
+ });
156
+ });
157
+ return eligibleSoloAccountMap;
158
+ }
159
+ sortUAByParent(accountProxies) {
160
+ const undefinedToStr = str => str !== null && str !== void 0 ? str : '';
161
+ return accountProxies.sort((a, b) => undefinedToStr(a.parentId) < undefinedToStr(b.parentId) ? -1 : undefinedToStr(a.parentId) > undefinedToStr(b.parentId) ? 1 : 0);
162
+ }
163
+ migrateSoloToUnifiedAccount(request) {
164
+ const {
165
+ accountName,
166
+ sessionId,
167
+ soloAccounts
168
+ } = request;
169
+ const password = this.sessionIdToPassword[sessionId].password;
170
+ keyring.unlockKeyring(password);
171
+ this.parentService.updateKeyringState();
172
+ const modifiedPairs = structuredClone(this.state.modifyPairs);
173
+ const firstAccountInfo = soloAccounts[0];
174
+ const upcomingProxyId = firstAccountInfo.upcomingProxyId;
175
+ const firstAccountOldProxyId = firstAccountInfo.proxyId;
176
+ try {
177
+ const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
178
+ password,
179
+ proxyId: firstAccountOldProxyId
180
+ }).result;
181
+ const keypairTypes = SUPPORTED_ACCOUNT_CHAIN_TYPES.map(chainType => getDefaultKeypairTypeFromAccountChainType(chainType));
182
+ keypairTypes.forEach(type => {
183
+ const suri = getSuri(mnemonic, type);
184
+ const pair = keyring.createFromUri(suri, {}, type);
185
+ const address = pair.address;
186
+ modifiedPairs[address] = {
187
+ accountProxyId: upcomingProxyId,
188
+ migrated: true,
189
+ key: address
190
+ };
191
+ });
192
+ this.state.upsertAccountProxyByKey({
193
+ id: upcomingProxyId,
194
+ name: accountName,
195
+ isMigrationDone: false
196
+ });
197
+ const soloAccountProxyIds = [];
198
+ keypairTypes.forEach(type => {
199
+ const suri = getSuri(mnemonic, type);
200
+ const {
201
+ derivePath
202
+ } = keyExtractSuri(suri);
203
+ const metadata = {
204
+ name: accountName.concat(' - ').concat(generateRandomString()),
205
+ derivationPath: derivePath ? derivePath.substring(1) : undefined
206
+ };
207
+ const rs = keyring.addUri(suri, metadata, type);
208
+ soloAccountProxyIds.push(rs.json.address);
209
+ const address = rs.pair.address;
210
+ this.state._addAddressToAuthList(address, true);
211
+ });
212
+ this.state.upsertModifyPairs(modifiedPairs);
213
+ this.migrateDerivedSoloAccountRelationship(soloAccounts);
214
+ this.state.upsertAccountProxyByKey({
215
+ id: upcomingProxyId,
216
+ name: accountName,
217
+ isMigrationDone: true
218
+ });
219
+
220
+ // Re-update account name
221
+ soloAccountProxyIds.forEach(oldProxyId => {
222
+ const pair = keyring.getPair(oldProxyId);
223
+ keyring.saveAccountMeta(pair, {
224
+ ...pair.meta,
225
+ name: accountName
226
+ });
227
+ });
228
+
229
+ // Update current account after migrating
230
+ const currentAccountProxyId = this.state.currentAccount.proxyId;
231
+ if (soloAccountProxyIds.includes(currentAccountProxyId)) {
232
+ this.state.saveCurrentAccountProxyId(upcomingProxyId);
233
+ }
234
+ } catch (error) {
235
+ console.error('Migration solo account failed with error', error);
236
+ } finally {
237
+ keyring.lockAll(false);
238
+ this.parentService.updateKeyringState();
239
+ }
240
+ return {
241
+ migratedUnifiedAccountId: upcomingProxyId
242
+ };
243
+ }
244
+ migrateDerivedSoloAccountRelationship(soloAccounts) {
245
+ const accountProxies = this.state.accountProxies;
246
+
247
+ // Use Set.has & Map.get to optimize search performance
248
+ const proxyIdsSet = new Set(soloAccounts.map(account => account.proxyId));
249
+ const proxyIdToUpcomingProxyIdMap = new Map(soloAccounts.map(account => [account.proxyId, account.upcomingProxyId]));
250
+ for (const account of Object.values(accountProxies)) {
251
+ const currentParent = account.parentId;
252
+ if (currentParent && proxyIdsSet.has(currentParent)) {
253
+ accountProxies[account.id].parentId = proxyIdToUpcomingProxyIdMap.get(currentParent);
254
+ }
255
+ }
256
+ this.state.upsertAccountProxy(accountProxies);
257
+ }
258
+ }
@@ -27,7 +27,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
27
27
  mnemonic: _seed,
28
28
  type = 'general'
29
29
  }) {
30
- const types = type === 'general' ? ['sr25519', 'ethereum', 'ton'] : ['ton-native'];
30
+ const types = type === 'general' ? ['sr25519', 'ethereum', 'ton', 'cardano'] : ['ton-native'];
31
31
  const seed = _seed || type === 'general' ? mnemonicGenerate(length) : await tonMnemonicGenerate(length);
32
32
  const rs = {
33
33
  mnemonic: seed,
@@ -97,7 +97,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
97
97
  const addressDict = {};
98
98
  let changedAccount = false;
99
99
  const hasMasterPassword = keyring.keyring.hasMasterPassword;
100
- const types = type ? [type] : ['sr25519', 'ethereum', 'ton'];
100
+ const types = type ? [type] : ['sr25519', 'ethereum', 'ton', 'cardano'];
101
101
  if (!hasMasterPassword) {
102
102
  if (!password) {
103
103
  throw Error(t('The password of each account is needed to set up master password'));
@@ -5,7 +5,7 @@ import { AccountExternalErrorCode } from '@subwallet/extension-base/background/K
5
5
  import { AccountChainType, CommonAccountErrorType, SWCommonAccountError } from '@subwallet/extension-base/types';
6
6
  import { getKeypairTypeByAddress } from '@subwallet/keyring';
7
7
  import { decodePair } from '@subwallet/keyring/pair/decode';
8
- import { BitcoinKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
8
+ import { BitcoinKeypairTypes, CardanoKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
9
9
  import keyring from '@subwallet/ui-keyring';
10
10
  import { t } from 'i18next';
11
11
  import { assert, hexStripPrefix, hexToU8a, isHex, u8aToHex } from '@polkadot/util';
@@ -49,7 +49,7 @@ export class AccountSecretHandler extends AccountBaseHandler {
49
49
  isReadOnly,
50
50
  genesisHash: ''
51
51
  };
52
- if ([...BitcoinKeypairTypes, ...TonKeypairTypes].includes(type) && isReadOnly) {
52
+ if ([...BitcoinKeypairTypes, ...TonKeypairTypes, ...CardanoKeypairTypes].includes(type) && isReadOnly) {
53
53
  meta.noPublicKey = true;
54
54
  }
55
55
  const result = keyring.keyring.addFromAddress(address, meta, null, type);
@@ -0,0 +1,2 @@
1
+ import { AccountProxy } from '@subwallet/extension-base/types';
2
+ export declare const hasAnyAccountForMigration: (allAccountProxies: AccountProxy[]) => boolean;
@@ -0,0 +1,11 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export const hasAnyAccountForMigration = allAccountProxies => {
5
+ for (const account of allAccountProxies) {
6
+ if (account.isNeedMigrateUnifiedAccount) {
7
+ return true;
8
+ }
9
+ }
10
+ return false;
11
+ };
@@ -1,4 +1,4 @@
1
- import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
- export default class ClearMetadataDatabase extends BaseMigrationJob {
3
- run(): Promise<void>;
1
+ import ClearMetadataForChains from './ClearMetadataForChains';
2
+ export default class ClearMetadataDatabase extends ClearMetadataForChains {
3
+ chains: string[];
4
4
  }
@@ -1,27 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
- import { cacheMetadata, waitTimeout } from '@subwallet/extension-base/utils';
6
- export default class ClearMetadataDatabase extends BaseMigrationJob {
7
- async run() {
8
- // Clear all old metadata data
9
- await this.state.dbService.stores.metadata.clear();
10
- const activeChains = this.state.chainService.getActiveChains();
11
- const chainInfoMap = this.state.chainService.getChainInfoMap();
12
- const reloadChains = activeChains.filter(chain => {
13
- var _chainInfoMap$chain$s;
14
- return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash);
15
- });
16
- for (const chain of reloadChains) {
17
- const substrateApi = this.state.chainService.getSubstrateApi(chain);
18
- const callback = substrateApi => {
19
- cacheMetadata(chain, substrateApi, this.state.chainService);
20
- };
21
- Promise.race([substrateApi.isReady, waitTimeout(2000)]).finally(() => {
22
- substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
23
- });
24
- }
25
- return Promise.resolve();
26
- }
4
+ import ClearMetadataForChains from "./ClearMetadataForChains.js";
5
+ export default class ClearMetadataDatabase extends ClearMetadataForChains {
6
+ chains = [];
27
7
  }
@@ -0,0 +1,5 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default abstract class ClearMetadataForChains extends BaseMigrationJob {
3
+ protected abstract chains: string[];
4
+ run(): Promise<void>;
5
+ }
@@ -0,0 +1,32 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
+ import { cacheMetadata, waitTimeout } from '@subwallet/extension-base/utils';
6
+ export default class ClearMetadataForChains extends BaseMigrationJob {
7
+ async run() {
8
+ const isClearAll = this.chains.length === 0;
9
+ if (isClearAll) {
10
+ // Clear all old metadata data
11
+ await this.state.dbService.stores.metadata.clear();
12
+ } else {
13
+ await this.state.dbService.stores.metadata.clearByChains(this.chains);
14
+ }
15
+ const activeChains = this.state.chainService.getActiveChains();
16
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
17
+ const reloadChains = activeChains.filter(chain => {
18
+ var _chainInfoMap$chain$s;
19
+ return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash) && (isClearAll || this.chains.includes(chain));
20
+ });
21
+ for (const chain of reloadChains) {
22
+ const substrateApi = this.state.chainService.getSubstrateApi(chain);
23
+ const callback = substrateApi => {
24
+ cacheMetadata(chain, substrateApi, this.state.chainService);
25
+ };
26
+ Promise.race([substrateApi.isReady, waitTimeout(2000)]).finally(() => {
27
+ substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
28
+ });
29
+ }
30
+ return Promise.resolve();
31
+ }
32
+ }
@@ -0,0 +1,4 @@
1
+ import ClearMetadataForChains from './ClearMetadataForChains';
2
+ export default class ClearMetadataForMythos extends ClearMetadataForChains {
3
+ chains: string[];
4
+ }
@@ -0,0 +1,7 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import ClearMetadataForChains from "./ClearMetadataForChains.js";
5
+ export default class ClearMetadataForMythos extends ClearMetadataForChains {
6
+ chains = ['mythos', 'muse_testnet'];
7
+ }
@@ -1,4 +1,5 @@
1
1
  import BaseMigrationJob from '../Base';
2
2
  export declare const EVERYTIME = "__everytime__";
3
+ export declare const MYTHOS_MIGRATION_KEY = "1.3.21-01";
3
4
  declare const _default: Record<string, typeof BaseMigrationJob>;
4
5
  export default _default;
@@ -3,6 +3,7 @@
3
3
 
4
4
  import AutoEnableSomeTokens from "./databases/AutoEnableSomeTokens.js";
5
5
  import ClearMetadataDatabase from "./databases/ClearMetadataDatabase.js";
6
+ import ClearMetadataForMythos from "./databases/ClearMetadataForMythos.js";
6
7
  import MigrateAssetSetting from "./databases/MigrateAssetSetting.js";
7
8
  import MigrateEarningVersion from "./databases/MigrateEarningVersion.js";
8
9
  import ReloadMetadata from "./databases/ReloadMetadata.js";
@@ -31,6 +32,7 @@ import MigrateTransactionHistoryBridge from "./MigrateTransactionHistoryBridge.j
31
32
  import MigrateTransactionHistoryBySymbol from "./MigrateTransactionHistoryBySymbol.js";
32
33
  import MigrateWalletReference from "./MigrateWalletReference.js";
33
34
  export const EVERYTIME = '__everytime__';
35
+ export const MYTHOS_MIGRATION_KEY = '1.3.21-01';
34
36
  export default {
35
37
  '1.0.1-11': MigrateNetworkSettings,
36
38
  '1.0.1-20': MigrateImportedToken,
@@ -61,7 +63,8 @@ export default {
61
63
  '1.2.13-01': ReloadMetadata,
62
64
  '1.2.32-01': MigratePairData,
63
65
  '1.3.6-01': MigrateTransactionHistoryBridge,
64
- '1.3.10-01': ClearMetadataDatabase
66
+ '1.3.10-01': ClearMetadataDatabase,
67
+ [MYTHOS_MIGRATION_KEY]: ClearMetadataForMythos
65
68
  // [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
66
69
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
67
70
  };
@@ -0,0 +1,16 @@
1
+ import { ConfirmationDefinitionsCardano, ConfirmationsQueueCardano, ConfirmationsQueueItemOptions, ConfirmationTypeCardano, RequestConfirmationCompleteCardano } from '@subwallet/extension-base/background/KoniTypes';
2
+ import RequestService from '@subwallet/extension-base/services/request-service';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ export default class CardanoRequestHandler {
5
+ #private;
6
+ private readonly confirmationsQueueSubjectCardano;
7
+ private readonly confirmationsPromiseMap;
8
+ constructor(requestService: RequestService);
9
+ get numCardanoRequests(): number;
10
+ getConfirmationsQueueSubjectCardano(): BehaviorSubject<ConfirmationsQueueCardano>;
11
+ addConfirmationCardano<CT extends ConfirmationTypeCardano>(id: string, url: string, type: CT, payload: ConfirmationDefinitionsCardano[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsCardano[CT][1]) => Error | undefined): Promise<ConfirmationDefinitionsCardano[CT][1]>;
12
+ completeConfirmationCardano(request: RequestConfirmationCompleteCardano): Promise<boolean>;
13
+ private decorateResult;
14
+ private signTransactionCardano;
15
+ resetWallet(): void;
16
+ }