@metamask-previews/profile-sync-controller 3.1.1-preview-e218ba33 → 3.1.1-preview-2983d87f

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 (94) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/controllers/user-storage/UserStorageController.cjs +218 -39
  3. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  4. package/dist/controllers/user-storage/UserStorageController.d.cts +1 -6
  5. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  6. package/dist/controllers/user-storage/UserStorageController.d.mts +1 -6
  7. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  8. package/dist/controllers/user-storage/UserStorageController.mjs +215 -36
  9. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/{account-syncing/__fixtures__ → __fixtures__}/mockAccounts.cjs +3 -3
  11. package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs.map +1 -0
  12. package/dist/controllers/user-storage/{account-syncing/__fixtures__ → __fixtures__}/mockAccounts.d.cts +6 -6
  13. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts.map +1 -0
  14. package/dist/controllers/user-storage/{account-syncing/__fixtures__ → __fixtures__}/mockAccounts.d.mts +6 -6
  15. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts.map +1 -0
  16. package/dist/controllers/user-storage/{account-syncing/__fixtures__ → __fixtures__}/mockAccounts.mjs +2 -2
  17. package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs.map +1 -0
  18. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +1 -45
  19. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -1
  20. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +0 -21
  21. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -1
  22. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +0 -21
  23. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -1
  24. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +0 -38
  25. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -1
  26. package/dist/controllers/user-storage/accounts/constants.cjs.map +1 -0
  27. package/dist/controllers/user-storage/accounts/constants.d.cts.map +1 -0
  28. package/dist/controllers/user-storage/accounts/constants.d.mts.map +1 -0
  29. package/dist/controllers/user-storage/accounts/constants.mjs.map +1 -0
  30. package/dist/controllers/user-storage/{account-syncing/utils.cjs → accounts/user-storage.cjs} +2 -12
  31. package/dist/controllers/user-storage/accounts/user-storage.cjs.map +1 -0
  32. package/dist/controllers/user-storage/{account-syncing/utils.d.mts → accounts/user-storage.d.cts} +17 -8
  33. package/dist/controllers/user-storage/accounts/user-storage.d.cts.map +1 -0
  34. package/dist/controllers/user-storage/{account-syncing/utils.d.cts → accounts/user-storage.d.mts} +17 -8
  35. package/dist/controllers/user-storage/accounts/user-storage.d.mts.map +1 -0
  36. package/dist/controllers/user-storage/{account-syncing/utils.mjs → accounts/user-storage.mjs} +1 -10
  37. package/dist/controllers/user-storage/accounts/user-storage.mjs.map +1 -0
  38. package/package.json +2 -2
  39. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +0 -1
  40. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +0 -1
  41. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +0 -1
  42. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +0 -1
  43. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +0 -50
  44. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +0 -1
  45. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +0 -85
  46. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +0 -1
  47. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +0 -85
  48. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +0 -1
  49. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +0 -44
  50. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +0 -1
  51. package/dist/controllers/user-storage/account-syncing/constants.cjs.map +0 -1
  52. package/dist/controllers/user-storage/account-syncing/constants.d.cts.map +0 -1
  53. package/dist/controllers/user-storage/account-syncing/constants.d.mts.map +0 -1
  54. package/dist/controllers/user-storage/account-syncing/constants.mjs.map +0 -1
  55. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +0 -194
  56. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +0 -1
  57. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +0 -31
  58. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +0 -1
  59. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +0 -31
  60. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +0 -1
  61. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +0 -188
  62. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +0 -1
  63. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +0 -35
  64. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +0 -1
  65. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +0 -8
  66. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +0 -1
  67. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +0 -8
  68. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +0 -1
  69. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +0 -31
  70. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +0 -1
  71. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +0 -47
  72. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +0 -1
  73. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +0 -20
  74. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +0 -1
  75. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +0 -20
  76. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +0 -1
  77. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +0 -41
  78. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +0 -1
  79. package/dist/controllers/user-storage/account-syncing/types.cjs +0 -3
  80. package/dist/controllers/user-storage/account-syncing/types.cjs.map +0 -1
  81. package/dist/controllers/user-storage/account-syncing/types.d.cts +0 -26
  82. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +0 -1
  83. package/dist/controllers/user-storage/account-syncing/types.d.mts +0 -26
  84. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +0 -1
  85. package/dist/controllers/user-storage/account-syncing/types.mjs +0 -2
  86. package/dist/controllers/user-storage/account-syncing/types.mjs.map +0 -1
  87. package/dist/controllers/user-storage/account-syncing/utils.cjs.map +0 -1
  88. package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +0 -1
  89. package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +0 -1
  90. package/dist/controllers/user-storage/account-syncing/utils.mjs.map +0 -1
  91. /package/dist/controllers/user-storage/{account-syncing → accounts}/constants.cjs +0 -0
  92. /package/dist/controllers/user-storage/{account-syncing → accounts}/constants.d.cts +0 -0
  93. /package/dist/controllers/user-storage/{account-syncing → accounts}/constants.d.mts +0 -0
  94. /package/dist/controllers/user-storage/{account-syncing → accounts}/constants.mjs +0 -0
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doesInternalAccountHaveCorrectKeyringType = exports.mapInternalAccountToUserStorageAccount = exports.isNameDefaultAccountName = void 0;
4
- const keyring_controller_1 = require("@metamask/keyring-controller");
3
+ exports.mapInternalAccountToUserStorageAccount = exports.isNameDefaultAccountName = void 0;
5
4
  const constants_1 = require("./constants.cjs");
6
5
  /**
7
6
  * Tells if the given name is a default account name.
@@ -33,13 +32,4 @@ const mapInternalAccountToUserStorageAccount = (internalAccount) => {
33
32
  };
34
33
  };
35
34
  exports.mapInternalAccountToUserStorageAccount = mapInternalAccountToUserStorageAccount;
36
- /**
37
- * Checks if the given internal account has the correct keyring type.
38
- * @param account - The internal account to check
39
- * @returns Returns true if the internal account has the correct keyring type, false otherwise.
40
- */
41
- function doesInternalAccountHaveCorrectKeyringType(account) {
42
- return account.metadata.keyring.type === keyring_controller_1.KeyringTypes.hd;
43
- }
44
- exports.doesInternalAccountHaveCorrectKeyringType = doesInternalAccountHaveCorrectKeyringType;
45
- //# sourceMappingURL=utils.cjs.map
35
+ //# sourceMappingURL=user-storage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-storage.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":";;;AAEA,+CAIqB;AAkBrB;;;;;;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;;;;GAIG;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';\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\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 * @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"]}
@@ -1,5 +1,20 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { UserStorageAccount } from "./types.mjs";
2
+ import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
3
+ export type UserStorageAccount = {
4
+ /**
5
+ * The Version 'v' of the User Storage.
6
+ * NOTE - will allow us to support upgrade/downgrades in the future
7
+ */
8
+ [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
9
+ /** the id 'i' of the account */
10
+ i: string;
11
+ /** the address 'a' of the account */
12
+ a: string;
13
+ /** the name 'n' of the account */
14
+ n: string;
15
+ /** the nameLastUpdatedAt timestamp 'nlu' of the account */
16
+ nlu?: number;
17
+ };
3
18
  /**
4
19
  * Tells if the given name is a default account name.
5
20
  * Default account names are localized names that are automatically generated by the clients.
@@ -14,10 +29,4 @@ export declare const isNameDefaultAccountName: (name: string) => boolean;
14
29
  * @returns A user storage account
15
30
  */
16
31
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
17
- /**
18
- * Checks if the given internal account has the correct keyring type.
19
- * @param account - The internal account to check
20
- * @returns Returns true if the internal account has the correct keyring type, false otherwise.
21
- */
22
- export declare function doesInternalAccountHaveCorrectKeyringType(account: InternalAccount): boolean;
23
- //# sourceMappingURL=utils.d.mts.map
32
+ //# sourceMappingURL=user-storage.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-storage.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EAErB,wBAAoB;AAErB,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;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
@@ -1,5 +1,20 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { UserStorageAccount } from "./types.cjs";
2
+ import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
3
+ export type UserStorageAccount = {
4
+ /**
5
+ * The Version 'v' of the User Storage.
6
+ * NOTE - will allow us to support upgrade/downgrades in the future
7
+ */
8
+ [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
9
+ /** the id 'i' of the account */
10
+ i: string;
11
+ /** the address 'a' of the account */
12
+ a: string;
13
+ /** the name 'n' of the account */
14
+ n: string;
15
+ /** the nameLastUpdatedAt timestamp 'nlu' of the account */
16
+ nlu?: number;
17
+ };
3
18
  /**
4
19
  * Tells if the given name is a default account name.
5
20
  * Default account names are localized names that are automatically generated by the clients.
@@ -14,10 +29,4 @@ export declare const isNameDefaultAccountName: (name: string) => boolean;
14
29
  * @returns A user storage account
15
30
  */
16
31
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
17
- /**
18
- * Checks if the given internal account has the correct keyring type.
19
- * @param account - The internal account to check
20
- * @returns Returns true if the internal account has the correct keyring type, false otherwise.
21
- */
22
- export declare function doesInternalAccountHaveCorrectKeyringType(account: InternalAccount): boolean;
23
- //# sourceMappingURL=utils.d.cts.map
32
+ //# sourceMappingURL=user-storage.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-storage.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EAErB,wBAAoB;AAErB,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;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
@@ -1,4 +1,3 @@
1
- import { KeyringTypes } from "@metamask/keyring-controller";
2
1
  import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION, LOCALIZED_DEFAULT_ACCOUNT_NAMES } from "./constants.mjs";
3
2
  /**
4
3
  * Tells if the given name is a default account name.
@@ -28,12 +27,4 @@ export const mapInternalAccountToUserStorageAccount = (internalAccount) => {
28
27
  ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),
29
28
  };
30
29
  };
31
- /**
32
- * Checks if the given internal account has the correct keyring type.
33
- * @param account - The internal account to check
34
- * @returns Returns true if the internal account has the correct keyring type, false otherwise.
35
- */
36
- export function doesInternalAccountHaveCorrectKeyringType(account) {
37
- return account.metadata.keyring.type === KeyringTypes.hd;
38
- }
39
- //# sourceMappingURL=utils.mjs.map
30
+ //# sourceMappingURL=user-storage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-storage.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/accounts/user-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAChC,wBAAoB;AAkBrB;;;;;;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;;;;GAIG;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';\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\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 * @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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/profile-sync-controller",
3
- "version": "3.1.1-preview-e218ba33",
3
+ "version": "3.1.1-preview-2983d87f",
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",
@@ -100,7 +100,7 @@
100
100
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
101
101
  },
102
102
  "dependencies": {
103
- "@metamask/base-controller": "^7.0.2",
103
+ "@metamask/base-controller": "^7.1.0",
104
104
  "@metamask/keyring-api": "^12.0.0",
105
105
  "@metamask/keyring-controller": "^19.0.2",
106
106
  "@metamask/network-controller": "^22.1.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockAccounts.cjs","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,qEAA4D;AAG5D,gDAA+D;AAC/D,wCAAkE;AAElE;;;;;GAKG;AACH,MAAM,gDAAgD,GAAG,CACvD,gBAAmC,E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EAAE,CAAC;gBACpB,OAAO,EAAE;oBACP,IAAI,EAAE,iCAAY,CAAC,EAAE;iBACtB;aACF;SACF;KACF;CACF,CAAC;AAEW,QAAA,0BAA0B,GAAG;IACxC,oBAAoB,EAAE,gDAAgD,CACpE,8BAAsB,CAAC,GAAwB,CAChD;IACD,GAAG,EAAE,gDAAgD,CACnD,8BAAsB,CAAC,GAAwB,CAChD;IACD,gCAAgC,EAC9B,gDAAgD,CAAC;QAC/C,GAAG,8BAAsB,CAAC,gBAAgB;QAC1C;YACE,GAAG,8BAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAC7C,OAAO,EAAE,UAAU;YACnB,QAAQ,EAAE;gBACR,IAAI,EAAE,GAAG,IAAA,uCAA+B,GAAE,IAAI;gBAC9C,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;IACzB,gBAAgB,EAAE,gDAAgD,CAChE,8BAAsB,CAAC,gBAAqC,CAC7D;IACD,oCAAoC,EAClC,gDAAgD,CAAC;QAC/C;YACE,GAAG,8BAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,4DAA4D;aACnE;SACF;KACmB,CAAC;IACzB,iCAAiC,EAC/B,gDAAgD,CAAC;QAC/C;YACE,GAAG,8BAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,yDAAyD;gBAC/D,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;CAC1B,CAAC","sourcesContent":["import { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { LOCALIZED_DEFAULT_ACCOUNT_NAMES } from '../constants';\nimport { mapInternalAccountToUserStorageAccount } from '../utils';\n\n/**\n * Map an array of internal accounts to an array of user storage accounts\n * Only used for testing purposes\n * @param internalAccounts - An array of internal accounts\n * @returns An array of user storage accounts\n */\nconst mapInternalAccountsListToUserStorageAccountsList = (\n internalAccounts: InternalAccount[],\n) => internalAccounts.map(mapInternalAccountToUserStorageAccount);\n\n/**\n * Get a random default account name from the list of localized default account names\n * @returns A random default account name\n */\nexport const getMockRandomDefaultAccountName = () =>\n LOCALIZED_DEFAULT_ACCOUNT_NAMES[\n Math.floor(Math.random() * LOCALIZED_DEFAULT_ACCOUNT_NAMES.length)\n ];\n\nexport const MOCK_INTERNAL_ACCOUNTS = {\n EMPTY: [],\n ONE: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_DEFAULT_NAME: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name without nameLastUpdatedAt',\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED_MOST_RECENT: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 9999,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ALL: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x456',\n id: '2',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Account 2',\n nameLastUpdatedAt: 2,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x789',\n id: '3',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Účet 2',\n nameLastUpdatedAt: 3,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0xabc',\n id: '4',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'My Account 4',\n nameLastUpdatedAt: 4,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n};\n\nexport const MOCK_USER_STORAGE_ACCOUNTS = {\n SAME_AS_INTERNAL_ALL: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ALL as InternalAccount[],\n ),\n ONE: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE as InternalAccount[],\n ),\n TWO_DEFAULT_NAMES_WITH_ONE_BOGUS:\n mapInternalAccountsListToUserStorageAccountsList([\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME,\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME[0],\n address: '0x000000',\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 2,\n },\n },\n ] as InternalAccount[]),\n ONE_DEFAULT_NAME: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME as InternalAccount[],\n ),\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name without nameLastUpdatedAt',\n },\n },\n ] as InternalAccount[]),\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 3,\n },\n },\n ] as InternalAccount[]),\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockAccounts.d.cts","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAgB5D;;;GAGG;AACH,eAAO,MAAM,+BAA+B,mbAGzC,CAAC;AAEJ,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHlC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;CAyCtC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockAccounts.d.mts","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,8BAA8B;AACvD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAgB5D;;;GAGG;AACH,eAAO,MAAM,+BAA+B,mbAGzC,CAAC;AAEJ,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHlC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;CAyCtC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockAccounts.mjs","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.ts"],"names":[],"mappings":"AAAA,OAA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YAAY,CAAC,EAAE;iBACtB;aACF;SACF;QACD;YACE,OAAO,EAAE,OAAO;YAChB,EAAE,EAAE,GAAG;YACP,IAAI,EAAE,cAAc,CAAC,GAAG;YACxB,QAAQ,EAAE;gBACR,IAAI,EAAE,cAAc;gBACpB,iBAAiB,EAAE,CAAC;gBACpB,OAAO,EAAE;oBACP,IAAI,EAAE,YAAY,CAAC,EAAE;iBACtB;aACF;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,oBAAoB,EAAE,gDAAgD,CACpE,sBAAsB,CAAC,GAAwB,CAChD;IACD,GAAG,EAAE,gDAAgD,CACnD,sBAAsB,CAAC,GAAwB,CAChD;IACD,gCAAgC,EAC9B,gDAAgD,CAAC;QAC/C,GAAG,sBAAsB,CAAC,gBAAgB;QAC1C;YACE,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAC7C,OAAO,EAAE,UAAU;YACnB,QAAQ,EAAE;gBACR,IAAI,EAAE,GAAG,+BAA+B,EAAE,IAAI;gBAC9C,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;IACzB,gBAAgB,EAAE,gDAAgD,CAChE,sBAAsB,CAAC,gBAAqC,CAC7D;IACD,oCAAoC,EAClC,gDAAgD,CAAC;QAC/C;YACE,GAAG,sBAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,4DAA4D;aACnE;SACF;KACmB,CAAC;IACzB,iCAAiC,EAC/B,gDAAgD,CAAC;QAC/C;YACE,GAAG,sBAAsB,CAAC,oCAAoC,CAAC,CAAC,CAAC;YACjE,QAAQ,EAAE;gBACR,IAAI,EAAE,yDAAyD;gBAC/D,iBAAiB,EAAE,CAAC;aACrB;SACF;KACmB,CAAC;CAC1B,CAAC","sourcesContent":["import { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { LOCALIZED_DEFAULT_ACCOUNT_NAMES } from '../constants';\nimport { mapInternalAccountToUserStorageAccount } from '../utils';\n\n/**\n * Map an array of internal accounts to an array of user storage accounts\n * Only used for testing purposes\n * @param internalAccounts - An array of internal accounts\n * @returns An array of user storage accounts\n */\nconst mapInternalAccountsListToUserStorageAccountsList = (\n internalAccounts: InternalAccount[],\n) => internalAccounts.map(mapInternalAccountToUserStorageAccount);\n\n/**\n * Get a random default account name from the list of localized default account names\n * @returns A random default account name\n */\nexport const getMockRandomDefaultAccountName = () =>\n LOCALIZED_DEFAULT_ACCOUNT_NAMES[\n Math.floor(Math.random() * LOCALIZED_DEFAULT_ACCOUNT_NAMES.length)\n ];\n\nexport const MOCK_INTERNAL_ACCOUNTS = {\n EMPTY: [],\n ONE: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_DEFAULT_NAME: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name without nameLastUpdatedAt',\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED_MOST_RECENT: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Internal account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 9999,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n ALL: [\n {\n address: '0x123',\n id: '1',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'test',\n nameLastUpdatedAt: 1,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x456',\n id: '2',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Account 2',\n nameLastUpdatedAt: 2,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0x789',\n id: '3',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'Účet 2',\n nameLastUpdatedAt: 3,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n {\n address: '0xabc',\n id: '4',\n type: EthAccountType.Eoa,\n metadata: {\n name: 'My Account 4',\n nameLastUpdatedAt: 4,\n keyring: {\n type: KeyringTypes.hd,\n },\n },\n },\n ],\n};\n\nexport const MOCK_USER_STORAGE_ACCOUNTS = {\n SAME_AS_INTERNAL_ALL: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ALL as InternalAccount[],\n ),\n ONE: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE as InternalAccount[],\n ),\n TWO_DEFAULT_NAMES_WITH_ONE_BOGUS:\n mapInternalAccountsListToUserStorageAccountsList([\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME,\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME[0],\n address: '0x000000',\n metadata: {\n name: `${getMockRandomDefaultAccountName()} 1`,\n nameLastUpdatedAt: 2,\n },\n },\n ] as InternalAccount[]),\n ONE_DEFAULT_NAME: mapInternalAccountsListToUserStorageAccountsList(\n MOCK_INTERNAL_ACCOUNTS.ONE_DEFAULT_NAME as InternalAccount[],\n ),\n ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name without nameLastUpdatedAt',\n },\n },\n ] as InternalAccount[]),\n ONE_CUSTOM_NAME_WITH_LAST_UPDATED:\n mapInternalAccountsListToUserStorageAccountsList([\n {\n ...MOCK_INTERNAL_ACCOUNTS.ONE_CUSTOM_NAME_WITHOUT_LAST_UPDATED[0],\n metadata: {\n name: 'User storage account custom name with nameLastUpdatedAt',\n nameLastUpdatedAt: 3,\n },\n },\n ] as InternalAccount[]),\n};\n"]}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createExpectedAccountSyncBatchDeleteBody = exports.createExpectedAccountSyncBatchUpsertBody = exports.mockUserStorageMessengerForAccountSyncing = void 0;
4
- const encryption_1 = require("../../../../shared/encryption/index.cjs");
5
- const mockMessenger_1 = require("../../__fixtures__/mockMessenger.cjs");
6
- const utils_1 = require("../utils.cjs");
7
- const mockAccounts_1 = require("./mockAccounts.cjs");
8
- /**
9
- * Test Utility - create a mock user storage messenger for account syncing tests
10
- *
11
- * @param options - options for the mock messenger
12
- * @param options.accounts - options for the accounts part of the controller
13
- * @param options.accounts.accountsList - list of accounts to return for the 'AccountsController:listAccounts' action
14
- * @returns Mock User Storage Messenger
15
- */
16
- function mockUserStorageMessengerForAccountSyncing(options) {
17
- const messengerMocks = (0, mockMessenger_1.mockUserStorageMessenger)();
18
- messengerMocks.mockKeyringAddNewAccount.mockImplementation(async () => {
19
- messengerMocks.baseMessenger.publish('AccountsController:accountAdded', mockAccounts_1.MOCK_INTERNAL_ACCOUNTS.ONE[0]);
20
- return mockAccounts_1.MOCK_INTERNAL_ACCOUNTS.ONE[0].address;
21
- });
22
- messengerMocks.mockAccountsListAccounts.mockReturnValue((options?.accounts?.accountsList ??
23
- mockAccounts_1.MOCK_INTERNAL_ACCOUNTS.ALL));
24
- return messengerMocks;
25
- }
26
- exports.mockUserStorageMessengerForAccountSyncing = mockUserStorageMessengerForAccountSyncing;
27
- /**
28
- * Test Utility - creates a realistic expected batch upsert payload
29
- * @param data - data supposed to be upserted
30
- * @param storageKey - storage key
31
- * @returns expected body
32
- */
33
- function createExpectedAccountSyncBatchUpsertBody(data, storageKey) {
34
- return data.map(([entryKey, entryValue]) => [
35
- (0, encryption_1.createSHA256Hash)(String(entryKey) + storageKey),
36
- JSON.stringify((0, utils_1.mapInternalAccountToUserStorageAccount)(entryValue)),
37
- ]);
38
- }
39
- exports.createExpectedAccountSyncBatchUpsertBody = createExpectedAccountSyncBatchUpsertBody;
40
- /**
41
- * Test Utility - creates a realistic expected batch delete payload
42
- * @param data - data supposed to be deleted
43
- * @param storageKey - storage key
44
- * @returns expected body
45
- */
46
- function createExpectedAccountSyncBatchDeleteBody(data, storageKey) {
47
- return data.map((entryKey) => (0, encryption_1.createSHA256Hash)(String(entryKey) + storageKey));
48
- }
49
- exports.createExpectedAccountSyncBatchDeleteBody = createExpectedAccountSyncBatchDeleteBody;
50
- //# sourceMappingURL=test-utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.cjs","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/test-utils.ts"],"names":[],"mappings":";;;AAEA,wEAAiE;AACjE,wEAA4E;AAC5E,wCAAkE;AAClE,qDAAwD;AAExD;;;;;;;GAOG;AACH,SAAgB,yCAAyC,CAAC,OAIzD;IACC,MAAM,cAAc,GAAG,IAAA,wCAAwB,GAAE,CAAC;IAElD,cAAc,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;QACpE,cAAc,CAAC,aAAa,CAAC,OAAO,CAClC,iCAAiC,EACjC,qCAAsB,CAAC,GAAG,CAAC,CAAC,CAAoB,CACjD,CAAC;QACF,OAAO,qCAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,cAAc,CAAC,wBAAwB,CAAC,eAAe,CACrD,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;QAC9B,qCAAsB,CAAC,GAAG,CAAsB,CACnD,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC;AArBD,8FAqBC;AAED;;;;;GAKG;AACH,SAAgB,wCAAwC,CACtD,IAAiC,EACjC,UAAkB;IAElB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAA,6BAAgB,EAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QAC/C,IAAI,CAAC,SAAS,CAAC,IAAA,8CAAsC,EAAC,UAAU,CAAC,CAAC;KACnE,CAAC,CAAC;AACL,CAAC;AARD,4FAQC;AAED;;;;;GAKG;AACH,SAAgB,wCAAwC,CACtD,IAAc,EACd,UAAkB;IAElB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC3B,IAAA,6BAAgB,EAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,CAChD,CAAC;AACJ,CAAC;AAPD,4FAOC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { createSHA256Hash } from '../../../../shared/encryption';\nimport { mockUserStorageMessenger } from '../../__fixtures__/mockMessenger';\nimport { mapInternalAccountToUserStorageAccount } from '../utils';\nimport { MOCK_INTERNAL_ACCOUNTS } from './mockAccounts';\n\n/**\n * Test Utility - create a mock user storage messenger for account syncing tests\n *\n * @param options - options for the mock messenger\n * @param options.accounts - options for the accounts part of the controller\n * @param options.accounts.accountsList - list of accounts to return for the 'AccountsController:listAccounts' action\n * @returns Mock User Storage Messenger\n */\nexport function mockUserStorageMessengerForAccountSyncing(options?: {\n accounts?: {\n accountsList?: InternalAccount[];\n };\n}) {\n const messengerMocks = mockUserStorageMessenger();\n\n messengerMocks.mockKeyringAddNewAccount.mockImplementation(async () => {\n messengerMocks.baseMessenger.publish(\n 'AccountsController:accountAdded',\n MOCK_INTERNAL_ACCOUNTS.ONE[0] as InternalAccount,\n );\n return MOCK_INTERNAL_ACCOUNTS.ONE[0].address;\n });\n\n messengerMocks.mockAccountsListAccounts.mockReturnValue(\n (options?.accounts?.accountsList ??\n MOCK_INTERNAL_ACCOUNTS.ALL) as InternalAccount[],\n );\n\n return messengerMocks;\n}\n\n/**\n * Test Utility - creates a realistic expected batch upsert payload\n * @param data - data supposed to be upserted\n * @param storageKey - storage key\n * @returns expected body\n */\nexport function createExpectedAccountSyncBatchUpsertBody(\n data: [string, InternalAccount][],\n storageKey: string,\n) {\n return data.map(([entryKey, entryValue]) => [\n createSHA256Hash(String(entryKey) + storageKey),\n JSON.stringify(mapInternalAccountToUserStorageAccount(entryValue)),\n ]);\n}\n\n/**\n * Test Utility - creates a realistic expected batch delete payload\n * @param data - data supposed to be deleted\n * @param storageKey - storage key\n * @returns expected body\n */\nexport function createExpectedAccountSyncBatchDeleteBody(\n data: string[],\n storageKey: string,\n) {\n return data.map((entryKey) =>\n createSHA256Hash(String(entryKey) + storageKey),\n );\n}\n"]}
@@ -1,85 +0,0 @@
1
- /// <reference types="jest" />
2
- import type { InternalAccount } from "@metamask/keyring-internal-api";
3
- /**
4
- * Test Utility - create a mock user storage messenger for account syncing tests
5
- *
6
- * @param options - options for the mock messenger
7
- * @param options.accounts - options for the accounts part of the controller
8
- * @param options.accounts.accountsList - list of accounts to return for the 'AccountsController:listAccounts' action
9
- * @returns Mock User Storage Messenger
10
- */
11
- export declare function mockUserStorageMessengerForAccountSyncing(options?: {
12
- accounts?: {
13
- accountsList?: InternalAccount[];
14
- };
15
- }): {
16
- baseMessenger: import("@metamask/base-controller").ControllerMessenger<import("../../index.cjs").AllowedActions, import("../../index.cjs").AllowedEvents>;
17
- messenger: import("@metamask/base-controller").RestrictedControllerMessenger<"UserStorageController", import("@metamask/snaps-controllers").HandleSnapRequest | {
18
- type: "AuthenticationController:isSignedIn";
19
- handler: () => boolean;
20
- } | {
21
- type: "AuthenticationController:performSignIn";
22
- handler: () => Promise<string>;
23
- } | {
24
- type: "AuthenticationController:performSignOut";
25
- handler: () => void;
26
- } | {
27
- type: "AuthenticationController:getBearerToken";
28
- handler: () => Promise<string>;
29
- } | {
30
- type: "AuthenticationController:getSessionProfile";
31
- handler: () => Promise<{
32
- identifierId: string;
33
- profileId: string;
34
- }>;
35
- } | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("../../index.cjs").NotificationServicesControllerDisableNotificationServices | import("../../index.cjs").NotificationServicesControllerSelectIsNotificationServicesEnabled | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../../index.cjs").UserStorageControllerStateChangeEvent | import("../../index.cjs").UserStorageControllerAccountSyncingInProgress | import("../../index.cjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "NotificationServicesController:disableNotificationServices" | "NotificationServicesController:selectIsNotificationServicesEnabled" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
36
- mockSnapGetPublicKey: jest.Mock<any, any>;
37
- mockSnapSignMessage: jest.Mock<any, any>;
38
- mockAuthGetBearerToken: jest.Mock<Promise<string>, []>;
39
- mockAuthGetSessionProfile: jest.Mock<Promise<{
40
- identifierId: string;
41
- profileId: string;
42
- }>, []>;
43
- mockAuthPerformSignIn: jest.Mock<Promise<string>, []>;
44
- mockAuthIsSignedIn: jest.Mock<boolean, []>;
45
- mockNotificationServicesIsEnabled: jest.Mock<boolean, []>;
46
- mockNotificationServicesDisableNotifications: jest.Mock<Promise<void>, []>;
47
- mockAuthPerformSignOut: jest.Mock<void, []>;
48
- mockKeyringAddNewAccount: jest.Mock<Promise<string>, [accountCount?: number | undefined]>;
49
- mockAccountsUpdateAccountMetadata: jest.Mock<void, [accountId: string, metadata: Partial<{
50
- name: string;
51
- importTime: number;
52
- keyring: {
53
- type: string;
54
- };
55
- nameLastUpdatedAt?: number | undefined;
56
- snap?: {
57
- name: string;
58
- id: string;
59
- enabled: boolean;
60
- } | undefined;
61
- lastSelected?: number | undefined;
62
- }>]>;
63
- mockAccountsListAccounts: jest.Mock<any, any>;
64
- mockNetworkControllerGetState: jest.Mock<import("@metamask/network-controller").NetworkState, []>;
65
- mockNetworkControllerAddNetwork: jest.Mock<import("@metamask/network-controller").NetworkConfiguration, [fields: import("@metamask/network-controller").AddNetworkFields]>;
66
- mockNetworkControllerRemoveNetwork: jest.Mock<void, [chainId: `0x${string}`]>;
67
- mockNetworkControllerUpdateNetwork: jest.Mock<Promise<import("@metamask/network-controller").NetworkConfiguration>, [`0x${string}`, import("@metamask/network-controller").UpdateNetworkFields, ({
68
- replacementSelectedRpcEndpointIndex?: number | undefined;
69
- } | undefined)?]>;
70
- };
71
- /**
72
- * Test Utility - creates a realistic expected batch upsert payload
73
- * @param data - data supposed to be upserted
74
- * @param storageKey - storage key
75
- * @returns expected body
76
- */
77
- export declare function createExpectedAccountSyncBatchUpsertBody(data: [string, InternalAccount][], storageKey: string): string[][];
78
- /**
79
- * Test Utility - creates a realistic expected batch delete payload
80
- * @param data - data supposed to be deleted
81
- * @param storageKey - storage key
82
- * @returns expected body
83
- */
84
- export declare function createExpectedAccountSyncBatchDeleteBody(data: string[], storageKey: string): string[];
85
- //# sourceMappingURL=test-utils.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.d.cts","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/test-utils.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE;;;;;;;GAOG;AACH,wBAAgB,yCAAyC,CAAC,OAAO,CAAC,EAAE;IAClE,QAAQ,CAAC,EAAE;QACT,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;KAClC,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,IAAI,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EACjC,UAAU,EAAE,MAAM,cAMnB;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,IAAI,EAAE,MAAM,EAAE,EACd,UAAU,EAAE,MAAM,YAKnB"}
@@ -1,85 +0,0 @@
1
- /// <reference types="jest" />
2
- import type { InternalAccount } from "@metamask/keyring-internal-api";
3
- /**
4
- * Test Utility - create a mock user storage messenger for account syncing tests
5
- *
6
- * @param options - options for the mock messenger
7
- * @param options.accounts - options for the accounts part of the controller
8
- * @param options.accounts.accountsList - list of accounts to return for the 'AccountsController:listAccounts' action
9
- * @returns Mock User Storage Messenger
10
- */
11
- export declare function mockUserStorageMessengerForAccountSyncing(options?: {
12
- accounts?: {
13
- accountsList?: InternalAccount[];
14
- };
15
- }): {
16
- baseMessenger: import("@metamask/base-controller").ControllerMessenger<import("../../index.mjs").AllowedActions, import("../../index.mjs").AllowedEvents>;
17
- messenger: import("@metamask/base-controller").RestrictedControllerMessenger<"UserStorageController", import("@metamask/snaps-controllers").HandleSnapRequest | {
18
- type: "AuthenticationController:isSignedIn";
19
- handler: () => boolean;
20
- } | {
21
- type: "AuthenticationController:performSignIn";
22
- handler: () => Promise<string>;
23
- } | {
24
- type: "AuthenticationController:performSignOut";
25
- handler: () => void;
26
- } | {
27
- type: "AuthenticationController:getBearerToken";
28
- handler: () => Promise<string>;
29
- } | {
30
- type: "AuthenticationController:getSessionProfile";
31
- handler: () => Promise<{
32
- identifierId: string;
33
- profileId: string;
34
- }>;
35
- } | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("../../index.mjs").NotificationServicesControllerDisableNotificationServices | import("../../index.mjs").NotificationServicesControllerSelectIsNotificationServicesEnabled | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../../index.mjs").UserStorageControllerStateChangeEvent | import("../../index.mjs").UserStorageControllerAccountSyncingInProgress | import("../../index.mjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "NotificationServicesController:disableNotificationServices" | "NotificationServicesController:selectIsNotificationServicesEnabled" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
36
- mockSnapGetPublicKey: jest.Mock<any, any>;
37
- mockSnapSignMessage: jest.Mock<any, any>;
38
- mockAuthGetBearerToken: jest.Mock<Promise<string>, []>;
39
- mockAuthGetSessionProfile: jest.Mock<Promise<{
40
- identifierId: string;
41
- profileId: string;
42
- }>, []>;
43
- mockAuthPerformSignIn: jest.Mock<Promise<string>, []>;
44
- mockAuthIsSignedIn: jest.Mock<boolean, []>;
45
- mockNotificationServicesIsEnabled: jest.Mock<boolean, []>;
46
- mockNotificationServicesDisableNotifications: jest.Mock<Promise<void>, []>;
47
- mockAuthPerformSignOut: jest.Mock<void, []>;
48
- mockKeyringAddNewAccount: jest.Mock<Promise<string>, [accountCount?: number | undefined]>;
49
- mockAccountsUpdateAccountMetadata: jest.Mock<void, [accountId: string, metadata: Partial<{
50
- name: string;
51
- importTime: number;
52
- keyring: {
53
- type: string;
54
- };
55
- nameLastUpdatedAt?: number | undefined;
56
- snap?: {
57
- name: string;
58
- id: string;
59
- enabled: boolean;
60
- } | undefined;
61
- lastSelected?: number | undefined;
62
- }>]>;
63
- mockAccountsListAccounts: jest.Mock<any, any>;
64
- mockNetworkControllerGetState: jest.Mock<import("@metamask/network-controller").NetworkState, []>;
65
- mockNetworkControllerAddNetwork: jest.Mock<import("@metamask/network-controller").NetworkConfiguration, [fields: import("@metamask/network-controller").AddNetworkFields]>;
66
- mockNetworkControllerRemoveNetwork: jest.Mock<void, [chainId: `0x${string}`]>;
67
- mockNetworkControllerUpdateNetwork: jest.Mock<Promise<import("@metamask/network-controller").NetworkConfiguration>, [`0x${string}`, import("@metamask/network-controller").UpdateNetworkFields, ({
68
- replacementSelectedRpcEndpointIndex?: number | undefined;
69
- } | undefined)?]>;
70
- };
71
- /**
72
- * Test Utility - creates a realistic expected batch upsert payload
73
- * @param data - data supposed to be upserted
74
- * @param storageKey - storage key
75
- * @returns expected body
76
- */
77
- export declare function createExpectedAccountSyncBatchUpsertBody(data: [string, InternalAccount][], storageKey: string): string[][];
78
- /**
79
- * Test Utility - creates a realistic expected batch delete payload
80
- * @param data - data supposed to be deleted
81
- * @param storageKey - storage key
82
- * @returns expected body
83
- */
84
- export declare function createExpectedAccountSyncBatchDeleteBody(data: string[], storageKey: string): string[];
85
- //# sourceMappingURL=test-utils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.d.mts","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/test-utils.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE;;;;;;;GAOG;AACH,wBAAgB,yCAAyC,CAAC,OAAO,CAAC,EAAE;IAClE,QAAQ,CAAC,EAAE;QACT,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;KAClC,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,IAAI,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EACjC,UAAU,EAAE,MAAM,cAMnB;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,IAAI,EAAE,MAAM,EAAE,EACd,UAAU,EAAE,MAAM,YAKnB"}
@@ -1,44 +0,0 @@
1
- import { createSHA256Hash } from "../../../../shared/encryption/index.mjs";
2
- import { mockUserStorageMessenger } from "../../__fixtures__/mockMessenger.mjs";
3
- import { mapInternalAccountToUserStorageAccount } from "../utils.mjs";
4
- import { MOCK_INTERNAL_ACCOUNTS } from "./mockAccounts.mjs";
5
- /**
6
- * Test Utility - create a mock user storage messenger for account syncing tests
7
- *
8
- * @param options - options for the mock messenger
9
- * @param options.accounts - options for the accounts part of the controller
10
- * @param options.accounts.accountsList - list of accounts to return for the 'AccountsController:listAccounts' action
11
- * @returns Mock User Storage Messenger
12
- */
13
- export function mockUserStorageMessengerForAccountSyncing(options) {
14
- const messengerMocks = mockUserStorageMessenger();
15
- messengerMocks.mockKeyringAddNewAccount.mockImplementation(async () => {
16
- messengerMocks.baseMessenger.publish('AccountsController:accountAdded', MOCK_INTERNAL_ACCOUNTS.ONE[0]);
17
- return MOCK_INTERNAL_ACCOUNTS.ONE[0].address;
18
- });
19
- messengerMocks.mockAccountsListAccounts.mockReturnValue((options?.accounts?.accountsList ??
20
- MOCK_INTERNAL_ACCOUNTS.ALL));
21
- return messengerMocks;
22
- }
23
- /**
24
- * Test Utility - creates a realistic expected batch upsert payload
25
- * @param data - data supposed to be upserted
26
- * @param storageKey - storage key
27
- * @returns expected body
28
- */
29
- export function createExpectedAccountSyncBatchUpsertBody(data, storageKey) {
30
- return data.map(([entryKey, entryValue]) => [
31
- createSHA256Hash(String(entryKey) + storageKey),
32
- JSON.stringify(mapInternalAccountToUserStorageAccount(entryValue)),
33
- ]);
34
- }
35
- /**
36
- * Test Utility - creates a realistic expected batch delete payload
37
- * @param data - data supposed to be deleted
38
- * @param storageKey - storage key
39
- * @returns expected body
40
- */
41
- export function createExpectedAccountSyncBatchDeleteBody(data, storageKey) {
42
- return data.map((entryKey) => createSHA256Hash(String(entryKey) + storageKey));
43
- }
44
- //# sourceMappingURL=test-utils.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.mjs","sourceRoot":"","sources":["../../../../../src/controllers/user-storage/account-syncing/__fixtures__/test-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,gDAAsC;AACjE,OAAO,EAAE,wBAAwB,EAAE,6CAAyC;AAC5E,OAAO,EAAE,sCAAsC,EAAE,qBAAiB;AAClE,OAAO,EAAE,sBAAsB,EAAE,2BAAuB;AAExD;;;;;;;GAOG;AACH,MAAM,UAAU,yCAAyC,CAAC,OAIzD;IACC,MAAM,cAAc,GAAG,wBAAwB,EAAE,CAAC;IAElD,cAAc,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE;QACpE,cAAc,CAAC,aAAa,CAAC,OAAO,CAClC,iCAAiC,EACjC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAoB,CACjD,CAAC;QACF,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,cAAc,CAAC,wBAAwB,CAAC,eAAe,CACrD,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY;QAC9B,sBAAsB,CAAC,GAAG,CAAsB,CACnD,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wCAAwC,CACtD,IAAiC,EACjC,UAAkB;IAElB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC;QAC1C,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QAC/C,IAAI,CAAC,SAAS,CAAC,sCAAsC,CAAC,UAAU,CAAC,CAAC;KACnE,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wCAAwC,CACtD,IAAc,EACd,UAAkB;IAElB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC3B,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,CAChD,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { createSHA256Hash } from '../../../../shared/encryption';\nimport { mockUserStorageMessenger } from '../../__fixtures__/mockMessenger';\nimport { mapInternalAccountToUserStorageAccount } from '../utils';\nimport { MOCK_INTERNAL_ACCOUNTS } from './mockAccounts';\n\n/**\n * Test Utility - create a mock user storage messenger for account syncing tests\n *\n * @param options - options for the mock messenger\n * @param options.accounts - options for the accounts part of the controller\n * @param options.accounts.accountsList - list of accounts to return for the 'AccountsController:listAccounts' action\n * @returns Mock User Storage Messenger\n */\nexport function mockUserStorageMessengerForAccountSyncing(options?: {\n accounts?: {\n accountsList?: InternalAccount[];\n };\n}) {\n const messengerMocks = mockUserStorageMessenger();\n\n messengerMocks.mockKeyringAddNewAccount.mockImplementation(async () => {\n messengerMocks.baseMessenger.publish(\n 'AccountsController:accountAdded',\n MOCK_INTERNAL_ACCOUNTS.ONE[0] as InternalAccount,\n );\n return MOCK_INTERNAL_ACCOUNTS.ONE[0].address;\n });\n\n messengerMocks.mockAccountsListAccounts.mockReturnValue(\n (options?.accounts?.accountsList ??\n MOCK_INTERNAL_ACCOUNTS.ALL) as InternalAccount[],\n );\n\n return messengerMocks;\n}\n\n/**\n * Test Utility - creates a realistic expected batch upsert payload\n * @param data - data supposed to be upserted\n * @param storageKey - storage key\n * @returns expected body\n */\nexport function createExpectedAccountSyncBatchUpsertBody(\n data: [string, InternalAccount][],\n storageKey: string,\n) {\n return data.map(([entryKey, entryValue]) => [\n createSHA256Hash(String(entryKey) + storageKey),\n JSON.stringify(mapInternalAccountToUserStorageAccount(entryValue)),\n ]);\n}\n\n/**\n * Test Utility - creates a realistic expected batch delete payload\n * @param data - data supposed to be deleted\n * @param storageKey - storage key\n * @returns expected body\n */\nexport function createExpectedAccountSyncBatchDeleteBody(\n data: string[],\n storageKey: string,\n) {\n return data.map((entryKey) =>\n createSHA256Hash(String(entryKey) + storageKey),\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,GAAG,CAAC;AAExC,4FAA4F;AAC/E,QAAA,wBAAwB,GAAkB,GAAY,CAAC;AAEpE,qGAAqG;AACxF,QAAA,+BAA+B,GAAG;IAC7C,SAAS;IACT,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;IACR,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,IAAI;IACJ,SAAS;IACT,OAAO;IACP,WAAW;IACX,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,IAAI;IACJ,IAAI;CACI,CAAC","sourcesContent":["export const USER_STORAGE_VERSION = '1';\n\n// Force cast. We don't really care about the type here since we treat it as a unique symbol\nexport const USER_STORAGE_VERSION_KEY: unique symbol = 'v' as never;\n\n// We need this in order to know if an account is a default account or not when we do account syncing\nexport const LOCALIZED_DEFAULT_ACCOUNT_NAMES = [\n 'Account',\n 'መለያ',\n 'الحساب',\n 'Профил',\n 'অ্যাকাউন্ট',\n 'Compte',\n 'Účet',\n 'Konto',\n 'Λογαριασμός',\n 'Cuenta',\n 'حساب',\n 'Tili',\n 'એકાઉન્ટ',\n 'חשבון',\n 'अकाउंट',\n 'खाता',\n 'Račun',\n 'Kont',\n 'Fiók',\n 'Akun',\n 'アカウント',\n 'ಖಾತೆ',\n '계정',\n 'Paskyra',\n 'Konts',\n 'അക്കൗണ്ട്',\n 'खाते',\n 'Akaun',\n 'Conta',\n 'Cont',\n 'Счет',\n 'налог',\n 'Akaunti',\n 'கணக்கு',\n 'ఖాతా',\n 'บัญชี',\n 'Hesap',\n 'Обліковий запис',\n 'Tài khoản',\n '账户',\n '帳戶',\n] as const;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAGxC,eAAO,MAAM,wBAAwB,EAAE,OAAO,MAAqB,CAAC;AAGpE,eAAO,MAAM,+BAA+B,gZA0ClC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAGxC,eAAO,MAAM,wBAAwB,EAAE,OAAO,MAAqB,CAAC;AAGpE,eAAO,MAAM,+BAA+B,gZA0ClC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,wBAAwB,GAAkB,GAAY,CAAC;AAEpE,qGAAqG;AACrG,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,SAAS;IACT,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;IACR,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,IAAI;IACJ,SAAS;IACT,OAAO;IACP,WAAW;IACX,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,IAAI;IACJ,IAAI;CACI,CAAC","sourcesContent":["export const USER_STORAGE_VERSION = '1';\n\n// Force cast. We don't really care about the type here since we treat it as a unique symbol\nexport const USER_STORAGE_VERSION_KEY: unique symbol = 'v' as never;\n\n// We need this in order to know if an account is a default account or not when we do account syncing\nexport const LOCALIZED_DEFAULT_ACCOUNT_NAMES = [\n 'Account',\n 'መለያ',\n 'الحساب',\n 'Профил',\n 'অ্যাকাউন্ট',\n 'Compte',\n 'Účet',\n 'Konto',\n 'Λογαριασμός',\n 'Cuenta',\n 'حساب',\n 'Tili',\n 'એકાઉન્ટ',\n 'חשבון',\n 'अकाउंट',\n 'खाता',\n 'Račun',\n 'Kont',\n 'Fiók',\n 'Akun',\n 'アカウント',\n 'ಖಾತೆ',\n '계정',\n 'Paskyra',\n 'Konts',\n 'അക്കൗണ്ട്',\n 'खाते',\n 'Akaun',\n 'Conta',\n 'Cont',\n 'Счет',\n 'налог',\n 'Akaunti',\n 'கணக்கு',\n 'ఖాతా',\n 'บัญชี',\n 'Hesap',\n 'Обліковий запис',\n 'Tài khoản',\n '账户',\n '帳戶',\n] as const;\n"]}