@metamask/profile-sync-controller 16.0.0 → 17.1.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 (126) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/dist/controllers/authentication/AuthenticationController.cjs +60 -24
  3. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  4. package/dist/controllers/authentication/AuthenticationController.d.cts +6 -4
  5. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  6. package/dist/controllers/authentication/AuthenticationController.d.mts +6 -4
  7. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  8. package/dist/controllers/authentication/AuthenticationController.mjs +61 -25
  9. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  10. package/dist/controllers/authentication/auth-snap-requests.cjs +25 -4
  11. package/dist/controllers/authentication/auth-snap-requests.cjs.map +1 -1
  12. package/dist/controllers/authentication/auth-snap-requests.d.cts +12 -2
  13. package/dist/controllers/authentication/auth-snap-requests.d.cts.map +1 -1
  14. package/dist/controllers/authentication/auth-snap-requests.d.mts +12 -2
  15. package/dist/controllers/authentication/auth-snap-requests.d.mts.map +1 -1
  16. package/dist/controllers/authentication/auth-snap-requests.mjs +23 -3
  17. package/dist/controllers/authentication/auth-snap-requests.mjs.map +1 -1
  18. package/dist/controllers/authentication/mocks/mockResponses.cjs +36 -3
  19. package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -1
  20. package/dist/controllers/authentication/mocks/mockResponses.d.cts +7 -5
  21. package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -1
  22. package/dist/controllers/authentication/mocks/mockResponses.d.mts +7 -5
  23. package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -1
  24. package/dist/controllers/authentication/mocks/mockResponses.mjs +36 -3
  25. package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -1
  26. package/dist/controllers/user-storage/UserStorageController.cjs +79 -27
  27. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  28. package/dist/controllers/user-storage/UserStorageController.d.cts +26 -10
  29. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  30. package/dist/controllers/user-storage/UserStorageController.d.mts +26 -10
  31. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  32. package/dist/controllers/user-storage/UserStorageController.mjs +79 -27
  33. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  34. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +22 -26
  35. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  36. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +5 -2
  37. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  38. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +5 -2
  39. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  40. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +23 -27
  41. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  42. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +8 -8
  43. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -1
  44. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -1
  45. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -1
  46. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +8 -8
  47. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -1
  48. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +16 -7
  49. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
  50. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +6 -2
  51. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
  52. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +6 -2
  53. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
  54. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +16 -7
  55. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
  56. package/dist/controllers/user-storage/account-syncing/utils.cjs +1 -42
  57. package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
  58. package/dist/controllers/user-storage/account-syncing/utils.d.cts +1 -18
  59. package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -1
  60. package/dist/controllers/user-storage/account-syncing/utils.d.mts +1 -18
  61. package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -1
  62. package/dist/controllers/user-storage/account-syncing/utils.mjs +0 -39
  63. package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
  64. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
  65. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
  66. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
  67. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  68. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +22 -22
  69. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  70. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +4 -4
  71. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  72. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +4 -4
  73. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  74. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +22 -22
  75. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  76. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  77. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  78. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  79. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  80. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
  81. package/dist/sdk/authentication-jwt-bearer/types.d.cts +8 -8
  82. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
  83. package/dist/sdk/authentication-jwt-bearer/types.d.mts +8 -8
  84. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
  85. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  86. package/dist/sdk/authentication.cjs +8 -11
  87. package/dist/sdk/authentication.cjs.map +1 -1
  88. package/dist/sdk/authentication.d.cts +4 -4
  89. package/dist/sdk/authentication.d.cts.map +1 -1
  90. package/dist/sdk/authentication.d.mts +4 -4
  91. package/dist/sdk/authentication.d.mts.map +1 -1
  92. package/dist/sdk/authentication.mjs +8 -11
  93. package/dist/sdk/authentication.mjs.map +1 -1
  94. package/dist/sdk/user-storage.cjs +38 -32
  95. package/dist/sdk/user-storage.cjs.map +1 -1
  96. package/dist/sdk/user-storage.d.cts +4 -3
  97. package/dist/sdk/user-storage.d.cts.map +1 -1
  98. package/dist/sdk/user-storage.d.mts +4 -3
  99. package/dist/sdk/user-storage.d.mts.map +1 -1
  100. package/dist/sdk/user-storage.mjs +38 -32
  101. package/dist/sdk/user-storage.mjs.map +1 -1
  102. package/dist/sdk/utils/messaging-signing-snap-requests.cjs +16 -4
  103. package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
  104. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +2 -2
  105. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
  106. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +2 -2
  107. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
  108. package/dist/sdk/utils/messaging-signing-snap-requests.mjs +16 -4
  109. package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
  110. package/dist/shared/storage-schema.cjs +1 -6
  111. package/dist/shared/storage-schema.cjs.map +1 -1
  112. package/dist/shared/storage-schema.d.cts +0 -1
  113. package/dist/shared/storage-schema.d.cts.map +1 -1
  114. package/dist/shared/storage-schema.d.mts +0 -1
  115. package/dist/shared/storage-schema.d.mts.map +1 -1
  116. package/dist/shared/storage-schema.mjs +0 -4
  117. package/dist/shared/storage-schema.mjs.map +1 -1
  118. package/dist/shared/utils/event-queue.cjs +24 -0
  119. package/dist/shared/utils/event-queue.cjs.map +1 -0
  120. package/dist/shared/utils/event-queue.d.cts +6 -0
  121. package/dist/shared/utils/event-queue.d.cts.map +1 -0
  122. package/dist/shared/utils/event-queue.d.mts +6 -0
  123. package/dist/shared/utils/event-queue.d.mts.map +1 -0
  124. package/dist/shared/utils/event-queue.mjs +20 -0
  125. package/dist/shared/utils/event-queue.mjs.map +1 -0
  126. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"setup-subscriptions.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,qBAAqB,QAqC/B"}
1
+ {"version":3,"file":"setup-subscriptions.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,qBAAqB,QA6C/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"setup-subscriptions.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,qBAAqB,QAqC/B"}
1
+ {"version":3,"file":"setup-subscriptions.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/setup-subscriptions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAErD;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,qBAAqB,QA6C/B"}
@@ -7,25 +7,25 @@ import { canPerformAccountSyncing } from "./sync-utils.mjs";
7
7
  */
8
8
  export function setupAccountSyncingSubscriptions(options) {
9
9
  const { getMessenger, getUserStorageControllerInstance } = options;
10
- getMessenger().subscribe('AccountsController:accountAdded',
11
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
12
- async (account) => {
10
+ getMessenger().subscribe('AccountsController:accountAdded', async (account) => {
13
11
  if (!canPerformAccountSyncing(options) ||
14
12
  !getUserStorageControllerInstance().state
15
13
  .hasAccountSyncingSyncedAtLeastOnce) {
16
14
  return;
17
15
  }
18
- await saveInternalAccountToUserStorage(account, options);
16
+ const { eventQueue } = getUserStorageControllerInstance();
17
+ eventQueue.push(async () => await saveInternalAccountToUserStorage(account, options));
18
+ await eventQueue.run();
19
19
  });
20
- getMessenger().subscribe('AccountsController:accountRenamed',
21
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
22
- async (account) => {
20
+ getMessenger().subscribe('AccountsController:accountRenamed', async (account) => {
23
21
  if (!canPerformAccountSyncing(options) ||
24
22
  !getUserStorageControllerInstance().state
25
23
  .hasAccountSyncingSyncedAtLeastOnce) {
26
24
  return;
27
25
  }
28
- await saveInternalAccountToUserStorage(account, options);
26
+ const { eventQueue } = getUserStorageControllerInstance();
27
+ eventQueue.push(async () => await saveInternalAccountToUserStorage(account, options));
28
+ await eventQueue.run();
29
29
  });
30
30
  }
31
31
  //# sourceMappingURL=setup-subscriptions.mjs.map
@@ -1 +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,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC;IAEjC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC;IAEnC,kEAAkE;IAClE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n *\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, options);\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n await saveInternalAccountToUserStorage(account, options);\n },\n );\n}\n"]}
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,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,YAAY,EAAE,CAAC,SAAS,CACtB,iCAAiC,EAEjC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,EAAE,UAAU,EAAE,GAAG,gCAAgC,EAAE,CAAC;QAE1D,UAAU,CAAC,IAAI,CACb,KAAK,IAAI,EAAE,CAAC,MAAM,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CACrE,CAAC;QACF,MAAM,UAAU,CAAC,GAAG,EAAE,CAAC;IACzB,CAAC,CACF,CAAC;IAEF,YAAY,EAAE,CAAC,SAAS,CACtB,mCAAmC,EAEnC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IACE,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClC,CAAC,gCAAgC,EAAE,CAAC,KAAK;iBACtC,kCAAkC,EACrC;YACA,OAAO;SACR;QAED,MAAM,EAAE,UAAU,EAAE,GAAG,gCAAgC,EAAE,CAAC;QAE1D,UAAU,CAAC,IAAI,CACb,KAAK,IAAI,EAAE,CAAC,MAAM,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CACrE,CAAC;QACF,MAAM,UAAU,CAAC,GAAG,EAAE,CAAC;IACzB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { saveInternalAccountToUserStorage } from './controller-integration';\nimport { canPerformAccountSyncing } from './sync-utils';\nimport type { AccountSyncingOptions } from './types';\n\n/**\n * Initialize and setup events to listen to for account syncing\n *\n * @param options - parameters used for initializing and enabling account syncing\n */\nexport function setupAccountSyncingSubscriptions(\n options: AccountSyncingOptions,\n) {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n getMessenger().subscribe(\n 'AccountsController:accountAdded',\n\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n const { eventQueue } = getUserStorageControllerInstance();\n\n eventQueue.push(\n async () => await saveInternalAccountToUserStorage(account, options),\n );\n await eventQueue.run();\n },\n );\n\n getMessenger().subscribe(\n 'AccountsController:accountRenamed',\n\n async (account) => {\n if (\n !canPerformAccountSyncing(options) ||\n !getUserStorageControllerInstance().state\n .hasAccountSyncingSyncedAtLeastOnce\n ) {\n return;\n }\n\n const { eventQueue } = getUserStorageControllerInstance();\n\n eventQueue.push(\n async () => await saveInternalAccountToUserStorage(account, options),\n );\n await eventQueue.run();\n },\n );\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getUserStorageAccountsList = exports.getInternalAccountsList = exports.canPerformAccountSyncing = void 0;
4
- const utils_1 = require("./utils.cjs");
4
+ const keyring_controller_1 = require("@metamask/keyring-controller");
5
5
  const storage_schema_1 = require("../../../shared/storage-schema.cjs");
6
6
  /**
7
7
  * Checks if account syncing can be performed based on a set of conditions
@@ -28,24 +28,33 @@ exports.canPerformAccountSyncing = canPerformAccountSyncing;
28
28
  * and are from the HD keyring
29
29
  *
30
30
  * @param options - parameters used for getting the list of internal accounts
31
+ * @param entropySourceId - The entropy source ID used to derive the key,
32
+ * when multiple sources are available (Multi-SRP).
31
33
  * @returns the list of internal accounts
32
34
  */
33
- async function getInternalAccountsList(options) {
35
+ async function getInternalAccountsList(options, entropySourceId) {
34
36
  const { getMessenger } = options;
35
- // eslint-disable-next-line @typescript-eslint/await-thenable
36
- const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
37
- return await (0, utils_1.mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList)(internalAccountsList, options);
37
+ let internalAccountsList = getMessenger().call('AccountsController:listAccounts');
38
+ const doEachInternalAccountHaveEntropySource = internalAccountsList.every((account) => Boolean(account.options.entropySource));
39
+ if (!doEachInternalAccountHaveEntropySource) {
40
+ await getMessenger().call('AccountsController:updateAccounts');
41
+ internalAccountsList = getMessenger().call('AccountsController:listAccounts');
42
+ }
43
+ return internalAccountsList.filter((account) => entropySourceId === account.options.entropySource &&
44
+ account.metadata.keyring.type === String(keyring_controller_1.KeyringTypes.hd));
38
45
  }
39
46
  exports.getInternalAccountsList = getInternalAccountsList;
40
47
  /**
41
48
  * Get the list of user storage accounts
42
49
  *
43
50
  * @param options - parameters used for getting the list of user storage accounts
51
+ * @param entropySourceId - The entropy source ID used to derive the storage key,
52
+ * when multiple sources are available (Multi-SRP).
44
53
  * @returns the list of user storage accounts
45
54
  */
46
- async function getUserStorageAccountsList(options) {
55
+ async function getUserStorageAccountsList(options, entropySourceId) {
47
56
  const { getUserStorageControllerInstance } = options;
48
- const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts);
57
+ const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts, entropySourceId);
49
58
  return (rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null);
50
59
  }
51
60
  exports.getUserStorageAccountsList = getUserStorageAccountsList;
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAGA,uCAA2F;AAC3F,uEAA4E;AAE5E;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EACJ,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,GAC3B,GAAG,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,sBAAsB;QACvB,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAxBD,4DAwBC;AAED;;;;;;;GAOG;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,MAAM,IAAA,wEAAgE,EAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAdD,0DAcC;AAED;;;;;GAKG;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 type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isBackupAndSyncEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isBackupAndSyncEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns 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 await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns 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"]}
1
+ {"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAI5D,uEAA4E;AAE5E;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EACJ,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,GAC3B,GAAG,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,sBAAsB;QACvB,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAxBD,4DAwBC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,uBAAuB,CAC3C,OAA8B,EAC9B,eAAuB;IAEvB,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,IAAI,oBAAoB,GAAG,YAAY,EAAE,CAAC,IAAI,CAC5C,iCAAiC,CAClC,CAAC;IAEF,MAAM,sCAAsC,GAAG,oBAAoB,CAAC,KAAK,CACvE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CACpD,CAAC;IAEF,IAAI,CAAC,sCAAsC,EAAE;QAC3C,MAAM,YAAY,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QAC/D,oBAAoB,GAAG,YAAY,EAAE,CAAC,IAAI,CACxC,iCAAiC,CAClC,CAAC;KACH;IAED,OAAO,oBAAoB,CAAC,MAAM,CAChC,CAAC,OAAO,EAAE,EAAE,CACV,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,aAAa;QACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,iCAAY,CAAC,EAAE,CAAC,CAC5D,CAAC;AACJ,CAAC;AA1BD,0DA0BC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAA8B,EAC9B,eAAwB;IAExB,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,2CAA0B,CAAC,QAAQ,EACnC,eAAe,CAChB,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC;AAfD,gEAeC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isBackupAndSyncEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isBackupAndSyncEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n let internalAccountsList = getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n const doEachInternalAccountHaveEntropySource = internalAccountsList.every(\n (account) => Boolean(account.options.entropySource),\n );\n\n if (!doEachInternalAccountHaveEntropySource) {\n await getMessenger().call('AccountsController:updateAccounts');\n internalAccountsList = getMessenger().call(\n 'AccountsController:listAccounts',\n );\n }\n\n return internalAccountsList.filter(\n (account) =>\n entropySourceId === account.options.entropySource &&\n account.metadata.keyring.type === String(KeyringTypes.hd), // sync only EVM accounts until we support multichain accounts\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @param entropySourceId - The entropy source ID used to derive the storage key,\n * when multiple sources are available (Multi-SRP).\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n entropySourceId?: string,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -13,14 +13,18 @@ export declare function canPerformAccountSyncing(options: AccountSyncingOptions)
13
13
  * and are from the HD keyring
14
14
  *
15
15
  * @param options - parameters used for getting the list of internal accounts
16
+ * @param entropySourceId - The entropy source ID used to derive the key,
17
+ * when multiple sources are available (Multi-SRP).
16
18
  * @returns the list of internal accounts
17
19
  */
18
- export declare function getInternalAccountsList(options: AccountSyncingOptions): Promise<InternalAccount[]>;
20
+ export declare function getInternalAccountsList(options: AccountSyncingOptions, entropySourceId: string): Promise<InternalAccount[]>;
19
21
  /**
20
22
  * Get the list of user storage accounts
21
23
  *
22
24
  * @param options - parameters used for getting the list of user storage accounts
25
+ * @param entropySourceId - The entropy source ID used to derive the storage key,
26
+ * when multiple sources are available (Multi-SRP).
23
27
  * @returns the list of user storage accounts
24
28
  */
25
- export declare function getUserStorageAccountsList(options: AccountSyncingOptions): Promise<UserStorageAccount[] | null>;
29
+ export declare function getUserStorageAccountsList(options: AccountSyncingOptions, entropySourceId?: string): Promise<UserStorageAccount[] | null>;
26
30
  //# sourceMappingURL=sync-utils.d.cts.map
@@ -1 +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;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAIzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAsBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
1
+ {"version":3,"file":"sync-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAGzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAsBT;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,eAAe,EAAE,CAAC,CAuB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,EAC9B,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAYtC"}
@@ -13,14 +13,18 @@ export declare function canPerformAccountSyncing(options: AccountSyncingOptions)
13
13
  * and are from the HD keyring
14
14
  *
15
15
  * @param options - parameters used for getting the list of internal accounts
16
+ * @param entropySourceId - The entropy source ID used to derive the key,
17
+ * when multiple sources are available (Multi-SRP).
16
18
  * @returns the list of internal accounts
17
19
  */
18
- export declare function getInternalAccountsList(options: AccountSyncingOptions): Promise<InternalAccount[]>;
20
+ export declare function getInternalAccountsList(options: AccountSyncingOptions, entropySourceId: string): Promise<InternalAccount[]>;
19
21
  /**
20
22
  * Get the list of user storage accounts
21
23
  *
22
24
  * @param options - parameters used for getting the list of user storage accounts
25
+ * @param entropySourceId - The entropy source ID used to derive the storage key,
26
+ * when multiple sources are available (Multi-SRP).
23
27
  * @returns the list of user storage accounts
24
28
  */
25
- export declare function getUserStorageAccountsList(options: AccountSyncingOptions): Promise<UserStorageAccount[] | null>;
29
+ export declare function getUserStorageAccountsList(options: AccountSyncingOptions, entropySourceId?: string): Promise<UserStorageAccount[] | null>;
26
30
  //# sourceMappingURL=sync-utils.d.mts.map
@@ -1 +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;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAIzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAsBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
1
+ {"version":3,"file":"sync-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAGzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAsBT;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,eAAe,EAAE,CAAC,CAuB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,EAC9B,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAYtC"}
@@ -1,4 +1,4 @@
1
- import { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from "./utils.mjs";
1
+ import { KeyringTypes } from "@metamask/keyring-controller";
2
2
  import { USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
3
3
  /**
4
4
  * Checks if account syncing can be performed based on a set of conditions
@@ -24,23 +24,32 @@ export function canPerformAccountSyncing(options) {
24
24
  * and are from the HD keyring
25
25
  *
26
26
  * @param options - parameters used for getting the list of internal accounts
27
+ * @param entropySourceId - The entropy source ID used to derive the key,
28
+ * when multiple sources are available (Multi-SRP).
27
29
  * @returns the list of internal accounts
28
30
  */
29
- export async function getInternalAccountsList(options) {
31
+ export async function getInternalAccountsList(options, entropySourceId) {
30
32
  const { getMessenger } = options;
31
- // eslint-disable-next-line @typescript-eslint/await-thenable
32
- const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
33
- return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(internalAccountsList, options);
33
+ let internalAccountsList = getMessenger().call('AccountsController:listAccounts');
34
+ const doEachInternalAccountHaveEntropySource = internalAccountsList.every((account) => Boolean(account.options.entropySource));
35
+ if (!doEachInternalAccountHaveEntropySource) {
36
+ await getMessenger().call('AccountsController:updateAccounts');
37
+ internalAccountsList = getMessenger().call('AccountsController:listAccounts');
38
+ }
39
+ return internalAccountsList.filter((account) => entropySourceId === account.options.entropySource &&
40
+ account.metadata.keyring.type === String(KeyringTypes.hd));
34
41
  }
35
42
  /**
36
43
  * Get the list of user storage accounts
37
44
  *
38
45
  * @param options - parameters used for getting the list of user storage accounts
46
+ * @param entropySourceId - The entropy source ID used to derive the storage key,
47
+ * when multiple sources are available (Multi-SRP).
39
48
  * @returns the list of user storage accounts
40
49
  */
41
- export async function getUserStorageAccountsList(options) {
50
+ export async function getUserStorageAccountsList(options, entropySourceId) {
42
51
  const { getUserStorageControllerInstance } = options;
43
- const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(USER_STORAGE_FEATURE_NAMES.accounts);
52
+ const rawAccountsListResponse = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(USER_STORAGE_FEATURE_NAMES.accounts, entropySourceId);
44
53
  return (rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null);
45
54
  }
46
55
  //# sourceMappingURL=sync-utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.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Account } from '@metamask/keyring-internal-api';\n\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isBackupAndSyncEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isBackupAndSyncEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns 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 await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns 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"]}
1
+ {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAI5D,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EACJ,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,GAC3B,GAAG,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC7C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,sBAAsB;QACvB,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B,EAC9B,eAAuB;IAEvB,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,IAAI,oBAAoB,GAAG,YAAY,EAAE,CAAC,IAAI,CAC5C,iCAAiC,CAClC,CAAC;IAEF,MAAM,sCAAsC,GAAG,oBAAoB,CAAC,KAAK,CACvE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CACpD,CAAC;IAEF,IAAI,CAAC,sCAAsC,EAAE;QAC3C,MAAM,YAAY,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QAC/D,oBAAoB,GAAG,YAAY,EAAE,CAAC,IAAI,CACxC,iCAAiC,CAClC,CAAC;KACH;IAED,OAAO,oBAAoB,CAAC,MAAM,CAChC,CAAC,OAAO,EAAE,EAAE,CACV,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,aAAa;QACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAC5D,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA8B,EAC9B,eAAwB;IAExB,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,0BAA0B,CAAC,QAAQ,EACnC,eAAe,CAChB,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n options: AccountSyncingOptions,\n): boolean {\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const {\n isBackupAndSyncEnabled,\n isAccountSyncingEnabled,\n isAccountSyncingInProgress,\n } = getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isBackupAndSyncEnabled ||\n !isAccountSyncingEnabled ||\n !isAuthEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n entropySourceId: string,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n let internalAccountsList = getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n const doEachInternalAccountHaveEntropySource = internalAccountsList.every(\n (account) => Boolean(account.options.entropySource),\n );\n\n if (!doEachInternalAccountHaveEntropySource) {\n await getMessenger().call('AccountsController:updateAccounts');\n internalAccountsList = getMessenger().call(\n 'AccountsController:listAccounts',\n );\n }\n\n return internalAccountsList.filter(\n (account) =>\n entropySourceId === account.options.entropySource &&\n account.metadata.keyring.type === String(KeyringTypes.hd), // sync only EVM accounts until we support multichain accounts\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @param entropySourceId - The entropy source ID used to derive the storage key,\n * when multiple sources are available (Multi-SRP).\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n entropySourceId?: string,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInternalAccountFromPrimarySRPHdKeyring = exports.mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList = 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.
@@ -34,44 +33,4 @@ const mapInternalAccountToUserStorageAccount = (internalAccount) => {
34
33
  };
35
34
  };
36
35
  exports.mapInternalAccountToUserStorageAccount = mapInternalAccountToUserStorageAccount;
37
- /**
38
- * Transforms a list of any internal accounts to a list of internal accounts that
39
- * have the correct keyring type and are from the primary SRP.
40
- *
41
- * @param internalAccountsList - The list of internal accounts
42
- * @param options - Parameters used for checking if the internal account is from the primary SRP
43
- * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.
44
- */
45
- async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(internalAccountsList, options) {
46
- const { getMessenger } = options;
47
- const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
48
- type: keyring_controller_1.KeyringTypes.hd,
49
- index: 0,
50
- }, async ({ keyring }) => {
51
- return await keyring.getAccounts();
52
- }));
53
- return internalAccountsList.filter((account) => primarySRPHdKeyringAccountsAddresses?.includes(account.address));
54
- }
55
- exports.mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList = mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList;
56
- /**
57
- * Checks if the given internal account is from the primary SRP and is from the HD keyring.
58
- *
59
- * @param account - The internal account to check
60
- * @param options - Parameters used for checking if the internal account is from the primary SRP
61
- * @returns Returns true if the internal account is from the primary SRP, false otherwise.
62
- */
63
- async function isInternalAccountFromPrimarySRPHdKeyring(account, options) {
64
- if (account.metadata.keyring.type !== keyring_controller_1.KeyringTypes.hd) {
65
- return false;
66
- }
67
- const { getMessenger } = options;
68
- const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
69
- type: keyring_controller_1.KeyringTypes.hd,
70
- index: 0,
71
- }, async ({ keyring }) => {
72
- return await keyring.getAccounts();
73
- }));
74
- return primarySRPHdKeyringAccountsAddresses.includes(account.address);
75
- }
76
- exports.isInternalAccountFromPrimarySRPHdKeyring = isInternalAccountFromPrimarySRPHdKeyring;
77
36
  //# sourceMappingURL=utils.cjs.map
@@ -1 +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;;;;;GAKG;AACI,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,oCAAwB,CAAC,EAAE,gCAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,sCAAsC,0CAajD;AAEF;;;;;;;GAOG;AACI,KAAK,UAAU,gEAAgE,CACpF,oBAAuC,EACvC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oCAAoC,GAAG,CAAC,MAAM,YAAY,EAAE,CAAC,IAAI,CACrE,+BAA+B,EAC/B;QACE,IAAI,EAAE,iCAAY,CAAC,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpB,OAAO,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CACF,CAAa,CAAC;IAEf,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAC7C,oCAAoC,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAChE,CAAC;AACJ,CAAC;AApBD,4IAoBC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,wCAAwC,CAC5D,OAAwB,EACxB,OAA8B;IAE9B,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,iCAAY,CAAC,EAAE,EAAE;QACrD,OAAO,KAAK,CAAC;KACd;IAED,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oCAAoC,GAAG,CAAC,MAAM,YAAY,EAAE,CAAC,IAAI,CACrE,+BAA+B,EAC/B;QACE,IAAI,EAAE,iCAAY,CAAC,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpB,OAAO,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CACF,CAAa,CAAC;IAEf,OAAO,oCAAoC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC;AAtBD,4FAsBC","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 { AccountSyncingOptions, UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n\n/**\n * Transforms a list of any internal accounts to a list of internal accounts that\n * have the correct keyring type and are from the primary SRP.\n *\n * @param internalAccountsList - The list of internal accounts\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.\n */\nexport async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList: InternalAccount[],\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return internalAccountsList.filter((account) =>\n primarySRPHdKeyringAccountsAddresses?.includes(account.address),\n );\n}\n\n/**\n * Checks if the given internal account is from the primary SRP and is from the HD keyring.\n *\n * @param account - The internal account to check\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns true if the internal account is from the primary SRP, false otherwise.\n */\nexport async function isInternalAccountFromPrimarySRPHdKeyring(\n account: InternalAccount,\n options: AccountSyncingOptions,\n): Promise<boolean> {\n if (account.metadata.keyring.type !== KeyringTypes.hd) {\n return false;\n }\n\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return primarySRPHdKeyringAccountsAddresses.includes(account.address);\n}\n"]}
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":";;;AAEA,+CAIqB;AAGrB;;;;;;GAMG;AAEI,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,2CAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC;AAEF;;;;;GAKG;AACI,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,oCAAwB,CAAC,EAAE,gCAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,sCAAsC,0CAajD","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\nimport type { UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { AccountSyncingOptions, UserStorageAccount } from "./types.cjs";
2
+ import type { UserStorageAccount } from "./types.cjs";
3
3
  /**
4
4
  * Tells if the given name is a default account name.
5
5
  * Default account names are localized names that are automatically generated by the clients.
@@ -15,21 +15,4 @@ export declare const isNameDefaultAccountName: (name: string) => boolean;
15
15
  * @returns A user storage account
16
16
  */
17
17
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
18
- /**
19
- * Transforms a list of any internal accounts to a list of internal accounts that
20
- * have the correct keyring type and are from the primary SRP.
21
- *
22
- * @param internalAccountsList - The list of internal accounts
23
- * @param options - Parameters used for checking if the internal account is from the primary SRP
24
- * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.
25
- */
26
- export declare function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(internalAccountsList: InternalAccount[], options: AccountSyncingOptions): Promise<InternalAccount[]>;
27
- /**
28
- * Checks if the given internal account is from the primary SRP and is from the HD keyring.
29
- *
30
- * @param account - The internal account to check
31
- * @param options - Parameters used for checking if the internal account is from the primary SRP
32
- * @returns Returns true if the internal account is from the primary SRP, false otherwise.
33
- */
34
- export declare function isInternalAccountFromPrimarySRPHdKeyring(account: InternalAccount, options: AccountSyncingOptions): Promise<boolean>;
35
18
  //# sourceMappingURL=utils.d.cts.map
@@ -1 +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,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAEzE;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gEAAgE,CACpF,oBAAoB,EAAE,eAAe,EAAE,EACvC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAiB5B;AAED;;;;;;GAMG;AACH,wBAAsB,wCAAwC,CAC5D,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,OAAO,CAAC,CAmBlB"}
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { AccountSyncingOptions, UserStorageAccount } from "./types.mjs";
2
+ import type { UserStorageAccount } from "./types.mjs";
3
3
  /**
4
4
  * Tells if the given name is a default account name.
5
5
  * Default account names are localized names that are automatically generated by the clients.
@@ -15,21 +15,4 @@ export declare const isNameDefaultAccountName: (name: string) => boolean;
15
15
  * @returns A user storage account
16
16
  */
17
17
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
18
- /**
19
- * Transforms a list of any internal accounts to a list of internal accounts that
20
- * have the correct keyring type and are from the primary SRP.
21
- *
22
- * @param internalAccountsList - The list of internal accounts
23
- * @param options - Parameters used for checking if the internal account is from the primary SRP
24
- * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.
25
- */
26
- export declare function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(internalAccountsList: InternalAccount[], options: AccountSyncingOptions): Promise<InternalAccount[]>;
27
- /**
28
- * Checks if the given internal account is from the primary SRP and is from the HD keyring.
29
- *
30
- * @param account - The internal account to check
31
- * @param options - Parameters used for checking if the internal account is from the primary SRP
32
- * @returns Returns true if the internal account is from the primary SRP, false otherwise.
33
- */
34
- export declare function isInternalAccountFromPrimarySRPHdKeyring(account: InternalAccount, options: AccountSyncingOptions): Promise<boolean>;
35
18
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +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,qBAAqB,EAAE,kBAAkB,EAAE,oBAAgB;AAEzE;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gEAAgE,CACpF,oBAAoB,EAAE,eAAe,EAAE,EACvC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAiB5B;AAED;;;;;;GAMG;AACH,wBAAsB,wCAAwC,CAC5D,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,OAAO,CAAC,CAmBlB"}
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAOtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;GAMG;AAEH,eAAO,MAAM,wBAAwB,SAAU,MAAM,YAIpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC"}
@@ -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.
@@ -29,42 +28,4 @@ export const mapInternalAccountToUserStorageAccount = (internalAccount) => {
29
28
  ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),
30
29
  };
31
30
  };
32
- /**
33
- * Transforms a list of any internal accounts to a list of internal accounts that
34
- * have the correct keyring type and are from the primary SRP.
35
- *
36
- * @param internalAccountsList - The list of internal accounts
37
- * @param options - Parameters used for checking if the internal account is from the primary SRP
38
- * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.
39
- */
40
- export async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(internalAccountsList, options) {
41
- const { getMessenger } = options;
42
- const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
43
- type: KeyringTypes.hd,
44
- index: 0,
45
- }, async ({ keyring }) => {
46
- return await keyring.getAccounts();
47
- }));
48
- return internalAccountsList.filter((account) => primarySRPHdKeyringAccountsAddresses?.includes(account.address));
49
- }
50
- /**
51
- * Checks if the given internal account is from the primary SRP and is from the HD keyring.
52
- *
53
- * @param account - The internal account to check
54
- * @param options - Parameters used for checking if the internal account is from the primary SRP
55
- * @returns Returns true if the internal account is from the primary SRP, false otherwise.
56
- */
57
- export async function isInternalAccountFromPrimarySRPHdKeyring(account, options) {
58
- if (account.metadata.keyring.type !== KeyringTypes.hd) {
59
- return false;
60
- }
61
- const { getMessenger } = options;
62
- const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
63
- type: KeyringTypes.hd,
64
- index: 0,
65
- }, async ({ keyring }) => {
66
- return await keyring.getAccounts();
67
- }));
68
- return primarySRPHdKeyringAccountsAddresses.includes(account.address);
69
- }
70
31
  //# sourceMappingURL=utils.mjs.map
@@ -1 +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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,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BAA+B,EAC/B;QACE,IAAI,EAAE,YAAY,CAAC,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpB,OAAO,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CACF,CAAa,CAAC;IAEf,OAAO,oCAAoC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACxE,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 { AccountSyncingOptions, UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n\n/**\n * Transforms a list of any internal accounts to a list of internal accounts that\n * have the correct keyring type and are from the primary SRP.\n *\n * @param internalAccountsList - The list of internal accounts\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.\n */\nexport async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList: InternalAccount[],\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return internalAccountsList.filter((account) =>\n primarySRPHdKeyringAccountsAddresses?.includes(account.address),\n );\n}\n\n/**\n * Checks if the given internal account is from the primary SRP and is from the HD keyring.\n *\n * @param account - The internal account to check\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns true if the internal account is from the primary SRP, false otherwise.\n */\nexport async function isInternalAccountFromPrimarySRPHdKeyring(\n account: InternalAccount,\n options: AccountSyncingOptions,\n): Promise<boolean> {\n if (account.metadata.keyring.type !== KeyringTypes.hd) {\n return false;\n }\n\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return primarySRPHdKeyringAccountsAddresses.includes(account.address);\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAChC,wBAAoB;AAGrB;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,+BAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,wBAAwB,CAAC,EAAE,oBAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\nimport type { UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"flow-siwe.cjs","sourceRoot":"","sources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BAAA,IAAI,iCAAQ,CAAC,IAAI,EACjB,uBAAA,IAAI,iCAAQ,CAAC,GAAG,CACjB,CAAC;IAEF,YAAY;IACZ,MAAM,aAAa,GAAG,MAAM,IAAA,wBAAa,EACvC,YAAY,CAAC,KAAK,EAClB,uBAAA,IAAI,iCAAQ,CAAC,GAAG,EAChB,uBAAA,IAAI,iCAAQ,CAAC,QAAQ,CACtB,CAAC;IAEF,OAAO;IACP,MAAM,MAAM,GAAkB;QAC5B,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,KAAK,EAAE,aAAa;KACrB,CAAC;IAEF,MAAM,uBAAA,IAAI,kCAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AAChB,CAAC,uGAE0B,KAAa;IACtC,uBAAA,IAAI,qEAAc,MAAlB,IAAI,EAAe,uBAAA,IAAI,iCAAQ,CAAC,CAAC;IAEjC,OAAO,IAAI,kBAAW,CAAC;QACrB,MAAM,EAAE,uBAAA,IAAI,iCAAQ,EAAE,MAAM;QAC5B,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,GAAG,EAAE,IAAA,yBAAc,EAAC,uBAAA,IAAI,iCAAQ,CAAC,GAAG,CAAC;QACrC,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC,CAAC,cAAc,EAAE,CAAC;AACtB,CAAC,6EAGC,MAAkC;IAElC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,wBAAe,CAAC,6CAA6C,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["import { SiweMessage } from 'siwe';\n\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getNonce,\n} from './services';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n} from './types';\nimport { ValidationError } from '../errors';\nimport { validateLoginResponse } from '../utils/validate-login-response';\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\n};\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"flow-siwe.cjs","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAmC;AAEnC,6CAKoB;AASpB,0CAA4C;AAC5C,kFAAyE;AAazE,MAAa,iBAAiB;IAO5B,YACE,MAA4C,EAC5C,OAAmC;;QAR5B,4CAAoB;QAEpB,6CAAqC;QAE9C,4CAA+C;QAM7C,uBAAA,IAAI,6BAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,8BAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,uEAAgB,MAApB,IAAI,CAAkB,CAAC;QAC7C,IAAI,OAAO,EAAE;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AM,CAAC;AAChB,CAAC,uGAE0B,KAAa;IACtC,uBAAA,IAAI,qEAAc,MAAlB,IAAI,EAAe,uBAAA,IAAI,iCAAQ,CAAC,CAAC;IAEjC,OAAO,IAAI,kBAAW,CAAC;QACrB,MAAM,EAAE,uBAAA,IAAI,iCAAQ,EAAE,MAAM;QAC5B,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,GAAG,EAAE,IAAA,yBAAc,EAAC,uBAAA,IAAI,iCAAQ,CAAC,GAAG,CAAC;QACrC,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC,CAAC,cAAc,EAAE,CAAC;AACtB,CAAC,6EAGC,MAAkC;IAElC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,wBAAe,CAAC,6CAA6C,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["import { SiweMessage } from 'siwe';\n\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getNonce,\n} from './services';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n} from './types';\nimport { ValidationError } from '../errors';\nimport { validateLoginResponse } from '../utils/validate-login-response';\n\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\n};\n\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"flow-siwe.d.cts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,SAAS,EAET,WAAW,EACZ,oBAAgB;AAMjB,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAIF,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,iBAAkB,YAAW,SAAS;;gBAQ/C,MAAM,EAAE,UAAU,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAA;KAAE,EAC5C,OAAO,EAAE,0BAA0B;IAM/B,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAUjC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAUtC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKhC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnD,OAAO,CAAC,MAAM,EAAE,yBAAyB;CA6E1C"}
1
+ {"version":3,"file":"flow-siwe.d.cts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,SAAS,EAET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 'siwe';\n\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getNonce,\n} from './services';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n} from './types';\nimport { ValidationError } from '../errors';\nimport { validateLoginResponse } from '../utils/validate-login-response';\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\n};\n\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"flow-siwe.mjs","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,aAAa;AAEnC,OAAO,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,QAAQ,EACT,uBAAmB;AASpB,OAAO,EAAE,eAAe,EAAE,sBAAkB;AAC5C,OAAO,EAAE,qBAAqB,EAAE,6CAAyC;AAazE,MAAM,OAAO,iBAAiB;IAO5B,YACE,MAA4C,EAC5C,OAAmC;;QAR5B,4CAAoB;QAEpB,6CAAqC;QA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O;IACP,MAAM,MAAM,GAAkB;QAC5B,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,KAAK,EAAE,aAAa;KACrB,CAAC;IAEF,MAAM,uBAAA,IAAI,kCAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AAChB,CAAC,uGAE0B,KAAa;IACtC,uBAAA,IAAI,qEAAc,MAAlB,IAAI,EAAe,uBAAA,IAAI,iCAAQ,CAAC,CAAC;IAEjC,OAAO,IAAI,WAAW,CAAC;QACrB,MAAM,EAAE,uBAAA,IAAI,iCAAQ,EAAE,MAAM;QAC5B,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,GAAG,EAAE,cAAc,CAAC,uBAAA,IAAI,iCAAQ,CAAC,GAAG,CAAC;QACrC,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC,CAAC,cAAc,EAAE,CAAC;AACtB,CAAC,6EAGC,MAAkC;IAElC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,eAAe,CAAC,6CAA6C,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["import { SiweMessage } from 'siwe';\n\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getNonce,\n} from './services';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n} from './types';\nimport { ValidationError } from '../errors';\nimport { validateLoginResponse } from '../utils/validate-login-response';\n\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\n};\n\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}