@metamask/profile-sync-controller 5.0.0 → 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 +20 -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 +7 -7
package/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.0.0]
11
+
12
+ ### Changed
13
+
14
+ - Improve logic & dependencies between profile sync, auth, user storage & notifications ([#5275](https://github.com/MetaMask/core/pull/5275))
15
+ - Mark `@metamask/snaps-controllers` peer dependency bump as breaking in CHANGELOG ([#5267](https://github.com/MetaMask/core/pull/5267))
16
+ - Fix eslint warnings & errors ([#5261](https://github.com/MetaMask/core/pull/5261))
17
+ - Rename `ControllerMessenger` to `Messenger` ([#5244](https://github.com/MetaMask/core/pull/5244))
18
+ - Bump snaps-sdk to v6.16.0 ([#5220](https://github.com/MetaMask/core/pull/5220))
19
+ - **BREAKING:** Bump `@metamask/snaps-controllers` peer dependency from `^9.10.0` to `^9.19.0` ([#5265](https://github.com/MetaMask/core/pull/5265))
20
+ - Bump `@metamask/snaps-sdk` from `^6.16.0` to `^6.17.1` ([#5265](https://github.com/MetaMask/core/pull/5265))
21
+ - Bump `@metamask/snaps-utils` from `^8.9.0` to `^8.10.0` ([#5265](https://github.com/MetaMask/core/pull/5265))
22
+ - Bump `@metamask/keyring-api"` from `^16.1.0` to `^17.0.0` ([#5280](https://github.com/MetaMask/core/pull/5280))
23
+
24
+ ### Removed
25
+
26
+ - **BREAKING:** Remove metametrics dependencies in UserStorageController ([#5278](https://github.com/MetaMask/core/pull/5278))
27
+
10
28
  ## [5.0.0]
11
29
 
12
30
  ### Changed
@@ -435,7 +453,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
435
453
 
436
454
  - Initial release
437
455
 
438
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@5.0.0...HEAD
456
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@6.0.0...HEAD
457
+ [6.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@5.0.0...@metamask/profile-sync-controller@6.0.0
439
458
  [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.1.1...@metamask/profile-sync-controller@5.0.0
440
459
  [4.1.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.1.0...@metamask/profile-sync-controller@4.1.1
441
460
  [4.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.0.1...@metamask/profile-sync-controller@4.1.0
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationController.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAQ3D,iEAG8B;AAC9B,6CAKoB;AAEpB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAErC,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA8BrC,QAAA,YAAY,GAAkC;IACzD,UAAU,EAAE,KAAK;CAClB,CAAC;AACF,MAAM,QAAQ,GAAiD;IAC7D,UAAU,EAAE;QACV,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AA0DF;;;GAGG;AACH,MAAqB,wBAAyB,SAAQ,gCAIrD;IAsBC,YAAY,EACV,SAAS,EACT,KAAK,EACL,WAAW,GASZ;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ;YACR,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,EAAE,GAAG,oBAAY,EAAE,GAAG,KAAK,EAAE;SACrC,CAAC,CAAC;;QAvCL,wDAA8B;QAE9B,+CAAc,KAAK,EAAC;QAEpB,sDAAqB;YACnB,6BAA6B,EAAE,GAAG,EAAE;gBAClC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC9C,4BAA4B,CAC7B,CAAC;gBACF,uBAAA,IAAI,wCAAe,UAAU,MAAA,CAAC;gBAE9B,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,0BAA0B,EAAE,GAAG,EAAE;oBAC9D,uBAAA,IAAI,wCAAe,IAAI,MAAA,CAAC;gBAC1B,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,wBAAwB,EAAE,GAAG,EAAE;oBAC5D,uBAAA,IAAI,wCAAe,KAAK,MAAA,CAAC;gBAC3B,CAAC,CAAC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AChB,CAAC;AAID;;;;;GAKG;AACH,KAAK,oDAAkB,OAA6B;IAClD,IAAI,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,iDAA4B,EAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;kBAnRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\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 | Promise<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 =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\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\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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 #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\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 if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\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.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: await 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(\n loginResponse.token,\n this.#metametrics.agent,\n );\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 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 #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\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 async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"AuthenticationController.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAQ3D,iEAG8B;AAC9B,6CAKoB;AAEpB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAA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IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,iDAA4B,EAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;kBAnRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\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 | Promise<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 =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\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\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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 readonly #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n readonly #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\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 if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\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.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: await 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(\n loginResponse.token,\n this.#metametrics.agent,\n );\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 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 #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\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 async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from "@metamask/base-controller";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
4
4
  import type { HandleSnapRequest } from "@metamask/snaps-controllers";
@@ -46,7 +46,7 @@ export type AuthenticationControllerStateChangeEvent = ControllerStateChangeEven
46
46
  export type Events = AuthenticationControllerStateChangeEvent;
47
47
  export type AllowedActions = HandleSnapRequest | KeyringControllerGetStateAction;
48
48
  export type AllowedEvents = KeyringControllerLockEvent | KeyringControllerUnlockEvent;
49
- export type AuthenticationControllerMessenger = RestrictedControllerMessenger<typeof controllerName, Actions | AllowedActions, Events | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
49
+ export type AuthenticationControllerMessenger = RestrictedMessenger<typeof controllerName, Actions | AllowedActions, Events | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
50
50
  /**
51
51
  * Controller that enables authentication for restricted endpoints.
52
52
  * Used for Global Profile Syncing and Notifications
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationController.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,gBAAgB,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;OAG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A6B,CAC3E,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAOhB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAW9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAWlD,UAAU,IAAI,OAAO;CAqJ7B"}
1
+ {"version":3,"file":"AuthenticationController.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC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0B,CACxB,OAAO,cAAc,EACrB,6BAA6B,CAC9B,CAAC;AAEJ,MAAM,MAAM,MAAM,GAAG,wCAAwC,CAAC;AAG9D,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,+BAA+B,CAAC;AAEpC,MAAM,MAAM,aAAa,GACrB,0BAA0B,GAC1B,4BAA4B,CAAC;AAGjC,MAAM,MAAM,iCAAiC,GAAG,mBAAmB,CACjE,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAOhB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAW9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAWlD,UAAU,IAAI,OAAO;CAqJ7B"}
@@ -1,4 +1,4 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from "@metamask/base-controller";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
4
4
  import type { HandleSnapRequest } from "@metamask/snaps-controllers";
@@ -46,7 +46,7 @@ export type AuthenticationControllerStateChangeEvent = ControllerStateChangeEven
46
46
  export type Events = AuthenticationControllerStateChangeEvent;
47
47
  export type AllowedActions = HandleSnapRequest | KeyringControllerGetStateAction;
48
48
  export type AllowedEvents = KeyringControllerLockEvent | KeyringControllerUnlockEvent;
49
- export type AuthenticationControllerMessenger = RestrictedControllerMessenger<typeof controllerName, Actions | AllowedActions, Events | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
49
+ export type AuthenticationControllerMessenger = RestrictedMessenger<typeof controllerName, Actions | AllowedActions, Events | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
50
50
  /**
51
51
  * Controller that enables authentication for restricted endpoints.
52
52
  * Used for Global Profile Syncing and Notifications
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationController.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,gBAAgB,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,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4BAA4B,CAAC;AAGjC,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,CAC3E,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAOhB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAW9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAWlD,UAAU,IAAI,OAAO;CAqJ7B"}
1
+ {"version":3,"file":"AuthenticationController.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc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,CAAC,CAAC;AAE1E,MAAM,MAAM,wCAAwC,GAClD,0BAA0B,CACxB,OAAO,cAAc,EACrB,6BAA6B,CAC9B,CAAC;AAEJ,MAAM,MAAM,MAAM,GAAG,wCAAwC,CAAC;AAG9D,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,+BAA+B,CAAC;AAEpC,MAAM,MAAM,aAAa,GACrB,0BAA0B,GAC1B,4BAA4B,CAAC;AAGjC,MAAM,MAAM,iCAAiC,GAAG,mBAAmB,CACjE,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAOhB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAW9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAWlD,UAAU,IAAI,OAAO;CAqJ7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationController.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC7B,iCAA6B;AAC9B,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,QAAQ,EACR,KAAK,EAC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AC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,4BAA4B,CAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;eAnRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\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 | Promise<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 =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\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\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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 #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\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 if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\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.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: await 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(\n loginResponse.token,\n this.#metametrics.agent,\n );\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 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 #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\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 async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"AuthenticationController.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC7B,iCAA6B;AAC9B,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,QAAQ,EACR,KAAK,EACN,uBAAmB;AAEpB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAErC,MAAM,cAAc,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KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,4BAA4B,CAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;eAnRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\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 | Promise<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 =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\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\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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 readonly #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n readonly #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\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 if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\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.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: await 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(\n loginResponse.token,\n this.#metametrics.agent,\n );\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 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 #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\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 async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
@@ -17,12 +17,9 @@ exports.getMockAuthNonceResponse = getMockAuthNonceResponse;
17
17
  exports.MOCK_JWT = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
18
18
  exports.MOCK_LOGIN_RESPONSE = {
19
19
  token: exports.MOCK_JWT,
20
- // eslint-disable-next-line @typescript-eslint/naming-convention
21
20
  expires_in: new Date().toString(),
22
21
  profile: {
23
- // eslint-disable-next-line @typescript-eslint/naming-convention
24
22
  identifier_id: 'MOCK_IDENTIFIER',
25
- // eslint-disable-next-line @typescript-eslint/naming-convention
26
23
  profile_id: 'MOCK_PROFILE_ID',
27
24
  },
28
25
  };
@@ -36,9 +33,7 @@ const getMockAuthLoginResponse = () => {
36
33
  exports.getMockAuthLoginResponse = getMockAuthLoginResponse;
37
34
  exports.MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${exports.MOCK_JWT}`;
38
35
  exports.MOCK_OATH_TOKEN_RESPONSE = {
39
- // eslint-disable-next-line @typescript-eslint/naming-convention
40
36
  access_token: exports.MOCK_ACCESS_TOKEN,
41
- // eslint-disable-next-line @typescript-eslint/naming-convention
42
37
  expires_in: new Date().getTime(),
43
38
  };
44
39
  const getMockAuthAccessTokenResponse = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponses.cjs","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":";;;AAKA,8CAIqB;AAQR,QAAA,UAAU,GAAG,mBAAmB,CAAC;AACjC,QAAA,mBAAmB,GAAkB;IAChD,KAAK,EAAE,kBAAU;CAClB,CAAC;AAEK,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO;QACL,GAAG,EAAE,8BAAmB;QACxB,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,2BAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC;AAEW,QAAA,QAAQ,GACnB,6JAA6J,CAAC;AACnJ,QAAA,mBAAmB,GAAkB;IAChD,KAAK,EAAE,gBAAQ;IACf,gEAAgE;IAChE,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE;IACjC,OAAO,EAAE;QACP,gEAAgE;QAChE,aAAa,EAAE,iBAAiB;QAChC,gEAAgE;QAChE,UAAU,EAAE,iBAAiB;KAC9B;CACF,CAAC;AAEK,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO;QACL,GAAG,EAAE,8BAAmB;QACxB,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,2BAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC;AAEW,QAAA,iBAAiB,GAAG,qBAAqB,gBAAQ,EAAE,CAAC;AACpD,QAAA,wBAAwB,GAAuB;IAC1D,gEAAgE;IAChE,YAAY,EAAE,yBAAiB;IAC/B,gEAAgE;IAChE,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;CACjC,CAAC;AAEK,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,OAAO;QACL,GAAG,EAAE,+BAAoB;QACzB,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,gCAAwB;KACZ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,8BAA8B,kCAMzC","sourcesContent":["import type {\n LoginResponse,\n NonceResponse,\n OAuthTokenResponse,\n} from '../services';\nimport {\n AUTH_LOGIN_ENDPOINT,\n AUTH_NONCE_ENDPOINT,\n OIDC_TOKENS_ENDPOINT,\n} from '../services';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_NONCE = '4cbfqzoQpcNxVImGv';\nexport const MOCK_NONCE_RESPONSE: NonceResponse = {\n nonce: MOCK_NONCE,\n};\n\nexport const getMockAuthNonceResponse = () => {\n return {\n url: AUTH_NONCE_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_NONCE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_JWT =\n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';\nexport const MOCK_LOGIN_RESPONSE: LoginResponse = {\n token: MOCK_JWT,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: new Date().toString(),\n profile: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_id: 'MOCK_IDENTIFIER',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n profile_id: 'MOCK_PROFILE_ID',\n },\n};\n\nexport const getMockAuthLoginResponse = () => {\n return {\n url: AUTH_LOGIN_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_LOGIN_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;\nexport const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n access_token: MOCK_ACCESS_TOKEN,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: new Date().getTime(),\n};\n\nexport const getMockAuthAccessTokenResponse = () => {\n return {\n url: OIDC_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_OATH_TOKEN_RESPONSE,\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponses.cjs","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":";;;AAKA,8CAIqB;AAQR,QAAA,UAAU,GAAG,mBAAmB,CAAC;AACjC,QAAA,mBAAmB,GAAkB;IAChD,KAAK,EAAE,kBAAU;CAClB,CAAC;AAEK,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO;QACL,GAAG,EAAE,8BAAmB;QACxB,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,2BAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC;AAEW,QAAA,QAAQ,GACnB,6JAA6J,CAAC;AACnJ,QAAA,mBAAmB,GAAkB;IAChD,KAAK,EAAE,gBAAQ;IACf,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE;IACjC,OAAO,EAAE;QACP,aAAa,EAAE,iBAAiB;QAChC,UAAU,EAAE,iBAAiB;KAC9B;CACF,CAAC;AAEK,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO;QACL,GAAG,EAAE,8BAAmB;QACxB,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,2BAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,wBAAwB,4BAMnC;AAEW,QAAA,iBAAiB,GAAG,qBAAqB,gBAAQ,EAAE,CAAC;AACpD,QAAA,wBAAwB,GAAuB;IAC1D,YAAY,EAAE,yBAAiB;IAE/B,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;CACjC,CAAC;AAEK,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,OAAO;QACL,GAAG,EAAE,+BAAoB;QACzB,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,gCAAwB;KACZ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,8BAA8B,kCAMzC","sourcesContent":["import type {\n LoginResponse,\n NonceResponse,\n OAuthTokenResponse,\n} from '../services';\nimport {\n AUTH_LOGIN_ENDPOINT,\n AUTH_NONCE_ENDPOINT,\n OIDC_TOKENS_ENDPOINT,\n} from '../services';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_NONCE = '4cbfqzoQpcNxVImGv';\nexport const MOCK_NONCE_RESPONSE: NonceResponse = {\n nonce: MOCK_NONCE,\n};\n\nexport const getMockAuthNonceResponse = () => {\n return {\n url: AUTH_NONCE_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_NONCE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_JWT =\n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';\nexport const MOCK_LOGIN_RESPONSE: LoginResponse = {\n token: MOCK_JWT,\n expires_in: new Date().toString(),\n profile: {\n identifier_id: 'MOCK_IDENTIFIER',\n profile_id: 'MOCK_PROFILE_ID',\n },\n};\n\nexport const getMockAuthLoginResponse = () => {\n return {\n url: AUTH_LOGIN_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_LOGIN_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;\nexport const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = {\n access_token: MOCK_ACCESS_TOKEN,\n\n expires_in: new Date().getTime(),\n};\n\nexport const getMockAuthAccessTokenResponse = () => {\n return {\n url: OIDC_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_OATH_TOKEN_RESPONSE,\n } satisfies MockResponse;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponses.d.cts","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EACnB,wBAAoB;AAarB,eAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,eAAO,MAAM,mBAAmB,EAAE,aAEjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,QAAQ,gKAC0I,CAAC;AAChK,eAAO,MAAM,mBAAmB,EAAE,aAUjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kLAAkC,CAAC;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAKtC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;CAM1C,CAAC"}
1
+ {"version":3,"file":"mockResponses.d.cts","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EACnB,wBAAoB;AAarB,eAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,eAAO,MAAM,mBAAmB,EAAE,aAEjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,QAAQ,gKAC0I,CAAC;AAChK,eAAO,MAAM,mBAAmB,EAAE,aAOjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kLAAkC,CAAC;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAItC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;CAM1C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponses.d.mts","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EACnB,wBAAoB;AAarB,eAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,eAAO,MAAM,mBAAmB,EAAE,aAEjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,QAAQ,gKAC0I,CAAC;AAChK,eAAO,MAAM,mBAAmB,EAAE,aAUjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kLAAkC,CAAC;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAKtC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;CAM1C,CAAC"}
1
+ {"version":3,"file":"mockResponses.d.mts","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EACnB,wBAAoB;AAarB,eAAO,MAAM,UAAU,sBAAsB,CAAC;AAC9C,eAAO,MAAM,mBAAmB,EAAE,aAEjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,QAAQ,gKAC0I,CAAC;AAChK,eAAO,MAAM,mBAAmB,EAAE,aAOjC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;CAMpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kLAAkC,CAAC;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAItC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;CAM1C,CAAC"}
@@ -13,12 +13,9 @@ export const getMockAuthNonceResponse = () => {
13
13
  export const MOCK_JWT = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
14
14
  export const MOCK_LOGIN_RESPONSE = {
15
15
  token: MOCK_JWT,
16
- // eslint-disable-next-line @typescript-eslint/naming-convention
17
16
  expires_in: new Date().toString(),
18
17
  profile: {
19
- // eslint-disable-next-line @typescript-eslint/naming-convention
20
18
  identifier_id: 'MOCK_IDENTIFIER',
21
- // eslint-disable-next-line @typescript-eslint/naming-convention
22
19
  profile_id: 'MOCK_PROFILE_ID',
23
20
  },
24
21
  };
@@ -31,9 +28,7 @@ export const getMockAuthLoginResponse = () => {
31
28
  };
32
29
  export const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;
33
30
  export const MOCK_OATH_TOKEN_RESPONSE = {
34
- // eslint-disable-next-line @typescript-eslint/naming-convention
35
31
  access_token: MOCK_ACCESS_TOKEN,
36
- // eslint-disable-next-line @typescript-eslint/naming-convention
37
32
  expires_in: new Date().getTime(),
38
33
  };
39
34
  export const getMockAuthAccessTokenResponse = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponses.mjs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aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,wBAAwB;KACZ,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import type {\n LoginResponse,\n NonceResponse,\n OAuthTokenResponse,\n} from '../services';\nimport {\n AUTH_LOGIN_ENDPOINT,\n AUTH_NONCE_ENDPOINT,\n OIDC_TOKENS_ENDPOINT,\n} from '../services';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_NONCE = '4cbfqzoQpcNxVImGv';\nexport const MOCK_NONCE_RESPONSE: NonceResponse = {\n nonce: MOCK_NONCE,\n};\n\nexport const getMockAuthNonceResponse = () => {\n return {\n url: AUTH_NONCE_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_NONCE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_JWT =\n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';\nexport const MOCK_LOGIN_RESPONSE: LoginResponse = {\n token: MOCK_JWT,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: new Date().toString(),\n profile: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_id: 'MOCK_IDENTIFIER',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n profile_id: 'MOCK_PROFILE_ID',\n },\n};\n\nexport const getMockAuthLoginResponse = () => {\n return {\n url: AUTH_LOGIN_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_LOGIN_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;\nexport const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n access_token: MOCK_ACCESS_TOKEN,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: new Date().getTime(),\n};\n\nexport const getMockAuthAccessTokenResponse = () => {\n return {\n url: OIDC_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_OATH_TOKEN_RESPONSE,\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponses.mjs","sourceRoot":"","sources":["../../../../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,wBAAoB;AAQrB,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAkB;IAChD,KAAK,EAAE,UAAU;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO;QACL,GAAG,EAAE,mBAAmB;QACxB,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,mBAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GACnB,6JAA6J,CAAC;AAChK,MAAM,CAAC,MAAM,mBAAmB,GAAkB;IAChD,KAAK,EAAE,QAAQ;IACf,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE;IACjC,OAAO,EAAE;QACP,aAAa,EAAE,iBAAiB;QAChC,UAAU,EAAE,iBAAiB;KAC9B;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO;QACL,GAAG,EAAE,mBAAmB;QACxB,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,mBAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,QAAQ,EAAE,CAAC;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAuB;IAC1D,YAAY,EAAE,iBAAiB;IAE/B,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,OAAO;QACL,GAAG,EAAE,oBAAoB;QACzB,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,wBAAwB;KACZ,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import type {\n LoginResponse,\n NonceResponse,\n OAuthTokenResponse,\n} from '../services';\nimport {\n AUTH_LOGIN_ENDPOINT,\n AUTH_NONCE_ENDPOINT,\n OIDC_TOKENS_ENDPOINT,\n} from '../services';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_NONCE = '4cbfqzoQpcNxVImGv';\nexport const MOCK_NONCE_RESPONSE: NonceResponse = {\n nonce: MOCK_NONCE,\n};\n\nexport const getMockAuthNonceResponse = () => {\n return {\n url: AUTH_NONCE_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_NONCE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_JWT =\n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';\nexport const MOCK_LOGIN_RESPONSE: LoginResponse = {\n token: MOCK_JWT,\n expires_in: new Date().toString(),\n profile: {\n identifier_id: 'MOCK_IDENTIFIER',\n profile_id: 'MOCK_PROFILE_ID',\n },\n};\n\nexport const getMockAuthLoginResponse = () => {\n return {\n url: AUTH_LOGIN_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_LOGIN_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;\nexport const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = {\n access_token: MOCK_ACCESS_TOKEN,\n\n expires_in: new Date().getTime(),\n};\n\nexport const getMockAuthAccessTokenResponse = () => {\n return {\n url: OIDC_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_OATH_TOKEN_RESPONSE,\n } satisfies MockResponse;\n};\n"]}
@@ -63,10 +63,8 @@ async function login(rawMessage, signature, clientMetaMetrics) {
63
63
  },
64
64
  body: JSON.stringify({
65
65
  signature,
66
- // eslint-disable-next-line @typescript-eslint/naming-convention
67
66
  raw_message: rawMessage,
68
67
  metametrics: {
69
- // eslint-disable-next-line @typescript-eslint/naming-convention
70
68
  metametrics_id: clientMetaMetrics.metametricsId,
71
69
  agent: clientMetaMetrics.agent,
72
70
  },
@@ -1 +1 @@
1
- {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAE3B,8CAA8E;AAE9E,MAAM,QAAQ,GAAG,IAAA,gBAAU,EAAC,SAAG,CAAC,GAAG,CAAC,CAAC;AAErC,MAAM,aAAa,GAAW,QAAQ,CAAC,UAAU,CAAC;AACrC,QAAA,mBAAmB,GAAG,GAAG,aAAa,eAAe,CAAC;AACtD,QAAA,mBAAmB,GAAG,GAAG,aAAa,mBAAmB,CAAC;AAEvE,MAAM,aAAa,GAAW,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC;AAC3C,QAAA,oBAAoB,GAAG,GAAG,aAAa,eAAe,CAAC;AACpE,MAAM,cAAc,GAAG,CAAC,QAAgC,EAAE,EAAE;IAC1D,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,OAAO,IAAA,qBAAe,EAAC,SAAG,CAAC,GAAG,EAAE,cAAQ,CAAC,SAAS,CAAC,CAAC;KACrD;IACD,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACzB,OAAO,IAAA,qBAAe,EAAC,SAAG,CAAC,GAAG,EAAE,cAAQ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,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,mBAAmB,EAAE,YAAY,IAAI,IAAI,CAAC;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,kBAAG,CAAC,KAAK,CACP,gEAAgE,EAChE,CAAC,CACF,CAAC;QACF,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AApCD,wCAoCC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,KAAa,EACb,SAAiB;IAEjB,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;AACnD,CAAC;AALD,sDAKC","sourcesContent":["import log from 'loglevel';\n\nimport { Env, Platform, getEnvUrls, getOidcClientId } from '../../shared/env';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nconst AUTH_ENDPOINT: string = ENV_URLS.authApiUrl;\nexport const AUTH_NONCE_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/nonce`;\nexport const AUTH_LOGIN_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/srp/login`;\n\nconst OIDC_ENDPOINT: string = ENV_URLS.oidcApiUrl || '';\nexport const OIDC_TOKENS_ENDPOINT = `${OIDC_ENDPOINT}/oauth2/token`;\nconst OIDC_CLIENT_ID = (platform: 'mobile' | 'extension') => {\n if (platform === 'extension') {\n return getOidcClientId(Env.PRD, Platform.EXTENSION);\n }\n if (platform === 'mobile') {\n return getOidcClientId(Env.PRD, Platform.MOBILE);\n }\n\n throw new Error(`Unsupported platform - ${platform as string}`);\n};\nconst OIDC_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n\nexport type NonceResponse = {\n nonce: string;\n};\n\n/**\n * Auth Service - Get Nonce. Used for the initial JWTBearer flow\n *\n * @param publicKey - public key to associate a nonce with\n * @returns the nonce or null if failed\n */\nexport async function getNonce(publicKey: string): Promise<string | null> {\n const nonceUrl = new URL(AUTH_NONCE_ENDPOINT);\n nonceUrl.searchParams.set('identifier', publicKey);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n log.error(\n `authentication-controller/services: unable to get nonce - HTTP ${nonceResponse.status}`,\n );\n return null;\n }\n\n const nonceJson: NonceResponse = await nonceResponse.json();\n return nonceJson?.nonce ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to get nonce', e);\n return null;\n }\n}\n\n/**\n * The Login API Server Response Shape\n */\nexport type LoginResponse = {\n token: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: string;\n /**\n * Contains anonymous information about the logged in profile.\n *\n * @property identifier_id - a deterministic unique identifier on the method used to sign in\n * @property profile_id - a unique id for a given profile\n * @property metametrics_id - an anonymous server id\n */\n profile: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n profile_id: string;\n };\n};\n\ntype ClientMetaMetrics = {\n metametricsId: string;\n agent: 'extension' | 'mobile';\n};\n\n/**\n * Auth Service - Login. Will perform login with a given signature and will return a single use JWT Token.\n *\n * @param rawMessage - the original message before signing\n * @param signature - the signed message\n * @param clientMetaMetrics - optional client metametrics id (to associate on backend)\n * @returns The Login Response\n */\nexport async function login(\n rawMessage: string,\n signature: string,\n clientMetaMetrics: ClientMetaMetrics,\n): Promise<LoginResponse | null> {\n try {\n const response = await fetch(AUTH_LOGIN_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n signature,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: rawMessage,\n metametrics: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n metametrics_id: clientMetaMetrics.metametricsId,\n agent: clientMetaMetrics.agent,\n },\n }),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to login - HTTP ${response.status}`,\n );\n return null;\n }\n\n const loginResponse: LoginResponse = await response.json();\n return loginResponse ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to login', e);\n return null;\n }\n}\n\n/**\n * The Auth API Token Response Shape\n */\nexport type OAuthTokenResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n access_token: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: number;\n};\n\n/**\n * OIDC Service - Access Token. Trades the Auth Token for an access token (to be used for other authenticated endpoints)\n * NOTE - the access token is short lived, which means it is best practice to validate session before calling authenticated endpoints\n *\n * @param jwtToken - the JWT Auth Token, received from `/login`\n * @param platform - the OIDC platform to retrieve access token\n * @returns JWT Access token to store and use on authorized endpoints.\n */\nexport async function getAccessToken(\n jwtToken: string,\n platform: ClientMetaMetrics['agent'],\n): Promise<string | null> {\n const headers = new Headers({\n 'Content-Type': 'application/x-www-form-urlencoded',\n });\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', OIDC_GRANT_TYPE);\n urlEncodedBody.append('client_id', OIDC_CLIENT_ID(platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKENS_ENDPOINT, {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to get access token - HTTP ${response.status}`,\n );\n return null;\n }\n\n const accessTokenResponse: OAuthTokenResponse = await response.json();\n return accessTokenResponse?.access_token ?? null;\n } catch (e) {\n log.error(\n 'authentication-controller/services: unable to get access token',\n e,\n );\n return null;\n }\n}\n\n/**\n * Utility to create the raw login message for the JWT bearer flow (via SRP)\n *\n * @param nonce - nonce received from `/nonce` endpoint\n * @param publicKey - public key used to retrieve nonce and for message signing\n * @returns Raw Message which will be used for signing & logging in.\n */\nexport function createLoginRawMessage(\n nonce: string,\n publicKey: string,\n): `metamask:${string}:${string}` {\n return `metamask:${nonce}:${publicKey}` as const;\n}\n"]}
1
+ {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAE3B,8CAA8E;AAE9E,MAAM,QAAQ,GAAG,IAAA,gBAAU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IAC7C,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IACrD,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7D,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAE7C,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,4BAAoB,EAAE;YACjD,MAAM,EAAE,MAAM;YACd,OAAO;YACP,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE;SAChC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,kBAAG,CAAC,KAAK,CACP,yEAAyE,QAAQ,CAAC,MAAM,EAAE,CAC3F,CAAC;YACF,OAAO,IAAI,CAAC;SACb;QAED,MAAM,mBAAmB,GAAuB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,mBAAmB,EAAE,YAAY,IAAI,IAAI,CAAC;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,kBAAG,CAAC,KAAK,CACP,gEAAgE,EAChE,CAAC,CACF,CAAC;QACF,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AApCD,wCAoCC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,KAAa,EACb,SAAiB;IAEjB,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;AACnD,CAAC;AALD,sDAKC","sourcesContent":["import log from 'loglevel';\n\nimport { Env, Platform, getEnvUrls, getOidcClientId } from '../../shared/env';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nconst AUTH_ENDPOINT: string = ENV_URLS.authApiUrl;\nexport const AUTH_NONCE_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/nonce`;\nexport const AUTH_LOGIN_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/srp/login`;\n\nconst OIDC_ENDPOINT: string = ENV_URLS.oidcApiUrl || '';\nexport const OIDC_TOKENS_ENDPOINT = `${OIDC_ENDPOINT}/oauth2/token`;\nconst OIDC_CLIENT_ID = (platform: 'mobile' | 'extension') => {\n if (platform === 'extension') {\n return getOidcClientId(Env.PRD, Platform.EXTENSION);\n }\n if (platform === 'mobile') {\n return getOidcClientId(Env.PRD, Platform.MOBILE);\n }\n\n throw new Error(`Unsupported platform - ${platform as string}`);\n};\nconst OIDC_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n\nexport type NonceResponse = {\n nonce: string;\n};\n\n/**\n * Auth Service - Get Nonce. Used for the initial JWTBearer flow\n *\n * @param publicKey - public key to associate a nonce with\n * @returns the nonce or null if failed\n */\nexport async function getNonce(publicKey: string): Promise<string | null> {\n const nonceUrl = new URL(AUTH_NONCE_ENDPOINT);\n nonceUrl.searchParams.set('identifier', publicKey);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n log.error(\n `authentication-controller/services: unable to get nonce - HTTP ${nonceResponse.status}`,\n );\n return null;\n }\n\n const nonceJson: NonceResponse = await nonceResponse.json();\n return nonceJson?.nonce ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to get nonce', e);\n return null;\n }\n}\n\n/**\n * The Login API Server Response Shape\n */\nexport type LoginResponse = {\n token: string;\n\n expires_in: string;\n /**\n * Contains anonymous information about the logged in profile.\n *\n * identifier_id - a deterministic unique identifier on the method used to sign in\n *\n * profile_id - a unique id for a given profile\n *\n * metametrics_id - an anonymous server id\n */\n profile: {\n identifier_id: string;\n\n profile_id: string;\n };\n};\n\ntype ClientMetaMetrics = {\n metametricsId: string;\n agent: 'extension' | 'mobile';\n};\n\n/**\n * Auth Service - Login. Will perform login with a given signature and will return a single use JWT Token.\n *\n * @param rawMessage - the original message before signing\n * @param signature - the signed message\n * @param clientMetaMetrics - optional client metametrics id (to associate on backend)\n * @returns The Login Response\n */\nexport async function login(\n rawMessage: string,\n signature: string,\n clientMetaMetrics: ClientMetaMetrics,\n): Promise<LoginResponse | null> {\n try {\n const response = await fetch(AUTH_LOGIN_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n signature,\n\n raw_message: rawMessage,\n metametrics: {\n metametrics_id: clientMetaMetrics.metametricsId,\n agent: clientMetaMetrics.agent,\n },\n }),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to login - HTTP ${response.status}`,\n );\n return null;\n }\n\n const loginResponse: LoginResponse = await response.json();\n return loginResponse ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to login', e);\n return null;\n }\n}\n\n/**\n * The Auth API Token Response Shape\n */\nexport type OAuthTokenResponse = {\n access_token: string;\n\n expires_in: number;\n};\n\n/**\n * OIDC Service - Access Token. Trades the Auth Token for an access token (to be used for other authenticated endpoints)\n * NOTE - the access token is short lived, which means it is best practice to validate session before calling authenticated endpoints\n *\n * @param jwtToken - the JWT Auth Token, received from `/login`\n * @param platform - the OIDC platform to retrieve access token\n * @returns JWT Access token to store and use on authorized endpoints.\n */\nexport async function getAccessToken(\n jwtToken: string,\n platform: ClientMetaMetrics['agent'],\n): Promise<string | null> {\n const headers = new Headers({\n 'Content-Type': 'application/x-www-form-urlencoded',\n });\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', OIDC_GRANT_TYPE);\n urlEncodedBody.append('client_id', OIDC_CLIENT_ID(platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKENS_ENDPOINT, {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to get access token - HTTP ${response.status}`,\n );\n return null;\n }\n\n const accessTokenResponse: OAuthTokenResponse = await response.json();\n return accessTokenResponse?.access_token ?? null;\n } catch (e) {\n log.error(\n 'authentication-controller/services: unable to get access token',\n e,\n );\n return null;\n }\n}\n\n/**\n * Utility to create the raw login message for the JWT bearer flow (via SRP)\n *\n * @param nonce - nonce received from `/nonce` endpoint\n * @param publicKey - public key used to retrieve nonce and for message signing\n * @returns Raw Message which will be used for signing & logging in.\n */\nexport function createLoginRawMessage(\n nonce: string,\n publicKey: string,\n): `metamask:${string}:${string}` {\n return `metamask:${nonce}:${publicKey}` as const;\n}\n"]}
@@ -20,9 +20,11 @@ export type LoginResponse = {
20
20
  /**
21
21
  * Contains anonymous information about the logged in profile.
22
22
  *
23
- * @property identifier_id - a deterministic unique identifier on the method used to sign in
24
- * @property profile_id - a unique id for a given profile
25
- * @property metametrics_id - an anonymous server id
23
+ * identifier_id - a deterministic unique identifier on the method used to sign in
24
+ *
25
+ * profile_id - a unique id for a given profile
26
+ *
27
+ * metametrics_id - an anonymous server id
26
28
  */
27
29
  profile: {
28
30
  identifier_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,QAAkC,CAAC;AACnE,eAAO,MAAM,mBAAmB,QAAsC,CAAC;AAGvE,eAAO,MAAM,oBAAoB,QAAkC,CAAC;AAapE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxE;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,EAAE;QAEP,aAAa,EAAE,MAAM,CAAC;QAEtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,KAAK,CACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,iBAAiB,GACnC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAgC/B;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAE/B,YAAY,EAAE,MAAM,CAAC;IAErB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACnC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiCxB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,YAAY,MAAM,IAAI,MAAM,EAAE,CAEhC"}
1
+ {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,QAAkC,CAAC;AACnE,eAAO,MAAM,mBAAmB,QAAsC,CAAC;AAGvE,eAAO,MAAM,oBAAoB,QAAkC,CAAC;AAapE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxE;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;OAQG;IACH,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QAEtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,KAAK,CACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,iBAAiB,GACnC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CA+B/B;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC;IAErB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACnC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiCxB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,YAAY,MAAM,IAAI,MAAM,EAAE,CAEhC"}
@@ -20,9 +20,11 @@ export type LoginResponse = {
20
20
  /**
21
21
  * Contains anonymous information about the logged in profile.
22
22
  *
23
- * @property identifier_id - a deterministic unique identifier on the method used to sign in
24
- * @property profile_id - a unique id for a given profile
25
- * @property metametrics_id - an anonymous server id
23
+ * identifier_id - a deterministic unique identifier on the method used to sign in
24
+ *
25
+ * profile_id - a unique id for a given profile
26
+ *
27
+ * metametrics_id - an anonymous server id
26
28
  */
27
29
  profile: {
28
30
  identifier_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,QAAkC,CAAC;AACnE,eAAO,MAAM,mBAAmB,QAAsC,CAAC;AAGvE,eAAO,MAAM,oBAAoB,QAAkC,CAAC;AAapE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxE;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,EAAE;QAEP,aAAa,EAAE,MAAM,CAAC;QAEtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,KAAK,CACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,iBAAiB,GACnC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAgC/B;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAE/B,YAAY,EAAE,MAAM,CAAC;IAErB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACnC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiCxB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,YAAY,MAAM,IAAI,MAAM,EAAE,CAEhC"}
1
+ {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,QAAkC,CAAC;AACnE,eAAO,MAAM,mBAAmB,QAAsC,CAAC;AAGvE,eAAO,MAAM,oBAAoB,QAAkC,CAAC;AAapE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxE;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IAEd,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;OAQG;IACH,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QAEtB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,KAAK,CACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,iBAAiB,GACnC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CA+B/B;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC;IAErB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACnC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiCxB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,YAAY,MAAM,IAAI,MAAM,EAAE,CAEhC"}
@@ -63,10 +63,8 @@ export async function login(rawMessage, signature, clientMetaMetrics) {
63
63
  },
64
64
  body: JSON.stringify({
65
65
  signature,
66
- // eslint-disable-next-line @typescript-eslint/naming-convention
67
66
  raw_message: rawMessage,
68
67
  metametrics: {
69
- // eslint-disable-next-line @typescript-eslint/naming-convention
70
68
  metametrics_id: clientMetaMetrics.metametricsId,
71
69
  agent: clientMetaMetrics.agent,
72
70
  },
@@ -1 +1 @@
1
- {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,6BAAyB;AAE9E,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAErC,MAAM,aAAa,GAAW,QAAQ,CAAC,UAAU,CAAC;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,aAAa,eAAe,CAAC;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,aAAa,mBAAmB,CAAC;AAEvE,MAAM,aAAa,GAAW,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,aAAa,eAAe,CAAC;AACpE,MAAM,cAAc,GAAG,CAAC,QAAgC,EAAE,EAAE;IAC1D,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;KACrD;IACD,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACzB,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;KAClD;IAED,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAkB,EAAE,CAAC,CAAC;AAClE,CAAC,CAAC;AACF,MAAM,eAAe,GAAG,6CAA6C,CAAC;AAMtE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,SAAiB;IAC9C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC9C,QAAQ,CAAC,YAAY,CAAC,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AAC;AACnD,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport { Env, Platform, getEnvUrls, getOidcClientId } from '../../shared/env';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nconst AUTH_ENDPOINT: string = ENV_URLS.authApiUrl;\nexport const AUTH_NONCE_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/nonce`;\nexport const AUTH_LOGIN_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/srp/login`;\n\nconst OIDC_ENDPOINT: string = ENV_URLS.oidcApiUrl || '';\nexport const OIDC_TOKENS_ENDPOINT = `${OIDC_ENDPOINT}/oauth2/token`;\nconst OIDC_CLIENT_ID = (platform: 'mobile' | 'extension') => {\n if (platform === 'extension') {\n return getOidcClientId(Env.PRD, Platform.EXTENSION);\n }\n if (platform === 'mobile') {\n return getOidcClientId(Env.PRD, Platform.MOBILE);\n }\n\n throw new Error(`Unsupported platform - ${platform as string}`);\n};\nconst OIDC_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n\nexport type NonceResponse = {\n nonce: string;\n};\n\n/**\n * Auth Service - Get Nonce. Used for the initial JWTBearer flow\n *\n * @param publicKey - public key to associate a nonce with\n * @returns the nonce or null if failed\n */\nexport async function getNonce(publicKey: string): Promise<string | null> {\n const nonceUrl = new URL(AUTH_NONCE_ENDPOINT);\n nonceUrl.searchParams.set('identifier', publicKey);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n log.error(\n `authentication-controller/services: unable to get nonce - HTTP ${nonceResponse.status}`,\n );\n return null;\n }\n\n const nonceJson: NonceResponse = await nonceResponse.json();\n return nonceJson?.nonce ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to get nonce', e);\n return null;\n }\n}\n\n/**\n * The Login API Server Response Shape\n */\nexport type LoginResponse = {\n token: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: string;\n /**\n * Contains anonymous information about the logged in profile.\n *\n * @property identifier_id - a deterministic unique identifier on the method used to sign in\n * @property profile_id - a unique id for a given profile\n * @property metametrics_id - an anonymous server id\n */\n profile: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n profile_id: string;\n };\n};\n\ntype ClientMetaMetrics = {\n metametricsId: string;\n agent: 'extension' | 'mobile';\n};\n\n/**\n * Auth Service - Login. Will perform login with a given signature and will return a single use JWT Token.\n *\n * @param rawMessage - the original message before signing\n * @param signature - the signed message\n * @param clientMetaMetrics - optional client metametrics id (to associate on backend)\n * @returns The Login Response\n */\nexport async function login(\n rawMessage: string,\n signature: string,\n clientMetaMetrics: ClientMetaMetrics,\n): Promise<LoginResponse | null> {\n try {\n const response = await fetch(AUTH_LOGIN_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n signature,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: rawMessage,\n metametrics: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n metametrics_id: clientMetaMetrics.metametricsId,\n agent: clientMetaMetrics.agent,\n },\n }),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to login - HTTP ${response.status}`,\n );\n return null;\n }\n\n const loginResponse: LoginResponse = await response.json();\n return loginResponse ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to login', e);\n return null;\n }\n}\n\n/**\n * The Auth API Token Response Shape\n */\nexport type OAuthTokenResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n access_token: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: number;\n};\n\n/**\n * OIDC Service - Access Token. Trades the Auth Token for an access token (to be used for other authenticated endpoints)\n * NOTE - the access token is short lived, which means it is best practice to validate session before calling authenticated endpoints\n *\n * @param jwtToken - the JWT Auth Token, received from `/login`\n * @param platform - the OIDC platform to retrieve access token\n * @returns JWT Access token to store and use on authorized endpoints.\n */\nexport async function getAccessToken(\n jwtToken: string,\n platform: ClientMetaMetrics['agent'],\n): Promise<string | null> {\n const headers = new Headers({\n 'Content-Type': 'application/x-www-form-urlencoded',\n });\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', OIDC_GRANT_TYPE);\n urlEncodedBody.append('client_id', OIDC_CLIENT_ID(platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKENS_ENDPOINT, {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to get access token - HTTP ${response.status}`,\n );\n return null;\n }\n\n const accessTokenResponse: OAuthTokenResponse = await response.json();\n return accessTokenResponse?.access_token ?? null;\n } catch (e) {\n log.error(\n 'authentication-controller/services: unable to get access token',\n e,\n );\n return null;\n }\n}\n\n/**\n * Utility to create the raw login message for the JWT bearer flow (via SRP)\n *\n * @param nonce - nonce received from `/nonce` endpoint\n * @param publicKey - public key used to retrieve nonce and for message signing\n * @returns Raw Message which will be used for signing & logging in.\n */\nexport function createLoginRawMessage(\n nonce: string,\n publicKey: string,\n): `metamask:${string}:${string}` {\n return `metamask:${nonce}:${publicKey}` as const;\n}\n"]}
1
+ {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/services.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,6BAAyB;AAE9E,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAErC,MAAM,aAAa,GAAW,QAAQ,CAAC,UAAU,CAAC;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,aAAa,eAAe,CAAC;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,aAAa,mBAAmB,CAAC;AAEvE,MAAM,aAAa,GAAW,QAAQ,CAAC,UAAU,IAAI,EAAE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AK,CAAC,oBAAoB,EAAE;YACjD,MAAM,EAAE,MAAM;YACd,OAAO;YACP,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE;SAChC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,GAAG,CAAC,KAAK,CACP,yEAAyE,QAAQ,CAAC,MAAM,EAAE,CAC3F,CAAC;YACF,OAAO,IAAI,CAAC;SACb;QAED,MAAM,mBAAmB,GAAuB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,mBAAmB,EAAE,YAAY,IAAI,IAAI,CAAC;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,CAAC,KAAK,CACP,gEAAgE,EAChE,CAAC,CACF,CAAC;QACF,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,SAAiB;IAEjB,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;AACnD,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport { Env, Platform, getEnvUrls, getOidcClientId } from '../../shared/env';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nconst AUTH_ENDPOINT: string = ENV_URLS.authApiUrl;\nexport const AUTH_NONCE_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/nonce`;\nexport const AUTH_LOGIN_ENDPOINT = `${AUTH_ENDPOINT}/api/v2/srp/login`;\n\nconst OIDC_ENDPOINT: string = ENV_URLS.oidcApiUrl || '';\nexport const OIDC_TOKENS_ENDPOINT = `${OIDC_ENDPOINT}/oauth2/token`;\nconst OIDC_CLIENT_ID = (platform: 'mobile' | 'extension') => {\n if (platform === 'extension') {\n return getOidcClientId(Env.PRD, Platform.EXTENSION);\n }\n if (platform === 'mobile') {\n return getOidcClientId(Env.PRD, Platform.MOBILE);\n }\n\n throw new Error(`Unsupported platform - ${platform as string}`);\n};\nconst OIDC_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n\nexport type NonceResponse = {\n nonce: string;\n};\n\n/**\n * Auth Service - Get Nonce. Used for the initial JWTBearer flow\n *\n * @param publicKey - public key to associate a nonce with\n * @returns the nonce or null if failed\n */\nexport async function getNonce(publicKey: string): Promise<string | null> {\n const nonceUrl = new URL(AUTH_NONCE_ENDPOINT);\n nonceUrl.searchParams.set('identifier', publicKey);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n log.error(\n `authentication-controller/services: unable to get nonce - HTTP ${nonceResponse.status}`,\n );\n return null;\n }\n\n const nonceJson: NonceResponse = await nonceResponse.json();\n return nonceJson?.nonce ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to get nonce', e);\n return null;\n }\n}\n\n/**\n * The Login API Server Response Shape\n */\nexport type LoginResponse = {\n token: string;\n\n expires_in: string;\n /**\n * Contains anonymous information about the logged in profile.\n *\n * identifier_id - a deterministic unique identifier on the method used to sign in\n *\n * profile_id - a unique id for a given profile\n *\n * metametrics_id - an anonymous server id\n */\n profile: {\n identifier_id: string;\n\n profile_id: string;\n };\n};\n\ntype ClientMetaMetrics = {\n metametricsId: string;\n agent: 'extension' | 'mobile';\n};\n\n/**\n * Auth Service - Login. Will perform login with a given signature and will return a single use JWT Token.\n *\n * @param rawMessage - the original message before signing\n * @param signature - the signed message\n * @param clientMetaMetrics - optional client metametrics id (to associate on backend)\n * @returns The Login Response\n */\nexport async function login(\n rawMessage: string,\n signature: string,\n clientMetaMetrics: ClientMetaMetrics,\n): Promise<LoginResponse | null> {\n try {\n const response = await fetch(AUTH_LOGIN_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n signature,\n\n raw_message: rawMessage,\n metametrics: {\n metametrics_id: clientMetaMetrics.metametricsId,\n agent: clientMetaMetrics.agent,\n },\n }),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to login - HTTP ${response.status}`,\n );\n return null;\n }\n\n const loginResponse: LoginResponse = await response.json();\n return loginResponse ?? null;\n } catch (e) {\n log.error('authentication-controller/services: unable to login', e);\n return null;\n }\n}\n\n/**\n * The Auth API Token Response Shape\n */\nexport type OAuthTokenResponse = {\n access_token: string;\n\n expires_in: number;\n};\n\n/**\n * OIDC Service - Access Token. Trades the Auth Token for an access token (to be used for other authenticated endpoints)\n * NOTE - the access token is short lived, which means it is best practice to validate session before calling authenticated endpoints\n *\n * @param jwtToken - the JWT Auth Token, received from `/login`\n * @param platform - the OIDC platform to retrieve access token\n * @returns JWT Access token to store and use on authorized endpoints.\n */\nexport async function getAccessToken(\n jwtToken: string,\n platform: ClientMetaMetrics['agent'],\n): Promise<string | null> {\n const headers = new Headers({\n 'Content-Type': 'application/x-www-form-urlencoded',\n });\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', OIDC_GRANT_TYPE);\n urlEncodedBody.append('client_id', OIDC_CLIENT_ID(platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKENS_ENDPOINT, {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n log.error(\n `authentication-controller/services: unable to get access token - HTTP ${response.status}`,\n );\n return null;\n }\n\n const accessTokenResponse: OAuthTokenResponse = await response.json();\n return accessTokenResponse?.access_token ?? null;\n } catch (e) {\n log.error(\n 'authentication-controller/services: unable to get access token',\n e,\n );\n return null;\n }\n}\n\n/**\n * Utility to create the raw login message for the JWT bearer flow (via SRP)\n *\n * @param nonce - nonce received from `/nonce` endpoint\n * @param publicKey - public key used to retrieve nonce and for message signing\n * @returns Raw Message which will be used for signing & logging in.\n */\nexport function createLoginRawMessage(\n nonce: string,\n publicKey: string,\n): `metamask:${string}:${string}` {\n return `metamask:${nonce}:${publicKey}` as const;\n}\n"]}