@metamask-previews/profile-sync-controller 24.0.0-preview-b13da658 → 24.0.0-preview-a421f85b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +0 -9
  2. package/dist/controllers/user-storage/UserStorageController.cjs +80 -4
  3. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  4. package/dist/controllers/user-storage/UserStorageController.d.cts +54 -5
  5. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  6. package/dist/controllers/user-storage/UserStorageController.d.mts +54 -5
  7. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  8. package/dist/controllers/user-storage/UserStorageController.mjs +76 -0
  9. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/account-syncing/constants.cjs +51 -0
  11. package/dist/controllers/user-storage/account-syncing/constants.cjs.map +1 -0
  12. package/dist/controllers/user-storage/account-syncing/constants.d.cts +4 -0
  13. package/dist/controllers/user-storage/account-syncing/constants.d.cts.map +1 -0
  14. package/dist/controllers/user-storage/account-syncing/constants.d.mts +4 -0
  15. package/dist/controllers/user-storage/account-syncing/constants.d.mts.map +1 -0
  16. package/dist/controllers/user-storage/account-syncing/constants.mjs +48 -0
  17. package/dist/controllers/user-storage/account-syncing/constants.mjs.map +1 -0
  18. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +271 -0
  19. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -0
  20. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +38 -0
  21. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -0
  22. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +38 -0
  23. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -0
  24. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +265 -0
  25. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -0
  26. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +41 -0
  27. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -0
  28. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +8 -0
  29. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -0
  30. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +8 -0
  31. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -0
  32. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +37 -0
  33. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -0
  34. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +61 -0
  35. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -0
  36. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +30 -0
  37. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -0
  38. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +30 -0
  39. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -0
  40. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +55 -0
  41. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -0
  42. package/dist/controllers/user-storage/account-syncing/types.cjs +3 -0
  43. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -0
  44. package/dist/controllers/user-storage/account-syncing/types.d.cts +25 -0
  45. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -0
  46. package/dist/controllers/user-storage/account-syncing/types.d.mts +25 -0
  47. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -0
  48. package/dist/controllers/user-storage/account-syncing/types.mjs +2 -0
  49. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -0
  50. package/dist/controllers/user-storage/account-syncing/utils.cjs +36 -0
  51. package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -0
  52. package/dist/controllers/user-storage/account-syncing/utils.d.cts +18 -0
  53. package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -0
  54. package/dist/controllers/user-storage/account-syncing/utils.d.mts +18 -0
  55. package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -0
  56. package/dist/controllers/user-storage/account-syncing/utils.mjs +31 -0
  57. package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -0
  58. package/dist/controllers/user-storage/constants.cjs +3 -0
  59. package/dist/controllers/user-storage/constants.cjs.map +1 -1
  60. package/dist/controllers/user-storage/constants.d.cts +2 -0
  61. package/dist/controllers/user-storage/constants.d.cts.map +1 -1
  62. package/dist/controllers/user-storage/constants.d.mts +2 -0
  63. package/dist/controllers/user-storage/constants.d.mts.map +1 -1
  64. package/dist/controllers/user-storage/constants.mjs +3 -0
  65. package/dist/controllers/user-storage/constants.mjs.map +1 -1
  66. package/package.json +3 -1
@@ -0,0 +1,55 @@
1
+ import { KeyringTypes } from "@metamask/keyring-controller";
2
+ import { USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
3
+ /**
4
+ * Checks if account syncing can be performed based on a set of conditions
5
+ *
6
+ * @param options - parameters used for checking if account syncing can be performed
7
+ * @returns Returns true if account syncing can be performed, false otherwise.
8
+ */
9
+ export function canPerformAccountSyncing(options) {
10
+ const { getMessenger, getUserStorageControllerInstance } = options;
11
+ const { isBackupAndSyncEnabled, isAccountSyncingEnabled, isAccountSyncingInProgress, } = getUserStorageControllerInstance().state;
12
+ const isAuthEnabled = getMessenger().call('AuthenticationController:isSignedIn');
13
+ if (!isBackupAndSyncEnabled ||
14
+ !isAccountSyncingEnabled ||
15
+ !isAuthEnabled ||
16
+ isAccountSyncingInProgress) {
17
+ return false;
18
+ }
19
+ return true;
20
+ }
21
+ /**
22
+ * Get the list of internal accounts
23
+ * This function returns only the internal accounts that are from the primary SRP
24
+ * and are from the HD keyring
25
+ *
26
+ * @param options - parameters used for getting the list of internal accounts
27
+ * @param entropySourceId - The entropy source ID used to derive the key,
28
+ * when multiple sources are available (Multi-SRP).
29
+ * @returns the list of internal accounts
30
+ */
31
+ export async function getInternalAccountsList(options, entropySourceId) {
32
+ const { getMessenger } = options;
33
+ let internalAccountsList = getMessenger().call('AccountsController:listAccounts');
34
+ const doEachInternalAccountHaveEntropySource = internalAccountsList.every((account) => Boolean(account.options.entropySource));
35
+ if (!doEachInternalAccountHaveEntropySource) {
36
+ await getMessenger().call('AccountsController:updateAccounts');
37
+ internalAccountsList = getMessenger().call('AccountsController:listAccounts');
38
+ }
39
+ return internalAccountsList.filter((account) => entropySourceId === account.options.entropySource &&
40
+ account.metadata.keyring.type === String(KeyringTypes.hd));
41
+ }
42
+ /**
43
+ * Get the list of user storage accounts
44
+ *
45
+ * @param options - parameters used for getting the list of user storage accounts
46
+ * @param entropySourceId - The entropy source ID used to derive the storage key,
47
+ * when multiple sources are available (Multi-SRP).
48
+ * @returns the list of user storage accounts
49
+ */
50
+ export async function getUserStorageAccountsList(options, entropySourceId) {
51
+ const { getUserStorageControllerInstance } = options;
52
+ const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(USER_STORAGE_FEATURE_NAMES.accounts, entropySourceId);
53
+ return (rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null);
54
+ }
55
+ //# sourceMappingURL=sync-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EACJ,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,GAC3B,GAAG,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,sBAAsB;QACvB,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B,EAC9B,eAAuB;IAEvB,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,IAAI,oBAAoB,GAAG,YAAY,EAAE,CAAC,IAAI,CAC5C,iCAAiC,CAClC,CAAC;IAEF,MAAM,sCAAsC,GAAG,oBAAoB,CAAC,KAAK,CACvE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CACpD,CAAC;IAEF,IAAI,CAAC,sCAAsC,EAAE;QAC3C,MAAM,YAAY,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QAC/D,oBAAoB,GAAG,YAAY,EAAE,CAAC,IAAI,CACxC,iCAAiC,CAClC,CAAC;KACH;IAED,OAAO,oBAAoB,CAAC,MAAM,CAChC,CAAC,OAAO,EAAE,EAAE,CACV,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,aAAa;QACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAC5D,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA8B,EAC9B,eAAwB;IAExB,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,0BAA0B,CAAC,QAAQ,EACnC,eAAe,CAChB,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isBackupAndSyncEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isBackupAndSyncEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n let internalAccountsList = getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n const doEachInternalAccountHaveEntropySource = internalAccountsList.every(\n (account) => Boolean(account.options.entropySource),\n );\n\n if (!doEachInternalAccountHaveEntropySource) {\n await getMessenger().call('AccountsController:updateAccounts');\n internalAccountsList = getMessenger().call(\n 'AccountsController:listAccounts',\n );\n }\n\n return internalAccountsList.filter(\n (account) =>\n entropySourceId === account.options.entropySource &&\n account.metadata.keyring.type === String(KeyringTypes.hd), // sync only EVM accounts until we support multichain accounts\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @param entropySourceId - The entropy source ID used to derive the storage key,\n * when multiple sources are available (Multi-SRP).\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n entropySourceId?: string,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceCallback } from '@metamask/controller-utils';\n\nimport type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n trace?: TraceCallback;\n};\n"]}
@@ -0,0 +1,25 @@
1
+ import type { TraceCallback } from "@metamask/controller-utils";
2
+ import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
3
+ import type { UserStorageControllerMessenger } from "../UserStorageController.cjs";
4
+ import type UserStorageController from "../UserStorageController.cjs";
5
+ export type UserStorageAccount = {
6
+ /**
7
+ * The Version 'v' of the User Storage.
8
+ * NOTE - will allow us to support upgrade/downgrades in the future
9
+ */
10
+ [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
11
+ /** the id 'i' of the account */
12
+ i: string;
13
+ /** the address 'a' of the account */
14
+ a: string;
15
+ /** the name 'n' of the account */
16
+ n: string;
17
+ /** the nameLastUpdatedAt timestamp 'nlu' of the account */
18
+ nlu?: number;
19
+ };
20
+ export type AccountSyncingOptions = {
21
+ getUserStorageControllerInstance: () => UserStorageController;
22
+ getMessenger: () => UserStorageControllerMessenger;
23
+ trace?: TraceCallback;
24
+ };
25
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;IACnD,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { TraceCallback } from "@metamask/controller-utils";
2
+ import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
3
+ import type { UserStorageControllerMessenger } from "../UserStorageController.mjs";
4
+ import type UserStorageController from "../UserStorageController.mjs";
5
+ export type UserStorageAccount = {
6
+ /**
7
+ * The Version 'v' of the User Storage.
8
+ * NOTE - will allow us to support upgrade/downgrades in the future
9
+ */
10
+ [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
11
+ /** the id 'i' of the account */
12
+ i: string;
13
+ /** the address 'a' of the account */
14
+ a: string;
15
+ /** the name 'n' of the account */
16
+ n: string;
17
+ /** the nameLastUpdatedAt timestamp 'nlu' of the account */
18
+ nlu?: number;
19
+ };
20
+ export type AccountSyncingOptions = {
21
+ getUserStorageControllerInstance: () => UserStorageController;
22
+ getMessenger: () => UserStorageControllerMessenger;
23
+ trace?: TraceCallback;
24
+ };
25
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAEhE,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;IACnD,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceCallback } from '@metamask/controller-utils';\n\nimport type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n trace?: TraceCallback;\n};\n"]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapInternalAccountToUserStorageAccount = exports.isNameDefaultAccountName = void 0;
4
+ const constants_1 = require("./constants.cjs");
5
+ /**
6
+ * Tells if the given name is a default account name.
7
+ * Default account names are localized names that are automatically generated by the clients.
8
+ *
9
+ * @param name - the name to check
10
+ * @returns true if the name is a default account name, false otherwise
11
+ */
12
+ const isNameDefaultAccountName = (name) => {
13
+ return constants_1.LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {
14
+ return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);
15
+ });
16
+ };
17
+ exports.isNameDefaultAccountName = isNameDefaultAccountName;
18
+ /**
19
+ * Map an internal account to a user storage account
20
+ *
21
+ * @param internalAccount - An internal account
22
+ * @returns A user storage account
23
+ */
24
+ const mapInternalAccountToUserStorageAccount = (internalAccount) => {
25
+ const { address, id, metadata } = internalAccount;
26
+ const { name, nameLastUpdatedAt } = metadata;
27
+ return {
28
+ [constants_1.USER_STORAGE_VERSION_KEY]: constants_1.USER_STORAGE_VERSION,
29
+ a: address,
30
+ i: id,
31
+ n: name,
32
+ ...((0, exports.isNameDefaultAccountName)(name) ? {} : { nlu: nameLastUpdatedAt }),
33
+ };
34
+ };
35
+ exports.mapInternalAccountToUserStorageAccount = mapInternalAccountToUserStorageAccount;
36
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":";;;AAEA,+CAIqB;AAGrB;;;;;;GAMG;AAEI,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,2CAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC;AAEF;;;;;GAKG;AACI,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,oCAAwB,CAAC,EAAE,gCAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,sCAAsC,0CAajD","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\nimport type { UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n"]}
@@ -0,0 +1,18 @@
1
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
+ import type { UserStorageAccount } from "./types.cjs";
3
+ /**
4
+ * Tells if the given name is a default account name.
5
+ * Default account names are localized names that are automatically generated by the clients.
6
+ *
7
+ * @param name - the name to check
8
+ * @returns true if the name is a default account name, false otherwise
9
+ */
10
+ export declare const isNameDefaultAccountName: (name: string) => boolean;
11
+ /**
12
+ * Map an internal account to a user storage account
13
+ *
14
+ * @param internalAccount - An internal account
15
+ * @returns A user storage account
16
+ */
17
+ export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
18
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
+ import type { UserStorageAccount } from "./types.mjs";
3
+ /**
4
+ * Tells if the given name is a default account name.
5
+ * Default account names are localized names that are automatically generated by the clients.
6
+ *
7
+ * @param name - the name to check
8
+ * @returns true if the name is a default account name, false otherwise
9
+ */
10
+ export declare const isNameDefaultAccountName: (name: string) => boolean;
11
+ /**
12
+ * Map an internal account to a user storage account
13
+ *
14
+ * @param internalAccount - An internal account
15
+ * @returns A user storage account
16
+ */
17
+ export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
18
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION, LOCALIZED_DEFAULT_ACCOUNT_NAMES } from "./constants.mjs";
2
+ /**
3
+ * Tells if the given name is a default account name.
4
+ * Default account names are localized names that are automatically generated by the clients.
5
+ *
6
+ * @param name - the name to check
7
+ * @returns true if the name is a default account name, false otherwise
8
+ */
9
+ export const isNameDefaultAccountName = (name) => {
10
+ return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {
11
+ return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);
12
+ });
13
+ };
14
+ /**
15
+ * Map an internal account to a user storage account
16
+ *
17
+ * @param internalAccount - An internal account
18
+ * @returns A user storage account
19
+ */
20
+ export const mapInternalAccountToUserStorageAccount = (internalAccount) => {
21
+ const { address, id, metadata } = internalAccount;
22
+ const { name, nameLastUpdatedAt } = metadata;
23
+ return {
24
+ [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,
25
+ a: address,
26
+ i: id,
27
+ n: name,
28
+ ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),
29
+ };
30
+ };
31
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAChC,wBAAoB;AAGrB;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,+BAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,wBAAwB,CAAC,EAAE,oBAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\nimport type { UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n"]}
@@ -15,5 +15,8 @@ exports.TraceName = {
15
15
  ContactSyncSaveBatch: 'Contact Sync Save Batch',
16
16
  ContactSyncUpdateRemote: 'Contact Sync Update Remote',
17
17
  ContactSyncDeleteRemote: 'Contact Sync Delete Remote',
18
+ // Account syncing traces
19
+ AccountSyncFull: 'Account Sync Full',
20
+ AccountSyncSaveIndividual: 'Account Sync Save Individual',
18
21
  };
19
22
  //# sourceMappingURL=constants.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IACpC,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAEX;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,oBAAoB,EAAE,yBAAyB;IAC/C,uBAAuB,EAAE,4BAA4B;IACrD,uBAAuB,EAAE,4BAA4B;CAC7C,CAAC","sourcesContent":["export const BACKUPANDSYNC_FEATURES = {\n main: 'main',\n accountSyncing: 'accountSyncing',\n contactSyncing: 'contactSyncing',\n} as const;\n\n/**\n * Trace names for UserStorage syncing operations\n */\nexport const TraceName = {\n // Contact syncing traces\n ContactSyncFull: 'Contact Sync Full',\n ContactSyncSaveBatch: 'Contact Sync Save Batch',\n ContactSyncUpdateRemote: 'Contact Sync Update Remote',\n ContactSyncDeleteRemote: 'Contact Sync Delete Remote',\n} as const;\n"]}
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG;IACpC,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAEX;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,oBAAoB,EAAE,yBAAyB;IAC/C,uBAAuB,EAAE,4BAA4B;IACrD,uBAAuB,EAAE,4BAA4B;IAErD,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,yBAAyB,EAAE,8BAA8B;CACjD,CAAC","sourcesContent":["export const BACKUPANDSYNC_FEATURES = {\n main: 'main',\n accountSyncing: 'accountSyncing',\n contactSyncing: 'contactSyncing',\n} as const;\n\n/**\n * Trace names for UserStorage syncing operations\n */\nexport const TraceName = {\n // Contact syncing traces\n ContactSyncFull: 'Contact Sync Full',\n ContactSyncSaveBatch: 'Contact Sync Save Batch',\n ContactSyncUpdateRemote: 'Contact Sync Update Remote',\n ContactSyncDeleteRemote: 'Contact Sync Delete Remote',\n\n // Account syncing traces\n AccountSyncFull: 'Account Sync Full',\n AccountSyncSaveIndividual: 'Account Sync Save Individual',\n} as const;\n"]}
@@ -11,5 +11,7 @@ export declare const TraceName: {
11
11
  readonly ContactSyncSaveBatch: "Contact Sync Save Batch";
12
12
  readonly ContactSyncUpdateRemote: "Contact Sync Update Remote";
13
13
  readonly ContactSyncDeleteRemote: "Contact Sync Delete Remote";
14
+ readonly AccountSyncFull: "Account Sync Full";
15
+ readonly AccountSyncSaveIndividual: "Account Sync Save Individual";
14
16
  };
15
17
  //# sourceMappingURL=constants.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;CAMZ,CAAC"}
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;CAUZ,CAAC"}
@@ -11,5 +11,7 @@ export declare const TraceName: {
11
11
  readonly ContactSyncSaveBatch: "Contact Sync Save Batch";
12
12
  readonly ContactSyncUpdateRemote: "Contact Sync Update Remote";
13
13
  readonly ContactSyncDeleteRemote: "Contact Sync Delete Remote";
14
+ readonly AccountSyncFull: "Account Sync Full";
15
+ readonly AccountSyncSaveIndividual: "Account Sync Save Individual";
14
16
  };
15
17
  //# sourceMappingURL=constants.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;CAMZ,CAAC"}
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;CAUZ,CAAC"}
@@ -12,5 +12,8 @@ export const TraceName = {
12
12
  ContactSyncSaveBatch: 'Contact Sync Save Batch',
13
13
  ContactSyncUpdateRemote: 'Contact Sync Update Remote',
14
14
  ContactSyncDeleteRemote: 'Contact Sync Delete Remote',
15
+ // Account syncing traces
16
+ AccountSyncFull: 'Account Sync Full',
17
+ AccountSyncSaveIndividual: 'Account Sync Save Individual',
15
18
  };
16
19
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,oBAAoB,EAAE,yBAAyB;IAC/C,uBAAuB,EAAE,4BAA4B;IACrD,uBAAuB,EAAE,4BAA4B;CAC7C,CAAC","sourcesContent":["export const BACKUPANDSYNC_FEATURES = {\n main: 'main',\n accountSyncing: 'accountSyncing',\n contactSyncing: 'contactSyncing',\n} as const;\n\n/**\n * Trace names for UserStorage syncing operations\n */\nexport const TraceName = {\n // Contact syncing traces\n ContactSyncFull: 'Contact Sync Full',\n ContactSyncSaveBatch: 'Contact Sync Save Batch',\n ContactSyncUpdateRemote: 'Contact Sync Update Remote',\n ContactSyncDeleteRemote: 'Contact Sync Delete Remote',\n} as const;\n"]}
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,oBAAoB,EAAE,yBAAyB;IAC/C,uBAAuB,EAAE,4BAA4B;IACrD,uBAAuB,EAAE,4BAA4B;IAErD,yBAAyB;IACzB,eAAe,EAAE,mBAAmB;IACpC,yBAAyB,EAAE,8BAA8B;CACjD,CAAC","sourcesContent":["export const BACKUPANDSYNC_FEATURES = {\n main: 'main',\n accountSyncing: 'accountSyncing',\n contactSyncing: 'contactSyncing',\n} as const;\n\n/**\n * Trace names for UserStorage syncing operations\n */\nexport const TraceName = {\n // Contact syncing traces\n ContactSyncFull: 'Contact Sync Full',\n ContactSyncSaveBatch: 'Contact Sync Save Batch',\n ContactSyncUpdateRemote: 'Contact Sync Update Remote',\n ContactSyncDeleteRemote: 'Contact Sync Delete Remote',\n\n // Account syncing traces\n AccountSyncFull: 'Account Sync Full',\n AccountSyncSaveIndividual: 'Account Sync Save Individual',\n} as const;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/profile-sync-controller",
3
- "version": "24.0.0-preview-b13da658",
3
+ "version": "24.0.0-preview-a421f85b",
4
4
  "description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -112,6 +112,7 @@
112
112
  "devDependencies": {
113
113
  "@lavamoat/allow-scripts": "^3.0.4",
114
114
  "@lavamoat/preinstall-always-fail": "^2.1.0",
115
+ "@metamask/accounts-controller": "^33.0.0",
115
116
  "@metamask/auto-changelog": "^3.4.4",
116
117
  "@metamask/keyring-api": "^20.1.0",
117
118
  "@metamask/keyring-controller": "^23.0.0",
@@ -131,6 +132,7 @@
131
132
  "webextension-polyfill": "^0.12.0"
132
133
  },
133
134
  "peerDependencies": {
135
+ "@metamask/accounts-controller": "^33.0.0",
134
136
  "@metamask/keyring-controller": "^23.0.0",
135
137
  "@metamask/providers": "^22.0.0",
136
138
  "@metamask/snaps-controllers": "^14.0.0",