@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
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SESSION_TIMEOUT = exports.AccountMigrationHandler = void 0;
7
+ var _Base = require("@subwallet/extension-base/services/keyring-service/context/handlers/Base");
8
+ var _types = require("@subwallet/extension-base/types");
9
+ var _utils = require("@subwallet/extension-base/utils");
10
+ var _getId = require("@subwallet/extension-base/utils/getId");
11
+ var _uiKeyring = require("@subwallet/ui-keyring");
12
+ var _utilCrypto = require("@polkadot/util-crypto");
13
+ // Copyright 2019-2022 @subwallet/extension-base
14
+ // SPDX-License-Identifier: Apache-2.0
15
+
16
+ const SESSION_TIMEOUT = 10000;
17
+ exports.SESSION_TIMEOUT = SESSION_TIMEOUT;
18
+ class AccountMigrationHandler extends _Base.AccountBaseHandler {
19
+ sessionIdToPassword = {};
20
+ pingSession(_ref) {
21
+ let {
22
+ sessionId
23
+ } = _ref;
24
+ if (!this.sessionIdToPassword[sessionId]) {
25
+ // todo: if no persistent sessionId, should we jump to enter password again?
26
+ throw Error(`Session ID ${sessionId} not found.`);
27
+ }
28
+ clearTimeout(this.sessionIdToPassword[sessionId].timeoutId);
29
+ this.sessionIdToPassword[sessionId].timeoutId = setTimeout(() => {
30
+ delete this.sessionIdToPassword[sessionId];
31
+ }, SESSION_TIMEOUT);
32
+ return true;
33
+ }
34
+ async migrateUnifiedAndFetchEligibleSoloAccounts(request, setMigratingModeFn) {
35
+ // Migrate unified -> unified
36
+ const password = request.password;
37
+ const allAccountProxies = Object.values(this.state.accounts);
38
+ const UACanBeMigrated = this.getUACanBeMigrated(allAccountProxies);
39
+ const UACanBeMigratedSortedByParent = this.sortUAByParent(UACanBeMigrated); // master account must be migrated before derived account
40
+ const migratedUnifiedAccountIds = await this.migrateUnifiedToUnifiedAccount(password, UACanBeMigratedSortedByParent, setMigratingModeFn);
41
+
42
+ // Get solo accounts can be migrated
43
+ const soloAccountsNeedToBeMigrated = this.getSoloAccountsNeedToBeMigrated(allAccountProxies);
44
+ const soloAccountsNeedToBeMigratedGroup = this.groupSoloAccountByMnemonic(password, soloAccountsNeedToBeMigrated);
45
+ const eligibleSoloAccountMap = this.accountProxiesToEligibleSoloAccountMap(soloAccountsNeedToBeMigratedGroup);
46
+
47
+ // Create persistent mapping sessionId <-> password
48
+ const uniqueId = Date.now().toString();
49
+ const timeoutId = setTimeout(() => delete this.sessionIdToPassword[uniqueId], SESSION_TIMEOUT * 2);
50
+ this.sessionIdToPassword[uniqueId] = {
51
+ password,
52
+ timeoutId
53
+ };
54
+ return {
55
+ migratedUnifiedAccountIds,
56
+ soloAccounts: eligibleSoloAccountMap,
57
+ sessionId: uniqueId
58
+ };
59
+ }
60
+ async migrateUnifiedToUnifiedAccount(password, accountProxies, setMigratingModeFn) {
61
+ _uiKeyring.keyring.unlockKeyring(password);
62
+ this.parentService.updateKeyringState();
63
+ setMigratingModeFn();
64
+ const unifiedAccountIds = [];
65
+ const modifiedPairs = structuredClone(this.state.modifyPairs);
66
+ const {
67
+ derivedUnifiedAccounts,
68
+ masterUnifiedAccounts
69
+ } = accountProxies.reduce((accountInfo, account) => {
70
+ const isDerivedAccount = !!account.parentId;
71
+ isDerivedAccount ? accountInfo.derivedUnifiedAccounts.push(account) : accountInfo.masterUnifiedAccounts.push(account);
72
+ return accountInfo;
73
+ }, {
74
+ derivedUnifiedAccounts: [],
75
+ masterUnifiedAccounts: []
76
+ });
77
+ try {
78
+ for (const unifiedAccount of masterUnifiedAccounts) {
79
+ const proxyId = unifiedAccount.id;
80
+ const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
81
+ password,
82
+ proxyId
83
+ }).result;
84
+ const newChainTypes = Object.values(_types.AccountChainType).filter(type => !unifiedAccount.chainTypes.includes(type) && _types.SUPPORTED_ACCOUNT_CHAIN_TYPES.includes(type));
85
+ const keypairTypes = newChainTypes.map(chainType => (0, _utils.getDefaultKeypairTypeFromAccountChainType)(chainType));
86
+ keypairTypes.forEach(type => {
87
+ const suri = (0, _utils.getSuri)(mnemonic, type);
88
+ const pair = _uiKeyring.keyring.createFromUri(suri, {}, type);
89
+ const address = pair.address;
90
+ modifiedPairs[address] = {
91
+ accountProxyId: proxyId,
92
+ migrated: true,
93
+ key: address
94
+ };
95
+ });
96
+ keypairTypes.forEach(type => {
97
+ const suri = (0, _utils.getSuri)(mnemonic, type);
98
+ const {
99
+ derivePath
100
+ } = (0, _utilCrypto.keyExtractSuri)(suri);
101
+ const metadata = {
102
+ name: unifiedAccount.name,
103
+ derivationPath: derivePath ? derivePath.substring(1) : undefined
104
+ };
105
+ const rs = _uiKeyring.keyring.addUri(suri, metadata, type);
106
+ const address = rs.pair.address;
107
+ this.state._addAddressToAuthList(address, true);
108
+ });
109
+ this.state.upsertModifyPairs(modifiedPairs);
110
+ unifiedAccountIds.push(proxyId);
111
+ }
112
+ 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
113
+
114
+ for (const unifiedAccount of derivedUnifiedAccounts) {
115
+ this.parentService.context.derivationAccountProxyCreate({
116
+ name: unifiedAccount.name,
117
+ suri: unifiedAccount.suri || '',
118
+ proxyId: unifiedAccount.parentId || ''
119
+ }, true);
120
+ unifiedAccountIds.push(unifiedAccount.id);
121
+ }
122
+ } catch (error) {
123
+ console.error('Migration unified account failed with error:', error);
124
+ } finally {
125
+ _uiKeyring.keyring.lockAll(false);
126
+ this.parentService.updateKeyringState();
127
+ }
128
+ return unifiedAccountIds;
129
+ }
130
+ getUACanBeMigrated(accountProxies) {
131
+ return accountProxies.filter(account => this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
132
+ }
133
+ getSoloAccountsNeedToBeMigrated(accountProxies) {
134
+ return accountProxies.filter(account => !this.state.isUnifiedAccount(account.id) && account.isNeedMigrateUnifiedAccount);
135
+ }
136
+ groupSoloAccountByMnemonic(password, accountProxies) {
137
+ const parentService = this.parentService;
138
+ return accountProxies.reduce(function (rs, item) {
139
+ const oldProxyId = item.id;
140
+ const mnemonic = parentService.context.exportAccountProxyMnemonic({
141
+ password,
142
+ proxyId: oldProxyId
143
+ }).result;
144
+ const upcomingProxyId = (0, _utils.createAccountProxyId)(mnemonic);
145
+ if (!rs[upcomingProxyId]) {
146
+ rs[upcomingProxyId] = [];
147
+ }
148
+ rs[upcomingProxyId].push(item);
149
+ return rs;
150
+ }, {});
151
+ }
152
+ accountProxiesToEligibleSoloAccountMap(accountProxyMap) {
153
+ const eligibleSoloAccountMap = {};
154
+ Object.entries(accountProxyMap).forEach(_ref2 => {
155
+ let [upcomingProxyId, accounts] = _ref2;
156
+ eligibleSoloAccountMap[upcomingProxyId] = accounts.map(account => {
157
+ return {
158
+ upcomingProxyId,
159
+ proxyId: account.accounts[0].proxyId,
160
+ address: account.accounts[0].address,
161
+ name: account.name,
162
+ chainType: account.chainTypes[0]
163
+ };
164
+ });
165
+ });
166
+ return eligibleSoloAccountMap;
167
+ }
168
+ sortUAByParent(accountProxies) {
169
+ const undefinedToStr = str => str !== null && str !== void 0 ? str : '';
170
+ return accountProxies.sort((a, b) => undefinedToStr(a.parentId) < undefinedToStr(b.parentId) ? -1 : undefinedToStr(a.parentId) > undefinedToStr(b.parentId) ? 1 : 0);
171
+ }
172
+ migrateSoloToUnifiedAccount(request) {
173
+ const {
174
+ accountName,
175
+ sessionId,
176
+ soloAccounts
177
+ } = request;
178
+ const password = this.sessionIdToPassword[sessionId].password;
179
+ _uiKeyring.keyring.unlockKeyring(password);
180
+ this.parentService.updateKeyringState();
181
+ const modifiedPairs = structuredClone(this.state.modifyPairs);
182
+ const firstAccountInfo = soloAccounts[0];
183
+ const upcomingProxyId = firstAccountInfo.upcomingProxyId;
184
+ const firstAccountOldProxyId = firstAccountInfo.proxyId;
185
+ try {
186
+ const mnemonic = this.parentService.context.exportAccountProxyMnemonic({
187
+ password,
188
+ proxyId: firstAccountOldProxyId
189
+ }).result;
190
+ const keypairTypes = _types.SUPPORTED_ACCOUNT_CHAIN_TYPES.map(chainType => (0, _utils.getDefaultKeypairTypeFromAccountChainType)(chainType));
191
+ keypairTypes.forEach(type => {
192
+ const suri = (0, _utils.getSuri)(mnemonic, type);
193
+ const pair = _uiKeyring.keyring.createFromUri(suri, {}, type);
194
+ const address = pair.address;
195
+ modifiedPairs[address] = {
196
+ accountProxyId: upcomingProxyId,
197
+ migrated: true,
198
+ key: address
199
+ };
200
+ });
201
+ this.state.upsertAccountProxyByKey({
202
+ id: upcomingProxyId,
203
+ name: accountName,
204
+ isMigrationDone: false
205
+ });
206
+ const soloAccountProxyIds = [];
207
+ keypairTypes.forEach(type => {
208
+ const suri = (0, _utils.getSuri)(mnemonic, type);
209
+ const {
210
+ derivePath
211
+ } = (0, _utilCrypto.keyExtractSuri)(suri);
212
+ const metadata = {
213
+ name: accountName.concat(' - ').concat((0, _getId.generateRandomString)()),
214
+ derivationPath: derivePath ? derivePath.substring(1) : undefined
215
+ };
216
+ const rs = _uiKeyring.keyring.addUri(suri, metadata, type);
217
+ soloAccountProxyIds.push(rs.json.address);
218
+ const address = rs.pair.address;
219
+ this.state._addAddressToAuthList(address, true);
220
+ });
221
+ this.state.upsertModifyPairs(modifiedPairs);
222
+ this.migrateDerivedSoloAccountRelationship(soloAccounts);
223
+ this.state.upsertAccountProxyByKey({
224
+ id: upcomingProxyId,
225
+ name: accountName,
226
+ isMigrationDone: true
227
+ });
228
+
229
+ // Re-update account name
230
+ soloAccountProxyIds.forEach(oldProxyId => {
231
+ const pair = _uiKeyring.keyring.getPair(oldProxyId);
232
+ _uiKeyring.keyring.saveAccountMeta(pair, {
233
+ ...pair.meta,
234
+ name: accountName
235
+ });
236
+ });
237
+
238
+ // Update current account after migrating
239
+ const currentAccountProxyId = this.state.currentAccount.proxyId;
240
+ if (soloAccountProxyIds.includes(currentAccountProxyId)) {
241
+ this.state.saveCurrentAccountProxyId(upcomingProxyId);
242
+ }
243
+ } catch (error) {
244
+ console.error('Migration solo account failed with error', error);
245
+ } finally {
246
+ _uiKeyring.keyring.lockAll(false);
247
+ this.parentService.updateKeyringState();
248
+ }
249
+ return {
250
+ migratedUnifiedAccountId: upcomingProxyId
251
+ };
252
+ }
253
+ migrateDerivedSoloAccountRelationship(soloAccounts) {
254
+ const accountProxies = this.state.accountProxies;
255
+
256
+ // Use Set.has & Map.get to optimize search performance
257
+ const proxyIdsSet = new Set(soloAccounts.map(account => account.proxyId));
258
+ const proxyIdToUpcomingProxyIdMap = new Map(soloAccounts.map(account => [account.proxyId, account.upcomingProxyId]));
259
+ for (const account of Object.values(accountProxies)) {
260
+ const currentParent = account.parentId;
261
+ if (currentParent && proxyIdsSet.has(currentParent)) {
262
+ accountProxies[account.id].parentId = proxyIdToUpcomingProxyIdMap.get(currentParent);
263
+ }
264
+ }
265
+ this.state.upsertAccountProxy(accountProxies);
266
+ }
267
+ }
268
+ exports.AccountMigrationHandler = AccountMigrationHandler;
@@ -36,7 +36,7 @@ class AccountMnemonicHandler extends _Base.AccountBaseHandler {
36
36
  mnemonic: _seed,
37
37
  type = 'general'
38
38
  } = _ref;
39
- const types = type === 'general' ? ['sr25519', 'ethereum', 'ton'] : ['ton-native'];
39
+ const types = type === 'general' ? ['sr25519', 'ethereum', 'ton', 'cardano'] : ['ton-native'];
40
40
  const seed = _seed || type === 'general' ? (0, _utilCrypto.mnemonicGenerate)(length) : await (0, _keyring.tonMnemonicGenerate)(length);
41
41
  const rs = {
42
42
  mnemonic: seed,
@@ -107,7 +107,7 @@ class AccountMnemonicHandler extends _Base.AccountBaseHandler {
107
107
  const addressDict = {};
108
108
  let changedAccount = false;
109
109
  const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
110
- const types = type ? [type] : ['sr25519', 'ethereum', 'ton'];
110
+ const types = type ? [type] : ['sr25519', 'ethereum', 'ton', 'cardano'];
111
111
  if (!hasMasterPassword) {
112
112
  if (!password) {
113
113
  throw Error((0, _i18next.t)('The password of each account is needed to set up master password'));
@@ -55,7 +55,7 @@ class AccountSecretHandler extends _Base.AccountBaseHandler {
55
55
  isReadOnly,
56
56
  genesisHash: ''
57
57
  };
58
- if ([..._types2.BitcoinKeypairTypes, ..._types2.TonKeypairTypes].includes(type) && isReadOnly) {
58
+ if ([..._types2.BitcoinKeypairTypes, ..._types2.TonKeypairTypes, ..._types2.CardanoKeypairTypes].includes(type) && isReadOnly) {
59
59
  meta.noPublicKey = true;
60
60
  }
61
61
  const result = _uiKeyring.default.keyring.addFromAddress(address, meta, null, type);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasAnyAccountForMigration = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ const hasAnyAccountForMigration = allAccountProxies => {
11
+ for (const account of allAccountProxies) {
12
+ if (account.isNeedMigrateUnifiedAccount) {
13
+ return true;
14
+ }
15
+ }
16
+ return false;
17
+ };
18
+ exports.hasAnyAccountForMigration = hasAnyAccountForMigration;
@@ -5,31 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
9
- var _utils = require("@subwallet/extension-base/utils");
8
+ var _ClearMetadataForChains = _interopRequireDefault(require("./ClearMetadataForChains"));
10
9
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
10
  // SPDX-License-Identifier: Apache-2.0
12
11
 
13
- class ClearMetadataDatabase extends _Base.default {
14
- async run() {
15
- // Clear all old metadata data
16
- await this.state.dbService.stores.metadata.clear();
17
- const activeChains = this.state.chainService.getActiveChains();
18
- const chainInfoMap = this.state.chainService.getChainInfoMap();
19
- const reloadChains = activeChains.filter(chain => {
20
- var _chainInfoMap$chain$s;
21
- return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash);
22
- });
23
- for (const chain of reloadChains) {
24
- const substrateApi = this.state.chainService.getSubstrateApi(chain);
25
- const callback = substrateApi => {
26
- (0, _utils.cacheMetadata)(chain, substrateApi, this.state.chainService);
27
- };
28
- Promise.race([substrateApi.isReady, (0, _utils.waitTimeout)(2000)]).finally(() => {
29
- substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
30
- });
31
- }
32
- return Promise.resolve();
33
- }
12
+ class ClearMetadataDatabase extends _ClearMetadataForChains.default {
13
+ chains = [];
34
14
  }
35
15
  exports.default = ClearMetadataDatabase;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
9
+ var _utils = require("@subwallet/extension-base/utils");
10
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class ClearMetadataForChains extends _Base.default {
14
+ async run() {
15
+ const isClearAll = this.chains.length === 0;
16
+ if (isClearAll) {
17
+ // Clear all old metadata data
18
+ await this.state.dbService.stores.metadata.clear();
19
+ } else {
20
+ await this.state.dbService.stores.metadata.clearByChains(this.chains);
21
+ }
22
+ const activeChains = this.state.chainService.getActiveChains();
23
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
24
+ const reloadChains = activeChains.filter(chain => {
25
+ var _chainInfoMap$chain$s;
26
+ return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash) && (isClearAll || this.chains.includes(chain));
27
+ });
28
+ for (const chain of reloadChains) {
29
+ const substrateApi = this.state.chainService.getSubstrateApi(chain);
30
+ const callback = substrateApi => {
31
+ (0, _utils.cacheMetadata)(chain, substrateApi, this.state.chainService);
32
+ };
33
+ Promise.race([substrateApi.isReady, (0, _utils.waitTimeout)(2000)]).finally(() => {
34
+ substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
35
+ });
36
+ }
37
+ return Promise.resolve();
38
+ }
39
+ }
40
+ exports.default = ClearMetadataForChains;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _ClearMetadataForChains = _interopRequireDefault(require("./ClearMetadataForChains"));
9
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
+ // SPDX-License-Identifier: Apache-2.0
11
+
12
+ class ClearMetadataForMythos extends _ClearMetadataForChains.default {
13
+ chains = ['mythos', 'muse_testnet'];
14
+ }
15
+ exports.default = ClearMetadataForMythos;
@@ -4,9 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = exports.EVERYTIME = void 0;
7
+ exports.default = exports.MYTHOS_MIGRATION_KEY = exports.EVERYTIME = void 0;
8
8
  var _AutoEnableSomeTokens = _interopRequireDefault(require("./databases/AutoEnableSomeTokens"));
9
9
  var _ClearMetadataDatabase = _interopRequireDefault(require("./databases/ClearMetadataDatabase"));
10
+ var _ClearMetadataForMythos = _interopRequireDefault(require("./databases/ClearMetadataForMythos"));
10
11
  var _MigrateAssetSetting = _interopRequireDefault(require("./databases/MigrateAssetSetting"));
11
12
  var _MigrateEarningVersion = _interopRequireDefault(require("./databases/MigrateEarningVersion"));
12
13
  var _ReloadMetadata = _interopRequireDefault(require("./databases/ReloadMetadata"));
@@ -39,6 +40,8 @@ var _MigrateWalletReference = _interopRequireDefault(require("./MigrateWalletRef
39
40
 
40
41
  const EVERYTIME = '__everytime__';
41
42
  exports.EVERYTIME = EVERYTIME;
43
+ const MYTHOS_MIGRATION_KEY = '1.3.21-01';
44
+ exports.MYTHOS_MIGRATION_KEY = MYTHOS_MIGRATION_KEY;
42
45
  var _default = {
43
46
  '1.0.1-11': _MigrateNetworkSettings.default,
44
47
  '1.0.1-20': _MigrateImportedToken.default,
@@ -69,7 +72,8 @@ var _default = {
69
72
  '1.2.13-01': _ReloadMetadata.default,
70
73
  '1.2.32-01': _MigratePairData.default,
71
74
  '1.3.6-01': _MigrateTransactionHistoryBridge.default,
72
- '1.3.10-01': _ClearMetadataDatabase.default
75
+ '1.3.10-01': _ClearMetadataDatabase.default,
76
+ [MYTHOS_MIGRATION_KEY]: _ClearMetadataForMythos.default
73
77
  // [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
74
78
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
75
79
  };
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _request = require("@subwallet/extension-base/utils/request");
8
+ var _uiKeyring = require("@subwallet/ui-keyring");
9
+ var _i18next = require("i18next");
10
+ var _rxjs = require("rxjs");
11
+ var _logger = require("@polkadot/util/logger");
12
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
13
+ // SPDX-License-Identifier: Apache-2.0
14
+
15
+ class CardanoRequestHandler {
16
+ #requestService;
17
+ #logger;
18
+ confirmationsQueueSubjectCardano = new _rxjs.BehaviorSubject({
19
+ cardanoSignatureRequest: {},
20
+ cardanoSendTransactionRequest: {},
21
+ cardanoWatchTransactionRequest: {}
22
+ });
23
+ confirmationsPromiseMap = {};
24
+ constructor(requestService) {
25
+ this.#requestService = requestService;
26
+ this.#logger = (0, _logger.logger)('CardanoRequestHandler');
27
+ }
28
+ get numCardanoRequests() {
29
+ let count = 0;
30
+ Object.values(this.confirmationsQueueSubjectCardano.getValue()).forEach(x => {
31
+ count += Object.keys(x).length;
32
+ });
33
+ return count;
34
+ }
35
+ getConfirmationsQueueSubjectCardano() {
36
+ return this.confirmationsQueueSubjectCardano;
37
+ }
38
+ async addConfirmationCardano(id, url, type, payload) {
39
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
40
+ let validator = arguments.length > 5 ? arguments[5] : undefined;
41
+ const confirmations = this.confirmationsQueueSubjectCardano.getValue();
42
+ const confirmationType = confirmations[type];
43
+ const payloadJson = JSON.stringify({});
44
+ const isInternal = (0, _request.isInternalRequest)(url);
45
+ if (['cardanoSendTransactionRequest', 'cardanoSignatureRequest'].includes(type)) {
46
+ const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
47
+ if (isAlwaysRequired) {
48
+ this.#requestService.keyringService.lock();
49
+ }
50
+ }
51
+
52
+ // Check duplicate request
53
+ const duplicated = Object.values(confirmationType).find(c => c.url === url && c.payloadJson === payloadJson);
54
+ if (duplicated) {
55
+ throw new Error('Cardano duplicate request'); // update this message.
56
+ }
57
+
58
+ confirmationType[id] = {
59
+ id,
60
+ url,
61
+ isInternal,
62
+ payload,
63
+ payloadJson,
64
+ ...options
65
+ };
66
+ const promise = new Promise((resolve, reject) => {
67
+ this.confirmationsPromiseMap[id] = {
68
+ validator: validator,
69
+ resolver: {
70
+ resolve: resolve,
71
+ reject: reject
72
+ }
73
+ };
74
+ });
75
+ this.confirmationsQueueSubjectCardano.next(confirmations);
76
+ if (!isInternal) {
77
+ this.#requestService.popupOpen();
78
+ }
79
+ this.#requestService.updateIconV2();
80
+ return promise;
81
+ }
82
+ async completeConfirmationCardano(request) {
83
+ const confirmations = this.confirmationsQueueSubjectCardano.getValue();
84
+ for (const ct in request) {
85
+ const type = ct;
86
+ const result = request[type];
87
+ const {
88
+ id
89
+ } = result;
90
+ const {
91
+ resolver,
92
+ validator
93
+ } = this.confirmationsPromiseMap[id];
94
+ const confirmation = confirmations[type][id];
95
+ if (!resolver || !confirmation) {
96
+ this.#logger.error((0, _i18next.t)('Unable to proceed. Please try again'), type, id);
97
+ throw new Error((0, _i18next.t)('Unable to proceed. Please try again'));
98
+ }
99
+
100
+ // Fill signature for some special type
101
+ await this.decorateResult(type, confirmation, result);
102
+
103
+ // Validate response from confirmation popup some info like password, response format....
104
+ const error = validator && validator(result);
105
+ if (error) {
106
+ resolver.reject(error);
107
+ }
108
+
109
+ // Delete confirmations from queue
110
+ delete this.confirmationsPromiseMap[id];
111
+ delete confirmations[type][id];
112
+ this.confirmationsQueueSubjectCardano.next(confirmations);
113
+
114
+ // Update icon, and close queue
115
+ this.#requestService.updateIconV2(this.#requestService.numAllRequests === 0);
116
+ resolver.resolve(result);
117
+ }
118
+
119
+ // TODO: Review later
120
+ return true;
121
+ }
122
+ async decorateResult(t, request, result) {
123
+ if (result.payload === '') {
124
+ if (t === 'cardanoSignatureRequest') {
125
+ // result.payload = await this.signMessage(request as ConfirmationDefinitions['evmSignatureRequest'][0]);
126
+ } else if (t === 'cardanoSendTransactionRequest') {
127
+ result.payload = this.signTransactionCardano(request);
128
+ }
129
+ if (t === 'cardanoSignatureRequest' || t === 'cardanoSendTransactionRequest') {
130
+ const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
131
+ if (isAlwaysRequired) {
132
+ this.#requestService.keyringService.lock();
133
+ }
134
+ }
135
+ }
136
+ }
137
+ signTransactionCardano(confirmation) {
138
+ // alibaba
139
+ const transaction = confirmation.payload;
140
+ const {
141
+ cardanoPayload,
142
+ from
143
+ } = transaction;
144
+ const pair = _uiKeyring.keyring.getPair(from);
145
+ if (pair.isLocked) {
146
+ _uiKeyring.keyring.unlockPair(pair.address);
147
+ }
148
+ return pair.cardano.sign(cardanoPayload);
149
+ }
150
+ resetWallet() {
151
+ const confirmations = this.confirmationsQueueSubjectCardano.getValue();
152
+ for (const [type, requests] of Object.entries(confirmations)) {
153
+ for (const confirmation of Object.values(requests)) {
154
+ const {
155
+ id
156
+ } = confirmation;
157
+ const {
158
+ resolver
159
+ } = this.confirmationsPromiseMap[id];
160
+ if (!resolver || !confirmation) {
161
+ console.error('Not found confirmation', type, id);
162
+ } else {
163
+ resolver.reject(new Error('Reset wallet'));
164
+ }
165
+ delete this.confirmationsPromiseMap[id];
166
+ delete confirmations[type][id];
167
+ }
168
+ }
169
+ this.confirmationsQueueSubjectCardano.next(confirmations);
170
+ }
171
+ }
172
+ exports.default = CardanoRequestHandler;
@@ -88,7 +88,7 @@ class EvmRequestHandler {
88
88
  }
89
89
  if (options.isPassConfirmation) {
90
90
  await this.completeConfirmation({
91
- evmSendTransactionRequest: {
91
+ [type]: {
92
92
  id,
93
93
  url,
94
94
  isApproved: true,