@metamask/profile-sync-controller 29.0.0 → 31.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 (537) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/dist/controllers/authentication/{AuthenticationController-method-action-types.d.mts → AuthenticationController-method-action-types.d.ts} +2 -2
  3. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.ts.map +1 -0
  4. package/dist/controllers/authentication/{AuthenticationController-method-action-types.mjs → AuthenticationController-method-action-types.js} +1 -1
  5. package/dist/controllers/authentication/AuthenticationController-method-action-types.js.map +1 -0
  6. package/dist/controllers/authentication/{AuthenticationController.d.mts → AuthenticationController.d.ts} +30 -12
  7. package/dist/controllers/authentication/AuthenticationController.d.ts.map +1 -0
  8. package/dist/controllers/authentication/AuthenticationController.js +656 -0
  9. package/dist/controllers/authentication/AuthenticationController.js.map +1 -0
  10. package/dist/controllers/authentication/{index.d.cts → index.d.ts} +5 -5
  11. package/dist/controllers/authentication/index.d.ts.map +1 -0
  12. package/dist/controllers/authentication/index.js +6 -0
  13. package/dist/controllers/authentication/index.js.map +1 -0
  14. package/dist/controllers/authentication/mocks/index.d.ts +2 -0
  15. package/dist/controllers/authentication/mocks/index.d.ts.map +1 -0
  16. package/dist/controllers/authentication/mocks/index.js +2 -0
  17. package/dist/controllers/authentication/mocks/index.js.map +1 -0
  18. package/dist/controllers/authentication/mocks/{mockResponses.d.cts → mockResponses.d.ts} +12 -1
  19. package/dist/controllers/authentication/mocks/{mockResponses.d.cts.map → mockResponses.d.ts.map} +1 -1
  20. package/dist/controllers/authentication/mocks/{mockResponses.mjs → mockResponses.js} +10 -2
  21. package/dist/controllers/authentication/mocks/mockResponses.js.map +1 -0
  22. package/dist/controllers/index.d.ts +3 -0
  23. package/dist/controllers/index.d.ts.map +1 -0
  24. package/dist/controllers/index.js +3 -0
  25. package/dist/controllers/index.js.map +1 -0
  26. package/dist/controllers/user-storage/{UserStorageController-method-action-types.d.mts → UserStorageController-method-action-types.d.ts} +2 -2
  27. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.ts.map +1 -0
  28. package/dist/controllers/user-storage/{UserStorageController-method-action-types.mjs → UserStorageController-method-action-types.js} +1 -1
  29. package/dist/controllers/user-storage/UserStorageController-method-action-types.js.map +1 -0
  30. package/dist/controllers/user-storage/{UserStorageController.d.cts → UserStorageController.d.ts} +15 -16
  31. package/dist/controllers/user-storage/UserStorageController.d.ts.map +1 -0
  32. package/dist/controllers/user-storage/UserStorageController.js +429 -0
  33. package/dist/controllers/user-storage/UserStorageController.js.map +1 -0
  34. package/dist/controllers/user-storage/constants.d.ts +15 -0
  35. package/dist/controllers/user-storage/constants.d.ts.map +1 -0
  36. package/dist/controllers/user-storage/{constants.mjs → constants.js} +1 -1
  37. package/dist/controllers/user-storage/constants.js.map +1 -0
  38. package/dist/controllers/user-storage/contact-syncing/{constants.d.cts → constants.d.ts} +1 -1
  39. package/dist/controllers/user-storage/contact-syncing/constants.d.ts.map +1 -0
  40. package/dist/controllers/user-storage/contact-syncing/{constants.mjs → constants.js} +1 -1
  41. package/dist/controllers/user-storage/contact-syncing/constants.js.map +1 -0
  42. package/dist/controllers/user-storage/contact-syncing/{controller-integration.d.cts → controller-integration.d.ts} +3 -3
  43. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.ts.map +1 -0
  44. package/dist/controllers/user-storage/contact-syncing/{controller-integration.mjs → controller-integration.js} +6 -6
  45. package/dist/controllers/user-storage/contact-syncing/controller-integration.js.map +1 -0
  46. package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.d.cts → setup-subscriptions.d.ts} +2 -2
  47. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.ts.map +1 -0
  48. package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.mjs → setup-subscriptions.js} +4 -4
  49. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.js.map +1 -0
  50. package/dist/controllers/user-storage/contact-syncing/{sync-utils.d.cts → sync-utils.d.ts} +2 -2
  51. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.ts.map +1 -0
  52. package/dist/controllers/user-storage/contact-syncing/{sync-utils.mjs → sync-utils.js} +1 -1
  53. package/dist/controllers/user-storage/contact-syncing/sync-utils.js.map +1 -0
  54. package/dist/controllers/user-storage/contact-syncing/{types.d.cts → types.d.ts} +6 -6
  55. package/dist/controllers/user-storage/contact-syncing/types.d.ts.map +1 -0
  56. package/dist/controllers/user-storage/contact-syncing/types.js +2 -0
  57. package/dist/controllers/user-storage/contact-syncing/types.js.map +1 -0
  58. package/dist/controllers/user-storage/contact-syncing/{utils.d.cts → utils.d.ts} +3 -3
  59. package/dist/controllers/user-storage/contact-syncing/utils.d.ts.map +1 -0
  60. package/dist/controllers/user-storage/contact-syncing/{utils.mjs → utils.js} +2 -2
  61. package/dist/controllers/user-storage/contact-syncing/utils.js.map +1 -0
  62. package/dist/controllers/user-storage/{index.d.cts → index.d.ts} +8 -8
  63. package/dist/controllers/user-storage/index.d.ts.map +1 -0
  64. package/dist/controllers/user-storage/index.js +9 -0
  65. package/dist/controllers/user-storage/index.js.map +1 -0
  66. package/dist/controllers/user-storage/mocks/index.d.ts +3 -0
  67. package/dist/controllers/user-storage/mocks/index.d.ts.map +1 -0
  68. package/dist/controllers/user-storage/mocks/index.js +3 -0
  69. package/dist/controllers/user-storage/mocks/index.js.map +1 -0
  70. package/dist/controllers/user-storage/mocks/{mockResponses.d.mts → mockResponses.d.ts} +3 -3
  71. package/dist/controllers/user-storage/mocks/mockResponses.d.ts.map +1 -0
  72. package/dist/controllers/user-storage/mocks/{mockResponses.mjs → mockResponses.js} +4 -4
  73. package/dist/controllers/user-storage/mocks/mockResponses.js.map +1 -0
  74. package/dist/controllers/user-storage/mocks/{mockStorage.d.cts → mockStorage.d.ts} +1 -1
  75. package/dist/controllers/user-storage/mocks/mockStorage.d.ts.map +1 -0
  76. package/dist/controllers/user-storage/mocks/{mockStorage.mjs → mockStorage.js} +3 -3
  77. package/dist/controllers/user-storage/mocks/mockStorage.js.map +1 -0
  78. package/dist/controllers/user-storage/{types.d.cts → types.d.ts} +3 -3
  79. package/dist/controllers/user-storage/types.d.ts.map +1 -0
  80. package/dist/controllers/user-storage/types.js +2 -0
  81. package/dist/controllers/user-storage/types.js.map +1 -0
  82. package/dist/controllers/user-storage/{utils.d.cts → utils.d.ts} +1 -1
  83. package/dist/controllers/user-storage/utils.d.ts.map +1 -0
  84. package/dist/controllers/user-storage/{utils.mjs → utils.js} +1 -1
  85. package/dist/controllers/user-storage/utils.js.map +1 -0
  86. package/dist/index.d.ts +4 -0
  87. package/dist/index.d.ts.map +1 -0
  88. package/dist/index.js +4 -0
  89. package/dist/index.js.map +1 -0
  90. package/dist/sdk/authentication-jwt-bearer/{flow-siwe.d.cts → flow-siwe.d.ts} +2 -2
  91. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +1 -0
  92. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +99 -0
  93. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js.map +1 -0
  94. package/dist/sdk/authentication-jwt-bearer/{flow-srp.d.mts → flow-srp.d.ts} +6 -5
  95. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +1 -0
  96. package/dist/sdk/authentication-jwt-bearer/flow-srp.js +258 -0
  97. package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +1 -0
  98. package/dist/sdk/authentication-jwt-bearer/{services.d.mts → services.d.ts} +20 -5
  99. package/dist/sdk/authentication-jwt-bearer/services.d.ts.map +1 -0
  100. package/dist/sdk/authentication-jwt-bearer/{services.mjs → services.js} +47 -6
  101. package/dist/sdk/authentication-jwt-bearer/services.js.map +1 -0
  102. package/dist/sdk/authentication-jwt-bearer/{types.d.cts → types.d.ts} +22 -3
  103. package/dist/sdk/authentication-jwt-bearer/types.d.ts.map +1 -0
  104. package/dist/sdk/authentication-jwt-bearer/{types.mjs → types.js} +1 -1
  105. package/dist/sdk/authentication-jwt-bearer/types.js.map +1 -0
  106. package/dist/sdk/authentication-jwt-bearer/utils/{identifier.d.cts → identifier.d.ts} +2 -2
  107. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.ts.map +1 -0
  108. package/dist/sdk/authentication-jwt-bearer/utils/{identifier.mjs → identifier.js} +2 -2
  109. package/dist/sdk/authentication-jwt-bearer/utils/identifier.js.map +1 -0
  110. package/dist/sdk/authentication-jwt-bearer/utils/{time.d.cts → time.d.ts} +1 -1
  111. package/dist/sdk/authentication-jwt-bearer/utils/time.d.ts.map +1 -0
  112. package/dist/sdk/authentication-jwt-bearer/utils/{time.mjs → time.js} +1 -1
  113. package/dist/sdk/authentication-jwt-bearer/utils/time.js.map +1 -0
  114. package/dist/sdk/{authentication.d.cts → authentication.d.ts} +10 -9
  115. package/dist/sdk/authentication.d.ts.map +1 -0
  116. package/dist/sdk/authentication.js +104 -0
  117. package/dist/sdk/authentication.js.map +1 -0
  118. package/dist/sdk/{constants.d.cts → constants.d.ts} +2 -1
  119. package/dist/sdk/constants.d.ts.map +1 -0
  120. package/dist/sdk/{constants.mjs → constants.js} +2 -1
  121. package/dist/sdk/constants.js.map +1 -0
  122. package/dist/sdk/{errors.d.mts → errors.d.ts} +10 -1
  123. package/dist/sdk/errors.d.ts.map +1 -0
  124. package/dist/sdk/{errors.mjs → errors.js} +16 -3
  125. package/dist/sdk/errors.js.map +1 -0
  126. package/dist/sdk/index.d.ts +8 -0
  127. package/dist/sdk/index.d.ts.map +1 -0
  128. package/dist/sdk/index.js +8 -0
  129. package/dist/sdk/index.js.map +1 -0
  130. package/dist/sdk/mocks/{auth.d.cts → auth.d.ts} +13 -2
  131. package/dist/sdk/mocks/auth.d.ts.map +1 -0
  132. package/dist/sdk/mocks/{auth.mjs → auth.js} +14 -3
  133. package/dist/sdk/mocks/auth.js.map +1 -0
  134. package/dist/sdk/mocks/{userstorage.d.cts → userstorage.d.ts} +1 -1
  135. package/dist/sdk/mocks/userstorage.d.ts.map +1 -0
  136. package/dist/sdk/mocks/{userstorage.mjs → userstorage.js} +5 -5
  137. package/dist/sdk/mocks/userstorage.js.map +1 -0
  138. package/dist/sdk/{user-storage.d.mts → user-storage.d.ts} +5 -5
  139. package/dist/sdk/user-storage.d.ts.map +1 -0
  140. package/dist/sdk/user-storage.js +364 -0
  141. package/dist/sdk/user-storage.js.map +1 -0
  142. package/dist/sdk/utils/{eip-6963-metamask-provider.d.cts → eip-6963-metamask-provider.d.ts} +2 -2
  143. package/dist/sdk/utils/eip-6963-metamask-provider.d.ts.map +1 -0
  144. package/dist/sdk/utils/{eip-6963-metamask-provider.mjs → eip-6963-metamask-provider.js} +1 -1
  145. package/dist/sdk/utils/eip-6963-metamask-provider.js.map +1 -0
  146. package/dist/sdk/utils/{messaging-signing-snap-requests.d.mts → messaging-signing-snap-requests.d.ts} +2 -2
  147. package/dist/sdk/utils/messaging-signing-snap-requests.d.ts.map +1 -0
  148. package/dist/sdk/utils/{messaging-signing-snap-requests.mjs → messaging-signing-snap-requests.js} +1 -1
  149. package/dist/sdk/utils/messaging-signing-snap-requests.js.map +1 -0
  150. package/dist/sdk/utils/{validate-login-response.d.mts → validate-login-response.d.ts} +2 -2
  151. package/dist/sdk/utils/validate-login-response.d.ts.map +1 -0
  152. package/dist/sdk/utils/{validate-login-response.mjs → validate-login-response.js} +1 -1
  153. package/dist/sdk/utils/validate-login-response.js.map +1 -0
  154. package/dist/sdk/utils/{validate-pair-response.d.cts → validate-pair-response.d.ts} +1 -1
  155. package/dist/sdk/utils/validate-pair-response.d.ts.map +1 -0
  156. package/dist/sdk/utils/{validate-pair-response.mjs → validate-pair-response.js} +1 -1
  157. package/dist/sdk/utils/validate-pair-response.js.map +1 -0
  158. package/dist/shared/encryption/{cache.d.cts → cache.d.ts} +1 -1
  159. package/dist/shared/encryption/cache.d.ts.map +1 -0
  160. package/dist/shared/encryption/{cache.mjs → cache.js} +4 -4
  161. package/dist/shared/encryption/cache.js.map +1 -0
  162. package/dist/shared/encryption/{constants.d.cts → constants.d.ts} +2 -2
  163. package/dist/shared/encryption/constants.d.ts.map +1 -0
  164. package/dist/shared/encryption/{constants.mjs → constants.js} +1 -1
  165. package/dist/shared/encryption/constants.js.map +1 -0
  166. package/dist/shared/encryption/{encryption.d.cts → encryption.d.ts} +3 -3
  167. package/dist/shared/encryption/encryption.d.ts.map +1 -0
  168. package/dist/shared/encryption/encryption.js +202 -0
  169. package/dist/shared/encryption/encryption.js.map +1 -0
  170. package/dist/shared/encryption/index.d.ts +5 -0
  171. package/dist/shared/encryption/index.d.ts.map +1 -0
  172. package/dist/shared/encryption/index.js +5 -0
  173. package/dist/shared/encryption/index.js.map +1 -0
  174. package/dist/shared/encryption/{utils.d.cts → utils.d.ts} +3 -3
  175. package/dist/shared/encryption/utils.d.ts.map +1 -0
  176. package/dist/shared/encryption/{utils.mjs → utils.js} +1 -1
  177. package/dist/shared/encryption/utils.js.map +1 -0
  178. package/dist/shared/{env.d.mts → env.d.ts} +1 -1
  179. package/dist/shared/env.d.ts.map +1 -0
  180. package/dist/shared/{env.mjs → env.js} +1 -1
  181. package/dist/shared/env.js.map +1 -0
  182. package/dist/shared/{storage-schema.d.mts → storage-schema.d.ts} +1 -1
  183. package/dist/shared/storage-schema.d.ts.map +1 -0
  184. package/dist/shared/{storage-schema.mjs → storage-schema.js} +2 -2
  185. package/dist/shared/storage-schema.js.map +1 -0
  186. package/dist/shared/types/{encryption.d.cts → encryption.d.ts} +1 -1
  187. package/dist/shared/types/encryption.d.ts.map +1 -0
  188. package/dist/shared/types/encryption.js +2 -0
  189. package/dist/shared/types/encryption.js.map +1 -0
  190. package/dist/shared/types/{services.d.cts → services.d.ts} +2 -2
  191. package/dist/shared/types/services.d.ts.map +1 -0
  192. package/dist/shared/types/services.js +2 -0
  193. package/dist/shared/types/services.js.map +1 -0
  194. package/dist/shared/utils/entropy-source.d.ts +22 -0
  195. package/dist/shared/utils/entropy-source.d.ts.map +1 -0
  196. package/dist/shared/utils/entropy-source.js +32 -0
  197. package/dist/shared/utils/entropy-source.js.map +1 -0
  198. package/dist/shared/utils/{event-queue.d.cts → event-queue.d.ts} +1 -1
  199. package/dist/shared/utils/event-queue.d.ts.map +1 -0
  200. package/dist/shared/utils/{event-queue.mjs → event-queue.js} +2 -4
  201. package/dist/shared/utils/event-queue.js.map +1 -0
  202. package/dist/shared/utils/hd-keyring-seed.d.ts +27 -0
  203. package/dist/shared/utils/hd-keyring-seed.d.ts.map +1 -0
  204. package/dist/shared/utils/hd-keyring-seed.js +45 -0
  205. package/dist/shared/utils/hd-keyring-seed.js.map +1 -0
  206. package/dist/shared/utils/message-signing.d.ts +73 -0
  207. package/dist/shared/utils/message-signing.d.ts.map +1 -0
  208. package/dist/shared/utils/message-signing.js +140 -0
  209. package/dist/shared/utils/message-signing.js.map +1 -0
  210. package/package.json +35 -69
  211. package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs +0 -7
  212. package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs.map +0 -1
  213. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.cts +0 -102
  214. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.cts.map +0 -1
  215. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts.map +0 -1
  216. package/dist/controllers/authentication/AuthenticationController-method-action-types.mjs.map +0 -1
  217. package/dist/controllers/authentication/AuthenticationController.cjs +0 -501
  218. package/dist/controllers/authentication/AuthenticationController.cjs.map +0 -1
  219. package/dist/controllers/authentication/AuthenticationController.d.cts +0 -131
  220. package/dist/controllers/authentication/AuthenticationController.d.cts.map +0 -1
  221. package/dist/controllers/authentication/AuthenticationController.d.mts.map +0 -1
  222. package/dist/controllers/authentication/AuthenticationController.mjs +0 -497
  223. package/dist/controllers/authentication/AuthenticationController.mjs.map +0 -1
  224. package/dist/controllers/authentication/auth-snap-requests.cjs +0 -60
  225. package/dist/controllers/authentication/auth-snap-requests.cjs.map +0 -1
  226. package/dist/controllers/authentication/auth-snap-requests.d.cts +0 -27
  227. package/dist/controllers/authentication/auth-snap-requests.d.cts.map +0 -1
  228. package/dist/controllers/authentication/auth-snap-requests.d.mts +0 -27
  229. package/dist/controllers/authentication/auth-snap-requests.d.mts.map +0 -1
  230. package/dist/controllers/authentication/auth-snap-requests.mjs +0 -54
  231. package/dist/controllers/authentication/auth-snap-requests.mjs.map +0 -1
  232. package/dist/controllers/authentication/index.cjs +0 -35
  233. package/dist/controllers/authentication/index.cjs.map +0 -1
  234. package/dist/controllers/authentication/index.d.cts.map +0 -1
  235. package/dist/controllers/authentication/index.d.mts +0 -7
  236. package/dist/controllers/authentication/index.d.mts.map +0 -1
  237. package/dist/controllers/authentication/index.mjs +0 -6
  238. package/dist/controllers/authentication/index.mjs.map +0 -1
  239. package/dist/controllers/authentication/mocks/index.cjs +0 -18
  240. package/dist/controllers/authentication/mocks/index.cjs.map +0 -1
  241. package/dist/controllers/authentication/mocks/index.d.cts +0 -2
  242. package/dist/controllers/authentication/mocks/index.d.cts.map +0 -1
  243. package/dist/controllers/authentication/mocks/index.d.mts +0 -2
  244. package/dist/controllers/authentication/mocks/index.d.mts.map +0 -1
  245. package/dist/controllers/authentication/mocks/index.mjs +0 -2
  246. package/dist/controllers/authentication/mocks/index.mjs.map +0 -1
  247. package/dist/controllers/authentication/mocks/mockResponses.cjs +0 -126
  248. package/dist/controllers/authentication/mocks/mockResponses.cjs.map +0 -1
  249. package/dist/controllers/authentication/mocks/mockResponses.d.mts +0 -58
  250. package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +0 -1
  251. package/dist/controllers/authentication/mocks/mockResponses.mjs.map +0 -1
  252. package/dist/controllers/index.cjs +0 -29
  253. package/dist/controllers/index.cjs.map +0 -1
  254. package/dist/controllers/index.d.cts +0 -3
  255. package/dist/controllers/index.d.cts.map +0 -1
  256. package/dist/controllers/index.d.mts +0 -3
  257. package/dist/controllers/index.d.mts.map +0 -1
  258. package/dist/controllers/index.mjs +0 -3
  259. package/dist/controllers/index.mjs.map +0 -1
  260. package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs +0 -7
  261. package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs.map +0 -1
  262. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.cts +0 -137
  263. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.cts.map +0 -1
  264. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts.map +0 -1
  265. package/dist/controllers/user-storage/UserStorageController-method-action-types.mjs.map +0 -1
  266. package/dist/controllers/user-storage/UserStorageController.cjs +0 -413
  267. package/dist/controllers/user-storage/UserStorageController.cjs.map +0 -1
  268. package/dist/controllers/user-storage/UserStorageController.d.cts.map +0 -1
  269. package/dist/controllers/user-storage/UserStorageController.d.mts +0 -183
  270. package/dist/controllers/user-storage/UserStorageController.d.mts.map +0 -1
  271. package/dist/controllers/user-storage/UserStorageController.mjs +0 -409
  272. package/dist/controllers/user-storage/UserStorageController.mjs.map +0 -1
  273. package/dist/controllers/user-storage/constants.cjs +0 -19
  274. package/dist/controllers/user-storage/constants.cjs.map +0 -1
  275. package/dist/controllers/user-storage/constants.d.cts +0 -15
  276. package/dist/controllers/user-storage/constants.d.cts.map +0 -1
  277. package/dist/controllers/user-storage/constants.d.mts +0 -15
  278. package/dist/controllers/user-storage/constants.d.mts.map +0 -1
  279. package/dist/controllers/user-storage/constants.mjs.map +0 -1
  280. package/dist/controllers/user-storage/contact-syncing/constants.cjs +0 -12
  281. package/dist/controllers/user-storage/contact-syncing/constants.cjs.map +0 -1
  282. package/dist/controllers/user-storage/contact-syncing/constants.d.cts.map +0 -1
  283. package/dist/controllers/user-storage/contact-syncing/constants.d.mts +0 -9
  284. package/dist/controllers/user-storage/contact-syncing/constants.d.mts.map +0 -1
  285. package/dist/controllers/user-storage/contact-syncing/constants.mjs.map +0 -1
  286. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +0 -346
  287. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +0 -1
  288. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +0 -1
  289. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +0 -47
  290. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +0 -1
  291. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +0 -1
  292. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs +0 -50
  293. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs.map +0 -1
  294. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.cts.map +0 -1
  295. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts +0 -8
  296. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts.map +0 -1
  297. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.mjs.map +0 -1
  298. package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs +0 -23
  299. package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs.map +0 -1
  300. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.cts.map +0 -1
  301. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts +0 -9
  302. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts.map +0 -1
  303. package/dist/controllers/user-storage/contact-syncing/sync-utils.mjs.map +0 -1
  304. package/dist/controllers/user-storage/contact-syncing/types.cjs +0 -3
  305. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +0 -1
  306. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +0 -1
  307. package/dist/controllers/user-storage/contact-syncing/types.d.mts +0 -37
  308. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +0 -1
  309. package/dist/controllers/user-storage/contact-syncing/types.mjs +0 -2
  310. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +0 -1
  311. package/dist/controllers/user-storage/contact-syncing/utils.cjs +0 -64
  312. package/dist/controllers/user-storage/contact-syncing/utils.cjs.map +0 -1
  313. package/dist/controllers/user-storage/contact-syncing/utils.d.cts.map +0 -1
  314. package/dist/controllers/user-storage/contact-syncing/utils.d.mts +0 -36
  315. package/dist/controllers/user-storage/contact-syncing/utils.d.mts.map +0 -1
  316. package/dist/controllers/user-storage/contact-syncing/utils.mjs.map +0 -1
  317. package/dist/controllers/user-storage/index.cjs +0 -38
  318. package/dist/controllers/user-storage/index.cjs.map +0 -1
  319. package/dist/controllers/user-storage/index.d.cts.map +0 -1
  320. package/dist/controllers/user-storage/index.d.mts +0 -10
  321. package/dist/controllers/user-storage/index.d.mts.map +0 -1
  322. package/dist/controllers/user-storage/index.mjs +0 -9
  323. package/dist/controllers/user-storage/index.mjs.map +0 -1
  324. package/dist/controllers/user-storage/mocks/index.cjs +0 -19
  325. package/dist/controllers/user-storage/mocks/index.cjs.map +0 -1
  326. package/dist/controllers/user-storage/mocks/index.d.cts +0 -3
  327. package/dist/controllers/user-storage/mocks/index.d.cts.map +0 -1
  328. package/dist/controllers/user-storage/mocks/index.d.mts +0 -3
  329. package/dist/controllers/user-storage/mocks/index.d.mts.map +0 -1
  330. package/dist/controllers/user-storage/mocks/index.mjs +0 -3
  331. package/dist/controllers/user-storage/mocks/index.mjs.map +0 -1
  332. package/dist/controllers/user-storage/mocks/mockResponses.cjs +0 -113
  333. package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +0 -1
  334. package/dist/controllers/user-storage/mocks/mockResponses.d.cts +0 -66
  335. package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +0 -1
  336. package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +0 -1
  337. package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +0 -1
  338. package/dist/controllers/user-storage/mocks/mockStorage.cjs +0 -36
  339. package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +0 -1
  340. package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +0 -1
  341. package/dist/controllers/user-storage/mocks/mockStorage.d.mts +0 -5
  342. package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +0 -1
  343. package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +0 -1
  344. package/dist/controllers/user-storage/types.cjs +0 -3
  345. package/dist/controllers/user-storage/types.cjs.map +0 -1
  346. package/dist/controllers/user-storage/types.d.cts.map +0 -1
  347. package/dist/controllers/user-storage/types.d.mts +0 -23
  348. package/dist/controllers/user-storage/types.d.mts.map +0 -1
  349. package/dist/controllers/user-storage/types.mjs +0 -2
  350. package/dist/controllers/user-storage/types.mjs.map +0 -1
  351. package/dist/controllers/user-storage/utils.cjs +0 -32
  352. package/dist/controllers/user-storage/utils.cjs.map +0 -1
  353. package/dist/controllers/user-storage/utils.d.cts.map +0 -1
  354. package/dist/controllers/user-storage/utils.d.mts +0 -19
  355. package/dist/controllers/user-storage/utils.d.mts.map +0 -1
  356. package/dist/controllers/user-storage/utils.mjs.map +0 -1
  357. package/dist/index.cjs +0 -30
  358. package/dist/index.cjs.map +0 -1
  359. package/dist/index.d.cts +0 -4
  360. package/dist/index.d.cts.map +0 -1
  361. package/dist/index.d.mts +0 -4
  362. package/dist/index.d.mts.map +0 -1
  363. package/dist/index.mjs +0 -4
  364. package/dist/index.mjs.map +0 -1
  365. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +0 -114
  366. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +0 -1
  367. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +0 -1
  368. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +0 -25
  369. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +0 -1
  370. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +0 -110
  371. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +0 -1
  372. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +0 -290
  373. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +0 -1
  374. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +0 -44
  375. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +0 -1
  376. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +0 -1
  377. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +0 -263
  378. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +0 -1
  379. package/dist/sdk/authentication-jwt-bearer/services.cjs +0 -400
  380. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +0 -1
  381. package/dist/sdk/authentication-jwt-bearer/services.d.cts +0 -105
  382. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +0 -1
  383. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +0 -1
  384. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +0 -1
  385. package/dist/sdk/authentication-jwt-bearer/types.cjs +0 -12
  386. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +0 -1
  387. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +0 -1
  388. package/dist/sdk/authentication-jwt-bearer/types.d.mts +0 -114
  389. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +0 -1
  390. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +0 -1
  391. package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs +0 -27
  392. package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs.map +0 -1
  393. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.cts.map +0 -1
  394. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts +0 -13
  395. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts.map +0 -1
  396. package/dist/sdk/authentication-jwt-bearer/utils/identifier.mjs.map +0 -1
  397. package/dist/sdk/authentication-jwt-bearer/utils/time.cjs +0 -17
  398. package/dist/sdk/authentication-jwt-bearer/utils/time.cjs.map +0 -1
  399. package/dist/sdk/authentication-jwt-bearer/utils/time.d.cts.map +0 -1
  400. package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts +0 -8
  401. package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts.map +0 -1
  402. package/dist/sdk/authentication-jwt-bearer/utils/time.mjs.map +0 -1
  403. package/dist/sdk/authentication.cjs +0 -132
  404. package/dist/sdk/authentication.cjs.map +0 -1
  405. package/dist/sdk/authentication.d.cts.map +0 -1
  406. package/dist/sdk/authentication.d.mts +0 -38
  407. package/dist/sdk/authentication.d.mts.map +0 -1
  408. package/dist/sdk/authentication.mjs +0 -112
  409. package/dist/sdk/authentication.mjs.map +0 -1
  410. package/dist/sdk/constants.cjs +0 -7
  411. package/dist/sdk/constants.cjs.map +0 -1
  412. package/dist/sdk/constants.d.cts.map +0 -1
  413. package/dist/sdk/constants.d.mts +0 -4
  414. package/dist/sdk/constants.d.mts.map +0 -1
  415. package/dist/sdk/constants.mjs.map +0 -1
  416. package/dist/sdk/errors.cjs +0 -76
  417. package/dist/sdk/errors.cjs.map +0 -1
  418. package/dist/sdk/errors.d.cts +0 -34
  419. package/dist/sdk/errors.d.cts.map +0 -1
  420. package/dist/sdk/errors.d.mts.map +0 -1
  421. package/dist/sdk/errors.mjs.map +0 -1
  422. package/dist/sdk/index.cjs +0 -24
  423. package/dist/sdk/index.cjs.map +0 -1
  424. package/dist/sdk/index.d.cts +0 -8
  425. package/dist/sdk/index.d.cts.map +0 -1
  426. package/dist/sdk/index.d.mts +0 -8
  427. package/dist/sdk/index.d.mts.map +0 -1
  428. package/dist/sdk/index.mjs +0 -8
  429. package/dist/sdk/index.mjs.map +0 -1
  430. package/dist/sdk/mocks/auth.cjs +0 -82
  431. package/dist/sdk/mocks/auth.cjs.map +0 -1
  432. package/dist/sdk/mocks/auth.d.cts.map +0 -1
  433. package/dist/sdk/mocks/auth.d.mts +0 -69
  434. package/dist/sdk/mocks/auth.d.mts.map +0 -1
  435. package/dist/sdk/mocks/auth.mjs.map +0 -1
  436. package/dist/sdk/mocks/userstorage.cjs +0 -43
  437. package/dist/sdk/mocks/userstorage.cjs.map +0 -1
  438. package/dist/sdk/mocks/userstorage.d.cts.map +0 -1
  439. package/dist/sdk/mocks/userstorage.d.mts +0 -10
  440. package/dist/sdk/mocks/userstorage.d.mts.map +0 -1
  441. package/dist/sdk/mocks/userstorage.mjs.map +0 -1
  442. package/dist/sdk/user-storage.cjs +0 -386
  443. package/dist/sdk/user-storage.cjs.map +0 -1
  444. package/dist/sdk/user-storage.d.cts +0 -47
  445. package/dist/sdk/user-storage.d.cts.map +0 -1
  446. package/dist/sdk/user-storage.d.mts.map +0 -1
  447. package/dist/sdk/user-storage.mjs +0 -358
  448. package/dist/sdk/user-storage.mjs.map +0 -1
  449. package/dist/sdk/utils/eip-6963-metamask-provider.cjs +0 -70
  450. package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +0 -1
  451. package/dist/sdk/utils/eip-6963-metamask-provider.d.cts.map +0 -1
  452. package/dist/sdk/utils/eip-6963-metamask-provider.d.mts +0 -25
  453. package/dist/sdk/utils/eip-6963-metamask-provider.d.mts.map +0 -1
  454. package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +0 -1
  455. package/dist/sdk/utils/messaging-signing-snap-requests.cjs +0 -96
  456. package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +0 -1
  457. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +0 -41
  458. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +0 -1
  459. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +0 -1
  460. package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +0 -1
  461. package/dist/sdk/utils/validate-login-response.cjs +0 -49
  462. package/dist/sdk/utils/validate-login-response.cjs.map +0 -1
  463. package/dist/sdk/utils/validate-login-response.d.cts +0 -14
  464. package/dist/sdk/utils/validate-login-response.d.cts.map +0 -1
  465. package/dist/sdk/utils/validate-login-response.d.mts.map +0 -1
  466. package/dist/sdk/utils/validate-login-response.mjs.map +0 -1
  467. package/dist/sdk/utils/validate-pair-response.cjs +0 -29
  468. package/dist/sdk/utils/validate-pair-response.cjs.map +0 -1
  469. package/dist/sdk/utils/validate-pair-response.d.cts.map +0 -1
  470. package/dist/sdk/utils/validate-pair-response.d.mts +0 -26
  471. package/dist/sdk/utils/validate-pair-response.d.mts.map +0 -1
  472. package/dist/sdk/utils/validate-pair-response.mjs.map +0 -1
  473. package/dist/shared/encryption/cache.cjs +0 -77
  474. package/dist/shared/encryption/cache.cjs.map +0 -1
  475. package/dist/shared/encryption/cache.d.cts.map +0 -1
  476. package/dist/shared/encryption/cache.d.mts +0 -32
  477. package/dist/shared/encryption/cache.d.mts.map +0 -1
  478. package/dist/shared/encryption/cache.mjs.map +0 -1
  479. package/dist/shared/encryption/constants.cjs +0 -17
  480. package/dist/shared/encryption/constants.cjs.map +0 -1
  481. package/dist/shared/encryption/constants.d.cts.map +0 -1
  482. package/dist/shared/encryption/constants.d.mts +0 -9
  483. package/dist/shared/encryption/constants.d.mts.map +0 -1
  484. package/dist/shared/encryption/constants.mjs.map +0 -1
  485. package/dist/shared/encryption/encryption.cjs +0 -209
  486. package/dist/shared/encryption/encryption.cjs.map +0 -1
  487. package/dist/shared/encryption/encryption.d.cts.map +0 -1
  488. package/dist/shared/encryption/encryption.d.mts +0 -30
  489. package/dist/shared/encryption/encryption.d.mts.map +0 -1
  490. package/dist/shared/encryption/encryption.mjs +0 -205
  491. package/dist/shared/encryption/encryption.mjs.map +0 -1
  492. package/dist/shared/encryption/index.cjs +0 -25
  493. package/dist/shared/encryption/index.cjs.map +0 -1
  494. package/dist/shared/encryption/index.d.cts +0 -5
  495. package/dist/shared/encryption/index.d.cts.map +0 -1
  496. package/dist/shared/encryption/index.d.mts +0 -5
  497. package/dist/shared/encryption/index.d.mts.map +0 -1
  498. package/dist/shared/encryption/index.mjs +0 -5
  499. package/dist/shared/encryption/index.mjs.map +0 -1
  500. package/dist/shared/encryption/utils.cjs +0 -21
  501. package/dist/shared/encryption/utils.cjs.map +0 -1
  502. package/dist/shared/encryption/utils.d.cts.map +0 -1
  503. package/dist/shared/encryption/utils.d.mts +0 -5
  504. package/dist/shared/encryption/utils.d.mts.map +0 -1
  505. package/dist/shared/encryption/utils.mjs.map +0 -1
  506. package/dist/shared/env.cjs +0 -85
  507. package/dist/shared/env.cjs.map +0 -1
  508. package/dist/shared/env.d.cts +0 -34
  509. package/dist/shared/env.d.cts.map +0 -1
  510. package/dist/shared/env.d.mts.map +0 -1
  511. package/dist/shared/env.mjs.map +0 -1
  512. package/dist/shared/storage-schema.cjs +0 -42
  513. package/dist/shared/storage-schema.cjs.map +0 -1
  514. package/dist/shared/storage-schema.d.cts +0 -34
  515. package/dist/shared/storage-schema.d.cts.map +0 -1
  516. package/dist/shared/storage-schema.d.mts.map +0 -1
  517. package/dist/shared/storage-schema.mjs.map +0 -1
  518. package/dist/shared/types/encryption.cjs +0 -3
  519. package/dist/shared/types/encryption.cjs.map +0 -1
  520. package/dist/shared/types/encryption.d.cts.map +0 -1
  521. package/dist/shared/types/encryption.d.mts +0 -2
  522. package/dist/shared/types/encryption.d.mts.map +0 -1
  523. package/dist/shared/types/encryption.mjs +0 -2
  524. package/dist/shared/types/encryption.mjs.map +0 -1
  525. package/dist/shared/types/services.cjs +0 -3
  526. package/dist/shared/types/services.cjs.map +0 -1
  527. package/dist/shared/types/services.d.cts.map +0 -1
  528. package/dist/shared/types/services.d.mts +0 -17
  529. package/dist/shared/types/services.d.mts.map +0 -1
  530. package/dist/shared/types/services.mjs +0 -2
  531. package/dist/shared/types/services.mjs.map +0 -1
  532. package/dist/shared/utils/event-queue.cjs +0 -24
  533. package/dist/shared/utils/event-queue.cjs.map +0 -1
  534. package/dist/shared/utils/event-queue.d.cts.map +0 -1
  535. package/dist/shared/utils/event-queue.d.mts +0 -6
  536. package/dist/shared/utils/event-queue.d.mts.map +0 -1
  537. package/dist/shared/utils/event-queue.mjs.map +0 -1
@@ -0,0 +1,364 @@
1
+ import { SHARED_SALT } from '../shared/encryption/constants.js';
2
+ import encryption, { createSHA256Hash } from '../shared/encryption/index.js';
3
+ import { getEnvUrls } from '../shared/env.js';
4
+ import { createEntryPath } from '../shared/storage-schema.js';
5
+ import { NotFoundError, UserStorageError } from './errors.js';
6
+ export const STORAGE_URL = (env, encryptedPath) => `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;
7
+ export class UserStorage {
8
+ config;
9
+ options;
10
+ env;
11
+ constructor(config, options) {
12
+ this.env = config.env;
13
+ this.config = config;
14
+ this.options = options;
15
+ }
16
+ async setItem(path, value, options) {
17
+ await this.#upsertUserStorage(path, value, options);
18
+ }
19
+ async batchSetItems(path, values, options) {
20
+ await this.#batchUpsertUserStorage(path, values, options);
21
+ }
22
+ async getItem(path, options) {
23
+ return this.#getUserStorage(path, options);
24
+ }
25
+ async getAllFeatureItems(path, options) {
26
+ return this.#getUserStorageAllFeatureEntries(path, options);
27
+ }
28
+ async deleteItem(path, options) {
29
+ return this.#deleteUserStorage(path, options);
30
+ }
31
+ async deleteAllFeatureItems(path, options) {
32
+ return this.#deleteUserStorageAllFeatureEntries(path, options);
33
+ }
34
+ async batchDeleteItems(path, values, options) {
35
+ return this.#batchDeleteUserStorage(path, values, options);
36
+ }
37
+ async getStorageKey(entropySourceId) {
38
+ const userProfile = await this.config.auth.getUserProfile(entropySourceId);
39
+ const message = `metamask:${userProfile.profileId}`;
40
+ const storageKey = await this.options.storage?.getStorageKey(message, entropySourceId);
41
+ if (storageKey) {
42
+ return storageKey;
43
+ }
44
+ const storageKeySignature = await this.config.auth.signMessage(message, entropySourceId);
45
+ const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);
46
+ await this.options.storage?.setStorageKey(message, hashedStorageKeySignature, entropySourceId);
47
+ return hashedStorageKeySignature;
48
+ }
49
+ async #upsertUserStorage(path, data, options) {
50
+ const entropySourceId = options?.entropySourceId;
51
+ try {
52
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
53
+ const profileScopeHeader = await this.#getProfileScopeHeader(entropySourceId, options?.useCanonicalScope);
54
+ const storageKey = await this.getStorageKey(entropySourceId);
55
+ const encryptedData = await encryption.encryptString(data, storageKey, options?.nativeScryptCrypto);
56
+ const encryptedPath = createEntryPath(path, storageKey);
57
+ const url = new URL(STORAGE_URL(this.env, encryptedPath));
58
+ const response = await fetch(url.toString(), {
59
+ method: 'PUT',
60
+ headers: {
61
+ 'Content-Type': 'application/json',
62
+ ...headers,
63
+ ...profileScopeHeader,
64
+ },
65
+ body: JSON.stringify({ data: encryptedData }),
66
+ });
67
+ if (!response.ok) {
68
+ const responseBody = await response.json().catch(() => ({
69
+ message: 'unknown',
70
+ error: 'unknown',
71
+ }));
72
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
73
+ }
74
+ }
75
+ catch (e) {
76
+ /* istanbul ignore next */
77
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
78
+ throw new UserStorageError(`failed to upsert user storage for path '${path}'. ${errorMessage}`);
79
+ }
80
+ }
81
+ async #batchUpsertUserStorage(path, data, options) {
82
+ const entropySourceId = options?.entropySourceId;
83
+ try {
84
+ if (!data.length) {
85
+ return;
86
+ }
87
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
88
+ const profileScopeHeader = await this.#getProfileScopeHeader(entropySourceId, options?.useCanonicalScope);
89
+ const storageKey = await this.getStorageKey(entropySourceId);
90
+ const encryptedData = await Promise.all(data.map(async (d) => {
91
+ return [
92
+ this.#createEntryKey(d[0], storageKey),
93
+ await encryption.encryptString(d[1], storageKey, options?.nativeScryptCrypto),
94
+ ];
95
+ }));
96
+ const url = new URL(STORAGE_URL(this.env, path));
97
+ const response = await fetch(url.toString(), {
98
+ method: 'PUT',
99
+ headers: {
100
+ 'Content-Type': 'application/json',
101
+ ...headers,
102
+ ...profileScopeHeader,
103
+ },
104
+ body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),
105
+ });
106
+ if (!response.ok) {
107
+ const responseBody = await response.json().catch(() => ({
108
+ message: 'unknown',
109
+ error: 'unknown',
110
+ }));
111
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
112
+ }
113
+ }
114
+ catch (e) {
115
+ /* istanbul ignore next */
116
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
117
+ throw new UserStorageError(`failed to batch upsert user storage for path '${path}'. ${errorMessage}`);
118
+ }
119
+ }
120
+ async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(path, encryptedData, entropySourceId, useCanonicalScope) {
121
+ try {
122
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
123
+ const profileScopeHeader = await this.#getProfileScopeHeader(entropySourceId, useCanonicalScope);
124
+ const url = new URL(STORAGE_URL(this.env, path));
125
+ const response = await fetch(url.toString(), {
126
+ method: 'PUT',
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ ...headers,
130
+ ...profileScopeHeader,
131
+ },
132
+ body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),
133
+ });
134
+ // istanbul ignore next
135
+ if (!response.ok) {
136
+ const responseBody = await response.json().catch(() => ({
137
+ message: 'unknown',
138
+ error: 'unknown',
139
+ }));
140
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
141
+ }
142
+ }
143
+ catch (e) {
144
+ /* istanbul ignore next */
145
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
146
+ // istanbul ignore next
147
+ throw new UserStorageError(`failed to batch upsert user storage for path '${path}'. ${errorMessage}`);
148
+ }
149
+ }
150
+ async #getUserStorage(path, options) {
151
+ const entropySourceId = options?.entropySourceId;
152
+ try {
153
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
154
+ const storageKey = await this.getStorageKey(entropySourceId);
155
+ const encryptedPath = createEntryPath(path, storageKey);
156
+ const url = new URL(STORAGE_URL(this.env, encryptedPath));
157
+ const response = await fetch(url.toString(), {
158
+ headers: {
159
+ 'Content-Type': 'application/json',
160
+ ...headers,
161
+ },
162
+ });
163
+ if (response.status === 404) {
164
+ return null;
165
+ }
166
+ if (!response.ok) {
167
+ const responseBody = (await response.json());
168
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
169
+ }
170
+ const userStorage = await response.json();
171
+ const encryptedData = userStorage?.Data ?? null;
172
+ if (!encryptedData) {
173
+ return null;
174
+ }
175
+ const decryptedData = await encryption.decryptString(encryptedData, storageKey, options?.nativeScryptCrypto);
176
+ // Re-encrypt the entry if it was encrypted with a random salt
177
+ const salt = encryption.getSalt(encryptedData);
178
+ if (salt.toString() !== SHARED_SALT.toString()) {
179
+ await this.#upsertUserStorage(path, decryptedData, options);
180
+ }
181
+ return decryptedData;
182
+ }
183
+ catch (e) {
184
+ /* istanbul ignore next */
185
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
186
+ throw new UserStorageError(`failed to get user storage for path '${path}'. ${errorMessage}`);
187
+ }
188
+ }
189
+ async #getUserStorageAllFeatureEntries(path, options) {
190
+ const entropySourceId = options?.entropySourceId;
191
+ try {
192
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
193
+ const profileScopeHeader = await this.#getProfileScopeHeader(entropySourceId, options?.useCanonicalScope);
194
+ const storageKey = await this.getStorageKey(entropySourceId);
195
+ const url = new URL(STORAGE_URL(this.env, path));
196
+ const response = await fetch(url.toString(), {
197
+ headers: {
198
+ 'Content-Type': 'application/json',
199
+ ...headers,
200
+ ...profileScopeHeader,
201
+ },
202
+ });
203
+ if (response.status === 404) {
204
+ return null;
205
+ }
206
+ if (!response.ok) {
207
+ const responseBody = (await response.json());
208
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
209
+ }
210
+ const userStorage = await response.json();
211
+ if (!Array.isArray(userStorage)) {
212
+ return null;
213
+ }
214
+ const decryptedData = [];
215
+ const reEncryptedEntries = [];
216
+ for (const entry of userStorage) {
217
+ if (!entry.Data) {
218
+ continue;
219
+ }
220
+ try {
221
+ const data = await encryption.decryptString(entry.Data, storageKey, options?.nativeScryptCrypto);
222
+ decryptedData.push(data);
223
+ // Re-encrypt the entry was encrypted with a random salt
224
+ const salt = encryption.getSalt(entry.Data);
225
+ if (salt.toString() !== SHARED_SALT.toString()) {
226
+ reEncryptedEntries.push([
227
+ entry.HashedKey,
228
+ await encryption.encryptString(data, storageKey, options?.nativeScryptCrypto),
229
+ ]);
230
+ }
231
+ }
232
+ catch {
233
+ // do nothing
234
+ }
235
+ }
236
+ // Re-upload the re-encrypted entries
237
+ if (reEncryptedEntries.length) {
238
+ await this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(path, reEncryptedEntries, entropySourceId, options?.useCanonicalScope);
239
+ }
240
+ return decryptedData;
241
+ }
242
+ catch (e) {
243
+ /* istanbul ignore next */
244
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
245
+ throw new UserStorageError(`failed to get user storage for path '${path}'. ${errorMessage}`);
246
+ }
247
+ }
248
+ async #deleteUserStorage(path, options) {
249
+ const entropySourceId = options?.entropySourceId;
250
+ try {
251
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
252
+ const storageKey = await this.getStorageKey(entropySourceId);
253
+ const encryptedPath = createEntryPath(path, storageKey);
254
+ const url = new URL(STORAGE_URL(this.env, encryptedPath));
255
+ const response = await fetch(url.toString(), {
256
+ method: 'DELETE',
257
+ headers: {
258
+ 'Content-Type': 'application/json',
259
+ ...headers,
260
+ },
261
+ });
262
+ if (response.status === 404) {
263
+ throw new NotFoundError(`feature/key set not found for path '${path}'.`);
264
+ }
265
+ if (!response.ok) {
266
+ const responseBody = (await response.json());
267
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
268
+ }
269
+ }
270
+ catch (e) {
271
+ if (e instanceof NotFoundError) {
272
+ throw e;
273
+ }
274
+ /* istanbul ignore next */
275
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
276
+ throw new UserStorageError(`failed to delete user storage for path '${path}'. ${errorMessage}`);
277
+ }
278
+ }
279
+ async #deleteUserStorageAllFeatureEntries(path, options) {
280
+ try {
281
+ const entropySourceId = options?.entropySourceId;
282
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
283
+ const profileScopeHeader = await this.#getProfileScopeHeader(entropySourceId, options?.useCanonicalScope);
284
+ const url = new URL(STORAGE_URL(this.env, path));
285
+ const response = await fetch(url.toString(), {
286
+ method: 'DELETE',
287
+ headers: {
288
+ 'Content-Type': 'application/json',
289
+ ...headers,
290
+ ...profileScopeHeader,
291
+ },
292
+ });
293
+ if (response.status === 404) {
294
+ throw new NotFoundError(`feature not found for path '${path}'.`);
295
+ }
296
+ if (!response.ok) {
297
+ const responseBody = (await response.json());
298
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
299
+ }
300
+ }
301
+ catch (e) {
302
+ if (e instanceof NotFoundError) {
303
+ throw e;
304
+ }
305
+ /* istanbul ignore next */
306
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
307
+ throw new UserStorageError(`failed to delete user storage for path '${path}'. ${errorMessage}`);
308
+ }
309
+ }
310
+ async #batchDeleteUserStorage(path, keysToDelete, options) {
311
+ try {
312
+ if (!keysToDelete.length) {
313
+ return;
314
+ }
315
+ const entropySourceId = options?.entropySourceId;
316
+ const headers = await this.#getAuthorizationHeader(entropySourceId);
317
+ const storageKey = await this.getStorageKey(entropySourceId);
318
+ const rawEntryKeys = keysToDelete.map((d) => this.#createEntryKey(d, storageKey));
319
+ const url = new URL(STORAGE_URL(this.env, path));
320
+ const response = await fetch(url.toString(), {
321
+ method: 'PUT',
322
+ headers: {
323
+ 'Content-Type': 'application/json',
324
+ ...headers,
325
+ },
326
+ body: JSON.stringify({ batch_delete: rawEntryKeys }),
327
+ });
328
+ if (!response.ok) {
329
+ const responseBody = await response.json().catch(() => ({
330
+ message: 'unknown',
331
+ error: 'unknown',
332
+ }));
333
+ throw new Error(`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`);
334
+ }
335
+ }
336
+ catch (e) {
337
+ /* istanbul ignore next */
338
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
339
+ throw new UserStorageError(`failed to batch delete user storage for path '${path}'. ${errorMessage}`);
340
+ }
341
+ }
342
+ #createEntryKey(key, storageKey) {
343
+ return createSHA256Hash(key + storageKey);
344
+ }
345
+ async #getAuthorizationHeader(entropySourceId) {
346
+ const accessToken = await this.config.auth.getAccessToken(entropySourceId);
347
+ return { Authorization: `Bearer ${accessToken}` };
348
+ }
349
+ async #getProfileScopeHeader(entropySourceId, useCanonicalScope) {
350
+ if (useCanonicalScope) {
351
+ return {};
352
+ }
353
+ const profile = await this.config.auth.getUserProfile(entropySourceId);
354
+ if (profile.profileId !== profile.canonicalProfileId) {
355
+ // After SRP pairing the JWT `sub` is the canonical profile id, but
356
+ // user storage data is still keyed by the original per-SRP profileId.
357
+ // The `x-profile-id` header tells the backend to scope reads/writes to
358
+ // that alias partition until ADR 0005 migrates storage keys to canonical.
359
+ return { 'x-profile-id': profile.profileId };
360
+ }
361
+ return {};
362
+ }
363
+ }
364
+ //# sourceMappingURL=user-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-storage.js","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAO9C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,aAAqB,EAAE,EAAE,CAC7D,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,aAAa,EAAE,CAAC;AA8C7E,MAAM,OAAO,WAAW;IACZ,MAAM,CAAoB;IAE7B,OAAO,CAAqB;IAEzB,GAAG,CAAM;IAEnB,YAAY,MAAyB,EAAE,OA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{ createSHA256Hash } from '../shared/encryption/index.js';\nimport type { Env } from '../shared/env.js';\nimport { getEnvUrls } from '../shared/env.js';\nimport type {\n UserStorageGenericFeatureKey,\n UserStorageGenericFeatureName,\n UserStorageGenericPathWithFeatureAndKey,\n UserStorageGenericPathWithFeatureOnly,\n} from '../shared/storage-schema.js';\nimport { createEntryPath } from '../shared/storage-schema.js';\nimport type { NativeScrypt } from '../shared/types/encryption.js';\nimport type { IBaseAuth } from './authentication-jwt-bearer/types.js';\nimport { NotFoundError, UserStorageError } from './errors.js';\n\nexport const STORAGE_URL = (env: Env, encryptedPath: string) =>\n `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;\n\nexport type UserStorageConfig = {\n env: Env;\n auth: Pick<IBaseAuth, 'getAccessToken' | 'getUserProfile' | 'signMessage'>;\n};\n\nexport type StorageOptions = {\n getStorageKey: (\n message: `metamask:${string}`,\n entropySourceId?: string,\n ) => Promise<string | null>;\n setStorageKey: (\n message: `metamask:${string}`,\n val: string,\n entropySourceId?: string,\n ) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n HashedKey: string;\n\n Data: string;\n}[];\n\nexport type UserStorageMethodOptions = {\n nativeScryptCrypto?: NativeScrypt;\n entropySourceId?: string;\n /**\n * When true, skip the `x-profile-id` header on feature-scoped requests,\n * letting the server default to the JWT `sub` (canonical profile ID).\n * Useful during canonical storage migration (ADR 0005) to read/verify\n * data stored under the canonical key.\n */\n useCanonicalScope?: boolean;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n public options: UserStorageOptions;\n\n protected env: Env;\n\n constructor(config: UserStorageConfig, options: UserStorageOptions) {\n this.env = config.env;\n this.config = config;\n this.options = options;\n }\n\n async setItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n value: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n await this.#upsertUserStorage(path, value, options);\n }\n\n async batchSetItems(\n path: UserStorageGenericFeatureName,\n values: [UserStorageGenericFeatureKey, string][],\n options?: UserStorageMethodOptions,\n ) {\n await this.#batchUpsertUserStorage(path, values, options);\n }\n\n async getItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n return this.#getUserStorage(path, options);\n }\n\n async getAllFeatureItems(\n path: UserStorageGenericFeatureName,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n return this.#getUserStorageAllFeatureEntries(path, options);\n }\n\n async deleteItem(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n return this.#deleteUserStorage(path, options);\n }\n\n async deleteAllFeatureItems(\n path: UserStorageGenericFeatureName,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n return this.#deleteUserStorageAllFeatureEntries(path, options);\n }\n\n async batchDeleteItems(\n path: UserStorageGenericFeatureName,\n values: UserStorageGenericFeatureKey[],\n options?: UserStorageMethodOptions,\n ) {\n return this.#batchDeleteUserStorage(path, values, options);\n }\n\n async getStorageKey(entropySourceId?: string): Promise<string> {\n const userProfile = await this.config.auth.getUserProfile(entropySourceId);\n const message = `metamask:${userProfile.profileId}` as const;\n\n const storageKey = await this.options.storage?.getStorageKey(\n message,\n entropySourceId,\n );\n if (storageKey) {\n return storageKey;\n }\n\n const storageKeySignature = await this.config.auth.signMessage(\n message,\n entropySourceId,\n );\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(\n message,\n hashedStorageKeySignature,\n entropySourceId,\n );\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n data: string,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const profileScopeHeader = await this.#getProfileScopeHeader(\n entropySourceId,\n options?.useCanonicalScope,\n );\n const storageKey = await this.getStorageKey(entropySourceId);\n const encryptedData = await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n ...profileScopeHeader,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchUpsertUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n data: [string, string][],\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n const entropySourceId = options?.entropySourceId;\n try {\n if (!data.length) {\n return;\n }\n\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const profileScopeHeader = await this.#getProfileScopeHeader(\n entropySourceId,\n options?.useCanonicalScope,\n );\n const storageKey = await this.getStorageKey(entropySourceId);\n\n const encryptedData = await Promise.all(\n data.map(async (d) => {\n return [\n this.#createEntryKey(d[0], storageKey),\n await encryption.encryptString(\n d[1],\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ];\n }),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n ...profileScopeHeader,\n },\n body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n encryptedData: [string, string][],\n entropySourceId?: string,\n useCanonicalScope?: boolean,\n ): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const profileScopeHeader = await this.#getProfileScopeHeader(\n entropySourceId,\n useCanonicalScope,\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n ...profileScopeHeader,\n },\n body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),\n });\n\n // istanbul ignore next\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n // istanbul ignore next\n throw new UserStorageError(\n `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<string | null> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const userStorage = await response.json();\n const encryptedData = userStorage?.Data ?? null;\n\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = await encryption.decryptString(\n encryptedData,\n storageKey,\n options?.nativeScryptCrypto,\n );\n\n // Re-encrypt the entry if it was encrypted with a random salt\n const salt = encryption.getSalt(encryptedData);\n if (salt.toString() !== SHARED_SALT.toString()) {\n await this.#upsertUserStorage(path, decryptedData, options);\n }\n\n return decryptedData;\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n options?: UserStorageMethodOptions,\n ): Promise<string[] | null> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const profileScopeHeader = await this.#getProfileScopeHeader(\n entropySourceId,\n options?.useCanonicalScope,\n );\n const storageKey = await this.getStorageKey(entropySourceId);\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n ...profileScopeHeader,\n },\n });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n await response.json();\n\n if (!Array.isArray(userStorage)) {\n return null;\n }\n\n const decryptedData: string[] = [];\n const reEncryptedEntries: [string, string][] = [];\n\n for (const entry of userStorage) {\n if (!entry.Data) {\n continue;\n }\n\n try {\n const data = await encryption.decryptString(\n entry.Data,\n storageKey,\n options?.nativeScryptCrypto,\n );\n decryptedData.push(data);\n\n // Re-encrypt the entry was encrypted with a random salt\n const salt = encryption.getSalt(entry.Data);\n if (salt.toString() !== SHARED_SALT.toString()) {\n reEncryptedEntries.push([\n entry.HashedKey,\n await encryption.encryptString(\n data,\n storageKey,\n options?.nativeScryptCrypto,\n ),\n ]);\n }\n } catch {\n // do nothing\n }\n }\n\n // Re-upload the re-encrypted entries\n if (reEncryptedEntries.length) {\n await this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n path,\n reEncryptedEntries,\n entropySourceId,\n options?.useCanonicalScope,\n );\n }\n\n return decryptedData;\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #deleteUserStorage(\n path: UserStorageGenericPathWithFeatureAndKey,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n const entropySourceId = options?.entropySourceId;\n try {\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(\n `feature/key set not found for path '${path}'.`,\n );\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #deleteUserStorageAllFeatureEntries(\n path: UserStorageGenericPathWithFeatureOnly,\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n const entropySourceId = options?.entropySourceId;\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const profileScopeHeader = await this.#getProfileScopeHeader(\n entropySourceId,\n options?.useCanonicalScope,\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'DELETE',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n ...profileScopeHeader,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(`feature not found for path '${path}'.`);\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #batchDeleteUserStorage(\n path: UserStorageGenericPathWithFeatureOnly,\n keysToDelete: string[],\n options?: UserStorageMethodOptions,\n ): Promise<void> {\n try {\n if (!keysToDelete.length) {\n return;\n }\n\n const entropySourceId = options?.entropySourceId;\n const headers = await this.#getAuthorizationHeader(entropySourceId);\n const storageKey = await this.getStorageKey(entropySourceId);\n\n const rawEntryKeys = keysToDelete.map((d) =>\n this.#createEntryKey(d, storageKey),\n );\n\n const url = new URL(STORAGE_URL(this.env, path));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n\n body: JSON.stringify({ batch_delete: rawEntryKeys }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to batch delete user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n #createEntryKey(key: string, storageKey: string): string {\n return createSHA256Hash(key + storageKey);\n }\n\n async #getAuthorizationHeader(\n entropySourceId?: string,\n ): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken(entropySourceId);\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async #getProfileScopeHeader(\n entropySourceId?: string,\n useCanonicalScope?: boolean,\n ): Promise<Record<string, string>> {\n if (useCanonicalScope) {\n return {};\n }\n const profile = await this.config.auth.getUserProfile(entropySourceId);\n if (profile.profileId !== profile.canonicalProfileId) {\n // After SRP pairing the JWT `sub` is the canonical profile id, but\n // user storage data is still keyed by the original per-SRP profileId.\n // The `x-profile-id` header tells the backend to scope reads/writes to\n // that alias partition until ADR 0005 migrates storage keys to canonical.\n return { 'x-profile-id': profile.profileId };\n }\n return {};\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Eip1193Provider } from "ethers";
1
+ import type { Eip1193Provider } from 'ethers';
2
2
  export type AnnounceProviderEventDetail = {
3
3
  info?: {
4
4
  rdns?: string;
@@ -22,4 +22,4 @@ type MetaMaskClientType = 'any' | MetamaskClientRdnsKey;
22
22
  */
23
23
  export declare function getMetaMaskProviderEIP6963(type?: MetaMaskClientType): Promise<Eip1193Provider | null>;
24
24
  export {};
25
- //# sourceMappingURL=eip-6963-metamask-provider.d.cts.map
25
+ //# sourceMappingURL=eip-6963-metamask-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eip-6963-metamask-provider.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/eip-6963-metamask-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9C,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,2BAA2B,CAAC,CAAC;AAE7E,eAAO,MAAM,mBAAmB;IAC9B,IAAI;IACJ,KAAK;IACL,aAAa;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAErE,KAAK,kBAAkB,GAAG,KAAK,GAAG,qBAAqB,CAAC;AAKxD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,GAAE,kBAA0B,GAC/B,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CA2DjC"}
@@ -63,4 +63,4 @@ export function getMetaMaskProviderEIP6963(type = 'any') {
63
63
  }, 100);
64
64
  });
65
65
  }
66
- //# sourceMappingURL=eip-6963-metamask-provider.mjs.map
66
+ //# sourceMappingURL=eip-6963-metamask-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eip-6963-metamask-provider.js","sourceRoot":"","sources":["../../../src/sdk/utils/eip-6963-metamask-provider.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE,mBAAmB;IAC1B,aAAa,EAAE,iBAAiB;CACjC,CAAC;AAMF,oFAAoF;AACpF,MAAM,aAAa,GAAyD,EAAE,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAI,GAAuB,KAAK;IAEhC,OAAO,IAAI,OAAO,CAAyB,CAAC,OAAO,EAAE,EAAE;QACrD,IAAI,IAAI,KAAK,KAAK,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAC;YACd,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,CAAC,cAAc,CAAC,CAAC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AAQ,IAAI,IAAI,CAAC;YACrE,CAAC;YAED,IAAI,QAAQ,EAAE,CAAC;gBACb,aAAa,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;YACjC,CAAC;YACD,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\n// We can isolate and create a metamask function/closure\nexport type AnnounceProviderEventDetail = {\n info?: { rdns?: string };\n provider?: Eip1193Provider;\n};\nexport type AnnounceProviderEvent = CustomEvent<AnnounceProviderEventDetail>;\n\nexport const metamaskClientsRdns = {\n main: 'io.metamask',\n flask: 'io.metamask.flask',\n institutional: 'io.metamask.mmi',\n};\n\nexport type MetamaskClientRdnsKey = keyof typeof metamaskClientsRdns;\n\ntype MetaMaskClientType = 'any' | MetamaskClientRdnsKey;\n\n// Cache, as when the function is recalled, we can reuse instead of continue waiting\nconst providerCache: Partial<Record<MetaMaskClientType, Eip1193Provider>> = {};\n\n/**\n * This uses EIP6963 to find all metamask accounts and returns the first matching provider\n * the consumer requests (main, flask, institutional, or any)\n *\n * @param type - the MetaMask Wallet type (main, flask, institutional, or any)\n * @returns a ethers provider so you can make requests to that specific wallet\n */\nexport function getMetaMaskProviderEIP6963(\n type: MetaMaskClientType = 'any',\n): Promise<Eip1193Provider | null> {\n return new Promise<Eip1193Provider | null>((resolve) => {\n if (type !== 'any' && metamaskClientsRdns[type] === undefined) {\n resolve(null);\n return;\n }\n\n const cachedProvider = providerCache[type];\n if (cachedProvider) {\n resolve(cachedProvider);\n return;\n }\n\n const providers: { rdns: string; provider: Eip1193Provider }[] = [];\n\n const handleProviderEvent = (event: unknown) => {\n const typedEvent = event as CustomEvent<AnnounceProviderEventDetail>;\n const providerDetail = typedEvent?.detail;\n if (providerDetail?.provider && providerDetail?.info?.rdns) {\n providers.push({\n rdns: providerDetail?.info?.rdns,\n provider: providerDetail?.provider,\n });\n }\n };\n\n window.addEventListener('eip6963:announceProvider', handleProviderEvent);\n window.dispatchEvent(new Event('eip6963:requestProvider'));\n\n /**\n * It may take some time for the events to be emitted from the different wallets.\n * So waiting a small period of time before we use the collected events.\n */\n setTimeout(() => {\n // remove attached listener\n window.removeEventListener(\n 'eip6963:announceProvider',\n handleProviderEvent,\n );\n\n let provider: Eip1193Provider | null;\n if (type === 'any') {\n // return the first MM client we find\n const metamaskClients = Object.values(metamaskClientsRdns);\n provider =\n providers.find((p) => metamaskClients.includes(p.rdns))?.provider ??\n null;\n } else {\n const metamaskRdns = metamaskClientsRdns[type];\n provider =\n providers.find((p) => p.rdns === metamaskRdns)?.provider ?? null;\n }\n\n if (provider) {\n providerCache[type] = provider;\n }\n return resolve(provider);\n }, 100);\n });\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Eip1193Provider } from "ethers";
1
+ import type { Eip1193Provider } from 'ethers';
2
2
  export type Snap = {
3
3
  permissionName: string;
4
4
  id: string;
@@ -38,4 +38,4 @@ export declare const MESSAGE_SIGNING_SNAP: {
38
38
  * @param message - The message to check.
39
39
  */
40
40
  export declare function assertMessageStartsWithMetamask(message: string): asserts message is `metamask:${string}`;
41
- //# sourceMappingURL=messaging-signing-snap-requests.d.mts.map
41
+ //# sourceMappingURL=messaging-signing-snap-requests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messaging-signing-snap-requests.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5E;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAM3B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,eAAO,MAAM,oBAAoB;IACzB,YAAY,WAAW,eAAe,oBAAoB,MAAM;IAehE,WAAW,WACL,eAAe,WAChB,YAAY,MAAM,EAAE,oBACX,MAAM;CAkB3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,IAAI,YAAY,MAAM,EAAE,CAIzC"}
@@ -86,4 +86,4 @@ export function assertMessageStartsWithMetamask(message) {
86
86
  throw new Error('Message must start with "metamask:"');
87
87
  }
88
88
  }
89
- //# sourceMappingURL=messaging-signing-snap-requests.mjs.map
89
+ //# sourceMappingURL=messaging-signing-snap-requests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messaging-signing-snap-requests.js","sourceRoot":"","sources":["../../../src/sdk/utils/messaging-signing-snap-requests.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,WAAW,GAAG,oCAAoC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAyB;IACzD,MAAM,MAAM,GAAW,MAAM,QAAQ,CAAC,OAAO,CAAC;QAC5C,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,WAAW,CAAC,EAAE,EAAE;SAClB;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CA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,mBAAmB;YAC3B,MAAM,EAAE;gBACN,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE;oBACP,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE;wBACN,OAAO;wBACP,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAChD;iBACF;aACF;SACF,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAe;IAEf,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;AACH,CAAC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nexport type Snap = {\n permissionName: string;\n id: string;\n version: string;\n initialPermissions: Record<string, unknown>;\n};\nexport type GetSnapsResponse = Record<string, Snap>;\n\nexport const SNAP_ORIGIN = 'npm:@metamask/message-signing-snap';\n\n/**\n * Requests Connection to the Message Signing Snap\n *\n * @param provider - MetaMask Wallet Provider\n * @returns snap connect result\n */\nexport async function connectSnap(provider: Eip1193Provider): Promise<string> {\n const result: string = await provider.request({\n method: 'wallet_requestSnaps',\n params: {\n [SNAP_ORIGIN]: {},\n },\n });\n\n return result;\n}\n\n/**\n * Gets Snaps from a MetaMask Wallet\n *\n * @param provider - MetaMask Wallet Provider\n * @returns All currently installed snaps.\n */\nexport async function getSnaps(\n provider: Eip1193Provider,\n): Promise<GetSnapsResponse> {\n const result: GetSnapsResponse = await provider.request({\n method: 'wallet_getSnaps',\n });\n\n return result;\n}\n\n/**\n * Check if snap is connected\n *\n * @param provider - MetaMask Wallet Provider\n * @returns if snap is connected\n */\nexport async function isSnapConnected(\n provider: Eip1193Provider,\n): Promise<boolean> {\n try {\n const snaps = await getSnaps(provider);\n if (!snaps) {\n return false;\n }\n return Object.keys(snaps).includes(SNAP_ORIGIN);\n } catch (e) {\n console.error('Failed to determine if snap is connected', e);\n return false;\n }\n}\n\nexport const MESSAGE_SIGNING_SNAP = {\n async getPublicKey(provider: Eip1193Provider, entropySourceId?: string) {\n const publicKey: string = await provider.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: SNAP_ORIGIN,\n request: {\n method: 'getPublicKey',\n ...(entropySourceId ? { params: { entropySourceId } } : {}),\n },\n },\n });\n\n return publicKey;\n },\n\n async signMessage(\n provider: Eip1193Provider,\n message: `metamask:${string}`,\n entropySourceId?: string,\n ) {\n const signedMessage: string = await provider?.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: SNAP_ORIGIN,\n request: {\n method: 'signMessage',\n params: {\n message,\n ...(entropySourceId ? { entropySourceId } : {}),\n },\n },\n },\n });\n\n return signedMessage;\n },\n};\n\n/**\n * Asserts that a message starts with \"metamask:\"\n *\n * @param message - The message to check.\n */\nexport function assertMessageStartsWithMetamask(\n message: string,\n): asserts message is `metamask:${string}` {\n if (!message.startsWith('metamask:')) {\n throw new Error('Message must start with \"metamask:\"');\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { LoginResponse } from "../authentication.mjs";
1
+ import type { LoginResponse } from '../authentication.js';
2
2
  /**
3
3
  * Validates that the input is a well-formed, non-expired LoginResponse.
4
4
  *
@@ -11,4 +11,4 @@ import type { LoginResponse } from "../authentication.mjs";
11
11
  * @returns boolean if input is a valid, non-expired LoginResponse
12
12
  */
13
13
  export declare function validateLoginResponse(input: unknown): input is LoginResponse;
14
- //# sourceMappingURL=validate-login-response.d.mts.map
14
+ //# sourceMappingURL=validate-login-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-login-response.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAgB5E"}
@@ -42,4 +42,4 @@ function isJwtExpired(token) {
42
42
  return true;
43
43
  }
44
44
  }
45
- //# sourceMappingURL=validate-login-response.mjs.map
45
+ //# sourceMappingURL=validate-login-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-login-response.js","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,YAAY,GAAG,KAAsB,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { LoginResponse } from '../authentication.js';\n\n/**\n * Validates that the input is a well-formed, non-expired LoginResponse.\n *\n * Checks structural shape (token + profile objects exist) and verifies\n * the JWT access token's `exp` claim is still in the future. This acts\n * as a hard guard against stale cached tokens regardless of client-side\n * TTL tracking (obtainedAt / expiresIn), which can be corrupted.\n *\n * @param input - unknown/untyped input\n * @returns boolean if input is a valid, non-expired LoginResponse\n */\nexport function validateLoginResponse(input: unknown): input is LoginResponse {\n const assumedInput = input as LoginResponse;\n\n if (!assumedInput) {\n return false;\n }\n\n if (!assumedInput?.token || !assumedInput?.profile) {\n return false;\n }\n\n if (isJwtExpired(assumedInput.token.accessToken)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Checks whether a JWT has expired by decoding its `exp` claim.\n *\n * @param token - A JWT string.\n * @returns true if the token is expired or cannot be decoded; false if still valid.\n */\nfunction isJwtExpired(token: string): boolean {\n try {\n const parts = token.split('.');\n if (parts.length !== 3) {\n return true;\n }\n const base64 = parts[1].replace(/-/gu, '+').replace(/_/gu, '/');\n const { exp } = JSON.parse(atob(base64));\n return !Number.isInteger(exp) || exp * 1000 <= Date.now();\n } catch {\n return true;\n }\n}\n"]}
@@ -23,4 +23,4 @@ export type RawPairResponse = {
23
23
  */
24
24
  export declare function validatePairResponse(input: unknown): asserts input is RawPairResponse;
25
25
  export {};
26
- //# sourceMappingURL=validate-pair-response.d.cts.map
26
+ //# sourceMappingURL=validate-pair-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-pair-response.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-pair-response.ts"],"names":[],"mappings":"AAEA,KAAK,eAAe,GAAG;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE;QACP,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,eAAe,CAAC,EAAE,eAAe,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,eAAe,CAwBlC"}
@@ -22,4 +22,4 @@ export function validatePairResponse(input) {
22
22
  throw new Error('validatePairResponse: profile.identifier_id is missing or empty');
23
23
  }
24
24
  }
25
- //# sourceMappingURL=validate-pair-response.mjs.map
25
+ //# sourceMappingURL=validate-pair-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-pair-response.js","sourceRoot":"","sources":["../../../src/sdk/utils/validate-pair-response.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAiBzD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc;IAEd,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,KAAgC,CAAC;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,OAA8C,CAAC;IACvE,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n\ntype RawProfileAlias = {\n alias_profile_id: string;\n canonical_profile_id: string;\n identifier_ids: { id: string; type: string }[];\n};\n\nexport type RawPairResponse = {\n profile: {\n profile_id: string;\n identifier_id: string;\n metametrics_id?: string;\n };\n profile_aliases?: RawProfileAlias[];\n};\n\n/**\n * Asserts that the raw API response from the profile pairing endpoint has the\n * expected shape before we attempt to map it into a `PairProfilesResponse`.\n * Throws if the response is malformed.\n *\n * @param input - The raw JSON parsed from the pair endpoint response body.\n */\nexport function validatePairResponse(\n input: unknown,\n): asserts input is RawPairResponse {\n if (!input || typeof input !== 'object') {\n throw new Error('validatePairResponse: input is not an object');\n }\n\n const assumed = input as Record<string, unknown>;\n const profile = assumed.profile as Record<string, unknown> | undefined;\n if (!profile || typeof profile !== 'object') {\n throw new Error(\n 'validatePairResponse: profile is missing or not an object',\n );\n }\n\n if (typeof profile.profile_id !== 'string' || !profile.profile_id) {\n throw new Error(\n 'validatePairResponse: profile.profile_id is missing or empty',\n );\n }\n\n if (typeof profile.identifier_id !== 'string' || !profile.identifier_id) {\n throw new Error(\n 'validatePairResponse: profile.identifier_id is missing or empty',\n );\n }\n}\n"]}
@@ -29,4 +29,4 @@ export declare function getCachedKeyGeneratedWithSharedSalt(hashedPassword: stri
29
29
  */
30
30
  export declare function setCachedKey(hashedPassword: string, salt: Uint8Array, key: Uint8Array): void;
31
31
  export {};
32
- //# sourceMappingURL=cache.d.cts.map
32
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/shared/encryption/cache.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,UAAU,CAAC;CACjB,CAAC;AAiBF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,GACf,WAAW,GAAG,SAAS,CAazB;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,cAAc,EAAE,MAAM,GACrB,WAAW,GAAG,SAAS,CAczB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,GACd,IAAI,CAeN"}
@@ -1,10 +1,10 @@
1
- import { SHARED_SALT } from "./constants.mjs";
2
- import { byteArrayToBase64 } from "./utils.mjs";
1
+ import { SHARED_SALT } from './constants.js';
2
+ import { byteArrayToBase64 } from './utils.js';
3
3
  const MAX_PASSWORD_CACHES = 100;
4
4
  const MAX_SALT_CACHES = 100;
5
5
  let inMemCachedKDF = {};
6
6
  const getPasswordCache = (hashedPassword) => {
7
- inMemCachedKDF[hashedPassword] ?? (inMemCachedKDF[hashedPassword] = new Map());
7
+ inMemCachedKDF[hashedPassword] ??= new Map();
8
8
  return inMemCachedKDF[hashedPassword];
9
9
  };
10
10
  /**
@@ -68,4 +68,4 @@ export function setCachedKey(hashedPassword, salt, key) {
68
68
  }
69
69
  cache.set(base64Salt, key);
70
70
  }
71
- //# sourceMappingURL=cache.mjs.map
71
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/shared/encryption/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAQ/C,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,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7D,cAAc,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAE3C,kBAAkB;IAClB,IAAI,KAAK,CAAC,IAAI,GAAG,eAAe,EAAE,CAAC;QACjC,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { SHARED_SALT } from './constants.js';\nimport { byteArrayToBase64 } from './utils.js';\n\ntype CachedEntry = {\n salt: Uint8Array;\n base64Salt: string;\n key: Uint8Array;\n};\n\nconst MAX_PASSWORD_CACHES = 100;\nconst MAX_SALT_CACHES = 100;\n\n/**\n * In-Memory Caching derived keys based from a given salt and password.\n */\ntype PasswordMemCachedKDF = {\n [hashedPassword: string]: Map<string, Uint8Array>;\n};\nlet inMemCachedKDF: PasswordMemCachedKDF = {};\nconst getPasswordCache = (hashedPassword: string) => {\n inMemCachedKDF[hashedPassword] ??= new Map();\n return inMemCachedKDF[hashedPassword];\n};\n\n/**\n * Returns a given cached derived key from a hashed password and salt\n *\n * @param hashedPassword - hashed password for cache lookup\n * @param salt - provide salt to receive cached key\n * @returns cached key\n */\nexport function getCachedKeyBySalt(\n hashedPassword: string,\n salt: Uint8Array,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(salt);\n const cachedKey = cache.get(base64Salt);\n if (!cachedKey) {\n return undefined;\n }\n\n return {\n salt,\n base64Salt,\n key: cachedKey,\n };\n}\n\n/**\n * Gets the cached key that was generated without a salt, if it exists.\n * This is unique per hashed password.\n *\n * @param hashedPassword - hashed password for cache lookup\n * @returns the cached key\n */\nexport function getCachedKeyGeneratedWithSharedSalt(\n hashedPassword: string,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(SHARED_SALT);\n const cachedKey = cache.get(base64Salt);\n\n if (!cachedKey) {\n return undefined;\n }\n\n return {\n salt: SHARED_SALT,\n base64Salt,\n key: cachedKey,\n };\n}\n\n/**\n * Sets a key to the in memory cache.\n * We have set an arbitrary size of 10 cached keys per hashed password.\n *\n * @param hashedPassword - hashed password for cache lookup\n * @param salt - salt to set new derived key\n * @param key - derived key we are setting\n */\nexport function setCachedKey(\n hashedPassword: string,\n salt: Uint8Array,\n key: Uint8Array,\n): void {\n // Max password caches\n if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {\n inMemCachedKDF = {};\n }\n\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(salt);\n\n // Max salt caches\n if (cache.size > MAX_SALT_CACHES) {\n cache.clear();\n }\n\n cache.set(base64Salt, key);\n}\n"]}
@@ -4,6 +4,6 @@ export declare const SCRYPT_SALT_SIZE = 16;
4
4
  export declare const SCRYPT_N: number;
5
5
  export declare const SCRYPT_r = 8;
6
6
  export declare const SCRYPT_p = 1;
7
- export declare const SHARED_SALT: Uint8Array;
7
+ export declare const SHARED_SALT: Uint8Array<ArrayBuffer>;
8
8
  export declare const MAX_KDF_PROMISE_CACHE_SIZE = 20;
9
- //# sourceMappingURL=constants.d.cts.map
9
+ //# sourceMappingURL=constants.d.ts.map