@metamask/profile-sync-controller 0.1.0 → 0.1.1

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 (163) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/{chunk-DHHBHLVN.mjs → chunk-2XGRQBXI.mjs} +4 -4
  3. package/dist/{chunk-PRDECQM6.mjs → chunk-32HAX3MW.mjs} +7 -4
  4. package/dist/chunk-32HAX3MW.mjs.map +1 -0
  5. package/dist/{chunk-K6G7X6PX.js → chunk-5SXXO4MV.js} +9 -9
  6. package/dist/{chunk-BFE6TB7Y.mjs → chunk-5TOWF6UW.mjs} +2 -2
  7. package/dist/{chunk-QHL6SQTC.mjs → chunk-AARMY5TW.mjs} +10 -36
  8. package/dist/chunk-AARMY5TW.mjs.map +1 -0
  9. package/dist/{chunk-JTDFOATG.js → chunk-AK7OTIWA.js} +3 -3
  10. package/dist/{chunk-772MKTIO.mjs → chunk-AUFUOKJW.mjs} +2 -2
  11. package/dist/{chunk-6TK7544L.js → chunk-AVOOINGJ.js} +27 -27
  12. package/dist/{chunk-UEZI2POO.mjs → chunk-AXWK4Y23.mjs} +4 -4
  13. package/dist/{chunk-VTM5T7Y4.mjs → chunk-B5DBQDB3.mjs} +2 -2
  14. package/dist/{chunk-7FCK4BY3.js → chunk-B6CSNLGE.js} +3 -3
  15. package/dist/{chunk-XUPRRLBI.js → chunk-BOET676P.js} +8 -8
  16. package/dist/{chunk-YWA77VMP.mjs → chunk-CAIIVJAO.mjs} +1 -1
  17. package/dist/chunk-CAIIVJAO.mjs.map +1 -0
  18. package/dist/{chunk-2MVOZPBN.js → chunk-ELHJSRS2.js} +4 -4
  19. package/dist/{chunk-3FJQHCCQ.mjs → chunk-FCT2LIGH.mjs} +5 -5
  20. package/dist/{chunk-GLS4QZF6.mjs → chunk-FQ5SDMRE.mjs} +1 -1
  21. package/dist/chunk-FQ5SDMRE.mjs.map +1 -0
  22. package/dist/chunk-H4TDS65R.js +81 -0
  23. package/dist/chunk-H4TDS65R.js.map +1 -0
  24. package/dist/chunk-IGY2S5BC.js +36 -0
  25. package/dist/{chunk-UWRKMJBI.mjs → chunk-JLDFMYAH.mjs} +3 -3
  26. package/dist/{chunk-QE2F5AZL.mjs → chunk-K5UKU454.mjs} +2 -2
  27. package/dist/{chunk-W7JFFMEZ.mjs → chunk-KBCXN3YW.mjs} +2 -2
  28. package/dist/{chunk-JAGWB4JI.mjs → chunk-LSVRA3X2.mjs} +13 -34
  29. package/dist/chunk-LSVRA3X2.mjs.map +1 -0
  30. package/dist/{chunk-DLXLU44Z.js → chunk-NLHLVVOO.js} +21 -21
  31. package/dist/{chunk-GLDUXN2T.js → chunk-P4DUDLMY.js} +24 -24
  32. package/dist/{chunk-LUKNP4HM.js → chunk-P52TG263.js} +19 -19
  33. package/dist/{chunk-T77FC4PB.js → chunk-PBRUOBEQ.js} +1 -1
  34. package/dist/chunk-PBRUOBEQ.js.map +1 -0
  35. package/dist/chunk-PTR4DAX6.js +79 -0
  36. package/dist/{chunk-LHDVZNW5.js → chunk-Q5WIUNX5.js} +37 -37
  37. package/dist/{chunk-BVM4HBM4.js → chunk-RX5R6BUI.js} +13 -39
  38. package/dist/chunk-RX5R6BUI.js.map +1 -0
  39. package/dist/{chunk-4OMJ7A6A.js → chunk-SMKTWM6I.js} +1 -1
  40. package/dist/chunk-SMKTWM6I.js.map +1 -0
  41. package/dist/{chunk-JWTNHCVG.js → chunk-T3FNDVE3.js} +13 -13
  42. package/dist/{chunk-PNZGAAT4.mjs → chunk-TGFMKARH.mjs} +5 -4
  43. package/dist/chunk-TGFMKARH.mjs.map +1 -0
  44. package/dist/chunk-U5UIDVOO.mjs +36 -0
  45. package/dist/{chunk-7VMXBDXN.mjs → chunk-WB6MUIML.mjs} +2 -2
  46. package/dist/{chunk-IZHWP5VW.mjs → chunk-WJCKQLKK.mjs} +9 -9
  47. package/dist/{chunk-LN2BY2QF.mjs → chunk-Y46NMA3V.mjs} +3 -3
  48. package/dist/{chunk-ARWL2LBB.js → chunk-YASNOFBV.js} +38 -37
  49. package/dist/chunk-YASNOFBV.js.map +1 -0
  50. package/dist/{chunk-WAS6V24H.js → chunk-YUXN5GSW.js} +33 -30
  51. package/dist/chunk-YUXN5GSW.js.map +1 -0
  52. package/dist/controllers/authentication/AuthenticationController.js +15 -13
  53. package/dist/controllers/authentication/AuthenticationController.mjs +16 -14
  54. package/dist/controllers/authentication/auth-snap-requests.js +1 -1
  55. package/dist/controllers/authentication/auth-snap-requests.mjs +1 -1
  56. package/dist/controllers/authentication/index.js +16 -15
  57. package/dist/controllers/authentication/index.mjs +17 -16
  58. package/dist/controllers/authentication/services.js +12 -12
  59. package/dist/controllers/authentication/services.mjs +11 -11
  60. package/dist/controllers/index.js +20 -21
  61. package/dist/controllers/index.mjs +19 -20
  62. package/dist/controllers/user-storage/UserStorageController.js +18 -16
  63. package/dist/controllers/user-storage/UserStorageController.mjs +19 -17
  64. package/dist/controllers/user-storage/encryption/cache.js +1 -1
  65. package/dist/controllers/user-storage/encryption/cache.mjs +1 -1
  66. package/dist/controllers/user-storage/encryption/encryption.js +3 -3
  67. package/dist/controllers/user-storage/encryption/encryption.mjs +2 -2
  68. package/dist/controllers/user-storage/encryption/index.js +4 -4
  69. package/dist/controllers/user-storage/encryption/index.mjs +3 -3
  70. package/dist/controllers/user-storage/encryption/utils.js +1 -1
  71. package/dist/controllers/user-storage/encryption/utils.mjs +1 -1
  72. package/dist/controllers/user-storage/index.js +19 -18
  73. package/dist/controllers/user-storage/index.mjs +20 -19
  74. package/dist/controllers/user-storage/schema.js +5 -5
  75. package/dist/controllers/user-storage/schema.mjs +4 -4
  76. package/dist/controllers/user-storage/services.js +15 -15
  77. package/dist/controllers/user-storage/services.mjs +14 -14
  78. package/dist/index.js +20 -21
  79. package/dist/index.mjs +19 -20
  80. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +6 -6
  81. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +5 -5
  82. package/dist/sdk/authentication-jwt-bearer/flow-srp.js +6 -6
  83. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +5 -5
  84. package/dist/sdk/authentication-jwt-bearer/services.js +5 -5
  85. package/dist/sdk/authentication-jwt-bearer/services.mjs +4 -4
  86. package/dist/sdk/authentication-jwt-bearer/types.js +3 -3
  87. package/dist/sdk/authentication-jwt-bearer/types.mjs +2 -2
  88. package/dist/sdk/authentication.js +8 -8
  89. package/dist/sdk/authentication.mjs +7 -7
  90. package/dist/sdk/encryption.js +3 -3
  91. package/dist/sdk/encryption.mjs +2 -2
  92. package/dist/sdk/env.js +3 -3
  93. package/dist/sdk/env.mjs +2 -2
  94. package/dist/sdk/errors.js +1 -1
  95. package/dist/sdk/errors.mjs +1 -1
  96. package/dist/sdk/index.js +11 -11
  97. package/dist/sdk/index.mjs +10 -10
  98. package/dist/sdk/user-storage.js +5 -5
  99. package/dist/sdk/user-storage.mjs +4 -4
  100. package/dist/sdk/utils/eip-6963-metamask-provider.js +1 -1
  101. package/dist/sdk/utils/eip-6963-metamask-provider.mjs +1 -1
  102. package/dist/sdk/utils/messaging-signing-snap-requests.js +1 -1
  103. package/dist/sdk/utils/messaging-signing-snap-requests.mjs +1 -1
  104. package/dist/tsconfig.build.tsbuildinfo +1 -1
  105. package/dist/types/controllers/authentication/AuthenticationController.d.ts +1 -0
  106. package/dist/types/controllers/authentication/AuthenticationController.d.ts.map +1 -1
  107. package/dist/types/controllers/authentication/__fixtures__/index.d.ts +0 -1
  108. package/dist/types/controllers/authentication/__fixtures__/index.d.ts.map +1 -1
  109. package/dist/types/controllers/user-storage/UserStorageController.d.ts +1 -0
  110. package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -1
  111. package/dist/types/controllers/user-storage/__fixtures__/index.d.ts +0 -1
  112. package/dist/types/controllers/user-storage/__fixtures__/index.d.ts.map +1 -1
  113. package/dist/types/sdk/authentication-jwt-bearer/types.d.ts +1 -1
  114. package/dist/types/sdk/authentication-jwt-bearer/types.d.ts.map +1 -1
  115. package/dist/types/sdk/env.d.ts +2 -2
  116. package/dist/types/sdk/env.d.ts.map +1 -1
  117. package/package.json +1 -1
  118. package/dist/chunk-26CCETCM.mjs +0 -70
  119. package/dist/chunk-4OMJ7A6A.js.map +0 -1
  120. package/dist/chunk-ARWL2LBB.js.map +0 -1
  121. package/dist/chunk-BVM4HBM4.js.map +0 -1
  122. package/dist/chunk-GJJT2CAL.js +0 -3342
  123. package/dist/chunk-GJJT2CAL.js.map +0 -1
  124. package/dist/chunk-GLS4QZF6.mjs.map +0 -1
  125. package/dist/chunk-JAGWB4JI.mjs.map +0 -1
  126. package/dist/chunk-JMU3OVPK.mjs +0 -3342
  127. package/dist/chunk-JMU3OVPK.mjs.map +0 -1
  128. package/dist/chunk-PNZGAAT4.mjs.map +0 -1
  129. package/dist/chunk-PRDECQM6.mjs.map +0 -1
  130. package/dist/chunk-QHL6SQTC.mjs.map +0 -1
  131. package/dist/chunk-QILE6KIE.js +0 -79
  132. package/dist/chunk-T77FC4PB.js.map +0 -1
  133. package/dist/chunk-V46WVGWN.js +0 -70
  134. package/dist/chunk-VYE2DKST.js +0 -102
  135. package/dist/chunk-VYE2DKST.js.map +0 -1
  136. package/dist/chunk-WAS6V24H.js.map +0 -1
  137. package/dist/chunk-YWA77VMP.mjs.map +0 -1
  138. /package/dist/{chunk-DHHBHLVN.mjs.map → chunk-2XGRQBXI.mjs.map} +0 -0
  139. /package/dist/{chunk-K6G7X6PX.js.map → chunk-5SXXO4MV.js.map} +0 -0
  140. /package/dist/{chunk-BFE6TB7Y.mjs.map → chunk-5TOWF6UW.mjs.map} +0 -0
  141. /package/dist/{chunk-JTDFOATG.js.map → chunk-AK7OTIWA.js.map} +0 -0
  142. /package/dist/{chunk-772MKTIO.mjs.map → chunk-AUFUOKJW.mjs.map} +0 -0
  143. /package/dist/{chunk-6TK7544L.js.map → chunk-AVOOINGJ.js.map} +0 -0
  144. /package/dist/{chunk-UEZI2POO.mjs.map → chunk-AXWK4Y23.mjs.map} +0 -0
  145. /package/dist/{chunk-VTM5T7Y4.mjs.map → chunk-B5DBQDB3.mjs.map} +0 -0
  146. /package/dist/{chunk-7FCK4BY3.js.map → chunk-B6CSNLGE.js.map} +0 -0
  147. /package/dist/{chunk-XUPRRLBI.js.map → chunk-BOET676P.js.map} +0 -0
  148. /package/dist/{chunk-2MVOZPBN.js.map → chunk-ELHJSRS2.js.map} +0 -0
  149. /package/dist/{chunk-3FJQHCCQ.mjs.map → chunk-FCT2LIGH.mjs.map} +0 -0
  150. /package/dist/{chunk-V46WVGWN.js.map → chunk-IGY2S5BC.js.map} +0 -0
  151. /package/dist/{chunk-UWRKMJBI.mjs.map → chunk-JLDFMYAH.mjs.map} +0 -0
  152. /package/dist/{chunk-QE2F5AZL.mjs.map → chunk-K5UKU454.mjs.map} +0 -0
  153. /package/dist/{chunk-W7JFFMEZ.mjs.map → chunk-KBCXN3YW.mjs.map} +0 -0
  154. /package/dist/{chunk-DLXLU44Z.js.map → chunk-NLHLVVOO.js.map} +0 -0
  155. /package/dist/{chunk-GLDUXN2T.js.map → chunk-P4DUDLMY.js.map} +0 -0
  156. /package/dist/{chunk-LUKNP4HM.js.map → chunk-P52TG263.js.map} +0 -0
  157. /package/dist/{chunk-QILE6KIE.js.map → chunk-PTR4DAX6.js.map} +0 -0
  158. /package/dist/{chunk-LHDVZNW5.js.map → chunk-Q5WIUNX5.js.map} +0 -0
  159. /package/dist/{chunk-JWTNHCVG.js.map → chunk-T3FNDVE3.js.map} +0 -0
  160. /package/dist/{chunk-26CCETCM.mjs.map → chunk-U5UIDVOO.mjs.map} +0 -0
  161. /package/dist/{chunk-7VMXBDXN.mjs.map → chunk-WB6MUIML.mjs.map} +0 -0
  162. /package/dist/{chunk-IZHWP5VW.mjs.map → chunk-WJCKQLKK.mjs.map} +0 -0
  163. /package/dist/{chunk-LN2BY2QF.mjs.map → chunk-Y46NMA3V.mjs.map} +0 -0
@@ -4,15 +4,15 @@ var _chunkIPSBQ3MSjs = require('./chunk-IPSBQ3MS.js');
4
4
 
5
5
 
6
6
 
7
- var _chunkK6G7X6PXjs = require('./chunk-K6G7X6PX.js');
7
+ var _chunk5SXXO4MVjs = require('./chunk-5SXXO4MV.js');
8
8
 
9
9
 
10
- var _chunkJWTNHCVGjs = require('./chunk-JWTNHCVG.js');
10
+ var _chunkT3FNDVE3js = require('./chunk-T3FNDVE3.js');
11
11
 
12
12
 
13
13
 
14
14
 
15
- var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
15
+ var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
16
16
 
17
17
  // src/controllers/user-storage/UserStorageController.ts
18
18
  var _basecontroller = require('@metamask/base-controller');
@@ -44,27 +44,27 @@ var UserStorageController = class extends _basecontroller.BaseController {
44
44
  * Constructor helper for registering this controller's messaging system
45
45
  * actions.
46
46
  */
47
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
48
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _assertProfileSyncingEnabled);
47
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
48
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _assertProfileSyncingEnabled);
49
49
  /**
50
50
  * Utility to get the bearer token and storage key
51
51
  */
52
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _getStorageKeyAndBearerToken);
52
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _getStorageKeyAndBearerToken);
53
53
  /**
54
54
  * Rather than storing the storage key, we can compute the storage key when needed.
55
55
  *
56
56
  * @returns the storage key
57
57
  */
58
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _createStorageKey);
58
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _createStorageKey);
59
59
  /**
60
60
  * Signs a specific message using an underlying auth snap.
61
61
  *
62
62
  * @param message - A specific tagged message to sign.
63
63
  * @returns A Signature created by the snap.
64
64
  */
65
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _snapSignMessage);
66
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _setIsProfileSyncingUpdateLoading);
67
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _auth, {
65
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _snapSignMessage);
66
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _setIsProfileSyncingUpdateLoading);
67
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _auth, {
68
68
  getBearerToken: async () => {
69
69
  return await this.messagingSystem.call(
70
70
  "AuthenticationController:getBearerToken"
@@ -90,7 +90,7 @@ var UserStorageController = class extends _basecontroller.BaseController {
90
90
  );
91
91
  }
92
92
  });
93
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _notificationServices, {
93
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _notificationServices, {
94
94
  disableNotificationServices: async () => {
95
95
  return await this.messagingSystem.call(
96
96
  "NotificationServicesController:disableNotificationServices"
@@ -103,21 +103,21 @@ var UserStorageController = class extends _basecontroller.BaseController {
103
103
  }
104
104
  });
105
105
  this.getMetaMetricsState = params.getMetaMetricsState;
106
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
106
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
107
107
  }
108
108
  async enableProfileSyncing() {
109
109
  try {
110
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
111
- const authEnabled = _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).isAuthEnabled();
110
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
111
+ const authEnabled = _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).isAuthEnabled();
112
112
  if (!authEnabled) {
113
- await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).signIn();
113
+ await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).signIn();
114
114
  }
115
115
  this.update((state) => {
116
116
  state.isProfileSyncingEnabled = true;
117
117
  });
118
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
118
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
119
119
  } catch (e) {
120
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
120
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
121
121
  const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
122
122
  throw new Error(
123
123
  `${controllerName} - failed to enable profile syncing - ${errorMessage}`
@@ -135,21 +135,21 @@ var UserStorageController = class extends _basecontroller.BaseController {
135
135
  return;
136
136
  }
137
137
  try {
138
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
139
- const isNotificationServicesEnabled = await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _notificationServices).selectIsNotificationServicesEnabled();
138
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
139
+ const isNotificationServicesEnabled = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _notificationServices).selectIsNotificationServicesEnabled();
140
140
  if (isNotificationServicesEnabled) {
141
- await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _notificationServices).disableNotificationServices();
141
+ await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _notificationServices).disableNotificationServices();
142
142
  }
143
143
  const isMetaMetricsParticipation = this.getMetaMetricsState();
144
144
  if (!isMetaMetricsParticipation) {
145
145
  this.messagingSystem.call("AuthenticationController:performSignOut");
146
146
  }
147
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
147
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
148
148
  this.update((state) => {
149
149
  state.isProfileSyncingEnabled = false;
150
150
  });
151
151
  } catch (e) {
152
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
152
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
153
153
  const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
154
154
  throw new Error(
155
155
  `${controllerName} - failed to disable profile syncing - ${errorMessage}`
@@ -164,9 +164,9 @@ var UserStorageController = class extends _basecontroller.BaseController {
164
164
  * @returns the decrypted string contents found from user storage (or null if not found)
165
165
  */
166
166
  async performGetStorage(entryKey) {
167
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
168
- const { bearerToken, storageKey } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
169
- const result = await _chunkK6G7X6PXjs.getUserStorage.call(void 0, {
167
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
168
+ const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
169
+ const result = await _chunk5SXXO4MVjs.getUserStorage.call(void 0, {
170
170
  entryKey,
171
171
  bearerToken,
172
172
  storageKey
@@ -182,9 +182,9 @@ var UserStorageController = class extends _basecontroller.BaseController {
182
182
  * @returns nothing. NOTE that an error is thrown if fails to store data.
183
183
  */
184
184
  async performSetStorage(entryKey, value) {
185
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
186
- const { bearerToken, storageKey } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
187
- await _chunkK6G7X6PXjs.upsertUserStorage.call(void 0, value, {
185
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
186
+ const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
187
+ await _chunk5SXXO4MVjs.upsertUserStorage.call(void 0, value, {
188
188
  entryKey,
189
189
  bearerToken,
190
190
  storageKey
@@ -196,8 +196,8 @@ var UserStorageController = class extends _basecontroller.BaseController {
196
196
  * @returns the storage key
197
197
  */
198
198
  async getStorageKey() {
199
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
200
- const storageKey = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _createStorageKey, createStorageKey_fn).call(this);
199
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
200
+ const storageKey = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _createStorageKey, createStorageKey_fn).call(this);
201
201
  return storageKey;
202
202
  }
203
203
  };
@@ -236,21 +236,21 @@ assertProfileSyncingEnabled_fn = function() {
236
236
  };
237
237
  _getStorageKeyAndBearerToken = new WeakSet();
238
238
  getStorageKeyAndBearerToken_fn = async function() {
239
- const bearerToken = await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).getBearerToken();
239
+ const bearerToken = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).getBearerToken();
240
240
  if (!bearerToken) {
241
241
  throw new Error("UserStorageController - unable to get bearer token");
242
242
  }
243
- const storageKey = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _createStorageKey, createStorageKey_fn).call(this);
243
+ const storageKey = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _createStorageKey, createStorageKey_fn).call(this);
244
244
  return { bearerToken, storageKey };
245
245
  };
246
246
  _createStorageKey = new WeakSet();
247
247
  createStorageKey_fn = async function() {
248
- const id = await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).getProfileId();
248
+ const id = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _auth).getProfileId();
249
249
  if (!id) {
250
250
  throw new Error("UserStorageController - unable to create storage key");
251
251
  }
252
- const storageKeySignature = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _snapSignMessage, snapSignMessage_fn).call(this, `metamask:${id}`);
253
- const storageKey = _chunkJWTNHCVGjs.createSHA256Hash.call(void 0, storageKeySignature);
252
+ const storageKeySignature = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _snapSignMessage, snapSignMessage_fn).call(this, `metamask:${id}`);
253
+ const storageKey = _chunkT3FNDVE3js.createSHA256Hash.call(void 0, storageKeySignature);
254
254
  return storageKey;
255
255
  };
256
256
  _snapSignMessage = new WeakSet();
@@ -269,5 +269,6 @@ setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
269
269
 
270
270
 
271
271
 
272
- exports.UserStorageController = UserStorageController;
273
- //# sourceMappingURL=chunk-ARWL2LBB.js.map
272
+
273
+ exports.defaultState = defaultState; exports.UserStorageController = UserStorageController;
274
+ //# sourceMappingURL=chunk-YASNOFBV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AA4B/B,IAAM,iBAAiB;AAchB,IAAM,eAA2C;AAAA,EACtD,yBAAyB;AAAA,EACzB,+BAA+B;AACjC;AAEA,IAAM,WAAsD;AAAA,EAC1D,yBAAyB;AAAA,IACvB,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,+BAA+B;AAAA,IAC7B,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AA5DA;AAsHA,IAAqB,wBAArB,cAAmD,eAIjD;AAAA,EA2CA,YAAY,QAIT;AACD,UAAM;AAAA,MACJ,WAAW,OAAO;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,GAAG,cAAc,GAAG,OAAO,MAAM;AAAA,IAC5C,CAAC;AAUH;AAAA;AAAA;AAAA;AAAA;AAsJA;AAWA;AAAA;AAAA;AAAA,uBAAM;AAkBN;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AAiBN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA;AAzQA,8BAAQ;AAAA,MACN,gBAAgB,YAAY;AAC1B,eAAO,MAAM,KAAK,gBAAgB;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAAA,MACA,cAAc,YAAY;AACxB,cAAM,iBAAiB,MAAM,KAAK,gBAAgB;AAAA,UAChD;AAAA,QACF;AACA,eAAO,gBAAgB;AAAA,MACzB;AAAA,MACA,eAAe,MAAM;AACnB,eAAO,KAAK,gBAAgB,KAAK,qCAAqC;AAAA,MACxE;AAAA,MACA,QAAQ,YAAY;AAClB,eAAO,MAAM,KAAK,gBAAgB;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAAA,MACA,SAAS,YAAY;AACnB,eAAO,KAAK,gBAAgB;AAAA,UAC1B;AAAA,QACF;AAAA,MACF;AAA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AgB;AAAA,IACnB;AAAA,IACA,KAAK,qBAAqB,KAAK,IAAI;AAAA,EACrC;AAEA,OAAK,gBAAgB;AAAA,IACnB;AAAA,IACA,KAAK,sBAAsB,KAAK,IAAI;AAAA,EACtC;AACF;AA6HA;AAAA,iCAA4B,WAAS;AACnC,MAAI,CAAC,KAAK,MAAM,yBAAyB;AACvC,UAAM,IAAI;AAAA,MACR,GAAG,cAAc;AAAA,IACnB;AAAA,EACF;AACF;AAKM;AAAA,iCAA4B,iBAG/B;AACD,QAAM,cAAc,MAAM,mBAAK,OAAM,eAAe;AACpD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,QAAM,aAAa,MAAM,sBAAK,wCAAL;AAEzB,SAAO,EAAE,aAAa,WAAW;AACnC;AAOM;AAAA,sBAAiB,iBAAoB;AACzC,QAAM,KAAa,MAAM,mBAAK,OAAM,aAAa;AACjD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AAEA,QAAM,sBAAsB,MAAM,sBAAK,sCAAL,WAAsB,YAAY,EAAE;AACtE,QAAM,aAAa,iBAAiB,mBAAmB;AACvD,SAAO;AACT;AAQA;AAAA,qBAAgB,SAAC,SAAgD;AAC/D,SAAO,KAAK,gBAAgB;AAAA,IAC1B;AAAA,IACA,6BAA6B,OAAO;AAAA,EACtC;AACF;AAEA;AAAA,sCAAiC,SAC/B,+BACM;AACN,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,gCAAgC;AAAA,EACxC,CAAC;AACH","sourcesContent":["import type {\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport { createSHA256Hash } from './encryption';\nimport type { UserStorageEntryKeys } from './schema';\nimport { getUserStorage, upsertUserStorage } from './services';\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n>;\nexport type Actions = ActionsObj[keyof ActionsObj];\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\n\n// Allowed Actions\nexport type AllowedActions =\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n never,\n AllowedActions['type'],\n never\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n getMetaMetricsState: () => boolean;\n\n constructor(params: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n getMetaMetricsState: () => boolean;\n }) {\n super({\n messenger: params.messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...params.state },\n });\n\n this.getMetaMetricsState = params.getMetaMetricsState;\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n this.messagingSystem.call('AuthenticationController:performSignOut');\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param entryKey - entry key that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n entryKey: UserStorageEntryKeys,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n const result = await getUserStorage({\n entryKey,\n bearerToken,\n storageKey,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param entryKey - entry key that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n entryKey: UserStorageEntryKeys,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n entryKey,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n return this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n ) as Promise<string>;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n}\n"]}
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk2MVOZPBNjs = require('./chunk-2MVOZPBN.js');
6
+ var _chunkELHJSRS2js = require('./chunk-ELHJSRS2.js');
7
7
 
8
8
 
9
9
 
@@ -13,13 +13,15 @@ var _chunkIPSBQ3MSjs = require('./chunk-IPSBQ3MS.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
16
+ var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
17
17
 
18
18
  // src/controllers/authentication/AuthenticationController.ts
19
19
  var _basecontroller = require('@metamask/base-controller');
20
20
  var THIRTY_MIN_MS = 1e3 * 60 * 30;
21
21
  var controllerName = "AuthenticationController";
22
- var defaultState = { isSignedIn: false };
22
+ var defaultState = {
23
+ isSignedIn: false
24
+ };
23
25
  var metadata = {
24
26
  isSignedIn: {
25
27
  persist: true,
@@ -47,44 +49,44 @@ var AuthenticationController = class extends _basecontroller.BaseController {
47
49
  * Constructor helper for registering this controller's messaging system
48
50
  * actions.
49
51
  */
50
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
51
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _assertLoggedIn);
52
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _performAuthenticationFlow);
53
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _hasValidSession);
52
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
53
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _assertLoggedIn);
54
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _performAuthenticationFlow);
55
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _hasValidSession);
54
56
  /**
55
57
  * Returns the auth snap public key.
56
58
  *
57
59
  * @returns The snap public key.
58
60
  */
59
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _snapGetPublicKey);
61
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _snapGetPublicKey);
60
62
  /**
61
63
  * Signs a specific message using an underlying auth snap.
62
64
  *
63
65
  * @param message - A specific tagged message to sign.
64
66
  * @returns A Signature created by the snap.
65
67
  */
66
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _snapSignMessage);
67
- _chunkV46WVGWNjs.__privateAdd.call(void 0, this, _metametrics, void 0);
68
- _chunkV46WVGWNjs.__privateSet.call(void 0, this, _metametrics, metametrics);
69
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
68
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _snapSignMessage);
69
+ _chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _metametrics, void 0);
70
+ _chunkIGY2S5BCjs.__privateSet.call(void 0, this, _metametrics, metametrics);
71
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
70
72
  }
71
73
  async performSignIn() {
72
- const { accessToken } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _performAuthenticationFlow, performAuthenticationFlow_fn).call(this);
74
+ const { accessToken } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _performAuthenticationFlow, performAuthenticationFlow_fn).call(this);
73
75
  return accessToken;
74
76
  }
75
77
  performSignOut() {
76
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertLoggedIn, assertLoggedIn_fn).call(this);
78
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertLoggedIn, assertLoggedIn_fn).call(this);
77
79
  this.update((state) => {
78
80
  state.isSignedIn = false;
79
81
  state.sessionData = void 0;
80
82
  });
81
83
  }
82
84
  async getBearerToken() {
83
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertLoggedIn, assertLoggedIn_fn).call(this);
84
- if (_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _hasValidSession, hasValidSession_fn).call(this, this.state.sessionData)) {
85
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertLoggedIn, assertLoggedIn_fn).call(this);
86
+ if (_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _hasValidSession, hasValidSession_fn).call(this, this.state.sessionData)) {
85
87
  return this.state.sessionData.accessToken;
86
88
  }
87
- const { accessToken } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _performAuthenticationFlow, performAuthenticationFlow_fn).call(this);
89
+ const { accessToken } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _performAuthenticationFlow, performAuthenticationFlow_fn).call(this);
88
90
  return accessToken;
89
91
  }
90
92
  /**
@@ -94,11 +96,11 @@ var AuthenticationController = class extends _basecontroller.BaseController {
94
96
  * @returns profile for the session.
95
97
  */
96
98
  async getSessionProfile() {
97
- _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertLoggedIn, assertLoggedIn_fn).call(this);
98
- if (_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _hasValidSession, hasValidSession_fn).call(this, this.state.sessionData)) {
99
+ _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertLoggedIn, assertLoggedIn_fn).call(this);
100
+ if (_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _hasValidSession, hasValidSession_fn).call(this, this.state.sessionData)) {
99
101
  return this.state.sessionData.profile;
100
102
  }
101
- const { profile } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _performAuthenticationFlow, performAuthenticationFlow_fn).call(this);
103
+ const { profile } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _performAuthenticationFlow, performAuthenticationFlow_fn).call(this);
102
104
  return profile;
103
105
  }
104
106
  isSignedIn() {
@@ -140,16 +142,16 @@ assertLoggedIn_fn = function() {
140
142
  _performAuthenticationFlow = new WeakSet();
141
143
  performAuthenticationFlow_fn = async function() {
142
144
  try {
143
- const publicKey = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _snapGetPublicKey, snapGetPublicKey_fn).call(this);
144
- const nonce = await _chunk2MVOZPBNjs.getNonce.call(void 0, publicKey);
145
+ const publicKey = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _snapGetPublicKey, snapGetPublicKey_fn).call(this);
146
+ const nonce = await _chunkELHJSRS2js.getNonce.call(void 0, publicKey);
145
147
  if (!nonce) {
146
148
  throw new Error(`Unable to get nonce`);
147
149
  }
148
- const rawMessage = _chunk2MVOZPBNjs.createLoginRawMessage.call(void 0, nonce, publicKey);
149
- const signature = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _snapSignMessage, snapSignMessage_fn).call(this, rawMessage);
150
- const loginResponse = await _chunk2MVOZPBNjs.login.call(void 0, rawMessage, signature, {
151
- metametricsId: _chunkV46WVGWNjs.__privateGet.call(void 0, this, _metametrics).getMetaMetricsId(),
152
- agent: _chunkV46WVGWNjs.__privateGet.call(void 0, this, _metametrics).agent
150
+ const rawMessage = _chunkELHJSRS2js.createLoginRawMessage.call(void 0, nonce, publicKey);
151
+ const signature = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _snapSignMessage, snapSignMessage_fn).call(this, rawMessage);
152
+ const loginResponse = await _chunkELHJSRS2js.login.call(void 0, rawMessage, signature, {
153
+ metametricsId: _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _metametrics).getMetaMetricsId(),
154
+ agent: _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _metametrics).agent
153
155
  });
154
156
  if (!loginResponse?.token) {
155
157
  throw new Error(`Unable to login`);
@@ -158,7 +160,7 @@ performAuthenticationFlow_fn = async function() {
158
160
  identifierId: loginResponse.profile.identifier_id,
159
161
  profileId: loginResponse.profile.profile_id
160
162
  };
161
- const accessToken = await _chunk2MVOZPBNjs.getAccessToken.call(void 0, loginResponse.token);
163
+ const accessToken = await _chunkELHJSRS2js.getAccessToken.call(void 0, loginResponse.token);
162
164
  if (!accessToken) {
163
165
  throw new Error(`Unable to get Access Token`);
164
166
  }
@@ -217,5 +219,6 @@ snapSignMessage_fn = function(message) {
217
219
 
218
220
 
219
221
 
220
- exports.AuthenticationController = AuthenticationController;
221
- //# sourceMappingURL=chunk-WAS6V24H.js.map
222
+
223
+ exports.defaultState = defaultState; exports.AuthenticationController = AuthenticationController;
224
+ //# sourceMappingURL=chunk-YUXN5GSW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AAe/B,IAAM,gBAAgB,MAAO,KAAK;AAElC,IAAM,iBAAiB;AA8BhB,IAAM,eAA8C;AAAA,EACzD,YAAY;AACd;AACA,IAAM,WAAyD;AAAA,EAC7D,YAAY;AAAA,IACV,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,I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AA4B;AAAA,IAC9C;AAGA,SAAK,OAAO,CAAC,UAAU;AACrB,YAAM,aAAa;AACnB,YAAM,YAAY,oBAAI,KAAK;AAC3B,gBAAU,QAAQ,UAAU,QAAQ,IAAI,aAAa;AACrD,YAAM,cAAc;AAAA,QAClB;AAAA,QACA;AAAA,QACA,WAAW,UAAU,SAAS;AAAA,MAChC;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,SAAS,GAAG;AACV,YAAQ,MAAM,0BAA0B,CAAC;AAEzC,UAAM,KAAK,gBAAgB;AAAA,MACzB;AAAA,IACF;AACA,UAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AACzD,UAAM,IAAI;AAAA,MACR,GAAG,cAAc,8BAA8B,YAAY;AAAA,IAC7D;AAAA,EACF;AACF;AAEA;AAAA,qBAAgB,SACd,aAC4B;AAC5B,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,KAAK,MAAM,YAAY,SAAS;AACjD,MAAI,MAAM,QAAQ,GAAG;AACnB,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,oBAAI,KAAK;AAC7B,QAAM,SAAS,KAAK,IAAI,YAAY,QAAQ,IAAI,QAAQ;AAExD,SAAO,gBAAgB;AACzB;AAOA;AAAA,sBAAiB,WAAoB;AACnC,SAAO,KAAK,gBAAgB;AAAA,IAC1B;AAAA,IACA,2BAA2B;AAAA,EAC7B;AACF;AAQA;AAAA,qBAAgB,SAAC,SAAgD;AAC/D,SAAO,KAAK,gBAAgB;AAAA,IAC1B;AAAA,IACA,6BAA6B,OAAO;AAAA,EACtC;AACF","sourcesContent":["import type {\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport type { UserStorageControllerDisableProfileSyncing } from '../user-storage/UserStorageController';\nimport {\n createSnapPublicKeyRequest,\n createSnapSignMessageRequest,\n} from './auth-snap-requests';\nimport {\n createLoginRawMessage,\n getAccessToken,\n getNonce,\n login,\n} from './services';\n\nconst THIRTY_MIN_MS = 1000 * 60 * 30;\n\nconst controllerName = 'AuthenticationController';\n\n// State\ntype SessionProfile = {\n identifierId: string;\n profileId: string;\n};\n\ntype SessionData = {\n /** profile - anonymous profile data for the given logged in user */\n profile: SessionProfile;\n /** accessToken - used to make requests authorized endpoints */\n accessToken: string;\n /** expiresIn - string date to determine if new access token is required */\n expiresIn: string;\n};\n\ntype MetaMetricsAuth = {\n getMetaMetricsId: () => string;\n agent: 'extension' | 'mobile';\n};\n\nexport type AuthenticationControllerState = {\n /**\n * Global isSignedIn state.\n * Can be used to determine if \"Profile Syncing\" is enabled.\n */\n isSignedIn: boolean;\n sessionData?: SessionData;\n};\nexport const defaultState: AuthenticationControllerState = {\n isSignedIn: false,\n};\nconst metadata: StateMetadata<AuthenticationControllerState> = {\n isSignedIn: {\n persist: true,\n anonymous: true,\n },\n sessionData: {\n persist: true,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof AuthenticationController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: AuthenticationController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performSignIn'\n | 'performSignOut'\n | 'getBearerToken'\n | 'getSessionProfile'\n | 'isSignedIn'\n>;\nexport type Actions = ActionsObj[keyof ActionsObj];\nexport type AuthenticationControllerPerformSignIn = ActionsObj['performSignIn'];\nexport type AuthenticationControllerPerformSignOut =\n ActionsObj['performSignOut'];\nexport type AuthenticationControllerGetBearerToken =\n ActionsObj['getBearerToken'];\nexport type AuthenticationControllerGetSessionProfile =\n ActionsObj['getSessionProfile'];\nexport type AuthenticationControllerIsSignedIn = ActionsObj['isSignedIn'];\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | UserStorageControllerDisableProfileSyncing;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n never,\n AllowedActions['type'],\n never\n>;\n\n/**\n * Controller that enables authentication for restricted endpoints.\n * Used for Global Profile Syncing and Notifications\n */\nexport default class AuthenticationController extends BaseController<\n typeof controllerName,\n AuthenticationControllerState,\n AuthenticationControllerMessenger\n> {\n #metametrics: MetaMetricsAuth;\n\n constructor({\n messenger,\n state,\n metametrics,\n }: {\n messenger: AuthenticationControllerMessenger;\n state?: AuthenticationControllerState;\n /**\n * Not using the Messaging System as we\n * do not want to tie this strictly to extension\n */\n metametrics: MetaMetricsAuth;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#metametrics = metametrics;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getBearerToken',\n this.getBearerToken.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getSessionProfile',\n this.getSessionProfile.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:isSignedIn',\n this.isSignedIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignIn',\n this.performSignIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignOut',\n this.performSignOut.bind(this),\n );\n }\n\n public async performSignIn(): Promise<string> {\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n public performSignOut(): void {\n this.#assertLoggedIn();\n\n this.update((state) => {\n state.isSignedIn = false;\n state.sessionData = undefined;\n });\n }\n\n public async getBearerToken(): Promise<string> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.accessToken;\n }\n\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n /**\n * Will return a session profile.\n * Throws if a user is not logged in.\n *\n * @returns profile for the session.\n */\n public async getSessionProfile(): Promise<SessionProfile> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.profile;\n }\n\n const { profile } = await this.#performAuthenticationFlow();\n return profile;\n }\n\n public isSignedIn(): boolean {\n return this.state.isSignedIn;\n }\n\n #assertLoggedIn(): void {\n if (!this.state.isSignedIn) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n async #performAuthenticationFlow(): Promise<{\n profile: SessionProfile;\n accessToken: string;\n }> {\n try {\n // 1. Nonce\n const publicKey = await this.#snapGetPublicKey();\n const nonce = await getNonce(publicKey);\n if (!nonce) {\n throw new Error(`Unable to get nonce`);\n }\n\n // 2. Login\n const rawMessage = createLoginRawMessage(nonce, publicKey);\n const signature = await this.#snapSignMessage(rawMessage);\n const loginResponse = await login(rawMessage, signature, {\n metametricsId: this.#metametrics.getMetaMetricsId(),\n agent: this.#metametrics.agent,\n });\n if (!loginResponse?.token) {\n throw new Error(`Unable to login`);\n }\n\n const profile: SessionProfile = {\n identifierId: loginResponse.profile.identifier_id,\n profileId: loginResponse.profile.profile_id,\n };\n\n // 3. Trade for Access Token\n const accessToken = await getAccessToken(loginResponse.token);\n if (!accessToken) {\n throw new Error(`Unable to get Access Token`);\n }\n\n // Update Internal State\n this.update((state) => {\n state.isSignedIn = true;\n const expiresIn = new Date();\n expiresIn.setTime(expiresIn.getTime() + THIRTY_MIN_MS);\n state.sessionData = {\n profile,\n accessToken,\n expiresIn: expiresIn.toString(),\n };\n });\n\n return {\n profile,\n accessToken,\n };\n } catch (e) {\n console.error('Failed to authenticate', e);\n // Disable Profile Syncing\n await this.messagingSystem.call(\n 'UserStorageController:disableProfileSyncing',\n );\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new Error(\n `${controllerName}: Failed to authenticate - ${errorMessage}`,\n );\n }\n }\n\n #hasValidSession(\n sessionData: SessionData | undefined,\n ): sessionData is SessionData {\n if (!sessionData) {\n return false;\n }\n\n const prevDate = Date.parse(sessionData.expiresIn);\n if (isNaN(prevDate)) {\n return false;\n }\n\n const currentDate = new Date();\n const diffMs = Math.abs(currentDate.getTime() - prevDate);\n\n return THIRTY_MIN_MS > diffMs;\n }\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n #snapGetPublicKey(): Promise<string> {\n return this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n ) as Promise<string>;\n }\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n return this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n ) as Promise<string>;\n }\n}\n"]}
@@ -1,22 +1,24 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkWAS6V24Hjs = require('../../chunk-WAS6V24H.js');
4
- require('../../chunk-2MVOZPBN.js');
3
+
4
+ var _chunkYUXN5GSWjs = require('../../chunk-YUXN5GSW.js');
5
+ require('../../chunk-ELHJSRS2.js');
5
6
  require('../../chunk-IPSBQ3MS.js');
6
- require('../../chunk-QILE6KIE.js');
7
- require('../../chunk-DLXLU44Z.js');
8
- require('../../chunk-LHDVZNW5.js');
9
- require('../../chunk-6TK7544L.js');
10
- require('../../chunk-XUPRRLBI.js');
11
- require('../../chunk-T77FC4PB.js');
7
+ require('../../chunk-PTR4DAX6.js');
8
+ require('../../chunk-NLHLVVOO.js');
9
+ require('../../chunk-Q5WIUNX5.js');
10
+ require('../../chunk-AVOOINGJ.js');
11
+ require('../../chunk-BOET676P.js');
12
+ require('../../chunk-PBRUOBEQ.js');
12
13
  require('../../chunk-RG4II6WH.js');
13
14
  require('../../chunk-PQ5T4GHY.js');
14
- require('../../chunk-LUKNP4HM.js');
15
- require('../../chunk-GLDUXN2T.js');
16
- require('../../chunk-4OMJ7A6A.js');
15
+ require('../../chunk-P52TG263.js');
16
+ require('../../chunk-P4DUDLMY.js');
17
+ require('../../chunk-SMKTWM6I.js');
17
18
  require('../../chunk-MBTBE4P5.js');
18
- require('../../chunk-V46WVGWN.js');
19
+ require('../../chunk-IGY2S5BC.js');
20
+
19
21
 
20
22
 
21
- exports.default = _chunkWAS6V24Hjs.AuthenticationController;
23
+ exports.default = _chunkYUXN5GSWjs.AuthenticationController; exports.defaultState = _chunkYUXN5GSWjs.defaultState;
22
24
  //# sourceMappingURL=AuthenticationController.js.map
@@ -1,22 +1,24 @@
1
1
  import {
2
- AuthenticationController
3
- } from "../../chunk-PRDECQM6.mjs";
4
- import "../../chunk-W7JFFMEZ.mjs";
2
+ AuthenticationController,
3
+ defaultState
4
+ } from "../../chunk-32HAX3MW.mjs";
5
+ import "../../chunk-KBCXN3YW.mjs";
5
6
  import "../../chunk-6P6CUKKI.mjs";
6
- import "../../chunk-IZHWP5VW.mjs";
7
- import "../../chunk-3FJQHCCQ.mjs";
8
- import "../../chunk-UWRKMJBI.mjs";
9
- import "../../chunk-LN2BY2QF.mjs";
10
- import "../../chunk-7VMXBDXN.mjs";
11
- import "../../chunk-YWA77VMP.mjs";
7
+ import "../../chunk-WJCKQLKK.mjs";
8
+ import "../../chunk-FCT2LIGH.mjs";
9
+ import "../../chunk-JLDFMYAH.mjs";
10
+ import "../../chunk-Y46NMA3V.mjs";
11
+ import "../../chunk-WB6MUIML.mjs";
12
+ import "../../chunk-CAIIVJAO.mjs";
12
13
  import "../../chunk-5XSXZTED.mjs";
13
14
  import "../../chunk-5EBUFNAN.mjs";
14
- import "../../chunk-UEZI2POO.mjs";
15
- import "../../chunk-VTM5T7Y4.mjs";
16
- import "../../chunk-GLS4QZF6.mjs";
15
+ import "../../chunk-AXWK4Y23.mjs";
16
+ import "../../chunk-B5DBQDB3.mjs";
17
+ import "../../chunk-FQ5SDMRE.mjs";
17
18
  import "../../chunk-TFFQFIJV.mjs";
18
- import "../../chunk-26CCETCM.mjs";
19
+ import "../../chunk-U5UIDVOO.mjs";
19
20
  export {
20
- AuthenticationController as default
21
+ AuthenticationController as default,
22
+ defaultState
21
23
  };
22
24
  //# sourceMappingURL=AuthenticationController.mjs.map
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  var _chunkIPSBQ3MSjs = require('../../chunk-IPSBQ3MS.js');
5
- require('../../chunk-V46WVGWN.js');
5
+ require('../../chunk-IGY2S5BC.js');
6
6
 
7
7
 
8
8
 
@@ -2,7 +2,7 @@ import {
2
2
  createSnapPublicKeyRequest,
3
3
  createSnapSignMessageRequest
4
4
  } from "../../chunk-6P6CUKKI.mjs";
5
- import "../../chunk-26CCETCM.mjs";
5
+ import "../../chunk-U5UIDVOO.mjs";
6
6
  export {
7
7
  createSnapPublicKeyRequest,
8
8
  createSnapSignMessageRequest
@@ -1,27 +1,28 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkBVM4HBM4js = require('../../chunk-BVM4HBM4.js');
3
+ var _chunkRX5R6BUIjs = require('../../chunk-RX5R6BUI.js');
4
4
 
5
5
 
6
- var _chunkWAS6V24Hjs = require('../../chunk-WAS6V24H.js');
7
- require('../../chunk-2MVOZPBN.js');
8
- require('../../chunk-GJJT2CAL.js');
6
+
7
+ var _chunkYUXN5GSWjs = require('../../chunk-YUXN5GSW.js');
8
+ require('../../chunk-ELHJSRS2.js');
9
9
  require('../../chunk-IPSBQ3MS.js');
10
- require('../../chunk-QILE6KIE.js');
11
- require('../../chunk-DLXLU44Z.js');
12
- require('../../chunk-LHDVZNW5.js');
13
- require('../../chunk-6TK7544L.js');
14
- require('../../chunk-XUPRRLBI.js');
15
- require('../../chunk-T77FC4PB.js');
10
+ require('../../chunk-PTR4DAX6.js');
11
+ require('../../chunk-NLHLVVOO.js');
12
+ require('../../chunk-Q5WIUNX5.js');
13
+ require('../../chunk-AVOOINGJ.js');
14
+ require('../../chunk-BOET676P.js');
15
+ require('../../chunk-PBRUOBEQ.js');
16
16
  require('../../chunk-RG4II6WH.js');
17
17
  require('../../chunk-PQ5T4GHY.js');
18
- require('../../chunk-LUKNP4HM.js');
19
- require('../../chunk-GLDUXN2T.js');
20
- require('../../chunk-4OMJ7A6A.js');
18
+ require('../../chunk-P52TG263.js');
19
+ require('../../chunk-P4DUDLMY.js');
20
+ require('../../chunk-SMKTWM6I.js');
21
21
  require('../../chunk-MBTBE4P5.js');
22
- require('../../chunk-V46WVGWN.js');
22
+ require('../../chunk-IGY2S5BC.js');
23
+
23
24
 
24
25
 
25
26
 
26
- exports.Controller = _chunkWAS6V24Hjs.AuthenticationController; exports.Mocks = _chunkBVM4HBM4js.fixtures_exports;
27
+ exports.Controller = _chunkYUXN5GSWjs.AuthenticationController; exports.Mocks = _chunkRX5R6BUIjs.fixtures_exports; exports.defaultState = _chunkYUXN5GSWjs.defaultState;
27
28
  //# sourceMappingURL=index.js.map
@@ -1,27 +1,28 @@
1
1
  import {
2
2
  fixtures_exports
3
- } from "../../chunk-QHL6SQTC.mjs";
3
+ } from "../../chunk-AARMY5TW.mjs";
4
4
  import {
5
- AuthenticationController
6
- } from "../../chunk-PRDECQM6.mjs";
7
- import "../../chunk-W7JFFMEZ.mjs";
8
- import "../../chunk-JMU3OVPK.mjs";
5
+ AuthenticationController,
6
+ defaultState
7
+ } from "../../chunk-32HAX3MW.mjs";
8
+ import "../../chunk-KBCXN3YW.mjs";
9
9
  import "../../chunk-6P6CUKKI.mjs";
10
- import "../../chunk-IZHWP5VW.mjs";
11
- import "../../chunk-3FJQHCCQ.mjs";
12
- import "../../chunk-UWRKMJBI.mjs";
13
- import "../../chunk-LN2BY2QF.mjs";
14
- import "../../chunk-7VMXBDXN.mjs";
15
- import "../../chunk-YWA77VMP.mjs";
10
+ import "../../chunk-WJCKQLKK.mjs";
11
+ import "../../chunk-FCT2LIGH.mjs";
12
+ import "../../chunk-JLDFMYAH.mjs";
13
+ import "../../chunk-Y46NMA3V.mjs";
14
+ import "../../chunk-WB6MUIML.mjs";
15
+ import "../../chunk-CAIIVJAO.mjs";
16
16
  import "../../chunk-5XSXZTED.mjs";
17
17
  import "../../chunk-5EBUFNAN.mjs";
18
- import "../../chunk-UEZI2POO.mjs";
19
- import "../../chunk-VTM5T7Y4.mjs";
20
- import "../../chunk-GLS4QZF6.mjs";
18
+ import "../../chunk-AXWK4Y23.mjs";
19
+ import "../../chunk-B5DBQDB3.mjs";
20
+ import "../../chunk-FQ5SDMRE.mjs";
21
21
  import "../../chunk-TFFQFIJV.mjs";
22
- import "../../chunk-26CCETCM.mjs";
22
+ import "../../chunk-U5UIDVOO.mjs";
23
23
  export {
24
24
  AuthenticationController as Controller,
25
- fixtures_exports as Mocks
25
+ fixtures_exports as Mocks,
26
+ defaultState
26
27
  };
27
28
  //# sourceMappingURL=index.mjs.map