@metamask-previews/account-tree-controller 0.14.0-preview-0684712d → 0.15.1-preview-1f079244

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.
package/CHANGELOG.md CHANGED
@@ -7,16 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Changed
11
+
12
+ - Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
13
+
14
+ ## [0.15.1]
15
+
16
+ ### Fixed
17
+
18
+ - Check for group existence prior to emitting analytics event in `createMultichainAccountGroup` ([#6582](https://github.com/MetaMask/core/pull/6582))
19
+ - Fix logger initialization ([#6581](https://github.com/MetaMask/core/pull/6581))
20
+ - There was a circular dependency between the controller and the logger itself, preventing the logger to be initialized properly.
21
+
22
+ ## [0.15.0]
23
+
10
24
  ### Added
11
25
 
12
- - Add `AccountWalletObject.status` support ([#6571](https://github.com/MetaMask/core/pull/6571))
26
+ - Add `AccountWalletObject.status` support ([#6571](https://github.com/MetaMask/core/pull/6571)), ([#6578](https://github.com/MetaMask/core/pull/6578))
13
27
  - The `status` field will now report the current wallet status.
14
28
  - Uses `MultichainAccountService` to report on-going operations (discovery, alignment, account creations) for `AccountWalletEntropyObject` multichain account wallet objects.
15
29
 
16
30
  ### Changed
17
31
 
32
+ - **BREAKING:** Bump peer dependency `@metamask/multichain-account-service` from `^0.7.0` to `^0.8.0` ([#6571](https://github.com/MetaMask/core/pull/6571)), ([#6578](https://github.com/MetaMask/core/pull/6578))
18
33
  - **BREAKING:** Bump peer dependency `@metamask/account-api` from `^0.9.0` to `^0.12.0` ([#6560](https://github.com/MetaMask/core/pull/6560))
19
- - Bump dependency `@metamask/multichain-account-service` `^0.7.0` to `^0.8.0` ([#6571](https://github.com/MetaMask/core/pull/6571))
20
34
 
21
35
  ## [0.14.0]
22
36
 
@@ -218,7 +232,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
218
232
  - Initial release ([#5847](https://github.com/MetaMask/core/pull/5847))
219
233
  - Grouping accounts into 3 main categories: Entropy source, Snap ID, keyring types.
220
234
 
221
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.14.0...HEAD
235
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.15.1...HEAD
236
+ [0.15.1]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.15.0...@metamask/account-tree-controller@0.15.1
237
+ [0.15.0]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.14.0...@metamask/account-tree-controller@0.15.0
222
238
  [0.14.0]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.13.1...@metamask/account-tree-controller@0.14.0
223
239
  [0.13.1]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.13.0...@metamask/account-tree-controller@0.13.1
224
240
  [0.13.0]: https://github.com/MetaMask/core/compare/@metamask/account-tree-controller@0.12.1...@metamask/account-tree-controller@0.13.0
@@ -18,15 +18,18 @@ const utils_1 = require("../utils/index.cjs");
18
18
  */
19
19
  const createMultichainAccountGroup = async (context, entropySourceId, groupIndex, profileId, analyticsAction) => {
20
20
  try {
21
+ const didGroupAlreadyExist = (0, utils_1.getLocalGroupForEntropyWallet)(context, entropySourceId, groupIndex);
21
22
  // This will be idempotent so we can create the group even if it already exists
22
23
  await context.messenger.call('MultichainAccountService:createMultichainAccountGroup', {
23
24
  entropySource: entropySourceId,
24
25
  groupIndex,
25
26
  });
26
- context.emitAnalyticsEventFn({
27
- action: analyticsAction,
28
- profileId,
29
- });
27
+ if (!didGroupAlreadyExist) {
28
+ context.emitAnalyticsEventFn({
29
+ action: analyticsAction,
30
+ profileId,
31
+ });
32
+ }
30
33
  }
31
34
  catch (error) {
32
35
  (0, logger_1.backupAndSyncLogger)(`Failed to create group ${groupIndex} for entropy ${entropySourceId}:`,
@@ -1 +1 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+C,EAC/C,oBAAyD,EACzD,eAAuB,EACvB,SAAoB;IAEpB,MAAM,eAAe,GAAG,MAAM,qCAAqC,CACjE,OAAO,EACP,UAAU,EACV,oBAAoB,EACpB,SAAS,CACV,CAAC;IAEF,IAAI,eAAe,EAAE;QACnB,MAAM,IAAA,2CAAsB,EAAC,OAAO,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;KACpE;AACH,CAAC;AAjBD,8CAiBC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,kBAAkB,CACtC,OAA6B,EAC7B,MAAkC,EAClC,qBAAqD,EACrD,eAAuB,EACvB,SAAoB;IAEpB,MAAM,0CAA0C,GAC9C,EAAE,CAAC;IAEL,MAAM,mBAAmB,GAAG,IAAA,sCAA8B,EACxD,OAAO,EACP,MAAM,CAAC,EAAE,CACV,CAAC;IAEF,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,EAAE;QACpD,MAAM,oBAAoB,GAAG,qBAAqB,CAAC,IAAI,CACrD,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,UAAU,KAAK,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CACtE,CAAC;QAEF,MAAM,eAAe,GAAG,MAAM,qCAAqC,CACjE,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,CACV,CAAC;QAEF,uEAAuE;QACvE,IAAI,eAAe,EAAE;YACnB,0CAA0C,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SACrE;KACF;IAED,0DAA0D;IAC1D,IAAI,0CAA0C,CAAC,MAAM,GAAG,CAAC,EAAE;QACzD,MAAM,IAAA,gDAA2B,EAC/B,OAAO,EACP,0CAA0C,EAC1C,eAAe,CAChB,CAAC;KACH;AACH,CAAC;AA1CD,gDA0CC","sourcesContent":["import { compareAndSyncMetadata } from './metadata';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncAnalyticsAction } from '../analytics';\nimport { BackupAndSyncAnalyticsEvent } from '../analytics';\nimport type { ProfileId } from '../authentication';\nimport {\n UserStorageSyncedWalletGroupSchema,\n type BackupAndSyncContext,\n type UserStorageSyncedWalletGroup,\n} from '../types';\nimport {\n pushGroupToUserStorage,\n pushGroupToUserStorageBatch,\n} from '../user-storage/network-operations';\nimport { getLocalGroupsForEntropyWallet } from '../utils';\n\n/**\n * Creates a multichain account group.\n *\n * @param context - The sync context containing controller and messenger.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @param profileId - The profile ID for analytics.\n * @param analyticsAction - The analytics action to log.\n */\nexport const createMultichainAccountGroup = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n profileId: ProfileId,\n analyticsAction: BackupAndSyncAnalyticsAction,\n) => {\n try {\n // This will be idempotent so we can create the group even if it already exists\n await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountGroup',\n {\n entropySource: entropySourceId,\n groupIndex,\n },\n );\n\n context.emitAnalyticsEventFn({\n action: analyticsAction,\n profileId,\n });\n } catch (error) {\n backupAndSyncLogger(\n `Failed to create group ${groupIndex} for entropy ${entropySourceId}:`,\n // istanbul ignore next\n error instanceof Error ? error.message : String(error),\n );\n throw error;\n }\n};\n\n/**\n * Creates local groups from user storage groups.\n *\n * @param context - The sync context containing controller and messenger.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function createLocalGroupsFromUserStorage(\n context: BackupAndSyncContext,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const numberOfAccountGroupsToCreate = Math.max(\n ...groupsFromUserStorage.map((g) => g.groupIndex),\n );\n\n for (\n let groupIndex = 0;\n groupIndex <= numberOfAccountGroupsToCreate;\n groupIndex++\n ) {\n try {\n // Creating multichain account group is idempotent, so we can safely\n // re-create every groups starting from 0.\n await createMultichainAccountGroup(\n context,\n entropySourceId,\n groupIndex,\n profileId,\n BackupAndSyncAnalyticsEvent.GroupAdded,\n );\n } catch {\n // This can happen if the Snap Keyring is not ready yet when invoking\n // `MultichainAccountService:createMultichainAccountGroup`.\n // Since `MultichainAccountService:createMultichainAccountGroup` will at\n // least create the EVM account and the account group before throwing, we can safely\n // ignore this error and continue.\n // Any missing Snap accounts will be added later with alignment.\n continue;\n }\n }\n}\n\n/**\n * Syncs group metadata fields and determines if the group needs to be pushed to user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against.\n * @param profileId - The profile ID for analytics.\n * @returns A promise that resolves to true if the group needs to be pushed to user storage.\n */\nasync function syncGroupMetadataAndCheckIfPushNeeded(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null | undefined,\n profileId: ProfileId,\n): Promise<boolean> {\n const groupPersistedMetadata =\n context.controller.state.accountGroupsMetadata[localGroup.id];\n\n if (!groupFromUserStorage) {\n backupAndSyncLogger(\n `Group ${localGroup.id} did not exist in user storage, pushing to user storage...`,\n );\n\n return true;\n }\n\n // Track if we need to push this group to user storage\n let shouldPushGroup = false;\n\n // Compare and sync name metadata\n const shouldPushForName = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.name,\n userStorageMetadata: groupFromUserStorage.name,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.name.schema.value.is(value),\n applyLocalUpdate: (name: string) => {\n context.controller.setAccountGroupName(localGroup.id, name);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupRenamed,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForName;\n\n // Compare and sync pinned metadata\n const shouldPushForPinned = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.pinned,\n userStorageMetadata: groupFromUserStorage.pinned,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.pinned.schema.value.is(value),\n applyLocalUpdate: (pinned: boolean) => {\n context.controller.setAccountGroupPinned(localGroup.id, pinned);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupPinnedStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForPinned;\n\n // Compare and sync hidden metadata\n const shouldPushForHidden = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.hidden,\n userStorageMetadata: groupFromUserStorage.hidden,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.hidden.schema.value.is(value),\n applyLocalUpdate: (hidden: boolean) => {\n context.controller.setAccountGroupHidden(localGroup.id, hidden);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupHiddenStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForHidden;\n\n return shouldPushGroup;\n}\n\n/**\n * Syncs a single group's metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against (or null if it doesn't exist).\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupMetadata(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null,\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localGroup,\n groupFromUserStorage,\n profileId,\n );\n\n if (shouldPushGroup) {\n await pushGroupToUserStorage(context, localGroup, entropySourceId);\n }\n}\n\n/**\n * Syncs group metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param wallet - The local wallet containing the groups.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupsMetadata(\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const localSyncableGroupsToBePushedToUserStorage: AccountGroupMultichainAccountObject[] =\n [];\n\n const localSyncableGroups = getLocalGroupsForEntropyWallet(\n context,\n wallet.id,\n );\n\n for (const localSyncableGroup of localSyncableGroups) {\n const groupFromUserStorage = groupsFromUserStorage.find(\n (group) =>\n group.groupIndex === localSyncableGroup.metadata.entropy.groupIndex,\n );\n\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localSyncableGroup,\n groupFromUserStorage,\n profileId,\n );\n\n // Add to push list if any metadata needs to be updated in user storage\n if (shouldPushGroup) {\n localSyncableGroupsToBePushedToUserStorage.push(localSyncableGroup);\n }\n }\n\n // Push all groups that need to be updated to user storage\n if (localSyncableGroupsToBePushedToUserStorage.length > 0) {\n await pushGroupToUserStorageBatch(\n context,\n localSyncableGroupsToBePushedToUserStorage,\n entropySourceId,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"group.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/syncing/group.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AAEpD,6CAAmD;AAGnD,sDAA2D;AAE3D,wCAIkB;AAClB,+EAG4C;AAC5C,8CAGkB;AAElB;;;;;;;;GAQG;AACI,MAAM,4BAA4B,GAAG,KAAK,EAC/C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAClB,SAAoB,EACpB,eAA6C,EAC7C,EAAE;IACF,IAAI;QACF,MAAM,oBAAoB,GAAG,IAAA,qCAA6B,EACxD,OAAO,EACP,eAAe,EACf,UAAU,CACX,CAAC;QAEF,+EAA+E;QAC/E,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAC1B,uDAAuD,EACvD;YACE,aAAa,EAAE,eAAe;YAC9B,UAAU;SACX,CACF,CAAC;QAEF,IAAI,CAAC,o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L,MAAM,mBAAmB,GAAG,IAAA,sCAA8B,EACxD,OAAO,EACP,MAAM,CAAC,EAAE,CACV,CAAC;IAEF,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,EAAE;QACpD,MAAM,oBAAoB,GAAG,qBAAqB,CAAC,IAAI,CACrD,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,UAAU,KAAK,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CACtE,CAAC;QAEF,MAAM,eAAe,GAAG,MAAM,qCAAqC,CACjE,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,CACV,CAAC;QAEF,uEAAuE;QACvE,IAAI,eAAe,EAAE;YACnB,0CAA0C,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SACrE;KACF;IAED,0DAA0D;IAC1D,IAAI,0CAA0C,CAAC,MAAM,GAAG,CAAC,EAAE;QACzD,MAAM,IAAA,gDAA2B,EAC/B,OAAO,EACP,0CAA0C,EAC1C,eAAe,CAChB,CAAC;KACH;AACH,CAAC;AA1CD,gDA0CC","sourcesContent":["import { compareAndSyncMetadata } from './metadata';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncAnalyticsAction } from '../analytics';\nimport { BackupAndSyncAnalyticsEvent } from '../analytics';\nimport type { ProfileId } from '../authentication';\nimport {\n UserStorageSyncedWalletGroupSchema,\n type BackupAndSyncContext,\n type UserStorageSyncedWalletGroup,\n} from '../types';\nimport {\n pushGroupToUserStorage,\n pushGroupToUserStorageBatch,\n} from '../user-storage/network-operations';\nimport {\n getLocalGroupForEntropyWallet,\n getLocalGroupsForEntropyWallet,\n} from '../utils';\n\n/**\n * Creates a multichain account group.\n *\n * @param context - The sync context containing controller and messenger.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @param profileId - The profile ID for analytics.\n * @param analyticsAction - The analytics action to log.\n */\nexport const createMultichainAccountGroup = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n profileId: ProfileId,\n analyticsAction: BackupAndSyncAnalyticsAction,\n) => {\n try {\n const didGroupAlreadyExist = getLocalGroupForEntropyWallet(\n context,\n entropySourceId,\n groupIndex,\n );\n\n // This will be idempotent so we can create the group even if it already exists\n await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountGroup',\n {\n entropySource: entropySourceId,\n groupIndex,\n },\n );\n\n if (!didGroupAlreadyExist) {\n context.emitAnalyticsEventFn({\n action: analyticsAction,\n profileId,\n });\n }\n } catch (error) {\n backupAndSyncLogger(\n `Failed to create group ${groupIndex} for entropy ${entropySourceId}:`,\n // istanbul ignore next\n error instanceof Error ? error.message : String(error),\n );\n throw error;\n }\n};\n\n/**\n * Creates local groups from user storage groups.\n *\n * @param context - The sync context containing controller and messenger.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function createLocalGroupsFromUserStorage(\n context: BackupAndSyncContext,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const numberOfAccountGroupsToCreate = Math.max(\n ...groupsFromUserStorage.map((g) => g.groupIndex),\n );\n\n for (\n let groupIndex = 0;\n groupIndex <= numberOfAccountGroupsToCreate;\n groupIndex++\n ) {\n try {\n // Creating multichain account group is idempotent, so we can safely\n // re-create every groups starting from 0.\n await createMultichainAccountGroup(\n context,\n entropySourceId,\n groupIndex,\n profileId,\n BackupAndSyncAnalyticsEvent.GroupAdded,\n );\n } catch {\n // This can happen if the Snap Keyring is not ready yet when invoking\n // `MultichainAccountService:createMultichainAccountGroup`.\n // Since `MultichainAccountService:createMultichainAccountGroup` will at\n // least create the EVM account and the account group before throwing, we can safely\n // ignore this error and continue.\n // Any missing Snap accounts will be added later with alignment.\n continue;\n }\n }\n}\n\n/**\n * Syncs group metadata fields and determines if the group needs to be pushed to user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against.\n * @param profileId - The profile ID for analytics.\n * @returns A promise that resolves to true if the group needs to be pushed to user storage.\n */\nasync function syncGroupMetadataAndCheckIfPushNeeded(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null | undefined,\n profileId: ProfileId,\n): Promise<boolean> {\n const groupPersistedMetadata =\n context.controller.state.accountGroupsMetadata[localGroup.id];\n\n if (!groupFromUserStorage) {\n backupAndSyncLogger(\n `Group ${localGroup.id} did not exist in user storage, pushing to user storage...`,\n );\n\n return true;\n }\n\n // Track if we need to push this group to user storage\n let shouldPushGroup = false;\n\n // Compare and sync name metadata\n const shouldPushForName = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.name,\n userStorageMetadata: groupFromUserStorage.name,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.name.schema.value.is(value),\n applyLocalUpdate: (name: string) => {\n context.controller.setAccountGroupName(localGroup.id, name);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupRenamed,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForName;\n\n // Compare and sync pinned metadata\n const shouldPushForPinned = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.pinned,\n userStorageMetadata: groupFromUserStorage.pinned,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.pinned.schema.value.is(value),\n applyLocalUpdate: (pinned: boolean) => {\n context.controller.setAccountGroupPinned(localGroup.id, pinned);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupPinnedStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForPinned;\n\n // Compare and sync hidden metadata\n const shouldPushForHidden = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.hidden,\n userStorageMetadata: groupFromUserStorage.hidden,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.hidden.schema.value.is(value),\n applyLocalUpdate: (hidden: boolean) => {\n context.controller.setAccountGroupHidden(localGroup.id, hidden);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupHiddenStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForHidden;\n\n return shouldPushGroup;\n}\n\n/**\n * Syncs a single group's metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against (or null if it doesn't exist).\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupMetadata(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null,\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localGroup,\n groupFromUserStorage,\n profileId,\n );\n\n if (shouldPushGroup) {\n await pushGroupToUserStorage(context, localGroup, entropySourceId);\n }\n}\n\n/**\n * Syncs group metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param wallet - The local wallet containing the groups.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupsMetadata(\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const localSyncableGroupsToBePushedToUserStorage: AccountGroupMultichainAccountObject[] =\n [];\n\n const localSyncableGroups = getLocalGroupsForEntropyWallet(\n context,\n wallet.id,\n );\n\n for (const localSyncableGroup of localSyncableGroups) {\n const groupFromUserStorage = groupsFromUserStorage.find(\n (group) =>\n group.groupIndex === localSyncableGroup.metadata.entropy.groupIndex,\n );\n\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localSyncableGroup,\n groupFromUserStorage,\n profileId,\n );\n\n // Add to push list if any metadata needs to be updated in user storage\n if (shouldPushGroup) {\n localSyncableGroupsToBePushedToUserStorage.push(localSyncableGroup);\n }\n }\n\n // Push all groups that need to be updated to user storage\n if (localSyncableGroupsToBePushedToUserStorage.length > 0) {\n await pushGroupToUserStorageBatch(\n context,\n localSyncableGroupsToBePushedToUserStorage,\n entropySourceId,\n );\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.cts","sourceRoot":"","sources":["../../../src/backup-and-sync/syncing/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mCAAmC,EAAE,wBAAoB;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAAqB;AAEjE,OAAO,KAAK,EAAE,SAAS,EAAE,oCAA0B;AACnD,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EAClC,qBAAiB;AAOlB;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,YAC9B,oBAAoB,mBACZ,MAAM,cACX,MAAM,aACP,SAAS,mBACH,4BAA4B,kBAwB9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,4BAA4B,EAAE,EACrD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAwFD;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,mCAAmC,EAC/C,oBAAoB,EAAE,4BAA4B,GAAG,IAAI,EACzD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAA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EAAE,4BAA4B,EAAE,EACrD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAoCf"}
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.mts","sourceRoot":"","sources":["../../../src/backup-and-sync/syncing/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mCAAmC,EAAE,wBAAoB;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAAqB;AAEjE,OAAO,KAAK,EAAE,SAAS,EAAE,oCAA0B;AACnD,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EAClC,qBAAiB;AAOlB;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,YAC9B,oBAAoB,mBACZ,MAAM,cACX,MAAM,aACP,SAAS,mBACH,4BAA4B,kBAwB9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,4BAA4B,EAAE,EACrD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAwFD;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,mCAAmC,EAC/C,oBAAoB,EAAE,4BAA4B,GAAG,IAAI,EACzD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,0BAA0B,EAClC,qBAAqB,EAAE,4BAA4B,EAAE,EACrD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAoCf"}
1
+ {"version":3,"file":"group.d.mts","sourceRoot":"","sources":["../../../src/backup-and-sync/syncing/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mCAAmC,EAAE,wBAAoB;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAAqB;AAEjE,OAAO,KAAK,EAAE,SAAS,EAAE,oCAA0B;AACnD,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EAClC,qBAAiB;AAUlB;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,YAC9B,oBAAoB,mBACZ,MAAM,cACX,MAAM,aACP,SAAS,mBACH,4BAA4B,kBAgC9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,oBAAoB,EAC7B,qBAAqB,EAAE,4BAA4B,EAAE,EACrD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAwFD;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,EAC7B,UAAU,EAAE,mCAAmC,EAC/C,oBAAoB,EAAE,4BAA4B,GAAG,IAAI,EACzD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,0BAA0B,EAClC,qBAAqB,EAAE,4BAA4B,EAAE,EACrD,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAoCf"}
@@ -3,7 +3,7 @@ import { backupAndSyncLogger } from "../../logger.mjs";
3
3
  import { BackupAndSyncAnalyticsEvent } from "../analytics/index.mjs";
4
4
  import { UserStorageSyncedWalletGroupSchema } from "../types.mjs";
5
5
  import { pushGroupToUserStorage, pushGroupToUserStorageBatch } from "../user-storage/network-operations.mjs";
6
- import { getLocalGroupsForEntropyWallet } from "../utils/index.mjs";
6
+ import { getLocalGroupForEntropyWallet, getLocalGroupsForEntropyWallet } from "../utils/index.mjs";
7
7
  /**
8
8
  * Creates a multichain account group.
9
9
  *
@@ -15,15 +15,18 @@ import { getLocalGroupsForEntropyWallet } from "../utils/index.mjs";
15
15
  */
16
16
  export const createMultichainAccountGroup = async (context, entropySourceId, groupIndex, profileId, analyticsAction) => {
17
17
  try {
18
+ const didGroupAlreadyExist = getLocalGroupForEntropyWallet(context, entropySourceId, groupIndex);
18
19
  // This will be idempotent so we can create the group even if it already exists
19
20
  await context.messenger.call('MultichainAccountService:createMultichainAccountGroup', {
20
21
  entropySource: entropySourceId,
21
22
  groupIndex,
22
23
  });
23
- context.emitAnalyticsEventFn({
24
- action: analyticsAction,
25
- profileId,
26
- });
24
+ if (!didGroupAlreadyExist) {
25
+ context.emitAnalyticsEventFn({
26
+ action: analyticsAction,
27
+ profileId,
28
+ });
29
+ }
27
30
  }
28
31
  catch (error) {
29
32
  backupAndSyncLogger(`Failed to create group ${groupIndex} for entropy ${entropySourceId}:`,
@@ -1 +1 @@
1
- {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/syncing/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAmB;AAEpD,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAGnD,OAAO,EAAE,2BAA2B,EAAE,+BAAqB;AAE3D,OAAO,EACL,kCAAkC,EAGnC,qBAAiB;AAClB,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC5B,+CAA2C;AAC5C,OAAO,EAAE,8BAA8B,EAAE,2BAAiB;AAE1D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,EAC/C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAClB,SAAoB,EACpB,eAA6C,EAC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AuB,EACvB,SAAoB;IAEpB,MAAM,0CAA0C,GAC9C,EAAE,CAAC;IAEL,MAAM,mBAAmB,GAAG,8BAA8B,CACxD,OAAO,EACP,MAAM,CAAC,EAAE,CACV,CAAC;IAEF,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,EAAE;QACpD,MAAM,oBAAoB,GAAG,qBAAqB,CAAC,IAAI,CACrD,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,UAAU,KAAK,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CACtE,CAAC;QAEF,MAAM,eAAe,GAAG,MAAM,qCAAqC,CACjE,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,CACV,CAAC;QAEF,uEAAuE;QACvE,IAAI,eAAe,EAAE;YACnB,0CAA0C,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SACrE;KACF;IAED,0DAA0D;IAC1D,IAAI,0CAA0C,CAAC,MAAM,GAAG,CAAC,EAAE;QACzD,MAAM,2BAA2B,CAC/B,OAAO,EACP,0CAA0C,EAC1C,eAAe,CAChB,CAAC;KACH;AACH,CAAC","sourcesContent":["import { compareAndSyncMetadata } from './metadata';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncAnalyticsAction } from '../analytics';\nimport { BackupAndSyncAnalyticsEvent } from '../analytics';\nimport type { ProfileId } from '../authentication';\nimport {\n UserStorageSyncedWalletGroupSchema,\n type BackupAndSyncContext,\n type UserStorageSyncedWalletGroup,\n} from '../types';\nimport {\n pushGroupToUserStorage,\n pushGroupToUserStorageBatch,\n} from '../user-storage/network-operations';\nimport { getLocalGroupsForEntropyWallet } from '../utils';\n\n/**\n * Creates a multichain account group.\n *\n * @param context - The sync context containing controller and messenger.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @param profileId - The profile ID for analytics.\n * @param analyticsAction - The analytics action to log.\n */\nexport const createMultichainAccountGroup = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n profileId: ProfileId,\n analyticsAction: BackupAndSyncAnalyticsAction,\n) => {\n try {\n // This will be idempotent so we can create the group even if it already exists\n await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountGroup',\n {\n entropySource: entropySourceId,\n groupIndex,\n },\n );\n\n context.emitAnalyticsEventFn({\n action: analyticsAction,\n profileId,\n });\n } catch (error) {\n backupAndSyncLogger(\n `Failed to create group ${groupIndex} for entropy ${entropySourceId}:`,\n // istanbul ignore next\n error instanceof Error ? error.message : String(error),\n );\n throw error;\n }\n};\n\n/**\n * Creates local groups from user storage groups.\n *\n * @param context - The sync context containing controller and messenger.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function createLocalGroupsFromUserStorage(\n context: BackupAndSyncContext,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const numberOfAccountGroupsToCreate = Math.max(\n ...groupsFromUserStorage.map((g) => g.groupIndex),\n );\n\n for (\n let groupIndex = 0;\n groupIndex <= numberOfAccountGroupsToCreate;\n groupIndex++\n ) {\n try {\n // Creating multichain account group is idempotent, so we can safely\n // re-create every groups starting from 0.\n await createMultichainAccountGroup(\n context,\n entropySourceId,\n groupIndex,\n profileId,\n BackupAndSyncAnalyticsEvent.GroupAdded,\n );\n } catch {\n // This can happen if the Snap Keyring is not ready yet when invoking\n // `MultichainAccountService:createMultichainAccountGroup`.\n // Since `MultichainAccountService:createMultichainAccountGroup` will at\n // least create the EVM account and the account group before throwing, we can safely\n // ignore this error and continue.\n // Any missing Snap accounts will be added later with alignment.\n continue;\n }\n }\n}\n\n/**\n * Syncs group metadata fields and determines if the group needs to be pushed to user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against.\n * @param profileId - The profile ID for analytics.\n * @returns A promise that resolves to true if the group needs to be pushed to user storage.\n */\nasync function syncGroupMetadataAndCheckIfPushNeeded(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null | undefined,\n profileId: ProfileId,\n): Promise<boolean> {\n const groupPersistedMetadata =\n context.controller.state.accountGroupsMetadata[localGroup.id];\n\n if (!groupFromUserStorage) {\n backupAndSyncLogger(\n `Group ${localGroup.id} did not exist in user storage, pushing to user storage...`,\n );\n\n return true;\n }\n\n // Track if we need to push this group to user storage\n let shouldPushGroup = false;\n\n // Compare and sync name metadata\n const shouldPushForName = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.name,\n userStorageMetadata: groupFromUserStorage.name,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.name.schema.value.is(value),\n applyLocalUpdate: (name: string) => {\n context.controller.setAccountGroupName(localGroup.id, name);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupRenamed,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForName;\n\n // Compare and sync pinned metadata\n const shouldPushForPinned = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.pinned,\n userStorageMetadata: groupFromUserStorage.pinned,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.pinned.schema.value.is(value),\n applyLocalUpdate: (pinned: boolean) => {\n context.controller.setAccountGroupPinned(localGroup.id, pinned);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupPinnedStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForPinned;\n\n // Compare and sync hidden metadata\n const shouldPushForHidden = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.hidden,\n userStorageMetadata: groupFromUserStorage.hidden,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.hidden.schema.value.is(value),\n applyLocalUpdate: (hidden: boolean) => {\n context.controller.setAccountGroupHidden(localGroup.id, hidden);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupHiddenStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForHidden;\n\n return shouldPushGroup;\n}\n\n/**\n * Syncs a single group's metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against (or null if it doesn't exist).\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupMetadata(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null,\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localGroup,\n groupFromUserStorage,\n profileId,\n );\n\n if (shouldPushGroup) {\n await pushGroupToUserStorage(context, localGroup, entropySourceId);\n }\n}\n\n/**\n * Syncs group metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param wallet - The local wallet containing the groups.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupsMetadata(\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const localSyncableGroupsToBePushedToUserStorage: AccountGroupMultichainAccountObject[] =\n [];\n\n const localSyncableGroups = getLocalGroupsForEntropyWallet(\n context,\n wallet.id,\n );\n\n for (const localSyncableGroup of localSyncableGroups) {\n const groupFromUserStorage = groupsFromUserStorage.find(\n (group) =>\n group.groupIndex === localSyncableGroup.metadata.entropy.groupIndex,\n );\n\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localSyncableGroup,\n groupFromUserStorage,\n profileId,\n );\n\n // Add to push list if any metadata needs to be updated in user storage\n if (shouldPushGroup) {\n localSyncableGroupsToBePushedToUserStorage.push(localSyncableGroup);\n }\n }\n\n // Push all groups that need to be updated to user storage\n if (localSyncableGroupsToBePushedToUserStorage.length > 0) {\n await pushGroupToUserStorageBatch(\n context,\n localSyncableGroupsToBePushedToUserStorage,\n entropySourceId,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/syncing/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAmB;AAEpD,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAGnD,OAAO,EAAE,2BAA2B,EAAE,+BAAqB;AAE3D,OAAO,EACL,kCAAkC,EAGnC,qBAAiB;AAClB,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC5B,+CAA2C;AAC5C,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,EAC/B,2BAAiB;AAElB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,EAC/C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAClB,SAAoB,EACpB,eAA6C,EAC7C,EAAE;IACF,IAAI;QACF,MAAM,oBAAoB,GAAG,6BAA6B,CACxD,OAAO,EACP,eAAe,EACf,UAAU,CACX,CAAC;QAEF,+EAA+E;QAC/E,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAC1B,uDAAuD,EACvD;YACE,aAAa,EAAE,eAAe;YAC9B,UAAU;SACX,CACF,CAAC;QAEF,IAAI,CAAC,oBAAoB,EAAE;YACzB,OAAO,CAAC,oBAAoB,CAAC;gBAC3B,MAAM,EAAE,eAAe;gBACvB,SAAS;aACV,CAAC,CAAC;SACJ;KACF;IAAC,OAAO,KAAK,EAAE;QACd,mBAAmB,CACjB,0BAA0B,UAAU,gBAAgB,eAAe,GAAG;QACtE,uBAAuB;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U,CACtE,CAAC;QAEF,MAAM,eAAe,GAAG,MAAM,qCAAqC,CACjE,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,CACV,CAAC;QAEF,uEAAuE;QACvE,IAAI,eAAe,EAAE;YACnB,0CAA0C,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SACrE;KACF;IAED,0DAA0D;IAC1D,IAAI,0CAA0C,CAAC,MAAM,GAAG,CAAC,EAAE;QACzD,MAAM,2BAA2B,CAC/B,OAAO,EACP,0CAA0C,EAC1C,eAAe,CAChB,CAAC;KACH;AACH,CAAC","sourcesContent":["import { compareAndSyncMetadata } from './metadata';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncAnalyticsAction } from '../analytics';\nimport { BackupAndSyncAnalyticsEvent } from '../analytics';\nimport type { ProfileId } from '../authentication';\nimport {\n UserStorageSyncedWalletGroupSchema,\n type BackupAndSyncContext,\n type UserStorageSyncedWalletGroup,\n} from '../types';\nimport {\n pushGroupToUserStorage,\n pushGroupToUserStorageBatch,\n} from '../user-storage/network-operations';\nimport {\n getLocalGroupForEntropyWallet,\n getLocalGroupsForEntropyWallet,\n} from '../utils';\n\n/**\n * Creates a multichain account group.\n *\n * @param context - The sync context containing controller and messenger.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @param profileId - The profile ID for analytics.\n * @param analyticsAction - The analytics action to log.\n */\nexport const createMultichainAccountGroup = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n profileId: ProfileId,\n analyticsAction: BackupAndSyncAnalyticsAction,\n) => {\n try {\n const didGroupAlreadyExist = getLocalGroupForEntropyWallet(\n context,\n entropySourceId,\n groupIndex,\n );\n\n // This will be idempotent so we can create the group even if it already exists\n await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountGroup',\n {\n entropySource: entropySourceId,\n groupIndex,\n },\n );\n\n if (!didGroupAlreadyExist) {\n context.emitAnalyticsEventFn({\n action: analyticsAction,\n profileId,\n });\n }\n } catch (error) {\n backupAndSyncLogger(\n `Failed to create group ${groupIndex} for entropy ${entropySourceId}:`,\n // istanbul ignore next\n error instanceof Error ? error.message : String(error),\n );\n throw error;\n }\n};\n\n/**\n * Creates local groups from user storage groups.\n *\n * @param context - The sync context containing controller and messenger.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function createLocalGroupsFromUserStorage(\n context: BackupAndSyncContext,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const numberOfAccountGroupsToCreate = Math.max(\n ...groupsFromUserStorage.map((g) => g.groupIndex),\n );\n\n for (\n let groupIndex = 0;\n groupIndex <= numberOfAccountGroupsToCreate;\n groupIndex++\n ) {\n try {\n // Creating multichain account group is idempotent, so we can safely\n // re-create every groups starting from 0.\n await createMultichainAccountGroup(\n context,\n entropySourceId,\n groupIndex,\n profileId,\n BackupAndSyncAnalyticsEvent.GroupAdded,\n );\n } catch {\n // This can happen if the Snap Keyring is not ready yet when invoking\n // `MultichainAccountService:createMultichainAccountGroup`.\n // Since `MultichainAccountService:createMultichainAccountGroup` will at\n // least create the EVM account and the account group before throwing, we can safely\n // ignore this error and continue.\n // Any missing Snap accounts will be added later with alignment.\n continue;\n }\n }\n}\n\n/**\n * Syncs group metadata fields and determines if the group needs to be pushed to user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against.\n * @param profileId - The profile ID for analytics.\n * @returns A promise that resolves to true if the group needs to be pushed to user storage.\n */\nasync function syncGroupMetadataAndCheckIfPushNeeded(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null | undefined,\n profileId: ProfileId,\n): Promise<boolean> {\n const groupPersistedMetadata =\n context.controller.state.accountGroupsMetadata[localGroup.id];\n\n if (!groupFromUserStorage) {\n backupAndSyncLogger(\n `Group ${localGroup.id} did not exist in user storage, pushing to user storage...`,\n );\n\n return true;\n }\n\n // Track if we need to push this group to user storage\n let shouldPushGroup = false;\n\n // Compare and sync name metadata\n const shouldPushForName = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.name,\n userStorageMetadata: groupFromUserStorage.name,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.name.schema.value.is(value),\n applyLocalUpdate: (name: string) => {\n context.controller.setAccountGroupName(localGroup.id, name);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupRenamed,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForName;\n\n // Compare and sync pinned metadata\n const shouldPushForPinned = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.pinned,\n userStorageMetadata: groupFromUserStorage.pinned,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.pinned.schema.value.is(value),\n applyLocalUpdate: (pinned: boolean) => {\n context.controller.setAccountGroupPinned(localGroup.id, pinned);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupPinnedStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForPinned;\n\n // Compare and sync hidden metadata\n const shouldPushForHidden = await compareAndSyncMetadata({\n context,\n localMetadata: groupPersistedMetadata?.hidden,\n userStorageMetadata: groupFromUserStorage.hidden,\n validateUserStorageValue: (value) =>\n UserStorageSyncedWalletGroupSchema.schema.hidden.schema.value.is(value),\n applyLocalUpdate: (hidden: boolean) => {\n context.controller.setAccountGroupHidden(localGroup.id, hidden);\n },\n analytics: {\n action: BackupAndSyncAnalyticsEvent.GroupHiddenStatusChanged,\n profileId,\n },\n });\n\n shouldPushGroup ||= shouldPushForHidden;\n\n return shouldPushGroup;\n}\n\n/**\n * Syncs a single group's metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param localGroup - The local group to sync.\n * @param groupFromUserStorage - The group from user storage to compare against (or null if it doesn't exist).\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupMetadata(\n context: BackupAndSyncContext,\n localGroup: AccountGroupMultichainAccountObject,\n groupFromUserStorage: UserStorageSyncedWalletGroup | null,\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localGroup,\n groupFromUserStorage,\n profileId,\n );\n\n if (shouldPushGroup) {\n await pushGroupToUserStorage(context, localGroup, entropySourceId);\n }\n}\n\n/**\n * Syncs group metadata between local and user storage.\n *\n * @param context - The sync context containing controller and messenger.\n * @param wallet - The local wallet containing the groups.\n * @param groupsFromUserStorage - Array of groups from user storage.\n * @param entropySourceId - The entropy source ID.\n * @param profileId - The profile ID for analytics.\n */\nexport async function syncGroupsMetadata(\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n groupsFromUserStorage: UserStorageSyncedWalletGroup[],\n entropySourceId: string,\n profileId: ProfileId,\n): Promise<void> {\n const localSyncableGroupsToBePushedToUserStorage: AccountGroupMultichainAccountObject[] =\n [];\n\n const localSyncableGroups = getLocalGroupsForEntropyWallet(\n context,\n wallet.id,\n );\n\n for (const localSyncableGroup of localSyncableGroups) {\n const groupFromUserStorage = groupsFromUserStorage.find(\n (group) =>\n group.groupIndex === localSyncableGroup.metadata.entropy.groupIndex,\n );\n\n const shouldPushGroup = await syncGroupMetadataAndCheckIfPushNeeded(\n context,\n localSyncableGroup,\n groupFromUserStorage,\n profileId,\n );\n\n // Add to push list if any metadata needs to be updated in user storage\n if (shouldPushGroup) {\n localSyncableGroupsToBePushedToUserStorage.push(localSyncableGroup);\n }\n }\n\n // Push all groups that need to be updated to user storage\n if (localSyncableGroupsToBePushedToUserStorage.length > 0) {\n await pushGroupToUserStorageBatch(\n context,\n localSyncableGroupsToBePushedToUserStorage,\n entropySourceId,\n );\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.restoreStateFromSnapshot = exports.createStateSnapshot = exports.getLocalGroupsForEntropyWallet = exports.getLocalEntropyWallets = void 0;
3
+ exports.restoreStateFromSnapshot = exports.createStateSnapshot = exports.getLocalGroupsForEntropyWallet = exports.getLocalGroupForEntropyWallet = exports.getLocalEntropyWallets = void 0;
4
4
  const account_api_1 = require("@metamask/account-api");
5
5
  const logger_1 = require("../../logger.cjs");
6
6
  /**
@@ -13,6 +13,25 @@ function getLocalEntropyWallets(context) {
13
13
  return Object.values(context.controller.state.accountTree.wallets).filter((wallet) => wallet.type === account_api_1.AccountWalletType.Entropy);
14
14
  }
15
15
  exports.getLocalEntropyWallets = getLocalEntropyWallets;
16
+ /**
17
+ * Gets the local group for a specific entropy wallet by its source ID and group index.
18
+ *
19
+ * @param context - The backup and sync context.
20
+ * @param entropySourceId - The entropy source ID.
21
+ * @param groupIndex - The group index.
22
+ * @returns The local group object if it exists, undefined otherwise.
23
+ */
24
+ const getLocalGroupForEntropyWallet = (context, entropySourceId, groupIndex) => {
25
+ const walletId = (0, account_api_1.toMultichainAccountWalletId)(entropySourceId);
26
+ const wallet = context.controller.state.accountTree.wallets[walletId];
27
+ if (!wallet || wallet.type !== account_api_1.AccountWalletType.Entropy) {
28
+ (0, logger_1.backupAndSyncLogger)(`Wallet ${walletId} not found or is not an entropy wallet`);
29
+ return undefined;
30
+ }
31
+ const groupId = (0, account_api_1.toMultichainAccountGroupId)(walletId, groupIndex);
32
+ return wallet.groups[groupId];
33
+ };
34
+ exports.getLocalGroupForEntropyWallet = getLocalGroupForEntropyWallet;
16
35
  /**
17
36
  * Gets all groups for a specific entropy wallet.
18
37
  *
@@ -1 +1 @@
1
- {"version":3,"file":"controller.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.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UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAC7D;KACF,CAAC;AACJ,CAAC;AAhBD,kDAgBC;AAED;;;;;;;GAOG;AACH,SAAgB,wBAAwB,CACtC,OAA6B,EAC7B,QAAuB;IAEvB,OAAO,CAAC,uBAAuB,CAAC,CAAC,KAAK,EAAE,EAAE;QACxC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QAC7D,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,sBAAsB,CAAC;QAC/D,KAAK,CAAC,WAAW,CAAC,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB,CAAC;QACvE,KAAK,CAAC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC,kBAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mFAAmF;IACnF,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC;AAfD,4DAeC","sourcesContent":["import { AccountWalletType } from '@metamask/account-api';\nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountTreeControllerState } from '../../types';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncContext } from '../types';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n ) as AccountWalletEntropyObject[];\n}\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (!wallet || wallet.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['accountTree']['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup:\n context.controller.state.accountTree.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.accountTree.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
1
+ {"version":3,"file":"controller.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":";;;AAAA,uDAI+B;AAI/B,6CAAmD;AAKnD;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,OAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,+BAAiB,CAAC,OAAO,CACtB,CAAC;AACpC,CAAC;AAND,wDAMC;AAED;;;;;;;GAOG;AACI,MAAM,6BAA6B,GAAG,CAC3C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAC+B,EAAE;IACnD,MAAM,QAAQ,GAAG,IAAA,yCAA2B,EAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEtE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,+BAAiB,CAAC,OAAO,EAAE;QACxD,IAAA,4BAAmB,EACjB,UAAU,QAAQ,wCAAwC,CAC3D,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,IAAA,wCAA0B,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAEjE,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAlBW,QAAA,6BAA6B,iCAkBxC;AAEF;;;;;;GAMG;AACH,SAAgB,8BAA8B,CAC5C,OAA6B,EAC7B,QAAyB;IAEzB,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,C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AAC,OAAO,GAAG,QAAQ,CAAC,kBAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mFAAmF;IACnF,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC;AAfD,4DAeC","sourcesContent":["import {\n AccountWalletType,\n toMultichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountTreeControllerState } from '../../types';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncContext } from '../types';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n ) as AccountWalletEntropyObject[];\n}\n\n/**\n * Gets the local group for a specific entropy wallet by its source ID and group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @returns The local group object if it exists, undefined otherwise.\n */\nexport const getLocalGroupForEntropyWallet = (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): AccountGroupMultichainAccountObject | undefined => {\n const walletId = toMultichainAccountWalletId(entropySourceId);\n const wallet = context.controller.state.accountTree.wallets[walletId];\n\n if (!wallet || wallet.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return undefined;\n }\n\n const groupId = toMultichainAccountGroupId(walletId, groupIndex);\n\n return wallet.groups[groupId];\n};\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (!wallet || wallet.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['accountTree']['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup:\n context.controller.state.accountTree.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.accountTree.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
@@ -10,6 +10,15 @@ import type { BackupAndSyncContext } from "../types.cjs";
10
10
  * @returns Array of entropy wallet objects.
11
11
  */
12
12
  export declare function getLocalEntropyWallets(context: BackupAndSyncContext): AccountWalletEntropyObject[];
13
+ /**
14
+ * Gets the local group for a specific entropy wallet by its source ID and group index.
15
+ *
16
+ * @param context - The backup and sync context.
17
+ * @param entropySourceId - The entropy source ID.
18
+ * @param groupIndex - The group index.
19
+ * @returns The local group object if it exists, undefined otherwise.
20
+ */
21
+ export declare const getLocalGroupForEntropyWallet: (context: BackupAndSyncContext, entropySourceId: string, groupIndex: number) => AccountGroupMultichainAccountObject | undefined;
13
22
  /**
14
23
  * Gets all groups for a specific entropy wallet.
15
24
  *
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.cts","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,KAAK,EAAE,mCAAmC,EAAE,wBAAoB;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,wBAAoB;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAiB;AAErD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,oBAAoB,GAC5B,0BAA0B,EAAE,CAI9B;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,eAAe,GACxB,mCAAmC,EAAE,CAUvC;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,qBAAqB,EAAE,0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C,wBAAwB,CAAC,CAAC;IAC7E,oBAAoB,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC,sBAAsB,CAAC,CAAC;IACxF,kBAAkB,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC;CAC1E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAcf;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,aAAa,GACtB,IAAI,CAYN"}
@@ -10,6 +10,15 @@ import type { BackupAndSyncContext } from "../types.mjs";
10
10
  * @returns Array of entropy wallet objects.
11
11
  */
12
12
  export declare function getLocalEntropyWallets(context: BackupAndSyncContext): AccountWalletEntropyObject[];
13
+ /**
14
+ * Gets the local group for a specific entropy wallet by its source ID and group index.
15
+ *
16
+ * @param context - The backup and sync context.
17
+ * @param entropySourceId - The entropy source ID.
18
+ * @param groupIndex - The group index.
19
+ * @returns The local group object if it exists, undefined otherwise.
20
+ */
21
+ export declare const getLocalGroupForEntropyWallet: (context: BackupAndSyncContext, entropySourceId: string, groupIndex: number) => AccountGroupMultichainAccountObject | undefined;
13
22
  /**
14
23
  * Gets all groups for a specific entropy wallet.
15
24
  *
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.mts","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,KAAK,EAAE,mCAAmC,EAAE,wBAAoB;AAEvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,wBAAoB;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAqB;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAiB;AAErD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,oBAAoB,GAC5B,0BA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O,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,eAAe,GACxB,mCAAmC,EAAE,CAUvC;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,qBAAqB,EAAE,0BAA0B,CAAC,uBAAuB,CAAC,CAAC;IAC3E,sBAAsB,EAAE,0BAA0B,CAAC,wBAAwB,CAAC,CAAC;IAC7E,oBAAoB,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC,sBAAsB,CAAC,CAAC;IACxF,kBAAkB,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC;CAC1E,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAcf;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,aAAa,GACtB,IAAI,CAYN"}
@@ -1,4 +1,4 @@
1
- import { AccountWalletType } from "@metamask/account-api";
1
+ import { AccountWalletType, toMultichainAccountGroupId, toMultichainAccountWalletId } from "@metamask/account-api";
2
2
  import { backupAndSyncLogger } from "../../logger.mjs";
3
3
  /**
4
4
  * Gets all local entropy wallets that can be synced.
@@ -9,6 +9,24 @@ import { backupAndSyncLogger } from "../../logger.mjs";
9
9
  export function getLocalEntropyWallets(context) {
10
10
  return Object.values(context.controller.state.accountTree.wallets).filter((wallet) => wallet.type === AccountWalletType.Entropy);
11
11
  }
12
+ /**
13
+ * Gets the local group for a specific entropy wallet by its source ID and group index.
14
+ *
15
+ * @param context - The backup and sync context.
16
+ * @param entropySourceId - The entropy source ID.
17
+ * @param groupIndex - The group index.
18
+ * @returns The local group object if it exists, undefined otherwise.
19
+ */
20
+ export const getLocalGroupForEntropyWallet = (context, entropySourceId, groupIndex) => {
21
+ const walletId = toMultichainAccountWalletId(entropySourceId);
22
+ const wallet = context.controller.state.accountTree.wallets[walletId];
23
+ if (!wallet || wallet.type !== AccountWalletType.Entropy) {
24
+ backupAndSyncLogger(`Wallet ${walletId} not found or is not an entropy wallet`);
25
+ return undefined;
26
+ }
27
+ const groupId = toMultichainAccountGroupId(walletId, groupIndex);
28
+ return wallet.groups[groupId];
29
+ };
12
30
  /**
13
31
  * Gets all groups for a specific entropy wallet.
14
32
  *
@@ -1 +1 @@
1
- {"version":3,"file":"controller.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAI1D,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAKnD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,OAAO,CACtB,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA6B,EAC7B,QAAyB;IAEzB,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,OAAO,EAAE;QACxD,mBAAmB,CACjB,UAAU,QAAQ,wCAAwC,CAC3D,CAAC;QACF,OAAO,EAAE,CAAC;KACX;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAaD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,OAAO;QACL,qBAAqB,EAAE,IAAI,CAAC,KAAK,CAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAC/D;QACD,sBAAsB,EAAE,IAAI,CAAC,KAAK,CAChC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAChE;QACD,oBAAoB,EAClB,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,oBAAoB;QAC3D,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAC5B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAC7D;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA6B,EAC7B,QAAuB;IAEvB,OAAO,CAAC,uBAAuB,CAAC,CAAC,KAAK,EAAE,EAAE;QACxC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QAC7D,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,sBAAsB,CAAC;QAC/D,KAAK,CAAC,WAAW,CAAC,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB,CAAC;QACvE,KAAK,CAAC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC,kBAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mFAAmF;IACnF,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import { AccountWalletType } from '@metamask/account-api';\nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountTreeControllerState } from '../../types';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncContext } from '../types';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n ) as AccountWalletEntropyObject[];\n}\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (!wallet || wallet.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['accountTree']['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup:\n context.controller.state.accountTree.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.accountTree.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
1
+ {"version":3,"file":"controller.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,2BAA2B,EAC5B,8BAA8B;AAI/B,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAKnD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,OAAO,CACtB,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,OAA6B,EAC7B,eAAuB,EACvB,UAAkB,EAC+B,EAAE;IACnD,MAAM,QAAQ,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEtE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,OAAO,EAAE;QACxD,mBAAmB,CACj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OAA6B,EAC7B,QAAuB;IAEvB,OAAO,CAAC,uBAAuB,CAAC,CAAC,KAAK,EAAE,EAAE;QACxC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QAC7D,KAAK,CAAC,sBAAsB,GAAG,QAAQ,CAAC,sBAAsB,CAAC;QAC/D,KAAK,CAAC,WAAW,CAAC,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB,CAAC;QACvE,KAAK,CAAC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC,kBAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,+EAA+E;IAC/E,mFAAmF;IACnF,sEAAsE;IACtE,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import {\n AccountWalletType,\n toMultichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountTreeControllerState } from '../../types';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type { BackupAndSyncContext } from '../types';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n ) as AccountWalletEntropyObject[];\n}\n\n/**\n * Gets the local group for a specific entropy wallet by its source ID and group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @returns The local group object if it exists, undefined otherwise.\n */\nexport const getLocalGroupForEntropyWallet = (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): AccountGroupMultichainAccountObject | undefined => {\n const walletId = toMultichainAccountWalletId(entropySourceId);\n const wallet = context.controller.state.accountTree.wallets[walletId];\n\n if (!wallet || wallet.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return undefined;\n }\n\n const groupId = toMultichainAccountGroupId(walletId, groupIndex);\n\n return wallet.groups[groupId];\n};\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (!wallet || wallet.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['accountTree']['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup:\n context.controller.state.accountTree.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.accountTree.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
package/dist/logger.cjs CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.backupAndSyncLogger = exports.projectLogger = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
- const AccountTreeController_1 = require("./AccountTreeController.cjs");
6
- exports.projectLogger = (0, utils_1.createProjectLogger)(AccountTreeController_1.controllerName);
5
+ exports.projectLogger = (0, utils_1.createProjectLogger)('account-tree-controller');
7
6
  exports.backupAndSyncLogger = (0, utils_1.createModuleLogger)(exports.projectLogger, 'Backup and sync');
8
7
  //# sourceMappingURL=logger.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.cjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAA0E;AAE1E,uEAAyD;AAE5C,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,sCAAc,CAAC,CAAC;AACpD,QAAA,mBAAmB,GAAG,IAAA,0BAAkB,EACnD,qBAAa,EACb,iBAAiB,CAClB,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nimport { controllerName } from './AccountTreeController';\n\nexport const projectLogger = createProjectLogger(controllerName);\nexport const backupAndSyncLogger = createModuleLogger(\n projectLogger,\n 'Backup and sync',\n);\n"]}
1
+ {"version":3,"file":"logger.cjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAA0E;AAE7D,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,yBAAyB,CAAC,CAAC;AAC/D,QAAA,mBAAmB,GAAG,IAAA,0BAAkB,EACnD,qBAAa,EACb,iBAAiB,CAClB,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('account-tree-controller');\nexport const backupAndSyncLogger = createModuleLogger(\n projectLogger,\n 'Backup and sync',\n);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAIA,eAAO,MAAM,aAAa,0BAAsC,CAAC;AACjE,eAAO,MAAM,mBAAmB,0BAG/B,CAAC"}
1
+ {"version":3,"file":"logger.d.cts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,aAAa,0BAAiD,CAAC;AAC5E,eAAO,MAAM,mBAAmB,0BAG/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAIA,eAAO,MAAM,aAAa,0BAAsC,CAAC;AACjE,eAAO,MAAM,mBAAmB,0BAG/B,CAAC"}
1
+ {"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,aAAa,0BAAiD,CAAC;AAC5E,eAAO,MAAM,mBAAmB,0BAG/B,CAAC"}
package/dist/logger.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { createProjectLogger, createModuleLogger } from "@metamask/utils";
2
- import { controllerName } from "./AccountTreeController.mjs";
3
- export const projectLogger = createProjectLogger(controllerName);
2
+ export const projectLogger = createProjectLogger('account-tree-controller');
4
3
  export const backupAndSyncLogger = createModuleLogger(projectLogger, 'Backup and sync');
5
4
  //# sourceMappingURL=logger.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAE1E,OAAO,EAAE,cAAc,EAAE,oCAAgC;AAEzD,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CACnD,aAAa,EACb,iBAAiB,CAClB,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nimport { controllerName } from './AccountTreeController';\n\nexport const projectLogger = createProjectLogger(controllerName);\nexport const backupAndSyncLogger = createModuleLogger(\n projectLogger,\n 'Backup and sync',\n);\n"]}
1
+ {"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CACnD,aAAa,EACb,iBAAiB,CAClB,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('account-tree-controller');\nexport const backupAndSyncLogger = createModuleLogger(\n projectLogger,\n 'Backup and sync',\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/account-tree-controller",
3
- "version": "0.14.0-preview-0684712d",
3
+ "version": "0.15.1-preview-1f079244",
4
4
  "description": "Controller to group account together based on some pre-defined rules",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -51,7 +51,7 @@
51
51
  "@metamask/snaps-sdk": "^9.0.0",
52
52
  "@metamask/snaps-utils": "^11.0.0",
53
53
  "@metamask/superstruct": "^3.1.0",
54
- "@metamask/utils": "^11.4.2",
54
+ "@metamask/utils": "^11.8.0",
55
55
  "fast-deep-equal": "^3.1.3",
56
56
  "lodash": "^4.17.21"
57
57
  },
@@ -60,7 +60,7 @@
60
60
  "@metamask/accounts-controller": "^33.1.0",
61
61
  "@metamask/auto-changelog": "^3.4.4",
62
62
  "@metamask/keyring-api": "^21.0.0",
63
- "@metamask/keyring-controller": "^23.0.0",
63
+ "@metamask/keyring-controller": "^23.1.0",
64
64
  "@metamask/multichain-account-service": "^0.8.0",
65
65
  "@metamask/profile-sync-controller": "^25.0.0",
66
66
  "@metamask/providers": "^22.1.0",
@@ -78,7 +78,7 @@
78
78
  "@metamask/account-api": "^0.12.0",
79
79
  "@metamask/accounts-controller": "^33.0.0",
80
80
  "@metamask/keyring-controller": "^23.0.0",
81
- "@metamask/multichain-account-service": "^0.7.0",
81
+ "@metamask/multichain-account-service": "^0.8.0",
82
82
  "@metamask/profile-sync-controller": "^25.0.0",
83
83
  "@metamask/providers": "^22.0.0",
84
84
  "@metamask/snaps-controllers": "^14.0.0",