@metamask/profile-sync-controller 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/controllers/authentication/services.cjs +10 -3
  3. package/dist/controllers/authentication/services.cjs.map +1 -1
  4. package/dist/controllers/authentication/services.d.cts.map +1 -1
  5. package/dist/controllers/authentication/services.d.mts.map +1 -1
  6. package/dist/controllers/authentication/services.mjs +14 -3
  7. package/dist/controllers/authentication/services.mjs.map +1 -1
  8. package/dist/controllers/user-storage/UserStorageController.cjs +39 -218
  9. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  10. package/dist/controllers/user-storage/UserStorageController.d.cts +6 -1
  11. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  12. package/dist/controllers/user-storage/UserStorageController.d.mts +6 -1
  13. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  14. package/dist/controllers/user-storage/UserStorageController.mjs +36 -215
  15. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  16. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +45 -1
  17. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -1
  18. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +21 -0
  19. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -1
  20. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +21 -0
  21. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -1
  22. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +38 -0
  23. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -1
  24. package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.cjs +3 -3
  25. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +1 -0
  26. package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.d.cts +6 -6
  27. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +1 -0
  28. package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.d.mts +6 -6
  29. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +1 -0
  30. package/dist/controllers/user-storage/{__fixtures__ → account-syncing/__fixtures__}/mockAccounts.mjs +2 -2
  31. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +1 -0
  32. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +50 -0
  33. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +1 -0
  34. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +85 -0
  35. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +1 -0
  36. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +85 -0
  37. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +1 -0
  38. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +44 -0
  39. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +1 -0
  40. package/dist/controllers/user-storage/account-syncing/constants.cjs.map +1 -0
  41. package/dist/controllers/user-storage/account-syncing/constants.d.cts.map +1 -0
  42. package/dist/controllers/user-storage/account-syncing/constants.d.mts.map +1 -0
  43. package/dist/controllers/user-storage/account-syncing/constants.mjs.map +1 -0
  44. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +194 -0
  45. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -0
  46. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +31 -0
  47. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -0
  48. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +31 -0
  49. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -0
  50. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +188 -0
  51. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -0
  52. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +35 -0
  53. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -0
  54. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +8 -0
  55. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -0
  56. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +8 -0
  57. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -0
  58. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +31 -0
  59. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -0
  60. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +47 -0
  61. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -0
  62. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +20 -0
  63. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -0
  64. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +20 -0
  65. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -0
  66. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +41 -0
  67. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -0
  68. package/dist/controllers/user-storage/account-syncing/types.cjs +3 -0
  69. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -0
  70. package/dist/controllers/user-storage/account-syncing/types.d.cts +26 -0
  71. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -0
  72. package/dist/controllers/user-storage/account-syncing/types.d.mts +26 -0
  73. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -0
  74. package/dist/controllers/user-storage/account-syncing/types.mjs +2 -0
  75. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -0
  76. package/dist/controllers/user-storage/{accounts/user-storage.cjs → account-syncing/utils.cjs} +12 -2
  77. package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -0
  78. package/dist/controllers/user-storage/{accounts/user-storage.d.cts → account-syncing/utils.d.cts} +8 -17
  79. package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -0
  80. package/dist/controllers/user-storage/{accounts/user-storage.d.mts → account-syncing/utils.d.mts} +8 -17
  81. package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -0
  82. package/dist/controllers/user-storage/{accounts/user-storage.mjs → account-syncing/utils.mjs} +10 -1
  83. package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -0
  84. package/dist/controllers/user-storage/services.cjs +10 -10
  85. package/dist/controllers/user-storage/services.cjs.map +1 -1
  86. package/dist/controllers/user-storage/services.d.cts.map +1 -1
  87. package/dist/controllers/user-storage/services.d.mts.map +1 -1
  88. package/dist/controllers/user-storage/services.mjs +10 -10
  89. package/dist/controllers/user-storage/services.mjs.map +1 -1
  90. package/package.json +2 -2
  91. package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs.map +0 -1
  92. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts.map +0 -1
  93. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts.map +0 -1
  94. package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs.map +0 -1
  95. package/dist/controllers/user-storage/accounts/constants.cjs.map +0 -1
  96. package/dist/controllers/user-storage/accounts/constants.d.cts.map +0 -1
  97. package/dist/controllers/user-storage/accounts/constants.d.mts.map +0 -1
  98. package/dist/controllers/user-storage/accounts/constants.mjs.map +0 -1
  99. package/dist/controllers/user-storage/accounts/user-storage.cjs.map +0 -1
  100. package/dist/controllers/user-storage/accounts/user-storage.d.cts.map +0 -1
  101. package/dist/controllers/user-storage/accounts/user-storage.d.mts.map +0 -1
  102. package/dist/controllers/user-storage/accounts/user-storage.mjs.map +0 -1
  103. /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.cjs +0 -0
  104. /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.d.cts +0 -0
  105. /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.d.mts +0 -0
  106. /package/dist/controllers/user-storage/{accounts → account-syncing}/constants.mjs +0 -0
@@ -0,0 +1,31 @@
1
+ import { saveInternalAccountToUserStorage } from "./controller-integration.mjs";
2
+ import { canPerformAccountSyncing } from "./sync-utils.mjs";
3
+ /**
4
+ * Initialize and setup events to listen to for account syncing
5
+ * @param config - configuration parameters
6
+ * @param options - parameters used for initializing and enabling account syncing
7
+ */
8
+ export function setupAccountSyncingSubscriptions(config, options) {
9
+ const { getMessenger, getUserStorageControllerInstance } = options;
10
+ getMessenger().subscribe('AccountsController:accountAdded',
11
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
12
+ async (account) => {
13
+ if (!canPerformAccountSyncing(config, options) ||
14
+ !getUserStorageControllerInstance().state
15
+ .hasAccountSyncingSyncedAtLeastOnce) {
16
+ return;
17
+ }
18
+ await saveInternalAccountToUserStorage(account, config, options);
19
+ });
20
+ getMessenger().subscribe('AccountsController:accountRenamed',
21
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
22
+ async (account) => {
23
+ if (!canPerformAccountSyncing(config, options) ||
24
+ !getUserStorageControllerInstance().state
25
+ .hasAccountSyncingSyncedAtLeastOnce) {
26
+ return;
27
+ }
28
+ await saveInternalAccountToUserStorage(account, config, options);
29
+ });
30
+ }
31
+ //# sourceMappingURL=setup-subscriptions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-subscriptions.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,qCAAiC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,yBAAqB;AAGxD;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAC9C,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC;IACjC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;YAC1C,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC;IACnC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;YAC1C,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n * @param config - configuration parameters\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(config, options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, config, options);\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(config, options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, config, options);\n },\n );\n}\n"]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserStorageAccountsList = exports.getInternalAccountsList = exports.canPerformAccountSyncing = void 0;
4
+ const storage_schema_1 = require("../../../shared/storage-schema.cjs");
5
+ const utils_1 = require("./utils.cjs");
6
+ /**
7
+ * Checks if account syncing can be performed based on a set of conditions
8
+ * @param config - configuration parameters
9
+ * @param options - parameters used for checking if account syncing can be performed
10
+ * @returns Returns true if account syncing can be performed, false otherwise.
11
+ */
12
+ function canPerformAccountSyncing(config, options) {
13
+ const { isAccountSyncingEnabled } = config;
14
+ const { getMessenger, getUserStorageControllerInstance } = options;
15
+ const { isProfileSyncingEnabled, isAccountSyncingInProgress } = getUserStorageControllerInstance().state;
16
+ const isAuthEnabled = getMessenger().call('AuthenticationController:isSignedIn');
17
+ if (!isProfileSyncingEnabled ||
18
+ !isAuthEnabled ||
19
+ !isAccountSyncingEnabled ||
20
+ isAccountSyncingInProgress) {
21
+ return false;
22
+ }
23
+ return true;
24
+ }
25
+ exports.canPerformAccountSyncing = canPerformAccountSyncing;
26
+ /**
27
+ * Get the list of internal accounts
28
+ * @param options - parameters used for getting the list of internal accounts
29
+ */
30
+ async function getInternalAccountsList(options) {
31
+ const { getMessenger } = options;
32
+ // eslint-disable-next-line @typescript-eslint/await-thenable
33
+ const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
34
+ return internalAccountsList?.filter(utils_1.doesInternalAccountHaveCorrectKeyringType);
35
+ }
36
+ exports.getInternalAccountsList = getInternalAccountsList;
37
+ /**
38
+ * Get the list of user storage accounts
39
+ * @param options - parameters used for getting the list of user storage accounts
40
+ */
41
+ async function getUserStorageAccountsList(options) {
42
+ const { getUserStorageControllerInstance } = options;
43
+ const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts);
44
+ return (rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null);
45
+ }
46
+ exports.getUserStorageAccountsList = getUserStorageAccountsList;
47
+ //# sourceMappingURL=sync-utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAEA,uEAA4E;AAM5E,uCAAoE;AAEpE;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAvBD,4DAuBC;AAED;;;GAGG;AACI,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,oBAAoB,EAAE,MAAM,CACjC,iDAAyC,CAC1C,CAAC;AACJ,CAAC;AAbD,0DAaC;AAED;;;GAGG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,2CAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC;AAbD,gEAaC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { doesInternalAccountHaveCorrectKeyringType } from './utils';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * @param options - parameters used for getting the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return internalAccountsList?.filter(\n doesInternalAccountHaveCorrectKeyringType,\n );\n}\n\n/**\n * Get the list of user storage accounts\n * @param options - parameters used for getting the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
+ import type { AccountSyncingConfig, AccountSyncingOptions, UserStorageAccount } from "./types.cjs";
3
+ /**
4
+ * Checks if account syncing can be performed based on a set of conditions
5
+ * @param config - configuration parameters
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 declare function canPerformAccountSyncing(config: AccountSyncingConfig, options: AccountSyncingOptions): boolean;
10
+ /**
11
+ * Get the list of internal accounts
12
+ * @param options - parameters used for getting the list of internal accounts
13
+ */
14
+ export declare function getInternalAccountsList(options: AccountSyncingOptions): Promise<InternalAccount[]>;
15
+ /**
16
+ * Get the list of user storage accounts
17
+ * @param options - parameters used for getting the list of user storage accounts
18
+ */
19
+ export declare function getUserStorageAccountsList(options: AccountSyncingOptions): Promise<UserStorageAccount[] | null>;
20
+ //# sourceMappingURL=sync-utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAGjB;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAW5B;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
@@ -0,0 +1,20 @@
1
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
+ import type { AccountSyncingConfig, AccountSyncingOptions, UserStorageAccount } from "./types.mjs";
3
+ /**
4
+ * Checks if account syncing can be performed based on a set of conditions
5
+ * @param config - configuration parameters
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 declare function canPerformAccountSyncing(config: AccountSyncingConfig, options: AccountSyncingOptions): boolean;
10
+ /**
11
+ * Get the list of internal accounts
12
+ * @param options - parameters used for getting the list of internal accounts
13
+ */
14
+ export declare function getInternalAccountsList(options: AccountSyncingOptions): Promise<InternalAccount[]>;
15
+ /**
16
+ * Get the list of user storage accounts
17
+ * @param options - parameters used for getting the list of user storage accounts
18
+ */
19
+ export declare function getUserStorageAccountsList(options: AccountSyncingOptions): Promise<UserStorageAccount[] | null>;
20
+ //# sourceMappingURL=sync-utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAGjB;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAW5B;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
@@ -0,0 +1,41 @@
1
+ import { USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
2
+ import { doesInternalAccountHaveCorrectKeyringType } from "./utils.mjs";
3
+ /**
4
+ * Checks if account syncing can be performed based on a set of conditions
5
+ * @param config - configuration parameters
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(config, options) {
10
+ const { isAccountSyncingEnabled } = config;
11
+ const { getMessenger, getUserStorageControllerInstance } = options;
12
+ const { isProfileSyncingEnabled, isAccountSyncingInProgress } = getUserStorageControllerInstance().state;
13
+ const isAuthEnabled = getMessenger().call('AuthenticationController:isSignedIn');
14
+ if (!isProfileSyncingEnabled ||
15
+ !isAuthEnabled ||
16
+ !isAccountSyncingEnabled ||
17
+ isAccountSyncingInProgress) {
18
+ return false;
19
+ }
20
+ return true;
21
+ }
22
+ /**
23
+ * Get the list of internal accounts
24
+ * @param options - parameters used for getting the list of internal accounts
25
+ */
26
+ export async function getInternalAccountsList(options) {
27
+ const { getMessenger } = options;
28
+ // eslint-disable-next-line @typescript-eslint/await-thenable
29
+ const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
30
+ return internalAccountsList?.filter(doesInternalAccountHaveCorrectKeyringType);
31
+ }
32
+ /**
33
+ * Get the list of user storage accounts
34
+ * @param options - parameters used for getting the list of user storage accounts
35
+ */
36
+ export async function getUserStorageAccountsList(options) {
37
+ const { getUserStorageControllerInstance } = options;
38
+ const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(USER_STORAGE_FEATURE_NAMES.accounts);
39
+ return (rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null);
40
+ }
41
+ //# 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":"AAEA,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAM5E,OAAO,EAAE,yCAAyC,EAAE,oBAAgB;AAEpE;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,oBAAoB,EAAE,MAAM,CACjC,yCAAyC,CAC1C,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,0BAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { doesInternalAccountHaveCorrectKeyringType } from './utils';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * @param options - parameters used for getting the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return internalAccountsList?.filter(\n doesInternalAccountHaveCorrectKeyringType,\n );\n}\n\n/**\n * Get the list of user storage accounts\n * @param options - parameters used for getting the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -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 { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\nimport type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\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\nexport type AccountSyncingConfig = {\n isAccountSyncingEnabled: boolean;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -0,0 +1,26 @@
1
+ import type { UserStorageControllerMessenger } from "../UserStorageController.cjs";
2
+ import type UserStorageController from "../UserStorageController.cjs";
3
+ import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
4
+ export type UserStorageAccount = {
5
+ /**
6
+ * The Version 'v' of the User Storage.
7
+ * NOTE - will allow us to support upgrade/downgrades in the future
8
+ */
9
+ [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
10
+ /** the id 'i' of the account */
11
+ i: string;
12
+ /** the address 'a' of the account */
13
+ a: string;
14
+ /** the name 'n' of the account */
15
+ n: string;
16
+ /** the nameLastUpdatedAt timestamp 'nlu' of the account */
17
+ nlu?: number;
18
+ };
19
+ export type AccountSyncingConfig = {
20
+ isAccountSyncingEnabled: boolean;
21
+ };
22
+ export type AccountSyncingOptions = {
23
+ getUserStorageControllerInstance: () => UserStorageController;
24
+ getMessenger: () => UserStorageControllerMessenger;
25
+ };
26
+ //# 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,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAClE,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,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,MAAM,MAAM,oBAAoB,GAAG;IACjC,uBAAuB,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { UserStorageControllerMessenger } from "../UserStorageController.mjs";
2
+ import type UserStorageController from "../UserStorageController.mjs";
3
+ import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
4
+ export type UserStorageAccount = {
5
+ /**
6
+ * The Version 'v' of the User Storage.
7
+ * NOTE - will allow us to support upgrade/downgrades in the future
8
+ */
9
+ [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;
10
+ /** the id 'i' of the account */
11
+ i: string;
12
+ /** the address 'a' of the account */
13
+ a: string;
14
+ /** the name 'n' of the account */
15
+ n: string;
16
+ /** the nameLastUpdatedAt timestamp 'nlu' of the account */
17
+ nlu?: number;
18
+ };
19
+ export type AccountSyncingConfig = {
20
+ isAccountSyncingEnabled: boolean;
21
+ };
22
+ export type AccountSyncingOptions = {
23
+ getUserStorageControllerInstance: () => UserStorageController;
24
+ getMessenger: () => UserStorageControllerMessenger;
25
+ };
26
+ //# 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,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAClE,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,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,MAAM,MAAM,oBAAoB,GAAG;IACjC,uBAAuB,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
@@ -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 { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\nimport type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\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\nexport type AccountSyncingConfig = {\n isAccountSyncingEnabled: boolean;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapInternalAccountToUserStorageAccount = exports.isNameDefaultAccountName = void 0;
3
+ exports.doesInternalAccountHaveCorrectKeyringType = exports.mapInternalAccountToUserStorageAccount = exports.isNameDefaultAccountName = void 0;
4
+ const keyring_controller_1 = require("@metamask/keyring-controller");
4
5
  const constants_1 = require("./constants.cjs");
5
6
  /**
6
7
  * Tells if the given name is a default account name.
@@ -32,4 +33,13 @@ const mapInternalAccountToUserStorageAccount = (internalAccount) => {
32
33
  };
33
34
  };
34
35
  exports.mapInternalAccountToUserStorageAccount = mapInternalAccountToUserStorageAccount;
35
- //# sourceMappingURL=user-storage.cjs.map
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAG5D,+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;;;;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;AAEF;;;;GAIG;AACH,SAAgB,yCAAyC,CACvD,OAAwB;IAExB,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,iCAAY,CAAC,EAAE,CAAC;AAC3D,CAAC;AAJD,8FAIC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport 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 * @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\n/**\n * Checks if the given internal account has the correct keyring type.\n * @param account - The internal account to check\n * @returns Returns true if the internal account has the correct keyring type, false otherwise.\n */\nexport function doesInternalAccountHaveCorrectKeyringType(\n account: InternalAccount,\n) {\n return account.metadata.keyring.type === KeyringTypes.hd;\n}\n"]}
@@ -1,20 +1,5 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
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
- };
2
+ import type { UserStorageAccount } from "./types.cjs";
18
3
  /**
19
4
  * Tells if the given name is a default account name.
20
5
  * Default account names are localized names that are automatically generated by the clients.
@@ -29,4 +14,10 @@ export declare const isNameDefaultAccountName: (name: string) => boolean;
29
14
  * @returns A user storage account
30
15
  */
31
16
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
32
- //# sourceMappingURL=user-storage.d.cts.map
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,yCAAyC,CACvD,OAAO,EAAE,eAAe,WAGzB"}
@@ -1,20 +1,5 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
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
- };
2
+ import type { UserStorageAccount } from "./types.mjs";
18
3
  /**
19
4
  * Tells if the given name is a default account name.
20
5
  * Default account names are localized names that are automatically generated by the clients.
@@ -29,4 +14,10 @@ export declare const isNameDefaultAccountName: (name: string) => boolean;
29
14
  * @returns A user storage account
30
15
  */
31
16
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
32
- //# sourceMappingURL=user-storage.d.mts.map
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,yCAAyC,CACvD,OAAO,EAAE,eAAe,WAGzB"}
@@ -1,3 +1,4 @@
1
+ import { KeyringTypes } from "@metamask/keyring-controller";
1
2
  import { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION, LOCALIZED_DEFAULT_ACCOUNT_NAMES } from "./constants.mjs";
2
3
  /**
3
4
  * Tells if the given name is a default account name.
@@ -27,4 +28,12 @@ export const mapInternalAccountToUserStorageAccount = (internalAccount) => {
27
28
  ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),
28
29
  };
29
30
  };
30
- //# sourceMappingURL=user-storage.mjs.map
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,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;;;;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;AAEF;;;;GAIG;AACH,MAAM,UAAU,yCAAyC,CACvD,OAAwB;IAExB,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport 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 * @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\n/**\n * Checks if the given internal account has the correct keyring type.\n * @param account - The internal account to check\n * @returns Returns true if the internal account has the correct keyring type, false otherwise.\n */\nexport function doesInternalAccountHaveCorrectKeyringType(\n account: InternalAccount,\n) {\n return account.metadata.keyring.type === KeyringTypes.hd;\n}\n"]}
@@ -57,7 +57,7 @@ async function getUserStorage(opts) {
57
57
  return null;
58
58
  }
59
59
  if (userStorageResponse.status !== 200) {
60
- throw new Error('Unable to get User Storage');
60
+ throw new Error(`Unable to get User Storage - HTTP ${userStorageResponse.status}`);
61
61
  }
62
62
  const userStorage = await userStorageResponse.json();
63
63
  const encryptedData = userStorage?.Data ?? null;
@@ -100,7 +100,7 @@ async function getUserStorageAllFeatureEntries(opts) {
100
100
  return null;
101
101
  }
102
102
  if (userStorageResponse.status !== 200) {
103
- throw new Error('Unable to get User Storage');
103
+ throw new Error(`Unable to get User Storage - HTTP ${userStorageResponse.status}`);
104
104
  }
105
105
  const userStorage = await userStorageResponse.json();
106
106
  if (!Array.isArray(userStorage)) {
@@ -161,7 +161,7 @@ async function upsertUserStorage(data, opts) {
161
161
  body: JSON.stringify({ data: encryptedData }),
162
162
  });
163
163
  if (!res.ok) {
164
- throw new Error('user-storage - unable to upsert data');
164
+ throw new Error(`user-storage - unable to upsert data - HTTP ${res.status}`);
165
165
  }
166
166
  }
167
167
  exports.upsertUserStorage = upsertUserStorage;
@@ -195,7 +195,7 @@ async function batchUpsertUserStorage(data, opts) {
195
195
  body: JSON.stringify({ data: formattedData }),
196
196
  });
197
197
  if (!res.ok) {
198
- throw new Error('user-storage - unable to batch upsert data');
198
+ throw new Error(`user-storage - unable to batch upsert data - HTTP ${res.status}`);
199
199
  }
200
200
  }
201
201
  exports.batchUpsertUserStorage = batchUpsertUserStorage;
@@ -222,7 +222,7 @@ async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(encryp
222
222
  body: JSON.stringify({ data: formattedData }),
223
223
  });
224
224
  if (!res.ok) {
225
- throw new Error('user-storage - unable to batch upsert data');
225
+ throw new Error(`user-storage - unable to batch upsert data - HTTP ${res.status}`);
226
226
  }
227
227
  }
228
228
  exports.batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries = batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries;
@@ -243,10 +243,10 @@ async function deleteUserStorage(opts) {
243
243
  },
244
244
  });
245
245
  if (userStorageResponse.status === 404) {
246
- throw new Error('user-storage - feature/entry not found');
246
+ throw new Error(`user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`);
247
247
  }
248
248
  if (!userStorageResponse.ok) {
249
- throw new Error('user-storage - unable to delete data');
249
+ throw new Error(`user-storage - unable to delete data - HTTP ${userStorageResponse.status}`);
250
250
  }
251
251
  }
252
252
  exports.deleteUserStorage = deleteUserStorage;
@@ -277,7 +277,7 @@ async function batchDeleteUserStorage(data, opts) {
277
277
  body: JSON.stringify({ batch_delete: encryptedData }),
278
278
  });
279
279
  if (!res.ok) {
280
- throw new Error('user-storage - unable to batch delete data');
280
+ throw new Error(`user-storage - unable to batch delete data - HTTP ${res.status}`);
281
281
  }
282
282
  }
283
283
  exports.batchDeleteUserStorage = batchDeleteUserStorage;
@@ -297,10 +297,10 @@ async function deleteUserStorageAllFeatureEntries(opts) {
297
297
  },
298
298
  });
299
299
  if (userStorageResponse.status === 404) {
300
- throw new Error('user-storage - feature not found');
300
+ throw new Error(`user-storage - feature not found - HTTP ${userStorageResponse.status}`);
301
301
  }
302
302
  if (!userStorageResponse.ok) {
303
- throw new Error('user-storage - unable to delete data');
303
+ throw new Error(`user-storage - unable to delete data - HTTP ${userStorageResponse.status}`);
304
304
  }
305
305
  }
306
306
  exports.deleteUserStorageAllFeatureEntries = deleteUserStorageAllFeatureEntries;
@@ -1 +1 @@
1
- {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAE3B,gFAAuE;AACvE,qEAAgE;AAChE,8CAAmD;AAKnD,oEAA8D;AAG9D,MAAM,QAAQ,GAAG,IAAA,gBAAU,EAAC,SAAG,CAAC,GAAG,CAAC,CAAC;AAExB,QAAA,gBAAgB,GAAW,QAAQ,CAAC,iBAAiB,CAAC;AACtD,QAAA,qBAAqB,GAAG,GAAG,wBAAgB,qBAAqB,CAAC;AAmC9E;;;;;GAKG;AACI,KAAK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,CAAC;KAC/D;AACH,CAAC;AA/BD,wDA+BC;AAED;;;;GAIG;AACI,KAAK,UAAU,kCAAkC,CACtD,IAAyC;IAEzC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,6BAAqB,IAAI,IAAI,EAAE,CAAC,CAAC;IAExD,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;QACtD,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC;KACF,CAAC,CAAC;IAEH,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;KACrD;IAED,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;AACH,CAAC;AArBD,gFAqBC","sourcesContent":["import log from 'loglevel';\n\nimport encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { SHARED_SALT } from '../../shared/encryption/constants';\nimport { Env, getEnvUrls } from '../../shared/env';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport { createEntryPath } from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nexport const USER_STORAGE_API: string = ENV_URLS.userStorageApiUrl;\nexport const USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;\n\n/**\n * This is the Server Response shape for a feature entry.\n */\nexport type GetUserStorageResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n}[];\n\nexport type UserStorageBaseOptions = {\n bearerToken: string;\n storageKey: string;\n nativeScryptCrypto?: NativeScrypt;\n};\n\nexport type UserStorageOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureAndKey;\n};\n\nexport type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureOnly;\n};\n\nexport type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;\n\n/**\n * User Storage Service - Get Storage Entry.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorage(\n opts: UserStorageOptions,\n): Promise<string | null> {\n try {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates entry does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error('Unable to get User Storage');\n }\n\n const userStorage: GetUserStorageResponse | null =\n await userStorageResponse.json();\n const encryptedData = userStorage?.Data ?? null;\n\n /* istanbul ignore if - this is an edge case where our endpoint returns invalid JSON payload */\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n opts.storageKey,\n nativeScryptCrypto,\n );\n\n // Re-encrypt and re-upload the entry if the salt is random\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await upsertUserStorage(decryptedData, opts);\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Get all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<string[] | null> {\n try {\n const { bearerToken, path, nativeScryptCrypto } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates feature does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error('Unable to get User Storage');\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await userStorageResponse.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n /* istanbul ignore if - unreachable if statement, but kept as edge case */\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry if the salt is different from the shared one\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n reEncryptedEntries,\n opts,\n );\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Set Storage Entry.\n *\n * @param data - data to store\n * @param opts - storage options\n */\nexport async function upsertUserStorage(\n data: string,\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData = await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to upsert data');\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorage(\n data: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData: string[][] = [];\n\n for (const d of data) {\n encryptedData.push([\n createSHA256Hash(d[0] + storageKey),\n await encryption.encryptString(d[1], opts.storageKey, nativeScryptCrypto),\n ]);\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to batch upsert data');\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n encryptedData: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!encryptedData.length) {\n return;\n }\n\n const { bearerToken, path } = opts;\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to batch upsert data');\n }\n}\n\n/**\n * User Storage Service - Delete Storage Entry.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorage(\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey } = opts;\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error('user-storage - feature/entry not found');\n }\n\n if (!userStorageResponse.ok) {\n throw new Error('user-storage - unable to delete data');\n }\n}\n\n/**\n * User Storage Service - Delete multiple storage entries for one specific feature.\n * You cannot use this method to delete multiple features at once.\n *\n * @param data - data to delete, in the form of an array entryKey[]\n * @param opts - storage options\n */\nexport async function batchDeleteUserStorage(\n data: string[],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey } = opts;\n\n const encryptedData: string[] = [];\n\n for (const d of data) {\n encryptedData.push(createSHA256Hash(d + storageKey));\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n // eslint-disable-next-line @typescript-eslint/naming-convention\n body: JSON.stringify({ batch_delete: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error('user-storage - unable to batch delete data');\n }\n}\n\n/**\n * User Storage Service - Delete all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<void> {\n const { bearerToken, path } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error('user-storage - feature not found');\n }\n\n if (!userStorageResponse.ok) {\n throw new Error('user-storage - unable to delete data');\n }\n}\n"]}
1
+ {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAE3B,gFAAuE;AACvE,qEAAgE;AAChE,8CAAmD;AAKnD,oEAA8D;AAG9D,MAAM,QAAQ,GAAG,IAAA,gBAAU,EAAC,SAAG,CAAC,GAAG,CAAC,CAAC;AAExB,QAAA,gBAAgB,GAAW,QAAQ,CAAC,iBAAiB,CAAC;AACtD,QAAA,qBAAqB,GAAG,GAAG,wBAAgB,qBAAqB,CAAC;AAmC9E;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,IAAwB;IAExB,IAAI;QACF,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;QAEnE,MAAM,aAAa,GAAG,IAAA,gCAAe,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,6BAAqB,IAAI,aAAa,EAAE,CAAC,CAAC;QAEjE,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACtD,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,WAAW,EAAE;aACvC;SACF,CAAC,CAAC;QAEH,2DA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AAQ,EAAE,EAAE;QACtD,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC;KACF,CAAC,CAAC;IAEH,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,2CAA2C,mBAAmB,CAAC,MAAM,EAAE,CACxE,CAAC;KACH;IAED,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,+CAA+C,mBAAmB,CAAC,MAAM,EAAE,CAC5E,CAAC;KACH;AACH,CAAC;AAzBD,gFAyBC","sourcesContent":["import log from 'loglevel';\n\nimport encryption, { createSHA256Hash } from '../../shared/encryption';\nimport { SHARED_SALT } from '../../shared/encryption/constants';\nimport { Env, getEnvUrls } from '../../shared/env';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport { createEntryPath } from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nexport const USER_STORAGE_API: string = ENV_URLS.userStorageApiUrl;\nexport const USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;\n\n/**\n * This is the Server Response shape for a feature entry.\n */\nexport type GetUserStorageResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n}[];\n\nexport type UserStorageBaseOptions = {\n bearerToken: string;\n storageKey: string;\n nativeScryptCrypto?: NativeScrypt;\n};\n\nexport type UserStorageOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureAndKey;\n};\n\nexport type UserStorageAllFeatureEntriesOptions = UserStorageBaseOptions & {\n path: UserStoragePathWithFeatureOnly;\n};\n\nexport type UserStorageBatchUpsertOptions = UserStorageAllFeatureEntriesOptions;\n\n/**\n * User Storage Service - Get Storage Entry.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorage(\n opts: UserStorageOptions,\n): Promise<string | null> {\n try {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates entry does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error(\n `Unable to get User Storage - HTTP ${userStorageResponse.status}`,\n );\n }\n\n const userStorage: GetUserStorageResponse | null =\n await userStorageResponse.json();\n const encryptedData = userStorage?.Data ?? null;\n\n /* istanbul ignore if - this is an edge case where our endpoint returns invalid JSON payload */\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n opts.storageKey,\n nativeScryptCrypto,\n );\n\n // Re-encrypt and re-upload the entry if the salt is random\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await upsertUserStorage(decryptedData, opts);\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Get all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<string[] | null> {\n try {\n const { bearerToken, path, nativeScryptCrypto } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates feature does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error(\n `Unable to get User Storage - HTTP ${userStorageResponse.status}`,\n );\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await userStorageResponse.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n /* istanbul ignore if - unreachable if statement, but kept as edge case */\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry if the salt is different from the shared one\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n reEncryptedEntries,\n opts,\n );\n }\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Set Storage Entry.\n *\n * @param data - data to store\n * @param opts - storage options\n */\nexport async function upsertUserStorage(\n data: string,\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData = await encryption.encryptString(\n data,\n opts.storageKey,\n nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param data - data to store, in the form of an array of [entryKey, entryValue] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorage(\n data: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;\n\n const encryptedData: string[][] = [];\n\n for (const d of data) {\n encryptedData.push([\n createSHA256Hash(d[0] + storageKey),\n await encryption.encryptString(d[1], opts.storageKey, nativeScryptCrypto),\n ]);\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Set multiple storage entries for one specific feature.\n * You cannot use this method to set multiple features at once.\n *\n * @param encryptedData - data to store, in the form of an array of [hashedKey, encryptedData] pairs\n * @param opts - storage options\n */\nexport async function batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n encryptedData: [string, string][],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!encryptedData.length) {\n return;\n }\n\n const { bearerToken, path } = opts;\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const formattedData = Object.fromEntries(encryptedData);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n body: JSON.stringify({ data: formattedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch upsert data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete Storage Entry.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorage(\n opts: UserStorageOptions,\n): Promise<void> {\n const { bearerToken, path, storageKey } = opts;\n const encryptedPath = createEntryPath(path, storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${encryptedPath}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error(\n `user-storage - feature/entry not found - HTTP ${userStorageResponse.status}`,\n );\n }\n\n if (!userStorageResponse.ok) {\n throw new Error(\n `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete multiple storage entries for one specific feature.\n * You cannot use this method to delete multiple features at once.\n *\n * @param data - data to delete, in the form of an array entryKey[]\n * @param opts - storage options\n */\nexport async function batchDeleteUserStorage(\n data: string[],\n opts: UserStorageBatchUpsertOptions,\n): Promise<void> {\n if (!data.length) {\n return;\n }\n\n const { bearerToken, path, storageKey } = opts;\n\n const encryptedData: string[] = [];\n\n for (const d of data) {\n encryptedData.push(createSHA256Hash(d + storageKey));\n }\n\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n // eslint-disable-next-line @typescript-eslint/naming-convention\n body: JSON.stringify({ batch_delete: encryptedData }),\n });\n\n if (!res.ok) {\n throw new Error(\n `user-storage - unable to batch delete data - HTTP ${res.status}`,\n );\n }\n}\n\n/**\n * User Storage Service - Delete all storage entries for a specific feature.\n *\n * @param opts - User Storage Options\n */\nexport async function deleteUserStorageAllFeatureEntries(\n opts: UserStorageAllFeatureEntriesOptions,\n): Promise<void> {\n const { bearerToken, path } = opts;\n const url = new URL(`${USER_STORAGE_ENDPOINT}/${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${bearerToken}`,\n },\n });\n\n if (userStorageResponse.status === 404) {\n throw new Error(\n `user-storage - feature not found - HTTP ${userStorageResponse.status}`,\n );\n }\n\n if (!userStorageResponse.ok) {\n throw new Error(\n `user-storage - unable to delete data - HTTP ${userStorageResponse.status}`,\n );\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MAAM,gBAAgB,EAAE,MAAmC,CAAC;AACnE,eAAO,MAAM,qBAAqB,QAA2C,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAEnC,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IAEpD,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;CACd,EAAE,CAAC;AAEJ,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,YAAY,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,GAAG;IACxD,IAAI,EAAE,gCAAgC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,sBAAsB,GAAG;IACzE,IAAI,EAAE,8BAA8B,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,mCAAmC,CAAC;AAEhF;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiDxB;AAED;;;;;GAKG;AACH,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,mCAAmC,GACxC,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CA2E1B;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACxB,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED;;;;;;GAMG;AACH,wBAAsB,0DAA0D,CAC9E,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACjC,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC,CA4Bf;AAED;;;;GAIG;AACH,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,mCAAmC,GACxC,OAAO,CAAC,IAAI,CAAC,CAmBf"}
1
+ {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,wCAAoC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAsC;AAIlE,eAAO,MA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