@metamask-previews/profile-sync-controller 19.0.0-preview-6fc9506d → 19.0.0-preview-83aa339c

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 (92) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/dist/controllers/authentication/AuthenticationController.cjs +5 -0
  3. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  4. package/dist/controllers/authentication/AuthenticationController.d.cts +4 -2
  5. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  6. package/dist/controllers/authentication/AuthenticationController.d.mts +4 -2
  7. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  8. package/dist/controllers/authentication/AuthenticationController.mjs +5 -0
  9. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/UserStorageController.cjs +3 -10
  11. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  12. package/dist/controllers/user-storage/UserStorageController.d.cts +1 -3
  13. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  14. package/dist/controllers/user-storage/UserStorageController.d.mts +1 -3
  15. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  16. package/dist/controllers/user-storage/UserStorageController.mjs +3 -10
  17. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  18. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +168 -184
  19. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  20. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +0 -3
  21. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  22. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +0 -3
  23. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  24. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +168 -184
  25. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  26. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
  27. package/dist/controllers/user-storage/account-syncing/types.d.cts +0 -2
  28. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
  29. package/dist/controllers/user-storage/account-syncing/types.d.mts +0 -2
  30. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
  31. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
  32. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +166 -233
  33. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -1
  34. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts +0 -3
  35. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -1
  36. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +0 -3
  37. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -1
  38. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs +166 -233
  39. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -1
  40. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -1
  41. package/dist/controllers/user-storage/contact-syncing/types.d.cts +0 -2
  42. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -1
  43. package/dist/controllers/user-storage/contact-syncing/types.d.mts +0 -2
  44. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -1
  45. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -1
  46. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +4 -0
  47. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
  48. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts +2 -1
  49. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
  50. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +2 -1
  51. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
  52. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +5 -1
  53. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  54. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +4 -0
  55. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  56. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -1
  57. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  58. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -1
  59. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  60. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +5 -1
  61. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  62. package/dist/sdk/authentication-jwt-bearer/services.cjs +33 -1
  63. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  64. package/dist/sdk/authentication-jwt-bearer/services.d.cts +10 -1
  65. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  66. package/dist/sdk/authentication-jwt-bearer/services.d.mts +10 -1
  67. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  68. package/dist/sdk/authentication-jwt-bearer/services.mjs +30 -0
  69. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  70. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
  71. package/dist/sdk/authentication-jwt-bearer/types.d.cts +11 -0
  72. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
  73. package/dist/sdk/authentication-jwt-bearer/types.d.mts +11 -0
  74. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
  75. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  76. package/dist/sdk/authentication.cjs +3 -0
  77. package/dist/sdk/authentication.cjs.map +1 -1
  78. package/dist/sdk/authentication.d.cts +2 -1
  79. package/dist/sdk/authentication.d.cts.map +1 -1
  80. package/dist/sdk/authentication.d.mts +2 -1
  81. package/dist/sdk/authentication.d.mts.map +1 -1
  82. package/dist/sdk/authentication.mjs +3 -0
  83. package/dist/sdk/authentication.mjs.map +1 -1
  84. package/dist/sdk/mocks/auth.cjs +22 -1
  85. package/dist/sdk/mocks/auth.cjs.map +1 -1
  86. package/dist/sdk/mocks/auth.d.cts +13 -0
  87. package/dist/sdk/mocks/auth.d.cts.map +1 -1
  88. package/dist/sdk/mocks/auth.d.mts +13 -0
  89. package/dist/sdk/mocks/auth.d.mts.map +1 -1
  90. package/dist/sdk/mocks/auth.mjs +23 -2
  91. package/dist/sdk/mocks/auth.mjs.map +1 -1
  92. package/package.json +2 -2
@@ -10,34 +10,27 @@ const storage_schema_1 = require("../../../shared/storage-schema.cjs");
10
10
  *
11
11
  * @param internalAccount - The internal account to save
12
12
  * @param options - parameters used for saving the internal account
13
- * @returns Promise that resolves when the account is saved
14
13
  */
15
14
  async function saveInternalAccountToUserStorage(internalAccount, options) {
16
- const { trace } = options;
17
- const saveAccount = async () => {
18
- const { getUserStorageControllerInstance } = options;
19
- if (!(0, sync_utils_1.canPerformAccountSyncing)(options) ||
20
- internalAccount.metadata.keyring.type !== String(keyring_controller_1.KeyringTypes.hd) // sync only EVM accounts until we support multichain accounts
21
- ) {
22
- return;
23
- }
24
- // properties of `options` are (wrongly?) typed as `Json` and eslint crashes if we try to interpret it as such and call a `?.toString()` on it.
25
- // but we know this is a string?, so we can safely cast it
26
- const entropySourceId = internalAccount.options?.entropySource;
27
- try {
28
- // Map the internal account to the user storage account schema
29
- const mappedAccount = (0, utils_1.mapInternalAccountToUserStorageAccount)(internalAccount);
30
- await getUserStorageControllerInstance().performSetStorage(`${storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`, JSON.stringify(mappedAccount), entropySourceId);
31
- }
32
- catch (e) {
33
- // istanbul ignore next
34
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
35
- throw new Error(`UserStorageController - failed to save account to user storage - ${errorMessage}`);
36
- }
37
- };
38
- return trace
39
- ? await trace({ name: 'Account Sync Save Individual' }, saveAccount)
40
- : await saveAccount();
15
+ const { getUserStorageControllerInstance } = options;
16
+ if (!(0, sync_utils_1.canPerformAccountSyncing)(options) ||
17
+ internalAccount.metadata.keyring.type !== String(keyring_controller_1.KeyringTypes.hd) // sync only EVM accounts until we support multichain accounts
18
+ ) {
19
+ return;
20
+ }
21
+ // properties of `options` are (wrongly?) typed as `Json` and eslint crashes if we try to interpret it as such and call a `?.toString()` on it.
22
+ // but we know this is a string?, so we can safely cast it
23
+ const entropySourceId = internalAccount.options.entropySource;
24
+ try {
25
+ // Map the internal account to the user storage account schema
26
+ const mappedAccount = (0, utils_1.mapInternalAccountToUserStorageAccount)(internalAccount);
27
+ await getUserStorageControllerInstance().performSetStorage(`${storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`, JSON.stringify(mappedAccount), entropySourceId);
28
+ }
29
+ catch (e) {
30
+ // istanbul ignore next
31
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
32
+ throw new Error(`UserStorageController - failed to save account to user storage - ${errorMessage}`);
33
+ }
41
34
  }
42
35
  exports.saveInternalAccountToUserStorage = saveInternalAccountToUserStorage;
43
36
  /**
@@ -46,7 +39,6 @@ exports.saveInternalAccountToUserStorage = saveInternalAccountToUserStorage;
46
39
  * @param options - parameters used for saving the list of internal accounts
47
40
  * @param entropySourceId - The entropy source ID used to derive the key,
48
41
  * when multiple sources are available (Multi-SRP).
49
- * @returns Promise that resolves when all accounts are saved
50
42
  */
51
43
  async function saveInternalAccountsListToUserStorage(options, entropySourceId) {
52
44
  const { getUserStorageControllerInstance } = options;
@@ -69,182 +61,174 @@ exports.saveInternalAccountsListToUserStorage = saveInternalAccountsListToUserSt
69
61
  * @param config - parameters used for syncing the internal accounts list with the user storage accounts list
70
62
  * @param options - parameters used for syncing the internal accounts list with the user storage accounts list
71
63
  * @param entropySourceId - The entropy source ID used to derive the key,
72
- * @returns Promise that resolves when synchronization is complete
73
64
  */
74
65
  async function syncInternalAccountsWithUserStorage(config, options, entropySourceId) {
75
- const { trace } = options;
76
- const performAccountSync = async () => {
77
- if (!(0, sync_utils_1.canPerformAccountSyncing)(options)) {
66
+ if (!(0, sync_utils_1.canPerformAccountSyncing)(options)) {
67
+ return;
68
+ }
69
+ const { maxNumberOfAccountsToAdd = Infinity, onAccountAdded, onAccountNameUpdated, onAccountSyncErroneousSituation, } = config;
70
+ const { getMessenger, getUserStorageControllerInstance } = options;
71
+ try {
72
+ await getUserStorageControllerInstance().setIsAccountSyncingInProgress(true);
73
+ const userStorageAccountsList = await (0, sync_utils_1.getUserStorageAccountsList)(options, entropySourceId);
74
+ if (!userStorageAccountsList || !userStorageAccountsList.length) {
75
+ await saveInternalAccountsListToUserStorage(options, entropySourceId);
78
76
  return;
79
77
  }
80
- const { maxNumberOfAccountsToAdd = Infinity, onAccountAdded, onAccountNameUpdated, onAccountSyncErroneousSituation, } = config;
81
- const { getMessenger, getUserStorageControllerInstance } = options;
82
- try {
83
- await getUserStorageControllerInstance().setIsAccountSyncingInProgress(true);
84
- const userStorageAccountsList = await (0, sync_utils_1.getUserStorageAccountsList)(options, entropySourceId);
85
- if (!userStorageAccountsList || !userStorageAccountsList.length) {
86
- await saveInternalAccountsListToUserStorage(options, entropySourceId);
87
- return;
88
- }
89
- // Keep a record if erroneous situations are found during the sync
90
- // This is done so we can send the context to Sentry in case of an erroneous situation
91
- let erroneousSituationsFound = false;
92
- // Prepare an array of internal accounts to be saved to the user storage
93
- const internalAccountsToBeSavedToUserStorage = [];
94
- // Compare internal accounts list with user storage accounts list
95
- // First step: compare lengths
96
- const internalAccountsList = await (0, sync_utils_1.getInternalAccountsList)(options, entropySourceId);
97
- if (!internalAccountsList || !internalAccountsList.length) {
98
- throw new Error(`Failed to get internal accounts list`);
99
- }
100
- const hasMoreUserStorageAccountsThanInternalAccounts = userStorageAccountsList.length > internalAccountsList.length;
101
- // We don't want to remove existing accounts for a user
102
- // so we only add new accounts if the user has more accounts in user storage than internal accounts
103
- if (hasMoreUserStorageAccountsThanInternalAccounts) {
104
- const numberOfAccountsToAdd = Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -
105
- internalAccountsList.length;
106
- // Create new accounts to match the user storage accounts list
107
- await getMessenger().call('KeyringController:withKeyring', {
108
- id: entropySourceId,
109
- }, async ({ keyring }) => {
110
- await keyring.addAccounts(numberOfAccountsToAdd);
111
- });
112
- // TODO: below code is kept for analytics but should probably be re-thought
113
- for (let i = 0; i < numberOfAccountsToAdd; i++) {
114
- onAccountAdded?.();
115
- }
78
+ // Keep a record if erroneous situations are found during the sync
79
+ // This is done so we can send the context to Sentry in case of an erroneous situation
80
+ let erroneousSituationsFound = false;
81
+ // Prepare an array of internal accounts to be saved to the user storage
82
+ const internalAccountsToBeSavedToUserStorage = [];
83
+ // Compare internal accounts list with user storage accounts list
84
+ // First step: compare lengths
85
+ const internalAccountsList = await (0, sync_utils_1.getInternalAccountsList)(options, entropySourceId);
86
+ if (!internalAccountsList || !internalAccountsList.length) {
87
+ throw new Error(`Failed to get internal accounts list`);
88
+ }
89
+ const hasMoreUserStorageAccountsThanInternalAccounts = userStorageAccountsList.length > internalAccountsList.length;
90
+ // We don't want to remove existing accounts for a user
91
+ // so we only add new accounts if the user has more accounts in user storage than internal accounts
92
+ if (hasMoreUserStorageAccountsThanInternalAccounts) {
93
+ const numberOfAccountsToAdd = Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -
94
+ internalAccountsList.length;
95
+ // Create new accounts to match the user storage accounts list
96
+ await getMessenger().call('KeyringController:withKeyring', {
97
+ id: entropySourceId,
98
+ }, async ({ keyring }) => {
99
+ await keyring.addAccounts(numberOfAccountsToAdd);
100
+ });
101
+ // TODO: below code is kept for analytics but should probably be re-thought
102
+ for (let i = 0; i < numberOfAccountsToAdd; i++) {
103
+ onAccountAdded?.();
116
104
  }
117
- // Second step: compare account names
118
- // Get the internal accounts list again since new accounts might have been added in the previous step
119
- const refreshedInternalAccountsList = await (0, sync_utils_1.getInternalAccountsList)(options, entropySourceId);
120
- const newlyAddedAccounts = refreshedInternalAccountsList.filter((account) => !internalAccountsList.find((a) => a.address === account.address));
121
- for (const internalAccount of refreshedInternalAccountsList) {
122
- const userStorageAccount = userStorageAccountsList.find((account) => account.a === internalAccount.address);
123
- // If the account is not present in user storage
124
- // istanbul ignore next
125
- if (!userStorageAccount) {
126
- // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account
127
- if (newlyAddedAccounts.includes(internalAccount)) {
128
- erroneousSituationsFound = true;
129
- onAccountSyncErroneousSituation?.('An account was added to the internal accounts list but was not present in the user storage accounts list', {
130
- internalAccount,
131
- userStorageAccount,
132
- newlyAddedAccounts,
133
- userStorageAccountsList,
134
- internalAccountsList,
135
- refreshedInternalAccountsList,
136
- internalAccountsToBeSavedToUserStorage,
137
- });
138
- continue;
139
- }
140
- // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage
141
- internalAccountsToBeSavedToUserStorage.push(internalAccount);
142
- continue;
143
- }
144
- // From this point on, we know that the account is present in
145
- // both the internal accounts list and the user storage accounts list
146
- // One or both accounts have default names
147
- const isInternalAccountNameDefault = (0, utils_1.isNameDefaultAccountName)(internalAccount.metadata.name);
148
- const isUserStorageAccountNameDefault = (0, utils_1.isNameDefaultAccountName)(userStorageAccount.n);
149
- // Internal account has default name
150
- if (isInternalAccountNameDefault) {
151
- if (!isUserStorageAccountNameDefault) {
152
- getMessenger().call('AccountsController:updateAccountMetadata', internalAccount.id, {
153
- name: userStorageAccount.n,
154
- });
155
- onAccountNameUpdated?.();
156
- }
157
- continue;
158
- }
159
- // Internal account has custom name but user storage account has default name
160
- if (isUserStorageAccountNameDefault) {
161
- internalAccountsToBeSavedToUserStorage.push(internalAccount);
105
+ }
106
+ // Second step: compare account names
107
+ // Get the internal accounts list again since new accounts might have been added in the previous step
108
+ const refreshedInternalAccountsList = await (0, sync_utils_1.getInternalAccountsList)(options, entropySourceId);
109
+ const newlyAddedAccounts = refreshedInternalAccountsList.filter((account) => !internalAccountsList.find((a) => a.address === account.address));
110
+ for (const internalAccount of refreshedInternalAccountsList) {
111
+ const userStorageAccount = userStorageAccountsList.find((account) => account.a === internalAccount.address);
112
+ // If the account is not present in user storage
113
+ // istanbul ignore next
114
+ if (!userStorageAccount) {
115
+ // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account
116
+ if (newlyAddedAccounts.includes(internalAccount)) {
117
+ erroneousSituationsFound = true;
118
+ onAccountSyncErroneousSituation?.('An account was added to the internal accounts list but was not present in the user storage accounts list', {
119
+ internalAccount,
120
+ userStorageAccount,
121
+ newlyAddedAccounts,
122
+ userStorageAccountsList,
123
+ internalAccountsList,
124
+ refreshedInternalAccountsList,
125
+ internalAccountsToBeSavedToUserStorage,
126
+ });
162
127
  continue;
163
128
  }
164
- // Both accounts have custom names
165
- // User storage account has a nameLastUpdatedAt timestamp
166
- // Note: not storing the undefined checks in constants to act as a type guard
167
- if (userStorageAccount.nlu !== undefined) {
168
- if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {
169
- const isInternalAccountNameNewer = internalAccount.metadata.nameLastUpdatedAt >
170
- userStorageAccount.nlu;
171
- if (isInternalAccountNameNewer) {
172
- internalAccountsToBeSavedToUserStorage.push(internalAccount);
173
- continue;
174
- }
175
- }
129
+ // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage
130
+ internalAccountsToBeSavedToUserStorage.push(internalAccount);
131
+ continue;
132
+ }
133
+ // From this point on, we know that the account is present in
134
+ // both the internal accounts list and the user storage accounts list
135
+ // One or both accounts have default names
136
+ const isInternalAccountNameDefault = (0, utils_1.isNameDefaultAccountName)(internalAccount.metadata.name);
137
+ const isUserStorageAccountNameDefault = (0, utils_1.isNameDefaultAccountName)(userStorageAccount.n);
138
+ // Internal account has default name
139
+ if (isInternalAccountNameDefault) {
140
+ if (!isUserStorageAccountNameDefault) {
176
141
  getMessenger().call('AccountsController:updateAccountMetadata', internalAccount.id, {
177
142
  name: userStorageAccount.n,
178
- nameLastUpdatedAt: userStorageAccount.nlu,
179
143
  });
180
- const areInternalAndUserStorageAccountNamesEqual = internalAccount.metadata.name === userStorageAccount.n;
181
- if (!areInternalAndUserStorageAccountNamesEqual) {
182
- onAccountNameUpdated?.();
183
- }
184
- continue;
185
- }
186
- else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {
187
- internalAccountsToBeSavedToUserStorage.push(internalAccount);
188
- continue;
144
+ onAccountNameUpdated?.();
189
145
  }
146
+ continue;
190
147
  }
191
- // Save the internal accounts list to the user storage
192
- if (internalAccountsToBeSavedToUserStorage.length) {
193
- await getUserStorageControllerInstance().performBatchSetStorage(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts, internalAccountsToBeSavedToUserStorage.map((account) => [
194
- account.address,
195
- JSON.stringify((0, utils_1.mapInternalAccountToUserStorageAccount)(account)),
196
- ]), entropySourceId);
148
+ // Internal account has custom name but user storage account has default name
149
+ if (isUserStorageAccountNameDefault) {
150
+ internalAccountsToBeSavedToUserStorage.push(internalAccount);
151
+ continue;
197
152
  }
198
- // In case we have corrupted user storage with accounts that don't exist in the internal accounts list
199
- // Delete those accounts from the user storage
200
- const userStorageAccountsToBeDeleted = userStorageAccountsList.filter((account) => !refreshedInternalAccountsList.find((a) => a.address === account.a));
201
- if (userStorageAccountsToBeDeleted.length) {
202
- await getUserStorageControllerInstance().performBatchDeleteStorage(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts, userStorageAccountsToBeDeleted.map((account) => account.a), entropySourceId);
203
- erroneousSituationsFound = true;
204
- onAccountSyncErroneousSituation?.('An account was present in the user storage accounts list but was not found in the internal accounts list after the sync', {
205
- userStorageAccountsToBeDeleted,
206
- internalAccountsList,
207
- refreshedInternalAccountsList,
208
- internalAccountsToBeSavedToUserStorage,
209
- userStorageAccountsList,
210
- });
211
- }
212
- if (erroneousSituationsFound) {
213
- const [finalUserStorageAccountsList, finalInternalAccountsList] = await Promise.all([
214
- (0, sync_utils_1.getUserStorageAccountsList)(options, entropySourceId),
215
- (0, sync_utils_1.getInternalAccountsList)(options, entropySourceId),
216
- ]);
217
- const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList = finalInternalAccountsList.every((account) => finalUserStorageAccountsList?.some((userStorageAccount) => userStorageAccount.a === account.address));
218
- // istanbul ignore next
219
- const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList = (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd
220
- ? true
221
- : finalUserStorageAccountsList?.every((account) => finalInternalAccountsList.some((internalAccount) => internalAccount.address === account.a));
222
- const doFinalListsMatch = doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&
223
- doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;
224
- const context = {
225
- finalUserStorageAccountsList,
226
- finalInternalAccountsList,
227
- };
228
- if (doFinalListsMatch) {
229
- onAccountSyncErroneousSituation?.('Erroneous situations were found during the sync, but final state matches the expected state', context);
153
+ // Both accounts have custom names
154
+ // User storage account has a nameLastUpdatedAt timestamp
155
+ // Note: not storing the undefined checks in constants to act as a type guard
156
+ if (userStorageAccount.nlu !== undefined) {
157
+ if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {
158
+ const isInternalAccountNameNewer = internalAccount.metadata.nameLastUpdatedAt > userStorageAccount.nlu;
159
+ if (isInternalAccountNameNewer) {
160
+ internalAccountsToBeSavedToUserStorage.push(internalAccount);
161
+ continue;
162
+ }
230
163
  }
231
- else {
232
- onAccountSyncErroneousSituation?.('Erroneous situations were found during the sync, and final state does not match the expected state', context);
164
+ getMessenger().call('AccountsController:updateAccountMetadata', internalAccount.id, {
165
+ name: userStorageAccount.n,
166
+ nameLastUpdatedAt: userStorageAccount.nlu,
167
+ });
168
+ const areInternalAndUserStorageAccountNamesEqual = internalAccount.metadata.name === userStorageAccount.n;
169
+ if (!areInternalAndUserStorageAccountNamesEqual) {
170
+ onAccountNameUpdated?.();
233
171
  }
172
+ continue;
173
+ }
174
+ else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {
175
+ internalAccountsToBeSavedToUserStorage.push(internalAccount);
176
+ continue;
234
177
  }
235
178
  }
236
- catch (e) {
237
- // istanbul ignore next
238
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
239
- throw new Error(`UserStorageController - failed to sync user storage accounts list - ${errorMessage}`);
179
+ // Save the internal accounts list to the user storage
180
+ if (internalAccountsToBeSavedToUserStorage.length) {
181
+ await getUserStorageControllerInstance().performBatchSetStorage(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts, internalAccountsToBeSavedToUserStorage.map((account) => [
182
+ account.address,
183
+ JSON.stringify((0, utils_1.mapInternalAccountToUserStorageAccount)(account)),
184
+ ]), entropySourceId);
240
185
  }
241
- finally {
242
- await getUserStorageControllerInstance().setIsAccountSyncingInProgress(false);
186
+ // In case we have corrupted user storage with accounts that don't exist in the internal accounts list
187
+ // Delete those accounts from the user storage
188
+ const userStorageAccountsToBeDeleted = userStorageAccountsList.filter((account) => !refreshedInternalAccountsList.find((a) => a.address === account.a));
189
+ if (userStorageAccountsToBeDeleted.length) {
190
+ await getUserStorageControllerInstance().performBatchDeleteStorage(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts, userStorageAccountsToBeDeleted.map((account) => account.a), entropySourceId);
191
+ erroneousSituationsFound = true;
192
+ onAccountSyncErroneousSituation?.('An account was present in the user storage accounts list but was not found in the internal accounts list after the sync', {
193
+ userStorageAccountsToBeDeleted,
194
+ internalAccountsList,
195
+ refreshedInternalAccountsList,
196
+ internalAccountsToBeSavedToUserStorage,
197
+ userStorageAccountsList,
198
+ });
243
199
  }
244
- };
245
- return trace
246
- ? await trace({ name: 'Account Sync Full' }, performAccountSync)
247
- : await performAccountSync();
200
+ if (erroneousSituationsFound) {
201
+ const [finalUserStorageAccountsList, finalInternalAccountsList] = await Promise.all([
202
+ (0, sync_utils_1.getUserStorageAccountsList)(options, entropySourceId),
203
+ (0, sync_utils_1.getInternalAccountsList)(options, entropySourceId),
204
+ ]);
205
+ const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList = finalInternalAccountsList.every((account) => finalUserStorageAccountsList?.some((userStorageAccount) => userStorageAccount.a === account.address));
206
+ // istanbul ignore next
207
+ const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList = (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd
208
+ ? true
209
+ : finalUserStorageAccountsList?.every((account) => finalInternalAccountsList.some((internalAccount) => internalAccount.address === account.a));
210
+ const doFinalListsMatch = doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&
211
+ doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;
212
+ const context = {
213
+ finalUserStorageAccountsList,
214
+ finalInternalAccountsList,
215
+ };
216
+ if (doFinalListsMatch) {
217
+ onAccountSyncErroneousSituation?.('Erroneous situations were found during the sync, but final state matches the expected state', context);
218
+ }
219
+ else {
220
+ onAccountSyncErroneousSituation?.('Erroneous situations were found during the sync, and final state does not match the expected state', context);
221
+ }
222
+ }
223
+ }
224
+ catch (e) {
225
+ // istanbul ignore next
226
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
227
+ throw new Error(`UserStorageController - failed to sync user storage accounts list - ${errorMessage}`);
228
+ }
229
+ finally {
230
+ await getUserStorageControllerInstance().setIsAccountSyncingInProgress(false);
231
+ }
248
232
  }
249
233
  exports.syncInternalAccountsWithUserStorage = syncInternalAccountsWithUserStorage;
250
234
  //# sourceMappingURL=controller-integration.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAG5D,iDAIsB;AAEtB,uCAGiB;AACjB,uEAA4E;AAE5E;;;;;;GAMG;AACI,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,OAA8B;IAE9B,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO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,CAAC,OAAO,EAAE,EAAE,CAC9C,yBAAyB,CAAC,IAAI,CAC5B,CAAC,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAC3D,CACF,CAAC;gBAER,MAAM,iBAAiB,GACrB,oEAAoE;oBACpE,oEAAoE,CAAC;gBAEvE,MAAM,OAAO,GAAG;oBACd,4BAA4B;oBAC5B,yBAAyB;iBAC1B,CAAC;gBACF,IAAI,iBAAiB,EAAE;oBACrB,+BAA+B,EAAE,CAC/B,6FAA6F,EAC7F,OAAO,CACR,CAAC;iBACH;qBAAM;oBACL,+BAA+B,EAAE,CAC/B,oGAAoG,EACpG,OAAO,CACR,CAAC;iBACH;aACF;SACF;QAAC,OAAO,CAAC,EAAE;YACV,uBAAuB;YACvB,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,IAAI,KAAK,CACb,uEAAuE,YAAY,EAAE,CACtF,CAAC;SACH;gBAAS;YACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;SACH;IACH,CAAC,CAAC;IAEF,OAAO,KAAK;QACV,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,kBAAkB,CAAC;QAChE,CAAC,CAAC,MAAM,kBAAkB,EAAE,CAAC;AACjC,CAAC;AAnSD,kFAmSC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n canPerformAccountSyncing,\n getInternalAccountsList,\n getUserStorageAccountsList,\n} from './sync-utils';\nimport type { AccountSyncingOptions } from './types';\nimport {\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n * @param options - parameters used for saving the internal account\n * @returns Promise that resolves when the account is saved\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { trace } = options;\n\n const saveAccount = async () => {\n const { getUserStorageControllerInstance } = options;\n\n if (\n !canPerformAccountSyncing(options) ||\n internalAccount.metadata.keyring.type !== String(KeyringTypes.hd) // sync only EVM accounts until we support multichain accounts\n ) {\n return;\n }\n\n // properties of `options` are (wrongly?) typed as `Json` and eslint crashes if we try to interpret it as such and call a `?.toString()` on it.\n // but we know this is a string?, so we can safely cast it\n const entropySourceId = internalAccount.options?.entropySource as\n | string\n | undefined;\n\n try {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await getUserStorageControllerInstance().performSetStorage(\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n entropySourceId,\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to save account to user storage - ${errorMessage}`,\n );\n }\n };\n\n return trace\n ? await trace({ name: 'Account Sync Save Individual' }, saveAccount)\n : await saveAccount();\n}\n\n/**\n * Saves the list of internal accounts to the user storage.\n *\n * @param options - parameters used for saving the list of internal accounts\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n * @returns Promise that resolves when all accounts are saved\n */\nexport async function saveInternalAccountsListToUserStorage(\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<void> {\n const { getUserStorageControllerInstance } = options;\n\n const internalAccountsList = await getInternalAccountsList(\n options,\n entropySourceId,\n );\n\n if (!internalAccountsList?.length) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n entropySourceId,\n );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = {\n maxNumberOfAccountsToAdd?: number;\n onAccountAdded?: () => void;\n onAccountNameUpdated?: () => void;\n onAccountSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\n};\n\n/**\n * Syncs the internal accounts list with the user storage accounts list.\n * This method is used to make sure that the internal accounts list is up-to-date with the user storage accounts list and vice-versa.\n * It will add new accounts to the internal accounts list, update/merge conflicting names and re-upload the results in some cases to the user storage.\n *\n * @param config - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param options - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param entropySourceId - The entropy source ID used to derive the key,\n * @returns Promise that resolves when synchronization is complete\n */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<void> {\n const { trace } = options;\n\n const performAccountSync = async () => {\n if (!canPerformAccountSyncing(options)) {\n return;\n }\n\n const {\n maxNumberOfAccountsToAdd = Infinity,\n onAccountAdded,\n onAccountNameUpdated,\n onAccountSyncErroneousSituation,\n } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n try {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n true,\n );\n\n const userStorageAccountsList = await getUserStorageAccountsList(\n options,\n entropySourceId,\n );\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(options, entropySourceId);\n return;\n }\n // Keep a record if erroneous situations are found during the sync\n // This is done so we can send the context to Sentry in case of an erroneous situation\n let erroneousSituationsFound = false;\n\n // Prepare an array of internal accounts to be saved to the user storage\n const internalAccountsToBeSavedToUserStorage: InternalAccount[] = [];\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n const internalAccountsList = await getInternalAccountsList(\n options,\n entropySourceId,\n );\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreUserStorageAccountsThanInternalAccounts =\n userStorageAccountsList.length > internalAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts in user storage than internal accounts\n if (hasMoreUserStorageAccountsThanInternalAccounts) {\n const numberOfAccountsToAdd =\n Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -\n internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n id: entropySourceId,\n },\n async ({ keyring }) => {\n await keyring.addAccounts(numberOfAccountsToAdd);\n },\n );\n\n // TODO: below code is kept for analytics but should probably be re-thought\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n onAccountAdded?.();\n }\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n const refreshedInternalAccountsList = await getInternalAccountsList(\n options,\n entropySourceId,\n );\n\n const newlyAddedAccounts = refreshedInternalAccountsList.filter(\n (account) =>\n !internalAccountsList.find((a) => a.address === account.address),\n );\n\n for (const internalAccount of refreshedInternalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n // If the account is not present in user storage\n // istanbul ignore next\n if (!userStorageAccount) {\n // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account\n if (newlyAddedAccounts.includes(internalAccount)) {\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was added to the internal accounts list but was not present in the user storage accounts list',\n {\n internalAccount,\n userStorageAccount,\n newlyAddedAccounts,\n userStorageAccountsList,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n },\n );\n continue;\n }\n // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // From this point on, we know that the account is present in\n // both the internal accounts list and the user storage accounts list\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n onAccountNameUpdated?.();\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt >\n userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n const areInternalAndUserStorageAccountNamesEqual =\n internalAccount.metadata.name === userStorageAccount.n;\n\n if (!areInternalAndUserStorageAccountNamesEqual) {\n onAccountNameUpdated?.();\n }\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n // Save the internal accounts list to the user storage\n if (internalAccountsToBeSavedToUserStorage.length) {\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n entropySourceId,\n );\n }\n\n // In case we have corrupted user storage with accounts that don't exist in the internal accounts list\n // Delete those accounts from the user storage\n const userStorageAccountsToBeDeleted = userStorageAccountsList.filter(\n (account) =>\n !refreshedInternalAccountsList.find((a) => a.address === account.a),\n );\n\n if (userStorageAccountsToBeDeleted.length) {\n await getUserStorageControllerInstance().performBatchDeleteStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n userStorageAccountsToBeDeleted.map((account) => account.a),\n entropySourceId,\n );\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was present in the user storage accounts list but was not found in the internal accounts list after the sync',\n {\n userStorageAccountsToBeDeleted,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n userStorageAccountsList,\n },\n );\n }\n\n if (erroneousSituationsFound) {\n const [finalUserStorageAccountsList, finalInternalAccountsList] =\n await Promise.all([\n getUserStorageAccountsList(options, entropySourceId),\n getInternalAccountsList(options, entropySourceId),\n ]);\n\n const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList =\n finalInternalAccountsList.every((account) =>\n finalUserStorageAccountsList?.some(\n (userStorageAccount) => userStorageAccount.a === account.address,\n ),\n );\n\n // istanbul ignore next\n const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList =\n (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd\n ? true\n : finalUserStorageAccountsList?.every((account) =>\n finalInternalAccountsList.some(\n (internalAccount) => internalAccount.address === account.a,\n ),\n );\n\n const doFinalListsMatch =\n doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&\n doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;\n\n const context = {\n finalUserStorageAccountsList,\n finalInternalAccountsList,\n };\n if (doFinalListsMatch) {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, but final state matches the expected state',\n context,\n );\n } else {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, and final state does not match the expected state',\n context,\n );\n }\n }\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n false,\n );\n }\n };\n\n return trace\n ? await trace({ name: 'Account Sync Full' }, performAccountSync)\n : await performAccountSync();\n}\n"]}
1
+ {"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAG5D,iDAIsB;AAEtB,uCAGiB;AACjB,uEAA4E;AAE5E;;;;;GAKG;AACI,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,IAAA,qCAAwB,EAAC,OAAO,CAAC;QAClC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,iCAAY,CAAC,EAAE,CAAC,CAAC,8DAA8D;MAChI;QACA,OAAO;KACR;IAED,+IAA+I;IAC/I,0DAA0D;IAC1D,MAAM,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,aAEnC,CAAC;IAEd,IAAI;QACF,8DAA8D;QAC9D,MAAM,aAAa,GACjB,IAAA,8CAAsC,EAAC,eAAe,CAAC,CAAC;QAE1D,MAAM,gCAAgC,EAAE,CAAC,iBAAiB,CACxD,GAAG,2CAA0B,CAAC,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,EACnE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EAC7B,eAAe,CAChB,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;QACvB,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IA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EAAoE,GACxE,CAAC,4BAA4B,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,wBAAwB;gBACpE,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAC9C,yBAAyB,CAAC,IAAI,CAC5B,CAAC,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAC3D,CACF,CAAC;YAER,MAAM,iBAAiB,GACrB,oEAAoE;gBACpE,oEAAoE,CAAC;YAEvE,MAAM,OAAO,GAAG;gBACd,4BAA4B;gBAC5B,yBAAyB;aAC1B,CAAC;YACF,IAAI,iBAAiB,EAAE;gBACrB,+BAA+B,EAAE,CAC/B,6FAA6F,EAC7F,OAAO,CACR,CAAC;aACH;iBAAM;gBACL,+BAA+B,EAAE,CAC/B,oGAAoG,EACpG,OAAO,CACR,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;QACvB,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACxE,MAAM,IAAI,KAAK,CACb,uEAAuE,YAAY,EAAE,CACtF,CAAC;KACH;YAAS;QACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;KACH;AACH,CAAC;AA1RD,kFA0RC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n canPerformAccountSyncing,\n getInternalAccountsList,\n getUserStorageAccountsList,\n} from './sync-utils';\nimport type { AccountSyncingOptions } from './types';\nimport {\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n * @param options - parameters used for saving the internal account\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { getUserStorageControllerInstance } = options;\n\n if (\n !canPerformAccountSyncing(options) ||\n internalAccount.metadata.keyring.type !== String(KeyringTypes.hd) // sync only EVM accounts until we support multichain accounts\n ) {\n return;\n }\n\n // properties of `options` are (wrongly?) typed as `Json` and eslint crashes if we try to interpret it as such and call a `?.toString()` on it.\n // but we know this is a string?, so we can safely cast it\n const entropySourceId = internalAccount.options.entropySource as\n | string\n | undefined;\n\n try {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await getUserStorageControllerInstance().performSetStorage(\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n entropySourceId,\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to save account to user storage - ${errorMessage}`,\n );\n }\n}\n\n/**\n * Saves the list of internal accounts to the user storage.\n *\n * @param options - parameters used for saving the list of internal accounts\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n */\nexport async function saveInternalAccountsListToUserStorage(\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<void> {\n const { getUserStorageControllerInstance } = options;\n\n const internalAccountsList = await getInternalAccountsList(\n options,\n entropySourceId,\n );\n\n if (!internalAccountsList?.length) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n entropySourceId,\n );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = {\n maxNumberOfAccountsToAdd?: number;\n onAccountAdded?: () => void;\n onAccountNameUpdated?: () => void;\n onAccountSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\n};\n\n/**\n * Syncs the internal accounts list with the user storage accounts list.\n * This method is used to make sure that the internal accounts list is up-to-date with the user storage accounts list and vice-versa.\n * It will add new accounts to the internal accounts list, update/merge conflicting names and re-upload the results in some cases to the user storage.\n *\n * @param config - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param options - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param entropySourceId - The entropy source ID used to derive the key,\n */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<void> {\n if (!canPerformAccountSyncing(options)) {\n return;\n }\n\n const {\n maxNumberOfAccountsToAdd = Infinity,\n onAccountAdded,\n onAccountNameUpdated,\n onAccountSyncErroneousSituation,\n } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n try {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n true,\n );\n\n const userStorageAccountsList = await getUserStorageAccountsList(\n options,\n entropySourceId,\n );\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(options, entropySourceId);\n return;\n }\n // Keep a record if erroneous situations are found during the sync\n // This is done so we can send the context to Sentry in case of an erroneous situation\n let erroneousSituationsFound = false;\n\n // Prepare an array of internal accounts to be saved to the user storage\n const internalAccountsToBeSavedToUserStorage: InternalAccount[] = [];\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n const internalAccountsList = await getInternalAccountsList(\n options,\n entropySourceId,\n );\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreUserStorageAccountsThanInternalAccounts =\n userStorageAccountsList.length > internalAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts in user storage than internal accounts\n if (hasMoreUserStorageAccountsThanInternalAccounts) {\n const numberOfAccountsToAdd =\n Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -\n internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n id: entropySourceId,\n },\n async ({ keyring }) => {\n await keyring.addAccounts(numberOfAccountsToAdd);\n },\n );\n\n // TODO: below code is kept for analytics but should probably be re-thought\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n onAccountAdded?.();\n }\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n const refreshedInternalAccountsList = await getInternalAccountsList(\n options,\n entropySourceId,\n );\n\n const newlyAddedAccounts = refreshedInternalAccountsList.filter(\n (account) =>\n !internalAccountsList.find((a) => a.address === account.address),\n );\n\n for (const internalAccount of refreshedInternalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n // If the account is not present in user storage\n // istanbul ignore next\n if (!userStorageAccount) {\n // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account\n if (newlyAddedAccounts.includes(internalAccount)) {\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was added to the internal accounts list but was not present in the user storage accounts list',\n {\n internalAccount,\n userStorageAccount,\n newlyAddedAccounts,\n userStorageAccountsList,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n },\n );\n continue;\n }\n // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // From this point on, we know that the account is present in\n // both the internal accounts list and the user storage accounts list\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n onAccountNameUpdated?.();\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt > userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n const areInternalAndUserStorageAccountNamesEqual =\n internalAccount.metadata.name === userStorageAccount.n;\n\n if (!areInternalAndUserStorageAccountNamesEqual) {\n onAccountNameUpdated?.();\n }\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n // Save the internal accounts list to the user storage\n if (internalAccountsToBeSavedToUserStorage.length) {\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n entropySourceId,\n );\n }\n\n // In case we have corrupted user storage with accounts that don't exist in the internal accounts list\n // Delete those accounts from the user storage\n const userStorageAccountsToBeDeleted = userStorageAccountsList.filter(\n (account) =>\n !refreshedInternalAccountsList.find((a) => a.address === account.a),\n );\n\n if (userStorageAccountsToBeDeleted.length) {\n await getUserStorageControllerInstance().performBatchDeleteStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n userStorageAccountsToBeDeleted.map((account) => account.a),\n entropySourceId,\n );\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was present in the user storage accounts list but was not found in the internal accounts list after the sync',\n {\n userStorageAccountsToBeDeleted,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n userStorageAccountsList,\n },\n );\n }\n\n if (erroneousSituationsFound) {\n const [finalUserStorageAccountsList, finalInternalAccountsList] =\n await Promise.all([\n getUserStorageAccountsList(options, entropySourceId),\n getInternalAccountsList(options, entropySourceId),\n ]);\n\n const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList =\n finalInternalAccountsList.every((account) =>\n finalUserStorageAccountsList?.some(\n (userStorageAccount) => userStorageAccount.a === account.address,\n ),\n );\n\n // istanbul ignore next\n const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList =\n (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd\n ? true\n : finalUserStorageAccountsList?.every((account) =>\n finalInternalAccountsList.some(\n (internalAccount) => internalAccount.address === account.a,\n ),\n );\n\n const doFinalListsMatch =\n doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&\n doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;\n\n const context = {\n finalUserStorageAccountsList,\n finalInternalAccountsList,\n };\n if (doFinalListsMatch) {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, but final state matches the expected state',\n context,\n );\n } else {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, and final state does not match the expected state',\n context,\n );\n }\n }\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n false,\n );\n }\n}\n"]}
@@ -5,7 +5,6 @@ import type { AccountSyncingOptions } from "./types.cjs";
5
5
  *
6
6
  * @param internalAccount - The internal account to save
7
7
  * @param options - parameters used for saving the internal account
8
- * @returns Promise that resolves when the account is saved
9
8
  */
10
9
  export declare function saveInternalAccountToUserStorage(internalAccount: InternalAccount, options: AccountSyncingOptions): Promise<void>;
11
10
  /**
@@ -14,7 +13,6 @@ export declare function saveInternalAccountToUserStorage(internalAccount: Intern
14
13
  * @param options - parameters used for saving the list of internal accounts
15
14
  * @param entropySourceId - The entropy source ID used to derive the key,
16
15
  * when multiple sources are available (Multi-SRP).
17
- * @returns Promise that resolves when all accounts are saved
18
16
  */
19
17
  export declare function saveInternalAccountsListToUserStorage(options: AccountSyncingOptions, entropySourceId: string): Promise<void>;
20
18
  type SyncInternalAccountsWithUserStorageConfig = {
@@ -31,7 +29,6 @@ type SyncInternalAccountsWithUserStorageConfig = {
31
29
  * @param config - parameters used for syncing the internal accounts list with the user storage accounts list
32
30
  * @param options - parameters used for syncing the internal accounts list with the user storage accounts list
33
31
  * @param entropySourceId - The entropy source ID used to derive the key,
34
- * @returns Promise that resolves when synchronization is complete
35
32
  */
36
33
  export declare function syncInternalAccountsWithUserStorage(config: SyncInternalAccountsWithUserStorageConfig, options: AccountSyncingOptions, entropySourceId: string): Promise<void>;
37
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAOrD;;;;;;GAMG;AACH,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAyCf;AAED;;;;;;;GAOG;AACH,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,KAAK,yCAAyC,GAAG;IAC/C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,+BAA+B,CAAC,EAAE,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpC,IAAI,CAAC;CACX,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,mCAAmC,CACvD,MAAM,EAAE,yCAAyC,EACjD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CA+Rf"}
1
+ {"version":3,"file":"controller-integration.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAOrD;;;;;GAKG;AACH,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAiCf;AAED;;;;;;GAMG;AACH,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,KAAK,yCAAyC,GAAG;IAC/C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,+BAA+B,CAAC,EAAE,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpC,IAAI,CAAC;CACX,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,mCAAmC,CACvD,MAAM,EAAE,yCAAyC,EACjD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAsRf"}
@@ -5,7 +5,6 @@ import type { AccountSyncingOptions } from "./types.mjs";
5
5
  *
6
6
  * @param internalAccount - The internal account to save
7
7
  * @param options - parameters used for saving the internal account
8
- * @returns Promise that resolves when the account is saved
9
8
  */
10
9
  export declare function saveInternalAccountToUserStorage(internalAccount: InternalAccount, options: AccountSyncingOptions): Promise<void>;
11
10
  /**
@@ -14,7 +13,6 @@ export declare function saveInternalAccountToUserStorage(internalAccount: Intern
14
13
  * @param options - parameters used for saving the list of internal accounts
15
14
  * @param entropySourceId - The entropy source ID used to derive the key,
16
15
  * when multiple sources are available (Multi-SRP).
17
- * @returns Promise that resolves when all accounts are saved
18
16
  */
19
17
  export declare function saveInternalAccountsListToUserStorage(options: AccountSyncingOptions, entropySourceId: string): Promise<void>;
20
18
  type SyncInternalAccountsWithUserStorageConfig = {
@@ -31,7 +29,6 @@ type SyncInternalAccountsWithUserStorageConfig = {
31
29
  * @param config - parameters used for syncing the internal accounts list with the user storage accounts list
32
30
  * @param options - parameters used for syncing the internal accounts list with the user storage accounts list
33
31
  * @param entropySourceId - The entropy source ID used to derive the key,
34
- * @returns Promise that resolves when synchronization is complete
35
32
  */
36
33
  export declare function syncInternalAccountsWithUserStorage(config: SyncInternalAccountsWithUserStorageConfig, options: AccountSyncingOptions, entropySourceId: string): Promise<void>;
37
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAOrD;;;;;;GAMG;AACH,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAyCf;AAED;;;;;;;GAOG;AACH,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,KAAK,yCAAyC,GAAG;IAC/C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,+BAA+B,CAAC,EAAE,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpC,IAAI,CAAC;CACX,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,mCAAmC,CACvD,MAAM,EAAE,yCAAyC,EACjD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CA+Rf"}
1
+ {"version":3,"file":"controller-integration.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAOrD;;;;;GAKG;AACH,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAiCf;AAED;;;;;;GAMG;AACH,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,KAAK,yCAAyC,GAAG;IAC/C,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,+BAA+B,CAAC,EAAE,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpC,IAAI,CAAC;CACX,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,mCAAmC,CACvD,MAAM,EAAE,yCAAyC,EACjD,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CAsRf"}