@metamask-previews/account-tree-controller 2.0.0-preview-ee982ebe → 2.0.0-preview-7f5161b8
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/dist/AccountTreeController.cjs +3 -3
- package/dist/AccountTreeController.cjs.map +1 -1
- package/dist/AccountTreeController.mjs +3 -3
- package/dist/AccountTreeController.mjs.map +1 -1
- package/dist/backup-and-sync/analytics/traces.cjs.map +1 -1
- package/dist/backup-and-sync/analytics/traces.mjs.map +1 -1
- package/dist/backup-and-sync/authentication/utils.cjs.map +1 -1
- package/dist/backup-and-sync/authentication/utils.mjs.map +1 -1
- package/dist/backup-and-sync/service/atomic-sync-queue.cjs.map +1 -1
- package/dist/backup-and-sync/service/atomic-sync-queue.mjs.map +1 -1
- package/dist/backup-and-sync/service/index.cjs.map +1 -1
- package/dist/backup-and-sync/service/index.mjs.map +1 -1
- package/dist/backup-and-sync/syncing/group.cjs.map +1 -1
- package/dist/backup-and-sync/syncing/group.mjs.map +1 -1
- package/dist/backup-and-sync/syncing/legacy.cjs.map +1 -1
- package/dist/backup-and-sync/syncing/legacy.mjs.map +1 -1
- package/dist/backup-and-sync/syncing/metadata.cjs.map +1 -1
- package/dist/backup-and-sync/syncing/metadata.mjs.map +1 -1
- package/dist/backup-and-sync/syncing/wallet.cjs.map +1 -1
- package/dist/backup-and-sync/syncing/wallet.mjs.map +1 -1
- package/dist/backup-and-sync/user-storage/format-utils.cjs.map +1 -1
- package/dist/backup-and-sync/user-storage/format-utils.mjs.map +1 -1
- package/dist/backup-and-sync/user-storage/network-operations.cjs.map +1 -1
- package/dist/backup-and-sync/user-storage/network-operations.mjs.map +1 -1
- package/dist/backup-and-sync/user-storage/network-utils.cjs.map +1 -1
- package/dist/backup-and-sync/user-storage/network-utils.mjs.map +1 -1
- package/dist/backup-and-sync/user-storage/validation.cjs.map +1 -1
- package/dist/backup-and-sync/user-storage/validation.mjs.map +1 -1
- package/dist/backup-and-sync/utils/controller.cjs.map +1 -1
- package/dist/backup-and-sync/utils/controller.mjs.map +1 -1
- package/dist/group.cjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/rules/entropy.cjs.map +1 -1
- package/dist/rules/entropy.mjs.map +1 -1
- package/dist/rules/keyring.cjs.map +1 -1
- package/dist/rules/keyring.mjs.map +1 -1
- package/dist/rules/snap.cjs.map +1 -1
- package/dist/rules/snap.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-utils.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/format-utils.ts"],"names":[],"mappings":";;;AAAA,iDAIsB;AAUtB;;;;;;;;GAQG;AACI,MAAM,+BAA+B,GAAG,CAC7C,OAA6B,EAC7B,MAAkC,EACT,EAAE;IAC3B,2DAA2D;IAC3D,MAAM,uBAAuB,GAC3B,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAE7D,OAAO;QACL,GAAG,CAAC,uBAAuB,IAAI,EAAE,CAAC;QAClC,8BAA8B,EAAE,IAAI,EAAE,yHAAyH;KAChK,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,+BAA+B,mCAY1C;AAEF;;;;;;;;GAQG;AACI,MAAM,8BAA8B,GAAG,CAC5C,OAA6B,EAC7B,KAA0C,EACZ,EAAE;IAChC,uFAAuF;IACvF,MAAM,sBAAsB,GAC1B,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAE3D,OAAO;QACL,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC;QACjC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU;KAC9C,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,8BAA8B,kCAYzC;AAEF;;;;;;;;GAQG;AACI,MAAM,kCAAkC,GAAG,CAChD,MAA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,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACrH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,kCAAkC,sCAY7C;AAEF;;;;;;;;GAQG;AACI,MAAM,iCAAiC,GAAG,CAC/C,KAAa,EACiB,EAAE;IAChC,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpC,IAAA,wCAA2B,EAAC,SAAS,CAAC,CAAC;QACvC,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,2DAA2D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACpH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,iCAAiC,qCAY5C;AAEF;;;;;;;;GAQG;AACI,MAAM,yCAAyC,GAAG,CACvD,OAAe,EACiB,EAAE;IAClC,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,IAAA,gDAAmC,EAAC,WAAW,CAAC,CAAC;QACjD,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,oEAAoE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC7H,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,yCAAyC,6CAYpD","sourcesContent":["import {\n assertValidUserStorageWallet,\n assertValidUserStorageGroup,\n assertValidLegacyUserStorageAccount,\n} from './validation';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\n\n/**\n * Formats the wallet for user storage usage.\n * This function extracts the necessary metadata from the wallet\n * and formats it according to the user storage requirements.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet object to format.\n * @returns The formatted wallet for user storage.\n */\nexport const formatWalletForUserStorageUsage = (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): UserStorageSyncedWallet => {\n // This can be null if the user has not manually set a name\n const persistedWalletMetadata =\n context.controller.state.accountWalletsMetadata[wallet.id];\n\n return {\n ...(persistedWalletMetadata ?? {}),\n isLegacyAccountSyncingDisabled: true, // If we're here, it means legacy account syncing has been performed at least once, so we can disable it for this wallet.\n };\n};\n\n/**\n * Formats the group for user storage usage.\n * This function extracts the necessary metadata from the group\n * and formats it according to the user storage requirements.\n *\n * @param context - The backup and sync context.\n * @param group - The group object to format.\n * @returns The formatted group for user storage.\n */\nexport const formatGroupForUserStorageUsage = (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n): UserStorageSyncedWalletGroup => {\n // This can be null if the user has not manually set a name, pinned or hidden the group\n const persistedGroupMetadata =\n context.controller.state.accountGroupsMetadata[group.id];\n\n return {\n ...(persistedGroupMetadata ?? {}),\n groupIndex: group.metadata.entropy.groupIndex,\n };\n};\n\n/**\n * Parses the wallet from user storage response.\n * This function attempts to parse the wallet data from a string format\n * and returns it as a UserStorageSyncedWallet object.\n *\n * @param wallet - The wallet data in string format.\n * @returns The parsed UserStorageSyncedWallet object.\n * @throws If the wallet data is not in valid JSON format or fails validation.\n */\nexport const parseWalletFromUserStorageResponse = (\n wallet: string,\n): UserStorageSyncedWallet => {\n try {\n const walletData = JSON.parse(wallet);\n assertValidUserStorageWallet(walletData);\n return walletData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse wallet from user storage response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n\n/**\n * Parses the group from user storage response.\n * This function attempts to parse the group data from a string format\n * and returns it as a UserStorageSyncedWalletGroup object.\n *\n * @param group - The group data in string format.\n * @returns The parsed UserStorageSyncedWalletGroup object.\n * @throws If the group data is not in valid JSON format or fails validation.\n */\nexport const parseGroupFromUserStorageResponse = (\n group: string,\n): UserStorageSyncedWalletGroup => {\n try {\n const groupData = JSON.parse(group);\n assertValidUserStorageGroup(groupData);\n return groupData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse group from user storage response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n\n/**\n * Parses the legacy account from user storage response.\n * This function attempts to parse the account data from a string format\n * and returns it as a LegacyUserStorageSyncedAccount object.\n *\n * @param account - The account data in string format.\n * @returns The parsed LegacyUserStorageSyncedAccount object.\n * @throws If the account data is not in valid JSON format or fails validation.\n */\nexport const parseLegacyAccountFromUserStorageResponse = (\n account: string,\n): LegacyUserStorageSyncedAccount => {\n try {\n const accountData = JSON.parse(account);\n assertValidLegacyUserStorageAccount(accountData);\n return accountData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse legacy account from user storage response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-utils.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/format-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,mCAAmC,EACpC,yBAAqB;AAUtB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,OAA6B,EAC7B,MAAkC,EACT,EAAE;IAC3B,2DAA2D;IAC3D,MAAM,uBAAuB,GAC3B,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAE7D,OAAO;QACL,GAAG,CAAC,uBAAuB,IAAI,EAAE,CAAC;QAClC,8BAA8B,EA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AAC,CAAC;QACxC,mCAAmC,CAAC,WAAW,CAAC,CAAC;QACjD,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,oEAAoE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC7H,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n assertValidUserStorageWallet,\n assertValidUserStorageGroup,\n assertValidLegacyUserStorageAccount,\n} from './validation';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\n\n/**\n * Formats the wallet for user storage usage.\n * This function extracts the necessary metadata from the wallet\n * and formats it according to the user storage requirements.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet object to format.\n * @returns The formatted wallet for user storage.\n */\nexport const formatWalletForUserStorageUsage = (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): UserStorageSyncedWallet => {\n // This can be null if the user has not manually set a name\n const persistedWalletMetadata =\n context.controller.state.accountWalletsMetadata[wallet.id];\n\n return {\n ...(persistedWalletMetadata ?? {}),\n isLegacyAccountSyncingDisabled: true, // If we're here, it means legacy account syncing has been performed at least once, so we can disable it for this wallet.\n };\n};\n\n/**\n * Formats the group for user storage usage.\n * This function extracts the necessary metadata from the group\n * and formats it according to the user storage requirements.\n *\n * @param context - The backup and sync context.\n * @param group - The group object to format.\n * @returns The formatted group for user storage.\n */\nexport const formatGroupForUserStorageUsage = (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n): UserStorageSyncedWalletGroup => {\n // This can be null if the user has not manually set a name, pinned or hidden the group\n const persistedGroupMetadata =\n context.controller.state.accountGroupsMetadata[group.id];\n\n return {\n ...(persistedGroupMetadata ?? {}),\n groupIndex: group.metadata.entropy.groupIndex,\n };\n};\n\n/**\n * Parses the wallet from user storage response.\n * This function attempts to parse the wallet data from a string format\n * and returns it as a UserStorageSyncedWallet object.\n *\n * @param wallet - The wallet data in string format.\n * @returns The parsed UserStorageSyncedWallet object.\n * @throws If the wallet data is not in valid JSON format or fails validation.\n */\nexport const parseWalletFromUserStorageResponse = (\n wallet: string,\n): UserStorageSyncedWallet => {\n try {\n const walletData = JSON.parse(wallet);\n assertValidUserStorageWallet(walletData);\n return walletData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse wallet from user storage response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n\n/**\n * Parses the group from user storage response.\n * This function attempts to parse the group data from a string format\n * and returns it as a UserStorageSyncedWalletGroup object.\n *\n * @param group - The group data in string format.\n * @returns The parsed UserStorageSyncedWalletGroup object.\n * @throws If the group data is not in valid JSON format or fails validation.\n */\nexport const parseGroupFromUserStorageResponse = (\n group: string,\n): UserStorageSyncedWalletGroup => {\n try {\n const groupData = JSON.parse(group);\n assertValidUserStorageGroup(groupData);\n return groupData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse group from user storage response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n\n/**\n * Parses the legacy account from user storage response.\n * This function attempts to parse the account data from a string format\n * and returns it as a LegacyUserStorageSyncedAccount object.\n *\n * @param account - The account data in string format.\n * @returns The parsed LegacyUserStorageSyncedAccount object.\n * @throws If the account data is not in valid JSON format or fails validation.\n */\nexport const parseLegacyAccountFromUserStorageResponse = (\n account: string,\n): LegacyUserStorageSyncedAccount => {\n try {\n const accountData = JSON.parse(account);\n assertValidLegacyUserStorageAccount(accountData);\n return accountData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse legacy account from user storage response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-operations.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-operations.ts"],"names":[],"mappings":";;;AAAA,+EAAwD;AAExD,+CAIqB;AACrB,qDAMwB;AACxB,uDAAmD;AAEnD,6CAAmD;AASnD;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAA6B,EAC7B,eAAuB,EACkB,EAAE;IAC3C,OAAO,IAAA,gCAAgB,EAAC,KAAK,IAAI,EAAE;QACjC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAC7C,yCAAyC,EACzC,GAAG,4CAAgC,IAAI,kDAAsC,EAAE,EAC/E,eAAe,CAChB,CAAC;QACF,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,IAAI;YACF,IAAA,4BAAmB,EACjB,4CAA4C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CACzE,CAAC;YACF,OAAO,IAAA,iDAAkC,EAAC,UAAU,CAAC,CAAC;SACvD;QAAC,OAAO,KAAK,EAAE;YACd,IAAA,4BAAmB,EACjB,kDAAkD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC3G,CAAC;YACF,OAAO,IAAI,CAAC;SACb;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA1BW,QAAA,wBAAwB,4BA0BnC;AAEF;;;;;;;;;GASG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAC1C,OAA6B,EAC7B,MAAkC,EACnB,EAAE;IACjB,OAAO,IAAA,gCAAgB,EAAC,KAAK,IAAI,EAAE;QACjC,MAAM,eAAe,GAAG,IAAA,8CAA+B,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzE,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QAC1D,MAAM,eAAe,GAAG,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AI,CAAC,YAAY,EAAE;YACjB,OAAO,EAAE,CAAC;SACX;QAED,MAAM,WAAW,GAAG,YAAY;aAC7B,GAAG,CAAC,CAAC,kBAAkB,EAAE,EAAE;YAC1B,IAAI;gBACF,OAAO,IAAA,wDAAyC,EAAC,kBAAkB,CAAC,CAAC;aACtE;YAAC,OAAO,KAAK,EAAE;gBACd,IAAA,4BAAmB,EACjB,0DAA0D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACnH,CAAC;gBACF,OAAO,IAAI,CAAC;aACb;QACH,CAAC,CAAC;aACD,MAAM,CACL,CAAC,OAAO,EAA6C,EAAE,CACrD,OAAO,KAAK,IAAI,CACnB,CAAC;QAEJ,IAAA,4BAAmB,EACjB,gDAAgD,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAC9E,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AArCW,QAAA,+BAA+B,mCAqC1C","sourcesContent":["import { SDK } from '@metamask/profile-sync-controller';\n\nimport {\n USER_STORAGE_GROUPS_FEATURE_KEY,\n USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY,\n USER_STORAGE_WALLETS_FEATURE_KEY,\n} from './constants';\nimport {\n formatWalletForUserStorageUsage,\n formatGroupForUserStorageUsage,\n parseWalletFromUserStorageResponse,\n parseGroupFromUserStorageResponse,\n parseLegacyAccountFromUserStorageResponse,\n} from './format-utils';\nimport { executeWithRetry } from './network-utils';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\n\n/**\n * Retrieves the wallet from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns The wallet from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getWalletFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWallet | null> => {\n return executeWithRetry(async () => {\n const walletData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n entropySourceId,\n );\n if (!walletData) {\n return null;\n }\n\n try {\n backupAndSyncLogger(\n `Retrieved wallet data from user storage: ${JSON.stringify(walletData)}`,\n );\n return parseWalletFromUserStorageResponse(walletData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse wallet data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes the wallet to user storage.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet to push to user storage.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted wallet data.\n */\nexport const pushWalletToUserStorage = async (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedWallet = formatWalletForUserStorageUsage(context, wallet);\n const stringifiedWallet = JSON.stringify(formattedWallet);\n const entropySourceId = wallet.metadata.entropy.id;\n\n backupAndSyncLogger(`Pushing wallet to user storage: ${stringifiedWallet}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n stringifiedWallet,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves all groups from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns An array of groups from user storage.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllGroupsFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWalletGroup[]> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}`,\n entropySourceId,\n );\n if (!groupData) {\n return [];\n }\n\n const allGroups = groupData\n .map((stringifiedGroup) => {\n try {\n return parseGroupFromUserStorageResponse(stringifiedGroup);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter((group): group is UserStorageSyncedWalletGroup => group !== null);\n\n backupAndSyncLogger(\n `Retrieved groups from user storage: ${JSON.stringify(allGroups)}`,\n );\n\n return allGroups;\n });\n};\n\n/**\n * Retrieves a single group from user storage by group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index to retrieve.\n * @returns The group from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getGroupFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): Promise<UserStorageSyncedWalletGroup | null> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${groupIndex}`,\n entropySourceId,\n );\n if (!groupData) {\n return null;\n }\n\n try {\n return parseGroupFromUserStorageResponse(groupData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes a group to user storage.\n *\n * @param context - The backup and sync context.\n * @param group - The group to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted group data.\n */\nexport const pushGroupToUserStorage = async (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroup = formatGroupForUserStorageUsage(context, group);\n const stringifiedGroup = JSON.stringify(formattedGroup);\n\n backupAndSyncLogger(`Pushing group to user storage: ${stringifiedGroup}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${formattedGroup.groupIndex}`,\n stringifiedGroup,\n entropySourceId,\n );\n });\n};\n\n/**\n * Pushes a batch of groups to user storage.\n *\n * @param context - The backup and sync context.\n * @param groups - The groups to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on any of the formatted group data.\n */\nexport const pushGroupToUserStorageBatch = async (\n context: BackupAndSyncContext,\n groups: AccountGroupMultichainAccountObject[],\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroups = groups.map((group) =>\n formatGroupForUserStorageUsage(context, group),\n );\n\n const entries: [string, string][] = formattedGroups.map((group) => [\n String(group.groupIndex),\n JSON.stringify(group),\n ]);\n\n backupAndSyncLogger(\n `Pushing groups to user storage: ${entries.map(([_, value]) => value).join(', ')}`,\n );\n\n return await context.messenger.call(\n 'UserStorageController:performBatchSetStorage',\n USER_STORAGE_GROUPS_FEATURE_KEY,\n entries,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves legacy user storage accounts for a specific entropy source ID.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID to retrieve data for.\n * @returns A promise that resolves with the legacy user storage accounts.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllLegacyUserStorageAccounts = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<LegacyUserStorageSyncedAccount[]> => {\n return executeWithRetry(async () => {\n const accountsData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n SDK.USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n if (!accountsData) {\n return [];\n }\n\n const allAccounts = accountsData\n .map((stringifiedAccount) => {\n try {\n return parseLegacyAccountFromUserStorageResponse(stringifiedAccount);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse legacy account data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter(\n (account): account is LegacyUserStorageSyncedAccount =>\n account !== null,\n );\n\n backupAndSyncLogger(\n `Retrieved legacy accounts from user storage: ${JSON.stringify(allAccounts)}`,\n );\n\n return allAccounts;\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"network-operations.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-operations.ts"],"names":[],"mappings":";;;AAAA,+EAAwD;AAExD,+CAIqB;AACrB,qDAMwB;AACxB,uDAAmD;AAEnD,6CAAmD;AASnD;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAA6B,EAC7B,eAAuB,EACkB,EAAE;IAC3C,OAAO,IAAA,gCAAgB,EAAC,KAAK,IAAI,EAAE;QACjC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAC7C,yCAAyC,EACzC,GAAG,4CAAgC,IAAI,kDAAsC,EAAE,EAC/E,eAAe,CAChB,CAAC;QACF,IAAI,CAAC,UAAU,EAAE,CAAC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AAM,CAAC,KAAK,CAAC,EAAE,CACnH,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC,CAAC;aACD,MAAM,CACL,CAAC,OAAO,EAA6C,EAAE,CACrD,OAAO,KAAK,IAAI,CACnB,CAAC;QAEJ,IAAA,4BAAmB,EACjB,gDAAgD,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAC9E,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AArCW,QAAA,+BAA+B,mCAqC1C","sourcesContent":["import { SDK } from '@metamask/profile-sync-controller';\n\nimport {\n USER_STORAGE_GROUPS_FEATURE_KEY,\n USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY,\n USER_STORAGE_WALLETS_FEATURE_KEY,\n} from './constants';\nimport {\n formatWalletForUserStorageUsage,\n formatGroupForUserStorageUsage,\n parseWalletFromUserStorageResponse,\n parseGroupFromUserStorageResponse,\n parseLegacyAccountFromUserStorageResponse,\n} from './format-utils';\nimport { executeWithRetry } from './network-utils';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\n\n/**\n * Retrieves the wallet from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns The wallet from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getWalletFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWallet | null> => {\n return executeWithRetry(async () => {\n const walletData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n entropySourceId,\n );\n if (!walletData) {\n return null;\n }\n\n try {\n backupAndSyncLogger(\n `Retrieved wallet data from user storage: ${JSON.stringify(walletData)}`,\n );\n return parseWalletFromUserStorageResponse(walletData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse wallet data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes the wallet to user storage.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet to push to user storage.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted wallet data.\n */\nexport const pushWalletToUserStorage = async (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedWallet = formatWalletForUserStorageUsage(context, wallet);\n const stringifiedWallet = JSON.stringify(formattedWallet);\n const entropySourceId = wallet.metadata.entropy.id;\n\n backupAndSyncLogger(`Pushing wallet to user storage: ${stringifiedWallet}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n stringifiedWallet,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves all groups from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns An array of groups from user storage.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllGroupsFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWalletGroup[]> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}`,\n entropySourceId,\n );\n if (!groupData) {\n return [];\n }\n\n const allGroups = groupData\n .map((stringifiedGroup) => {\n try {\n return parseGroupFromUserStorageResponse(stringifiedGroup);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter((group): group is UserStorageSyncedWalletGroup => group !== null);\n\n backupAndSyncLogger(\n `Retrieved groups from user storage: ${JSON.stringify(allGroups)}`,\n );\n\n return allGroups;\n });\n};\n\n/**\n * Retrieves a single group from user storage by group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index to retrieve.\n * @returns The group from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getGroupFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): Promise<UserStorageSyncedWalletGroup | null> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${groupIndex}`,\n entropySourceId,\n );\n if (!groupData) {\n return null;\n }\n\n try {\n return parseGroupFromUserStorageResponse(groupData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes a group to user storage.\n *\n * @param context - The backup and sync context.\n * @param group - The group to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted group data.\n */\nexport const pushGroupToUserStorage = async (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroup = formatGroupForUserStorageUsage(context, group);\n const stringifiedGroup = JSON.stringify(formattedGroup);\n\n backupAndSyncLogger(`Pushing group to user storage: ${stringifiedGroup}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${formattedGroup.groupIndex}`,\n stringifiedGroup,\n entropySourceId,\n );\n });\n};\n\n/**\n * Pushes a batch of groups to user storage.\n *\n * @param context - The backup and sync context.\n * @param groups - The groups to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on any of the formatted group data.\n */\nexport const pushGroupToUserStorageBatch = async (\n context: BackupAndSyncContext,\n groups: AccountGroupMultichainAccountObject[],\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroups = groups.map((group) =>\n formatGroupForUserStorageUsage(context, group),\n );\n\n const entries: [string, string][] = formattedGroups.map((group) => [\n String(group.groupIndex),\n JSON.stringify(group),\n ]);\n\n backupAndSyncLogger(\n `Pushing groups to user storage: ${entries.map(([_, value]) => value).join(', ')}`,\n );\n\n return await context.messenger.call(\n 'UserStorageController:performBatchSetStorage',\n USER_STORAGE_GROUPS_FEATURE_KEY,\n entries,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves legacy user storage accounts for a specific entropy source ID.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID to retrieve data for.\n * @returns A promise that resolves with the legacy user storage accounts.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllLegacyUserStorageAccounts = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<LegacyUserStorageSyncedAccount[]> => {\n return executeWithRetry(async () => {\n const accountsData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n SDK.USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n if (!accountsData) {\n return [];\n }\n\n const allAccounts = accountsData\n .map((stringifiedAccount) => {\n try {\n return parseLegacyAccountFromUserStorageResponse(stringifiedAccount);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse legacy account data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter(\n (account): account is LegacyUserStorageSyncedAccount =>\n account !== null,\n );\n\n backupAndSyncLogger(\n `Retrieved legacy accounts from user storage: ${JSON.stringify(allAccounts)}`,\n );\n\n return allAccounts;\n });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-operations.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,0CAA0C;AAExD,OAAO,EACL,+BAA+B,EAC/B,sCAAsC,EACtC,gCAAgC,EACjC,wBAAoB;AACrB,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,EAC9B,kCAAkC,EAClC,iCAAiC,EACjC,yCAAyC,EAC1C,2BAAuB;AACxB,OAAO,EAAE,gBAAgB,EAAE,4BAAwB;AAEnD,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AASnD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAA6B,EAC7B,eAAuB,EACkB,EAAE;IAC3C,OAAO,gBAAgB,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAC7C,yCAAyC,EACzC,GAAG,gCAAgC,IAAI,sCAAsC,EAAE,EAC/E,eAAe,CAChB,CAAC;QACF,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,IAAI;YACF,mBAAmB,CACjB,4CAA4C,IAAI,CAAC,SAAS,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O,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CACjC,8CAA8C,EAC9C,+BAA+B,EAC/B,OAAO,EACP,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,KAAK,EAClD,OAA6B,EAC7B,eAAuB,EACoB,EAAE;IAC7C,OAAO,gBAAgB,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,IAAI,CAC/C,0DAA0D,EAC1D,GAAG,CAAC,0BAA0B,CAAC,QAAQ,EACvC,eAAe,CAChB,CAAC;QAEF,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO,EAAE,CAAC;SACX;QAED,MAAM,WAAW,GAAG,YAAY;aAC7B,GAAG,CAAC,CAAC,kBAAkB,EAAE,EAAE;YAC1B,IAAI;gBACF,OAAO,yCAAyC,CAAC,kBAAkB,CAAC,CAAC;aACtE;YAAC,OAAO,KAAK,EAAE;gBACd,mBAAmB,CACjB,0DAA0D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACnH,CAAC;gBACF,OAAO,IAAI,CAAC;aACb;QACH,CAAC,CAAC;aACD,MAAM,CACL,CAAC,OAAO,EAA6C,EAAE,CACrD,OAAO,KAAK,IAAI,CACnB,CAAC;QAEJ,mBAAmB,CACjB,gDAAgD,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAC9E,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { SDK } from '@metamask/profile-sync-controller';\n\nimport {\n USER_STORAGE_GROUPS_FEATURE_KEY,\n USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY,\n USER_STORAGE_WALLETS_FEATURE_KEY,\n} from './constants';\nimport {\n formatWalletForUserStorageUsage,\n formatGroupForUserStorageUsage,\n parseWalletFromUserStorageResponse,\n parseGroupFromUserStorageResponse,\n parseLegacyAccountFromUserStorageResponse,\n} from './format-utils';\nimport { executeWithRetry } from './network-utils';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\n\n/**\n * Retrieves the wallet from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns The wallet from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getWalletFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWallet | null> => {\n return executeWithRetry(async () => {\n const walletData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n entropySourceId,\n );\n if (!walletData) {\n return null;\n }\n\n try {\n backupAndSyncLogger(\n `Retrieved wallet data from user storage: ${JSON.stringify(walletData)}`,\n );\n return parseWalletFromUserStorageResponse(walletData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse wallet data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes the wallet to user storage.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet to push to user storage.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted wallet data.\n */\nexport const pushWalletToUserStorage = async (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedWallet = formatWalletForUserStorageUsage(context, wallet);\n const stringifiedWallet = JSON.stringify(formattedWallet);\n const entropySourceId = wallet.metadata.entropy.id;\n\n backupAndSyncLogger(`Pushing wallet to user storage: ${stringifiedWallet}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n stringifiedWallet,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves all groups from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns An array of groups from user storage.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllGroupsFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWalletGroup[]> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}`,\n entropySourceId,\n );\n if (!groupData) {\n return [];\n }\n\n const allGroups = groupData\n .map((stringifiedGroup) => {\n try {\n return parseGroupFromUserStorageResponse(stringifiedGroup);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter((group): group is UserStorageSyncedWalletGroup => group !== null);\n\n backupAndSyncLogger(\n `Retrieved groups from user storage: ${JSON.stringify(allGroups)}`,\n );\n\n return allGroups;\n });\n};\n\n/**\n * Retrieves a single group from user storage by group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index to retrieve.\n * @returns The group from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getGroupFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): Promise<UserStorageSyncedWalletGroup | null> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${groupIndex}`,\n entropySourceId,\n );\n if (!groupData) {\n return null;\n }\n\n try {\n return parseGroupFromUserStorageResponse(groupData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes a group to user storage.\n *\n * @param context - The backup and sync context.\n * @param group - The group to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted group data.\n */\nexport const pushGroupToUserStorage = async (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroup = formatGroupForUserStorageUsage(context, group);\n const stringifiedGroup = JSON.stringify(formattedGroup);\n\n backupAndSyncLogger(`Pushing group to user storage: ${stringifiedGroup}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${formattedGroup.groupIndex}`,\n stringifiedGroup,\n entropySourceId,\n );\n });\n};\n\n/**\n * Pushes a batch of groups to user storage.\n *\n * @param context - The backup and sync context.\n * @param groups - The groups to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on any of the formatted group data.\n */\nexport const pushGroupToUserStorageBatch = async (\n context: BackupAndSyncContext,\n groups: AccountGroupMultichainAccountObject[],\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroups = groups.map((group) =>\n formatGroupForUserStorageUsage(context, group),\n );\n\n const entries: [string, string][] = formattedGroups.map((group) => [\n String(group.groupIndex),\n JSON.stringify(group),\n ]);\n\n backupAndSyncLogger(\n `Pushing groups to user storage: ${entries.map(([_, value]) => value).join(', ')}`,\n );\n\n return await context.messenger.call(\n 'UserStorageController:performBatchSetStorage',\n USER_STORAGE_GROUPS_FEATURE_KEY,\n entries,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves legacy user storage accounts for a specific entropy source ID.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID to retrieve data for.\n * @returns A promise that resolves with the legacy user storage accounts.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllLegacyUserStorageAccounts = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<LegacyUserStorageSyncedAccount[]> => {\n return executeWithRetry(async () => {\n const accountsData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n SDK.USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n if (!accountsData) {\n return [];\n }\n\n const allAccounts = accountsData\n .map((stringifiedAccount) => {\n try {\n return parseLegacyAccountFromUserStorageResponse(stringifiedAccount);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse legacy account data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter(\n (account): account is LegacyUserStorageSyncedAccount =>\n account !== null,\n );\n\n backupAndSyncLogger(\n `Retrieved legacy accounts from user storage: ${JSON.stringify(allAccounts)}`,\n );\n\n return allAccounts;\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"network-operations.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-operations.ts"],"names":[],"mappings":"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CAChB,CAAC;QAEF,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,YAAY;aAC7B,GAAG,CAAC,CAAC,kBAAkB,EAAE,EAAE;YAC1B,IAAI,CAAC;gBACH,OAAO,yCAAyC,CAAC,kBAAkB,CAAC,CAAC;YACvE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,mBAAmB,CACjB,0DAA0D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACnH,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC,CAAC;aACD,MAAM,CACL,CAAC,OAAO,EAA6C,EAAE,CACrD,OAAO,KAAK,IAAI,CACnB,CAAC;QAEJ,mBAAmB,CACjB,gDAAgD,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAC9E,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { SDK } from '@metamask/profile-sync-controller';\n\nimport {\n USER_STORAGE_GROUPS_FEATURE_KEY,\n USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY,\n USER_STORAGE_WALLETS_FEATURE_KEY,\n} from './constants';\nimport {\n formatWalletForUserStorageUsage,\n formatGroupForUserStorageUsage,\n parseWalletFromUserStorageResponse,\n parseGroupFromUserStorageResponse,\n parseLegacyAccountFromUserStorageResponse,\n} from './format-utils';\nimport { executeWithRetry } from './network-utils';\nimport type { AccountGroupMultichainAccountObject } from '../../group';\nimport { backupAndSyncLogger } from '../../logger';\nimport type { AccountWalletEntropyObject } from '../../wallet';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\n\n/**\n * Retrieves the wallet from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns The wallet from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getWalletFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWallet | null> => {\n return executeWithRetry(async () => {\n const walletData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n entropySourceId,\n );\n if (!walletData) {\n return null;\n }\n\n try {\n backupAndSyncLogger(\n `Retrieved wallet data from user storage: ${JSON.stringify(walletData)}`,\n );\n return parseWalletFromUserStorageResponse(walletData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse wallet data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes the wallet to user storage.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet to push to user storage.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted wallet data.\n */\nexport const pushWalletToUserStorage = async (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedWallet = formatWalletForUserStorageUsage(context, wallet);\n const stringifiedWallet = JSON.stringify(formattedWallet);\n const entropySourceId = wallet.metadata.entropy.id;\n\n backupAndSyncLogger(`Pushing wallet to user storage: ${stringifiedWallet}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n stringifiedWallet,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves all groups from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns An array of groups from user storage.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllGroupsFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWalletGroup[]> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}`,\n entropySourceId,\n );\n if (!groupData) {\n return [];\n }\n\n const allGroups = groupData\n .map((stringifiedGroup) => {\n try {\n return parseGroupFromUserStorageResponse(stringifiedGroup);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter((group): group is UserStorageSyncedWalletGroup => group !== null);\n\n backupAndSyncLogger(\n `Retrieved groups from user storage: ${JSON.stringify(allGroups)}`,\n );\n\n return allGroups;\n });\n};\n\n/**\n * Retrieves a single group from user storage by group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index to retrieve.\n * @returns The group from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getGroupFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): Promise<UserStorageSyncedWalletGroup | null> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${groupIndex}`,\n entropySourceId,\n );\n if (!groupData) {\n return null;\n }\n\n try {\n return parseGroupFromUserStorageResponse(groupData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes a group to user storage.\n *\n * @param context - The backup and sync context.\n * @param group - The group to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted group data.\n */\nexport const pushGroupToUserStorage = async (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroup = formatGroupForUserStorageUsage(context, group);\n const stringifiedGroup = JSON.stringify(formattedGroup);\n\n backupAndSyncLogger(`Pushing group to user storage: ${stringifiedGroup}`);\n\n return await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${formattedGroup.groupIndex}`,\n stringifiedGroup,\n entropySourceId,\n );\n });\n};\n\n/**\n * Pushes a batch of groups to user storage.\n *\n * @param context - The backup and sync context.\n * @param groups - The groups to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on any of the formatted group data.\n */\nexport const pushGroupToUserStorageBatch = async (\n context: BackupAndSyncContext,\n groups: AccountGroupMultichainAccountObject[],\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroups = groups.map((group) =>\n formatGroupForUserStorageUsage(context, group),\n );\n\n const entries: [string, string][] = formattedGroups.map((group) => [\n String(group.groupIndex),\n JSON.stringify(group),\n ]);\n\n backupAndSyncLogger(\n `Pushing groups to user storage: ${entries.map(([_, value]) => value).join(', ')}`,\n );\n\n return await context.messenger.call(\n 'UserStorageController:performBatchSetStorage',\n USER_STORAGE_GROUPS_FEATURE_KEY,\n entries,\n entropySourceId,\n );\n });\n};\n\n/**\n * Retrieves legacy user storage accounts for a specific entropy source ID.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID to retrieve data for.\n * @returns A promise that resolves with the legacy user storage accounts.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllLegacyUserStorageAccounts = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<LegacyUserStorageSyncedAccount[]> => {\n return executeWithRetry(async () => {\n const accountsData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n SDK.USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n if (!accountsData) {\n return [];\n }\n\n const allAccounts = accountsData\n .map((stringifiedAccount) => {\n try {\n return parseLegacyAccountFromUserStorageResponse(stringifiedAccount);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse legacy account data from user storage: ${error instanceof Error ? error.message : String(error)}`,\n );\n return null;\n }\n })\n .filter(\n (account): account is LegacyUserStorageSyncedAccount =>\n account !== null,\n );\n\n backupAndSyncLogger(\n `Retrieved legacy accounts from user storage: ${JSON.stringify(allAccounts)}`,\n );\n\n return allAccounts;\n });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-utils.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CACpC,SAA2B,EAC3B,UAAU,GAAG,CAAC,EACd,WAAW,GAAG,IAAI;IAElB,IAAI,SAAS,GAAU,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAElD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"network-utils.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CACpC,SAA2B,EAC3B,UAAU,GAAG,CAAC,EACd,WAAW,GAAG,IAAI;IAElB,IAAI,SAAS,GAAU,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAElD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAEtE,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;gBAC3B,MAAM,CAAC,gCAAgC;YACzC,CAAC;YAED,sCAAsC;YACtC,MAAM,OAAO,GAAG,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAEnD,oBAAoB;YACpB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,MAAM,SAAS,CAAC;AAClB,CAAC;AA3BD,4CA2BC","sourcesContent":["/**\n * Executes a network operation with retry logic for transient failures.\n *\n * @param operation - The async operation to execute.\n * @param maxRetries - Maximum number of retry attempts.\n * @param baseDelayMs - Base delay between retries in milliseconds.\n * @returns Promise that resolves with the operation result.\n */\nexport async function executeWithRetry<T>(\n operation: () => Promise<T>,\n maxRetries = 3,\n baseDelayMs = 1000,\n): Promise<T> {\n let lastError: Error = new Error('Unknown error');\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await operation();\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n\n if (attempt === maxRetries) {\n break; // Exit loop after final attempt\n }\n\n // Calculate exponential backoff delay\n const delayMs = baseDelayMs * Math.pow(2, attempt);\n\n // Wait before retry\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n }\n\n // This will only be reached if all attempts failed\n throw lastError;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-utils.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA2B,EAC3B,UAAU,GAAG,CAAC,EACd,WAAW,GAAG,IAAI;IAElB,IAAI,SAAS,GAAU,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAElD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"network-utils.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA2B,EAC3B,UAAU,GAAG,CAAC,EACd,WAAW,GAAG,IAAI;IAElB,IAAI,SAAS,GAAU,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAElD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAEtE,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;gBAC3B,MAAM,CAAC,gCAAgC;YACzC,CAAC;YAED,sCAAsC;YACtC,MAAM,OAAO,GAAG,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAEnD,oBAAoB;YACpB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,MAAM,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Executes a network operation with retry logic for transient failures.\n *\n * @param operation - The async operation to execute.\n * @param maxRetries - Maximum number of retry attempts.\n * @param baseDelayMs - Base delay between retries in milliseconds.\n * @returns Promise that resolves with the operation result.\n */\nexport async function executeWithRetry<T>(\n operation: () => Promise<T>,\n maxRetries = 3,\n baseDelayMs = 1000,\n): Promise<T> {\n let lastError: Error = new Error('Unknown error');\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await operation();\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n\n if (attempt === maxRetries) {\n break; // Exit loop after final attempt\n }\n\n // Calculate exponential backoff delay\n const delayMs = baseDelayMs * Math.pow(2, attempt);\n\n // Wait before retry\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n }\n\n // This will only be reached if all attempts failed\n throw lastError;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/validation.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAO5D,wCAIkB;AAElB;;;;;GAKG;AACH,MAAM,6BAA6B,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3D,MAAM,kBAAkB,GAAG,KAAK;SAC7B,QAAQ,EAAE;SACV,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE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AAC;YACjC,MAAM,IAAI,KAAK,CACb,oCAAoC,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAC3E,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAdD,kEAcC;AAED;;;;;GAKG;AACH,SAAgB,mCAAmC,CACjD,WAAoB;IAEpB,IAAI,CAAC;QACH,IAAA,oBAAM,EAAC,WAAW,EAAE,4CAAoC,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,6CAA6C,6BAA6B,CAAC,KAAK,CAAC,EAAE,CACpF,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAdD,kFAcC","sourcesContent":["import { assert, StructError } from '@metamask/superstruct';\n\nimport type {\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\nimport {\n UserStorageSyncedWalletSchema,\n UserStorageSyncedWalletGroupSchema,\n LegacyUserStorageSyncedAccountSchema,\n} from '../types';\n\n/**\n * Formats validation error messages for user storage data.\n *\n * @param error - The StructError thrown during validation.\n * @returns A formatted string of validation error messages.\n */\nconst formatValidationErrorMessages = (error: StructError) => {\n const validationFailures = error\n .failures()\n .map(({ path, message }) => `[${path.join('.')}] ${message}`)\n .join(', ');\n return `Invalid user storage data: ${validationFailures}`;\n};\n\n/**\n * Validates and asserts user storage wallet data, throwing detailed errors if invalid.\n *\n * @param walletData - The wallet data from user storage to validate.\n * @throws StructError if the wallet data is invalid.\n */\nexport function assertValidUserStorageWallet(\n walletData: unknown,\n): asserts walletData is UserStorageSyncedWallet {\n try {\n assert(walletData, UserStorageSyncedWalletSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid user storage wallet data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates and asserts user storage group data, throwing detailed errors if invalid.\n *\n * @param groupData - The group data from user storage to validate.\n * @throws StructError if the group data is invalid.\n */\nexport function assertValidUserStorageGroup(\n groupData: unknown,\n): asserts groupData is UserStorageSyncedWalletGroup {\n try {\n assert(groupData, UserStorageSyncedWalletGroupSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid user storage group data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates and asserts legacy user storage account data, throwing detailed errors if invalid.\n *\n * @param accountData - The account data from user storage to validate.\n * @throws StructError if the account data is invalid.\n */\nexport function assertValidLegacyUserStorageAccount(\n accountData: unknown,\n): asserts accountData is LegacyUserStorageSyncedAccount {\n try {\n assert(accountData, LegacyUserStorageSyncedAccountSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid legacy user storage account data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,8BAA8B;AAO5D,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,oCAAoC,EACrC,qBAAiB;AAElB;;;;;GAKG;AACH,MAAM,6BAA6B,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3D,MAAM,kBAAkB,GAAG,KAAK;SAC7B,QAAQ,EAAE;SACV,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAC;SAC5D,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,8BAA8B,kBAAkB,EAAE,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,UAAmB;IAEnB,IAAI;
|
|
1
|
+
{"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,8BAA8B;AAO5D,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,oCAAoC,EACrC,qBAAiB;AAElB;;;;;GAKG;AACH,MAAM,6BAA6B,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3D,MAAM,kBAAkB,GAAG,KAAK;SAC7B,QAAQ,EAAE;SACV,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAC;SAC5D,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,8BAA8B,kBAAkB,EAAE,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,UAAmB;IAEnB,IAAI,CAAC;QACH,MAAM,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAC5E,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,CAAC,SAAS,EAAE,kCAAkC,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,oCAAoC,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAC3E,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mCAAmC,CACjD,WAAoB;IAEpB,IAAI,CAAC;QACH,MAAM,CAAC,WAAW,EAAE,oCAAoC,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,6CAA6C,6BAA6B,CAAC,KAAK,CAAC,EAAE,CACpF,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { assert, StructError } from '@metamask/superstruct';\n\nimport type {\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types';\nimport {\n UserStorageSyncedWalletSchema,\n UserStorageSyncedWalletGroupSchema,\n LegacyUserStorageSyncedAccountSchema,\n} from '../types';\n\n/**\n * Formats validation error messages for user storage data.\n *\n * @param error - The StructError thrown during validation.\n * @returns A formatted string of validation error messages.\n */\nconst formatValidationErrorMessages = (error: StructError) => {\n const validationFailures = error\n .failures()\n .map(({ path, message }) => `[${path.join('.')}] ${message}`)\n .join(', ');\n return `Invalid user storage data: ${validationFailures}`;\n};\n\n/**\n * Validates and asserts user storage wallet data, throwing detailed errors if invalid.\n *\n * @param walletData - The wallet data from user storage to validate.\n * @throws StructError if the wallet data is invalid.\n */\nexport function assertValidUserStorageWallet(\n walletData: unknown,\n): asserts walletData is UserStorageSyncedWallet {\n try {\n assert(walletData, UserStorageSyncedWalletSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid user storage wallet data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates and asserts user storage group data, throwing detailed errors if invalid.\n *\n * @param groupData - The group data from user storage to validate.\n * @throws StructError if the group data is invalid.\n */\nexport function assertValidUserStorageGroup(\n groupData: unknown,\n): asserts groupData is UserStorageSyncedWalletGroup {\n try {\n assert(groupData, UserStorageSyncedWalletGroupSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid user storage group data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates and asserts legacy user storage account data, throwing detailed errors if invalid.\n *\n * @param accountData - The account data from user storage to validate.\n * @throws StructError if the account data is invalid.\n */\nexport function assertValidLegacyUserStorageAccount(\n accountData: unknown,\n): asserts accountData is LegacyUserStorageSyncedAccount {\n try {\n assert(accountData, LegacyUserStorageSyncedAccountSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid legacy user storage account data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
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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sB,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 {\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"]}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"controller.mjs","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/contro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C,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/group.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.cjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":";;;AAMA,uDAO+B;AAkBlB,QAAA,cAAc,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACU,QAAA,0BAA0B,GAAuC;IAC5E,CAAC,4BAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IACvB,CAAC,4BAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B,CAAC,4BAAc,CAAC,WAAW,CAAC,EAAE,CAAC;IAC/B,CAAC,4BAAc,CAAC,KAAK,CAAC,EAAE,CAAC;IACzB,CAAC,4BAAc,CAAC,IAAI,CAAC,EAAE,CAAC;IACxB,CAAC,4BAAc,CAAC,MAAM,CAAC,EAAE,CAAC;IAC1B,CAAC,4BAAc,CAAC,IAAI,CAAC,EAAE,CAAC;IACxB,CAAC,4BAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IACvB,CAAC,4BAAc,CAAC,OAAO,CAAC,EAAE,sBAAc;CACzC,CAAC;AAsEF;;;;;;;GAOG;AACH,SAAgB,kCAAkC,CAChD,MAA2B,EAC3B,OAAuB,EACvB,IAAY;IAEZ,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAEhC,0CAA0C;IAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"group.cjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":";;;AAMA,uDAO+B;AAkBlB,QAAA,cAAc,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACU,QAAA,0BAA0B,GAAuC;IAC5E,CAAC,4BAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IACvB,CAAC,4BAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B,CAAC,4BAAc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C1E,CAAC;AAdD,4DAcC","sourcesContent":["import {\n type AccountGroupType,\n type MultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type { AccountGroupId } from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport {\n AnyAccountType,\n BtcAccountType,\n EthAccountType,\n type KeyringAccountType,\n SolAccountType,\n TrxAccountType,\n} from '@metamask/keyring-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils';\nimport type { AccountTreeControllerState } from './types';\nimport type { AccountWalletObject } from './wallet';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n};\n\nexport const MAX_SORT_ORDER = 9999;\n\n/**\n * Order of account types.\n */\nexport const ACCOUNT_TYPE_TO_SORT_ORDER: Record<KeyringAccountType, number> = {\n [EthAccountType.Eoa]: 0,\n [EthAccountType.Erc4337]: 1,\n [SolAccountType.DataAccount]: 2,\n [BtcAccountType.P2pkh]: 3,\n [BtcAccountType.P2sh]: 4,\n [BtcAccountType.P2wpkh]: 5,\n [BtcAccountType.P2tr]: 6,\n [TrxAccountType.Eoa]: 7,\n [AnyAccountType.Account]: MAX_SORT_ORDER,\n};\n\nexport type AccountTypeOrderKey = keyof typeof ACCOUNT_TYPE_TO_SORT_ORDER;\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Checks if a group name is unique within a specific wallet.\n *\n * @param wallet - The wallet to check within.\n * @param groupId - The account group ID to exclude from the check.\n * @param name - The name to validate for uniqueness.\n * @returns True if the name is unique within the wallet, false otherwise.\n */\nexport function isAccountGroupNameUniqueFromWallet(\n wallet: AccountWalletObject,\n groupId: AccountGroupId,\n name: string,\n): boolean {\n const trimmedName = name.trim();\n\n // Check for duplicates within this wallet\n for (const group of Object.values(wallet.groups)) {\n if (group.id !== groupId && group.metadata.name.trim() === trimmedName) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Checks if an account group name is unique within the same wallet.\n *\n * @param state - The account tree controller state.\n * @param groupId - The account group ID to exclude from the check.\n * @param name - The name to validate for uniqueness.\n * @returns True if the name is unique within the same wallet, false otherwise.\n * @throws Error if the group ID does not exist.\n */\nexport function isAccountGroupNameUnique(\n state: AccountTreeControllerState,\n groupId: AccountGroupId,\n name: string,\n): boolean {\n // Find the wallet that contains the group being validated\n for (const wallet of Object.values(state.accountTree.wallets)) {\n if (wallet.groups[groupId]) {\n // Use the wallet-specific function for consistency\n return isAccountGroupNameUniqueFromWallet(wallet, groupId, name);\n }\n }\n\n throw new Error(`Account group with ID \"${groupId}\" not found in tree`);\n}\n"]}
|
package/dist/group.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.mjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,cAAc,EACd,cAAc,EAEd,cAAc,EACd,cAAc,EACf,8BAA8B;AAkB/B,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAuC;IAC5E,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IACvB,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC;IAC/B,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;IACzB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;IACxB,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;IAC1B,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;IACxB,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IACvB,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,cAAc;CACzC,CAAC;AAsEF;;;;;;;GAOG;AACH,MAAM,UAAU,kCAAkC,CAChD,MAA2B,EAC3B,OAAuB,EACvB,IAAY;IAEZ,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAEhC,0CAA0C;IAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"group.mjs","sourceRoot":"","sources":["../src/group.ts"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,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9D,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,mDAAmD;YACnD,OAAO,kCAAkC,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,qBAAqB,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import {\n type AccountGroupType,\n type MultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type { AccountGroupId } from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport {\n AnyAccountType,\n BtcAccountType,\n EthAccountType,\n type KeyringAccountType,\n SolAccountType,\n TrxAccountType,\n} from '@metamask/keyring-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils';\nimport type { AccountTreeControllerState } from './types';\nimport type { AccountWalletObject } from './wallet';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n};\n\nexport const MAX_SORT_ORDER = 9999;\n\n/**\n * Order of account types.\n */\nexport const ACCOUNT_TYPE_TO_SORT_ORDER: Record<KeyringAccountType, number> = {\n [EthAccountType.Eoa]: 0,\n [EthAccountType.Erc4337]: 1,\n [SolAccountType.DataAccount]: 2,\n [BtcAccountType.P2pkh]: 3,\n [BtcAccountType.P2sh]: 4,\n [BtcAccountType.P2wpkh]: 5,\n [BtcAccountType.P2tr]: 6,\n [TrxAccountType.Eoa]: 7,\n [AnyAccountType.Account]: MAX_SORT_ORDER,\n};\n\nexport type AccountTypeOrderKey = keyof typeof ACCOUNT_TYPE_TO_SORT_ORDER;\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Checks if a group name is unique within a specific wallet.\n *\n * @param wallet - The wallet to check within.\n * @param groupId - The account group ID to exclude from the check.\n * @param name - The name to validate for uniqueness.\n * @returns True if the name is unique within the wallet, false otherwise.\n */\nexport function isAccountGroupNameUniqueFromWallet(\n wallet: AccountWalletObject,\n groupId: AccountGroupId,\n name: string,\n): boolean {\n const trimmedName = name.trim();\n\n // Check for duplicates within this wallet\n for (const group of Object.values(wallet.groups)) {\n if (group.id !== groupId && group.metadata.name.trim() === trimmedName) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Checks if an account group name is unique within the same wallet.\n *\n * @param state - The account tree controller state.\n * @param groupId - The account group ID to exclude from the check.\n * @param name - The name to validate for uniqueness.\n * @returns True if the name is unique within the same wallet, false otherwise.\n * @throws Error if the group ID does not exist.\n */\nexport function isAccountGroupNameUnique(\n state: AccountTreeControllerState,\n groupId: AccountGroupId,\n name: string,\n): boolean {\n // Find the wallet that contains the group being validated\n for (const wallet of Object.values(state.accountTree.wallets)) {\n if (wallet.groups[groupId]) {\n // Use the wallet-specific function for consistency\n return isAccountGroupNameUniqueFromWallet(wallet, groupId, name);\n }\n }\n\n throw new Error(`Account group with ID \"${groupId}\" not found in tree`);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entropy.cjs","sourceRoot":"","sources":["../../src/rules/entropy.ts"],"names":[],"mappings":";;;AAAA,uDAM+B;AAC/B,uDAAyD;AACzD,qEAA4D;AAI5D,sCAA+D;AAG/D,MAAa,WACX,SAAQ,eAAQ;IADlB;;QAIW,eAAU,GAAG,+BAAiB,CAAC,OAAO,CAAC;QAEvC,cAAS,GAAG,8BAAgB,CAAC,iBAAiB,CAAC;IA4F1D,CAAC;IA1FC,qBAAqB,CAAC,aAAqB;QACzC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAEvE,OAAO,QAAQ;aACZ,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,EAAa,CAAC;aACjE,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,aAAa,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CACH,OAAwB;QAIxB,IAAI,CAAC,IAAA,4BAAc,EAAC,OAAO,CAAC,EAAE;
|
|
1
|
+
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\n toMultichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountGroupObjectOf } from '../group';\nimport { BaseRule, type Rule, type RuleResult } from '../rule';\nimport type { AccountWalletObjectOf } from '../wallet';\n\nexport class EntropyRule\n extends BaseRule\n implements Rule<AccountWalletType.Entropy, AccountGroupType.MultichainAccount>\n{\n readonly walletType = AccountWalletType.Entropy;\n\n readonly groupType = AccountGroupType.MultichainAccount;\n\n getEntropySourceIndex(entropySource: string) {\n const { keyrings } = this.messenger.call('KeyringController:getState');\n\n return keyrings\n .filter((keyring) => keyring.type === (KeyringTypes.hd as string))\n .findIndex((keyring) => keyring.metadata.id === entropySource);\n }\n\n match(\n account: InternalAccount,\n ):\n | RuleResult<AccountWalletType.Entropy, AccountGroupType.MultichainAccount>\n | undefined {\n if (!isBip44Account(account)) {\n return undefined;\n }\n\n const entropySource = account.options.entropy.id;\n const entropySourceIndex = this.getEntropySourceIndex(entropySource);\n if (entropySourceIndex === -1) {\n console.warn(\n `! Found an unknown entropy ID: \"${entropySource}\", account \"${account.id}\" won't be grouped by entropy.`,\n );\n return undefined;\n }\n\n const walletId = toMultichainAccountWalletId(entropySource);\n const groupId = toMultichainAccountGroupId(\n walletId,\n account.options.entropy.groupIndex,\n );\n\n return {\n wallet: {\n type: this.walletType,\n id: walletId,\n metadata: {\n entropy: {\n id: entropySource,\n },\n },\n },\n\n group: {\n type: this.groupType,\n id: groupId,\n metadata: {\n entropy: {\n groupIndex: account.options.entropy.groupIndex,\n },\n pinned: false,\n hidden: false,\n },\n },\n };\n }\n\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<AccountWalletType.Entropy>,\n ): string {\n // NOTE: We have checked during the rule matching, so we can safely assume it will\n // well-defined here.\n const entropySourceIndex = this.getEntropySourceIndex(\n wallet.metadata.entropy.id,\n );\n\n return `Wallet ${entropySourceIndex + 1}`; // Use human indexing (starts at 1).\n }\n\n getComputedAccountGroupName(\n group: AccountGroupObjectOf<AccountGroupType.MultichainAccount>,\n ): string {\n // Only use EVM account names for multichain groups to avoid chain-specific names becoming group names.\n // Non-EVM account names should not be used as group names since groups represent multichain collections.\n for (const id of group.accounts) {\n const account = this.messenger.call('AccountsController:getAccount', id);\n\n if (account && isEvmAccountType(account.type)) {\n return account.metadata.name;\n }\n }\n\n return '';\n }\n\n getDefaultAccountGroupPrefix(\n _wallet: AccountWalletObjectOf<AccountWalletType.Entropy>,\n ): string {\n return 'Account';\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entropy.mjs","sourceRoot":"","sources":["../../src/rules/entropy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,0BAA0B,EAC1B,2BAA2B,EAC5B,8BAA8B;AAC/B,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EAAE,QAAQ,EAA8B,oBAAgB;AAG/D,MAAM,OAAO,WACX,SAAQ,QAAQ;IADlB;;QAIW,eAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC;QAEvC,cAAS,GAAG,gBAAgB,CAAC,iBAAiB,CAAC;IA4F1D,CAAC;IA1FC,qBAAqB,CAAC,aAAqB;QACzC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAEvE,OAAO,QAAQ;aACZ,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAM,YAAY,CAAC,EAAa,CAAC;aACjE,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,aAAa,CAAC,CAAC;IACnE,CAAC;I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AC,QAAQ,CAAC,IAAI,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4BAA4B,CAC1B,OAAyD;QAEzD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import {\n AccountGroupType,\n AccountWalletType,\n isBip44Account,\n toMultichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountGroupObjectOf } from '../group';\nimport { BaseRule, type Rule, type RuleResult } from '../rule';\nimport type { AccountWalletObjectOf } from '../wallet';\n\nexport class EntropyRule\n extends BaseRule\n implements Rule<AccountWalletType.Entropy, AccountGroupType.MultichainAccount>\n{\n readonly walletType = AccountWalletType.Entropy;\n\n readonly groupType = AccountGroupType.MultichainAccount;\n\n getEntropySourceIndex(entropySource: string) {\n const { keyrings } = this.messenger.call('KeyringController:getState');\n\n return keyrings\n .filter((keyring) => keyring.type === (KeyringTypes.hd as string))\n .findIndex((keyring) => keyring.metadata.id === entropySource);\n }\n\n match(\n account: InternalAccount,\n ):\n | RuleResult<AccountWalletType.Entropy, AccountGroupType.MultichainAccount>\n | undefined {\n if (!isBip44Account(account)) {\n return undefined;\n }\n\n const entropySource = account.options.entropy.id;\n const entropySourceIndex = this.getEntropySourceIndex(entropySource);\n if (entropySourceIndex === -1) {\n console.warn(\n `! Found an unknown entropy ID: \"${entropySource}\", account \"${account.id}\" won't be grouped by entropy.`,\n );\n return undefined;\n }\n\n const walletId = toMultichainAccountWalletId(entropySource);\n const groupId = toMultichainAccountGroupId(\n walletId,\n account.options.entropy.groupIndex,\n );\n\n return {\n wallet: {\n type: this.walletType,\n id: walletId,\n metadata: {\n entropy: {\n id: entropySource,\n },\n },\n },\n\n group: {\n type: this.groupType,\n id: groupId,\n metadata: {\n entropy: {\n groupIndex: account.options.entropy.groupIndex,\n },\n pinned: false,\n hidden: false,\n },\n },\n };\n }\n\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<AccountWalletType.Entropy>,\n ): string {\n // NOTE: We have checked during the rule matching, so we can safely assume it will\n // well-defined here.\n const entropySourceIndex = this.getEntropySourceIndex(\n wallet.metadata.entropy.id,\n );\n\n return `Wallet ${entropySourceIndex + 1}`; // Use human indexing (starts at 1).\n }\n\n getComputedAccountGroupName(\n group: AccountGroupObjectOf<AccountGroupType.MultichainAccount>,\n ): string {\n // Only use EVM account names for multichain groups to avoid chain-specific names becoming group names.\n // Non-EVM account names should not be used as group names since groups represent multichain collections.\n for (const id of group.accounts) {\n const account = this.messenger.call('AccountsController:getAccount', id);\n\n if (account && isEvmAccountType(account.type)) {\n return account.metadata.name;\n }\n }\n\n return '';\n }\n\n getDefaultAccountGroupPrefix(\n _wallet: AccountWalletObjectOf<AccountWalletType.Entropy>,\n ): string {\n return 'Account';\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.cjs","sourceRoot":"","sources":["../../src/rules/keyring.ts"],"names":[],"mappings":";;;AAAA,uDAAyD;AACzD,uDAA0D;AAC1D,uDAA4E;AAC5E,qEAA4D;AAI5D,sCAA+D;AAG/D;;;;;GAKG;AACH,SAAgB,mCAAmC,CAAC,IAAkB;IACpE,QAAQ,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"keyring.cjs","sourceRoot":"","sources":["../../src/rules/keyring.ts"],"names":[],"mappings":";;;AAAA,uDAAyD;AACzD,uDAA0D;AAC1D,uDAA4E;AAC5E,qEAA4D;AAI5D,sCAA+D;AAG/D;;;;;GAKG;AACH,SAAgB,mCAAmC,CAAC,IAAkB;IACpE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC,CAAC;YACzB,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QACD,KAAK,iCAAY,CAAC,MAAM,CAAC,C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,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED,2BAA2B,CACzB,KAA2D;QAE3D,OAAO,KAAK,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,4BAA4B,CAC1B,MAAwD;QAExD,OAAO,oCAAoC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;CACF;AAzDD,kCAyDC","sourcesContent":["import { AccountGroupType } from '@metamask/account-api';\nimport { AccountWalletType } from '@metamask/account-api';\nimport { toAccountGroupId, toAccountWalletId } from '@metamask/account-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountGroupObjectOf } from '../group';\nimport { BaseRule, type Rule, type RuleResult } from '../rule';\nimport type { AccountWalletObjectOf } from '../wallet';\n\n/**\n * Get wallet name from a keyring type.\n *\n * @param type - Keyring's type.\n * @returns Wallet name.\n */\nexport function getAccountWalletNameFromKeyringType(type: KeyringTypes) {\n switch (type) {\n case KeyringTypes.simple: {\n return 'Imported accounts';\n }\n case KeyringTypes.trezor: {\n return 'Trezor';\n }\n case KeyringTypes.oneKey: {\n return 'OneKey';\n }\n case KeyringTypes.ledger: {\n return 'Ledger';\n }\n case KeyringTypes.lattice: {\n return 'Lattice';\n }\n case KeyringTypes.qr: {\n return 'QR';\n }\n // Those keyrings should never really be used in such context since they\n // should be used by other grouping rules.\n case KeyringTypes.hd: {\n return 'HD Wallet';\n }\n case KeyringTypes.snap: {\n return 'Snap Wallet';\n }\n // ------------------------------------------------------------------------\n default: {\n return 'Unknown';\n }\n }\n}\n\n/**\n * Get group name prefix from a keyring type.\n *\n * @param type - Keyring's type.\n * @returns Wallet name.\n */\nexport function getAccountGroupPrefixFromKeyringType(type: KeyringTypes) {\n switch (type) {\n case KeyringTypes.simple: {\n return 'Imported Account';\n }\n case KeyringTypes.trezor: {\n return 'Trezor Account';\n }\n case KeyringTypes.oneKey: {\n return 'OneKey Account';\n }\n case KeyringTypes.ledger: {\n return 'Ledger Account';\n }\n case KeyringTypes.lattice: {\n return 'Lattice Account';\n }\n case KeyringTypes.qr: {\n return 'QR Account';\n }\n // Those keyrings should never really be used in such context since they\n // should be used by other grouping rules.\n case KeyringTypes.hd: {\n return 'Account';\n }\n case KeyringTypes.snap: {\n return 'Snap Account';\n }\n // ------------------------------------------------------------------------\n default: {\n return 'Unknown Account';\n }\n }\n}\n\nexport class KeyringRule\n extends BaseRule\n implements Rule<AccountWalletType.Keyring, AccountGroupType.SingleAccount>\n{\n readonly walletType = AccountWalletType.Keyring;\n\n readonly groupType = AccountGroupType.SingleAccount;\n\n match(\n account: InternalAccount,\n // No `| undefined` return type for this rule, as it cannot fail.\n ): RuleResult<AccountWalletType.Keyring, AccountGroupType.SingleAccount> {\n // We assume that `type` is really a `KeyringTypes`.\n const keyringType = account.metadata.keyring.type as KeyringTypes;\n\n const walletId = toAccountWalletId(this.walletType, keyringType);\n const groupId = toAccountGroupId(walletId, account.address);\n\n return {\n wallet: {\n type: this.walletType,\n id: walletId,\n metadata: {\n keyring: {\n type: keyringType,\n },\n },\n },\n\n group: {\n type: this.groupType,\n id: groupId,\n metadata: {\n pinned: false,\n hidden: false,\n },\n },\n };\n }\n\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<AccountWalletType.Keyring>,\n ): string {\n return getAccountWalletNameFromKeyringType(wallet.metadata.keyring.type);\n }\n\n getComputedAccountGroupName(\n group: AccountGroupObjectOf<AccountGroupType.SingleAccount>,\n ): string {\n return super.getComputedAccountGroupName(group);\n }\n\n getDefaultAccountGroupPrefix(\n wallet: AccountWalletObjectOf<AccountWalletType.Keyring>,\n ): string {\n return getAccountGroupPrefixFromKeyringType(wallet.metadata.keyring.type);\n }\n}\n"]}
|