@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
@@ -1,209 +0,0 @@
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_kdfPromiseCache, _EncryptorDecryptor_encryptStringV1, _EncryptorDecryptor_decryptStringV1, _EncryptorDecryptor_encrypt, _EncryptorDecryptor_decrypt, _EncryptorDecryptor_getOrGenerateScryptKey, _EncryptorDecryptor_createKdfCacheKey, _EncryptorDecryptor_performKdfOperation;
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_js_1 = require("./cache.cjs");
16
- const constants_js_1 = require("./constants.cjs");
17
- const utils_js_1 = require("./utils.cjs");
18
- class EncryptorDecryptor {
19
- constructor() {
20
- _EncryptorDecryptor_instances.add(this);
21
- // Promise cache for ongoing KDF operations to prevent duplicate work
22
- _EncryptorDecryptor_kdfPromiseCache.set(this, new Map());
23
- }
24
- async encryptString(plaintext, password, nativeScryptCrypto) {
25
- try {
26
- return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encryptStringV1).call(this, plaintext, password, nativeScryptCrypto);
27
- }
28
- catch (e) {
29
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
30
- throw new Error(`Unable to encrypt string - ${errorMessage}`);
31
- }
32
- }
33
- async decryptString(encryptedDataStr, password, nativeScryptCrypto) {
34
- try {
35
- const encryptedData = JSON.parse(encryptedDataStr);
36
- if (encryptedData.v === '1') {
37
- if (encryptedData.t === 'scrypt') {
38
- return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decryptStringV1).call(this, encryptedData, password, nativeScryptCrypto);
39
- }
40
- }
41
- throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
42
- }
43
- catch (e) {
44
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
45
- throw new Error(`Unable to decrypt string - ${errorMessage}`);
46
- }
47
- }
48
- getSalt(encryptedDataStr) {
49
- try {
50
- const encryptedData = JSON.parse(encryptedDataStr);
51
- if (encryptedData.v === '1') {
52
- if (encryptedData.t === 'scrypt') {
53
- const { d: base64CiphertextAndNonceAndSalt, saltLen } = encryptedData;
54
- // Decode the base64.
55
- const ciphertextAndNonceAndSalt = (0, utils_js_1.base64ToByteArray)(base64CiphertextAndNonceAndSalt);
56
- // Create buffers of salt and ciphertextAndNonce.
57
- const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
58
- return salt;
59
- }
60
- }
61
- throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
62
- }
63
- catch (e) {
64
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
65
- throw new Error(`Unable to get salt - ${errorMessage}`);
66
- }
67
- }
68
- getIfEntriesHaveDifferentSalts(entries) {
69
- const salts = entries
70
- .map((e) => {
71
- try {
72
- return this.getSalt(e);
73
- }
74
- catch {
75
- return undefined;
76
- }
77
- })
78
- .filter((s) => s !== undefined);
79
- const strSet = new Set(salts.map((arr) => arr.toString()));
80
- return strSet.size === salts.length;
81
- }
82
- }
83
- _EncryptorDecryptor_kdfPromiseCache = new WeakMap(), _EncryptorDecryptor_instances = new WeakSet(), _EncryptorDecryptor_encryptStringV1 = async function _EncryptorDecryptor_encryptStringV1(plaintext, password, nativeScryptCrypto) {
84
- const { key, salt } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
85
- N: constants_js_1.SCRYPT_N,
86
- r: constants_js_1.SCRYPT_r,
87
- p: constants_js_1.SCRYPT_p,
88
- dkLen: constants_js_1.ALGORITHM_KEY_SIZE,
89
- }, undefined, nativeScryptCrypto);
90
- // Encrypt and prepend salt.
91
- const plaintextRaw = (0, utils_1.utf8ToBytes)(plaintext);
92
- const ciphertextAndNonceAndSalt = (0, utils_1.concatBytes)(salt, __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encrypt).call(this, plaintextRaw, key));
93
- // Convert to Base64
94
- const encryptedData = (0, utils_js_1.byteArrayToBase64)(ciphertextAndNonceAndSalt);
95
- const encryptedPayload = {
96
- v: '1',
97
- t: 'scrypt',
98
- d: encryptedData,
99
- o: {
100
- N: constants_js_1.SCRYPT_N,
101
- r: constants_js_1.SCRYPT_r,
102
- p: constants_js_1.SCRYPT_p,
103
- dkLen: constants_js_1.ALGORITHM_KEY_SIZE,
104
- },
105
- saltLen: constants_js_1.SCRYPT_SALT_SIZE,
106
- };
107
- return JSON.stringify(encryptedPayload);
108
- }, _EncryptorDecryptor_decryptStringV1 = async function _EncryptorDecryptor_decryptStringV1(data, password, nativeScryptCrypto) {
109
- const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
110
- // Decode the base64.
111
- const ciphertextAndNonceAndSalt = (0, utils_js_1.base64ToByteArray)(base64CiphertextAndNonceAndSalt);
112
- // Create buffers of salt and ciphertextAndNonce.
113
- const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
114
- const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(saltLen, ciphertextAndNonceAndSalt.length);
115
- // Derive the key.
116
- const { key } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
117
- N: o.N,
118
- r: o.r,
119
- p: o.p,
120
- dkLen: o.dkLen,
121
- }, salt, nativeScryptCrypto);
122
- // Decrypt and return result.
123
- return (0, utils_js_1.bytesToUtf8)(__classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decrypt).call(this, ciphertextAndNonce, key));
124
- }, _EncryptorDecryptor_encrypt = function _EncryptorDecryptor_encrypt(plaintext, key) {
125
- const nonce = (0, webcrypto_1.randomBytes)(constants_js_1.ALGORITHM_NONCE_SIZE);
126
- // Encrypt and prepend nonce.
127
- const ciphertext = (0, aes_1.gcm)(key, nonce).encrypt(plaintext);
128
- return (0, utils_1.concatBytes)(nonce, ciphertext);
129
- }, _EncryptorDecryptor_decrypt = function _EncryptorDecryptor_decrypt(ciphertextAndNonce, key) {
130
- // Create buffers of nonce and ciphertext.
131
- const nonce = ciphertextAndNonce.slice(0, constants_js_1.ALGORITHM_NONCE_SIZE);
132
- const ciphertext = ciphertextAndNonce.slice(constants_js_1.ALGORITHM_NONCE_SIZE, ciphertextAndNonce.length);
133
- // Decrypt and return result.
134
- return (0, aes_1.gcm)(key, nonce).decrypt(ciphertext);
135
- }, _EncryptorDecryptor_getOrGenerateScryptKey = async function _EncryptorDecryptor_getOrGenerateScryptKey(password, o, salt, nativeScryptCrypto) {
136
- const hashedPassword = createSHA256Hash(password);
137
- // Check if we already have the key cached
138
- const cachedKey = salt
139
- ? (0, cache_js_1.getCachedKeyBySalt)(hashedPassword, salt)
140
- : (0, cache_js_1.getCachedKeyGeneratedWithSharedSalt)(hashedPassword);
141
- if (cachedKey) {
142
- return {
143
- key: cachedKey.key,
144
- salt: cachedKey.salt,
145
- };
146
- }
147
- // Create a unique cache key for this KDF operation
148
- const newSalt = salt ?? constants_js_1.SHARED_SALT;
149
- const cacheKey = __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_createKdfCacheKey).call(this, hashedPassword, o, newSalt, nativeScryptCrypto);
150
- // Check if there's already an ongoing KDF operation with the same parameters
151
- const existingPromise = __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").get(cacheKey);
152
- if (existingPromise) {
153
- return existingPromise;
154
- }
155
- // Limit cache size to prevent unbounded growth
156
- if (__classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").size >= constants_js_1.MAX_KDF_PROMISE_CACHE_SIZE) {
157
- // Remove the oldest entry (first inserted)
158
- const firstKey = __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").keys().next().value;
159
- if (firstKey) {
160
- __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").delete(firstKey);
161
- }
162
- }
163
- // Create and cache the promise for the KDF operation
164
- const kdfPromise = __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_performKdfOperation).call(this, password, o, newSalt, hashedPassword, nativeScryptCrypto);
165
- // Cache the promise and set up cleanup
166
- __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").set(cacheKey, kdfPromise);
167
- // Clean up the cache after completion (both success and failure)
168
- // eslint-disable-next-line no-void
169
- void kdfPromise.finally(() => {
170
- __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").delete(cacheKey);
171
- });
172
- return kdfPromise;
173
- }, _EncryptorDecryptor_createKdfCacheKey = function _EncryptorDecryptor_createKdfCacheKey(hashedPassword, o, salt, nativeScryptCrypto) {
174
- const saltStr = (0, utils_js_1.byteArrayToBase64)(salt);
175
- const hasNative = Boolean(nativeScryptCrypto);
176
- return `${hashedPassword}:${o.N}:${o.r}:${o.p}:${o.dkLen}:${saltStr}:${hasNative}`;
177
- }, _EncryptorDecryptor_performKdfOperation = async function _EncryptorDecryptor_performKdfOperation(password, o, salt, hashedPassword, nativeScryptCrypto) {
178
- let newKey;
179
- if (nativeScryptCrypto) {
180
- newKey = await nativeScryptCrypto((0, utils_js_1.stringToByteArray)(password), salt, o.N, o.r, o.p, o.dkLen);
181
- }
182
- else {
183
- newKey = await (0, scrypt_1.scryptAsync)(password, salt, {
184
- N: o.N,
185
- r: o.r,
186
- p: o.p,
187
- dkLen: o.dkLen,
188
- });
189
- }
190
- (0, cache_js_1.setCachedKey)(hashedPassword, salt, newKey);
191
- return {
192
- key: newKey,
193
- salt,
194
- };
195
- };
196
- const encryption = new EncryptorDecryptor();
197
- exports.default = encryption;
198
- /**
199
- * Receive a SHA256 hash from a given string
200
- *
201
- * @param data - input
202
- * @returns sha256 hash
203
- */
204
- function createSHA256Hash(data) {
205
- const hashedData = (0, sha256_1.sha256)(data);
206
- return (0, utils_1.bytesToHex)(hashedData);
207
- }
208
- exports.createSHA256Hash = createSHA256Hash;
209
- //# sourceMappingURL=encryption.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption.cjs","sourceRoot":"","sources":["../../../src/shared/encryption/encryption.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4CAAyC;AACzC,wDAAuD;AACvD,iDAAmD;AACnD,iDAA8C;AAC9C,+CAA2E;AAG3E,0CAIoB;AACpB,kDASwB;AACxB,0CAKoB;AAwBpB,MAAM,kBAAkB;IAAxB;;QACE,qEAAqE;QAC5D,8CAAmB,IAAI,GAAG,EAGhC,EAAC;IAuSN,CAAC;IArSC,KAAK,CAAC,aAAa,CACjB,SAAiB,EACjB,QAAgB,EAChB,kBAAiC;QAEjC,IAAI,CAAC;YACH,OAAO,MAAM,uBAAA,IAAI,0EAAiB,MAArB,IAAI,EACf,SAAS,EACT,QAAQ,EACR,kBAAkB,CACnB,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,gBAAwB,EACxB,QAAgB,EAChB,kBAAiC;QAEjC,IAAI,CAAC;YACH,MAAM,aAAa,GAAqB,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACrE,IAAI,aAAa,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBAC5B,IAAI,aAAa,CAAC,CAAC,KAAK,QAAQ,EAAE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AACrF,CAAC,4CAED,KAAK,kDACH,QAAgB,EAChB,CAAwB,EACxB,IAAgB,EAChB,cAAsB,EACtB,kBAAiC;IAEjC,IAAI,MAAkB,CAAC;IAEvB,IAAI,kBAAkB,EAAE,CAAC;QACvB,MAAM,GAAG,MAAM,kBAAkB,CAC/B,IAAA,4BAAiB,EAAC,QAAQ,CAAC,EAC3B,IAAI,EACJ,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,KAAK,CACR,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,IAAA,oBAAW,EAAC,QAAQ,EAAE,IAAI,EAAE;YACzC,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC,CAAC;IACL,CAAC;IAED,IAAA,uBAAY,EAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAE3C,OAAO;QACL,GAAG,EAAE,MAAM;QACX,IAAI;KACL,CAAC;AACJ,CAAC;AAGH,MAAM,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC5C,kBAAe,UAAU,CAAC;AAE1B;;;;;GAKG;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 '../types/encryption.js';\nimport {\n getCachedKeyBySalt,\n getCachedKeyGeneratedWithSharedSalt,\n setCachedKey,\n} from './cache.js';\nimport {\n ALGORITHM_KEY_SIZE,\n ALGORITHM_NONCE_SIZE,\n MAX_KDF_PROMISE_CACHE_SIZE,\n SCRYPT_N,\n SCRYPT_p,\n SCRYPT_r,\n SCRYPT_SALT_SIZE,\n SHARED_SALT,\n} from './constants.js';\nimport {\n base64ToByteArray,\n byteArrayToBase64,\n bytesToUtf8,\n stringToByteArray,\n} from './utils.js';\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 N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\nclass EncryptorDecryptor {\n // Promise cache for ongoing KDF operations to prevent duplicate work\n readonly #kdfPromiseCache = new Map<\n string,\n Promise<{ key: Uint8Array; salt: Uint8Array }>\n >();\n\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 undefined,\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 getSalt(encryptedDataStr: string) {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n const { d: base64CiphertextAndNonceAndSalt, saltLen } = encryptedData;\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 return salt;\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 get salt - ${errorMessage}`);\n }\n }\n\n getIfEntriesHaveDifferentSalts(entries: string[]): boolean {\n const salts = entries\n .map((e) => {\n try {\n return this.getSalt(e);\n } catch {\n return undefined;\n }\n })\n .filter((s): s is Uint8Array => s !== undefined);\n\n const strSet = new Set(salts.map((arr) => arr.toString()));\n return strSet.size === salts.length;\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\n // Check if we already have the key cached\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getCachedKeyGeneratedWithSharedSalt(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n // Create a unique cache key for this KDF operation\n const newSalt = salt ?? SHARED_SALT;\n const cacheKey = this.#createKdfCacheKey(\n hashedPassword,\n o,\n newSalt,\n nativeScryptCrypto,\n );\n\n // Check if there's already an ongoing KDF operation with the same parameters\n const existingPromise = this.#kdfPromiseCache.get(cacheKey);\n if (existingPromise) {\n return existingPromise;\n }\n\n // Limit cache size to prevent unbounded growth\n if (this.#kdfPromiseCache.size >= MAX_KDF_PROMISE_CACHE_SIZE) {\n // Remove the oldest entry (first inserted)\n const firstKey = this.#kdfPromiseCache.keys().next().value;\n if (firstKey) {\n this.#kdfPromiseCache.delete(firstKey);\n }\n }\n\n // Create and cache the promise for the KDF operation\n const kdfPromise = this.#performKdfOperation(\n password,\n o,\n newSalt,\n hashedPassword,\n nativeScryptCrypto,\n );\n\n // Cache the promise and set up cleanup\n this.#kdfPromiseCache.set(cacheKey, kdfPromise);\n\n // Clean up the cache after completion (both success and failure)\n // eslint-disable-next-line no-void\n void kdfPromise.finally(() => {\n this.#kdfPromiseCache.delete(cacheKey);\n });\n\n return kdfPromise;\n }\n\n #createKdfCacheKey(\n hashedPassword: string,\n o: EncryptedPayload['o'],\n salt: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ): string {\n const saltStr = byteArrayToBase64(salt);\n const hasNative = Boolean(nativeScryptCrypto);\n return `${hashedPassword}:${o.N}:${o.r}:${o.p}:${o.dkLen}:${saltStr}:${hasNative}`;\n }\n\n async #performKdfOperation(\n password: string,\n o: EncryptedPayload['o'],\n salt: Uint8Array,\n hashedPassword: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<{ key: Uint8Array; salt: Uint8Array }> {\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n stringToByteArray(password),\n salt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, salt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n\n setCachedKey(hashedPassword, salt, newKey);\n\n return {\n key: newKey,\n salt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n *\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 +0,0 @@
1
- {"version":3,"file":"encryption.d.cts","sourceRoot":"","sources":["../../../src/shared/encryption/encryption.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,gCAA+B;AAuB3D,MAAM,MAAM,gBAAgB,GAAG;IAE7B,CAAC,EAAE,GAAG,CAAC;IAGP,CAAC,EAAE,QAAQ,CAAC;IAGZ,CAAC,EAAE,MAAM,CAAC;IAGV,CAAC,EAAE;QACD,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;;IAOhB,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;IAoGlB,OAAO,CAAC,gBAAgB,EAAE,MAAM;IA0BhC,8BAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO;CAkJ3D;AAED,QAAA,MAAM,UAAU,oBAA2B,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD"}
@@ -1,30 +0,0 @@
1
- import type { NativeScrypt } from "../types/encryption.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
- getSalt(encryptedDataStr: string): Uint8Array;
19
- getIfEntriesHaveDifferentSalts(entries: string[]): boolean;
20
- }
21
- declare const encryption: EncryptorDecryptor;
22
- export default encryption;
23
- /**
24
- * Receive a SHA256 hash from a given string
25
- *
26
- * @param data - input
27
- * @returns sha256 hash
28
- */
29
- export declare function createSHA256Hash(data: string): string;
30
- //# sourceMappingURL=encryption.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption.d.mts","sourceRoot":"","sources":["../../../src/shared/encryption/encryption.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,gCAA+B;AAuB3D,MAAM,MAAM,gBAAgB,GAAG;IAE7B,CAAC,EAAE,GAAG,CAAC;IAGP,CAAC,EAAE,QAAQ,CAAC;IAGZ,CAAC,EAAE,MAAM,CAAC;IAGV,CAAC,EAAE;QACD,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;;IAOhB,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;IAoGlB,OAAO,CAAC,gBAAgB,EAAE,MAAM;IA0BhC,8BAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO;CAkJ3D;AAED,QAAA,MAAM,UAAU,oBAA2B,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD"}
@@ -1,205 +0,0 @@
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);
5
- };
6
- var _EncryptorDecryptor_instances, _EncryptorDecryptor_kdfPromiseCache, _EncryptorDecryptor_encryptStringV1, _EncryptorDecryptor_decryptStringV1, _EncryptorDecryptor_encrypt, _EncryptorDecryptor_decrypt, _EncryptorDecryptor_getOrGenerateScryptKey, _EncryptorDecryptor_createKdfCacheKey, _EncryptorDecryptor_performKdfOperation;
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 { getCachedKeyBySalt, getCachedKeyGeneratedWithSharedSalt, setCachedKey } from "./cache.mjs";
13
- import { ALGORITHM_KEY_SIZE, ALGORITHM_NONCE_SIZE, MAX_KDF_PROMISE_CACHE_SIZE, SCRYPT_N, SCRYPT_p, SCRYPT_r, SCRYPT_SALT_SIZE, SHARED_SALT } from "./constants.mjs";
14
- import { base64ToByteArray, byteArrayToBase64, bytesToUtf8, stringToByteArray } from "./utils.mjs";
15
- class EncryptorDecryptor {
16
- constructor() {
17
- _EncryptorDecryptor_instances.add(this);
18
- // Promise cache for ongoing KDF operations to prevent duplicate work
19
- _EncryptorDecryptor_kdfPromiseCache.set(this, new Map());
20
- }
21
- async encryptString(plaintext, password, nativeScryptCrypto) {
22
- try {
23
- return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encryptStringV1).call(this, plaintext, password, nativeScryptCrypto);
24
- }
25
- catch (e) {
26
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
27
- throw new Error(`Unable to encrypt string - ${errorMessage}`);
28
- }
29
- }
30
- async decryptString(encryptedDataStr, password, nativeScryptCrypto) {
31
- try {
32
- const encryptedData = JSON.parse(encryptedDataStr);
33
- if (encryptedData.v === '1') {
34
- if (encryptedData.t === 'scrypt') {
35
- return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decryptStringV1).call(this, encryptedData, password, nativeScryptCrypto);
36
- }
37
- }
38
- throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
39
- }
40
- catch (e) {
41
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
42
- throw new Error(`Unable to decrypt string - ${errorMessage}`);
43
- }
44
- }
45
- getSalt(encryptedDataStr) {
46
- try {
47
- const encryptedData = JSON.parse(encryptedDataStr);
48
- if (encryptedData.v === '1') {
49
- if (encryptedData.t === 'scrypt') {
50
- const { d: base64CiphertextAndNonceAndSalt, saltLen } = encryptedData;
51
- // Decode the base64.
52
- const ciphertextAndNonceAndSalt = base64ToByteArray(base64CiphertextAndNonceAndSalt);
53
- // Create buffers of salt and ciphertextAndNonce.
54
- const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
55
- return salt;
56
- }
57
- }
58
- throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
59
- }
60
- catch (e) {
61
- const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
62
- throw new Error(`Unable to get salt - ${errorMessage}`);
63
- }
64
- }
65
- getIfEntriesHaveDifferentSalts(entries) {
66
- const salts = entries
67
- .map((e) => {
68
- try {
69
- return this.getSalt(e);
70
- }
71
- catch {
72
- return undefined;
73
- }
74
- })
75
- .filter((s) => s !== undefined);
76
- const strSet = new Set(salts.map((arr) => arr.toString()));
77
- return strSet.size === salts.length;
78
- }
79
- }
80
- _EncryptorDecryptor_kdfPromiseCache = new WeakMap(), _EncryptorDecryptor_instances = new WeakSet(), _EncryptorDecryptor_encryptStringV1 = async function _EncryptorDecryptor_encryptStringV1(plaintext, password, nativeScryptCrypto) {
81
- const { key, salt } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
82
- N: SCRYPT_N,
83
- r: SCRYPT_r,
84
- p: SCRYPT_p,
85
- dkLen: ALGORITHM_KEY_SIZE,
86
- }, undefined, nativeScryptCrypto);
87
- // Encrypt and prepend salt.
88
- const plaintextRaw = utf8ToBytes(plaintext);
89
- const ciphertextAndNonceAndSalt = concatBytes(salt, __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encrypt).call(this, plaintextRaw, key));
90
- // Convert to Base64
91
- const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);
92
- const encryptedPayload = {
93
- v: '1',
94
- t: 'scrypt',
95
- d: encryptedData,
96
- o: {
97
- N: SCRYPT_N,
98
- r: SCRYPT_r,
99
- p: SCRYPT_p,
100
- dkLen: ALGORITHM_KEY_SIZE,
101
- },
102
- saltLen: SCRYPT_SALT_SIZE,
103
- };
104
- return JSON.stringify(encryptedPayload);
105
- }, _EncryptorDecryptor_decryptStringV1 = async function _EncryptorDecryptor_decryptStringV1(data, password, nativeScryptCrypto) {
106
- const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
107
- // Decode the base64.
108
- const ciphertextAndNonceAndSalt = base64ToByteArray(base64CiphertextAndNonceAndSalt);
109
- // Create buffers of salt and ciphertextAndNonce.
110
- const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
111
- const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(saltLen, ciphertextAndNonceAndSalt.length);
112
- // Derive the key.
113
- const { key } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
114
- N: o.N,
115
- r: o.r,
116
- p: o.p,
117
- dkLen: o.dkLen,
118
- }, salt, nativeScryptCrypto);
119
- // Decrypt and return result.
120
- return bytesToUtf8(__classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decrypt).call(this, ciphertextAndNonce, key));
121
- }, _EncryptorDecryptor_encrypt = function _EncryptorDecryptor_encrypt(plaintext, key) {
122
- const nonce = randomBytes(ALGORITHM_NONCE_SIZE);
123
- // Encrypt and prepend nonce.
124
- const ciphertext = gcm(key, nonce).encrypt(plaintext);
125
- return concatBytes(nonce, ciphertext);
126
- }, _EncryptorDecryptor_decrypt = function _EncryptorDecryptor_decrypt(ciphertextAndNonce, key) {
127
- // Create buffers of nonce and ciphertext.
128
- const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
129
- const ciphertext = ciphertextAndNonce.slice(ALGORITHM_NONCE_SIZE, ciphertextAndNonce.length);
130
- // Decrypt and return result.
131
- return gcm(key, nonce).decrypt(ciphertext);
132
- }, _EncryptorDecryptor_getOrGenerateScryptKey = async function _EncryptorDecryptor_getOrGenerateScryptKey(password, o, salt, nativeScryptCrypto) {
133
- const hashedPassword = createSHA256Hash(password);
134
- // Check if we already have the key cached
135
- const cachedKey = salt
136
- ? getCachedKeyBySalt(hashedPassword, salt)
137
- : getCachedKeyGeneratedWithSharedSalt(hashedPassword);
138
- if (cachedKey) {
139
- return {
140
- key: cachedKey.key,
141
- salt: cachedKey.salt,
142
- };
143
- }
144
- // Create a unique cache key for this KDF operation
145
- const newSalt = salt ?? SHARED_SALT;
146
- const cacheKey = __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_createKdfCacheKey).call(this, hashedPassword, o, newSalt, nativeScryptCrypto);
147
- // Check if there's already an ongoing KDF operation with the same parameters
148
- const existingPromise = __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").get(cacheKey);
149
- if (existingPromise) {
150
- return existingPromise;
151
- }
152
- // Limit cache size to prevent unbounded growth
153
- if (__classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").size >= MAX_KDF_PROMISE_CACHE_SIZE) {
154
- // Remove the oldest entry (first inserted)
155
- const firstKey = __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").keys().next().value;
156
- if (firstKey) {
157
- __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").delete(firstKey);
158
- }
159
- }
160
- // Create and cache the promise for the KDF operation
161
- const kdfPromise = __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_performKdfOperation).call(this, password, o, newSalt, hashedPassword, nativeScryptCrypto);
162
- // Cache the promise and set up cleanup
163
- __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").set(cacheKey, kdfPromise);
164
- // Clean up the cache after completion (both success and failure)
165
- // eslint-disable-next-line no-void
166
- void kdfPromise.finally(() => {
167
- __classPrivateFieldGet(this, _EncryptorDecryptor_kdfPromiseCache, "f").delete(cacheKey);
168
- });
169
- return kdfPromise;
170
- }, _EncryptorDecryptor_createKdfCacheKey = function _EncryptorDecryptor_createKdfCacheKey(hashedPassword, o, salt, nativeScryptCrypto) {
171
- const saltStr = byteArrayToBase64(salt);
172
- const hasNative = Boolean(nativeScryptCrypto);
173
- return `${hashedPassword}:${o.N}:${o.r}:${o.p}:${o.dkLen}:${saltStr}:${hasNative}`;
174
- }, _EncryptorDecryptor_performKdfOperation = async function _EncryptorDecryptor_performKdfOperation(password, o, salt, hashedPassword, nativeScryptCrypto) {
175
- let newKey;
176
- if (nativeScryptCrypto) {
177
- newKey = await nativeScryptCrypto(stringToByteArray(password), salt, o.N, o.r, o.p, o.dkLen);
178
- }
179
- else {
180
- newKey = await scryptAsync(password, salt, {
181
- N: o.N,
182
- r: o.r,
183
- p: o.p,
184
- dkLen: o.dkLen,
185
- });
186
- }
187
- setCachedKey(hashedPassword, salt, newKey);
188
- return {
189
- key: newKey,
190
- salt,
191
- };
192
- };
193
- const encryption = new EncryptorDecryptor();
194
- export default encryption;
195
- /**
196
- * Receive a SHA256 hash from a given string
197
- *
198
- * @param data - input
199
- * @returns sha256 hash
200
- */
201
- export function createSHA256Hash(data) {
202
- const hashedData = sha256(data);
203
- return bytesToHex(hashedData);
204
- }
205
- //# sourceMappingURL=encryption.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryption.mjs","sourceRoot":"","sources":["../../../src/shared/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,EACL,kBAAkB,EAClB,mCAAmC,EACnC,YAAY,EACb,oBAAmB;AACpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACZ,wBAAuB;AACxB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EAClB,oBAAmB;AAwBpB,MAAM,kBAAkB;IAAxB;;QACE,qEAAqE;QAC5D,8CAAmB,IAAI,GAAG,EAGhC,EAAC;IAuSN,CAAC;IArSC,KAAK,CAAC,aAAa,CACjB,SAAiB,EACjB,QAAgB,EAChB,kBAAiC;QAEjC,IAAI,CAAC;YACH,OAAO,MAAM,uBAAA,IAAI,0EAAiB,MAArB,IAAI,EACf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AE,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC","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 '../types/encryption.js';\nimport {\n getCachedKeyBySalt,\n getCachedKeyGeneratedWithSharedSalt,\n setCachedKey,\n} from './cache.js';\nimport {\n ALGORITHM_KEY_SIZE,\n ALGORITHM_NONCE_SIZE,\n MAX_KDF_PROMISE_CACHE_SIZE,\n SCRYPT_N,\n SCRYPT_p,\n SCRYPT_r,\n SCRYPT_SALT_SIZE,\n SHARED_SALT,\n} from './constants.js';\nimport {\n base64ToByteArray,\n byteArrayToBase64,\n bytesToUtf8,\n stringToByteArray,\n} from './utils.js';\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 N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\nclass EncryptorDecryptor {\n // Promise cache for ongoing KDF operations to prevent duplicate work\n readonly #kdfPromiseCache = new Map<\n string,\n Promise<{ key: Uint8Array; salt: Uint8Array }>\n >();\n\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 undefined,\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 getSalt(encryptedDataStr: string) {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n const { d: base64CiphertextAndNonceAndSalt, saltLen } = encryptedData;\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 return salt;\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 get salt - ${errorMessage}`);\n }\n }\n\n getIfEntriesHaveDifferentSalts(entries: string[]): boolean {\n const salts = entries\n .map((e) => {\n try {\n return this.getSalt(e);\n } catch {\n return undefined;\n }\n })\n .filter((s): s is Uint8Array => s !== undefined);\n\n const strSet = new Set(salts.map((arr) => arr.toString()));\n return strSet.size === salts.length;\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\n // Check if we already have the key cached\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getCachedKeyGeneratedWithSharedSalt(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n // Create a unique cache key for this KDF operation\n const newSalt = salt ?? SHARED_SALT;\n const cacheKey = this.#createKdfCacheKey(\n hashedPassword,\n o,\n newSalt,\n nativeScryptCrypto,\n );\n\n // Check if there's already an ongoing KDF operation with the same parameters\n const existingPromise = this.#kdfPromiseCache.get(cacheKey);\n if (existingPromise) {\n return existingPromise;\n }\n\n // Limit cache size to prevent unbounded growth\n if (this.#kdfPromiseCache.size >= MAX_KDF_PROMISE_CACHE_SIZE) {\n // Remove the oldest entry (first inserted)\n const firstKey = this.#kdfPromiseCache.keys().next().value;\n if (firstKey) {\n this.#kdfPromiseCache.delete(firstKey);\n }\n }\n\n // Create and cache the promise for the KDF operation\n const kdfPromise = this.#performKdfOperation(\n password,\n o,\n newSalt,\n hashedPassword,\n nativeScryptCrypto,\n );\n\n // Cache the promise and set up cleanup\n this.#kdfPromiseCache.set(cacheKey, kdfPromise);\n\n // Clean up the cache after completion (both success and failure)\n // eslint-disable-next-line no-void\n void kdfPromise.finally(() => {\n this.#kdfPromiseCache.delete(cacheKey);\n });\n\n return kdfPromise;\n }\n\n #createKdfCacheKey(\n hashedPassword: string,\n o: EncryptedPayload['o'],\n salt: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ): string {\n const saltStr = byteArrayToBase64(salt);\n const hasNative = Boolean(nativeScryptCrypto);\n return `${hashedPassword}:${o.N}:${o.r}:${o.p}:${o.dkLen}:${saltStr}:${hasNative}`;\n }\n\n async #performKdfOperation(\n password: string,\n o: EncryptedPayload['o'],\n salt: Uint8Array,\n hashedPassword: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<{ key: Uint8Array; salt: Uint8Array }> {\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n stringToByteArray(password),\n salt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, salt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n\n setCachedKey(hashedPassword, salt, newKey);\n\n return {\n key: newKey,\n salt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n *\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,25 +0,0 @@
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_js_1 = __importDefault(require("./encryption.cjs"));
22
- exports.Encryption = encryption_js_1.default;
23
- __exportStar(require("./encryption.cjs"), exports);
24
- exports.default = encryption_js_1.default;
25
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/shared/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,qEAAyC;AAEhC,qBAFF,uBAAU,CAEE;AACnB,mDAAgC;AAChC,kBAAe,uBAAU,CAAC","sourcesContent":["import Encryption from './encryption.js';\n\nexport { Encryption };\nexport * from './encryption.js';\nexport default Encryption;\n"]}
@@ -1,5 +0,0 @@
1
- import Encryption from "./encryption.cjs";
2
- export { Encryption };
3
- export * from "./encryption.cjs";
4
- export default Encryption;
5
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/shared/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAwB;AAEzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAAgC;AAChC,eAAe,UAAU,CAAC"}
@@ -1,5 +0,0 @@
1
- import Encryption from "./encryption.mjs";
2
- export { Encryption };
3
- export * from "./encryption.mjs";
4
- export default Encryption;
5
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/shared/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAwB;AAEzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAAgC;AAChC,eAAe,UAAU,CAAC"}
@@ -1,5 +0,0 @@
1
- import Encryption from "./encryption.mjs";
2
- export { Encryption };
3
- export * from "./encryption.mjs";
4
- export default Encryption;
5
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/shared/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAwB;AAEzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAAgC;AAChC,eAAe,UAAU,CAAC","sourcesContent":["import Encryption from './encryption.js';\n\nexport { Encryption };\nexport * from './encryption.js';\nexport default Encryption;\n"]}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringToByteArray = exports.bytesToUtf8 = exports.base64ToByteArray = exports.byteArrayToBase64 = void 0;
4
- const byteArrayToBase64 = (byteArray) => {
5
- return Buffer.from(byteArray).toString('base64');
6
- };
7
- exports.byteArrayToBase64 = byteArrayToBase64;
8
- const base64ToByteArray = (base64) => {
9
- return new Uint8Array(Buffer.from(base64, 'base64'));
10
- };
11
- exports.base64ToByteArray = base64ToByteArray;
12
- const bytesToUtf8 = (byteArray) => {
13
- const decoder = new TextDecoder('utf-8');
14
- return decoder.decode(byteArray);
15
- };
16
- exports.bytesToUtf8 = bytesToUtf8;
17
- const stringToByteArray = (str) => {
18
- return new TextEncoder().encode(str);
19
- };
20
- exports.stringToByteArray = stringToByteArray;
21
- //# sourceMappingURL=utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../src/shared/encryption/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,SAAqB,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,EAAE;IAClD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,WAAW,GAAG,CAAC,SAAqB,EAAE,EAAE;IACnD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,CAAC;AAHW,QAAA,WAAW,eAGtB;AAEK,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAE,EAAE;IAC/C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B","sourcesContent":["export const byteArrayToBase64 = (byteArray: Uint8Array) => {\n return Buffer.from(byteArray).toString('base64');\n};\n\nexport const base64ToByteArray = (base64: string) => {\n return new Uint8Array(Buffer.from(base64, 'base64'));\n};\n\nexport const bytesToUtf8 = (byteArray: Uint8Array) => {\n const decoder = new TextDecoder('utf-8');\n return decoder.decode(byteArray);\n};\n\nexport const stringToByteArray = (str: string) => {\n return new TextEncoder().encode(str);\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../../src/shared/encryption/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,cAAe,UAAU,WAEtD,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,MAAM,eAE/C,CAAC;AAEF,eAAO,MAAM,WAAW,cAAe,UAAU,WAGhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAS,MAAM,eAE5C,CAAC"}
@@ -1,5 +0,0 @@
1
- export declare const byteArrayToBase64: (byteArray: Uint8Array) => string;
2
- export declare const base64ToByteArray: (base64: string) => Uint8Array;
3
- export declare const bytesToUtf8: (byteArray: Uint8Array) => string;
4
- export declare const stringToByteArray: (str: string) => Uint8Array;
5
- //# sourceMappingURL=utils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../../src/shared/encryption/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,cAAe,UAAU,WAEtD,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,MAAM,eAE/C,CAAC;AAEF,eAAO,MAAM,WAAW,cAAe,UAAU,WAGhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAS,MAAM,eAE5C,CAAC"}