@metamask/profile-sync-controller 0.9.2 → 0.9.4

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 (36) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/controllers/user-storage/UserStorageController.cjs +7 -9
  3. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  4. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  5. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  6. package/dist/controllers/user-storage/UserStorageController.mjs +7 -9
  7. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  8. package/dist/controllers/user-storage/accounts/user-storage.cjs +3 -2
  9. package/dist/controllers/user-storage/accounts/user-storage.cjs.map +1 -1
  10. package/dist/controllers/user-storage/accounts/user-storage.d.cts.map +1 -1
  11. package/dist/controllers/user-storage/accounts/user-storage.d.mts.map +1 -1
  12. package/dist/controllers/user-storage/accounts/user-storage.mjs +3 -2
  13. package/dist/controllers/user-storage/accounts/user-storage.mjs.map +1 -1
  14. package/dist/controllers/user-storage/services.cjs +17 -11
  15. package/dist/controllers/user-storage/services.cjs.map +1 -1
  16. package/dist/controllers/user-storage/services.d.cts.map +1 -1
  17. package/dist/controllers/user-storage/services.d.mts.map +1 -1
  18. package/dist/controllers/user-storage/services.mjs +17 -11
  19. package/dist/controllers/user-storage/services.mjs.map +1 -1
  20. package/dist/controllers/user-storage/utils.cjs +1 -27
  21. package/dist/controllers/user-storage/utils.cjs.map +1 -1
  22. package/dist/controllers/user-storage/utils.d.cts +0 -11
  23. package/dist/controllers/user-storage/utils.d.cts.map +1 -1
  24. package/dist/controllers/user-storage/utils.d.mts +0 -11
  25. package/dist/controllers/user-storage/utils.d.mts.map +1 -1
  26. package/dist/controllers/user-storage/utils.mjs +0 -25
  27. package/dist/controllers/user-storage/utils.mjs.map +1 -1
  28. package/dist/shared/encryption/cache.cjs +2 -2
  29. package/dist/shared/encryption/cache.cjs.map +1 -1
  30. package/dist/shared/encryption/cache.mjs +2 -2
  31. package/dist/shared/encryption/cache.mjs.map +1 -1
  32. package/dist/shared/encryption/encryption.cjs +1 -1
  33. package/dist/shared/encryption/encryption.cjs.map +1 -1
  34. package/dist/shared/encryption/encryption.mjs +1 -1
  35. package/dist/shared/encryption/encryption.mjs.map +1 -1
  36. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.4]
11
+
12
+ ### Fixed
13
+
14
+ - Account syncing performance issues and bugs ([#4746](https://github.com/MetaMask/core/pull/4746))
15
+ - Batch `GET` / `PUT` will now encrypt and decrypt sequentially in order to leverage the in-memory cache
16
+ - `nameLastUpdatedAt` will stop being saved to user storage if account name is a default name
17
+ - `waitForExpectedValue` has been removed and will stop waiting for `AccountsController:accountAdded` callback
18
+ - `randomBytes` leftover from sync -> async encryption migration was removed
19
+
20
+ ## [0.9.3]
21
+
22
+ ### Fixed
23
+
24
+ - Only fire `onAccountNameUpdated` when account name has changed ([#4735](https://github.com/MetaMask/core/pull/4735))
25
+
10
26
  ## [0.9.2]
11
27
 
12
28
  ### Changed
@@ -240,7 +256,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
240
256
 
241
257
  - Initial release
242
258
 
243
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.9.2...HEAD
259
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.9.4...HEAD
260
+ [0.9.4]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.9.3...@metamask/profile-sync-controller@0.9.4
261
+ [0.9.3]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.9.2...@metamask/profile-sync-controller@0.9.3
244
262
  [0.9.2]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.9.1...@metamask/profile-sync-controller@0.9.2
245
263
  [0.9.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.9.0...@metamask/profile-sync-controller@0.9.1
246
264
  [0.9.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@0.8.1...@metamask/profile-sync-controller@0.9.0
@@ -21,7 +21,6 @@ const auth_snap_requests_1 = require("../authentication/auth-snap-requests.cjs")
21
21
  const user_storage_1 = require("./accounts/user-storage.cjs");
22
22
  const controller_integration_1 = require("./network-syncing/controller-integration.cjs");
23
23
  const services_1 = require("./services.cjs");
24
- const utils_1 = require("./utils.cjs");
25
24
  const controllerName = 'UserStorageController';
26
25
  exports.defaultState = {
27
26
  isProfileSyncingEnabled: true,
@@ -111,6 +110,7 @@ class UserStorageController extends base_controller_1.BaseController {
111
110
  account.metadata.keyring.type === keyring_controller_1.KeyringTypes.simple);
112
111
  },
113
112
  getInternalAccountsList: async () => {
113
+ // eslint-disable-next-line @typescript-eslint/await-thenable
114
114
  const internalAccountsList = await this.messagingSystem.call('AccountsController:listAccounts');
115
115
  return internalAccountsList?.filter(__classPrivateFieldGet(this, _UserStorageController_accounts, "f").doesInternalAccountHaveCorrectKeyringType);
116
116
  },
@@ -345,20 +345,15 @@ class UserStorageController extends base_controller_1.BaseController {
345
345
  if (!hasMoreInternalAccountsThanUserStorageAccounts) {
346
346
  const numberOfAccountsToAdd = userStorageAccountsList.length - internalAccountsList.length;
347
347
  // Create new accounts to match the user storage accounts list
348
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
349
- for await (const _ of Array.from({
350
- length: numberOfAccountsToAdd,
351
- })) {
352
- const expectedAccountsCountAfterAddition = __classPrivateFieldGet(this, _UserStorageController_accounts, "f").addedAccountsCount + 1;
348
+ for (let i = 0; i < numberOfAccountsToAdd; i++) {
353
349
  await this.messagingSystem.call('KeyringController:addNewAccount');
354
- await (0, utils_1.waitForExpectedValue)(() => __classPrivateFieldGet(this, _UserStorageController_accounts, "f").addedAccountsCount, expectedAccountsCountAfterAddition, 5000);
355
350
  __classPrivateFieldGet(this, _UserStorageController_config, "f")?.accountSyncing?.onAccountAdded?.(profileId);
356
351
  }
357
352
  }
358
353
  // Second step: compare account names
359
354
  // Get the internal accounts list again since new accounts might have been added in the previous step
360
355
  internalAccountsList = await __classPrivateFieldGet(this, _UserStorageController_accounts, "f").getInternalAccountsList();
361
- for await (const internalAccount of internalAccountsList) {
356
+ for (const internalAccount of internalAccountsList) {
362
357
  const userStorageAccount = userStorageAccountsList.find((account) => account.a === internalAccount.address);
363
358
  if (!userStorageAccount) {
364
359
  internalAccountsToBeSavedToUserStorage.push(internalAccount);
@@ -398,7 +393,10 @@ class UserStorageController extends base_controller_1.BaseController {
398
393
  name: userStorageAccount.n,
399
394
  nameLastUpdatedAt: userStorageAccount.nlu,
400
395
  });
401
- __classPrivateFieldGet(this, _UserStorageController_config, "f")?.accountSyncing?.onAccountNameUpdated?.(profileId);
396
+ const areInternalAndUserStorageAccountNamesEqual = internalAccount.metadata.name === userStorageAccount.n;
397
+ if (!areInternalAndUserStorageAccountNamesEqual) {
398
+ __classPrivateFieldGet(this, _UserStorageController_config, "f")?.accountSyncing?.onAccountNameUpdated?.(profileId);
399
+ }
402
400
  continue;
403
401
  }
404
402
  else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"UserStorageController.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAYA,+DAA2D;AAC3D,uDAA+E;AAC/E,qEAMsC;AAItC,kEAA2D;AAO3D,iFAAoF;AASpF,8DAGiC;AACjC,yFAA+E;AAC/E,6CAKoB;AACpB,uCAA+C;AAoC/C,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAclC,QAAA,YAAY,GAA+B;IACtD,uBAAuB,EAAE,IAAI;IAC7B,6BAA6B,EAAE,KAAK;CACrC,CAAC;AAEF,MAAM,QAAQ,GAA8C;IAC1D,uBA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AC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC;kBA5gBkB,qBAAqB","sourcesContent":["import type {\n AccountsControllerListAccountsAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountAddedEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { type InternalAccount, isEvmAccountType } from '@metamask/keyring-api';\nimport {\n type KeyringControllerGetStateAction,\n type KeyringControllerLockEvent,\n type KeyringControllerUnlockEvent,\n type KeyringControllerAddNewAccountAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { NetworkConfiguration } from '@metamask/network-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSHA256Hash } from '../../shared/encryption';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n UserStoragePathWithKeyOnly,\n} from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport type { UserStorageAccount } from './accounts/user-storage';\nimport {\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './accounts/user-storage';\nimport { startNetworkSyncing } from './network-syncing/controller-integration';\nimport {\n batchUpsertUserStorage,\n getUserStorage,\n getUserStorageAllFeatureEntries,\n upsertUserStorage,\n} from './services';\nimport { waitForExpectedValue } from './utils';\n\n// TODO: add external NetworkController event\n// Need to listen for when a network gets added\ntype NetworkControllerNetworkAddedEvent = {\n type: 'NetworkController:networkAdded';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n// TODO: add external NetworkController event\n// Need to listen for when a network is updated, or the default rpc/block explorer changes\ntype NetworkControllerNetworkChangedEvent = {\n type: 'NetworkController:networkChanged';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n// TODO: add external NetworkController event\n// Need to listen for when a network gets deleted\ntype NetworkControllerNetworkDeletedEvent = {\n type: 'NetworkController:networkDeleted';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n};\n\ntype ControllerConfig = {\n accountSyncing?: {\n /**\n * Callback that fires when account sync adds an account.\n * This is used for analytics.\n */\n onAccountAdded?: (profileId: string) => void;\n\n /**\n * Callback that fires when account sync updates the name of an account.\n * This is used for analytics.\n */\n onAccountNameUpdated?: (profileId: string) => void;\n };\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performGetStorageAllFeatureEntries'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n | 'syncInternalAccountsWithUserStorage'\n | 'saveInternalAccountToUserStorage'\n>;\nexport type UserStorageControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | UserStorageControllerGetStateAction;\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformGetStorageAllFeatureEntries =\n ActionsObj['performGetStorageAllFeatureEntries'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\nexport type UserStorageControllerSyncInternalAccountsWithUserStorage =\n ActionsObj['syncInternalAccountsWithUserStorage'];\nexport type UserStorageControllerSaveInternalAccountToUserStorage =\n ActionsObj['saveInternalAccountToUserStorage'];\n\nexport type AllowedActions =\n // Keyring Requests\n | KeyringControllerGetStateAction\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled\n // Account syncing\n | AccountsControllerListAccountsAction\n | AccountsControllerUpdateAccountMetadataAction\n | KeyringControllerAddNewAccountAction;\n\n// Messenger events\nexport type UserStorageControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type UserStorageControllerAccountSyncingInProgress = {\n type: `${typeof controllerName}:accountSyncingInProgress`;\n payload: [boolean];\n};\nexport type UserStorageControllerAccountSyncingComplete = {\n type: `${typeof controllerName}:accountSyncingComplete`;\n payload: [boolean];\n};\nexport type Events =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete;\n\nexport type AllowedEvents =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n // Account Syncing Events\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRenamedEvent\n // Network Syncing Events\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkChangedEvent\n | NetworkControllerNetworkDeletedEvent;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #accounts = {\n // This is replaced with the actual value in the constructor\n // We will remove this once the feature will be released\n isAccountSyncingEnabled: false,\n isAccountSyncingInProgress: false,\n addedAccountsCount: 0,\n canSync: () => {\n try {\n this.#assertProfileSyncingEnabled();\n\n return (\n this.#accounts.isAccountSyncingEnabled && this.#auth.isAuthEnabled()\n );\n } catch {\n return false;\n }\n },\n setupAccountSyncingSubscriptions: () => {\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (this.#accounts.isAccountSyncingInProgress) {\n this.#accounts.addedAccountsCount += 1;\n return;\n }\n\n await this.saveInternalAccountToUserStorage(account);\n },\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountRenamed',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (this.#accounts.isAccountSyncingInProgress) {\n return;\n }\n await this.saveInternalAccountToUserStorage(account);\n },\n );\n },\n doesInternalAccountHaveCorrectKeyringType: (account: InternalAccount) => {\n return (\n account.metadata.keyring.type === KeyringTypes.hd ||\n account.metadata.keyring.type === KeyringTypes.simple\n );\n },\n getInternalAccountsList: async (): Promise<InternalAccount[]> => {\n const internalAccountsList = await this.messagingSystem.call(\n 'AccountsController:listAccounts',\n );\n\n return internalAccountsList?.filter(\n this.#accounts.doesInternalAccountHaveCorrectKeyringType,\n );\n },\n getUserStorageAccountsList: async (): Promise<\n UserStorageAccount[] | null\n > => {\n const rawAccountsListResponse =\n await this.performGetStorageAllFeatureEntries('accounts');\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ??\n null\n );\n },\n saveInternalAccountToUserStorage: async (\n internalAccount: InternalAccount,\n ) => {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await this.performSetStorage(\n `accounts.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n );\n },\n saveInternalAccountsListToUserStorage: async () => {\n const internalAccountsList =\n await this.#accounts.getInternalAccountsList();\n\n if (!internalAccountsList) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage =\n internalAccountsList.map(mapInternalAccountToUserStorageAccount);\n\n await this.performBatchSetStorage(\n 'accounts',\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n );\n },\n };\n\n #config?: ControllerConfig;\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n #nativeScryptCrypto: NativeScrypt | undefined = undefined;\n\n getMetaMetricsState: () => boolean;\n\n constructor({\n messenger,\n state,\n env,\n config,\n getMetaMetricsState,\n nativeScryptCrypto,\n }: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n config?: ControllerConfig;\n env?: {\n isAccountSyncingEnabled?: boolean;\n isNetworkSyncingEnabled?: boolean;\n };\n getMetaMetricsState: () => boolean;\n nativeScryptCrypto?: NativeScrypt;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#config = config;\n\n this.#accounts.isAccountSyncingEnabled = Boolean(\n env?.isAccountSyncingEnabled,\n );\n\n this.getMetaMetricsState = getMetaMetricsState;\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n this.#nativeScryptCrypto = nativeScryptCrypto;\n this.#accounts.setupAccountSyncingSubscriptions();\n\n // Network Syncing\n if (env?.isNetworkSyncingEnabled) {\n startNetworkSyncing({\n messenger,\n getStorageConfig: async () => {\n const { storageKey, bearerToken } =\n await this.#getStorageKeyAndBearerToken();\n return {\n storageKey,\n bearerToken,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n };\n },\n });\n }\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n this.performGetStorageAllFeatureEntries.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:syncInternalAccountsWithUserStorage',\n this.syncInternalAccountsWithUserStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:saveInternalAccountToUserStorage',\n this.saveInternalAccountToUserStorage.bind(this),\n );\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n await this.#auth.signOut();\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows retrieval of all stored data for a specific feature. Data stored is formatted as an array of strings.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns the array of decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Allows storage of multiple user data entries for one specific feature. Data stored must be string formatted.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @param values - data to store, in the form of an array of `[entryKey, entryValue]` pairs\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performBatchSetStorage(\n path: UserStoragePathWithFeatureOnly,\n values: [UserStoragePathWithKeyOnly, string][],\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await batchUpsertUserStorage(values, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\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 async syncInternalAccountsWithUserStorage(): Promise<void> {\n if (!this.#accounts.canSync()) {\n return;\n }\n\n try {\n this.#accounts.isAccountSyncingInProgress = true;\n this.#accounts.addedAccountsCount = 0;\n\n const profileId = await this.#auth.getProfileId();\n\n const userStorageAccountsList =\n await this.#accounts.getUserStorageAccountsList();\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await this.#accounts.saveInternalAccountsListToUserStorage();\n return;\n }\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 let internalAccountsList = await this.#accounts.getInternalAccountsList();\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreInternalAccountsThanUserStorageAccounts =\n internalAccountsList.length > userStorageAccountsList.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 than the internal accounts list\n if (!hasMoreInternalAccountsThanUserStorageAccounts) {\n const numberOfAccountsToAdd =\n userStorageAccountsList.length - internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n for await (const _ of Array.from({\n length: numberOfAccountsToAdd,\n })) {\n const expectedAccountsCountAfterAddition =\n this.#accounts.addedAccountsCount + 1;\n await this.messagingSystem.call('KeyringController:addNewAccount');\n await waitForExpectedValue(\n () => this.#accounts.addedAccountsCount,\n expectedAccountsCountAfterAddition,\n 5000,\n );\n this.#config?.accountSyncing?.onAccountAdded?.(profileId);\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 internalAccountsList = await this.#accounts.getInternalAccountsList();\n\n for await (const internalAccount of internalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n if (!userStorageAccount) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\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 this.messagingSystem.call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n this.#config?.accountSyncing?.onAccountNameUpdated?.(profileId);\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 this.messagingSystem.call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n this.#config?.accountSyncing?.onAccountNameUpdated?.(profileId);\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 await this.performBatchSetStorage(\n 'accounts',\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n this.#accounts.isAccountSyncingInProgress = false;\n }\n }\n\n /**\n * Saves an individual internal account to the user storage.\n * @param internalAccount - The internal account to save\n */\n async saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n ): Promise<void> {\n if (\n !this.#accounts.canSync() ||\n !isEvmAccountType(internalAccount.type) ||\n !this.#accounts.doesInternalAccountHaveCorrectKeyringType(internalAccount)\n ) {\n return;\n }\n\n try {\n await this.#accounts.saveInternalAccountToUserStorage(internalAccount);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to save account to user storage - ${errorMessage}`,\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"UserStorageController.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAYA,+DAA2D;AAC3D,uDAA+E;AAC/E,qEAMsC;AAItC,kEAA2D;AAO3D,iFAAoF;AASpF,8DAGiC;AACjC,yFAA+E;AAC/E,6CAKoB;AAoCpB,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAclC,QAAA,YAAY,GAA+B;IACtD,uBAAuB,EAAE,IAAI;IAC7B,6BAA6B,EAAE,KAAK;CACrC,CAAC;AAEF,MAAM,QAAQ,GAA8C;IAC1D,uBAAuB,EAAE;QACvB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,6BAA6B,EAAE;QAC7B,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAsHF;;;;;;;GAOG;AACH,MAAqB,qBAAsB,SAAQ,gCAIlD;IAwKC,YAAY,EACV,SAAS,EACT,KAAK,EACL,GAAG,EACH,MAAM,EACN,mBAAmB,EACnB,kBAAkB,GAWnB;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ;YACR,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,EAAE,GAAG,oBAAY,EAAE,GAAG,KAAK,EAAE;SACrC,CAAC,CAAC;;QA9LL,sCAAQ;YACN,cAAc,EAAE,KAAK,IAAI,EAAE;gBACzB,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CACpC,yCAAyC,CAC1C,CAAC;YACJ,CAAC;YACD,YAAY,EAAE,KAAK,IAAI,EAAE;gBACvB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CACpD,4CAA4C,CAC7C,CA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AAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,yCAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,iDAA4B,EAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,oDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC,6HAGC,6BAAsC;IAEtC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC;kBA7gBkB,qBAAqB","sourcesContent":["import type {\n AccountsControllerListAccountsAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountAddedEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { type InternalAccount, isEvmAccountType } from '@metamask/keyring-api';\nimport {\n type KeyringControllerGetStateAction,\n type KeyringControllerLockEvent,\n type KeyringControllerUnlockEvent,\n type KeyringControllerAddNewAccountAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { NetworkConfiguration } from '@metamask/network-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSHA256Hash } from '../../shared/encryption';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n UserStoragePathWithKeyOnly,\n} from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport type { UserStorageAccount } from './accounts/user-storage';\nimport {\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './accounts/user-storage';\nimport { startNetworkSyncing } from './network-syncing/controller-integration';\nimport {\n batchUpsertUserStorage,\n getUserStorage,\n getUserStorageAllFeatureEntries,\n upsertUserStorage,\n} from './services';\n\n// TODO: add external NetworkController event\n// Need to listen for when a network gets added\ntype NetworkControllerNetworkAddedEvent = {\n type: 'NetworkController:networkAdded';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n// TODO: add external NetworkController event\n// Need to listen for when a network is updated, or the default rpc/block explorer changes\ntype NetworkControllerNetworkChangedEvent = {\n type: 'NetworkController:networkChanged';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n// TODO: add external NetworkController event\n// Need to listen for when a network gets deleted\ntype NetworkControllerNetworkDeletedEvent = {\n type: 'NetworkController:networkDeleted';\n payload: [networkConfiguration: NetworkConfiguration];\n};\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n};\n\ntype ControllerConfig = {\n accountSyncing?: {\n /**\n * Callback that fires when account sync adds an account.\n * This is used for analytics.\n */\n onAccountAdded?: (profileId: string) => void;\n\n /**\n * Callback that fires when account sync updates the name of an account.\n * This is used for analytics.\n */\n onAccountNameUpdated?: (profileId: string) => void;\n };\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performGetStorageAllFeatureEntries'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n | 'syncInternalAccountsWithUserStorage'\n | 'saveInternalAccountToUserStorage'\n>;\nexport type UserStorageControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | UserStorageControllerGetStateAction;\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformGetStorageAllFeatureEntries =\n ActionsObj['performGetStorageAllFeatureEntries'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\nexport type UserStorageControllerSyncInternalAccountsWithUserStorage =\n ActionsObj['syncInternalAccountsWithUserStorage'];\nexport type UserStorageControllerSaveInternalAccountToUserStorage =\n ActionsObj['saveInternalAccountToUserStorage'];\n\nexport type AllowedActions =\n // Keyring Requests\n | KeyringControllerGetStateAction\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled\n // Account syncing\n | AccountsControllerListAccountsAction\n | AccountsControllerUpdateAccountMetadataAction\n | KeyringControllerAddNewAccountAction;\n\n// Messenger events\nexport type UserStorageControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type UserStorageControllerAccountSyncingInProgress = {\n type: `${typeof controllerName}:accountSyncingInProgress`;\n payload: [boolean];\n};\nexport type UserStorageControllerAccountSyncingComplete = {\n type: `${typeof controllerName}:accountSyncingComplete`;\n payload: [boolean];\n};\nexport type Events =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete;\n\nexport type AllowedEvents =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n // Account Syncing Events\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRenamedEvent\n // Network Syncing Events\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkChangedEvent\n | NetworkControllerNetworkDeletedEvent;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #accounts = {\n // This is replaced with the actual value in the constructor\n // We will remove this once the feature will be released\n isAccountSyncingEnabled: false,\n isAccountSyncingInProgress: false,\n addedAccountsCount: 0,\n canSync: () => {\n try {\n this.#assertProfileSyncingEnabled();\n\n return (\n this.#accounts.isAccountSyncingEnabled && this.#auth.isAuthEnabled()\n );\n } catch {\n return false;\n }\n },\n setupAccountSyncingSubscriptions: () => {\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (this.#accounts.isAccountSyncingInProgress) {\n this.#accounts.addedAccountsCount += 1;\n return;\n }\n\n await this.saveInternalAccountToUserStorage(account);\n },\n );\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountRenamed',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (this.#accounts.isAccountSyncingInProgress) {\n return;\n }\n await this.saveInternalAccountToUserStorage(account);\n },\n );\n },\n doesInternalAccountHaveCorrectKeyringType: (account: InternalAccount) => {\n return (\n account.metadata.keyring.type === KeyringTypes.hd ||\n account.metadata.keyring.type === KeyringTypes.simple\n );\n },\n getInternalAccountsList: async (): Promise<InternalAccount[]> => {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await this.messagingSystem.call(\n 'AccountsController:listAccounts',\n );\n\n return internalAccountsList?.filter(\n this.#accounts.doesInternalAccountHaveCorrectKeyringType,\n );\n },\n getUserStorageAccountsList: async (): Promise<\n UserStorageAccount[] | null\n > => {\n const rawAccountsListResponse =\n await this.performGetStorageAllFeatureEntries('accounts');\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ??\n null\n );\n },\n saveInternalAccountToUserStorage: async (\n internalAccount: InternalAccount,\n ) => {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await this.performSetStorage(\n `accounts.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n );\n },\n saveInternalAccountsListToUserStorage: async () => {\n const internalAccountsList =\n await this.#accounts.getInternalAccountsList();\n\n if (!internalAccountsList) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage =\n internalAccountsList.map(mapInternalAccountToUserStorageAccount);\n\n await this.performBatchSetStorage(\n 'accounts',\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n );\n },\n };\n\n #config?: ControllerConfig;\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n #nativeScryptCrypto: NativeScrypt | undefined = undefined;\n\n getMetaMetricsState: () => boolean;\n\n constructor({\n messenger,\n state,\n env,\n config,\n getMetaMetricsState,\n nativeScryptCrypto,\n }: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n config?: ControllerConfig;\n env?: {\n isAccountSyncingEnabled?: boolean;\n isNetworkSyncingEnabled?: boolean;\n };\n getMetaMetricsState: () => boolean;\n nativeScryptCrypto?: NativeScrypt;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#config = config;\n\n this.#accounts.isAccountSyncingEnabled = Boolean(\n env?.isAccountSyncingEnabled,\n );\n\n this.getMetaMetricsState = getMetaMetricsState;\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n this.#nativeScryptCrypto = nativeScryptCrypto;\n this.#accounts.setupAccountSyncingSubscriptions();\n\n // Network Syncing\n if (env?.isNetworkSyncingEnabled) {\n startNetworkSyncing({\n messenger,\n getStorageConfig: async () => {\n const { storageKey, bearerToken } =\n await this.#getStorageKeyAndBearerToken();\n return {\n storageKey,\n bearerToken,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n };\n },\n });\n }\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n this.performGetStorageAllFeatureEntries.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:syncInternalAccountsWithUserStorage',\n this.syncInternalAccountsWithUserStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:saveInternalAccountToUserStorage',\n this.saveInternalAccountToUserStorage.bind(this),\n );\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n await this.#auth.signOut();\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows retrieval of all stored data for a specific feature. Data stored is formatted as an array of strings.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns the array of decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Allows storage of multiple user data entries for one specific feature. Data stored must be string formatted.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @param values - data to store, in the form of an array of `[entryKey, entryValue]` pairs\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performBatchSetStorage(\n path: UserStoragePathWithFeatureOnly,\n values: [UserStoragePathWithKeyOnly, string][],\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await batchUpsertUserStorage(values, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\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 async syncInternalAccountsWithUserStorage(): Promise<void> {\n if (!this.#accounts.canSync()) {\n return;\n }\n\n try {\n this.#accounts.isAccountSyncingInProgress = true;\n this.#accounts.addedAccountsCount = 0;\n\n const profileId = await this.#auth.getProfileId();\n\n const userStorageAccountsList =\n await this.#accounts.getUserStorageAccountsList();\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await this.#accounts.saveInternalAccountsListToUserStorage();\n return;\n }\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 let internalAccountsList = await this.#accounts.getInternalAccountsList();\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreInternalAccountsThanUserStorageAccounts =\n internalAccountsList.length > userStorageAccountsList.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 than the internal accounts list\n if (!hasMoreInternalAccountsThanUserStorageAccounts) {\n const numberOfAccountsToAdd =\n userStorageAccountsList.length - internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n await this.messagingSystem.call('KeyringController:addNewAccount');\n\n this.#config?.accountSyncing?.onAccountAdded?.(profileId);\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 internalAccountsList = await this.#accounts.getInternalAccountsList();\n\n for (const internalAccount of internalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n if (!userStorageAccount) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\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 this.messagingSystem.call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n this.#config?.accountSyncing?.onAccountNameUpdated?.(profileId);\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 this.messagingSystem.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 this.#config?.accountSyncing?.onAccountNameUpdated?.(profileId);\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 await this.performBatchSetStorage(\n 'accounts',\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n this.#accounts.isAccountSyncingInProgress = false;\n }\n }\n\n /**\n * Saves an individual internal account to the user storage.\n * @param internalAccount - The internal account to save\n */\n async saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n ): Promise<void> {\n if (\n !this.#accounts.canSync() ||\n !isEvmAccountType(internalAccount.type) ||\n !this.#accounts.doesInternalAccountHaveCorrectKeyringType(internalAccount)\n ) {\n return;\n }\n\n try {\n await this.#accounts.saveInternalAccountToUserStorage(internalAccount);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to save account to user storage - ${errorMessage}`,\n );\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"UserStorageController.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,6CAA6C,EAC7C,qCAAqC,EACrC,mCAAmC,EACpC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAoB,8BAA8B;AAC/E,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EACjC,KAAK,oCAAoC,EAE1C,qCAAqC;AACtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAGrE,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,0BAA0B,EAC3B,wCAAoC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAElE,OAAO,KAAK,EACV,sCAAsC,EACtC,yCAAyC,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AuB,CAAC,EAAE,OAAO,CAAC;SACnC,CAAC;QACF,mBAAmB,EAAE,MAAM,OAAO,CAAC;QACnC,kBAAkB,CAAC,EAAE,YAAY,CAAC;KACnC;IAmFY,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBrC,0BAA0B,CACrC,uBAAuB,EAAE,OAAO,GAC/B,OAAO,CAAC,IAAI,CAAC;IAMH,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAoCnD;;;;;;OAMG;IACU,iBAAiB,CAC5B,IAAI,EAAE,gCAAgC,GACrC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBzB;;;;;;OAMG;IACU,kCAAkC,CAC7C,IAAI,EAAE,8BAA8B,GACnC,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAgB3B;;;;;;;OAOG;IACU,iBAAiB,CAC5B,IAAI,EAAE,gCAAgC,EACtC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAchB;;;;;;;OAOG;IACU,sBAAsB,CACjC,IAAI,EAAE,8BAA8B,EACpC,MAAM,EAAE,CAAC,0BAA0B,EAAE,MAAM,CAAC,EAAE,GAC7C,OAAO,CAAC,IAAI,CAAC;IAchB;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAmF7C;;;;OAIG;IACG,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC;IAyJ1D;;;OAGG;IACG,gCAAgC,CACpC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;CAkBjB"}
1
+ {"version":3,"file":"UserStorageController.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,6CAA6C,EAC7C,qCAAqC,EACrC,mCAAmC,EACpC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCA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;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAmF7C;;;;OAIG;IACG,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC;IAqJ1D;;;OAGG;IACG,gCAAgC,CACpC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;CAkBjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"UserStorageController.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,6CAA6C,EAC7C,qCAAqC,EACrC,mCAAmC,EACpC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAoB,8BAA8B;AAC/E,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EACjC,KAAK,oCAAoC,EAE1C,qCAAqC;AACtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAGrE,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,0BAA0B,EAC3B,wCAAoC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAElE,OAAO,KAAK,EACV,sCAAsC,EACtC,yCAAyC,EACzC,kCAAkC,EAClC,qCAAqC,EACrC,sCAAsC,EACvC,uDAAmD;AAiBpD,KAAK,kCAAkC,GAAG;IACxC,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAIF,KAAK,oCAAoC,GAAG;IAC1C,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,CAAC,oBAAoB,EAAE,oBA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nD;;;;;;OAMG;IACU,iBAAiB,CAC5B,IAAI,EAAE,gCAAgC,GACrC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBzB;;;;;;OAMG;IACU,kCAAkC,CAC7C,IAAI,EAAE,8BAA8B,GACnC,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAgB3B;;;;;;;OAOG;IACU,iBAAiB,CAC5B,IAAI,EAAE,gCAAgC,EACtC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAchB;;;;;;;OAOG;IACU,sBAAsB,CACjC,IAAI,EAAE,8BAA8B,EACpC,MAAM,EAAE,CAAC,0BAA0B,EAAE,MAAM,CAAC,EAAE,GAC7C,OAAO,CAAC,IAAI,CAAC;IAchB;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAmF7C;;;;OAIG;IACG,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC;IAyJ1D;;;OAGG;IACG,gCAAgC,CACpC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;CAkBjB"}
1
+ {"version":3,"file":"UserStorageController.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,6CAA6C,EAC7C,qCAAqC,EACrC,mCAAmC,EACpC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAoB,8BAA8B;AAC/E,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EACjC,KAAK,oCAAoC,EAE1C,qCAAqC;AACtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAo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InternalAccountToUserStorageAccount } from "./accounts/user-storage.mjs";
20
20
  import { startNetworkSyncing } from "./network-syncing/controller-integration.mjs";
21
21
  import { batchUpsertUserStorage, getUserStorage, getUserStorageAllFeatureEntries, upsertUserStorage } from "./services.mjs";
22
- import { waitForExpectedValue } from "./utils.mjs";
23
22
  const controllerName = 'UserStorageController';
24
23
  export const defaultState = {
25
24
  isProfileSyncingEnabled: true,
@@ -109,6 +108,7 @@ class UserStorageController extends BaseController {
109
108
  account.metadata.keyring.type === KeyringTypes.simple);
110
109
  },
111
110
  getInternalAccountsList: async () => {
111
+ // eslint-disable-next-line @typescript-eslint/await-thenable
112
112
  const internalAccountsList = await this.messagingSystem.call('AccountsController:listAccounts');
113
113
  return internalAccountsList?.filter(__classPrivateFieldGet(this, _UserStorageController_accounts, "f").doesInternalAccountHaveCorrectKeyringType);
114
114
  },
@@ -343,20 +343,15 @@ class UserStorageController extends BaseController {
343
343
  if (!hasMoreInternalAccountsThanUserStorageAccounts) {
344
344
  const numberOfAccountsToAdd = userStorageAccountsList.length - internalAccountsList.length;
345
345
  // Create new accounts to match the user storage accounts list
346
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
347
- for await (const _ of Array.from({
348
- length: numberOfAccountsToAdd,
349
- })) {
350
- const expectedAccountsCountAfterAddition = __classPrivateFieldGet(this, _UserStorageController_accounts, "f").addedAccountsCount + 1;
346
+ for (let i = 0; i < numberOfAccountsToAdd; i++) {
351
347
  await this.messagingSystem.call('KeyringController:addNewAccount');
352
- await waitForExpectedValue(() => __classPrivateFieldGet(this, _UserStorageController_accounts, "f").addedAccountsCount, expectedAccountsCountAfterAddition, 5000);
353
348
  __classPrivateFieldGet(this, _UserStorageController_config, "f")?.accountSyncing?.onAccountAdded?.(profileId);
354
349
  }
355
350
  }
356
351
  // Second step: compare account names
357
352
  // Get the internal accounts list again since new accounts might have been added in the previous step
358
353
  internalAccountsList = await __classPrivateFieldGet(this, _UserStorageController_accounts, "f").getInternalAccountsList();
359
- for await (const internalAccount of internalAccountsList) {
354
+ for (const internalAccount of internalAccountsList) {
360
355
  const userStorageAccount = userStorageAccountsList.find((account) => account.a === internalAccount.address);
361
356
  if (!userStorageAccount) {
362
357
  internalAccountsToBeSavedToUserStorage.push(internalAccount);
@@ -396,7 +391,10 @@ class UserStorageController extends BaseController {
396
391
  name: userStorageAccount.n,
397
392
  nameLastUpdatedAt: userStorageAccount.nlu,
398
393
  });
399
- __classPrivateFieldGet(this, _UserStorageController_config, "f")?.accountSyncing?.onAccountNameUpdated?.(profileId);
394
+ const areInternalAndUserStorageAccountNamesEqual = internalAccount.metadata.name === userStorageAccount.n;
395
+ if (!areInternalAndUserStorageAccountNamesEqual) {
396
+ __classPrivateFieldGet(this, _UserStorageController_config, "f")?.accountSyncing?.onAccountNameUpdated?.(profileId);
397
+ }
400
398
  continue;
401
399
  }
402
400
  else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {