@metamask/profile-sync-controller 11.0.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/controllers/authentication/auth-snap-requests.cjs +2 -2
  3. package/dist/controllers/authentication/auth-snap-requests.cjs.map +1 -1
  4. package/dist/controllers/authentication/auth-snap-requests.mjs +2 -2
  5. package/dist/controllers/authentication/auth-snap-requests.mjs.map +1 -1
  6. package/dist/controllers/user-storage/UserStorageController.cjs +28 -32
  7. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  8. package/dist/controllers/user-storage/UserStorageController.d.cts +11 -10
  9. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  10. package/dist/controllers/user-storage/UserStorageController.d.mts +11 -10
  11. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  12. package/dist/controllers/user-storage/UserStorageController.mjs +28 -32
  13. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  14. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +5 -14
  15. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  16. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +4 -6
  17. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  18. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +4 -6
  19. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  20. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +5 -14
  21. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  22. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +11 -8
  23. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -1
  24. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +2 -3
  25. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -1
  26. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +2 -3
  27. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -1
  28. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +11 -8
  29. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -1
  30. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +3 -5
  31. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
  32. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +2 -3
  33. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
  34. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +2 -3
  35. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
  36. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +3 -5
  37. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
  38. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
  39. package/dist/controllers/user-storage/account-syncing/types.d.cts +0 -3
  40. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
  41. package/dist/controllers/user-storage/account-syncing/types.d.mts +0 -3
  42. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
  43. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
  44. package/dist/controllers/user-storage/constants.cjs +8 -0
  45. package/dist/controllers/user-storage/constants.cjs.map +1 -0
  46. package/dist/controllers/user-storage/constants.d.cts +5 -0
  47. package/dist/controllers/user-storage/constants.d.cts.map +1 -0
  48. package/dist/controllers/user-storage/constants.d.mts +5 -0
  49. package/dist/controllers/user-storage/constants.d.mts.map +1 -0
  50. package/dist/controllers/user-storage/constants.mjs +5 -0
  51. package/dist/controllers/user-storage/constants.mjs.map +1 -0
  52. package/dist/controllers/user-storage/index.cjs +1 -0
  53. package/dist/controllers/user-storage/index.cjs.map +1 -1
  54. package/dist/controllers/user-storage/index.d.cts +1 -0
  55. package/dist/controllers/user-storage/index.d.cts.map +1 -1
  56. package/dist/controllers/user-storage/index.d.mts +1 -0
  57. package/dist/controllers/user-storage/index.d.mts.map +1 -1
  58. package/dist/controllers/user-storage/index.mjs +1 -0
  59. package/dist/controllers/user-storage/index.mjs.map +1 -1
  60. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC3B,yBAAqB;AAEtB,OAAO,EACL,wCAAwC,EACxC,wBAAwB,EACxB,sCAAsC,EACvC,oBAAgB;AACjB,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,uBAAuB;QACxB,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;QAC1C,CAAC,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,wCAAwC,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAC3E;QACA,OAAO;KACR;IAED,IAAI;QACF,8DAA8D;QAC9D,MAAM,aAAa,GACjB,sCAAsC,CAAC,eAAe,CAAC,CAAC;QAE1D,MAAM,gCAAgC,EAAE,CAAC,iBAAiB;QACxD,2BAA2B;QAE3B,GAAG,0BAA0B,CAAC,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,EACnE,IAAI,CAAC,SAAS,C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AAC;KACH;YAAS;QACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;KACH;AACH,CAAC","sourcesContent":["import { isEvmAccountType } from '@metamask/keyring-api';\nimport { 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 { AccountSyncingConfig, AccountSyncingOptions } from './types';\nimport {\n isInternalAccountFromPrimarySRPHdKeyring,\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 config - parameters used for saving the internal account\n * @param options - parameters used for saving the internal account\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (\n !isAccountSyncingEnabled ||\n !canPerformAccountSyncing(config, options) ||\n !isEvmAccountType(internalAccount.type) ||\n !(await isInternalAccountFromPrimarySRPHdKeyring(internalAccount, options))\n ) {\n return;\n }\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 // ESLint is confused here.\n\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\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 config - parameters used for saving the list of internal accounts\n * @param options - parameters used for saving the list of internal accounts\n */\nexport async function saveInternalAccountsListToUserStorage(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (!isAccountSyncingEnabled) {\n return;\n }\n\n const internalAccountsList = await getInternalAccountsList(options);\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 );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = AccountSyncingConfig & {\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 */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n\n if (!canPerformAccountSyncing(config, options) || !isAccountSyncingEnabled) {\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(options);\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(\n { isAccountSyncingEnabled },\n options,\n );\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\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(options);\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 // NOTE: we only support the primary SRP HD keyring for now\n // This is why we are hardcoding the index to 0\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\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 =\n await getInternalAccountsList(options);\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 );\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 );\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),\n getInternalAccountsList(options),\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\n // We do this here and not in the finally statement because we want to make sure that\n // the accounts are saved / updated / deleted at least once before we set this flag\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\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"]}
1
+ {"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC3B,yBAAqB;AAEtB,OAAO,EACL,wCAAwC,EACxC,wBAAwB,EACxB,sCAAsC,EACvC,oBAAgB;AACjB,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;QAClC,CAAC,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,wCAAwC,CAAC,e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E,MAAM,IAAI,KAAK,CACb,uEAAuE,YAAY,EAAE,CACtF,CAAC;KACH;YAAS;QACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;KACH;AACH,CAAC","sourcesContent":["import { isEvmAccountType } from '@metamask/keyring-api';\nimport { 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 isInternalAccountFromPrimarySRPHdKeyring,\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 !isEvmAccountType(internalAccount.type) ||\n !(await isInternalAccountFromPrimarySRPHdKeyring(internalAccount, options))\n ) {\n return;\n }\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 // ESLint is confused here.\n\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\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 */\nexport async function saveInternalAccountsListToUserStorage(\n options: AccountSyncingOptions,\n): Promise<void> {\n const { getUserStorageControllerInstance } = options;\n\n const internalAccountsList = await getInternalAccountsList(options);\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 );\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 */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\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(options);\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(options);\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\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(options);\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 // NOTE: we only support the primary SRP HD keyring for now\n // This is why we are hardcoding the index to 0\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\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 =\n await getInternalAccountsList(options);\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 );\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 );\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),\n getInternalAccountsList(options),\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\n // We do this here and not in the finally statement because we want to make sure that\n // the accounts are saved / updated / deleted at least once before we set this flag\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\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"]}
@@ -6,26 +6,29 @@ const sync_utils_1 = require("./sync-utils.cjs");
6
6
  /**
7
7
  * Initialize and setup events to listen to for account syncing
8
8
  *
9
- * @param config - configuration parameters
10
9
  * @param options - parameters used for initializing and enabling account syncing
11
10
  */
12
- function setupAccountSyncingSubscriptions(config, options) {
11
+ function setupAccountSyncingSubscriptions(options) {
13
12
  const { getMessenger, getUserStorageControllerInstance } = options;
14
- getMessenger().subscribe('AccountsController:accountAdded', async (account) => {
15
- if (!(0, sync_utils_1.canPerformAccountSyncing)(config, options) ||
13
+ getMessenger().subscribe('AccountsController:accountAdded',
14
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
15
+ async (account) => {
16
+ if (!(0, sync_utils_1.canPerformAccountSyncing)(options) ||
16
17
  !getUserStorageControllerInstance().state
17
18
  .hasAccountSyncingSyncedAtLeastOnce) {
18
19
  return;
19
20
  }
20
- await (0, controller_integration_1.saveInternalAccountToUserStorage)(account, config, options);
21
+ await (0, controller_integration_1.saveInternalAccountToUserStorage)(account, options);
21
22
  });
22
- getMessenger().subscribe('AccountsController:accountRenamed', async (account) => {
23
- if (!(0, sync_utils_1.canPerformAccountSyncing)(config, options) ||
23
+ getMessenger().subscribe('AccountsController:accountRenamed',
24
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
25
+ async (account) => {
26
+ if (!(0, sync_utils_1.canPerformAccountSyncing)(options) ||
24
27
  !getUserStorageControllerInstance().state
25
28
  .hasAccountSyncingSyncedAtLeastOnce) {
26
29
  return;
27
30
  }
28
- await (0, controller_integration_1.saveInternalAccountToUserStorage)(account, config, options);
31
+ await (0, controller_integration_1.saveInternalAccountToUserStorage)(account, options);
29
32
  });
30
33
  }
31
34
  exports.setupAccountSyncingSubscriptions = setupAccountSyncingSubscriptions;
@@ -1 +1 @@
1
- {"version":3,"file":"setup-subscriptions.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":";;;AAAA,yEAA4E;AAC5E,iDAAwD;AAGxD;;;;;GAKG;AACH,SAAgB,gCAAgC,CAC9C,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC,EAEjC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,IAAA,qCAAwB,EAAC,MAAM,EAAE,OAAO,CAAC;YAC1C,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,IAAA,yDAAgC,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC,EAEnC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,IAAA,qCAAwB,EAAC,MAAM,EAAE,OAAO,CAAC;YAC1C,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,IAAA,yDAAgC,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;AACJ,CAAC;AArCD,4EAqCC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n *\n * @param config - configuration parameters\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n\n async (account) => {\n if (\n !canPerformAccountSyncing(config, options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, config, options);\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n\n async (account) => {\n if (\n !canPerformAccountSyncing(config, options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, config, options);\n },\n );\n}\n"]}
1
+ {"version":3,"file":"setup-subscriptions.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":";;;AAAA,yEAA4E;AAC5E,iDAAwD;AAGxD;;;;GAIG;AACH,SAAgB,gCAAgC,CAC9C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC;IAEjC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,IAAA,qCAAwB,EAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,IAAA,yDAAgC,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC;IAEnC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,IAAA,qCAAwB,EAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,IAAA,yDAAgC,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;AACJ,CAAC;AAtCD,4EAsCC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n *\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, options);\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, options);\n },\n );\n}\n"]}
@@ -1,9 +1,8 @@
1
- import type { AccountSyncingConfig, AccountSyncingOptions } from "./types.cjs";
1
+ import type { AccountSyncingOptions } from "./types.cjs";
2
2
  /**
3
3
  * Initialize and setup events to listen to for account syncing
4
4
  *
5
- * @param config - configuration parameters
6
5
  * @param options - parameters used for initializing and enabling account syncing
7
6
  */
8
- export declare function setupAccountSyncingSubscriptions(config: AccountSyncingConfig, options: AccountSyncingOptions): void;
7
+ export declare function setupAccountSyncingSubscriptions(options: AccountSyncingOptions): void;
9
8
  //# sourceMappingURL=setup-subscriptions.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup-subscriptions.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,oBAAgB;AAE3E;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,QAmC/B"}
1
+ {"version":3,"file":"setup-subscriptions.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,qBAAqB,QAqC/B"}
@@ -1,9 +1,8 @@
1
- import type { AccountSyncingConfig, AccountSyncingOptions } from "./types.mjs";
1
+ import type { AccountSyncingOptions } from "./types.mjs";
2
2
  /**
3
3
  * Initialize and setup events to listen to for account syncing
4
4
  *
5
- * @param config - configuration parameters
6
5
  * @param options - parameters used for initializing and enabling account syncing
7
6
  */
8
- export declare function setupAccountSyncingSubscriptions(config: AccountSyncingConfig, options: AccountSyncingOptions): void;
7
+ export declare function setupAccountSyncingSubscriptions(options: AccountSyncingOptions): void;
9
8
  //# sourceMappingURL=setup-subscriptions.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup-subscriptions.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,oBAAgB;AAE3E;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,QAmC/B"}
1
+ {"version":3,"file":"setup-subscriptions.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,qBAAqB,QAqC/B"}
@@ -3,26 +3,29 @@ import { canPerformAccountSyncing } from "./sync-utils.mjs";
3
3
  /**
4
4
  * Initialize and setup events to listen to for account syncing
5
5
  *
6
- * @param config - configuration parameters
7
6
  * @param options - parameters used for initializing and enabling account syncing
8
7
  */
9
- export function setupAccountSyncingSubscriptions(config, options) {
8
+ export function setupAccountSyncingSubscriptions(options) {
10
9
  const { getMessenger, getUserStorageControllerInstance } = options;
11
- getMessenger().subscribe('AccountsController:accountAdded', async (account) => {
12
- if (!canPerformAccountSyncing(config, options) ||
10
+ getMessenger().subscribe('AccountsController:accountAdded',
11
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
12
+ async (account) => {
13
+ if (!canPerformAccountSyncing(options) ||
13
14
  !getUserStorageControllerInstance().state
14
15
  .hasAccountSyncingSyncedAtLeastOnce) {
15
16
  return;
16
17
  }
17
- await saveInternalAccountToUserStorage(account, config, options);
18
+ await saveInternalAccountToUserStorage(account, options);
18
19
  });
19
- getMessenger().subscribe('AccountsController:accountRenamed', async (account) => {
20
- if (!canPerformAccountSyncing(config, options) ||
20
+ getMessenger().subscribe('AccountsController:accountRenamed',
21
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
22
+ async (account) => {
23
+ if (!canPerformAccountSyncing(options) ||
21
24
  !getUserStorageControllerInstance().state
22
25
  .hasAccountSyncingSyncedAtLeastOnce) {
23
26
  return;
24
27
  }
25
- await saveInternalAccountToUserStorage(account, config, options);
28
+ await saveInternalAccountToUserStorage(account, options);
26
29
  });
27
30
  }
28
31
  //# sourceMappingURL=setup-subscriptions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup-subscriptions.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,qCAAiC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,yBAAqB;AAGxD;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC9C,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC,EAEjC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;YAC1C,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC,EAEnC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;YAC1C,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n *\n * @param config - configuration parameters\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n\n async (account) => {\n if (\n !canPerformAccountSyncing(config, options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, config, options);\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n\n async (account) => {\n if (\n !canPerformAccountSyncing(config, options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, config, options);\n },\n );\n}\n"]}
1
+ {"version":3,"file":"setup-subscriptions.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,qCAAiC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,yBAAqB;AAGxD;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC;IAEjC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC;IAEnC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n *\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, options);\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, options);\n },\n );\n}\n"]}
@@ -6,18 +6,16 @@ const storage_schema_1 = require("../../../shared/storage-schema.cjs");
6
6
  /**
7
7
  * Checks if account syncing can be performed based on a set of conditions
8
8
  *
9
- * @param config - configuration parameters
10
9
  * @param options - parameters used for checking if account syncing can be performed
11
10
  * @returns Returns true if account syncing can be performed, false otherwise.
12
11
  */
13
- function canPerformAccountSyncing(config, options) {
14
- const { isAccountSyncingEnabled } = config;
12
+ function canPerformAccountSyncing(options) {
15
13
  const { getMessenger, getUserStorageControllerInstance } = options;
16
- const { isProfileSyncingEnabled, isAccountSyncingInProgress } = getUserStorageControllerInstance().state;
14
+ const { isProfileSyncingEnabled, isAccountSyncingEnabled, isAccountSyncingInProgress, } = getUserStorageControllerInstance().state;
17
15
  const isAuthEnabled = getMessenger().call('AuthenticationController:isSignedIn');
18
16
  if (!isProfileSyncingEnabled ||
19
- !isAuthEnabled ||
20
17
  !isAccountSyncingEnabled ||
18
+ !isAuthEnabled ||
21
19
  isAccountSyncingInProgress) {
22
20
  return false;
23
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAOA,uCAA2F;AAC3F,uEAA4E;AAE5E;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAvBD,4DAuBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,IAAA,wEAAgE,EAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAdD,0DAcC;AAED;;;;;GAKG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,2CAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC;AAbD,gEAaC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
1
+ {"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAGA,uCAA2F;AAC3F,uEAA4E;AAE5E;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EACJ,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,GAC3B,GAAG,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAxBD,4DAwBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,IAAA,wEAAgE,EAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAdD,0DAcC;AAED;;;;;GAKG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,2CAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC;AAbD,gEAaC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isProfileSyncingEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -1,13 +1,12 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { AccountSyncingConfig, AccountSyncingOptions, UserStorageAccount } from "./types.cjs";
2
+ import type { AccountSyncingOptions, UserStorageAccount } from "./types.cjs";
3
3
  /**
4
4
  * Checks if account syncing can be performed based on a set of conditions
5
5
  *
6
- * @param config - configuration parameters
7
6
  * @param options - parameters used for checking if account syncing can be performed
8
7
  * @returns Returns true if account syncing can be performed, false otherwise.
9
8
  */
10
- export declare function canPerformAccountSyncing(config: AccountSyncingConfig, options: AccountSyncingOptions): boolean;
9
+ export declare function canPerformAccountSyncing(options: AccountSyncingOptions): boolean;
11
10
  /**
12
11
  * Get the list of internal accounts
13
12
  * This function returns only the internal accounts that are from the primary SRP
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
1
+ {"version":3,"file":"sync-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAIzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAsBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
@@ -1,13 +1,12 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { AccountSyncingConfig, AccountSyncingOptions, UserStorageAccount } from "./types.mjs";
2
+ import type { AccountSyncingOptions, UserStorageAccount } from "./types.mjs";
3
3
  /**
4
4
  * Checks if account syncing can be performed based on a set of conditions
5
5
  *
6
- * @param config - configuration parameters
7
6
  * @param options - parameters used for checking if account syncing can be performed
8
7
  * @returns Returns true if account syncing can be performed, false otherwise.
9
8
  */
10
- export declare function canPerformAccountSyncing(config: AccountSyncingConfig, options: AccountSyncingOptions): boolean;
9
+ export declare function canPerformAccountSyncing(options: AccountSyncingOptions): boolean;
11
10
  /**
12
11
  * Get the list of internal accounts
13
12
  * This function returns only the internal accounts that are from the primary SRP
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
1
+ {"version":3,"file":"sync-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAIzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAsBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
@@ -3,18 +3,16 @@ import { USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
3
3
  /**
4
4
  * Checks if account syncing can be performed based on a set of conditions
5
5
  *
6
- * @param config - configuration parameters
7
6
  * @param options - parameters used for checking if account syncing can be performed
8
7
  * @returns Returns true if account syncing can be performed, false otherwise.
9
8
  */
10
- export function canPerformAccountSyncing(config, options) {
11
- const { isAccountSyncingEnabled } = config;
9
+ export function canPerformAccountSyncing(options) {
12
10
  const { getMessenger, getUserStorageControllerInstance } = options;
13
- const { isProfileSyncingEnabled, isAccountSyncingInProgress } = getUserStorageControllerInstance().state;
11
+ const { isProfileSyncingEnabled, isAccountSyncingEnabled, isAccountSyncingInProgress, } = getUserStorageControllerInstance().state;
14
12
  const isAuthEnabled = getMessenger().call('AuthenticationController:isSignedIn');
15
13
  if (!isProfileSyncingEnabled ||
16
- !isAuthEnabled ||
17
14
  !isAccountSyncingEnabled ||
15
+ !isAuthEnabled ||
18
16
  isAccountSyncingInProgress) {
19
17
  return false;
20
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gEAAgE,EAAE,oBAAgB;AAC3F,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,gEAAgE,CAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,0BAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
1
+ {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gEAAgE,EAAE,oBAAgB;AAC3F,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EACJ,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,GAC3B,GAAG,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,gEAAgE,CAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,0BAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isProfileSyncingEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingConfig = {\n isAccountSyncingEnabled: boolean;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -16,9 +16,6 @@ export type UserStorageAccount = {
16
16
  /** the nameLastUpdatedAt timestamp 'nlu' of the account */
17
17
  nlu?: number;
18
18
  };
19
- export type AccountSyncingConfig = {
20
- isAccountSyncingEnabled: boolean;
21
- };
22
19
  export type AccountSyncingOptions = {
23
20
  getUserStorageControllerInstance: () => UserStorageController;
24
21
  getMessenger: () => UserStorageControllerMessenger;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,uBAAuB,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
@@ -16,9 +16,6 @@ export type UserStorageAccount = {
16
16
  /** the nameLastUpdatedAt timestamp 'nlu' of the account */
17
17
  nlu?: number;
18
18
  };
19
- export type AccountSyncingConfig = {
20
- isAccountSyncingEnabled: boolean;
21
- };
22
19
  export type AccountSyncingOptions = {
23
20
  getUserStorageControllerInstance: () => UserStorageController;
24
21
  getMessenger: () => UserStorageControllerMessenger;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,uBAAuB,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingConfig = {\n isAccountSyncingEnabled: boolean;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BACKUPANDSYNC_FEATURES = void 0;
4
+ exports.BACKUPANDSYNC_FEATURES = {
5
+ main: 'main',
6
+ accountSyncing: 'accountSyncing',
7
+ };
8
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IACpC,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,gBAAgB;CACxB,CAAC","sourcesContent":["export const BACKUPANDSYNC_FEATURES = {\n main: 'main',\n accountSyncing: 'accountSyncing',\n} as const;\n"]}
@@ -0,0 +1,5 @@
1
+ export declare const BACKUPANDSYNC_FEATURES: {
2
+ readonly main: "main";
3
+ readonly accountSyncing: "accountSyncing";
4
+ };
5
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;CAGzB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const BACKUPANDSYNC_FEATURES: {
2
+ readonly main: "main";
3
+ readonly accountSyncing: "accountSyncing";
4
+ };
5
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;CAGzB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const BACKUPANDSYNC_FEATURES = {
2
+ main: 'main',
3
+ accountSyncing: 'accountSyncing',
4
+ };
5
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,gBAAgB;CACxB,CAAC","sourcesContent":["export const BACKUPANDSYNC_FEATURES = {\n main: 'main',\n accountSyncing: 'accountSyncing',\n} as const;\n"]}
@@ -36,6 +36,7 @@ const UserStorageController = UserStorageController_1.default;
36
36
  exports.default = UserStorageController;
37
37
  __exportStar(require("./UserStorageController.cjs"), exports);
38
38
  exports.Mocks = __importStar(require("./mocks/index.cjs"));
39
+ __exportStar(require("./constants.cjs"), exports);
39
40
  __exportStar(require("../../shared/encryption/index.cjs"), exports);
40
41
  __exportStar(require("../../shared/storage-schema.cjs"), exports);
41
42
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAiD;AAGxC,qBAHF,+BAAU,CAGE;AADnB,MAAM,qBAAqB,GAAG,+BAAU,CAAC;AAEzC,kBAAe,qBAAqB,CAAC;AACrC,8DAAwC;AACxC,2DAAiC;AACjC,oEAAwC;AACxC,kEAA4C","sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * as Mocks from './mocks';\nexport * from '../../shared/encryption';\nexport * from '../../shared/storage-schema';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAiD;AAGxC,qBAHF,+BAAU,CAGE;AADnB,MAAM,qBAAqB,GAAG,+BAAU,CAAC;AAEzC,kBAAe,qBAAqB,CAAC;AACrC,8DAAwC;AACxC,2DAAiC;AACjC,kDAA4B;AAC5B,oEAAwC;AACxC,kEAA4C","sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * as Mocks from './mocks';\nexport * from './constants';\nexport * from '../../shared/encryption';\nexport * from '../../shared/storage-schema';\n"]}
@@ -4,6 +4,7 @@ export { Controller };
4
4
  export default UserStorageController;
5
5
  export * from "./UserStorageController.cjs";
6
6
  export * as Mocks from "./mocks/index.cjs";
7
+ export * from "./constants.cjs";
7
8
  export * from "../../shared/encryption/index.cjs";
8
9
  export * from "../../shared/storage-schema.cjs";
9
10
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,kDAAwC;AACxC,gDAA4C"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,gCAA4B;AAC5B,kDAAwC;AACxC,gDAA4C"}
@@ -4,6 +4,7 @@ export { Controller };
4
4
  export default UserStorageController;
5
5
  export * from "./UserStorageController.mjs";
6
6
  export * as Mocks from "./mocks/index.mjs";
7
+ export * from "./constants.mjs";
7
8
  export * from "../../shared/encryption/index.mjs";
8
9
  export * from "../../shared/storage-schema.mjs";
9
10
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,kDAAwC;AACxC,gDAA4C"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,gCAA4B;AAC5B,kDAAwC;AACxC,gDAA4C"}
@@ -4,6 +4,7 @@ export { Controller };
4
4
  export default UserStorageController;
5
5
  export * from "./UserStorageController.mjs";
6
6
  export * as Mocks from "./mocks/index.mjs";
7
+ export * from "./constants.mjs";
7
8
  export * from "../../shared/encryption/index.mjs";
8
9
  export * from "../../shared/storage-schema.mjs";
9
10
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,MAAM,qBAAqB,GAAG,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,kDAAwC;AACxC,gDAA4C","sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * as Mocks from './mocks';\nexport * from '../../shared/encryption';\nexport * from '../../shared/storage-schema';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,MAAM,qBAAqB,GAAG,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,gCAA4B;AAC5B,kDAAwC;AACxC,gDAA4C","sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * as Mocks from './mocks';\nexport * from './constants';\nexport * from '../../shared/encryption';\nexport * from '../../shared/storage-schema';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/profile-sync-controller",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -101,7 +101,7 @@
101
101
  },
102
102
  "dependencies": {
103
103
  "@metamask/base-controller": "^8.0.0",
104
- "@metamask/keyring-api": "^17.2.0",
104
+ "@metamask/keyring-api": "^17.4.0",
105
105
  "@metamask/snaps-sdk": "^6.17.1",
106
106
  "@metamask/snaps-utils": "^8.10.0",
107
107
  "@noble/ciphers": "^0.5.2",
@@ -115,9 +115,9 @@
115
115
  "@lavamoat/preinstall-always-fail": "^2.1.0",
116
116
  "@metamask/accounts-controller": "^27.0.0",
117
117
  "@metamask/auto-changelog": "^3.4.4",
118
- "@metamask/keyring-controller": "^21.0.0",
119
- "@metamask/keyring-internal-api": "^6.0.0",
120
- "@metamask/network-controller": "^23.0.0",
118
+ "@metamask/keyring-controller": "^21.0.2",
119
+ "@metamask/keyring-internal-api": "^6.0.1",
120
+ "@metamask/network-controller": "^23.2.0",
121
121
  "@metamask/providers": "^18.1.1",
122
122
  "@metamask/snaps-controllers": "^9.19.0",
123
123
  "@types/jest": "^27.4.1",