@metamask/profile-sync-controller 0.4.0 → 0.6.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 (606) hide show
  1. package/CHANGELOG.md +54 -1
  2. package/dist/controllers/authentication/AuthenticationController.cjs +211 -0
  3. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -0
  4. package/dist/{types/controllers/authentication/AuthenticationController.d.ts → controllers/authentication/AuthenticationController.d.cts} +5 -5
  5. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -0
  6. package/dist/controllers/authentication/AuthenticationController.d.mts +78 -0
  7. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -0
  8. package/dist/controllers/authentication/AuthenticationController.mjs +206 -11
  9. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  10. package/dist/controllers/authentication/__fixtures__/index.cjs +18 -0
  11. package/dist/controllers/authentication/__fixtures__/index.cjs.map +1 -0
  12. package/dist/controllers/authentication/__fixtures__/index.d.cts +2 -0
  13. package/dist/controllers/authentication/__fixtures__/index.d.cts.map +1 -0
  14. package/dist/controllers/authentication/__fixtures__/index.d.mts +2 -0
  15. package/dist/controllers/authentication/__fixtures__/index.d.mts.map +1 -0
  16. package/dist/controllers/authentication/__fixtures__/index.mjs +2 -0
  17. package/dist/controllers/authentication/__fixtures__/index.mjs.map +1 -0
  18. package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +52 -0
  19. package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +1 -0
  20. package/dist/{types/controllers/authentication/__fixtures__/mockResponses.d.ts → controllers/authentication/__fixtures__/mockResponses.d.cts} +2 -2
  21. package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +1 -0
  22. package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts +23 -0
  23. package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +1 -0
  24. package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +46 -0
  25. package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +1 -0
  26. package/dist/controllers/authentication/__fixtures__/mockServices.cjs +37 -0
  27. package/dist/controllers/authentication/__fixtures__/mockServices.cjs.map +1 -0
  28. package/dist/{types/controllers/authentication/__fixtures__/mockServices.d.ts → controllers/authentication/__fixtures__/mockServices.d.cts} +2 -2
  29. package/dist/controllers/authentication/__fixtures__/mockServices.d.cts.map +1 -0
  30. package/dist/controllers/authentication/__fixtures__/mockServices.d.mts +10 -0
  31. package/dist/controllers/authentication/__fixtures__/mockServices.d.mts.map +1 -0
  32. package/dist/controllers/authentication/__fixtures__/mockServices.mjs +35 -0
  33. package/dist/controllers/authentication/__fixtures__/mockServices.mjs.map +1 -0
  34. package/dist/controllers/authentication/auth-snap-requests.cjs +39 -0
  35. package/dist/controllers/authentication/auth-snap-requests.cjs.map +1 -0
  36. package/dist/{types/controllers/authentication/auth-snap-requests.d.ts → controllers/authentication/auth-snap-requests.d.cts} +2 -2
  37. package/dist/controllers/authentication/auth-snap-requests.d.cts.map +1 -0
  38. package/dist/controllers/authentication/auth-snap-requests.d.mts +17 -0
  39. package/dist/controllers/authentication/auth-snap-requests.d.mts.map +1 -0
  40. package/dist/controllers/authentication/auth-snap-requests.mjs +33 -9
  41. package/dist/controllers/authentication/auth-snap-requests.mjs.map +1 -1
  42. package/dist/controllers/authentication/index.cjs +39 -0
  43. package/dist/controllers/authentication/index.cjs.map +1 -0
  44. package/dist/controllers/authentication/index.d.cts +7 -0
  45. package/dist/controllers/authentication/index.d.cts.map +1 -0
  46. package/dist/controllers/authentication/index.d.mts +7 -0
  47. package/dist/controllers/authentication/index.d.mts.map +1 -0
  48. package/dist/controllers/authentication/index.mjs +6 -18
  49. package/dist/controllers/authentication/index.mjs.map +1 -1
  50. package/dist/controllers/authentication/services.cjs +127 -0
  51. package/dist/controllers/authentication/services.cjs.map +1 -0
  52. package/dist/{types/controllers/authentication/services.d.ts → controllers/authentication/services.d.cts} +1 -1
  53. package/dist/controllers/authentication/services.d.cts.map +1 -0
  54. package/dist/controllers/authentication/services.d.mts +70 -0
  55. package/dist/controllers/authentication/services.d.mts.map +1 -0
  56. package/dist/controllers/authentication/services.mjs +118 -19
  57. package/dist/controllers/authentication/services.mjs.map +1 -1
  58. package/dist/controllers/index.cjs +29 -0
  59. package/dist/controllers/index.cjs.map +1 -0
  60. package/dist/controllers/index.d.cts +3 -0
  61. package/dist/controllers/index.d.cts.map +1 -0
  62. package/dist/controllers/index.d.mts +3 -0
  63. package/dist/controllers/index.d.mts.map +1 -0
  64. package/dist/controllers/index.mjs +2 -24
  65. package/dist/controllers/index.mjs.map +1 -1
  66. package/dist/controllers/user-storage/UserStorageController.cjs +462 -0
  67. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -0
  68. package/dist/{types/controllers/user-storage/UserStorageController.d.ts → controllers/user-storage/UserStorageController.d.cts} +44 -16
  69. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -0
  70. package/dist/controllers/user-storage/UserStorageController.d.mts +156 -0
  71. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -0
  72. package/dist/controllers/user-storage/UserStorageController.mjs +457 -18
  73. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  74. package/dist/controllers/user-storage/__fixtures__/index.cjs +19 -0
  75. package/dist/controllers/user-storage/__fixtures__/index.cjs.map +1 -0
  76. package/dist/controllers/user-storage/__fixtures__/index.d.cts +3 -0
  77. package/dist/controllers/user-storage/__fixtures__/index.d.cts.map +1 -0
  78. package/dist/controllers/user-storage/__fixtures__/index.d.mts +3 -0
  79. package/dist/controllers/user-storage/__fixtures__/index.d.mts.map +1 -0
  80. package/dist/controllers/user-storage/__fixtures__/index.mjs +3 -0
  81. package/dist/controllers/user-storage/__fixtures__/index.mjs.map +1 -0
  82. package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs +127 -0
  83. package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs.map +1 -0
  84. package/dist/{types/controllers/user-storage/__fixtures__/mockAccounts.d.ts → controllers/user-storage/__fixtures__/mockAccounts.d.cts} +6 -6
  85. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts.map +1 -0
  86. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts +63 -0
  87. package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts.map +1 -0
  88. package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs +123 -0
  89. package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs.map +1 -0
  90. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs +48 -0
  91. package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +1 -0
  92. package/dist/{types/controllers/user-storage/__fixtures__/mockResponses.d.ts → controllers/user-storage/__fixtures__/mockResponses.d.cts} +6 -4
  93. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +1 -0
  94. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts +21 -0
  95. package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +1 -0
  96. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs +39 -0
  97. package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +1 -0
  98. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +41 -0
  99. package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +1 -0
  100. package/dist/{types/controllers/user-storage/__fixtures__/mockServices.d.ts → controllers/user-storage/__fixtures__/mockServices.d.cts} +3 -3
  101. package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +1 -0
  102. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts +11 -0
  103. package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +1 -0
  104. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +39 -0
  105. package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +1 -0
  106. package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs +36 -0
  107. package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs.map +1 -0
  108. package/dist/{types/controllers/user-storage/__fixtures__/mockStorage.d.ts → controllers/user-storage/__fixtures__/mockStorage.d.cts} +2 -2
  109. package/dist/controllers/user-storage/__fixtures__/mockStorage.d.cts.map +1 -0
  110. package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts +5 -0
  111. package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts.map +1 -0
  112. package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs +9 -0
  113. package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs.map +1 -0
  114. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +31 -0
  115. package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -0
  116. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +14 -0
  117. package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -0
  118. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +14 -0
  119. package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -0
  120. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +27 -0
  121. package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -0
  122. package/dist/controllers/user-storage/accounts/constants.cjs +51 -0
  123. package/dist/controllers/user-storage/accounts/constants.cjs.map +1 -0
  124. package/dist/{types/controllers/user-storage/accounts/constants.d.ts → controllers/user-storage/accounts/constants.d.cts} +1 -1
  125. package/dist/controllers/user-storage/accounts/constants.d.cts.map +1 -0
  126. package/dist/controllers/user-storage/accounts/constants.d.mts +4 -0
  127. package/dist/controllers/user-storage/accounts/constants.d.mts.map +1 -0
  128. package/dist/controllers/user-storage/accounts/constants.mjs +47 -11
  129. package/dist/controllers/user-storage/accounts/constants.mjs.map +1 -1
  130. package/dist/controllers/user-storage/accounts/user-storage.cjs +34 -0
  131. package/dist/controllers/user-storage/accounts/user-storage.cjs.map +1 -0
  132. package/dist/{types/controllers/user-storage/accounts/user-storage.d.ts → controllers/user-storage/accounts/user-storage.d.cts} +3 -3
  133. package/dist/controllers/user-storage/accounts/user-storage.d.cts.map +1 -0
  134. package/dist/controllers/user-storage/accounts/user-storage.d.mts +32 -0
  135. package/dist/controllers/user-storage/accounts/user-storage.d.mts.map +1 -0
  136. package/dist/controllers/user-storage/accounts/user-storage.mjs +27 -9
  137. package/dist/controllers/user-storage/accounts/user-storage.mjs.map +1 -1
  138. package/dist/controllers/user-storage/encryption/cache.cjs +79 -0
  139. package/dist/controllers/user-storage/encryption/cache.cjs.map +1 -0
  140. package/dist/{types/controllers/user-storage/encryption/cache.d.ts → controllers/user-storage/encryption/cache.d.cts} +1 -1
  141. package/dist/controllers/user-storage/encryption/cache.d.cts.map +1 -0
  142. package/dist/controllers/user-storage/encryption/cache.d.mts +31 -0
  143. package/dist/controllers/user-storage/encryption/cache.d.mts.map +1 -0
  144. package/dist/controllers/user-storage/encryption/cache.mjs +71 -11
  145. package/dist/controllers/user-storage/encryption/cache.mjs.map +1 -1
  146. package/dist/controllers/user-storage/encryption/encryption.cjs +151 -0
  147. package/dist/controllers/user-storage/encryption/encryption.cjs.map +1 -0
  148. package/dist/{types/controllers/user-storage/encryption/encryption.d.ts → controllers/user-storage/encryption/encryption.d.cts} +2 -2
  149. package/dist/controllers/user-storage/encryption/encryption.d.cts.map +1 -0
  150. package/dist/controllers/user-storage/encryption/encryption.d.mts +27 -0
  151. package/dist/controllers/user-storage/encryption/encryption.d.mts.map +1 -0
  152. package/dist/controllers/user-storage/encryption/encryption.mjs +145 -10
  153. package/dist/controllers/user-storage/encryption/encryption.mjs.map +1 -1
  154. package/dist/controllers/user-storage/encryption/index.cjs +25 -0
  155. package/dist/controllers/user-storage/encryption/index.cjs.map +1 -0
  156. package/dist/controllers/user-storage/encryption/index.d.cts +5 -0
  157. package/dist/controllers/user-storage/encryption/index.d.cts.map +1 -0
  158. package/dist/controllers/user-storage/encryption/index.d.mts +5 -0
  159. package/dist/controllers/user-storage/encryption/index.d.mts.map +1 -0
  160. package/dist/controllers/user-storage/encryption/index.mjs +4 -15
  161. package/dist/controllers/user-storage/encryption/index.mjs.map +1 -1
  162. package/dist/controllers/user-storage/encryption/utils.cjs +17 -0
  163. package/dist/controllers/user-storage/encryption/utils.cjs.map +1 -0
  164. package/dist/{types/controllers/user-storage/encryption/utils.d.ts → controllers/user-storage/encryption/utils.d.cts} +1 -1
  165. package/dist/controllers/user-storage/encryption/utils.d.cts.map +1 -0
  166. package/dist/controllers/user-storage/encryption/utils.d.mts +4 -0
  167. package/dist/controllers/user-storage/encryption/utils.d.mts.map +1 -0
  168. package/dist/controllers/user-storage/encryption/utils.mjs +9 -10
  169. package/dist/controllers/user-storage/encryption/utils.mjs.map +1 -1
  170. package/dist/controllers/user-storage/index.cjs +40 -0
  171. package/dist/controllers/user-storage/index.cjs.map +1 -0
  172. package/dist/controllers/user-storage/index.d.cts +8 -0
  173. package/dist/controllers/user-storage/index.d.cts.map +1 -0
  174. package/dist/controllers/user-storage/index.d.mts +8 -0
  175. package/dist/controllers/user-storage/index.d.mts.map +1 -0
  176. package/dist/controllers/user-storage/index.mjs +7 -30
  177. package/dist/controllers/user-storage/index.mjs.map +1 -1
  178. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs +25 -0
  179. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs.map +1 -0
  180. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts +4 -0
  181. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts.map +1 -0
  182. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts +4 -0
  183. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts.map +1 -0
  184. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs +20 -0
  185. package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs.map +1 -0
  186. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +65 -0
  187. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -0
  188. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +13 -0
  189. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -0
  190. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +13 -0
  191. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -0
  192. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +65 -0
  193. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -0
  194. package/dist/controllers/user-storage/network-syncing/services.cjs +64 -0
  195. package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -0
  196. package/dist/controllers/user-storage/network-syncing/services.d.cts +21 -0
  197. package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -0
  198. package/dist/controllers/user-storage/network-syncing/services.d.mts +21 -0
  199. package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -0
  200. package/dist/controllers/user-storage/network-syncing/services.mjs +58 -0
  201. package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -0
  202. package/dist/controllers/user-storage/network-syncing/sync-all.cjs +171 -0
  203. package/dist/controllers/user-storage/network-syncing/sync-all.cjs.map +1 -0
  204. package/dist/controllers/user-storage/network-syncing/sync-all.d.cts +35 -0
  205. package/dist/controllers/user-storage/network-syncing/sync-all.d.cts.map +1 -0
  206. package/dist/controllers/user-storage/network-syncing/sync-all.d.mts +35 -0
  207. package/dist/controllers/user-storage/network-syncing/sync-all.d.mts.map +1 -0
  208. package/dist/controllers/user-storage/network-syncing/sync-all.mjs +162 -0
  209. package/dist/controllers/user-storage/network-syncing/sync-all.mjs.map +1 -0
  210. package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs +28 -0
  211. package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -0
  212. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +9 -0
  213. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -0
  214. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +9 -0
  215. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -0
  216. package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs +22 -0
  217. package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -0
  218. package/dist/controllers/user-storage/network-syncing/types.cjs +16 -0
  219. package/dist/controllers/user-storage/network-syncing/types.cjs.map +1 -0
  220. package/dist/controllers/user-storage/network-syncing/types.d.cts +18 -0
  221. package/dist/controllers/user-storage/network-syncing/types.d.cts.map +1 -0
  222. package/dist/controllers/user-storage/network-syncing/types.d.mts +18 -0
  223. package/dist/controllers/user-storage/network-syncing/types.d.mts.map +1 -0
  224. package/dist/controllers/user-storage/network-syncing/types.mjs +11 -0
  225. package/dist/controllers/user-storage/network-syncing/types.mjs.map +1 -0
  226. package/dist/controllers/user-storage/schema.cjs +56 -0
  227. package/dist/controllers/user-storage/schema.cjs.map +1 -0
  228. package/dist/{types/controllers/user-storage/schema.d.ts → controllers/user-storage/schema.d.cts} +2 -1
  229. package/dist/controllers/user-storage/schema.d.cts.map +1 -0
  230. package/dist/controllers/user-storage/schema.d.mts +38 -0
  231. package/dist/controllers/user-storage/schema.d.mts.map +1 -0
  232. package/dist/controllers/user-storage/schema.mjs +48 -16
  233. package/dist/controllers/user-storage/schema.mjs.map +1 -1
  234. package/dist/controllers/user-storage/services.cjs +119 -0
  235. package/dist/controllers/user-storage/services.cjs.map +1 -0
  236. package/dist/{types/controllers/user-storage/services.d.ts → controllers/user-storage/services.d.cts} +4 -5
  237. package/dist/controllers/user-storage/services.d.cts.map +1 -0
  238. package/dist/controllers/user-storage/services.d.mts +48 -0
  239. package/dist/controllers/user-storage/services.d.mts.map +1 -0
  240. package/dist/controllers/user-storage/services.mjs +116 -21
  241. package/dist/controllers/user-storage/services.mjs.map +1 -1
  242. package/dist/controllers/user-storage/utils.cjs +30 -0
  243. package/dist/controllers/user-storage/utils.cjs.map +1 -0
  244. package/dist/controllers/user-storage/utils.d.cts +17 -0
  245. package/dist/controllers/user-storage/utils.d.cts.map +1 -0
  246. package/dist/controllers/user-storage/utils.d.mts +17 -0
  247. package/dist/controllers/user-storage/utils.d.mts.map +1 -0
  248. package/dist/controllers/user-storage/utils.mjs +25 -0
  249. package/dist/controllers/user-storage/utils.mjs.map +1 -0
  250. package/dist/index.cjs +30 -0
  251. package/dist/index.cjs.map +1 -0
  252. package/dist/index.d.cts +4 -0
  253. package/dist/index.d.cts.map +1 -0
  254. package/dist/index.d.mts +4 -0
  255. package/dist/index.d.mts.map +1 -0
  256. package/dist/index.mjs +3 -39
  257. package/dist/index.mjs.map +1 -1
  258. package/dist/sdk/__fixtures__/mock-auth.cjs +139 -0
  259. package/dist/sdk/__fixtures__/mock-auth.cjs.map +1 -0
  260. package/dist/{types/sdk/__fixtures__/mock-auth.d.ts → sdk/__fixtures__/mock-auth.d.cts} +2 -2
  261. package/dist/sdk/__fixtures__/mock-auth.d.cts.map +1 -0
  262. package/dist/sdk/__fixtures__/mock-auth.d.mts +42 -0
  263. package/dist/sdk/__fixtures__/mock-auth.d.mts.map +1 -0
  264. package/dist/sdk/__fixtures__/mock-auth.mjs +134 -0
  265. package/dist/sdk/__fixtures__/mock-auth.mjs.map +1 -0
  266. package/dist/sdk/__fixtures__/mock-userstorage.cjs +58 -0
  267. package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +1 -0
  268. package/dist/{types/sdk/__fixtures__/mock-userstorage.d.ts → sdk/__fixtures__/mock-userstorage.d.cts} +2 -2
  269. package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +1 -0
  270. package/dist/sdk/__fixtures__/mock-userstorage.d.mts +19 -0
  271. package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +1 -0
  272. package/dist/sdk/__fixtures__/mock-userstorage.mjs +54 -0
  273. package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +1 -0
  274. package/dist/sdk/__fixtures__/test-utils.cjs +74 -0
  275. package/dist/sdk/__fixtures__/test-utils.cjs.map +1 -0
  276. package/dist/{types/sdk/__fixtures__/test-utils.d.ts → sdk/__fixtures__/test-utils.d.cts} +6 -6
  277. package/dist/sdk/__fixtures__/test-utils.d.cts.map +1 -0
  278. package/dist/sdk/__fixtures__/test-utils.d.mts +25 -0
  279. package/dist/sdk/__fixtures__/test-utils.d.mts.map +1 -0
  280. package/dist/sdk/__fixtures__/test-utils.mjs +69 -0
  281. package/dist/sdk/__fixtures__/test-utils.mjs.map +1 -0
  282. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +106 -0
  283. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -0
  284. package/dist/{types/sdk/authentication-jwt-bearer/flow-siwe.d.ts → sdk/authentication-jwt-bearer/flow-siwe.d.cts} +2 -2
  285. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -0
  286. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +23 -0
  287. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -0
  288. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +101 -11
  289. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  290. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +111 -0
  291. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -0
  292. package/dist/{types/sdk/authentication-jwt-bearer/flow-srp.d.ts → sdk/authentication-jwt-bearer/flow-srp.d.cts} +2 -2
  293. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -0
  294. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +17 -0
  295. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -0
  296. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +105 -13
  297. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  298. package/dist/sdk/authentication-jwt-bearer/services.cjs +180 -0
  299. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -0
  300. package/dist/{types/sdk/authentication-jwt-bearer/services.d.ts → sdk/authentication-jwt-bearer/services.d.cts} +4 -4
  301. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -0
  302. package/dist/sdk/authentication-jwt-bearer/services.d.mts +63 -0
  303. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -0
  304. package/dist/sdk/authentication-jwt-bearer/services.mjs +166 -25
  305. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  306. package/dist/sdk/authentication-jwt-bearer/types.cjs +12 -0
  307. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -0
  308. package/dist/{types/sdk/authentication-jwt-bearer/types.d.ts → sdk/authentication-jwt-bearer/types.d.cts} +2 -2
  309. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -0
  310. package/dist/sdk/authentication-jwt-bearer/types.d.mts +67 -0
  311. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -0
  312. package/dist/sdk/authentication-jwt-bearer/types.mjs +8 -7
  313. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  314. package/dist/sdk/authentication.cjs +129 -0
  315. package/dist/sdk/authentication.cjs.map +1 -0
  316. package/dist/{types/sdk/authentication.d.ts → sdk/authentication.d.cts} +8 -7
  317. package/dist/sdk/authentication.d.cts.map +1 -0
  318. package/dist/sdk/authentication.d.mts +32 -0
  319. package/dist/sdk/authentication.d.mts.map +1 -0
  320. package/dist/sdk/authentication.mjs +107 -24
  321. package/dist/sdk/authentication.mjs.map +1 -1
  322. package/dist/sdk/encryption.cjs +23 -0
  323. package/dist/sdk/encryption.cjs.map +1 -0
  324. package/dist/sdk/encryption.d.cts +4 -0
  325. package/dist/sdk/encryption.d.cts.map +1 -0
  326. package/dist/sdk/encryption.d.mts +4 -0
  327. package/dist/sdk/encryption.d.mts.map +1 -0
  328. package/dist/sdk/encryption.mjs +3 -13
  329. package/dist/sdk/encryption.mjs.map +1 -1
  330. package/dist/sdk/env.cjs +85 -0
  331. package/dist/sdk/env.cjs.map +1 -0
  332. package/dist/{types/sdk/env.d.ts → sdk/env.d.cts} +1 -1
  333. package/dist/sdk/env.d.cts.map +1 -0
  334. package/dist/sdk/env.d.mts +34 -0
  335. package/dist/sdk/env.d.mts.map +1 -0
  336. package/dist/sdk/env.mjs +78 -12
  337. package/dist/sdk/env.mjs.map +1 -1
  338. package/dist/sdk/errors.cjs +53 -0
  339. package/dist/sdk/errors.cjs.map +1 -0
  340. package/dist/{types/sdk/errors.d.ts → sdk/errors.d.cts} +1 -1
  341. package/dist/sdk/errors.d.cts.map +1 -0
  342. package/dist/sdk/errors.d.mts +22 -0
  343. package/dist/sdk/errors.d.mts.map +1 -0
  344. package/dist/sdk/errors.mjs +42 -19
  345. package/dist/sdk/errors.mjs.map +1 -1
  346. package/dist/sdk/index.cjs +23 -0
  347. package/dist/sdk/index.cjs.map +1 -0
  348. package/dist/sdk/index.d.cts +7 -0
  349. package/dist/sdk/index.d.cts.map +1 -0
  350. package/dist/sdk/index.d.mts +7 -0
  351. package/dist/sdk/index.d.mts.map +1 -0
  352. package/dist/sdk/index.mjs +6 -76
  353. package/dist/sdk/index.mjs.map +1 -1
  354. package/dist/sdk/user-storage.cjs +176 -0
  355. package/dist/sdk/user-storage.cjs.map +1 -0
  356. package/dist/{types/sdk/user-storage.d.ts → sdk/user-storage.d.cts} +4 -4
  357. package/dist/sdk/user-storage.d.cts.map +1 -0
  358. package/dist/sdk/user-storage.d.mts +27 -0
  359. package/dist/sdk/user-storage.d.mts.map +1 -0
  360. package/dist/sdk/user-storage.mjs +146 -16
  361. package/dist/sdk/user-storage.mjs.map +1 -1
  362. package/dist/sdk/utils/eip-6963-metamask-provider.cjs +70 -0
  363. package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -0
  364. package/dist/{types/sdk/utils/eip-6963-metamask-provider.d.ts → sdk/utils/eip-6963-metamask-provider.d.cts} +2 -2
  365. package/dist/sdk/utils/eip-6963-metamask-provider.d.cts.map +1 -0
  366. package/dist/sdk/utils/eip-6963-metamask-provider.d.mts +25 -0
  367. package/dist/sdk/utils/eip-6963-metamask-provider.d.mts.map +1 -0
  368. package/dist/sdk/utils/eip-6963-metamask-provider.mjs +64 -8
  369. package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -1
  370. package/dist/sdk/utils/messaging-signing-snap-requests.cjs +89 -0
  371. package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -0
  372. package/dist/{types/sdk/utils/messaging-signing-snap-requests.d.ts → sdk/utils/messaging-signing-snap-requests.d.cts} +9 -2
  373. package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -0
  374. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +40 -0
  375. package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -0
  376. package/dist/sdk/utils/messaging-signing-snap-requests.mjs +80 -14
  377. package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
  378. package/dist/sdk/utils/validate-login-response.cjs +22 -0
  379. package/dist/sdk/utils/validate-login-response.cjs.map +1 -0
  380. package/dist/{types/sdk/utils/validate-login-response.d.ts → sdk/utils/validate-login-response.d.cts} +2 -2
  381. package/dist/sdk/utils/validate-login-response.d.cts.map +1 -0
  382. package/dist/sdk/utils/validate-login-response.d.mts +10 -0
  383. package/dist/sdk/utils/validate-login-response.d.mts.map +1 -0
  384. package/dist/sdk/utils/validate-login-response.mjs +17 -7
  385. package/dist/sdk/utils/validate-login-response.mjs.map +1 -1
  386. package/package.json +20 -14
  387. package/dist/chunk-246Z6L5V.js +0 -534
  388. package/dist/chunk-246Z6L5V.js.map +0 -1
  389. package/dist/chunk-2677XY6G.mjs +0 -107
  390. package/dist/chunk-2677XY6G.mjs.map +0 -1
  391. package/dist/chunk-2CWF7ZTL.mjs +0 -129
  392. package/dist/chunk-2CWF7ZTL.mjs.map +0 -1
  393. package/dist/chunk-2VEMA6OE.mjs +0 -47
  394. package/dist/chunk-2VEMA6OE.mjs.map +0 -1
  395. package/dist/chunk-4LMFZDL4.js +0 -114
  396. package/dist/chunk-4LMFZDL4.js.map +0 -1
  397. package/dist/chunk-4ZGRRVMI.js +0 -133
  398. package/dist/chunk-4ZGRRVMI.js.map +0 -1
  399. package/dist/chunk-5EBUFNAN.mjs +0 -55
  400. package/dist/chunk-5EBUFNAN.mjs.map +0 -1
  401. package/dist/chunk-5MQUI24U.js +0 -47
  402. package/dist/chunk-5MQUI24U.js.map +0 -1
  403. package/dist/chunk-5XSXZTED.mjs +0 -57
  404. package/dist/chunk-5XSXZTED.mjs.map +0 -1
  405. package/dist/chunk-6DAK2U35.mjs +0 -11
  406. package/dist/chunk-6DAK2U35.mjs.map +0 -1
  407. package/dist/chunk-76NMME23.mjs +0 -114
  408. package/dist/chunk-76NMME23.mjs.map +0 -1
  409. package/dist/chunk-76VRE4BI.mjs +0 -18
  410. package/dist/chunk-76VRE4BI.mjs.map +0 -1
  411. package/dist/chunk-7MSQV43P.mjs +0 -77
  412. package/dist/chunk-7MSQV43P.mjs.map +0 -1
  413. package/dist/chunk-BKQE7DB5.js +0 -170
  414. package/dist/chunk-BKQE7DB5.js.map +0 -1
  415. package/dist/chunk-CAIIVJAO.mjs +0 -11
  416. package/dist/chunk-CAIIVJAO.mjs.map +0 -1
  417. package/dist/chunk-CHUZGCDV.js +0 -107
  418. package/dist/chunk-CHUZGCDV.js.map +0 -1
  419. package/dist/chunk-COBJUBZE.mjs +0 -170
  420. package/dist/chunk-COBJUBZE.mjs.map +0 -1
  421. package/dist/chunk-D4SNJOID.mjs +0 -269
  422. package/dist/chunk-D4SNJOID.mjs.map +0 -1
  423. package/dist/chunk-DF24ZX4H.js +0 -76
  424. package/dist/chunk-DF24ZX4H.js.map +0 -1
  425. package/dist/chunk-DRB2MN4T.js +0 -16
  426. package/dist/chunk-DRB2MN4T.js.map +0 -1
  427. package/dist/chunk-EHZFPUJH.mjs +0 -53
  428. package/dist/chunk-EHZFPUJH.mjs.map +0 -1
  429. package/dist/chunk-F6BAOSH2.js +0 -269
  430. package/dist/chunk-F6BAOSH2.js.map +0 -1
  431. package/dist/chunk-GQXYWBFK.js +0 -28
  432. package/dist/chunk-GQXYWBFK.js.map +0 -1
  433. package/dist/chunk-H25EBXG5.mjs +0 -58
  434. package/dist/chunk-H25EBXG5.mjs.map +0 -1
  435. package/dist/chunk-IGY2S5BC.js +0 -36
  436. package/dist/chunk-IGY2S5BC.js.map +0 -1
  437. package/dist/chunk-J7NSK6BO.mjs +0 -133
  438. package/dist/chunk-J7NSK6BO.mjs.map +0 -1
  439. package/dist/chunk-JAQ5TPSZ.js +0 -53
  440. package/dist/chunk-JAQ5TPSZ.js.map +0 -1
  441. package/dist/chunk-KHASG4H3.mjs +0 -11
  442. package/dist/chunk-KHASG4H3.mjs.map +0 -1
  443. package/dist/chunk-KIVBL6OM.js +0 -129
  444. package/dist/chunk-KIVBL6OM.js.map +0 -1
  445. package/dist/chunk-KTCSRECK.mjs +0 -76
  446. package/dist/chunk-KTCSRECK.mjs.map +0 -1
  447. package/dist/chunk-LGXQBALM.mjs +0 -106
  448. package/dist/chunk-LGXQBALM.mjs.map +0 -1
  449. package/dist/chunk-LLG4D2SC.js +0 -157
  450. package/dist/chunk-LLG4D2SC.js.map +0 -1
  451. package/dist/chunk-MBTBE4P5.js +0 -54
  452. package/dist/chunk-MBTBE4P5.js.map +0 -1
  453. package/dist/chunk-MK7ABX2V.mjs +0 -186
  454. package/dist/chunk-MK7ABX2V.mjs.map +0 -1
  455. package/dist/chunk-NIUQ34PY.js +0 -11
  456. package/dist/chunk-NIUQ34PY.js.map +0 -1
  457. package/dist/chunk-NMIF3LSX.mjs +0 -29
  458. package/dist/chunk-NMIF3LSX.mjs.map +0 -1
  459. package/dist/chunk-PBRUOBEQ.js +0 -11
  460. package/dist/chunk-PBRUOBEQ.js.map +0 -1
  461. package/dist/chunk-PCOIRDTO.js +0 -18
  462. package/dist/chunk-PCOIRDTO.js.map +0 -1
  463. package/dist/chunk-PQ5T4GHY.js +0 -55
  464. package/dist/chunk-PQ5T4GHY.js.map +0 -1
  465. package/dist/chunk-PRYLTXW4.js +0 -92
  466. package/dist/chunk-PRYLTXW4.js.map +0 -1
  467. package/dist/chunk-Q5KTSMRE.js +0 -120
  468. package/dist/chunk-Q5KTSMRE.js.map +0 -1
  469. package/dist/chunk-QDGLIUUS.mjs +0 -16
  470. package/dist/chunk-QDGLIUUS.mjs.map +0 -1
  471. package/dist/chunk-RG4II6WH.js +0 -57
  472. package/dist/chunk-RG4II6WH.js.map +0 -1
  473. package/dist/chunk-SZ6WMC6C.mjs +0 -534
  474. package/dist/chunk-SZ6WMC6C.mjs.map +0 -1
  475. package/dist/chunk-T2YURW25.js +0 -77
  476. package/dist/chunk-T2YURW25.js.map +0 -1
  477. package/dist/chunk-TFFQFIJV.mjs +0 -54
  478. package/dist/chunk-TFFQFIJV.mjs.map +0 -1
  479. package/dist/chunk-U5UIDVOO.mjs +0 -36
  480. package/dist/chunk-U5UIDVOO.mjs.map +0 -1
  481. package/dist/chunk-UAXWZN5J.js +0 -58
  482. package/dist/chunk-UAXWZN5J.js.map +0 -1
  483. package/dist/chunk-UHP2Y32K.mjs +0 -92
  484. package/dist/chunk-UHP2Y32K.mjs.map +0 -1
  485. package/dist/chunk-UHX7HJAI.js +0 -11
  486. package/dist/chunk-UHX7HJAI.js.map +0 -1
  487. package/dist/chunk-UIRAMHNM.js +0 -186
  488. package/dist/chunk-UIRAMHNM.js.map +0 -1
  489. package/dist/chunk-YHGWG3EQ.js +0 -29
  490. package/dist/chunk-YHGWG3EQ.js.map +0 -1
  491. package/dist/chunk-YKOMKXG4.mjs +0 -120
  492. package/dist/chunk-YKOMKXG4.mjs.map +0 -1
  493. package/dist/chunk-YLURF2PF.mjs +0 -157
  494. package/dist/chunk-YLURF2PF.mjs.map +0 -1
  495. package/dist/chunk-ZUPTMFEA.mjs +0 -28
  496. package/dist/chunk-ZUPTMFEA.mjs.map +0 -1
  497. package/dist/chunk-ZX2KHPXG.js +0 -106
  498. package/dist/chunk-ZX2KHPXG.js.map +0 -1
  499. package/dist/controllers/authentication/AuthenticationController.js +0 -13
  500. package/dist/controllers/authentication/AuthenticationController.js.map +0 -1
  501. package/dist/controllers/authentication/auth-snap-requests.js +0 -10
  502. package/dist/controllers/authentication/auth-snap-requests.js.map +0 -1
  503. package/dist/controllers/authentication/index.js +0 -19
  504. package/dist/controllers/authentication/index.js.map +0 -1
  505. package/dist/controllers/authentication/services.js +0 -21
  506. package/dist/controllers/authentication/services.js.map +0 -1
  507. package/dist/controllers/index.js +0 -25
  508. package/dist/controllers/index.js.map +0 -1
  509. package/dist/controllers/user-storage/UserStorageController.js +0 -20
  510. package/dist/controllers/user-storage/UserStorageController.js.map +0 -1
  511. package/dist/controllers/user-storage/accounts/constants.js +0 -12
  512. package/dist/controllers/user-storage/accounts/constants.js.map +0 -1
  513. package/dist/controllers/user-storage/accounts/user-storage.js +0 -11
  514. package/dist/controllers/user-storage/accounts/user-storage.js.map +0 -1
  515. package/dist/controllers/user-storage/encryption/cache.js +0 -13
  516. package/dist/controllers/user-storage/encryption/cache.js.map +0 -1
  517. package/dist/controllers/user-storage/encryption/encryption.js +0 -12
  518. package/dist/controllers/user-storage/encryption/encryption.js.map +0 -1
  519. package/dist/controllers/user-storage/encryption/index.js +0 -16
  520. package/dist/controllers/user-storage/encryption/index.js.map +0 -1
  521. package/dist/controllers/user-storage/encryption/utils.js +0 -12
  522. package/dist/controllers/user-storage/encryption/utils.js.map +0 -1
  523. package/dist/controllers/user-storage/index.js +0 -31
  524. package/dist/controllers/user-storage/index.js.map +0 -1
  525. package/dist/controllers/user-storage/schema.js +0 -18
  526. package/dist/controllers/user-storage/schema.js.map +0 -1
  527. package/dist/controllers/user-storage/services.js +0 -22
  528. package/dist/controllers/user-storage/services.js.map +0 -1
  529. package/dist/index.js +0 -40
  530. package/dist/index.js.map +0 -1
  531. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +0 -13
  532. package/dist/sdk/authentication-jwt-bearer/flow-siwe.js.map +0 -1
  533. package/dist/sdk/authentication-jwt-bearer/flow-srp.js +0 -15
  534. package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +0 -1
  535. package/dist/sdk/authentication-jwt-bearer/services.js +0 -27
  536. package/dist/sdk/authentication-jwt-bearer/services.js.map +0 -1
  537. package/dist/sdk/authentication-jwt-bearer/types.js +0 -8
  538. package/dist/sdk/authentication-jwt-bearer/types.js.map +0 -1
  539. package/dist/sdk/authentication.js +0 -26
  540. package/dist/sdk/authentication.js.map +0 -1
  541. package/dist/sdk/encryption.js +0 -14
  542. package/dist/sdk/encryption.js.map +0 -1
  543. package/dist/sdk/env.js +0 -14
  544. package/dist/sdk/env.js.map +0 -1
  545. package/dist/sdk/errors.js +0 -20
  546. package/dist/sdk/errors.js.map +0 -1
  547. package/dist/sdk/index.js +0 -77
  548. package/dist/sdk/index.js.map +0 -1
  549. package/dist/sdk/user-storage.js +0 -18
  550. package/dist/sdk/user-storage.js.map +0 -1
  551. package/dist/sdk/utils/eip-6963-metamask-provider.js +0 -10
  552. package/dist/sdk/utils/eip-6963-metamask-provider.js.map +0 -1
  553. package/dist/sdk/utils/messaging-signing-snap-requests.js +0 -16
  554. package/dist/sdk/utils/messaging-signing-snap-requests.js.map +0 -1
  555. package/dist/sdk/utils/validate-login-response.js +0 -8
  556. package/dist/sdk/utils/validate-login-response.js.map +0 -1
  557. package/dist/tsconfig.build.tsbuildinfo +0 -1
  558. package/dist/types/controllers/authentication/AuthenticationController.d.ts.map +0 -1
  559. package/dist/types/controllers/authentication/__fixtures__/index.d.ts +0 -2
  560. package/dist/types/controllers/authentication/__fixtures__/index.d.ts.map +0 -1
  561. package/dist/types/controllers/authentication/__fixtures__/mockResponses.d.ts.map +0 -1
  562. package/dist/types/controllers/authentication/__fixtures__/mockServices.d.ts.map +0 -1
  563. package/dist/types/controllers/authentication/auth-snap-requests.d.ts.map +0 -1
  564. package/dist/types/controllers/authentication/index.d.ts +0 -7
  565. package/dist/types/controllers/authentication/index.d.ts.map +0 -1
  566. package/dist/types/controllers/authentication/services.d.ts.map +0 -1
  567. package/dist/types/controllers/index.d.ts +0 -3
  568. package/dist/types/controllers/index.d.ts.map +0 -1
  569. package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +0 -1
  570. package/dist/types/controllers/user-storage/__fixtures__/index.d.ts +0 -3
  571. package/dist/types/controllers/user-storage/__fixtures__/index.d.ts.map +0 -1
  572. package/dist/types/controllers/user-storage/__fixtures__/mockAccounts.d.ts.map +0 -1
  573. package/dist/types/controllers/user-storage/__fixtures__/mockResponses.d.ts.map +0 -1
  574. package/dist/types/controllers/user-storage/__fixtures__/mockServices.d.ts.map +0 -1
  575. package/dist/types/controllers/user-storage/__fixtures__/mockStorage.d.ts.map +0 -1
  576. package/dist/types/controllers/user-storage/accounts/constants.d.ts.map +0 -1
  577. package/dist/types/controllers/user-storage/accounts/user-storage.d.ts.map +0 -1
  578. package/dist/types/controllers/user-storage/encryption/cache.d.ts.map +0 -1
  579. package/dist/types/controllers/user-storage/encryption/encryption.d.ts.map +0 -1
  580. package/dist/types/controllers/user-storage/encryption/index.d.ts +0 -5
  581. package/dist/types/controllers/user-storage/encryption/index.d.ts.map +0 -1
  582. package/dist/types/controllers/user-storage/encryption/utils.d.ts.map +0 -1
  583. package/dist/types/controllers/user-storage/index.d.ts +0 -8
  584. package/dist/types/controllers/user-storage/index.d.ts.map +0 -1
  585. package/dist/types/controllers/user-storage/schema.d.ts.map +0 -1
  586. package/dist/types/controllers/user-storage/services.d.ts.map +0 -1
  587. package/dist/types/index.d.ts +0 -4
  588. package/dist/types/index.d.ts.map +0 -1
  589. package/dist/types/sdk/__fixtures__/mock-auth.d.ts.map +0 -1
  590. package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +0 -1
  591. package/dist/types/sdk/__fixtures__/test-utils.d.ts.map +0 -1
  592. package/dist/types/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +0 -1
  593. package/dist/types/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +0 -1
  594. package/dist/types/sdk/authentication-jwt-bearer/services.d.ts.map +0 -1
  595. package/dist/types/sdk/authentication-jwt-bearer/types.d.ts.map +0 -1
  596. package/dist/types/sdk/authentication.d.ts.map +0 -1
  597. package/dist/types/sdk/encryption.d.ts +0 -4
  598. package/dist/types/sdk/encryption.d.ts.map +0 -1
  599. package/dist/types/sdk/env.d.ts.map +0 -1
  600. package/dist/types/sdk/errors.d.ts.map +0 -1
  601. package/dist/types/sdk/index.d.ts +0 -7
  602. package/dist/types/sdk/index.d.ts.map +0 -1
  603. package/dist/types/sdk/user-storage.d.ts.map +0 -1
  604. package/dist/types/sdk/utils/eip-6963-metamask-provider.d.ts.map +0 -1
  605. package/dist/types/sdk/utils/messaging-signing-snap-requests.d.ts.map +0 -1
  606. package/dist/types/sdk/utils/validate-login-response.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":";;;AAAA,uCAA+D;AAQ/D,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAQ3B,IAAI,cAAc,GAAyB,EAAE,CAAC;AAC9C,MAAM,gBAAgB,GAAG,CAAC,cAAsB,EAAE,EAAE;IAClD,cAAc,CAAC,cAAc,MAA7B,cAAc,CAAC,cAAc,IAAM,IAAI,GAAG,EAAE,EAAC;IAC7C,OAAO,cAAc,CAAC,cAAc,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,cAAsB,EACtB,IAAgB;IAEhB,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG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":["import { base64ToByteArray, byteArrayToBase64 } from './utils';\n\ntype CachedEntry = {\n salt: Uint8Array;\n base64Salt: string;\n key: Uint8Array;\n};\n\nconst MAX_PASSWORD_CACHES = 3;\nconst MAX_SALT_CACHES = 10;\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 any cached key for a given hashed password\n *\n * @param hashedPassword - hashed password for cache lookup\n * @returns any (the first) cached key\n */\nexport function getAnyCachedKey(\n hashedPassword: string,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n\n // Takes 1 item from an Iterator via Map.entries()\n const cachedEntry: [string, Uint8Array] | undefined = cache\n .entries()\n .next().value;\n\n if (!cachedEntry) {\n return undefined;\n }\n\n const base64Salt = cachedEntry[0];\n const bytesSalt = base64ToByteArray(base64Salt);\n return {\n salt: bytesSalt,\n base64Salt,\n key: cachedEntry[1],\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"]}
@@ -28,4 +28,4 @@ export declare function getAnyCachedKey(hashedPassword: string): CachedEntry | u
28
28
  */
29
29
  export declare function setCachedKey(hashedPassword: string, salt: Uint8Array, key: Uint8Array): void;
30
30
  export {};
31
- //# sourceMappingURL=cache.d.ts.map
31
+ //# sourceMappingURL=cache.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":"AAEA,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;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,GACrB,WAAW,GAAG,SAAS,CAmBzB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,GACd,IAAI,CAeN"}
@@ -0,0 +1,31 @@
1
+ type CachedEntry = {
2
+ salt: Uint8Array;
3
+ base64Salt: string;
4
+ key: Uint8Array;
5
+ };
6
+ /**
7
+ * Returns a given cached derived key from a hashed password and salt
8
+ *
9
+ * @param hashedPassword - hashed password for cache lookup
10
+ * @param salt - provide salt to receive cached key
11
+ * @returns cached key
12
+ */
13
+ export declare function getCachedKeyBySalt(hashedPassword: string, salt: Uint8Array): CachedEntry | undefined;
14
+ /**
15
+ * Gets any cached key for a given hashed password
16
+ *
17
+ * @param hashedPassword - hashed password for cache lookup
18
+ * @returns any (the first) cached key
19
+ */
20
+ export declare function getAnyCachedKey(hashedPassword: string): CachedEntry | undefined;
21
+ /**
22
+ * Sets a key to the in memory cache.
23
+ * We have set an arbitrary size of 10 cached keys per hashed password.
24
+ *
25
+ * @param hashedPassword - hashed password for cache lookup
26
+ * @param salt - salt to set new derived key
27
+ * @param key - derived key we are setting
28
+ */
29
+ export declare function setCachedKey(hashedPassword: string, salt: Uint8Array, key: Uint8Array): void;
30
+ export {};
31
+ //# sourceMappingURL=cache.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":"AAEA,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;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,GACrB,WAAW,GAAG,SAAS,CAmBzB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,GACd,IAAI,CAeN"}
@@ -1,13 +1,73 @@
1
- import {
2
- getAnyCachedKey,
3
- getCachedKeyBySalt,
4
- setCachedKey
5
- } from "../../../chunk-H25EBXG5.mjs";
6
- import "../../../chunk-76VRE4BI.mjs";
7
- import "../../../chunk-U5UIDVOO.mjs";
8
- export {
9
- getAnyCachedKey,
10
- getCachedKeyBySalt,
11
- setCachedKey
1
+ import { base64ToByteArray, byteArrayToBase64 } from "./utils.mjs";
2
+ const MAX_PASSWORD_CACHES = 3;
3
+ const MAX_SALT_CACHES = 10;
4
+ let inMemCachedKDF = {};
5
+ const getPasswordCache = (hashedPassword) => {
6
+ inMemCachedKDF[hashedPassword] ?? (inMemCachedKDF[hashedPassword] = new Map());
7
+ return inMemCachedKDF[hashedPassword];
12
8
  };
9
+ /**
10
+ * Returns a given cached derived key from a hashed password and salt
11
+ *
12
+ * @param hashedPassword - hashed password for cache lookup
13
+ * @param salt - provide salt to receive cached key
14
+ * @returns cached key
15
+ */
16
+ export function getCachedKeyBySalt(hashedPassword, salt) {
17
+ const cache = getPasswordCache(hashedPassword);
18
+ const base64Salt = byteArrayToBase64(salt);
19
+ const cachedKey = cache.get(base64Salt);
20
+ if (!cachedKey) {
21
+ return undefined;
22
+ }
23
+ return {
24
+ salt,
25
+ base64Salt,
26
+ key: cachedKey,
27
+ };
28
+ }
29
+ /**
30
+ * Gets any cached key for a given hashed password
31
+ *
32
+ * @param hashedPassword - hashed password for cache lookup
33
+ * @returns any (the first) cached key
34
+ */
35
+ export function getAnyCachedKey(hashedPassword) {
36
+ const cache = getPasswordCache(hashedPassword);
37
+ // Takes 1 item from an Iterator via Map.entries()
38
+ const cachedEntry = cache
39
+ .entries()
40
+ .next().value;
41
+ if (!cachedEntry) {
42
+ return undefined;
43
+ }
44
+ const base64Salt = cachedEntry[0];
45
+ const bytesSalt = base64ToByteArray(base64Salt);
46
+ return {
47
+ salt: bytesSalt,
48
+ base64Salt,
49
+ key: cachedEntry[1],
50
+ };
51
+ }
52
+ /**
53
+ * Sets a key to the in memory cache.
54
+ * We have set an arbitrary size of 10 cached keys per hashed password.
55
+ *
56
+ * @param hashedPassword - hashed password for cache lookup
57
+ * @param salt - salt to set new derived key
58
+ * @param key - derived key we are setting
59
+ */
60
+ export function setCachedKey(hashedPassword, salt, key) {
61
+ // Max password caches
62
+ if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {
63
+ inMemCachedKDF = {};
64
+ }
65
+ const cache = getPasswordCache(hashedPassword);
66
+ const base64Salt = byteArrayToBase64(salt);
67
+ // Max salt caches
68
+ if (cache.size > MAX_SALT_CACHES) {
69
+ cache.clear();
70
+ }
71
+ cache.set(base64Salt, key);
72
+ }
13
73
  //# sourceMappingURL=cache.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"cache.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAgB;AAQ/D,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAQ3B,IAAI,cAAc,GAAyB,EAAE,CAAC;AAC9C,MAAM,gBAAgB,GAAG,CAAC,cAAsB,EAAE,EAAE;IAClD,cAAc,CAAC,cAAc,MAA7B,cAAc,CAAC,cAAc,IAAM,IAAI,GAAG,EAAE,EAAC;IAC7C,OAAO,cAAc,CAAC,cAAc,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,cAAsB,EACtB,IAAgB;IAEhB,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI;QACJ,UAAU;QACV,GAAG,EAAE,SAAS;KACf,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,cAAsB;IAEtB,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAE/C,kDAAkD;IAClD,MAAM,WAAW,GAAqC,KAAK;SACxD,OAAO,EAAE;SACT,IAAI,EAAE,CAAC,KAAK,CAAC;IAEhB,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,UAAU;QACV,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;KACpB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,cAAsB,EACtB,IAAgB,EAChB,GAAe;IAEf,sBAAsB;IACtB,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,mBAAmB,EAAE;QAC5D,cAAc,GAAG,EAAE,CAAC;KACrB;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;QAChC,KAAK,CAAC,KAAK,EAAE,CAAC;KACf;IAED,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { base64ToByteArray, byteArrayToBase64 } from './utils';\n\ntype CachedEntry = {\n salt: Uint8Array;\n base64Salt: string;\n key: Uint8Array;\n};\n\nconst MAX_PASSWORD_CACHES = 3;\nconst MAX_SALT_CACHES = 10;\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 any cached key for a given hashed password\n *\n * @param hashedPassword - hashed password for cache lookup\n * @returns any (the first) cached key\n */\nexport function getAnyCachedKey(\n hashedPassword: string,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n\n // Takes 1 item from an Iterator via Map.entries()\n const cachedEntry: [string, Uint8Array] | undefined = cache\n .entries()\n .next().value;\n\n if (!cachedEntry) {\n return undefined;\n }\n\n const base64Salt = cachedEntry[0];\n const bytesSalt = base64ToByteArray(base64Salt);\n return {\n salt: bytesSalt,\n base64Salt,\n key: cachedEntry[1],\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"]}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _EncryptorDecryptor_instances, _EncryptorDecryptor_encryptStringV1, _EncryptorDecryptor_decryptStringV1, _EncryptorDecryptor_encrypt, _EncryptorDecryptor_decrypt, _EncryptorDecryptor_getOrGenerateScryptKey;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createSHA256Hash = void 0;
10
+ const aes_1 = require("@noble/ciphers/aes");
11
+ const webcrypto_1 = require("@noble/ciphers/webcrypto");
12
+ const scrypt_1 = require("@noble/hashes/scrypt");
13
+ const sha256_1 = require("@noble/hashes/sha256");
14
+ const utils_1 = require("@noble/hashes/utils");
15
+ const cache_1 = require("./cache.cjs");
16
+ const utils_2 = require("./utils.cjs");
17
+ // Nonce/Key Sizes
18
+ const ALGORITHM_NONCE_SIZE = 12; // 12 bytes
19
+ const ALGORITHM_KEY_SIZE = 16; // 16 bytes
20
+ // Scrypt settings
21
+ // see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt
22
+ const SCRYPT_SALT_SIZE = 16; // 16 bytes
23
+ const SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)
24
+ // eslint-disable-next-line @typescript-eslint/naming-convention
25
+ const SCRYPT_r = 8; // Block size parameter
26
+ // eslint-disable-next-line @typescript-eslint/naming-convention
27
+ const SCRYPT_p = 1; // Parallelization parameter
28
+ class EncryptorDecryptor {
29
+ constructor() {
30
+ _EncryptorDecryptor_instances.add(this);
31
+ }
32
+ async encryptString(plaintext, password, nativeScryptCrypto) {
33
+ try {
34
+ return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encryptStringV1).call(this, plaintext, password, nativeScryptCrypto);
35
+ }
36
+ catch (e) {
37
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
38
+ throw new Error(`Unable to encrypt string - ${errorMessage}`);
39
+ }
40
+ }
41
+ async decryptString(encryptedDataStr, password, nativeScryptCrypto) {
42
+ try {
43
+ const encryptedData = JSON.parse(encryptedDataStr);
44
+ if (encryptedData.v === '1') {
45
+ if (encryptedData.t === 'scrypt') {
46
+ return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decryptStringV1).call(this, encryptedData, password, nativeScryptCrypto);
47
+ }
48
+ }
49
+ throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
50
+ }
51
+ catch (e) {
52
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
53
+ throw new Error(`Unable to decrypt string - ${errorMessage}`);
54
+ }
55
+ }
56
+ }
57
+ _EncryptorDecryptor_instances = new WeakSet(), _EncryptorDecryptor_encryptStringV1 = async function _EncryptorDecryptor_encryptStringV1(plaintext, password, nativeScryptCrypto) {
58
+ const { key, salt } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
59
+ N: SCRYPT_N,
60
+ r: SCRYPT_r,
61
+ p: SCRYPT_p,
62
+ dkLen: ALGORITHM_KEY_SIZE,
63
+ }, (0, webcrypto_1.randomBytes)(SCRYPT_SALT_SIZE), nativeScryptCrypto);
64
+ // Encrypt and prepend salt.
65
+ const plaintextRaw = (0, utils_1.utf8ToBytes)(plaintext);
66
+ const ciphertextAndNonceAndSalt = (0, utils_1.concatBytes)(salt, __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encrypt).call(this, plaintextRaw, key));
67
+ // Convert to Base64
68
+ const encryptedData = (0, utils_2.byteArrayToBase64)(ciphertextAndNonceAndSalt);
69
+ const encryptedPayload = {
70
+ v: '1',
71
+ t: 'scrypt',
72
+ d: encryptedData,
73
+ o: {
74
+ N: SCRYPT_N,
75
+ r: SCRYPT_r,
76
+ p: SCRYPT_p,
77
+ dkLen: ALGORITHM_KEY_SIZE,
78
+ },
79
+ saltLen: SCRYPT_SALT_SIZE,
80
+ };
81
+ return JSON.stringify(encryptedPayload);
82
+ }, _EncryptorDecryptor_decryptStringV1 = async function _EncryptorDecryptor_decryptStringV1(data, password, nativeScryptCrypto) {
83
+ const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
84
+ // Decode the base64.
85
+ const ciphertextAndNonceAndSalt = (0, utils_2.base64ToByteArray)(base64CiphertextAndNonceAndSalt);
86
+ // Create buffers of salt and ciphertextAndNonce.
87
+ const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
88
+ const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(saltLen, ciphertextAndNonceAndSalt.length);
89
+ // Derive the key.
90
+ const { key } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
91
+ N: o.N,
92
+ r: o.r,
93
+ p: o.p,
94
+ dkLen: o.dkLen,
95
+ }, salt, nativeScryptCrypto);
96
+ // Decrypt and return result.
97
+ return (0, utils_2.bytesToUtf8)(__classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decrypt).call(this, ciphertextAndNonce, key));
98
+ }, _EncryptorDecryptor_encrypt = function _EncryptorDecryptor_encrypt(plaintext, key) {
99
+ const nonce = (0, webcrypto_1.randomBytes)(ALGORITHM_NONCE_SIZE);
100
+ // Encrypt and prepend nonce.
101
+ const ciphertext = (0, aes_1.gcm)(key, nonce).encrypt(plaintext);
102
+ return (0, utils_1.concatBytes)(nonce, ciphertext);
103
+ }, _EncryptorDecryptor_decrypt = function _EncryptorDecryptor_decrypt(ciphertextAndNonce, key) {
104
+ // Create buffers of nonce and ciphertext.
105
+ const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
106
+ const ciphertext = ciphertextAndNonce.slice(ALGORITHM_NONCE_SIZE, ciphertextAndNonce.length);
107
+ // Decrypt and return result.
108
+ return (0, aes_1.gcm)(key, nonce).decrypt(ciphertext);
109
+ }, _EncryptorDecryptor_getOrGenerateScryptKey = async function _EncryptorDecryptor_getOrGenerateScryptKey(password, o, salt, nativeScryptCrypto) {
110
+ const hashedPassword = createSHA256Hash(password);
111
+ const cachedKey = salt
112
+ ? (0, cache_1.getCachedKeyBySalt)(hashedPassword, salt)
113
+ : (0, cache_1.getAnyCachedKey)(hashedPassword);
114
+ if (cachedKey) {
115
+ return {
116
+ key: cachedKey.key,
117
+ salt: cachedKey.salt,
118
+ };
119
+ }
120
+ const newSalt = salt ?? (0, webcrypto_1.randomBytes)(SCRYPT_SALT_SIZE);
121
+ let newKey;
122
+ if (nativeScryptCrypto) {
123
+ newKey = await nativeScryptCrypto(password, newSalt, o.N, o.r, o.p, o.dkLen);
124
+ }
125
+ else {
126
+ newKey = await (0, scrypt_1.scryptAsync)(password, newSalt, {
127
+ N: o.N,
128
+ r: o.r,
129
+ p: o.p,
130
+ dkLen: o.dkLen,
131
+ });
132
+ }
133
+ (0, cache_1.setCachedKey)(hashedPassword, newSalt, newKey);
134
+ return {
135
+ key: newKey,
136
+ salt: newSalt,
137
+ };
138
+ };
139
+ const encryption = new EncryptorDecryptor();
140
+ exports.default = encryption;
141
+ /**
142
+ * Receive a SHA256 hash from a given string
143
+ * @param data - input
144
+ * @returns sha256 hash
145
+ */
146
+ function createSHA256Hash(data) {
147
+ const hashedData = (0, sha256_1.sha256)(data);
148
+ return (0, utils_1.bytesToHex)(hashedData);
149
+ }
150
+ exports.createSHA256Hash = createSHA256Hash;
151
+ //# sourceMappingURL=encryption.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4CAAyC;AACzC,wDAAuD;AACvD,iDAAmD;AACnD,iDAA8C;AAC9C,+CAA2E;AAG3E,uCAA4E;AAC5E,uCAA4E;AAyB5E,kBA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,OAAO,EAAE,MAAM,CAAC,CAAC;IAE9C,OAAO;QACL,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,OAAO;KACd,CAAC;AACJ,CAAC;AAGH,MAAM,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC5C,kBAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,MAAM,UAAU,GAAG,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;IAChC,OAAO,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAHD,4CAGC","sourcesContent":["import { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { scryptAsync } from '@noble/hashes/scrypt';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { utf8ToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';\n\nimport type { NativeScrypt } from '../UserStorageController';\nimport { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from './cache';\nimport { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from './utils';\n\nexport type EncryptedPayload = {\n // version\n v: '1';\n\n // key derivation function algorithm - scrypt\n t: 'scrypt';\n\n // data\n d: string;\n\n // encryption options - scrypt\n o: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\n// Nonce/Key Sizes\nconst ALGORITHM_NONCE_SIZE = 12; // 12 bytes\nconst ALGORITHM_KEY_SIZE = 16; // 16 bytes\n\n// Scrypt settings\n// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt\nconst SCRYPT_SALT_SIZE = 16; // 16 bytes\nconst SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_r = 8; // Block size parameter\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_p = 1; // Parallelization parameter\n\nclass EncryptorDecryptor {\n async encryptString(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n return await this.#encryptStringV1(\n plaintext,\n password,\n nativeScryptCrypto,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to encrypt string - ${errorMessage}`);\n }\n }\n\n async decryptString(\n encryptedDataStr: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n return await this.#decryptStringV1(\n encryptedData,\n password,\n nativeScryptCrypto,\n );\n }\n }\n throw new Error(\n `Unsupported encrypted data payload - ${encryptedDataStr}`,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to decrypt string - ${errorMessage}`);\n }\n }\n\n async #encryptStringV1(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { key, salt } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n randomBytes(SCRYPT_SALT_SIZE),\n nativeScryptCrypto,\n );\n\n // Encrypt and prepend salt.\n const plaintextRaw = utf8ToBytes(plaintext);\n const ciphertextAndNonceAndSalt = concatBytes(\n salt,\n this.#encrypt(plaintextRaw, key),\n );\n\n // Convert to Base64\n const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);\n\n const encryptedPayload: EncryptedPayload = {\n v: '1',\n t: 'scrypt',\n d: encryptedData,\n o: {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n saltLen: SCRYPT_SALT_SIZE,\n };\n\n return JSON.stringify(encryptedPayload);\n }\n\n async #decryptStringV1(\n data: EncryptedPayload,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;\n\n // Decode the base64.\n const ciphertextAndNonceAndSalt = base64ToByteArray(\n base64CiphertextAndNonceAndSalt,\n );\n\n // Create buffers of salt and ciphertextAndNonce.\n const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);\n const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(\n saltLen,\n ciphertextAndNonceAndSalt.length,\n );\n\n // Derive the key.\n const { key } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n },\n salt,\n nativeScryptCrypto,\n );\n\n // Decrypt and return result.\n return bytesToUtf8(this.#decrypt(ciphertextAndNonce, key));\n }\n\n #encrypt(plaintext: Uint8Array, key: Uint8Array): Uint8Array {\n const nonce = randomBytes(ALGORITHM_NONCE_SIZE);\n\n // Encrypt and prepend nonce.\n const ciphertext = gcm(key, nonce).encrypt(plaintext);\n\n return concatBytes(nonce, ciphertext);\n }\n\n #decrypt(ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {\n // Create buffers of nonce and ciphertext.\n const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);\n const ciphertext = ciphertextAndNonce.slice(\n ALGORITHM_NONCE_SIZE,\n ciphertextAndNonce.length,\n );\n\n // Decrypt and return result.\n return gcm(key, nonce).decrypt(ciphertext);\n }\n\n async #getOrGenerateScryptKey(\n password: string,\n o: EncryptedPayload['o'],\n salt?: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ) {\n const hashedPassword = createSHA256Hash(password);\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getAnyCachedKey(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);\n\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n password,\n newSalt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, newSalt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n setCachedKey(hashedPassword, newSalt, newKey);\n\n return {\n key: newKey,\n salt: newSalt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n * @param data - input\n * @returns sha256 hash\n */\nexport function createSHA256Hash(data: string): string {\n const hashedData = sha256(data);\n return bytesToHex(hashedData);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { NativeScrypt } from '../UserStorageController';
1
+ import type { NativeScrypt } from "../UserStorageController.cjs";
2
2
  export type EncryptedPayload = {
3
3
  v: '1';
4
4
  t: 'scrypt';
@@ -24,4 +24,4 @@ export default encryption;
24
24
  * @returns sha256 hash
25
25
  */
26
26
  export declare function createSHA256Hash(data: string): string;
27
- //# sourceMappingURL=encryption.d.ts.map
27
+ //# sourceMappingURL=encryption.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAiC;AAI7D,MAAM,MAAM,gBAAgB,GAAG;IAE7B,CAAC,EAAE,GAAG,CAAC;IAGP,CAAC,EAAE,QAAQ,CAAC;IAGZ,CAAC,EAAE,MAAM,CAAC;IAGV,CAAC,EAAE;QAED,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAeF,cAAM,kBAAkB;;IAChB,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;IAaZ,aAAa,CACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;CAuKnB;AAED,QAAA,MAAM,UAAU,oBAA2B,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD"}
@@ -0,0 +1,27 @@
1
+ import type { NativeScrypt } from "../UserStorageController.mjs";
2
+ export type EncryptedPayload = {
3
+ v: '1';
4
+ t: 'scrypt';
5
+ d: string;
6
+ o: {
7
+ N: number;
8
+ r: number;
9
+ p: number;
10
+ dkLen: number;
11
+ };
12
+ saltLen: number;
13
+ };
14
+ declare class EncryptorDecryptor {
15
+ #private;
16
+ encryptString(plaintext: string, password: string, nativeScryptCrypto?: NativeScrypt): Promise<string>;
17
+ decryptString(encryptedDataStr: string, password: string, nativeScryptCrypto?: NativeScrypt): Promise<string>;
18
+ }
19
+ declare const encryption: EncryptorDecryptor;
20
+ export default encryption;
21
+ /**
22
+ * Receive a SHA256 hash from a given string
23
+ * @param data - input
24
+ * @returns sha256 hash
25
+ */
26
+ export declare function createSHA256Hash(data: string): string;
27
+ //# sourceMappingURL=encryption.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAiC;AAI7D,MAAM,MAAM,gBAAgB,GAAG;IAE7B,CAAC,EAAE,GAAG,CAAC;IAGP,CAAC,EAAE,QAAQ,CAAC;IAGZ,CAAC,EAAE,MAAM,CAAC;IAGV,CAAC,EAAE;QAED,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAeF,cAAM,kBAAkB;;IAChB,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;IAaZ,aAAa,CACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;CAuKnB;AAED,QAAA,MAAM,UAAU,oBAA2B,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD"}
@@ -1,12 +1,147 @@
1
- import {
2
- createSHA256Hash,
3
- encryption_default
4
- } from "../../../chunk-COBJUBZE.mjs";
5
- import "../../../chunk-H25EBXG5.mjs";
6
- import "../../../chunk-76VRE4BI.mjs";
7
- import "../../../chunk-U5UIDVOO.mjs";
8
- export {
9
- createSHA256Hash,
10
- encryption_default as default
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
5
  };
6
+ var _EncryptorDecryptor_instances, _EncryptorDecryptor_encryptStringV1, _EncryptorDecryptor_decryptStringV1, _EncryptorDecryptor_encrypt, _EncryptorDecryptor_decrypt, _EncryptorDecryptor_getOrGenerateScryptKey;
7
+ import { gcm } from "@noble/ciphers/aes";
8
+ import { randomBytes } from "@noble/ciphers/webcrypto";
9
+ import { scryptAsync } from "@noble/hashes/scrypt";
10
+ import { sha256 } from "@noble/hashes/sha256";
11
+ import { utf8ToBytes, concatBytes, bytesToHex } from "@noble/hashes/utils";
12
+ import { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from "./cache.mjs";
13
+ import { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from "./utils.mjs";
14
+ // Nonce/Key Sizes
15
+ const ALGORITHM_NONCE_SIZE = 12; // 12 bytes
16
+ const ALGORITHM_KEY_SIZE = 16; // 16 bytes
17
+ // Scrypt settings
18
+ // see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt
19
+ const SCRYPT_SALT_SIZE = 16; // 16 bytes
20
+ const SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)
21
+ // eslint-disable-next-line @typescript-eslint/naming-convention
22
+ const SCRYPT_r = 8; // Block size parameter
23
+ // eslint-disable-next-line @typescript-eslint/naming-convention
24
+ const SCRYPT_p = 1; // Parallelization parameter
25
+ class EncryptorDecryptor {
26
+ constructor() {
27
+ _EncryptorDecryptor_instances.add(this);
28
+ }
29
+ async encryptString(plaintext, password, nativeScryptCrypto) {
30
+ try {
31
+ return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encryptStringV1).call(this, plaintext, password, nativeScryptCrypto);
32
+ }
33
+ catch (e) {
34
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
35
+ throw new Error(`Unable to encrypt string - ${errorMessage}`);
36
+ }
37
+ }
38
+ async decryptString(encryptedDataStr, password, nativeScryptCrypto) {
39
+ try {
40
+ const encryptedData = JSON.parse(encryptedDataStr);
41
+ if (encryptedData.v === '1') {
42
+ if (encryptedData.t === 'scrypt') {
43
+ return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decryptStringV1).call(this, encryptedData, password, nativeScryptCrypto);
44
+ }
45
+ }
46
+ throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
47
+ }
48
+ catch (e) {
49
+ const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
50
+ throw new Error(`Unable to decrypt string - ${errorMessage}`);
51
+ }
52
+ }
53
+ }
54
+ _EncryptorDecryptor_instances = new WeakSet(), _EncryptorDecryptor_encryptStringV1 = async function _EncryptorDecryptor_encryptStringV1(plaintext, password, nativeScryptCrypto) {
55
+ const { key, salt } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
56
+ N: SCRYPT_N,
57
+ r: SCRYPT_r,
58
+ p: SCRYPT_p,
59
+ dkLen: ALGORITHM_KEY_SIZE,
60
+ }, randomBytes(SCRYPT_SALT_SIZE), nativeScryptCrypto);
61
+ // Encrypt and prepend salt.
62
+ const plaintextRaw = utf8ToBytes(plaintext);
63
+ const ciphertextAndNonceAndSalt = concatBytes(salt, __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encrypt).call(this, plaintextRaw, key));
64
+ // Convert to Base64
65
+ const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);
66
+ const encryptedPayload = {
67
+ v: '1',
68
+ t: 'scrypt',
69
+ d: encryptedData,
70
+ o: {
71
+ N: SCRYPT_N,
72
+ r: SCRYPT_r,
73
+ p: SCRYPT_p,
74
+ dkLen: ALGORITHM_KEY_SIZE,
75
+ },
76
+ saltLen: SCRYPT_SALT_SIZE,
77
+ };
78
+ return JSON.stringify(encryptedPayload);
79
+ }, _EncryptorDecryptor_decryptStringV1 = async function _EncryptorDecryptor_decryptStringV1(data, password, nativeScryptCrypto) {
80
+ const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
81
+ // Decode the base64.
82
+ const ciphertextAndNonceAndSalt = base64ToByteArray(base64CiphertextAndNonceAndSalt);
83
+ // Create buffers of salt and ciphertextAndNonce.
84
+ const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
85
+ const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(saltLen, ciphertextAndNonceAndSalt.length);
86
+ // Derive the key.
87
+ const { key } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
88
+ N: o.N,
89
+ r: o.r,
90
+ p: o.p,
91
+ dkLen: o.dkLen,
92
+ }, salt, nativeScryptCrypto);
93
+ // Decrypt and return result.
94
+ return bytesToUtf8(__classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decrypt).call(this, ciphertextAndNonce, key));
95
+ }, _EncryptorDecryptor_encrypt = function _EncryptorDecryptor_encrypt(plaintext, key) {
96
+ const nonce = randomBytes(ALGORITHM_NONCE_SIZE);
97
+ // Encrypt and prepend nonce.
98
+ const ciphertext = gcm(key, nonce).encrypt(plaintext);
99
+ return concatBytes(nonce, ciphertext);
100
+ }, _EncryptorDecryptor_decrypt = function _EncryptorDecryptor_decrypt(ciphertextAndNonce, key) {
101
+ // Create buffers of nonce and ciphertext.
102
+ const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
103
+ const ciphertext = ciphertextAndNonce.slice(ALGORITHM_NONCE_SIZE, ciphertextAndNonce.length);
104
+ // Decrypt and return result.
105
+ return gcm(key, nonce).decrypt(ciphertext);
106
+ }, _EncryptorDecryptor_getOrGenerateScryptKey = async function _EncryptorDecryptor_getOrGenerateScryptKey(password, o, salt, nativeScryptCrypto) {
107
+ const hashedPassword = createSHA256Hash(password);
108
+ const cachedKey = salt
109
+ ? getCachedKeyBySalt(hashedPassword, salt)
110
+ : getAnyCachedKey(hashedPassword);
111
+ if (cachedKey) {
112
+ return {
113
+ key: cachedKey.key,
114
+ salt: cachedKey.salt,
115
+ };
116
+ }
117
+ const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);
118
+ let newKey;
119
+ if (nativeScryptCrypto) {
120
+ newKey = await nativeScryptCrypto(password, newSalt, o.N, o.r, o.p, o.dkLen);
121
+ }
122
+ else {
123
+ newKey = await scryptAsync(password, newSalt, {
124
+ N: o.N,
125
+ r: o.r,
126
+ p: o.p,
127
+ dkLen: o.dkLen,
128
+ });
129
+ }
130
+ setCachedKey(hashedPassword, newSalt, newKey);
131
+ return {
132
+ key: newKey,
133
+ salt: newSalt,
134
+ };
135
+ };
136
+ const encryption = new EncryptorDecryptor();
137
+ export default encryption;
138
+ /**
139
+ * Receive a SHA256 hash from a given string
140
+ * @param data - input
141
+ * @returns sha256 hash
142
+ */
143
+ export function createSHA256Hash(data) {
144
+ const hashedData = sha256(data);
145
+ return bytesToHex(hashedData);
146
+ }
12
147
  //# sourceMappingURL=encryption.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"encryption.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,2BAA2B;AACzC,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EAAE,WAAW,EAAE,6BAA6B;AACnD,OAAO,EAAE,MAAM,EAAE,6BAA6B;AAC9C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,4BAA4B;AAG3E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,YAAY,EAAE,oBAAgB;AAC5E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,oBAAgB;AAyB5E,kBAAkB;AAClB,MAAM,oBAAoB,GAAG,EAAE,CAAC,CAAC,WAAW;AAC5C,MAAM,kBAAkB,GAAG,EAAE,CAAC,CAAC,WAAW;AAE1C,kBAAkB;AAClB,+FAA+F;AAC/F,MAAM,gBAAgB,GAAG,EAAE,CAAC,CAAC,WAAW;AACxC,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,wD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AC","sourcesContent":["import { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { scryptAsync } from '@noble/hashes/scrypt';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { utf8ToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';\n\nimport type { NativeScrypt } from '../UserStorageController';\nimport { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from './cache';\nimport { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from './utils';\n\nexport type EncryptedPayload = {\n // version\n v: '1';\n\n // key derivation function algorithm - scrypt\n t: 'scrypt';\n\n // data\n d: string;\n\n // encryption options - scrypt\n o: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\n// Nonce/Key Sizes\nconst ALGORITHM_NONCE_SIZE = 12; // 12 bytes\nconst ALGORITHM_KEY_SIZE = 16; // 16 bytes\n\n// Scrypt settings\n// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt\nconst SCRYPT_SALT_SIZE = 16; // 16 bytes\nconst SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_r = 8; // Block size parameter\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_p = 1; // Parallelization parameter\n\nclass EncryptorDecryptor {\n async encryptString(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n return await this.#encryptStringV1(\n plaintext,\n password,\n nativeScryptCrypto,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to encrypt string - ${errorMessage}`);\n }\n }\n\n async decryptString(\n encryptedDataStr: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n return await this.#decryptStringV1(\n encryptedData,\n password,\n nativeScryptCrypto,\n );\n }\n }\n throw new Error(\n `Unsupported encrypted data payload - ${encryptedDataStr}`,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to decrypt string - ${errorMessage}`);\n }\n }\n\n async #encryptStringV1(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { key, salt } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n randomBytes(SCRYPT_SALT_SIZE),\n nativeScryptCrypto,\n );\n\n // Encrypt and prepend salt.\n const plaintextRaw = utf8ToBytes(plaintext);\n const ciphertextAndNonceAndSalt = concatBytes(\n salt,\n this.#encrypt(plaintextRaw, key),\n );\n\n // Convert to Base64\n const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);\n\n const encryptedPayload: EncryptedPayload = {\n v: '1',\n t: 'scrypt',\n d: encryptedData,\n o: {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n saltLen: SCRYPT_SALT_SIZE,\n };\n\n return JSON.stringify(encryptedPayload);\n }\n\n async #decryptStringV1(\n data: EncryptedPayload,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;\n\n // Decode the base64.\n const ciphertextAndNonceAndSalt = base64ToByteArray(\n base64CiphertextAndNonceAndSalt,\n );\n\n // Create buffers of salt and ciphertextAndNonce.\n const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);\n const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(\n saltLen,\n ciphertextAndNonceAndSalt.length,\n );\n\n // Derive the key.\n const { key } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n },\n salt,\n nativeScryptCrypto,\n );\n\n // Decrypt and return result.\n return bytesToUtf8(this.#decrypt(ciphertextAndNonce, key));\n }\n\n #encrypt(plaintext: Uint8Array, key: Uint8Array): Uint8Array {\n const nonce = randomBytes(ALGORITHM_NONCE_SIZE);\n\n // Encrypt and prepend nonce.\n const ciphertext = gcm(key, nonce).encrypt(plaintext);\n\n return concatBytes(nonce, ciphertext);\n }\n\n #decrypt(ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {\n // Create buffers of nonce and ciphertext.\n const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);\n const ciphertext = ciphertextAndNonce.slice(\n ALGORITHM_NONCE_SIZE,\n ciphertextAndNonce.length,\n );\n\n // Decrypt and return result.\n return gcm(key, nonce).decrypt(ciphertext);\n }\n\n async #getOrGenerateScryptKey(\n password: string,\n o: EncryptedPayload['o'],\n salt?: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ) {\n const hashedPassword = createSHA256Hash(password);\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getAnyCachedKey(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);\n\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n password,\n newSalt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, newSalt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n setCachedKey(hashedPassword, newSalt, newKey);\n\n return {\n key: newKey,\n salt: newSalt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n * @param data - input\n * @returns sha256 hash\n */\nexport function createSHA256Hash(data: string): string {\n const hashedData = sha256(data);\n return bytesToHex(hashedData);\n}\n"]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.Encryption = void 0;
21
+ const encryption_1 = __importDefault(require("./encryption.cjs"));
22
+ exports.Encryption = encryption_1.default;
23
+ __exportStar(require("./encryption.cjs"), exports);
24
+ exports.default = encryption_1.default;
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kEAAsC;AAE7B,qBAFF,oBAAU,CAEE;AACnB,mDAA6B;AAC7B,kBAAe,oBAAU,CAAC","sourcesContent":["import Encryption from './encryption';\n\nexport { Encryption };\nexport * from './encryption';\nexport default Encryption;\n"]}
@@ -0,0 +1,5 @@
1
+ import Encryption from "./encryption.cjs";
2
+ export { Encryption };
3
+ export * from "./encryption.cjs";
4
+ export default Encryption;
5
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAqB;AAEtC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAA6B;AAC7B,eAAe,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ import Encryption from "./encryption.mjs";
2
+ export { Encryption };
3
+ export * from "./encryption.mjs";
4
+ export default Encryption;
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAqB;AAEtC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAA6B;AAC7B,eAAe,UAAU,CAAC"}