@metamask-previews/profile-sync-controller 29.0.0-preview-3866c0ff1 → 29.0.0-preview-e3275932a

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 (548) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs +7 -0
  3. package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs.map +1 -0
  4. package/dist/controllers/authentication/{AuthenticationController-method-action-types.d.ts → AuthenticationController-method-action-types.d.cts} +2 -2
  5. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.cts.map +1 -0
  6. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts +102 -0
  7. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts.map +1 -0
  8. package/dist/controllers/authentication/{AuthenticationController-method-action-types.js → AuthenticationController-method-action-types.mjs} +1 -1
  9. package/dist/controllers/authentication/AuthenticationController-method-action-types.mjs.map +1 -0
  10. package/dist/controllers/authentication/AuthenticationController.cjs +489 -0
  11. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -0
  12. package/dist/controllers/authentication/{AuthenticationController.d.ts → AuthenticationController.d.cts} +10 -10
  13. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -0
  14. package/dist/controllers/authentication/AuthenticationController.d.mts +130 -0
  15. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -0
  16. package/dist/controllers/authentication/AuthenticationController.mjs +485 -0
  17. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -0
  18. package/dist/controllers/authentication/index.cjs +35 -0
  19. package/dist/controllers/authentication/index.cjs.map +1 -0
  20. package/dist/controllers/authentication/{index.d.ts → index.d.cts} +5 -5
  21. package/dist/controllers/authentication/index.d.cts.map +1 -0
  22. package/dist/controllers/authentication/index.d.mts +7 -0
  23. package/dist/controllers/authentication/index.d.mts.map +1 -0
  24. package/dist/controllers/authentication/index.mjs +6 -0
  25. package/dist/controllers/authentication/index.mjs.map +1 -0
  26. package/dist/controllers/authentication/mocks/index.cjs +18 -0
  27. package/dist/controllers/authentication/mocks/index.cjs.map +1 -0
  28. package/dist/controllers/authentication/mocks/index.d.cts +2 -0
  29. package/dist/controllers/authentication/mocks/index.d.cts.map +1 -0
  30. package/dist/controllers/authentication/mocks/index.d.mts +2 -0
  31. package/dist/controllers/authentication/mocks/index.d.mts.map +1 -0
  32. package/dist/controllers/authentication/mocks/index.mjs +2 -0
  33. package/dist/controllers/authentication/mocks/index.mjs.map +1 -0
  34. package/dist/controllers/authentication/mocks/mockResponses.cjs +126 -0
  35. package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -0
  36. package/dist/controllers/authentication/mocks/{mockResponses.d.ts → mockResponses.d.cts} +1 -1
  37. package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -0
  38. package/dist/controllers/authentication/mocks/mockResponses.d.mts +58 -0
  39. package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -0
  40. package/dist/controllers/authentication/mocks/{mockResponses.js → mockResponses.mjs} +2 -2
  41. package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -0
  42. package/dist/controllers/index.cjs +29 -0
  43. package/dist/controllers/index.cjs.map +1 -0
  44. package/dist/controllers/index.d.cts +3 -0
  45. package/dist/controllers/index.d.cts.map +1 -0
  46. package/dist/controllers/index.d.mts +3 -0
  47. package/dist/controllers/index.d.mts.map +1 -0
  48. package/dist/controllers/index.mjs +3 -0
  49. package/dist/controllers/index.mjs.map +1 -0
  50. package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs +7 -0
  51. package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs.map +1 -0
  52. package/dist/controllers/user-storage/{UserStorageController-method-action-types.d.ts → UserStorageController-method-action-types.d.cts} +2 -2
  53. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.cts.map +1 -0
  54. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts +137 -0
  55. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts.map +1 -0
  56. package/dist/controllers/user-storage/{UserStorageController-method-action-types.js → UserStorageController-method-action-types.mjs} +1 -1
  57. package/dist/controllers/user-storage/UserStorageController-method-action-types.mjs.map +1 -0
  58. package/dist/controllers/user-storage/UserStorageController.cjs +412 -0
  59. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -0
  60. package/dist/controllers/user-storage/{UserStorageController.d.ts → UserStorageController.d.cts} +14 -14
  61. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -0
  62. package/dist/controllers/user-storage/UserStorageController.d.mts +182 -0
  63. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -0
  64. package/dist/controllers/user-storage/UserStorageController.mjs +408 -0
  65. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -0
  66. package/dist/controllers/user-storage/constants.cjs +19 -0
  67. package/dist/controllers/user-storage/constants.cjs.map +1 -0
  68. package/dist/controllers/user-storage/constants.d.cts +15 -0
  69. package/dist/controllers/user-storage/constants.d.cts.map +1 -0
  70. package/dist/controllers/user-storage/constants.d.mts +15 -0
  71. package/dist/controllers/user-storage/constants.d.mts.map +1 -0
  72. package/dist/controllers/user-storage/{constants.js → constants.mjs} +1 -1
  73. package/dist/controllers/user-storage/constants.mjs.map +1 -0
  74. package/dist/controllers/user-storage/contact-syncing/constants.cjs +12 -0
  75. package/dist/controllers/user-storage/contact-syncing/constants.cjs.map +1 -0
  76. package/dist/controllers/user-storage/contact-syncing/{constants.d.ts → constants.d.cts} +1 -1
  77. package/dist/controllers/user-storage/contact-syncing/constants.d.cts.map +1 -0
  78. package/dist/controllers/user-storage/contact-syncing/constants.d.mts +9 -0
  79. package/dist/controllers/user-storage/contact-syncing/constants.d.mts.map +1 -0
  80. package/dist/controllers/user-storage/contact-syncing/{constants.js → constants.mjs} +1 -1
  81. package/dist/controllers/user-storage/contact-syncing/constants.mjs.map +1 -0
  82. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +346 -0
  83. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -0
  84. package/dist/controllers/user-storage/contact-syncing/{controller-integration.d.ts → controller-integration.d.cts} +3 -3
  85. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -0
  86. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +47 -0
  87. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -0
  88. package/dist/controllers/user-storage/contact-syncing/{controller-integration.js → controller-integration.mjs} +6 -6
  89. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -0
  90. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs +50 -0
  91. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs.map +1 -0
  92. package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.d.ts → setup-subscriptions.d.cts} +2 -2
  93. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.cts.map +1 -0
  94. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts +8 -0
  95. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts.map +1 -0
  96. package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.js → setup-subscriptions.mjs} +4 -4
  97. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.mjs.map +1 -0
  98. package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs +23 -0
  99. package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs.map +1 -0
  100. package/dist/controllers/user-storage/contact-syncing/{sync-utils.d.ts → sync-utils.d.cts} +2 -2
  101. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.cts.map +1 -0
  102. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts +9 -0
  103. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts.map +1 -0
  104. package/dist/controllers/user-storage/contact-syncing/{sync-utils.js → sync-utils.mjs} +1 -1
  105. package/dist/controllers/user-storage/contact-syncing/sync-utils.mjs.map +1 -0
  106. package/dist/controllers/user-storage/contact-syncing/types.cjs +3 -0
  107. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -0
  108. package/dist/controllers/user-storage/contact-syncing/{types.d.ts → types.d.cts} +6 -6
  109. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -0
  110. package/dist/controllers/user-storage/contact-syncing/types.d.mts +37 -0
  111. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -0
  112. package/dist/controllers/user-storage/contact-syncing/types.mjs +2 -0
  113. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -0
  114. package/dist/controllers/user-storage/contact-syncing/utils.cjs +64 -0
  115. package/dist/controllers/user-storage/contact-syncing/utils.cjs.map +1 -0
  116. package/dist/controllers/user-storage/contact-syncing/{utils.d.ts → utils.d.cts} +3 -3
  117. package/dist/controllers/user-storage/contact-syncing/utils.d.cts.map +1 -0
  118. package/dist/controllers/user-storage/contact-syncing/utils.d.mts +36 -0
  119. package/dist/controllers/user-storage/contact-syncing/utils.d.mts.map +1 -0
  120. package/dist/controllers/user-storage/contact-syncing/{utils.js → utils.mjs} +2 -2
  121. package/dist/controllers/user-storage/contact-syncing/utils.mjs.map +1 -0
  122. package/dist/controllers/user-storage/index.cjs +38 -0
  123. package/dist/controllers/user-storage/index.cjs.map +1 -0
  124. package/dist/controllers/user-storage/{index.d.ts → index.d.cts} +8 -8
  125. package/dist/controllers/user-storage/index.d.cts.map +1 -0
  126. package/dist/controllers/user-storage/index.d.mts +10 -0
  127. package/dist/controllers/user-storage/index.d.mts.map +1 -0
  128. package/dist/controllers/user-storage/index.mjs +9 -0
  129. package/dist/controllers/user-storage/index.mjs.map +1 -0
  130. package/dist/controllers/user-storage/mocks/index.cjs +19 -0
  131. package/dist/controllers/user-storage/mocks/index.cjs.map +1 -0
  132. package/dist/controllers/user-storage/mocks/index.d.cts +3 -0
  133. package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -0
  134. package/dist/controllers/user-storage/mocks/index.d.mts +3 -0
  135. package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -0
  136. package/dist/controllers/user-storage/mocks/index.mjs +3 -0
  137. package/dist/controllers/user-storage/mocks/index.mjs.map +1 -0
  138. package/dist/controllers/user-storage/mocks/mockResponses.cjs +113 -0
  139. package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -0
  140. package/dist/controllers/user-storage/mocks/{mockResponses.d.ts → mockResponses.d.cts} +3 -3
  141. package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -0
  142. package/dist/controllers/user-storage/mocks/mockResponses.d.mts +66 -0
  143. package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -0
  144. package/dist/controllers/user-storage/mocks/{mockResponses.js → mockResponses.mjs} +4 -4
  145. package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -0
  146. package/dist/controllers/user-storage/mocks/mockStorage.cjs +36 -0
  147. package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -0
  148. package/dist/controllers/user-storage/mocks/{mockStorage.d.ts → mockStorage.d.cts} +1 -1
  149. package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -0
  150. package/dist/controllers/user-storage/mocks/mockStorage.d.mts +5 -0
  151. package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -0
  152. package/dist/controllers/user-storage/mocks/{mockStorage.js → mockStorage.mjs} +3 -3
  153. package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -0
  154. package/dist/controllers/user-storage/types.cjs +3 -0
  155. package/dist/controllers/user-storage/types.cjs.map +1 -0
  156. package/dist/controllers/user-storage/{types.d.ts → types.d.cts} +3 -3
  157. package/dist/controllers/user-storage/types.d.cts.map +1 -0
  158. package/dist/controllers/user-storage/types.d.mts +23 -0
  159. package/dist/controllers/user-storage/types.d.mts.map +1 -0
  160. package/dist/controllers/user-storage/types.mjs +2 -0
  161. package/dist/controllers/user-storage/types.mjs.map +1 -0
  162. package/dist/controllers/user-storage/utils.cjs +32 -0
  163. package/dist/controllers/user-storage/utils.cjs.map +1 -0
  164. package/dist/controllers/user-storage/{utils.d.ts → utils.d.cts} +1 -1
  165. package/dist/controllers/user-storage/utils.d.cts.map +1 -0
  166. package/dist/controllers/user-storage/utils.d.mts +19 -0
  167. package/dist/controllers/user-storage/utils.d.mts.map +1 -0
  168. package/dist/controllers/user-storage/{utils.js → utils.mjs} +1 -1
  169. package/dist/controllers/user-storage/utils.mjs.map +1 -0
  170. package/dist/index.cjs +30 -0
  171. package/dist/index.cjs.map +1 -0
  172. package/dist/index.d.cts +4 -0
  173. package/dist/index.d.cts.map +1 -0
  174. package/dist/index.d.mts +4 -0
  175. package/dist/index.d.mts.map +1 -0
  176. package/dist/index.mjs +4 -0
  177. package/dist/index.mjs.map +1 -0
  178. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +114 -0
  179. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -0
  180. package/dist/sdk/authentication-jwt-bearer/{flow-siwe.d.ts → flow-siwe.d.cts} +2 -2
  181. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -0
  182. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +25 -0
  183. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -0
  184. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +110 -0
  185. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -0
  186. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +290 -0
  187. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -0
  188. package/dist/sdk/authentication-jwt-bearer/{flow-srp.d.ts → flow-srp.d.cts} +5 -5
  189. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -0
  190. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +44 -0
  191. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -0
  192. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +263 -0
  193. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -0
  194. package/dist/sdk/authentication-jwt-bearer/services.cjs +400 -0
  195. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -0
  196. package/dist/sdk/authentication-jwt-bearer/{services.d.ts → services.d.cts} +5 -5
  197. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -0
  198. package/dist/sdk/authentication-jwt-bearer/services.d.mts +105 -0
  199. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -0
  200. package/dist/sdk/authentication-jwt-bearer/{services.js → services.mjs} +6 -6
  201. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -0
  202. package/dist/sdk/authentication-jwt-bearer/types.cjs +12 -0
  203. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -0
  204. package/dist/sdk/authentication-jwt-bearer/{types.d.ts → types.d.cts} +2 -2
  205. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -0
  206. package/dist/sdk/authentication-jwt-bearer/types.d.mts +114 -0
  207. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -0
  208. package/dist/sdk/authentication-jwt-bearer/{types.js → types.mjs} +1 -1
  209. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -0
  210. package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs +27 -0
  211. package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs.map +1 -0
  212. package/dist/sdk/authentication-jwt-bearer/utils/{identifier.d.ts → identifier.d.cts} +2 -2
  213. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.cts.map +1 -0
  214. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts +13 -0
  215. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts.map +1 -0
  216. package/dist/sdk/authentication-jwt-bearer/utils/{identifier.js → identifier.mjs} +2 -2
  217. package/dist/sdk/authentication-jwt-bearer/utils/identifier.mjs.map +1 -0
  218. package/dist/sdk/authentication-jwt-bearer/utils/time.cjs +17 -0
  219. package/dist/sdk/authentication-jwt-bearer/utils/time.cjs.map +1 -0
  220. package/dist/sdk/authentication-jwt-bearer/utils/{time.d.ts → time.d.cts} +1 -1
  221. package/dist/sdk/authentication-jwt-bearer/utils/time.d.cts.map +1 -0
  222. package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts +8 -0
  223. package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts.map +1 -0
  224. package/dist/sdk/authentication-jwt-bearer/utils/{time.js → time.mjs} +1 -1
  225. package/dist/sdk/authentication-jwt-bearer/utils/time.mjs.map +1 -0
  226. package/dist/sdk/authentication.cjs +132 -0
  227. package/dist/sdk/authentication.cjs.map +1 -0
  228. package/dist/sdk/{authentication.d.ts → authentication.d.cts} +9 -9
  229. package/dist/sdk/authentication.d.cts.map +1 -0
  230. package/dist/sdk/authentication.d.mts +38 -0
  231. package/dist/sdk/authentication.d.mts.map +1 -0
  232. package/dist/sdk/authentication.mjs +112 -0
  233. package/dist/sdk/authentication.mjs.map +1 -0
  234. package/dist/sdk/constants.cjs +7 -0
  235. package/dist/sdk/constants.cjs.map +1 -0
  236. package/dist/sdk/{constants.d.ts → constants.d.cts} +1 -1
  237. package/dist/sdk/constants.d.cts.map +1 -0
  238. package/dist/sdk/constants.d.mts +4 -0
  239. package/dist/sdk/constants.d.mts.map +1 -0
  240. package/dist/sdk/{constants.js → constants.mjs} +1 -1
  241. package/dist/sdk/constants.mjs.map +1 -0
  242. package/dist/sdk/errors.cjs +76 -0
  243. package/dist/sdk/errors.cjs.map +1 -0
  244. package/dist/sdk/{errors.d.ts → errors.d.cts} +1 -1
  245. package/dist/sdk/errors.d.cts.map +1 -0
  246. package/dist/sdk/errors.d.mts +34 -0
  247. package/dist/sdk/errors.d.mts.map +1 -0
  248. package/dist/sdk/{errors.js → errors.mjs} +3 -4
  249. package/dist/sdk/errors.mjs.map +1 -0
  250. package/dist/sdk/index.cjs +24 -0
  251. package/dist/sdk/index.cjs.map +1 -0
  252. package/dist/sdk/index.d.cts +8 -0
  253. package/dist/sdk/index.d.cts.map +1 -0
  254. package/dist/sdk/index.d.mts +8 -0
  255. package/dist/sdk/index.d.mts.map +1 -0
  256. package/dist/sdk/index.mjs +8 -0
  257. package/dist/sdk/index.mjs.map +1 -0
  258. package/dist/sdk/mocks/auth.cjs +82 -0
  259. package/dist/sdk/mocks/auth.cjs.map +1 -0
  260. package/dist/sdk/mocks/{auth.d.ts → auth.d.cts} +2 -2
  261. package/dist/sdk/mocks/auth.d.cts.map +1 -0
  262. package/dist/sdk/mocks/auth.d.mts +69 -0
  263. package/dist/sdk/mocks/auth.d.mts.map +1 -0
  264. package/dist/sdk/mocks/{auth.js → auth.mjs} +3 -3
  265. package/dist/sdk/mocks/auth.mjs.map +1 -0
  266. package/dist/sdk/mocks/userstorage.cjs +43 -0
  267. package/dist/sdk/mocks/userstorage.cjs.map +1 -0
  268. package/dist/sdk/mocks/{userstorage.d.ts → userstorage.d.cts} +1 -1
  269. package/dist/sdk/mocks/userstorage.d.cts.map +1 -0
  270. package/dist/sdk/mocks/userstorage.d.mts +10 -0
  271. package/dist/sdk/mocks/userstorage.d.mts.map +1 -0
  272. package/dist/sdk/mocks/{userstorage.js → userstorage.mjs} +5 -5
  273. package/dist/sdk/mocks/userstorage.mjs.map +1 -0
  274. package/dist/sdk/user-storage.cjs +386 -0
  275. package/dist/sdk/user-storage.cjs.map +1 -0
  276. package/dist/sdk/{user-storage.d.ts → user-storage.d.cts} +5 -5
  277. package/dist/sdk/user-storage.d.cts.map +1 -0
  278. package/dist/sdk/user-storage.d.mts +47 -0
  279. package/dist/sdk/user-storage.d.mts.map +1 -0
  280. package/dist/sdk/user-storage.mjs +358 -0
  281. package/dist/sdk/user-storage.mjs.map +1 -0
  282. package/dist/sdk/utils/eip-6963-metamask-provider.cjs +70 -0
  283. package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -0
  284. package/dist/sdk/utils/{eip-6963-metamask-provider.d.ts → eip-6963-metamask-provider.d.cts} +2 -2
  285. package/dist/sdk/utils/eip-6963-metamask-provider.d.cts.map +1 -0
  286. package/dist/sdk/utils/eip-6963-metamask-provider.d.mts +25 -0
  287. package/dist/sdk/utils/eip-6963-metamask-provider.d.mts.map +1 -0
  288. package/dist/sdk/utils/{eip-6963-metamask-provider.js → eip-6963-metamask-provider.mjs} +1 -1
  289. package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -0
  290. package/dist/sdk/utils/messaging-signing-snap-requests.cjs +96 -0
  291. package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -0
  292. package/dist/sdk/utils/{messaging-signing-snap-requests.d.ts → messaging-signing-snap-requests.d.cts} +2 -2
  293. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -0
  294. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +41 -0
  295. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -0
  296. package/dist/sdk/utils/{messaging-signing-snap-requests.js → messaging-signing-snap-requests.mjs} +1 -1
  297. package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -0
  298. package/dist/sdk/utils/validate-login-response.cjs +49 -0
  299. package/dist/sdk/utils/validate-login-response.cjs.map +1 -0
  300. package/dist/sdk/utils/{validate-login-response.d.ts → validate-login-response.d.cts} +2 -2
  301. package/dist/sdk/utils/validate-login-response.d.cts.map +1 -0
  302. package/dist/sdk/utils/validate-login-response.d.mts +14 -0
  303. package/dist/sdk/utils/validate-login-response.d.mts.map +1 -0
  304. package/dist/sdk/utils/{validate-login-response.js → validate-login-response.mjs} +1 -1
  305. package/dist/sdk/utils/validate-login-response.mjs.map +1 -0
  306. package/dist/sdk/utils/validate-pair-response.cjs +29 -0
  307. package/dist/sdk/utils/validate-pair-response.cjs.map +1 -0
  308. package/dist/sdk/utils/{validate-pair-response.d.ts → validate-pair-response.d.cts} +1 -1
  309. package/dist/sdk/utils/validate-pair-response.d.cts.map +1 -0
  310. package/dist/sdk/utils/validate-pair-response.d.mts +26 -0
  311. package/dist/sdk/utils/validate-pair-response.d.mts.map +1 -0
  312. package/dist/sdk/utils/{validate-pair-response.js → validate-pair-response.mjs} +1 -1
  313. package/dist/sdk/utils/validate-pair-response.mjs.map +1 -0
  314. package/dist/shared/encryption/cache.cjs +77 -0
  315. package/dist/shared/encryption/cache.cjs.map +1 -0
  316. package/dist/shared/encryption/{cache.d.ts → cache.d.cts} +1 -1
  317. package/dist/shared/encryption/cache.d.cts.map +1 -0
  318. package/dist/shared/encryption/cache.d.mts +32 -0
  319. package/dist/shared/encryption/cache.d.mts.map +1 -0
  320. package/dist/shared/encryption/{cache.js → cache.mjs} +4 -4
  321. package/dist/shared/encryption/cache.mjs.map +1 -0
  322. package/dist/shared/encryption/constants.cjs +17 -0
  323. package/dist/shared/encryption/constants.cjs.map +1 -0
  324. package/dist/shared/encryption/{constants.d.ts → constants.d.cts} +2 -2
  325. package/dist/shared/encryption/constants.d.cts.map +1 -0
  326. package/dist/shared/encryption/constants.d.mts +9 -0
  327. package/dist/shared/encryption/constants.d.mts.map +1 -0
  328. package/dist/shared/encryption/{constants.js → constants.mjs} +1 -1
  329. package/dist/shared/encryption/constants.mjs.map +1 -0
  330. package/dist/shared/encryption/encryption.cjs +209 -0
  331. package/dist/shared/encryption/encryption.cjs.map +1 -0
  332. package/dist/shared/encryption/{encryption.d.ts → encryption.d.cts} +3 -3
  333. package/dist/shared/encryption/encryption.d.cts.map +1 -0
  334. package/dist/shared/encryption/encryption.d.mts +30 -0
  335. package/dist/shared/encryption/encryption.d.mts.map +1 -0
  336. package/dist/shared/encryption/encryption.mjs +205 -0
  337. package/dist/shared/encryption/encryption.mjs.map +1 -0
  338. package/dist/shared/encryption/index.cjs +25 -0
  339. package/dist/shared/encryption/index.cjs.map +1 -0
  340. package/dist/shared/encryption/index.d.cts +5 -0
  341. package/dist/shared/encryption/index.d.cts.map +1 -0
  342. package/dist/shared/encryption/index.d.mts +5 -0
  343. package/dist/shared/encryption/index.d.mts.map +1 -0
  344. package/dist/shared/encryption/index.mjs +5 -0
  345. package/dist/shared/encryption/index.mjs.map +1 -0
  346. package/dist/shared/encryption/utils.cjs +21 -0
  347. package/dist/shared/encryption/utils.cjs.map +1 -0
  348. package/dist/shared/encryption/{utils.d.ts → utils.d.cts} +3 -3
  349. package/dist/shared/encryption/utils.d.cts.map +1 -0
  350. package/dist/shared/encryption/utils.d.mts +5 -0
  351. package/dist/shared/encryption/utils.d.mts.map +1 -0
  352. package/dist/shared/encryption/{utils.js → utils.mjs} +1 -1
  353. package/dist/shared/encryption/utils.mjs.map +1 -0
  354. package/dist/shared/env.cjs +85 -0
  355. package/dist/shared/env.cjs.map +1 -0
  356. package/dist/shared/{env.d.ts → env.d.cts} +1 -1
  357. package/dist/shared/env.d.cts.map +1 -0
  358. package/dist/shared/env.d.mts +34 -0
  359. package/dist/shared/env.d.mts.map +1 -0
  360. package/dist/shared/{env.js → env.mjs} +1 -1
  361. package/dist/shared/env.mjs.map +1 -0
  362. package/dist/shared/storage-schema.cjs +42 -0
  363. package/dist/shared/storage-schema.cjs.map +1 -0
  364. package/dist/shared/{storage-schema.d.ts → storage-schema.d.cts} +1 -1
  365. package/dist/shared/storage-schema.d.cts.map +1 -0
  366. package/dist/shared/storage-schema.d.mts +34 -0
  367. package/dist/shared/storage-schema.d.mts.map +1 -0
  368. package/dist/shared/{storage-schema.js → storage-schema.mjs} +2 -2
  369. package/dist/shared/storage-schema.mjs.map +1 -0
  370. package/dist/shared/types/encryption.cjs +3 -0
  371. package/dist/shared/types/encryption.cjs.map +1 -0
  372. package/dist/shared/types/{encryption.d.ts → encryption.d.cts} +1 -1
  373. package/dist/shared/types/encryption.d.cts.map +1 -0
  374. package/dist/shared/types/encryption.d.mts +2 -0
  375. package/dist/shared/types/encryption.d.mts.map +1 -0
  376. package/dist/shared/types/encryption.mjs +2 -0
  377. package/dist/shared/types/encryption.mjs.map +1 -0
  378. package/dist/shared/types/services.cjs +3 -0
  379. package/dist/shared/types/services.cjs.map +1 -0
  380. package/dist/shared/types/{services.d.ts → services.d.cts} +2 -2
  381. package/dist/shared/types/services.d.cts.map +1 -0
  382. package/dist/shared/types/services.d.mts +17 -0
  383. package/dist/shared/types/services.d.mts.map +1 -0
  384. package/dist/shared/types/services.mjs +2 -0
  385. package/dist/shared/types/services.mjs.map +1 -0
  386. package/dist/shared/utils/entropy-source.cjs +37 -0
  387. package/dist/shared/utils/entropy-source.cjs.map +1 -0
  388. package/dist/shared/utils/{entropy-source.d.ts → entropy-source.d.cts} +2 -2
  389. package/dist/shared/utils/entropy-source.d.cts.map +1 -0
  390. package/dist/shared/utils/entropy-source.d.mts +22 -0
  391. package/dist/shared/utils/entropy-source.d.mts.map +1 -0
  392. package/dist/shared/utils/{entropy-source.js → entropy-source.mjs} +2 -2
  393. package/dist/shared/utils/entropy-source.mjs.map +1 -0
  394. package/dist/shared/utils/event-queue.cjs +24 -0
  395. package/dist/shared/utils/event-queue.cjs.map +1 -0
  396. package/dist/shared/utils/{event-queue.d.ts → event-queue.d.cts} +1 -1
  397. package/dist/shared/utils/event-queue.d.cts.map +1 -0
  398. package/dist/shared/utils/event-queue.d.mts +6 -0
  399. package/dist/shared/utils/event-queue.d.mts.map +1 -0
  400. package/dist/shared/utils/{event-queue.js → event-queue.mjs} +4 -2
  401. package/dist/shared/utils/event-queue.mjs.map +1 -0
  402. package/dist/shared/utils/hd-keyring-seed.cjs +49 -0
  403. package/dist/shared/utils/hd-keyring-seed.cjs.map +1 -0
  404. package/dist/shared/utils/{hd-keyring-seed.d.ts → hd-keyring-seed.d.cts} +3 -3
  405. package/dist/shared/utils/hd-keyring-seed.d.cts.map +1 -0
  406. package/dist/shared/utils/hd-keyring-seed.d.mts +27 -0
  407. package/dist/shared/utils/hd-keyring-seed.d.mts.map +1 -0
  408. package/dist/shared/utils/{hd-keyring-seed.js → hd-keyring-seed.mjs} +1 -1
  409. package/dist/shared/utils/hd-keyring-seed.mjs.map +1 -0
  410. package/dist/shared/utils/message-signing.cjs +147 -0
  411. package/dist/shared/utils/message-signing.cjs.map +1 -0
  412. package/dist/shared/utils/{message-signing.d.ts → message-signing.d.cts} +1 -1
  413. package/dist/shared/utils/message-signing.d.cts.map +1 -0
  414. package/dist/shared/utils/message-signing.d.mts +73 -0
  415. package/dist/shared/utils/message-signing.d.mts.map +1 -0
  416. package/dist/shared/utils/{message-signing.js → message-signing.mjs} +7 -7
  417. package/dist/shared/utils/message-signing.mjs.map +1 -0
  418. package/package.json +56 -22
  419. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.ts.map +0 -1
  420. package/dist/controllers/authentication/AuthenticationController-method-action-types.js.map +0 -1
  421. package/dist/controllers/authentication/AuthenticationController.d.ts.map +0 -1
  422. package/dist/controllers/authentication/AuthenticationController.js +0 -536
  423. package/dist/controllers/authentication/AuthenticationController.js.map +0 -1
  424. package/dist/controllers/authentication/index.d.ts.map +0 -1
  425. package/dist/controllers/authentication/index.js +0 -6
  426. package/dist/controllers/authentication/index.js.map +0 -1
  427. package/dist/controllers/authentication/mocks/index.d.ts +0 -2
  428. package/dist/controllers/authentication/mocks/index.d.ts.map +0 -1
  429. package/dist/controllers/authentication/mocks/index.js +0 -2
  430. package/dist/controllers/authentication/mocks/index.js.map +0 -1
  431. package/dist/controllers/authentication/mocks/mockResponses.d.ts.map +0 -1
  432. package/dist/controllers/authentication/mocks/mockResponses.js.map +0 -1
  433. package/dist/controllers/index.d.ts +0 -3
  434. package/dist/controllers/index.d.ts.map +0 -1
  435. package/dist/controllers/index.js +0 -3
  436. package/dist/controllers/index.js.map +0 -1
  437. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.ts.map +0 -1
  438. package/dist/controllers/user-storage/UserStorageController-method-action-types.js.map +0 -1
  439. package/dist/controllers/user-storage/UserStorageController.d.ts.map +0 -1
  440. package/dist/controllers/user-storage/UserStorageController.js +0 -429
  441. package/dist/controllers/user-storage/UserStorageController.js.map +0 -1
  442. package/dist/controllers/user-storage/constants.d.ts +0 -15
  443. package/dist/controllers/user-storage/constants.d.ts.map +0 -1
  444. package/dist/controllers/user-storage/constants.js.map +0 -1
  445. package/dist/controllers/user-storage/contact-syncing/constants.d.ts.map +0 -1
  446. package/dist/controllers/user-storage/contact-syncing/constants.js.map +0 -1
  447. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.ts.map +0 -1
  448. package/dist/controllers/user-storage/contact-syncing/controller-integration.js.map +0 -1
  449. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.ts.map +0 -1
  450. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.js.map +0 -1
  451. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.ts.map +0 -1
  452. package/dist/controllers/user-storage/contact-syncing/sync-utils.js.map +0 -1
  453. package/dist/controllers/user-storage/contact-syncing/types.d.ts.map +0 -1
  454. package/dist/controllers/user-storage/contact-syncing/types.js +0 -2
  455. package/dist/controllers/user-storage/contact-syncing/types.js.map +0 -1
  456. package/dist/controllers/user-storage/contact-syncing/utils.d.ts.map +0 -1
  457. package/dist/controllers/user-storage/contact-syncing/utils.js.map +0 -1
  458. package/dist/controllers/user-storage/index.d.ts.map +0 -1
  459. package/dist/controllers/user-storage/index.js +0 -9
  460. package/dist/controllers/user-storage/index.js.map +0 -1
  461. package/dist/controllers/user-storage/mocks/index.d.ts +0 -3
  462. package/dist/controllers/user-storage/mocks/index.d.ts.map +0 -1
  463. package/dist/controllers/user-storage/mocks/index.js +0 -3
  464. package/dist/controllers/user-storage/mocks/index.js.map +0 -1
  465. package/dist/controllers/user-storage/mocks/mockResponses.d.ts.map +0 -1
  466. package/dist/controllers/user-storage/mocks/mockResponses.js.map +0 -1
  467. package/dist/controllers/user-storage/mocks/mockStorage.d.ts.map +0 -1
  468. package/dist/controllers/user-storage/mocks/mockStorage.js.map +0 -1
  469. package/dist/controllers/user-storage/types.d.ts.map +0 -1
  470. package/dist/controllers/user-storage/types.js +0 -2
  471. package/dist/controllers/user-storage/types.js.map +0 -1
  472. package/dist/controllers/user-storage/utils.d.ts.map +0 -1
  473. package/dist/controllers/user-storage/utils.js.map +0 -1
  474. package/dist/index.d.ts +0 -4
  475. package/dist/index.d.ts.map +0 -1
  476. package/dist/index.js +0 -4
  477. package/dist/index.js.map +0 -1
  478. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +0 -1
  479. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +0 -99
  480. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js.map +0 -1
  481. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +0 -1
  482. package/dist/sdk/authentication-jwt-bearer/flow-srp.js +0 -255
  483. package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +0 -1
  484. package/dist/sdk/authentication-jwt-bearer/services.d.ts.map +0 -1
  485. package/dist/sdk/authentication-jwt-bearer/services.js.map +0 -1
  486. package/dist/sdk/authentication-jwt-bearer/types.d.ts.map +0 -1
  487. package/dist/sdk/authentication-jwt-bearer/types.js.map +0 -1
  488. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.ts.map +0 -1
  489. package/dist/sdk/authentication-jwt-bearer/utils/identifier.js.map +0 -1
  490. package/dist/sdk/authentication-jwt-bearer/utils/time.d.ts.map +0 -1
  491. package/dist/sdk/authentication-jwt-bearer/utils/time.js.map +0 -1
  492. package/dist/sdk/authentication.d.ts.map +0 -1
  493. package/dist/sdk/authentication.js +0 -100
  494. package/dist/sdk/authentication.js.map +0 -1
  495. package/dist/sdk/constants.d.ts.map +0 -1
  496. package/dist/sdk/constants.js.map +0 -1
  497. package/dist/sdk/errors.d.ts.map +0 -1
  498. package/dist/sdk/errors.js.map +0 -1
  499. package/dist/sdk/index.d.ts +0 -8
  500. package/dist/sdk/index.d.ts.map +0 -1
  501. package/dist/sdk/index.js +0 -8
  502. package/dist/sdk/index.js.map +0 -1
  503. package/dist/sdk/mocks/auth.d.ts.map +0 -1
  504. package/dist/sdk/mocks/auth.js.map +0 -1
  505. package/dist/sdk/mocks/userstorage.d.ts.map +0 -1
  506. package/dist/sdk/mocks/userstorage.js.map +0 -1
  507. package/dist/sdk/user-storage.d.ts.map +0 -1
  508. package/dist/sdk/user-storage.js +0 -364
  509. package/dist/sdk/user-storage.js.map +0 -1
  510. package/dist/sdk/utils/eip-6963-metamask-provider.d.ts.map +0 -1
  511. package/dist/sdk/utils/eip-6963-metamask-provider.js.map +0 -1
  512. package/dist/sdk/utils/messaging-signing-snap-requests.d.ts.map +0 -1
  513. package/dist/sdk/utils/messaging-signing-snap-requests.js.map +0 -1
  514. package/dist/sdk/utils/validate-login-response.d.ts.map +0 -1
  515. package/dist/sdk/utils/validate-login-response.js.map +0 -1
  516. package/dist/sdk/utils/validate-pair-response.d.ts.map +0 -1
  517. package/dist/sdk/utils/validate-pair-response.js.map +0 -1
  518. package/dist/shared/encryption/cache.d.ts.map +0 -1
  519. package/dist/shared/encryption/cache.js.map +0 -1
  520. package/dist/shared/encryption/constants.d.ts.map +0 -1
  521. package/dist/shared/encryption/constants.js.map +0 -1
  522. package/dist/shared/encryption/encryption.d.ts.map +0 -1
  523. package/dist/shared/encryption/encryption.js +0 -202
  524. package/dist/shared/encryption/encryption.js.map +0 -1
  525. package/dist/shared/encryption/index.d.ts +0 -5
  526. package/dist/shared/encryption/index.d.ts.map +0 -1
  527. package/dist/shared/encryption/index.js +0 -5
  528. package/dist/shared/encryption/index.js.map +0 -1
  529. package/dist/shared/encryption/utils.d.ts.map +0 -1
  530. package/dist/shared/encryption/utils.js.map +0 -1
  531. package/dist/shared/env.d.ts.map +0 -1
  532. package/dist/shared/env.js.map +0 -1
  533. package/dist/shared/storage-schema.d.ts.map +0 -1
  534. package/dist/shared/storage-schema.js.map +0 -1
  535. package/dist/shared/types/encryption.d.ts.map +0 -1
  536. package/dist/shared/types/encryption.js +0 -2
  537. package/dist/shared/types/encryption.js.map +0 -1
  538. package/dist/shared/types/services.d.ts.map +0 -1
  539. package/dist/shared/types/services.js +0 -2
  540. package/dist/shared/types/services.js.map +0 -1
  541. package/dist/shared/utils/entropy-source.d.ts.map +0 -1
  542. package/dist/shared/utils/entropy-source.js.map +0 -1
  543. package/dist/shared/utils/event-queue.d.ts.map +0 -1
  544. package/dist/shared/utils/event-queue.js.map +0 -1
  545. package/dist/shared/utils/hd-keyring-seed.d.ts.map +0 -1
  546. package/dist/shared/utils/hd-keyring-seed.js.map +0 -1
  547. package/dist/shared/utils/message-signing.d.ts.map +0 -1
  548. package/dist/shared/utils/message-signing.js.map +0 -1
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _SIWEJwtBearerAuth_instances, _SIWEJwtBearerAuth_config, _SIWEJwtBearerAuth_options, _SIWEJwtBearerAuth_signer, _SIWEJwtBearerAuth_getAuthSession, _SIWEJwtBearerAuth_login, _SIWEJwtBearerAuth_createSiWELoginRawMessage, _SIWEJwtBearerAuth_assertSigner;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SIWEJwtBearerAuth = void 0;
16
+ const siwe_1 = require("siwe");
17
+ const errors_js_1 = require("../errors.cjs");
18
+ const validate_login_response_js_1 = require("../utils/validate-login-response.cjs");
19
+ const services_js_1 = require("./services.cjs");
20
+ class SIWEJwtBearerAuth {
21
+ constructor(config, options) {
22
+ _SIWEJwtBearerAuth_instances.add(this);
23
+ _SIWEJwtBearerAuth_config.set(this, void 0);
24
+ _SIWEJwtBearerAuth_options.set(this, void 0);
25
+ _SIWEJwtBearerAuth_signer.set(this, void 0);
26
+ __classPrivateFieldSet(this, _SIWEJwtBearerAuth_config, config, "f");
27
+ __classPrivateFieldSet(this, _SIWEJwtBearerAuth_options, options, "f");
28
+ }
29
+ async getAccessToken() {
30
+ const session = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_getAuthSession).call(this);
31
+ if (session) {
32
+ return session.token.accessToken;
33
+ }
34
+ const loginResponse = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_login).call(this);
35
+ return loginResponse.token.accessToken;
36
+ }
37
+ async getUserProfile() {
38
+ const session = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_getAuthSession).call(this);
39
+ if (session) {
40
+ return session.profile;
41
+ }
42
+ const loginResponse = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_login).call(this);
43
+ return loginResponse.profile;
44
+ }
45
+ async getIdentifier() {
46
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
47
+ return __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f").address;
48
+ }
49
+ async getUserProfileLineage() {
50
+ const accessToken = await this.getAccessToken();
51
+ return await (0, services_js_1.getUserProfileLineage)(__classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env, accessToken);
52
+ }
53
+ async getCustomerServiceToken() {
54
+ const accessToken = await this.getAccessToken();
55
+ return await (0, services_js_1.getCustomerServiceToken)(__classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env, accessToken);
56
+ }
57
+ async signMessage(message) {
58
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
59
+ return await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f").signMessage(message);
60
+ }
61
+ prepare(signer) {
62
+ __classPrivateFieldSet(this, _SIWEJwtBearerAuth_signer, signer, "f");
63
+ }
64
+ }
65
+ exports.SIWEJwtBearerAuth = SIWEJwtBearerAuth;
66
+ _SIWEJwtBearerAuth_config = new WeakMap(), _SIWEJwtBearerAuth_options = new WeakMap(), _SIWEJwtBearerAuth_signer = new WeakMap(), _SIWEJwtBearerAuth_instances = new WeakSet(), _SIWEJwtBearerAuth_getAuthSession =
67
+ // convert expiresIn from seconds to milliseconds and use 90% of expiresIn
68
+ async function _SIWEJwtBearerAuth_getAuthSession() {
69
+ const auth = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_options, "f").storage.getLoginResponse();
70
+ if (!(0, validate_login_response_js_1.validateLoginResponse)(auth)) {
71
+ return null;
72
+ }
73
+ const currentTime = Date.now();
74
+ const sessionAge = currentTime - auth.token.obtainedAt;
75
+ const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;
76
+ if (sessionAge < refreshThreshold) {
77
+ return auth;
78
+ }
79
+ return null;
80
+ }, _SIWEJwtBearerAuth_login = async function _SIWEJwtBearerAuth_login() {
81
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
82
+ // Nonce
83
+ const address = await this.getIdentifier();
84
+ const nonceRes = await (0, services_js_1.getNonce)(address, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env);
85
+ const rawMessage = __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_createSiWELoginRawMessage).call(this, nonceRes.nonce);
86
+ const signature = await this.signMessage(rawMessage);
87
+ // Authenticate
88
+ const authResponse = await (0, services_js_1.authenticate)(rawMessage, signature, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").type, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env);
89
+ // Authorize
90
+ const tokenResponse = await (0, services_js_1.authorizeOIDC)(authResponse.token, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").platform);
91
+ // Save
92
+ const result = {
93
+ profile: authResponse.profile,
94
+ token: tokenResponse,
95
+ };
96
+ await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_options, "f").storage.setLoginResponse(result);
97
+ return result;
98
+ }, _SIWEJwtBearerAuth_createSiWELoginRawMessage = function _SIWEJwtBearerAuth_createSiWELoginRawMessage(nonce) {
99
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
100
+ return new siwe_1.SiweMessage({
101
+ domain: __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f")?.domain,
102
+ address: __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f")?.address,
103
+ uri: (0, services_js_1.SIWE_LOGIN_URL)(__classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env),
104
+ version: '1',
105
+ chainId: __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f")?.chainId,
106
+ nonce,
107
+ issuedAt: new Date().toISOString(),
108
+ }).prepareMessage();
109
+ }, _SIWEJwtBearerAuth_assertSigner = function _SIWEJwtBearerAuth_assertSigner(signer) {
110
+ if (!signer) {
111
+ throw new errors_js_1.ValidationError(`you must call 'prepare()' before logging in`);
112
+ }
113
+ };
114
+ //# sourceMappingURL=flow-siw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GAAG,EAAE,IAAA,4BAAc,EAAC,uBAAA,IAAI,iCAAQ,CAAC,GAAG,CAAC;QACrC,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC,CAAC,cAAc,EAAE,CAAC;AACtB,CAAC,6EAGC,MAAkC;IAElC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,2BAAe,CAAC,6CAA6C,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { SiweMessage } from 'siwe';\n\nimport { ValidationError } from '../errors.js';\nimport { validateLoginResponse } from '../utils/validate-login-response.js';\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getCustomerServiceToken,\n getNonce,\n getUserProfileLineage,\n} from './services.js';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n UserProfileLineage,\n} from './types.js';\n\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\n};\n\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async getUserProfileLineage(): Promise<UserProfileLineage> {\n const accessToken = await this.getAccessToken();\n return await getUserProfileLineage(this.#config.env, accessToken);\n }\n\n async getCustomerServiceToken(): Promise<string> {\n const accessToken = await this.getAccessToken();\n return await getCustomerServiceToken(this.#config.env, accessToken);\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { AuthConfig, AuthStorageOptions, AuthType, IBaseAuth, UserProfile, UserProfileLineage } from './types.js';
1
+ import type { AuthConfig, AuthStorageOptions, AuthType, IBaseAuth, UserProfile, UserProfileLineage } from "./types.cjs";
2
2
  type JwtBearerAuth_SIWE_Options = {
3
3
  storage: AuthStorageOptions;
4
4
  };
@@ -22,4 +22,4 @@ export declare class SIWEJwtBearerAuth implements IBaseAuth {
22
22
  prepare(signer: JwtBearerAuth_SIWE_Signer): void;
23
23
  }
24
24
  export {};
25
- //# sourceMappingURL=flow-siwe.d.ts.map
25
+ //# sourceMappingURL=flow-siwe.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-siwe.d.cts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,SAAS,EAET,WAAW,EACX,kBAAkB,EACnB,oBAAmB;AAEpB,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,iBAAkB,YAAW,SAAS;;gBAQ/C,MAAM,EAAE,UAAU,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAA;KAAE,EAC5C,OAAO,EAAE,0BAA0B;IAM/B,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAUjC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAUtC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKhC,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAKpD,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAK1C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnD,OAAO,CAAC,MAAM,EAAE,yBAAyB;CA6E1C"}
@@ -0,0 +1,25 @@
1
+ import type { AuthConfig, AuthStorageOptions, AuthType, IBaseAuth, UserProfile, UserProfileLineage } from "./types.mjs";
2
+ type JwtBearerAuth_SIWE_Options = {
3
+ storage: AuthStorageOptions;
4
+ };
5
+ type JwtBearerAuth_SIWE_Signer = {
6
+ address: string;
7
+ chainId: number;
8
+ signMessage: (message: string) => Promise<string>;
9
+ domain: string;
10
+ };
11
+ export declare class SIWEJwtBearerAuth implements IBaseAuth {
12
+ #private;
13
+ constructor(config: AuthConfig & {
14
+ type: AuthType.SiWE;
15
+ }, options: JwtBearerAuth_SIWE_Options);
16
+ getAccessToken(): Promise<string>;
17
+ getUserProfile(): Promise<UserProfile>;
18
+ getIdentifier(): Promise<string>;
19
+ getUserProfileLineage(): Promise<UserProfileLineage>;
20
+ getCustomerServiceToken(): Promise<string>;
21
+ signMessage(message: string): Promise<string>;
22
+ prepare(signer: JwtBearerAuth_SIWE_Signer): void;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=flow-siwe.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-siwe.d.mts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,SAAS,EAET,WAAW,EACX,kBAAkB,EACnB,oBAAmB;AAEpB,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,iBAAkB,YAAW,SAAS;;gBAQ/C,MAAM,EAAE,UAAU,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAA;KAAE,EAC5C,OAAO,EAAE,0BAA0B;IAM/B,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAUjC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAUtC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKhC,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAKpD,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC;IAK1C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnD,OAAO,CAAC,MAAM,EAAE,yBAAyB;CA6E1C"}
@@ -0,0 +1,110 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _SIWEJwtBearerAuth_instances, _SIWEJwtBearerAuth_config, _SIWEJwtBearerAuth_options, _SIWEJwtBearerAuth_signer, _SIWEJwtBearerAuth_getAuthSession, _SIWEJwtBearerAuth_login, _SIWEJwtBearerAuth_createSiWELoginRawMessage, _SIWEJwtBearerAuth_assertSigner;
13
+ import { SiweMessage } from "siwe";
14
+ import { ValidationError } from "../errors.mjs";
15
+ import { validateLoginResponse } from "../utils/validate-login-response.mjs";
16
+ import { SIWE_LOGIN_URL, authenticate, authorizeOIDC, getCustomerServiceToken, getNonce, getUserProfileLineage } from "./services.mjs";
17
+ export class SIWEJwtBearerAuth {
18
+ constructor(config, options) {
19
+ _SIWEJwtBearerAuth_instances.add(this);
20
+ _SIWEJwtBearerAuth_config.set(this, void 0);
21
+ _SIWEJwtBearerAuth_options.set(this, void 0);
22
+ _SIWEJwtBearerAuth_signer.set(this, void 0);
23
+ __classPrivateFieldSet(this, _SIWEJwtBearerAuth_config, config, "f");
24
+ __classPrivateFieldSet(this, _SIWEJwtBearerAuth_options, options, "f");
25
+ }
26
+ async getAccessToken() {
27
+ const session = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_getAuthSession).call(this);
28
+ if (session) {
29
+ return session.token.accessToken;
30
+ }
31
+ const loginResponse = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_login).call(this);
32
+ return loginResponse.token.accessToken;
33
+ }
34
+ async getUserProfile() {
35
+ const session = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_getAuthSession).call(this);
36
+ if (session) {
37
+ return session.profile;
38
+ }
39
+ const loginResponse = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_login).call(this);
40
+ return loginResponse.profile;
41
+ }
42
+ async getIdentifier() {
43
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
44
+ return __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f").address;
45
+ }
46
+ async getUserProfileLineage() {
47
+ const accessToken = await this.getAccessToken();
48
+ return await getUserProfileLineage(__classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env, accessToken);
49
+ }
50
+ async getCustomerServiceToken() {
51
+ const accessToken = await this.getAccessToken();
52
+ return await getCustomerServiceToken(__classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env, accessToken);
53
+ }
54
+ async signMessage(message) {
55
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
56
+ return await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f").signMessage(message);
57
+ }
58
+ prepare(signer) {
59
+ __classPrivateFieldSet(this, _SIWEJwtBearerAuth_signer, signer, "f");
60
+ }
61
+ }
62
+ _SIWEJwtBearerAuth_config = new WeakMap(), _SIWEJwtBearerAuth_options = new WeakMap(), _SIWEJwtBearerAuth_signer = new WeakMap(), _SIWEJwtBearerAuth_instances = new WeakSet(), _SIWEJwtBearerAuth_getAuthSession =
63
+ // convert expiresIn from seconds to milliseconds and use 90% of expiresIn
64
+ async function _SIWEJwtBearerAuth_getAuthSession() {
65
+ const auth = await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_options, "f").storage.getLoginResponse();
66
+ if (!validateLoginResponse(auth)) {
67
+ return null;
68
+ }
69
+ const currentTime = Date.now();
70
+ const sessionAge = currentTime - auth.token.obtainedAt;
71
+ const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;
72
+ if (sessionAge < refreshThreshold) {
73
+ return auth;
74
+ }
75
+ return null;
76
+ }, _SIWEJwtBearerAuth_login = async function _SIWEJwtBearerAuth_login() {
77
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
78
+ // Nonce
79
+ const address = await this.getIdentifier();
80
+ const nonceRes = await getNonce(address, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env);
81
+ const rawMessage = __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_createSiWELoginRawMessage).call(this, nonceRes.nonce);
82
+ const signature = await this.signMessage(rawMessage);
83
+ // Authenticate
84
+ const authResponse = await authenticate(rawMessage, signature, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").type, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env);
85
+ // Authorize
86
+ const tokenResponse = await authorizeOIDC(authResponse.token, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").platform);
87
+ // Save
88
+ const result = {
89
+ profile: authResponse.profile,
90
+ token: tokenResponse,
91
+ };
92
+ await __classPrivateFieldGet(this, _SIWEJwtBearerAuth_options, "f").storage.setLoginResponse(result);
93
+ return result;
94
+ }, _SIWEJwtBearerAuth_createSiWELoginRawMessage = function _SIWEJwtBearerAuth_createSiWELoginRawMessage(nonce) {
95
+ __classPrivateFieldGet(this, _SIWEJwtBearerAuth_instances, "m", _SIWEJwtBearerAuth_assertSigner).call(this, __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f"));
96
+ return new SiweMessage({
97
+ domain: __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f")?.domain,
98
+ address: __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f")?.address,
99
+ uri: SIWE_LOGIN_URL(__classPrivateFieldGet(this, _SIWEJwtBearerAuth_config, "f").env),
100
+ version: '1',
101
+ chainId: __classPrivateFieldGet(this, _SIWEJwtBearerAuth_signer, "f")?.chainId,
102
+ nonce,
103
+ issuedAt: new Date().toISOString(),
104
+ }).prepareMessage();
105
+ }, _SIWEJwtBearerAuth_assertSigner = function _SIWEJwtBearerAuth_assertSigner(signer) {
106
+ if (!signer) {
107
+ throw new ValidationError(`you must call 'prepare()' before logging in`);
108
+ }
109
+ };
110
+ //# sourceMappingURL=flow-siwe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-siwe.mjs","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,aAAa;AAEnC,OAAO,EAAE,eAAe,EAAE,sBAAqB;AAC/C,OAAO,EAAE,qBAAqB,EAAE,6CAA4C;AAC5E,OAAO,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,QAAQ,EACR,qBAAqB,EACtB,uBAAsB;AAsBvB,MAAM,OAAO,iBAAiB;IAO5B,YACE,MAA4C,EAC5C,OAAmC;;QAR5B,4CAAoB;QAEpB,6CAAqC;QAE9C,4CAA+C;QAM7C,uBAAA,IAAI,6BAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,8BAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,uEAAgB,MAApB,IAAI,CAAkB,CAAC;QAC7C,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC;QACnC,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,uBAAA,IAAI,8DAAO,MAAX,IAAI,CAAS,CAAC;QAC1C,OAAO,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,uEAAgB,MAApB,IAAI,CAAkB,CAAC;QA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A,IAAI,kCAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AAChB,CAAC,uGAE0B,KAAa;IACtC,uBAAA,IAAI,qEAAc,MAAlB,IAAI,EAAe,uBAAA,IAAI,iCAAQ,CAAC,CAAC;IAEjC,OAAO,IAAI,WAAW,CAAC;QACrB,MAAM,EAAE,uBAAA,IAAI,iCAAQ,EAAE,MAAM;QAC5B,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,GAAG,EAAE,cAAc,CAAC,uBAAA,IAAI,iCAAQ,CAAC,GAAG,CAAC;QACrC,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,uBAAA,IAAI,iCAAQ,EAAE,OAAO;QAC9B,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC,CAAC,cAAc,EAAE,CAAC;AACtB,CAAC,6EAGC,MAAkC;IAElC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,eAAe,CAAC,6CAA6C,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { SiweMessage } from 'siwe';\n\nimport { ValidationError } from '../errors.js';\nimport { validateLoginResponse } from '../utils/validate-login-response.js';\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getCustomerServiceToken,\n getNonce,\n getUserProfileLineage,\n} from './services.js';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n UserProfileLineage,\n} from './types.js';\n\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\n};\n\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async getUserProfileLineage(): Promise<UserProfileLineage> {\n const accessToken = await this.getAccessToken();\n return await getUserProfileLineage(this.#config.env, accessToken);\n }\n\n async getCustomerServiceToken(): Promise<string> {\n const accessToken = await this.getAccessToken();\n return await getCustomerServiceToken(this.#config.env, accessToken);\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
+ if (kind === "m") throw new TypeError("Private method is not writable");
27
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
29
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
+ };
31
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
34
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
+ };
36
+ var _SRPJwtBearerAuth_instances, _SRPJwtBearerAuth_config, _SRPJwtBearerAuth_options, _SRPJwtBearerAuth_metametrics, _SRPJwtBearerAuth_ongoingLogins, _SRPJwtBearerAuth_ongoingPairings, _SRPJwtBearerAuth_cooldownDefaultMs, _SRPJwtBearerAuth_maxLoginRetries, _SRPJwtBearerAuth_getLoginTag, _SRPJwtBearerAuth_getLoginIdentifierType, _SRPJwtBearerAuth_customProvider, _SRPJwtBearerAuth_getAuthSession, _SRPJwtBearerAuth_login, _SRPJwtBearerAuth_performLogin, _SRPJwtBearerAuth_deferredLogin, _SRPJwtBearerAuth_loginWithRetry, _SRPJwtBearerAuth_createSrpLoginRawMessage;
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.SRPJwtBearerAuth = exports.PAIR_DEDUPE_TTL_MS = void 0;
39
+ const errors_js_1 = require("../errors.cjs");
40
+ const eip_6963_metamask_provider_js_1 = require("../utils/eip-6963-metamask-provider.cjs");
41
+ const messaging_signing_snap_requests_js_1 = require("../utils/messaging-signing-snap-requests.cjs");
42
+ const validate_login_response_js_1 = require("../utils/validate-login-response.cjs");
43
+ const services_js_1 = require("./services.cjs");
44
+ const identifier_js_1 = require("./utils/identifier.cjs");
45
+ const timeUtils = __importStar(require("./utils/time.cjs"));
46
+ // How long a successful pairing result stays cached so identical payloads
47
+ // (concurrent or sequential retries) reuse it instead of re-hitting the endpoint.
48
+ exports.PAIR_DEDUPE_TTL_MS = 30000;
49
+ const getDefaultEIP6963Provider = async () => {
50
+ const provider = await (0, eip_6963_metamask_provider_js_1.getMetaMaskProviderEIP6963)();
51
+ if (!provider) {
52
+ throw new errors_js_1.ValidationError('No MetaMask wallet connected');
53
+ }
54
+ return provider;
55
+ };
56
+ const getDefaultEIP6963SigningOptions = (customProvider) => ({
57
+ getIdentifier: async (entropySourceId) => {
58
+ const provider = customProvider ?? (await getDefaultEIP6963Provider());
59
+ return await messaging_signing_snap_requests_js_1.MESSAGE_SIGNING_SNAP.getPublicKey(provider, entropySourceId);
60
+ },
61
+ signMessage: async (message, entropySourceId) => {
62
+ const provider = customProvider ?? (await getDefaultEIP6963Provider());
63
+ (0, messaging_signing_snap_requests_js_1.assertMessageStartsWithMetamask)(message);
64
+ return await messaging_signing_snap_requests_js_1.MESSAGE_SIGNING_SNAP.signMessage(provider, message, entropySourceId);
65
+ },
66
+ });
67
+ class SRPJwtBearerAuth {
68
+ constructor(config, options) {
69
+ _SRPJwtBearerAuth_instances.add(this);
70
+ _SRPJwtBearerAuth_config.set(this, void 0);
71
+ _SRPJwtBearerAuth_options.set(this, void 0);
72
+ _SRPJwtBearerAuth_metametrics.set(this, void 0);
73
+ // Map to store ongoing login promises by entropySourceId
74
+ _SRPJwtBearerAuth_ongoingLogins.set(this, new Map());
75
+ // Map to dedupe pairing calls by an order-insensitive token-set key.
76
+ // Holds the in-flight promise (coalescing concurrent callers) and keeps it
77
+ // for a short TTL after success (collapsing sequential retries).
78
+ _SRPJwtBearerAuth_ongoingPairings.set(this, new Map());
79
+ // Default cooldown when 429 has no Retry-After header
80
+ _SRPJwtBearerAuth_cooldownDefaultMs.set(this, void 0);
81
+ // Maximum number of login retries on rate limit errors
82
+ _SRPJwtBearerAuth_maxLoginRetries.set(this, void 0);
83
+ _SRPJwtBearerAuth_getLoginTag.set(this, void 0);
84
+ _SRPJwtBearerAuth_getLoginIdentifierType.set(this, void 0);
85
+ _SRPJwtBearerAuth_customProvider.set(this, void 0);
86
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_config, config, "f");
87
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_customProvider, options.customProvider, "f");
88
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_getLoginTag, options.getLoginTag, "f");
89
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_getLoginIdentifierType, options.getLoginIdentifierType, "f");
90
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_options, {
91
+ storage: options.storage,
92
+ signing: options.signing ??
93
+ getDefaultEIP6963SigningOptions(__classPrivateFieldGet(this, _SRPJwtBearerAuth_customProvider, "f")),
94
+ }, "f");
95
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_metametrics, options.metametrics, "f");
96
+ // Apply rate limit retry config if provided
97
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_cooldownDefaultMs, options.rateLimitRetry?.cooldownDefaultMs ?? 10000, "f");
98
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_maxLoginRetries, options.rateLimitRetry?.maxLoginRetries ?? 1, "f");
99
+ }
100
+ setCustomProvider(provider) {
101
+ __classPrivateFieldSet(this, _SRPJwtBearerAuth_customProvider, provider, "f");
102
+ __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").signing = getDefaultEIP6963SigningOptions(provider);
103
+ }
104
+ // TODO: might be easier to keep entropySourceId as a class param and use multiple SRPJwtBearerAuth instances where needed
105
+ async getAccessToken(entropySourceId) {
106
+ const session = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_getAuthSession).call(this, entropySourceId);
107
+ if (session) {
108
+ return session.token.accessToken;
109
+ }
110
+ const loginResponse = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_login).call(this, entropySourceId);
111
+ return loginResponse.token.accessToken;
112
+ }
113
+ async getUserProfile(entropySourceId) {
114
+ const session = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_getAuthSession).call(this, entropySourceId);
115
+ if (session) {
116
+ return session.profile;
117
+ }
118
+ const loginResponse = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_login).call(this, entropySourceId);
119
+ return loginResponse.profile;
120
+ }
121
+ async getIdentifier(entropySourceId) {
122
+ return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").signing.getIdentifier(entropySourceId);
123
+ }
124
+ async getUserProfileLineage(entropySourceId) {
125
+ const accessToken = await this.getAccessToken(entropySourceId);
126
+ return await (0, services_js_1.getUserProfileLineage)(__classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, accessToken);
127
+ }
128
+ async getCustomerServiceToken(entropySourceId) {
129
+ const accessToken = await this.getAccessToken(entropySourceId);
130
+ return await (0, services_js_1.getCustomerServiceToken)(__classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, accessToken);
131
+ }
132
+ async pairSrpProfiles(accessTokens, authAccessToken) {
133
+ // Order-insensitive key: the same token set in any order maps to the same
134
+ // entry. Sort a copy so the request payload itself stays primary-first.
135
+ const key = JSON.stringify([...accessTokens].sort());
136
+ const cached = __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").get(key);
137
+ if (cached && cached.expiresAt > Date.now()) {
138
+ return await cached.promise;
139
+ }
140
+ const promise = (0, services_js_1.pairProfiles)(accessTokens, authAccessToken, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env);
141
+ // Store the in-flight promise immediately so concurrent callers coalesce
142
+ // regardless of how long the request takes.
143
+ __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").set(key, {
144
+ promise,
145
+ expiresAt: Number.MAX_SAFE_INTEGER,
146
+ });
147
+ try {
148
+ const result = await promise;
149
+ // Keep the resolved result cached for a short window so sequential
150
+ // retries with the same payload reuse it.
151
+ __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").set(key, {
152
+ promise,
153
+ expiresAt: Date.now() + exports.PAIR_DEDUPE_TTL_MS,
154
+ });
155
+ return result;
156
+ }
157
+ catch (error) {
158
+ // Never cache failures: the pairing retry loop must be able to re-hit
159
+ // the endpoint on the next attempt.
160
+ __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").delete(key);
161
+ throw error;
162
+ }
163
+ }
164
+ async signMessage(message, entropySourceId) {
165
+ return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").signing.signMessage(message, entropySourceId);
166
+ }
167
+ async isSnapConnected() {
168
+ const provider = __classPrivateFieldGet(this, _SRPJwtBearerAuth_customProvider, "f") ?? (await getDefaultEIP6963Provider());
169
+ if (!provider) {
170
+ return false;
171
+ }
172
+ const isConnected = await (0, messaging_signing_snap_requests_js_1.isSnapConnected)(provider);
173
+ return isConnected;
174
+ }
175
+ async connectSnap() {
176
+ const provider = __classPrivateFieldGet(this, _SRPJwtBearerAuth_customProvider, "f") ?? (await getDefaultEIP6963Provider());
177
+ const res = await (0, messaging_signing_snap_requests_js_1.connectSnap)(provider);
178
+ return res;
179
+ }
180
+ }
181
+ exports.SRPJwtBearerAuth = SRPJwtBearerAuth;
182
+ _SRPJwtBearerAuth_config = new WeakMap(), _SRPJwtBearerAuth_options = new WeakMap(), _SRPJwtBearerAuth_metametrics = new WeakMap(), _SRPJwtBearerAuth_ongoingLogins = new WeakMap(), _SRPJwtBearerAuth_ongoingPairings = new WeakMap(), _SRPJwtBearerAuth_cooldownDefaultMs = new WeakMap(), _SRPJwtBearerAuth_maxLoginRetries = new WeakMap(), _SRPJwtBearerAuth_getLoginTag = new WeakMap(), _SRPJwtBearerAuth_getLoginIdentifierType = new WeakMap(), _SRPJwtBearerAuth_customProvider = new WeakMap(), _SRPJwtBearerAuth_instances = new WeakSet(), _SRPJwtBearerAuth_getAuthSession =
183
+ // convert expiresIn from seconds to milliseconds and use 90% of expiresIn
184
+ async function _SRPJwtBearerAuth_getAuthSession(entropySourceId) {
185
+ const auth = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").storage.getLoginResponse(entropySourceId);
186
+ if (!(0, validate_login_response_js_1.validateLoginResponse)(auth)) {
187
+ return null;
188
+ }
189
+ // get canonical profile id from server if not present in the cached session
190
+ if (!auth.profile.canonicalProfileId) {
191
+ return null;
192
+ }
193
+ const currentTime = Date.now();
194
+ const sessionAge = currentTime - auth.token.obtainedAt;
195
+ const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;
196
+ if (sessionAge < refreshThreshold) {
197
+ return auth;
198
+ }
199
+ return null;
200
+ }, _SRPJwtBearerAuth_login = async function _SRPJwtBearerAuth_login(entropySourceId) {
201
+ // Use a deferred login to avoid race conditions
202
+ return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_deferredLogin).call(this, entropySourceId);
203
+ }, _SRPJwtBearerAuth_performLogin = async function _SRPJwtBearerAuth_performLogin(entropySourceId) {
204
+ // Nonce
205
+ const publicKey = await this.getIdentifier(entropySourceId);
206
+ const nonceRes = await (0, services_js_1.getNonce)(publicKey, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env);
207
+ // Tag only when the wallet supplies getLoginTag. SDK callers keep the
208
+ // legacy 3-part message rather than guessing `primary`.
209
+ const tag = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_getLoginTag, "f")?.call(this, entropySourceId);
210
+ const identifierType = (await __classPrivateFieldGet(this, _SRPJwtBearerAuth_getLoginIdentifierType, "f")?.call(this, entropySourceId)) ?? 'SRP';
211
+ const rawMessage = __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_createSrpLoginRawMessage).call(this, nonceRes.nonce, publicKey, tag);
212
+ const signature = await this.signMessage(rawMessage, entropySourceId);
213
+ // Authenticate
214
+ const authResponse = await (0, services_js_1.authenticate)(rawMessage, signature, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").type, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, __classPrivateFieldGet(this, _SRPJwtBearerAuth_metametrics, "f"), identifierType);
215
+ // Resolve original profileId from aliases.
216
+ // This is done mainly to preserve the original profileId for storage key derivation
217
+ // until we migrate to the canonical profileId storage system.
218
+ const canonicalProfileId = authResponse.profile.profileId;
219
+ const profile = { ...authResponse.profile };
220
+ if (authResponse.profileAliases?.length > 0) {
221
+ const targetIdentifierId = (0, identifier_js_1.computeIdentifierId)(publicKey, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env);
222
+ const matchingAliases = authResponse.profileAliases.filter((alias) => alias.identifierIds.some((id) => id.id === targetIdentifierId));
223
+ // Prefer the leaf alias (single identifier) — it's the original profile
224
+ // created for this SRP. Multi-identifier aliases are former canonicals
225
+ // that absorbed other profiles; they are correct only when this SRP's
226
+ // original profile was itself a canonical before being absorbed.
227
+ const targetAlias = matchingAliases.find((alias) => alias.identifierIds.length === 1) ??
228
+ matchingAliases[0];
229
+ if (targetAlias) {
230
+ profile.profileId = targetAlias.aliasProfileId;
231
+ }
232
+ }
233
+ profile.canonicalProfileId = canonicalProfileId;
234
+ // Authorize
235
+ const tokenResponse = await (0, services_js_1.authorizeOIDC)(authResponse.token, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").platform);
236
+ // Save
237
+ const result = {
238
+ profile,
239
+ token: tokenResponse,
240
+ };
241
+ await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").storage.setLoginResponse(result, entropySourceId);
242
+ return result;
243
+ }, _SRPJwtBearerAuth_deferredLogin = async function _SRPJwtBearerAuth_deferredLogin(entropySourceId) {
244
+ // Check if there's already an ongoing login for this entropySourceId
245
+ const existingLogin = __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingLogins, "f").get(entropySourceId);
246
+ if (existingLogin) {
247
+ return existingLogin;
248
+ }
249
+ // Create a new login promise
250
+ const loginPromise = __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_loginWithRetry).call(this, entropySourceId);
251
+ // Store the promise in the map
252
+ __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingLogins, "f").set(entropySourceId, loginPromise);
253
+ try {
254
+ // Wait for the login to complete
255
+ return await loginPromise;
256
+ }
257
+ finally {
258
+ // Always clean up the ongoing login promise when done
259
+ __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingLogins, "f").delete(entropySourceId);
260
+ }
261
+ }, _SRPJwtBearerAuth_loginWithRetry = async function _SRPJwtBearerAuth_loginWithRetry(entropySourceId) {
262
+ // Allow max attempts: initial + maxLoginRetries on 429
263
+ for (let attempt = 0; attempt < 1 + __classPrivateFieldGet(this, _SRPJwtBearerAuth_maxLoginRetries, "f"); attempt += 1) {
264
+ try {
265
+ return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_performLogin).call(this, entropySourceId);
266
+ }
267
+ catch (e) {
268
+ // Only retry on rate-limit (429) errors
269
+ if (!errors_js_1.RateLimitedError.isRateLimitError(e)) {
270
+ throw e;
271
+ }
272
+ // If we've exhausted attempts, rethrow
273
+ if (attempt >= __classPrivateFieldGet(this, _SRPJwtBearerAuth_maxLoginRetries, "f")) {
274
+ throw e;
275
+ }
276
+ // Wait for Retry-After or default cooldown
277
+ const waitMs = e.retryAfterMs ?? __classPrivateFieldGet(this, _SRPJwtBearerAuth_cooldownDefaultMs, "f");
278
+ await timeUtils.delay(waitMs);
279
+ // Loop continues to retry
280
+ }
281
+ }
282
+ // Should never reach here due to loop logic, but TypeScript needs a return
283
+ throw new Error('Unexpected: login loop exhausted without result');
284
+ }, _SRPJwtBearerAuth_createSrpLoginRawMessage = function _SRPJwtBearerAuth_createSrpLoginRawMessage(nonce, publicKey, tag) {
285
+ if (tag) {
286
+ return `metamask:${nonce}:${publicKey}:${tag}`;
287
+ }
288
+ return `metamask:${nonce}:${publicKey}`;
289
+ };
290
+ //# sourceMappingURL=flow-srp.cjs.map