@metamask/profile-sync-controller 4.1.1 → 6.0.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 (240) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  3. package/dist/controllers/authentication/AuthenticationController.d.cts +2 -2
  4. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  5. package/dist/controllers/authentication/AuthenticationController.d.mts +2 -2
  6. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  7. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  8. package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +0 -5
  9. package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +1 -1
  10. package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +1 -1
  11. package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +1 -1
  12. package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +0 -5
  13. package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +1 -1
  14. package/dist/controllers/authentication/services.cjs +0 -2
  15. package/dist/controllers/authentication/services.cjs.map +1 -1
  16. package/dist/controllers/authentication/services.d.cts +5 -3
  17. package/dist/controllers/authentication/services.d.cts.map +1 -1
  18. package/dist/controllers/authentication/services.d.mts +5 -3
  19. package/dist/controllers/authentication/services.d.mts.map +1 -1
  20. package/dist/controllers/authentication/services.mjs +0 -2
  21. package/dist/controllers/authentication/services.mjs.map +1 -1
  22. package/dist/controllers/user-storage/UserStorageController.cjs +11 -42
  23. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  24. package/dist/controllers/user-storage/UserStorageController.d.cts +8 -15
  25. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  26. package/dist/controllers/user-storage/UserStorageController.d.mts +8 -15
  27. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  28. package/dist/controllers/user-storage/UserStorageController.mjs +11 -42
  29. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  30. package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +3 -15
  31. package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +1 -1
  32. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +10 -10
  33. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +1 -1
  34. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +10 -10
  35. package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +1 -1
  36. package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +4 -16
  37. package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +1 -1
  38. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs +5 -1
  39. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +1 -1
  40. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts +4 -0
  41. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +1 -1
  42. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts +4 -0
  43. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +1 -1
  44. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs +5 -1
  45. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +1 -1
  46. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +1 -1
  47. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +1 -1
  48. package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +1 -1
  49. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +1 -1
  50. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +1 -1
  51. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +1 -1
  52. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +5 -2
  53. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -1
  54. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +3 -0
  55. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -1
  56. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +3 -0
  57. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -1
  58. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +5 -2
  59. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -1
  60. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs +2 -0
  61. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +1 -1
  62. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts +1 -0
  63. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +1 -1
  64. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts +1 -0
  65. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +1 -1
  66. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs +2 -0
  67. package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +1 -1
  68. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +3 -1
  69. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +1 -1
  70. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +5 -5
  71. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +1 -1
  72. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +5 -5
  73. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +1 -1
  74. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +3 -1
  75. package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +1 -1
  76. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +4 -2
  77. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  78. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +3 -0
  79. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  80. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +3 -0
  81. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  82. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +4 -2
  83. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  84. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +3 -6
  85. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -1
  86. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +1 -0
  87. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -1
  88. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +1 -0
  89. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -1
  90. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +3 -6
  91. package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -1
  92. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +6 -2
  93. package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
  94. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +5 -0
  95. package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
  96. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +5 -0
  97. package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
  98. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +6 -2
  99. package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
  100. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
  101. package/dist/controllers/user-storage/account-syncing/types.d.cts +1 -1
  102. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
  103. package/dist/controllers/user-storage/account-syncing/types.d.mts +1 -1
  104. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
  105. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
  106. package/dist/controllers/user-storage/account-syncing/utils.cjs +3 -1
  107. package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
  108. package/dist/controllers/user-storage/account-syncing/utils.d.cts +2 -0
  109. package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -1
  110. package/dist/controllers/user-storage/account-syncing/utils.d.mts +2 -0
  111. package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -1
  112. package/dist/controllers/user-storage/account-syncing/utils.mjs +3 -1
  113. package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
  114. package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs +1 -0
  115. package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs.map +1 -1
  116. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts +1 -0
  117. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts.map +1 -1
  118. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts +1 -0
  119. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts.map +1 -1
  120. package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs +1 -0
  121. package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs.map +1 -1
  122. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +3 -3
  123. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
  124. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +2 -0
  125. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -1
  126. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +2 -0
  127. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -1
  128. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +3 -3
  129. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
  130. package/dist/controllers/user-storage/network-syncing/services.cjs +5 -0
  131. package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
  132. package/dist/controllers/user-storage/network-syncing/services.d.cts +5 -1
  133. package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
  134. package/dist/controllers/user-storage/network-syncing/services.d.mts +5 -1
  135. package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
  136. package/dist/controllers/user-storage/network-syncing/services.mjs +5 -0
  137. package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
  138. package/dist/controllers/user-storage/network-syncing/sync-all.cjs +1 -1
  139. package/dist/controllers/user-storage/network-syncing/sync-all.cjs.map +1 -1
  140. package/dist/controllers/user-storage/network-syncing/sync-all.d.cts.map +1 -1
  141. package/dist/controllers/user-storage/network-syncing/sync-all.d.mts.map +1 -1
  142. package/dist/controllers/user-storage/network-syncing/sync-all.mjs +1 -1
  143. package/dist/controllers/user-storage/network-syncing/sync-all.mjs.map +1 -1
  144. package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -1
  145. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -1
  146. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
  147. package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
  148. package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs +3 -0
  149. package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs.map +1 -1
  150. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts +3 -0
  151. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts.map +1 -1
  152. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts +3 -0
  153. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts.map +1 -1
  154. package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs +3 -0
  155. package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs.map +1 -1
  156. package/dist/controllers/user-storage/services.cjs +0 -1
  157. package/dist/controllers/user-storage/services.cjs.map +1 -1
  158. package/dist/controllers/user-storage/services.d.cts.map +1 -1
  159. package/dist/controllers/user-storage/services.d.mts.map +1 -1
  160. package/dist/controllers/user-storage/services.mjs +0 -1
  161. package/dist/controllers/user-storage/services.mjs.map +1 -1
  162. package/dist/controllers/user-storage/utils.cjs +2 -0
  163. package/dist/controllers/user-storage/utils.cjs.map +1 -1
  164. package/dist/controllers/user-storage/utils.d.cts +2 -0
  165. package/dist/controllers/user-storage/utils.d.cts.map +1 -1
  166. package/dist/controllers/user-storage/utils.d.mts +2 -0
  167. package/dist/controllers/user-storage/utils.d.mts.map +1 -1
  168. package/dist/controllers/user-storage/utils.mjs +2 -0
  169. package/dist/controllers/user-storage/utils.mjs.map +1 -1
  170. package/dist/sdk/__fixtures__/mock-auth.cjs +0 -15
  171. package/dist/sdk/__fixtures__/mock-auth.cjs.map +1 -1
  172. package/dist/sdk/__fixtures__/mock-auth.mjs +0 -15
  173. package/dist/sdk/__fixtures__/mock-auth.mjs.map +1 -1
  174. package/dist/sdk/__fixtures__/mock-userstorage.cjs +0 -2
  175. package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +1 -1
  176. package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +1 -1
  177. package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +1 -1
  178. package/dist/sdk/__fixtures__/mock-userstorage.mjs +0 -2
  179. package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +1 -1
  180. package/dist/sdk/__fixtures__/test-utils.cjs +2 -1
  181. package/dist/sdk/__fixtures__/test-utils.cjs.map +1 -1
  182. package/dist/sdk/__fixtures__/test-utils.d.cts +1 -0
  183. package/dist/sdk/__fixtures__/test-utils.d.cts.map +1 -1
  184. package/dist/sdk/__fixtures__/test-utils.d.mts +1 -0
  185. package/dist/sdk/__fixtures__/test-utils.d.mts.map +1 -1
  186. package/dist/sdk/__fixtures__/test-utils.mjs +2 -1
  187. package/dist/sdk/__fixtures__/test-utils.mjs.map +1 -1
  188. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +1 -1
  189. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
  190. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
  191. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
  192. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +1 -1
  193. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  194. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +1 -1
  195. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  196. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  197. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  198. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +1 -1
  199. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  200. package/dist/sdk/authentication-jwt-bearer/services.cjs +1 -2
  201. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  202. package/dist/sdk/authentication-jwt-bearer/services.d.cts +1 -1
  203. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  204. package/dist/sdk/authentication-jwt-bearer/services.d.mts +1 -1
  205. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  206. package/dist/sdk/authentication-jwt-bearer/services.mjs +1 -2
  207. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  208. package/dist/sdk/authentication.cjs +0 -3
  209. package/dist/sdk/authentication.cjs.map +1 -1
  210. package/dist/sdk/authentication.d.cts.map +1 -1
  211. package/dist/sdk/authentication.d.mts.map +1 -1
  212. package/dist/sdk/authentication.mjs +0 -3
  213. package/dist/sdk/authentication.mjs.map +1 -1
  214. package/dist/sdk/user-storage.cjs +1 -3
  215. package/dist/sdk/user-storage.cjs.map +1 -1
  216. package/dist/sdk/user-storage.d.cts +1 -1
  217. package/dist/sdk/user-storage.d.cts.map +1 -1
  218. package/dist/sdk/user-storage.d.mts +1 -1
  219. package/dist/sdk/user-storage.d.mts.map +1 -1
  220. package/dist/sdk/user-storage.mjs +1 -3
  221. package/dist/sdk/user-storage.mjs.map +1 -1
  222. package/dist/sdk/utils/eip-6963-metamask-provider.cjs +4 -4
  223. package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -1
  224. package/dist/sdk/utils/eip-6963-metamask-provider.mjs +4 -4
  225. package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -1
  226. package/dist/shared/encryption/constants.cjs +0 -2
  227. package/dist/shared/encryption/constants.cjs.map +1 -1
  228. package/dist/shared/encryption/constants.d.cts.map +1 -1
  229. package/dist/shared/encryption/constants.d.mts.map +1 -1
  230. package/dist/shared/encryption/constants.mjs +0 -2
  231. package/dist/shared/encryption/constants.mjs.map +1 -1
  232. package/dist/shared/encryption/encryption.cjs +1 -0
  233. package/dist/shared/encryption/encryption.cjs.map +1 -1
  234. package/dist/shared/encryption/encryption.d.cts +1 -0
  235. package/dist/shared/encryption/encryption.d.cts.map +1 -1
  236. package/dist/shared/encryption/encryption.d.mts +1 -0
  237. package/dist/shared/encryption/encryption.d.mts.map +1 -1
  238. package/dist/shared/encryption/encryption.mjs +1 -0
  239. package/dist/shared/encryption/encryption.mjs.map +1 -1
  240. package/package.json +11 -11
@@ -2,6 +2,7 @@ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
2
  import type { AccountSyncingConfig, AccountSyncingOptions, UserStorageAccount } from "./types.mjs";
3
3
  /**
4
4
  * Checks if account syncing can be performed based on a set of conditions
5
+ *
5
6
  * @param config - configuration parameters
6
7
  * @param options - parameters used for checking if account syncing can be performed
7
8
  * @returns Returns true if account syncing can be performed, false otherwise.
@@ -9,12 +10,16 @@ import type { AccountSyncingConfig, AccountSyncingOptions, UserStorageAccount }
9
10
  export declare function canPerformAccountSyncing(config: AccountSyncingConfig, options: AccountSyncingOptions): boolean;
10
11
  /**
11
12
  * Get the list of internal accounts
13
+ *
12
14
  * @param options - parameters used for getting the list of internal accounts
15
+ * @returns the list of internal accounts
13
16
  */
14
17
  export declare function getInternalAccountsList(options: AccountSyncingOptions): Promise<InternalAccount[]>;
15
18
  /**
16
19
  * Get the list of user storage accounts
20
+ *
17
21
  * @param options - parameters used for getting the list of user storage accounts
22
+ * @returns the list of user storage accounts
18
23
  */
19
24
  export declare function getUserStorageAccountsList(options: AccountSyncingOptions): Promise<UserStorageAccount[] | null>;
20
25
  //# 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;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"}
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,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAU5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
@@ -1,7 +1,8 @@
1
- import { USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
2
1
  import { doesInternalAccountHaveCorrectKeyringType } from "./utils.mjs";
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
5
+ *
5
6
  * @param config - configuration parameters
6
7
  * @param options - parameters used for checking if account syncing can be performed
7
8
  * @returns Returns true if account syncing can be performed, false otherwise.
@@ -21,17 +22,20 @@ export function canPerformAccountSyncing(config, options) {
21
22
  }
22
23
  /**
23
24
  * Get the list of internal accounts
25
+ *
24
26
  * @param options - parameters used for getting the list of internal accounts
27
+ * @returns the list of internal accounts
25
28
  */
26
29
  export async function getInternalAccountsList(options) {
27
30
  const { getMessenger } = options;
28
- // eslint-disable-next-line @typescript-eslint/await-thenable
29
31
  const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
30
32
  return internalAccountsList?.filter(doesInternalAccountHaveCorrectKeyringType);
31
33
  }
32
34
  /**
33
35
  * Get the list of user storage accounts
36
+ *
34
37
  * @param options - parameters used for getting the list of user storage accounts
38
+ * @returns the list of user storage accounts
35
39
  */
36
40
  export async function getUserStorageAccountsList(options) {
37
41
  const { getUserStorageControllerInstance } = options;
@@ -1 +1 @@
1
- {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"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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"]}
1
+ {"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yCAAyC,EAAE,oBAAgB;AACpE,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;;GAMG;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;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,oBAAoB,EAAE,MAAM,CACjC,yCAAyC,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;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 type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { doesInternalAccountHaveCorrectKeyringType } 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 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 *\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 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 *\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 +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"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingConfig = {\n isAccountSyncingEnabled: boolean;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -1,6 +1,6 @@
1
+ import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
1
2
  import type { UserStorageControllerMessenger } from "../UserStorageController.cjs";
2
3
  import type UserStorageController from "../UserStorageController.cjs";
3
- import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
4
4
  export type UserStorageAccount = {
5
5
  /**
6
6
  * The Version 'v' of the User Storage.
@@ -1 +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"}
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,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"}
@@ -1,6 +1,6 @@
1
+ import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
1
2
  import type { UserStorageControllerMessenger } from "../UserStorageController.mjs";
2
3
  import type UserStorageController from "../UserStorageController.mjs";
3
- import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
4
4
  export type UserStorageAccount = {
5
5
  /**
6
6
  * The Version 'v' of the User Storage.
@@ -1 +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"}
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,gCAAgC;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,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"}
@@ -1 +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
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageAccount = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the id 'i' of the account */\n i: string;\n /** the address 'a' of the account */\n a: string;\n /** the name 'n' of the account */\n n: string;\n /** the nameLastUpdatedAt timestamp 'nlu' of the account */\n nlu?: number;\n};\n\nexport type AccountSyncingConfig = {\n isAccountSyncingEnabled: boolean;\n};\n\nexport type AccountSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -18,6 +18,7 @@ const isNameDefaultAccountName = (name) => {
18
18
  exports.isNameDefaultAccountName = isNameDefaultAccountName;
19
19
  /**
20
20
  * Map an internal account to a user storage account
21
+ *
21
22
  * @param internalAccount - An internal account
22
23
  * @returns A user storage account
23
24
  */
@@ -35,11 +36,12 @@ const mapInternalAccountToUserStorageAccount = (internalAccount) => {
35
36
  exports.mapInternalAccountToUserStorageAccount = mapInternalAccountToUserStorageAccount;
36
37
  /**
37
38
  * Checks if the given internal account has the correct keyring type.
39
+ *
38
40
  * @param account - The internal account to check
39
41
  * @returns Returns true if the internal account has the correct keyring type, false otherwise.
40
42
  */
41
43
  function doesInternalAccountHaveCorrectKeyringType(account) {
42
- return account.metadata.keyring.type === keyring_controller_1.KeyringTypes.hd;
44
+ return account.metadata.keyring.type === String(keyring_controller_1.KeyringTypes.hd);
43
45
  }
44
46
  exports.doesInternalAccountHaveCorrectKeyringType = doesInternalAccountHaveCorrectKeyringType;
45
47
  //# 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;;;;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
+ {"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;;;;;GAKG;AACH,SAAgB,yCAAyC,CACvD,OAAwB;IAExB,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,iCAAY,CAAC,EAAE,CAAC,CAAC;AACnE,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 *\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 *\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 === String(KeyringTypes.hd);\n}\n"]}
@@ -10,12 +10,14 @@ import type { UserStorageAccount } from "./types.cjs";
10
10
  export declare const isNameDefaultAccountName: (name: string) => boolean;
11
11
  /**
12
12
  * Map an internal account to a user storage account
13
+ *
13
14
  * @param internalAccount - An internal account
14
15
  * @returns A user storage account
15
16
  */
16
17
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
17
18
  /**
18
19
  * Checks if the given internal account has the correct keyring type.
20
+ *
19
21
  * @param account - The internal account to check
20
22
  * @returns Returns true if the internal account has the correct keyring type, false otherwise.
21
23
  */
@@ -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,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
+ {"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;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,yCAAyC,CACvD,OAAO,EAAE,eAAe,WAGzB"}
@@ -10,12 +10,14 @@ import type { UserStorageAccount } from "./types.mjs";
10
10
  export declare const isNameDefaultAccountName: (name: string) => boolean;
11
11
  /**
12
12
  * Map an internal account to a user storage account
13
+ *
13
14
  * @param internalAccount - An internal account
14
15
  * @returns A user storage account
15
16
  */
16
17
  export declare const mapInternalAccountToUserStorageAccount: (internalAccount: InternalAccount) => UserStorageAccount;
17
18
  /**
18
19
  * Checks if the given internal account has the correct keyring type.
20
+ *
19
21
  * @param account - The internal account to check
20
22
  * @returns Returns true if the internal account has the correct keyring type, false otherwise.
21
23
  */
@@ -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,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
+ {"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;;;;;GAKG;AACH,eAAO,MAAM,sCAAsC,oBAChC,eAAe,KAC/B,kBAWF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,yCAAyC,CACvD,OAAO,EAAE,eAAe,WAGzB"}
@@ -14,6 +14,7 @@ export const isNameDefaultAccountName = (name) => {
14
14
  };
15
15
  /**
16
16
  * Map an internal account to a user storage account
17
+ *
17
18
  * @param internalAccount - An internal account
18
19
  * @returns A user storage account
19
20
  */
@@ -30,10 +31,11 @@ export const mapInternalAccountToUserStorageAccount = (internalAccount) => {
30
31
  };
31
32
  /**
32
33
  * Checks if the given internal account has the correct keyring type.
34
+ *
33
35
  * @param account - The internal account to check
34
36
  * @returns Returns true if the internal account has the correct keyring type, false otherwise.
35
37
  */
36
38
  export function doesInternalAccountHaveCorrectKeyringType(account) {
37
- return account.metadata.keyring.type === KeyringTypes.hd;
39
+ return account.metadata.keyring.type === String(KeyringTypes.hd);
38
40
  }
39
41
  //# 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;;;;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"]}
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,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;;;;;GAKG;AACH,MAAM,UAAU,yCAAyC,CACvD,OAAwB;IAExB,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AACnE,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 *\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 *\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 === String(KeyringTypes.hd);\n}\n"]}
@@ -5,6 +5,7 @@ exports.MAX_NETWORKS_SIZE = 50;
5
5
  /**
6
6
  * Calculates the available space to add new networks
7
7
  * exported for testability.
8
+ *
8
9
  * @param originalListSize - size of original list
9
10
  * @param maxSize - max size
10
11
  * @returns a positive number on the available space
@@ -1 +1 @@
1
- {"version":3,"file":"add-network-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,CAC1C,gBAAwB,EACxB,OAAe,EACf,EAAE;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,4BAA4B,gCAKvC;AAEF;;;;;;;;GAQG;AACI,MAAM,uBAAuB,GAAG,CACrC,gBAAwC,EACxC,aAAqC,EACrC,OAAO,GAAG,yBAAiB,EAC3B,EAAE;IACF,MAAM,cAAc,GAAG,IAAA,oCAA4B,EACjD,gBAAgB,CAAC,MAAM,EACvB,OAAO,CACR,CAAC;IACF,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CACvC,cAAc,EACd,aAAa,CAAC,MAAM,CACrB,CAAC;IAEF,yCAAyC;IACzC,6DAA6D;IAC7D,OAAO,aAAa;SACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAClD,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACxC,CAAC,CAAC;AAnBW,QAAA,uBAAuB,2BAmBlC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\n\nexport const MAX_NETWORKS_SIZE = 50;\n\n/**\n * Calculates the available space to add new networks\n * exported for testability.\n * @param originalListSize - size of original list\n * @param maxSize - max size\n * @returns a positive number on the available space\n */\nexport const calculateAvailableSpaceToAdd = (\n originalListSize: number,\n maxSize: number,\n) => {\n return Math.max(0, maxSize - originalListSize);\n};\n\n/**\n * Returns a bounded number of networks to add (set by a max bound)\n * The items will be ordered to give determinism on items to append (not random)\n *\n * @param originalNetworks - The original list of network configurations.\n * @param networksToAdd - The list of network configurations to add.\n * @param maxSize - The maximum allowed size of the list. Defaults to MAX_NETWORKS_SIZE.\n * @returns The networks to add, sorted by chainId.\n */\nexport const getBoundedNetworksToAdd = (\n originalNetworks: NetworkConfiguration[],\n networksToAdd: NetworkConfiguration[],\n maxSize = MAX_NETWORKS_SIZE,\n) => {\n const availableSpace = calculateAvailableSpaceToAdd(\n originalNetworks.length,\n maxSize,\n );\n const numberOfNetworksToAppend = Math.min(\n availableSpace,\n networksToAdd.length,\n );\n\n // Order and slice the networks to append\n // Ordering so we have some determinism on the order of items\n return networksToAdd\n .sort((a, b) => a.chainId.localeCompare(b.chainId))\n .slice(0, numberOfNetworksToAppend);\n};\n"]}
1
+ {"version":3,"file":"add-network-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;;;;;GAOG;AACI,MAAM,4BAA4B,GAAG,CAC1C,gBAAwB,EACxB,OAAe,EACf,EAAE;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,4BAA4B,gCAKvC;AAEF;;;;;;;;GAQG;AACI,MAAM,uBAAuB,GAAG,CACrC,gBAAwC,EACxC,aAAqC,EACrC,OAAO,GAAG,yBAAiB,EAC3B,EAAE;IACF,MAAM,cAAc,GAAG,IAAA,oCAA4B,EACjD,gBAAgB,CAAC,MAAM,EACvB,OAAO,CACR,CAAC;IACF,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CACvC,cAAc,EACd,aAAa,CAAC,MAAM,CACrB,CAAC;IAEF,yCAAyC;IACzC,6DAA6D;IAC7D,OAAO,aAAa;SACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAClD,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACxC,CAAC,CAAC;AAnBW,QAAA,uBAAuB,2BAmBlC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\n\nexport const MAX_NETWORKS_SIZE = 50;\n\n/**\n * Calculates the available space to add new networks\n * exported for testability.\n *\n * @param originalListSize - size of original list\n * @param maxSize - max size\n * @returns a positive number on the available space\n */\nexport const calculateAvailableSpaceToAdd = (\n originalListSize: number,\n maxSize: number,\n) => {\n return Math.max(0, maxSize - originalListSize);\n};\n\n/**\n * Returns a bounded number of networks to add (set by a max bound)\n * The items will be ordered to give determinism on items to append (not random)\n *\n * @param originalNetworks - The original list of network configurations.\n * @param networksToAdd - The list of network configurations to add.\n * @param maxSize - The maximum allowed size of the list. Defaults to MAX_NETWORKS_SIZE.\n * @returns The networks to add, sorted by chainId.\n */\nexport const getBoundedNetworksToAdd = (\n originalNetworks: NetworkConfiguration[],\n networksToAdd: NetworkConfiguration[],\n maxSize = MAX_NETWORKS_SIZE,\n) => {\n const availableSpace = calculateAvailableSpaceToAdd(\n originalNetworks.length,\n maxSize,\n );\n const numberOfNetworksToAppend = Math.min(\n availableSpace,\n networksToAdd.length,\n );\n\n // Order and slice the networks to append\n // Ordering so we have some determinism on the order of items\n return networksToAdd\n .sort((a, b) => a.chainId.localeCompare(b.chainId))\n .slice(0, numberOfNetworksToAppend);\n};\n"]}
@@ -3,6 +3,7 @@ export declare const MAX_NETWORKS_SIZE = 50;
3
3
  /**
4
4
  * Calculates the available space to add new networks
5
5
  * exported for testability.
6
+ *
6
7
  * @param originalListSize - size of original list
7
8
  * @param maxSize - max size
8
9
  * @returns a positive number on the available space
@@ -1 +1 @@
1
- {"version":3,"file":"add-network-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAEzE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,qBACrB,MAAM,WACf,MAAM,WAGhB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,qBAChB,oBAAoB,EAAE,iBACzB,oBAAoB,EAAE,6CAiBtC,CAAC"}
1
+ {"version":3,"file":"add-network-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAEzE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,qBACrB,MAAM,WACf,MAAM,WAGhB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,qBAChB,oBAAoB,EAAE,iBACzB,oBAAoB,EAAE,6CAiBtC,CAAC"}
@@ -3,6 +3,7 @@ export declare const MAX_NETWORKS_SIZE = 50;
3
3
  /**
4
4
  * Calculates the available space to add new networks
5
5
  * exported for testability.
6
+ *
6
7
  * @param originalListSize - size of original list
7
8
  * @param maxSize - max size
8
9
  * @returns a positive number on the available space
@@ -1 +1 @@
1
- {"version":3,"file":"add-network-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAEzE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,qBACrB,MAAM,WACf,MAAM,WAGhB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,qBAChB,oBAAoB,EAAE,iBACzB,oBAAoB,EAAE,6CAiBtC,CAAC"}
1
+ {"version":3,"file":"add-network-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAEzE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,qBACrB,MAAM,WACf,MAAM,WAGhB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,qBAChB,oBAAoB,EAAE,iBACzB,oBAAoB,EAAE,6CAiBtC,CAAC"}
@@ -2,6 +2,7 @@ export const MAX_NETWORKS_SIZE = 50;
2
2
  /**
3
3
  * Calculates the available space to add new networks
4
4
  * exported for testability.
5
+ *
5
6
  * @param originalListSize - size of original list
6
7
  * @param maxSize - max size
7
8
  * @returns a positive number on the available space
@@ -1 +1 @@
1
- {"version":3,"file":"add-network-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,gBAAwB,EACxB,OAAe,EACf,EAAE;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAwC,EACxC,aAAqC,EACrC,OAAO,GAAG,iBAAiB,EAC3B,EAAE;IACF,MAAM,cAAc,GAAG,4BAA4B,CACjD,gBAAgB,CAAC,MAAM,EACvB,OAAO,CACR,CAAC;IACF,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CACvC,cAAc,EACd,aAAa,CAAC,MAAM,CACrB,CAAC;IAEF,yCAAyC;IACzC,6DAA6D;IAC7D,OAAO,aAAa;SACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAClD,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\n\nexport const MAX_NETWORKS_SIZE = 50;\n\n/**\n * Calculates the available space to add new networks\n * exported for testability.\n * @param originalListSize - size of original list\n * @param maxSize - max size\n * @returns a positive number on the available space\n */\nexport const calculateAvailableSpaceToAdd = (\n originalListSize: number,\n maxSize: number,\n) => {\n return Math.max(0, maxSize - originalListSize);\n};\n\n/**\n * Returns a bounded number of networks to add (set by a max bound)\n * The items will be ordered to give determinism on items to append (not random)\n *\n * @param originalNetworks - The original list of network configurations.\n * @param networksToAdd - The list of network configurations to add.\n * @param maxSize - The maximum allowed size of the list. Defaults to MAX_NETWORKS_SIZE.\n * @returns The networks to add, sorted by chainId.\n */\nexport const getBoundedNetworksToAdd = (\n originalNetworks: NetworkConfiguration[],\n networksToAdd: NetworkConfiguration[],\n maxSize = MAX_NETWORKS_SIZE,\n) => {\n const availableSpace = calculateAvailableSpaceToAdd(\n originalNetworks.length,\n maxSize,\n );\n const numberOfNetworksToAppend = Math.min(\n availableSpace,\n networksToAdd.length,\n );\n\n // Order and slice the networks to append\n // Ordering so we have some determinism on the order of items\n return networksToAdd\n .sort((a, b) => a.chainId.localeCompare(b.chainId))\n .slice(0, numberOfNetworksToAppend);\n};\n"]}
1
+ {"version":3,"file":"add-network-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,gBAAwB,EACxB,OAAe,EACf,EAAE;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAwC,EACxC,aAAqC,EACrC,OAAO,GAAG,iBAAiB,EAC3B,EAAE;IACF,MAAM,cAAc,GAAG,4BAA4B,CACjD,gBAAgB,CAAC,MAAM,EACvB,OAAO,CACR,CAAC;IACF,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CACvC,cAAc,EACd,aAAa,CAAC,MAAM,CACrB,CAAC;IAEF,yCAAyC;IACzC,6DAA6D;IAC7D,OAAO,aAAa;SACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAClD,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\n\nexport const MAX_NETWORKS_SIZE = 50;\n\n/**\n * Calculates the available space to add new networks\n * exported for testability.\n *\n * @param originalListSize - size of original list\n * @param maxSize - max size\n * @returns a positive number on the available space\n */\nexport const calculateAvailableSpaceToAdd = (\n originalListSize: number,\n maxSize: number,\n) => {\n return Math.max(0, maxSize - originalListSize);\n};\n\n/**\n * Returns a bounded number of networks to add (set by a max bound)\n * The items will be ordered to give determinism on items to append (not random)\n *\n * @param originalNetworks - The original list of network configurations.\n * @param networksToAdd - The list of network configurations to add.\n * @param maxSize - The maximum allowed size of the list. Defaults to MAX_NETWORKS_SIZE.\n * @returns The networks to add, sorted by chainId.\n */\nexport const getBoundedNetworksToAdd = (\n originalNetworks: NetworkConfiguration[],\n networksToAdd: NetworkConfiguration[],\n maxSize = MAX_NETWORKS_SIZE,\n) => {\n const availableSpace = calculateAvailableSpaceToAdd(\n originalNetworks.length,\n maxSize,\n );\n const numberOfNetworksToAppend = Math.min(\n availableSpace,\n networksToAdd.length,\n );\n\n // Order and slice the networks to append\n // Ordering so we have some determinism on the order of items\n return networksToAdd\n .sort((a, b) => a.chainId.localeCompare(b.chainId))\n .slice(0, numberOfNetworksToAppend);\n};\n"]}
@@ -30,9 +30,7 @@ exports.isMainNetworkSyncInProgress = false;
30
30
  function startNetworkSyncing(props) {
31
31
  const { messenger, getStorageConfig, isMutationSyncBlocked } = props;
32
32
  try {
33
- messenger.subscribe('NetworkController:networkRemoved',
34
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
35
- async (networkConfiguration) => {
33
+ messenger.subscribe('NetworkController:networkRemoved', async (networkConfiguration) => {
36
34
  try {
37
35
  // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations
38
36
  if (isMutationSyncBlocked()) {
@@ -62,6 +60,7 @@ exports.startNetworkSyncing = startNetworkSyncing;
62
60
  /**
63
61
  * method that will dispatch the `NetworkController:updateNetwork` action.
64
62
  * transforms and corrects the network configuration (and RPCs) we pass through.
63
+ *
65
64
  * @param props - properties
66
65
  * @param props.messenger - messenger to call the action
67
66
  * @param props.originalNetworkConfiguration - original network config (from network controller state)
@@ -81,6 +80,7 @@ exports.dispatchUpdateNetwork = dispatchUpdateNetwork;
81
80
  /**
82
81
  * Action to perform the main network sync.
83
82
  * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update
83
+ *
84
84
  * @param props - parameters used for this main sync
85
85
  */
86
86
  async function performMainNetworkSync(props) {
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,wDAA2B;AAI3B,+DAA8D;AAC9D,6CAAkD;AAClD,6CAAkD;AAClD,yDAAsE;AACtE,qEAAkE;AAiBlE;;;GAGG;AACH,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,2BAA2B,GAAG,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,SAAgB,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC;IACrE,IAAI;QACF,SAAS,CAAC,SAAS,CACjB,kCAAkC;QAClC,kEAAkE;QAClE,KAAK,EAAE,oBAAoB,EAAE,EAAE;YAC7B,IAAI;gBACF,oGAAoG;gBACpG,IAAI,qBAAqB,EAAE,EAAE;oBAC3B,OAAO;iBACR;gBAED,yEAAyE;gBACzE,kCAAkC;gBAClC,IAAI,mCAA2B,EAAE;oBAC/B,OAAO;iBACR;gBAED,MAAM,IAAI,GAAG,MAAM,gBAAgB,EAAE,CAAC;gBACtC,IAAI,CAAC,IAAI,EAAE;oBACT,OAAO;iBACR;gBACD,MAAM,IAAA,8BAAa,EAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;aACjD;YAAC,MAAM;gBACN,qBAAqB;aACtB;QACH,CAAC,CACF,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,kBAAG,CAAC,IAAI,CAAC,2CAA2C,EAAE,CAAC,CAAC,CAAC;KAC1D;AACH,CAAC;AAhCD,kDAgCC;AAED;;;;;;;;GAQG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,KA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AiJC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
1
+ {"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,wDAA2B;AAE3B,+DAA8D;AAC9D,6CAAkD;AAClD,6CAAkD;AAClD,yDAAsE;AACtE,qEAAkE;AAmBlE;;;GAGG;AACH,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,2BAA2B,GAAG,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,SAAgB,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC;IACrE,IAAI;QACF,SAAS,CAAC,SAAS,CACjB,kCAAkC,EAElC,KAAK,EAAE,oBAAoB,EAAE,EAAE;YAC7B,IAAI;gBACF,oGAAoG;gBACpG,IAAI,qBAAqB,EAAE,EAAE;oBAC3B,OAAO;iBACR;gBAED,yEAAyE;gBACzE,kCAAkC;gBAClC,IAAI,mCAA2B,EAAE;oBAC/B,OAAO;iBACR;gBAED,MAAM,IAAI,GAAG,MAAM,gBAAgB,EAAE,CAAC;gBACtC,IAAI,CAAC,IAAI,EAAE;oBACT,OAAO;iBACR;gBACD,MAAM,IAA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,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,kBAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,kBAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,mCAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC;AAjJD,wDAiJC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n *\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n *\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
@@ -33,6 +33,7 @@ export declare function startNetworkSyncing(props: StartNetworkSyncingProps): vo
33
33
  /**
34
34
  * method that will dispatch the `NetworkController:updateNetwork` action.
35
35
  * transforms and corrects the network configuration (and RPCs) we pass through.
36
+ *
36
37
  * @param props - properties
37
38
  * @param props.messenger - messenger to call the action
38
39
  * @param props.originalNetworkConfiguration - original network config (from network controller state)
@@ -48,6 +49,7 @@ export declare const dispatchUpdateNetwork: (props: {
48
49
  /**
49
50
  * Action to perform the main network sync.
50
51
  * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update
52
+ *
51
53
  * @param props - parameters used for this main sync
52
54
  */
53
55
  export declare function performMainNetworkSync(props: PerformMainNetworkSyncProps): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAGzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAoB;AAC1D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAO/E,KAAK,wBAAwB,GAAG;IAC9B,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,qBAAqB,EAAE,MAAM,OAAO,CAAC;CACtC,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AAGH,eAAO,IAAI,2BAA2B,SAAQ,CAAC;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,QAgClE;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,UAAiB;IACjD,SAAS,EAAE,8BAA8B,CAAC;IAC1C,4BAA4B,EAAE,oBAAoB,CAAC;IACnD,uBAAuB,EAAE,oBAAoB,CAAC;IAC9C,uBAAuB,EAAE,MAAM,CAAC;CACjC,kBAqBA,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,2BAA2B,iBAgJnC"}
1
+ {"version":3,"file":"controller-integration.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAQzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAoB;AAC1D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAE/E,KAAK,wBAAwB,GAAG;IAC9B,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,qBAAqB,EAAE,MAAM,OAAO,CAAC;CACtC,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AAGH,eAAO,IAAI,2BAA2B,SAAQ,CAAC;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,QAgClE;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,UAAiB;IACjD,SAAS,EAAE,8BAA8B,CAAC;IAC1C,4BAA4B,EAAE,oBAAoB,CAAC;IACnD,uBAAuB,EAAE,oBAAoB,CAAC;IAC9C,uBAAuB,EAAE,MAAM,CAAC;CACjC,kBAqBA,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,2BAA2B,iBAgJnC"}
@@ -33,6 +33,7 @@ export declare function startNetworkSyncing(props: StartNetworkSyncingProps): vo
33
33
  /**
34
34
  * method that will dispatch the `NetworkController:updateNetwork` action.
35
35
  * transforms and corrects the network configuration (and RPCs) we pass through.
36
+ *
36
37
  * @param props - properties
37
38
  * @param props.messenger - messenger to call the action
38
39
  * @param props.originalNetworkConfiguration - original network config (from network controller state)
@@ -48,6 +49,7 @@ export declare const dispatchUpdateNetwork: (props: {
48
49
  /**
49
50
  * Action to perform the main network sync.
50
51
  * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update
52
+ *
51
53
  * @param props - parameters used for this main sync
52
54
  */
53
55
  export declare function performMainNetworkSync(props: PerformMainNetworkSyncProps): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAGzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAoB;AAC1D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAO/E,KAAK,wBAAwB,GAAG;IAC9B,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,qBAAqB,EAAE,MAAM,OAAO,CAAC;CACtC,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AAGH,eAAO,IAAI,2BAA2B,SAAQ,CAAC;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,QAgClE;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,UAAiB;IACjD,SAAS,EAAE,8BAA8B,CAAC;IAC1C,4BAA4B,EAAE,oBAAoB,CAAC;IACnD,uBAAuB,EAAE,oBAAoB,CAAC;IAC9C,uBAAuB,EAAE,MAAM,CAAC;CACjC,kBAqBA,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,2BAA2B,iBAgJnC"}
1
+ {"version":3,"file":"controller-integration.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qCAAqC;AAQzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAoB;AAC1D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAE/E,KAAK,wBAAwB,GAAG;IAC9B,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,qBAAqB,EAAE,MAAM,OAAO,CAAC;CACtC,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AAGH,eAAO,IAAI,2BAA2B,SAAQ,CAAC;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,QAgClE;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,UAAiB;IACjD,SAAS,EAAE,8BAA8B,CAAC;IAC1C,4BAA4B,EAAE,oBAAoB,CAAC;IACnD,uBAAuB,EAAE,oBAAoB,CAAC;IAC9C,uBAAuB,EAAE,MAAM,CAAC;CACjC,kBAqBA,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,2BAA2B,iBAgJnC"}
@@ -31,9 +31,7 @@ export let isMainNetworkSyncInProgress = false;
31
31
  export function startNetworkSyncing(props) {
32
32
  const { messenger, getStorageConfig, isMutationSyncBlocked } = props;
33
33
  try {
34
- messenger.subscribe('NetworkController:networkRemoved',
35
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
36
- async (networkConfiguration) => {
34
+ messenger.subscribe('NetworkController:networkRemoved', async (networkConfiguration) => {
37
35
  try {
38
36
  // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations
39
37
  if (isMutationSyncBlocked()) {
@@ -62,6 +60,7 @@ export function startNetworkSyncing(props) {
62
60
  /**
63
61
  * method that will dispatch the `NetworkController:updateNetwork` action.
64
62
  * transforms and corrects the network configuration (and RPCs) we pass through.
63
+ *
65
64
  * @param props - properties
66
65
  * @param props.messenger - messenger to call the action
67
66
  * @param props.originalNetworkConfiguration - original network config (from network controller state)
@@ -80,6 +79,7 @@ export const dispatchUpdateNetwork = async (props) => {
80
79
  /**
81
80
  * Action to perform the main network sync.
82
81
  * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update
82
+ *
83
83
  * @param props - parameters used for this main sync
84
84
  */
85
85
  export async function performMainNetworkSync(props) {
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-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E,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBAC/B;gBAAC,OAAO,CAAC,EAAE;oBACV,gEAAgE;oBAChE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACf,yDAAyD;iBAC1D;aACF;YAED,+DAA+D;YAC/D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,GAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;QAED,wBAAwB;QACxB,IACE,cAAc,EAAE,qBAAqB;YACrC,cAAc,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAC/C;YACA,MAAM,MAAM,GAAc,EAAE,CAAC;YAC7B,cAAc,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACjD,IAAI;oBACF,SAAS,CAAC,IAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBAC7D,gBAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBAC/B;gBAAC,OAAO,CAAC,EAAE;oBACV,gEAAgE;oBAChE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACf,yDAAyD;iBAC1D;YACH,CAAC,CAAC,CAAC;YAEH,+DAA+D;YAC/D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,GAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,2BAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
1
+ {"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EAAE,uBAAuB,EAAE,gCAA4B;AAC9D,OAAO,EAAE,oBAAoB,EAAE,uBAAmB;AAClD,OAAO,EAAE,oBAAoB,EAAE,uBAAmB;AAClD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,6BAAyB;AACtE,OAAO,EAAE,wBAAwB,EAAE,mCAA+B;AAmBlE;;;GAGG;AACH,2BAA2B;AAC3B,uDAAuD;AACvD,MAAM,CAAC,IAAI,2BAA2B,GAAG,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC;IACrE,IAAI;QACF,SAAS,CAAC,SAAS,CACjB,kCAAkC,EAElC,KAAK,EAAE,oBAAoB,EAAE,EAAE;YAC7B,IAAI;gBACF,oGAAoG;gBACpG,IAAI,qBAAqB,EAAE,EAAE;oBAC3B,OAAO;iBACR;gBAED,yEAAyE;gBACzE,kCAAkC;gBAClC,IAAI,2BAA2B,EAAE;oBAC/B,OAAO;iBACR;gBAED,MAAM,IAAI,GAAG,MAAM,gBAAgB,EAAE,CAAC;gBACtC,IAAI,CAAC,IA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AE;gBACrB,GAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,2BAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n *\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n *\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}