@digitaldefiance/ecies-lib 4.4.2 → 4.4.4

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 (589) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +9 -6
  3. package/src/builders/ecies-builder.ts +39 -0
  4. package/src/builders/{index.js → index.ts} +1 -1
  5. package/src/builders/member-builder.ts +155 -0
  6. package/src/constants.ts +609 -0
  7. package/src/core/errors/crypto-error.ts +78 -0
  8. package/src/core/{index.js → index.ts} +1 -1
  9. package/src/core/types/result.ts +19 -0
  10. package/src/email-string.ts +82 -0
  11. package/src/enumerations/disposed-error-type.ts +11 -0
  12. package/src/enumerations/ecies-cipher-suite.ts +4 -0
  13. package/src/enumerations/ecies-encryption-type.ts +41 -0
  14. package/src/enumerations/ecies-error-type.ts +43 -0
  15. package/src/enumerations/ecies-string-key.ts +205 -0
  16. package/src/enumerations/ecies-version.ts +3 -0
  17. package/src/enumerations/guid-brand-type.ts +26 -0
  18. package/src/enumerations/guid-error-type.ts +6 -0
  19. package/src/enumerations/id-provider-error-type.ts +50 -0
  20. package/src/enumerations/{index.js → index.ts} +0 -1
  21. package/src/enumerations/invalid-email-type.ts +5 -0
  22. package/src/enumerations/length-encoding-type.ts +6 -0
  23. package/src/enumerations/length-error-type.ts +5 -0
  24. package/src/enumerations/member-error-type.ts +106 -0
  25. package/src/enumerations/{member-type.d.ts → member-type.ts} +7 -6
  26. package/src/enumerations/password-login-error-type.ts +4 -0
  27. package/src/enumerations/pbkdf2-error-type.ts +5 -0
  28. package/src/enumerations/pbkdf2-profile.ts +5 -0
  29. package/src/enumerations/secure-storage-error-type.ts +5 -0
  30. package/src/errors/disposed.ts +36 -0
  31. package/src/errors/ecies.ts +153 -0
  32. package/src/errors/guid.ts +130 -0
  33. package/src/errors/id-provider.ts +40 -0
  34. package/src/errors/{index.d.ts → index.ts} +0 -1
  35. package/src/errors/invalid-email.ts +23 -0
  36. package/src/errors/length.ts +19 -0
  37. package/src/errors/member.ts +20 -0
  38. package/src/errors/pbkdf2.ts +20 -0
  39. package/src/errors/secure-storage.ts +17 -0
  40. package/src/errors/simple-ecies.ts +21 -0
  41. package/src/errors/simple-test-error.ts +6 -0
  42. package/src/i18n-setup.ts +130 -0
  43. package/src/{index.js → index.ts} +64 -7
  44. package/src/interfaces/checksum-config.ts +4 -0
  45. package/src/interfaces/checksum-consts.ts +13 -0
  46. package/src/interfaces/configuration-provenance.ts +54 -0
  47. package/src/interfaces/constants.ts +75 -0
  48. package/src/interfaces/ecies-config.ts +8 -0
  49. package/src/interfaces/ecies-consts.ts +74 -0
  50. package/src/interfaces/ecies-file-service.ts +6 -0
  51. package/src/interfaces/encrypted-chunk.ts +64 -0
  52. package/src/interfaces/encryption-state.ts +19 -0
  53. package/src/interfaces/frontend-member-operational.ts +77 -0
  54. package/src/interfaces/guid.ts +86 -0
  55. package/src/interfaces/id-provider.ts +152 -0
  56. package/src/interfaces/{index.d.ts → index.ts} +0 -1
  57. package/src/interfaces/invariant.ts +60 -0
  58. package/src/interfaces/library-error.ts +23 -0
  59. package/src/interfaces/{member-storage.d.ts → member-storage.ts} +11 -10
  60. package/src/interfaces/{member-with-mnemonic.d.ts → member-with-mnemonic.ts} +3 -3
  61. package/src/interfaces/member.ts +84 -0
  62. package/src/interfaces/multi-recipient-chunk.ts +61 -0
  63. package/src/interfaces/pbkdf2-config.ts +6 -0
  64. package/src/interfaces/pbkdf2-consts.ts +10 -0
  65. package/src/interfaces/pbkdf2-result.ts +5 -0
  66. package/src/interfaces/stream-config.ts +17 -0
  67. package/src/interfaces/stream-header.ts +34 -0
  68. package/src/interfaces/stream-progress.ts +31 -0
  69. package/src/lib/configuration-provenance-utils.ts +26 -0
  70. package/src/lib/crypto-container.ts +64 -0
  71. package/src/lib/guid.ts +1097 -0
  72. package/src/lib/id-providers/custom-provider.ts +109 -0
  73. package/src/lib/id-providers/guidv4-provider.ts +141 -0
  74. package/src/lib/id-providers/{index.d.ts → index.ts} +6 -5
  75. package/src/lib/id-providers/objectid-provider.ts +125 -0
  76. package/src/lib/id-providers/uuid-provider.ts +133 -0
  77. package/src/lib/{index.js → index.ts} +2 -2
  78. package/src/lib/invariant-validator.ts +133 -0
  79. package/src/lib/invariants/encryption-algorithm-consistency.ts +73 -0
  80. package/src/lib/invariants/{index.js → index.ts} +0 -1
  81. package/src/lib/invariants/pbkdf2-profiles-validity.ts +78 -0
  82. package/src/lib/invariants/recipient-id-consistency.ts +46 -0
  83. package/src/lib/multi-recipient-chunk-utils.ts +63 -0
  84. package/src/member.ts +495 -0
  85. package/src/{pbkdf2-profiles.d.ts → pbkdf2-profiles.ts} +2 -2
  86. package/src/phone-number.ts +18 -0
  87. package/src/regexes.ts +10 -0
  88. package/src/secure-buffer.ts +226 -0
  89. package/src/secure-string.ts +244 -0
  90. package/src/services/aes-gcm.ts +220 -0
  91. package/src/services/chunk-processor.ts +188 -0
  92. package/src/services/ecies/README.md +147 -0
  93. package/src/services/ecies/crypto-core.ts +292 -0
  94. package/src/services/ecies/example.ts +185 -0
  95. package/src/services/ecies/file.ts +167 -0
  96. package/src/services/ecies/{index.js → index.ts} +2 -1
  97. package/src/services/ecies/integration.ts +241 -0
  98. package/src/services/ecies/interfaces.ts +62 -0
  99. package/src/services/ecies/manual-test.ts +219 -0
  100. package/src/services/ecies/multi-recipient.ts +545 -0
  101. package/src/services/ecies/service.ts +370 -0
  102. package/src/services/ecies/signature.ts +93 -0
  103. package/src/services/ecies/single-recipient.ts +476 -0
  104. package/src/services/encryption-stream.ts +435 -0
  105. package/src/services/{index.js → index.ts} +0 -1
  106. package/src/services/multi-recipient-processor.ts +377 -0
  107. package/src/services/password-login.ts +226 -0
  108. package/src/services/pbkdf2.ts +169 -0
  109. package/src/services/progress-tracker.ts +128 -0
  110. package/src/services/resumable-encryption.ts +135 -0
  111. package/src/services/xor.ts +65 -0
  112. package/src/test-mocks/index.ts +1 -0
  113. package/src/test-mocks/mock-frontend-member.ts +276 -0
  114. package/src/{testing.js → testing.ts} +0 -1
  115. package/src/translations/{de.js → de.ts} +112 -56
  116. package/src/translations/{en-US.js → en-US.ts} +116 -58
  117. package/src/translations/{es.js → es.ts} +134 -67
  118. package/src/translations/{fr.js → fr.ts} +129 -64
  119. package/src/translations/{ja.js → ja.ts} +111 -55
  120. package/src/translations/{uk.js → uk.ts} +132 -67
  121. package/src/translations/{zh-cn.js → zh-cn.ts} +60 -29
  122. package/src/types/deep-partial.ts +11 -0
  123. package/src/{types.d.ts → types.ts} +15 -7
  124. package/src/utils/encryption-type-utils.ts +76 -0
  125. package/src/utils.ts +329 -0
  126. package/src/builders/ecies-builder.d.ts +0 -18
  127. package/src/builders/ecies-builder.d.ts.map +0 -1
  128. package/src/builders/ecies-builder.js +0 -30
  129. package/src/builders/ecies-builder.js.map +0 -1
  130. package/src/builders/index.d.ts +0 -6
  131. package/src/builders/index.d.ts.map +0 -1
  132. package/src/builders/index.js.map +0 -1
  133. package/src/builders/member-builder.d.ts +0 -51
  134. package/src/builders/member-builder.d.ts.map +0 -1
  135. package/src/builders/member-builder.js +0 -97
  136. package/src/builders/member-builder.js.map +0 -1
  137. package/src/constants.d.ts +0 -60
  138. package/src/constants.d.ts.map +0 -1
  139. package/src/constants.js +0 -446
  140. package/src/constants.js.map +0 -1
  141. package/src/core/errors/crypto-error.d.ts +0 -34
  142. package/src/core/errors/crypto-error.d.ts.map +0 -1
  143. package/src/core/errors/crypto-error.js +0 -56
  144. package/src/core/errors/crypto-error.js.map +0 -1
  145. package/src/core/index.d.ts +0 -6
  146. package/src/core/index.d.ts.map +0 -1
  147. package/src/core/index.js.map +0 -1
  148. package/src/core/types/result.d.ts +0 -16
  149. package/src/core/types/result.d.ts.map +0 -1
  150. package/src/core/types/result.js +0 -12
  151. package/src/core/types/result.js.map +0 -1
  152. package/src/email-string.d.ts +0 -42
  153. package/src/email-string.d.ts.map +0 -1
  154. package/src/email-string.js +0 -67
  155. package/src/email-string.js.map +0 -1
  156. package/src/enumerations/disposed-error-type.d.ts +0 -12
  157. package/src/enumerations/disposed-error-type.d.ts.map +0 -1
  158. package/src/enumerations/disposed-error-type.js +0 -13
  159. package/src/enumerations/disposed-error-type.js.map +0 -1
  160. package/src/enumerations/ecies-cipher-suite.d.ts +0 -4
  161. package/src/enumerations/ecies-cipher-suite.d.ts.map +0 -1
  162. package/src/enumerations/ecies-cipher-suite.js +0 -6
  163. package/src/enumerations/ecies-cipher-suite.js.map +0 -1
  164. package/src/enumerations/ecies-encryption-type.d.ts +0 -11
  165. package/src/enumerations/ecies-encryption-type.d.ts.map +0 -1
  166. package/src/enumerations/ecies-encryption-type.js +0 -27
  167. package/src/enumerations/ecies-encryption-type.js.map +0 -1
  168. package/src/enumerations/ecies-error-type.d.ts +0 -44
  169. package/src/enumerations/ecies-error-type.d.ts.map +0 -1
  170. package/src/enumerations/ecies-error-type.js +0 -45
  171. package/src/enumerations/ecies-error-type.js.map +0 -1
  172. package/src/enumerations/ecies-string-key.d.ts +0 -192
  173. package/src/enumerations/ecies-string-key.d.ts.map +0 -1
  174. package/src/enumerations/ecies-string-key.js +0 -199
  175. package/src/enumerations/ecies-string-key.js.map +0 -1
  176. package/src/enumerations/ecies-version.d.ts +0 -4
  177. package/src/enumerations/ecies-version.d.ts.map +0 -1
  178. package/src/enumerations/ecies-version.js +0 -5
  179. package/src/enumerations/ecies-version.js.map +0 -1
  180. package/src/enumerations/guid-brand-type.d.ts +0 -27
  181. package/src/enumerations/guid-brand-type.d.ts.map +0 -1
  182. package/src/enumerations/guid-brand-type.js +0 -28
  183. package/src/enumerations/guid-brand-type.js.map +0 -1
  184. package/src/enumerations/guid-error-type.d.ts +0 -7
  185. package/src/enumerations/guid-error-type.d.ts.map +0 -1
  186. package/src/enumerations/guid-error-type.js +0 -8
  187. package/src/enumerations/guid-error-type.js.map +0 -1
  188. package/src/enumerations/id-provider-error-type.d.ts +0 -43
  189. package/src/enumerations/id-provider-error-type.d.ts.map +0 -1
  190. package/src/enumerations/id-provider-error-type.js +0 -44
  191. package/src/enumerations/id-provider-error-type.js.map +0 -1
  192. package/src/enumerations/index.d.ts +0 -18
  193. package/src/enumerations/index.d.ts.map +0 -1
  194. package/src/enumerations/index.js.map +0 -1
  195. package/src/enumerations/invalid-email-type.d.ts +0 -6
  196. package/src/enumerations/invalid-email-type.d.ts.map +0 -1
  197. package/src/enumerations/invalid-email-type.js +0 -7
  198. package/src/enumerations/invalid-email-type.js.map +0 -1
  199. package/src/enumerations/length-encoding-type.d.ts +0 -7
  200. package/src/enumerations/length-encoding-type.d.ts.map +0 -1
  201. package/src/enumerations/length-encoding-type.js +0 -8
  202. package/src/enumerations/length-encoding-type.js.map +0 -1
  203. package/src/enumerations/length-error-type.d.ts +0 -6
  204. package/src/enumerations/length-error-type.d.ts.map +0 -1
  205. package/src/enumerations/length-error-type.js +0 -7
  206. package/src/enumerations/length-error-type.js.map +0 -1
  207. package/src/enumerations/member-error-type.d.ts +0 -87
  208. package/src/enumerations/member-error-type.d.ts.map +0 -1
  209. package/src/enumerations/member-error-type.js +0 -88
  210. package/src/enumerations/member-error-type.js.map +0 -1
  211. package/src/enumerations/member-type.d.ts.map +0 -1
  212. package/src/enumerations/member-type.js +0 -16
  213. package/src/enumerations/member-type.js.map +0 -1
  214. package/src/enumerations/password-login-error-type.d.ts +0 -5
  215. package/src/enumerations/password-login-error-type.d.ts.map +0 -1
  216. package/src/enumerations/password-login-error-type.js +0 -6
  217. package/src/enumerations/password-login-error-type.js.map +0 -1
  218. package/src/enumerations/pbkdf2-error-type.d.ts +0 -6
  219. package/src/enumerations/pbkdf2-error-type.d.ts.map +0 -1
  220. package/src/enumerations/pbkdf2-error-type.js +0 -7
  221. package/src/enumerations/pbkdf2-error-type.js.map +0 -1
  222. package/src/enumerations/pbkdf2-profile.d.ts +0 -6
  223. package/src/enumerations/pbkdf2-profile.d.ts.map +0 -1
  224. package/src/enumerations/pbkdf2-profile.js +0 -7
  225. package/src/enumerations/pbkdf2-profile.js.map +0 -1
  226. package/src/enumerations/secure-storage-error-type.d.ts +0 -6
  227. package/src/enumerations/secure-storage-error-type.d.ts.map +0 -1
  228. package/src/enumerations/secure-storage-error-type.js +0 -7
  229. package/src/enumerations/secure-storage-error-type.js.map +0 -1
  230. package/src/errors/disposed.d.ts +0 -22
  231. package/src/errors/disposed.d.ts.map +0 -1
  232. package/src/errors/disposed.js +0 -28
  233. package/src/errors/disposed.js.map +0 -1
  234. package/src/errors/ecies.d.ts +0 -52
  235. package/src/errors/ecies.d.ts.map +0 -1
  236. package/src/errors/ecies.js +0 -78
  237. package/src/errors/ecies.js.map +0 -1
  238. package/src/errors/guid.d.ts +0 -49
  239. package/src/errors/guid.d.ts.map +0 -1
  240. package/src/errors/guid.js +0 -96
  241. package/src/errors/guid.js.map +0 -1
  242. package/src/errors/id-provider.d.ts +0 -23
  243. package/src/errors/id-provider.d.ts.map +0 -1
  244. package/src/errors/id-provider.js +0 -29
  245. package/src/errors/id-provider.js.map +0 -1
  246. package/src/errors/index.d.ts.map +0 -1
  247. package/src/errors/index.js +0 -10
  248. package/src/errors/index.js.map +0 -1
  249. package/src/errors/invalid-email.d.ts +0 -8
  250. package/src/errors/invalid-email.d.ts.map +0 -1
  251. package/src/errors/invalid-email.js +0 -15
  252. package/src/errors/invalid-email.js.map +0 -1
  253. package/src/errors/length.d.ts +0 -7
  254. package/src/errors/length.d.ts.map +0 -1
  255. package/src/errors/length.js +0 -11
  256. package/src/errors/length.js.map +0 -1
  257. package/src/errors/member.d.ts +0 -7
  258. package/src/errors/member.d.ts.map +0 -1
  259. package/src/errors/member.js +0 -11
  260. package/src/errors/member.js.map +0 -1
  261. package/src/errors/pbkdf2.d.ts +0 -7
  262. package/src/errors/pbkdf2.d.ts.map +0 -1
  263. package/src/errors/pbkdf2.js +0 -11
  264. package/src/errors/pbkdf2.js.map +0 -1
  265. package/src/errors/secure-storage.d.ts +0 -7
  266. package/src/errors/secure-storage.d.ts.map +0 -1
  267. package/src/errors/secure-storage.js +0 -12
  268. package/src/errors/secure-storage.js.map +0 -1
  269. package/src/errors/simple-ecies.d.ts +0 -6
  270. package/src/errors/simple-ecies.d.ts.map +0 -1
  271. package/src/errors/simple-ecies.js +0 -12
  272. package/src/errors/simple-ecies.js.map +0 -1
  273. package/src/errors/simple-test-error.d.ts +0 -4
  274. package/src/errors/simple-test-error.d.ts.map +0 -1
  275. package/src/errors/simple-test-error.js +0 -7
  276. package/src/errors/simple-test-error.js.map +0 -1
  277. package/src/i18n-setup.d.ts +0 -32
  278. package/src/i18n-setup.d.ts.map +0 -1
  279. package/src/i18n-setup.js +0 -101
  280. package/src/i18n-setup.js.map +0 -1
  281. package/src/index.d.ts +0 -80
  282. package/src/index.d.ts.map +0 -1
  283. package/src/index.js.map +0 -1
  284. package/src/interfaces/checksum-config.d.ts +0 -5
  285. package/src/interfaces/checksum-config.d.ts.map +0 -1
  286. package/src/interfaces/checksum-config.js +0 -2
  287. package/src/interfaces/checksum-config.js.map +0 -1
  288. package/src/interfaces/checksum-consts.d.ts +0 -11
  289. package/src/interfaces/checksum-consts.d.ts.map +0 -1
  290. package/src/interfaces/checksum-consts.js +0 -2
  291. package/src/interfaces/checksum-consts.js.map +0 -1
  292. package/src/interfaces/configuration-provenance.d.ts +0 -43
  293. package/src/interfaces/configuration-provenance.d.ts.map +0 -1
  294. package/src/interfaces/configuration-provenance.js +0 -3
  295. package/src/interfaces/configuration-provenance.js.map +0 -1
  296. package/src/interfaces/constants.d.ts +0 -70
  297. package/src/interfaces/constants.d.ts.map +0 -1
  298. package/src/interfaces/constants.js +0 -2
  299. package/src/interfaces/constants.js.map +0 -1
  300. package/src/interfaces/ecies-config.d.ts +0 -9
  301. package/src/interfaces/ecies-config.d.ts.map +0 -1
  302. package/src/interfaces/ecies-config.js +0 -2
  303. package/src/interfaces/ecies-config.js.map +0 -1
  304. package/src/interfaces/ecies-consts.d.ts +0 -61
  305. package/src/interfaces/ecies-consts.d.ts.map +0 -1
  306. package/src/interfaces/ecies-consts.js +0 -2
  307. package/src/interfaces/ecies-consts.js.map +0 -1
  308. package/src/interfaces/ecies-file-service.d.ts +0 -7
  309. package/src/interfaces/ecies-file-service.d.ts.map +0 -1
  310. package/src/interfaces/ecies-file-service.js +0 -2
  311. package/src/interfaces/ecies-file-service.js.map +0 -1
  312. package/src/interfaces/encrypted-chunk.d.ts +0 -55
  313. package/src/interfaces/encrypted-chunk.d.ts.map +0 -1
  314. package/src/interfaces/encrypted-chunk.js +0 -12
  315. package/src/interfaces/encrypted-chunk.js.map +0 -1
  316. package/src/interfaces/encryption-state.d.ts +0 -18
  317. package/src/interfaces/encryption-state.d.ts.map +0 -1
  318. package/src/interfaces/encryption-state.js +0 -2
  319. package/src/interfaces/encryption-state.js.map +0 -1
  320. package/src/interfaces/frontend-member-operational.d.ts +0 -51
  321. package/src/interfaces/frontend-member-operational.d.ts.map +0 -1
  322. package/src/interfaces/frontend-member-operational.js +0 -2
  323. package/src/interfaces/frontend-member-operational.js.map +0 -1
  324. package/src/interfaces/guid.d.ts +0 -78
  325. package/src/interfaces/guid.d.ts.map +0 -1
  326. package/src/interfaces/guid.js +0 -2
  327. package/src/interfaces/guid.js.map +0 -1
  328. package/src/interfaces/id-provider.d.ts +0 -107
  329. package/src/interfaces/id-provider.d.ts.map +0 -1
  330. package/src/interfaces/id-provider.js +0 -52
  331. package/src/interfaces/id-provider.js.map +0 -1
  332. package/src/interfaces/index.d.ts.map +0 -1
  333. package/src/interfaces/index.js +0 -13
  334. package/src/interfaces/index.js.map +0 -1
  335. package/src/interfaces/invariant.d.ts +0 -46
  336. package/src/interfaces/invariant.d.ts.map +0 -1
  337. package/src/interfaces/invariant.js +0 -18
  338. package/src/interfaces/invariant.js.map +0 -1
  339. package/src/interfaces/library-error.d.ts +0 -23
  340. package/src/interfaces/library-error.d.ts.map +0 -1
  341. package/src/interfaces/library-error.js +0 -2
  342. package/src/interfaces/library-error.js.map +0 -1
  343. package/src/interfaces/member-storage.d.ts.map +0 -1
  344. package/src/interfaces/member-storage.js +0 -2
  345. package/src/interfaces/member-storage.js.map +0 -1
  346. package/src/interfaces/member-with-mnemonic.d.ts.map +0 -1
  347. package/src/interfaces/member-with-mnemonic.js +0 -2
  348. package/src/interfaces/member-with-mnemonic.js.map +0 -1
  349. package/src/interfaces/member.d.ts +0 -55
  350. package/src/interfaces/member.d.ts.map +0 -1
  351. package/src/interfaces/member.js +0 -2
  352. package/src/interfaces/member.js.map +0 -1
  353. package/src/interfaces/multi-recipient-chunk.d.ts +0 -54
  354. package/src/interfaces/multi-recipient-chunk.d.ts.map +0 -1
  355. package/src/interfaces/multi-recipient-chunk.js +0 -11
  356. package/src/interfaces/multi-recipient-chunk.js.map +0 -1
  357. package/src/interfaces/pbkdf2-config.d.ts +0 -7
  358. package/src/interfaces/pbkdf2-config.d.ts.map +0 -1
  359. package/src/interfaces/pbkdf2-config.js +0 -2
  360. package/src/interfaces/pbkdf2-config.js.map +0 -1
  361. package/src/interfaces/pbkdf2-consts.d.ts +0 -9
  362. package/src/interfaces/pbkdf2-consts.d.ts.map +0 -1
  363. package/src/interfaces/pbkdf2-consts.js +0 -2
  364. package/src/interfaces/pbkdf2-consts.js.map +0 -1
  365. package/src/interfaces/pbkdf2-result.d.ts +0 -6
  366. package/src/interfaces/pbkdf2-result.d.ts.map +0 -1
  367. package/src/interfaces/pbkdf2-result.js +0 -2
  368. package/src/interfaces/pbkdf2-result.js.map +0 -1
  369. package/src/interfaces/stream-config.d.ts +0 -14
  370. package/src/interfaces/stream-config.d.ts.map +0 -1
  371. package/src/interfaces/stream-config.js +0 -8
  372. package/src/interfaces/stream-config.js.map +0 -1
  373. package/src/interfaces/stream-header.d.ts +0 -29
  374. package/src/interfaces/stream-header.d.ts.map +0 -1
  375. package/src/interfaces/stream-header.js +0 -9
  376. package/src/interfaces/stream-header.js.map +0 -1
  377. package/src/interfaces/stream-progress.d.ts +0 -33
  378. package/src/interfaces/stream-progress.d.ts.map +0 -1
  379. package/src/interfaces/stream-progress.js +0 -2
  380. package/src/interfaces/stream-progress.js.map +0 -1
  381. package/src/lib/configuration-provenance-utils.d.ts +0 -11
  382. package/src/lib/configuration-provenance-utils.d.ts.map +0 -1
  383. package/src/lib/configuration-provenance-utils.js +0 -23
  384. package/src/lib/configuration-provenance-utils.js.map +0 -1
  385. package/src/lib/crypto-container.d.ts +0 -25
  386. package/src/lib/crypto-container.d.ts.map +0 -1
  387. package/src/lib/crypto-container.js +0 -46
  388. package/src/lib/crypto-container.js.map +0 -1
  389. package/src/lib/guid.d.ts +0 -344
  390. package/src/lib/guid.d.ts.map +0 -1
  391. package/src/lib/guid.js +0 -914
  392. package/src/lib/guid.js.map +0 -1
  393. package/src/lib/id-providers/custom-provider.d.ts +0 -46
  394. package/src/lib/id-providers/custom-provider.d.ts.map +0 -1
  395. package/src/lib/id-providers/custom-provider.js +0 -85
  396. package/src/lib/id-providers/custom-provider.js.map +0 -1
  397. package/src/lib/id-providers/guidv4-provider.d.ts +0 -56
  398. package/src/lib/id-providers/guidv4-provider.d.ts.map +0 -1
  399. package/src/lib/id-providers/guidv4-provider.js +0 -122
  400. package/src/lib/id-providers/guidv4-provider.js.map +0 -1
  401. package/src/lib/id-providers/index.d.ts.map +0 -1
  402. package/src/lib/id-providers/index.js +0 -29
  403. package/src/lib/id-providers/index.js.map +0 -1
  404. package/src/lib/id-providers/objectid-provider.d.ts +0 -43
  405. package/src/lib/id-providers/objectid-provider.d.ts.map +0 -1
  406. package/src/lib/id-providers/objectid-provider.js +0 -104
  407. package/src/lib/id-providers/objectid-provider.js.map +0 -1
  408. package/src/lib/id-providers/uuid-provider.d.ts +0 -52
  409. package/src/lib/id-providers/uuid-provider.d.ts.map +0 -1
  410. package/src/lib/id-providers/uuid-provider.js +0 -110
  411. package/src/lib/id-providers/uuid-provider.js.map +0 -1
  412. package/src/lib/index.d.ts +0 -6
  413. package/src/lib/index.d.ts.map +0 -1
  414. package/src/lib/index.js.map +0 -1
  415. package/src/lib/invariant-validator.d.ts +0 -59
  416. package/src/lib/invariant-validator.d.ts.map +0 -1
  417. package/src/lib/invariant-validator.js +0 -97
  418. package/src/lib/invariant-validator.js.map +0 -1
  419. package/src/lib/invariants/encryption-algorithm-consistency.d.ts +0 -17
  420. package/src/lib/invariants/encryption-algorithm-consistency.d.ts.map +0 -1
  421. package/src/lib/invariants/encryption-algorithm-consistency.js +0 -49
  422. package/src/lib/invariants/encryption-algorithm-consistency.js.map +0 -1
  423. package/src/lib/invariants/index.d.ts +0 -4
  424. package/src/lib/invariants/index.d.ts.map +0 -1
  425. package/src/lib/invariants/index.js.map +0 -1
  426. package/src/lib/invariants/pbkdf2-profiles-validity.d.ts +0 -16
  427. package/src/lib/invariants/pbkdf2-profiles-validity.d.ts.map +0 -1
  428. package/src/lib/invariants/pbkdf2-profiles-validity.js +0 -58
  429. package/src/lib/invariants/pbkdf2-profiles-validity.js.map +0 -1
  430. package/src/lib/invariants/recipient-id-consistency.d.ts +0 -18
  431. package/src/lib/invariants/recipient-id-consistency.d.ts.map +0 -1
  432. package/src/lib/invariants/recipient-id-consistency.js +0 -31
  433. package/src/lib/invariants/recipient-id-consistency.js.map +0 -1
  434. package/src/lib/multi-recipient-chunk-utils.d.ts +0 -38
  435. package/src/lib/multi-recipient-chunk-utils.d.ts.map +0 -1
  436. package/src/lib/multi-recipient-chunk-utils.js +0 -41
  437. package/src/lib/multi-recipient-chunk-utils.js.map +0 -1
  438. package/src/member.d.ts +0 -92
  439. package/src/member.d.ts.map +0 -1
  440. package/src/member.js +0 -322
  441. package/src/member.js.map +0 -1
  442. package/src/pbkdf2-profiles.d.ts.map +0 -1
  443. package/src/pbkdf2-profiles.js +0 -2
  444. package/src/pbkdf2-profiles.js.map +0 -1
  445. package/src/phone-number.d.ts +0 -6
  446. package/src/phone-number.d.ts.map +0 -1
  447. package/src/phone-number.js +0 -18
  448. package/src/phone-number.js.map +0 -1
  449. package/src/regexes.d.ts +0 -7
  450. package/src/regexes.d.ts.map +0 -1
  451. package/src/regexes.js +0 -7
  452. package/src/regexes.js.map +0 -1
  453. package/src/secure-buffer.d.ts +0 -61
  454. package/src/secure-buffer.d.ts.map +0 -1
  455. package/src/secure-buffer.js +0 -201
  456. package/src/secure-buffer.js.map +0 -1
  457. package/src/secure-string.d.ts +0 -46
  458. package/src/secure-string.d.ts.map +0 -1
  459. package/src/secure-string.js +0 -206
  460. package/src/secure-string.js.map +0 -1
  461. package/src/services/aes-gcm.d.ts +0 -57
  462. package/src/services/aes-gcm.d.ts.map +0 -1
  463. package/src/services/aes-gcm.js +0 -142
  464. package/src/services/aes-gcm.js.map +0 -1
  465. package/src/services/chunk-processor.d.ts +0 -31
  466. package/src/services/chunk-processor.d.ts.map +0 -1
  467. package/src/services/chunk-processor.js +0 -145
  468. package/src/services/chunk-processor.js.map +0 -1
  469. package/src/services/ecies/crypto-core.d.ts +0 -72
  470. package/src/services/ecies/crypto-core.d.ts.map +0 -1
  471. package/src/services/ecies/crypto-core.js +0 -205
  472. package/src/services/ecies/crypto-core.js.map +0 -1
  473. package/src/services/ecies/example.d.ts +0 -25
  474. package/src/services/ecies/example.d.ts.map +0 -1
  475. package/src/services/ecies/example.js +0 -121
  476. package/src/services/ecies/example.js.map +0 -1
  477. package/src/services/ecies/file.d.ts +0 -18
  478. package/src/services/ecies/file.d.ts.map +0 -1
  479. package/src/services/ecies/file.js +0 -106
  480. package/src/services/ecies/file.js.map +0 -1
  481. package/src/services/ecies/index.d.ts +0 -38
  482. package/src/services/ecies/index.d.ts.map +0 -1
  483. package/src/services/ecies/index.js.map +0 -1
  484. package/src/services/ecies/integration.d.ts +0 -59
  485. package/src/services/ecies/integration.d.ts.map +0 -1
  486. package/src/services/ecies/integration.js +0 -167
  487. package/src/services/ecies/integration.js.map +0 -1
  488. package/src/services/ecies/interfaces.d.ts +0 -54
  489. package/src/services/ecies/interfaces.d.ts.map +0 -1
  490. package/src/services/ecies/interfaces.js +0 -5
  491. package/src/services/ecies/interfaces.js.map +0 -1
  492. package/src/services/ecies/manual-test.d.ts +0 -29
  493. package/src/services/ecies/manual-test.d.ts.map +0 -1
  494. package/src/services/ecies/manual-test.js +0 -163
  495. package/src/services/ecies/manual-test.js.map +0 -1
  496. package/src/services/ecies/multi-recipient.d.ts +0 -56
  497. package/src/services/ecies/multi-recipient.d.ts.map +0 -1
  498. package/src/services/ecies/multi-recipient.js +0 -344
  499. package/src/services/ecies/multi-recipient.js.map +0 -1
  500. package/src/services/ecies/service.d.ts +0 -120
  501. package/src/services/ecies/service.d.ts.map +0 -1
  502. package/src/services/ecies/service.js +0 -210
  503. package/src/services/ecies/service.js.map +0 -1
  504. package/src/services/ecies/signature.d.ts +0 -27
  505. package/src/services/ecies/signature.d.ts.map +0 -1
  506. package/src/services/ecies/signature.js +0 -72
  507. package/src/services/ecies/signature.js.map +0 -1
  508. package/src/services/ecies/single-recipient.d.ts +0 -46
  509. package/src/services/ecies/single-recipient.d.ts.map +0 -1
  510. package/src/services/ecies/single-recipient.js +0 -322
  511. package/src/services/ecies/single-recipient.js.map +0 -1
  512. package/src/services/encryption-stream.d.ts +0 -71
  513. package/src/services/encryption-stream.d.ts.map +0 -1
  514. package/src/services/encryption-stream.js +0 -295
  515. package/src/services/encryption-stream.js.map +0 -1
  516. package/src/services/index.d.ts +0 -11
  517. package/src/services/index.d.ts.map +0 -1
  518. package/src/services/index.js.map +0 -1
  519. package/src/services/multi-recipient-processor.d.ts +0 -35
  520. package/src/services/multi-recipient-processor.d.ts.map +0 -1
  521. package/src/services/multi-recipient-processor.js +0 -289
  522. package/src/services/multi-recipient-processor.js.map +0 -1
  523. package/src/services/password-login.d.ts +0 -47
  524. package/src/services/password-login.d.ts.map +0 -1
  525. package/src/services/password-login.js +0 -115
  526. package/src/services/password-login.js.map +0 -1
  527. package/src/services/pbkdf2.d.ts +0 -54
  528. package/src/services/pbkdf2.d.ts.map +0 -1
  529. package/src/services/pbkdf2.js +0 -108
  530. package/src/services/pbkdf2.js.map +0 -1
  531. package/src/services/progress-tracker.d.ts +0 -23
  532. package/src/services/progress-tracker.d.ts.map +0 -1
  533. package/src/services/progress-tracker.js +0 -103
  534. package/src/services/progress-tracker.js.map +0 -1
  535. package/src/services/resumable-encryption.d.ts +0 -19
  536. package/src/services/resumable-encryption.d.ts.map +0 -1
  537. package/src/services/resumable-encryption.js +0 -105
  538. package/src/services/resumable-encryption.js.map +0 -1
  539. package/src/services/xor.d.ts +0 -37
  540. package/src/services/xor.d.ts.map +0 -1
  541. package/src/services/xor.js +0 -63
  542. package/src/services/xor.js.map +0 -1
  543. package/src/test-mocks/index.d.ts +0 -2
  544. package/src/test-mocks/index.d.ts.map +0 -1
  545. package/src/test-mocks/index.js +0 -2
  546. package/src/test-mocks/index.js.map +0 -1
  547. package/src/test-mocks/mock-frontend-member.d.ts +0 -85
  548. package/src/test-mocks/mock-frontend-member.d.ts.map +0 -1
  549. package/src/test-mocks/mock-frontend-member.js +0 -190
  550. package/src/test-mocks/mock-frontend-member.js.map +0 -1
  551. package/src/testing.d.ts +0 -2
  552. package/src/testing.d.ts.map +0 -1
  553. package/src/testing.js.map +0 -1
  554. package/src/translations/de.d.ts +0 -4
  555. package/src/translations/de.d.ts.map +0 -1
  556. package/src/translations/de.js.map +0 -1
  557. package/src/translations/en-US.d.ts +0 -4
  558. package/src/translations/en-US.d.ts.map +0 -1
  559. package/src/translations/en-US.js.map +0 -1
  560. package/src/translations/es.d.ts +0 -4
  561. package/src/translations/es.d.ts.map +0 -1
  562. package/src/translations/es.js.map +0 -1
  563. package/src/translations/fr.d.ts +0 -4
  564. package/src/translations/fr.d.ts.map +0 -1
  565. package/src/translations/fr.js.map +0 -1
  566. package/src/translations/ja.d.ts +0 -4
  567. package/src/translations/ja.d.ts.map +0 -1
  568. package/src/translations/ja.js.map +0 -1
  569. package/src/translations/uk.d.ts +0 -4
  570. package/src/translations/uk.d.ts.map +0 -1
  571. package/src/translations/uk.js.map +0 -1
  572. package/src/translations/zh-cn.d.ts +0 -4
  573. package/src/translations/zh-cn.d.ts.map +0 -1
  574. package/src/translations/zh-cn.js.map +0 -1
  575. package/src/types/deep-partial.d.ts +0 -4
  576. package/src/types/deep-partial.d.ts.map +0 -1
  577. package/src/types/deep-partial.js +0 -2
  578. package/src/types/deep-partial.js.map +0 -1
  579. package/src/types.d.ts.map +0 -1
  580. package/src/types.js +0 -2
  581. package/src/types.js.map +0 -1
  582. package/src/utils/encryption-type-utils.d.ts +0 -29
  583. package/src/utils/encryption-type-utils.d.ts.map +0 -1
  584. package/src/utils/encryption-type-utils.js +0 -61
  585. package/src/utils/encryption-type-utils.js.map +0 -1
  586. package/src/utils.d.ts +0 -68
  587. package/src/utils.d.ts.map +0 -1
  588. package/src/utils.js +0 -273
  589. package/src/utils.js.map +0 -1
@@ -0,0 +1,609 @@
1
+ import { ECIESErrorTypeEnum, EciesStringKey } from './enumerations';
2
+ import { Pbkdf2ProfileEnum } from './enumerations/pbkdf2-profile';
3
+ import { ECIESError } from './errors/ecies';
4
+ import { EciesComponentId, getEciesI18nEngine } from './i18n-setup';
5
+ import type { IChecksumConsts } from './interfaces/checksum-consts';
6
+ import type { IConfigurationProvenance } from './interfaces/configuration-provenance';
7
+ import {
8
+ calculateConfigChecksum,
9
+ captureCreationStack,
10
+ } from './interfaces/configuration-provenance';
11
+ import type { IConstants } from './interfaces/constants';
12
+ import type { IECIESConstants } from './interfaces/ecies-consts';
13
+ import type { IPBkdf2Consts } from './interfaces/pbkdf2-consts';
14
+ import { ObjectIdProvider } from './lib/id-providers/objectid-provider';
15
+ import { InvariantValidator } from './lib/invariant-validator';
16
+ import type { Pbkdf2Profiles } from './pbkdf2-profiles';
17
+ import { MNEMONIC_REGEX, PASSWORD_REGEX } from './regexes';
18
+ import type { DeepPartial } from './types/deep-partial';
19
+
20
+ export const UINT8_SIZE: number = 1 as const;
21
+ export const UINT16_SIZE: number = 2 as const;
22
+ export const UINT16_MAX: number = 65535 as const;
23
+ export const UINT32_SIZE: number = 4 as const;
24
+ export const UINT32_MAX: number = 4294967295 as const;
25
+ export const UINT64_SIZE: number = 8 as const;
26
+ export const UINT64_MAX: bigint = 18446744073709551615n as const;
27
+ export const OBJECT_ID_LENGTH: number = 12 as const;
28
+
29
+ if (OBJECT_ID_LENGTH !== 12) {
30
+ console.warn(
31
+ 'ObjectID length may have changed, breaking encryption',
32
+ OBJECT_ID_LENGTH,
33
+ );
34
+ }
35
+
36
+ /**
37
+ * Constants for checksum operations
38
+ * These values are critical for data integrity and MUST NOT be changed
39
+ * in an already established system as it will break all existing checksums.
40
+ */
41
+ export const CHECKSUM: IChecksumConsts = Object.freeze({
42
+ /** Default hash bits for SHA3 */
43
+ SHA3_DEFAULT_HASH_BITS: 512 as const,
44
+
45
+ /** Length of a SHA3 checksum buffer in bytes */
46
+ SHA3_BUFFER_LENGTH: 64 as const,
47
+
48
+ /** algorithm to use for checksum */
49
+ ALGORITHM: 'sha3-512' as const,
50
+
51
+ /** encoding to use for checksum */
52
+ ENCODING: 'hex' as const,
53
+ } as const);
54
+
55
+ export const PBKDF2: IPBkdf2Consts = Object.freeze({
56
+ ALGORITHM: 'SHA-256' as const,
57
+ SALT_BYTES: 32 as const,
58
+ /**
59
+ * Number of pbkdf2 iterations per second when hashing a password.
60
+ * This is the high-security default for user login operations.
61
+ */
62
+ ITERATIONS_PER_SECOND: 1304000 as const,
63
+ } as const);
64
+
65
+ export const PBKDF2_PROFILES: Pbkdf2Profiles = Object.freeze({
66
+ [Pbkdf2ProfileEnum.BROWSER_PASSWORD]: Object.freeze({
67
+ hashBytes: 32 as const,
68
+ saltBytes: 64 as const,
69
+ iterations: 2000000 as const,
70
+ algorithm: 'SHA-512' as const,
71
+ } as const),
72
+ [Pbkdf2ProfileEnum.HIGH_SECURITY]: Object.freeze({
73
+ hashBytes: 64 as const,
74
+ saltBytes: 32 as const,
75
+ iterations: 5000000 as const,
76
+ algorithm: 'SHA-256' as const,
77
+ } as const),
78
+ [Pbkdf2ProfileEnum.TEST_FAST]: Object.freeze({
79
+ hashBytes: 32 as const,
80
+ saltBytes: 64 as const,
81
+ iterations: 1000 as const,
82
+ algorithm: 'SHA-512' as const,
83
+ } as const),
84
+ } as const);
85
+
86
+ const ECIES_SYMMETRIC_KEY_SIZE = 32 as const;
87
+ const ECIES_PUBLIC_KEY_LENGTH = 33 as const;
88
+ const ECIES_RAW_PUBLIC_KEY_LENGTH = 32 as const;
89
+ const ECIES_IV_SIZE = 12 as const;
90
+ const ECIES_AUTH_TAG_SIZE = 16 as const;
91
+ const ECIES_MULTIPLE_RECIPIENT_ID_SIZE = 12 as const;
92
+ const ECIES_VERSION_SIZE = 1 as const;
93
+ const ECIES_CIPHER_SUITE_SIZE = 1 as const;
94
+
95
+ // Define the expected value for SIMPLE.FIXED_OVERHEAD_SIZE
96
+ const expectedSimpleOverhead =
97
+ ECIES_VERSION_SIZE +
98
+ ECIES_CIPHER_SUITE_SIZE +
99
+ UINT8_SIZE +
100
+ ECIES_PUBLIC_KEY_LENGTH +
101
+ ECIES_IV_SIZE +
102
+ ECIES_AUTH_TAG_SIZE;
103
+
104
+ // Define the expected value for MULTIPLE.FIXED_OVERHEAD_SIZE
105
+ // Includes: version (1) + cipher suite (1) + type (1) + public key (33) + IV (16) + auth tag (16) = 68 (no CRC, AES-GCM provides authentication)
106
+ const expectedMultipleOverhead =
107
+ ECIES_VERSION_SIZE +
108
+ ECIES_CIPHER_SUITE_SIZE +
109
+ UINT8_SIZE +
110
+ ECIES_PUBLIC_KEY_LENGTH +
111
+ ECIES_IV_SIZE +
112
+ ECIES_AUTH_TAG_SIZE;
113
+
114
+ // Update ENCRYPTED_KEY_SIZE to match Simple encryption (no CRC)
115
+ // Now only contains IV + Tag + EncryptedSymKey (Public Key is moved to global header)
116
+ const expectedMultipleEncryptedKeySize =
117
+ ECIES_IV_SIZE + ECIES_AUTH_TAG_SIZE + ECIES_SYMMETRIC_KEY_SIZE;
118
+
119
+ export const ECIES: IECIESConstants = Object.freeze({
120
+ /** The elliptic curve to use for all ECDSA operations */
121
+ CURVE_NAME: 'secp256k1' as const,
122
+
123
+ /** The primary key derivation path for HD wallets */
124
+ PRIMARY_KEY_DERIVATION_PATH: "m/44'/60'/0'/0/0" as const,
125
+
126
+ SYMMETRIC_ALGORITHM_CONFIGURATION: 'aes-256-gcm' as const,
127
+
128
+ /** Length of ECDSA signatures in bytes */
129
+ SIGNATURE_SIZE: 64 as const,
130
+
131
+ /** Length of raw public keys in bytes (without 0x04 prefix) */
132
+ RAW_PUBLIC_KEY_LENGTH: ECIES_RAW_PUBLIC_KEY_LENGTH,
133
+
134
+ /** Length of public keys in bytes (with 0x02/0x03 prefix) */
135
+ PUBLIC_KEY_LENGTH: ECIES_PUBLIC_KEY_LENGTH,
136
+
137
+ PUBLIC_KEY_MAGIC: 0x02 as const, // Compressed keys start with 0x02 or 0x03
138
+
139
+ /** Mnemonic strength in bits. This will produce a 32-bit key for ECDSA */
140
+ MNEMONIC_STRENGTH: 256 as const,
141
+
142
+ /** Symmetric encryption algorithm configuration */
143
+ SYMMETRIC: Object.freeze({
144
+ ALGORITHM: 'aes' as const,
145
+ MODE: 'gcm' as const,
146
+ KEY_BITS: 256 as const,
147
+ KEY_SIZE: ECIES_SYMMETRIC_KEY_SIZE, // KEY_BITS / 8
148
+ } as const),
149
+
150
+ IV_SIZE: ECIES_IV_SIZE,
151
+ AUTH_TAG_SIZE: ECIES_AUTH_TAG_SIZE,
152
+ MAX_RAW_DATA_SIZE: 9007199254740991 as const, // 2^53 - 1 (max safe integer for JS)
153
+
154
+ VERSION_SIZE: ECIES_VERSION_SIZE,
155
+ CIPHER_SUITE_SIZE: ECIES_CIPHER_SUITE_SIZE,
156
+ ENCRYPTION_TYPE_SIZE: 1 as const,
157
+
158
+ /**
159
+ * Message encrypts without data length or crc
160
+ */
161
+ SIMPLE: Object.freeze({
162
+ FIXED_OVERHEAD_SIZE: expectedSimpleOverhead, // version (1) + cipher suite (1) + type (1) + public key (33) + IV (16) + auth tag (16)
163
+ DATA_LENGTH_SIZE: 0 as const,
164
+ } as const),
165
+
166
+ /**
167
+ * Message encrypts with data length but no CRC (AES-GCM provides authentication)
168
+ */
169
+ SINGLE: Object.freeze({
170
+ FIXED_OVERHEAD_SIZE: expectedSimpleOverhead + 8, // version (1) + cipher suite (1) + type (1) + public key (33) + IV (16) + auth tag (16) + data length (8)
171
+ DATA_LENGTH_SIZE: 8,
172
+ } as const),
173
+
174
+ /**
175
+ * Message encrypts for multiple recipients
176
+ */
177
+ MULTIPLE: Object.freeze({
178
+ FIXED_OVERHEAD_SIZE: expectedMultipleOverhead, // version (1) + cipher suite (1) + type (1) + public key (33) + IV (16) + auth tag (16)
179
+ ENCRYPTED_KEY_SIZE: expectedMultipleEncryptedKeySize, // 64
180
+ MAX_RECIPIENTS: 65535,
181
+ RECIPIENT_ID_SIZE: ECIES_MULTIPLE_RECIPIENT_ID_SIZE,
182
+ RECIPIENT_COUNT_SIZE: 2,
183
+ DATA_LENGTH_SIZE: 8,
184
+ } as const),
185
+
186
+ ENCRYPTION_TYPE: Object.freeze({
187
+ SIMPLE: 33 as const,
188
+ SINGLE: 66 as const,
189
+ MULTIPLE: 99 as const,
190
+ } as const),
191
+ });
192
+
193
+ /**
194
+ * Default ID provider instance (singleton).
195
+ * Uses MongoDB ObjectID format (12 bytes).
196
+ */
197
+ const DEFAULT_ID_PROVIDER = new ObjectIdProvider();
198
+
199
+ export const Constants: IConstants = Object.freeze({
200
+ UINT8_SIZE: UINT8_SIZE,
201
+ UINT16_SIZE: UINT16_SIZE,
202
+ UINT16_MAX: UINT16_MAX,
203
+ UINT32_SIZE: UINT32_SIZE,
204
+ UINT32_MAX: UINT32_MAX,
205
+ UINT64_SIZE: UINT64_SIZE,
206
+ UINT64_MAX: UINT64_MAX,
207
+ HEX_RADIX: 16 as const,
208
+ MEMBER_ID_LENGTH: DEFAULT_ID_PROVIDER.byteLength,
209
+ OBJECT_ID_LENGTH: OBJECT_ID_LENGTH,
210
+ idProvider: DEFAULT_ID_PROVIDER,
211
+ CHECKSUM: CHECKSUM,
212
+ ECIES: ECIES,
213
+ PBKDF2: PBKDF2,
214
+ PBKDF2_PROFILES: PBKDF2_PROFILES,
215
+ /**
216
+ * Number of rounds for bcrypt hashing. Higher values increase security but also consume more CPU resources.
217
+ */
218
+ BcryptRounds: 10 as const,
219
+ /**
220
+ * Minimum password length
221
+ */
222
+ PasswordMinLength: 8 as const,
223
+ /**
224
+ * The regular expression for valid passwords.
225
+ */
226
+ PasswordRegex: PASSWORD_REGEX,
227
+ /**
228
+ * The regular expression for valid mnemonic phrases.
229
+ * BIP39 - supports 12, 15, 18, 21, or 24 word mnemonics
230
+ */
231
+ MnemonicRegex: MNEMONIC_REGEX,
232
+ /**
233
+ * Matches a 64-character hexadecimal string (SHA-256).
234
+ */
235
+ MnemonicHmacRegex: /^[a-f0-9]{64}$/,
236
+ } as const);
237
+
238
+ export type ConfigurationKey = string | symbol;
239
+
240
+ const DEFAULT_CONFIGURATION_KEY: ConfigurationKey = Symbol.for(
241
+ 'digitaldefiance.ecies.constants.default',
242
+ );
243
+
244
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
245
+ if (value === null) {
246
+ return false;
247
+ }
248
+ if (typeof value !== 'object') {
249
+ return false;
250
+ }
251
+ if (Array.isArray(value)) {
252
+ return false;
253
+ }
254
+ if (value instanceof RegExp || value instanceof Date) {
255
+ return false;
256
+ }
257
+ return Object.getPrototypeOf(value) === Object.prototype;
258
+ }
259
+
260
+ function deepClone<T>(input: T): T {
261
+ if (input === null || input === undefined) {
262
+ return input;
263
+ }
264
+
265
+ if (typeof input !== 'object') {
266
+ return input;
267
+ }
268
+
269
+ if (Array.isArray(input)) {
270
+ return input.map((item) => deepClone(item)) as T;
271
+ }
272
+
273
+ if (input instanceof RegExp) {
274
+ return new RegExp(input.source, input.flags) as T;
275
+ }
276
+
277
+ if (input instanceof Date) {
278
+ return new Date(input.getTime()) as T;
279
+ }
280
+
281
+ if (isPlainObject(input)) {
282
+ const result: Record<string, unknown> = {};
283
+ for (const [key, value] of Object.entries(input)) {
284
+ result[key] = deepClone(value);
285
+ }
286
+ return result as T;
287
+ }
288
+
289
+ return input;
290
+ }
291
+
292
+ function applyOverrides<T>(target: T, overrides?: DeepPartial<T>): T {
293
+ if (!overrides) {
294
+ return target;
295
+ }
296
+
297
+ for (const [key, overrideValue] of Object.entries(overrides)) {
298
+ const typedKey = key as keyof T;
299
+ if (overrideValue === undefined) {
300
+ continue;
301
+ }
302
+
303
+ const currentValue = target[typedKey];
304
+
305
+ if (isPlainObject(currentValue) && isPlainObject(overrideValue)) {
306
+ (target as Record<string, unknown>)[typedKey as string] = applyOverrides(
307
+ currentValue,
308
+ overrideValue as DeepPartial<typeof currentValue>,
309
+ );
310
+ } else {
311
+ (target as Record<string, unknown>)[typedKey as string] =
312
+ deepClone(overrideValue);
313
+ }
314
+ }
315
+
316
+ return target;
317
+ }
318
+
319
+ function deepFreeze<T>(value: T): T {
320
+ if (value === null || typeof value !== 'object') {
321
+ return value;
322
+ }
323
+ if (Object.isFrozen(value)) {
324
+ return value;
325
+ }
326
+
327
+ Object.freeze(value);
328
+
329
+ for (const property of Object.getOwnPropertyNames(value)) {
330
+ const nestedValue = (value as Record<string, unknown>)[property];
331
+ if (nestedValue && typeof nestedValue === 'object') {
332
+ deepFreeze(nestedValue);
333
+ }
334
+ }
335
+
336
+ return value;
337
+ }
338
+
339
+ function computeMultipleEncryptedKeySize(ecies: IECIESConstants): number {
340
+ return ecies.IV_SIZE + ecies.AUTH_TAG_SIZE + ecies.SYMMETRIC.KEY_SIZE;
341
+ }
342
+
343
+ function validateConstants(config: IConstants): void {
344
+ const checksum = config.CHECKSUM;
345
+ const ecies = config.ECIES;
346
+
347
+ if (
348
+ checksum.SHA3_BUFFER_LENGTH !== checksum.SHA3_DEFAULT_HASH_BITS / 8 ||
349
+ checksum.SHA3_BUFFER_LENGTH !== checksum.SHA3_DEFAULT_HASH_BITS / 8
350
+ ) {
351
+ const engine = getEciesI18nEngine();
352
+ throw new Error(
353
+ engine.translate(
354
+ EciesComponentId,
355
+ EciesStringKey.Error_ECIESError_InvalidChecksumConstants,
356
+ ),
357
+ );
358
+ }
359
+
360
+ const expectedEncryptedKeySize = computeMultipleEncryptedKeySize(ecies);
361
+ if (ecies.MULTIPLE.ENCRYPTED_KEY_SIZE !== expectedEncryptedKeySize) {
362
+ throw new ECIESError(
363
+ ECIESErrorTypeEnum.InvalidECIESMultipleEncryptedKeySize,
364
+ );
365
+ }
366
+
367
+ if (ecies.PUBLIC_KEY_LENGTH !== ecies.RAW_PUBLIC_KEY_LENGTH + 1) {
368
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESPublicKeyLength);
369
+ }
370
+
371
+ if (ecies.MULTIPLE.RECIPIENT_COUNT_SIZE !== UINT16_SIZE) {
372
+ throw new ECIESError(
373
+ ECIESErrorTypeEnum.InvalidECIESMultipleRecipientCountSize,
374
+ );
375
+ }
376
+
377
+ if (ecies.MULTIPLE.DATA_LENGTH_SIZE !== UINT64_SIZE) {
378
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESMultipleDataLengthSize);
379
+ }
380
+
381
+ // Validate ID provider is present and valid
382
+ if (!config.idProvider) {
383
+ throw new Error('ID provider is required in constants configuration');
384
+ }
385
+
386
+ if (
387
+ typeof config.idProvider.byteLength !== 'number' ||
388
+ config.idProvider.byteLength < 1 ||
389
+ config.idProvider.byteLength > 255
390
+ ) {
391
+ throw new Error(
392
+ `Invalid ID provider byteLength: ${config.idProvider.byteLength}. Must be between 1 and 255.`,
393
+ );
394
+ }
395
+
396
+ // Validate MEMBER_ID_LENGTH matches ID provider
397
+ if (config.MEMBER_ID_LENGTH !== config.idProvider.byteLength) {
398
+ throw new Error(
399
+ `MEMBER_ID_LENGTH (${config.MEMBER_ID_LENGTH}) must match idProvider.byteLength (${config.idProvider.byteLength})`,
400
+ );
401
+ }
402
+
403
+ // NOTE: We now validate against idProvider.byteLength instead of OBJECT_ID_LENGTH
404
+ // This allows for flexible ID sizes (12 bytes for ObjectID, 16 for GUID, 32 for legacy, etc.)
405
+ if (ecies.MULTIPLE.RECIPIENT_ID_SIZE !== config.idProvider.byteLength) {
406
+ throw new ECIESError(
407
+ ECIESErrorTypeEnum.InvalidECIESMultipleRecipientIdSize,
408
+ );
409
+ }
410
+ }
411
+
412
+ validateConstants(Constants);
413
+
414
+ const configurationRegistry = new Map<ConfigurationKey, IConstants>();
415
+ configurationRegistry.set(DEFAULT_CONFIGURATION_KEY, Constants);
416
+
417
+ // Provenance tracking
418
+ const provenanceRegistry = new Map<
419
+ ConfigurationKey,
420
+ IConfigurationProvenance
421
+ >();
422
+ provenanceRegistry.set(DEFAULT_CONFIGURATION_KEY, {
423
+ baseConfigKey: 'none',
424
+ overrides: {},
425
+ timestamp: new Date(),
426
+ source: 'default',
427
+ checksum: calculateConfigChecksum(Constants),
428
+ description: 'Built-in default configuration',
429
+ });
430
+
431
+ function isFullConstantsConfig(value: unknown): value is IConstants {
432
+ if (!isPlainObject(value)) {
433
+ return false;
434
+ }
435
+ const candidate = value as Partial<IConstants>;
436
+ return (
437
+ candidate.CHECKSUM !== undefined &&
438
+ candidate.ECIES !== undefined &&
439
+ candidate.PBKDF2 !== undefined &&
440
+ candidate.PBKDF2_PROFILES !== undefined &&
441
+ candidate.idProvider !== undefined
442
+ );
443
+ }
444
+
445
+ export function createRuntimeConfiguration(
446
+ overrides?: DeepPartial<IConstants>,
447
+ base: IConstants = Constants,
448
+ ): IConstants {
449
+ const merged = deepClone(base);
450
+ applyOverrides(merged, overrides);
451
+
452
+ // Auto-sync MEMBER_ID_LENGTH with idProvider.byteLength if provider changed
453
+ if (merged.idProvider && merged.idProvider !== base.idProvider) {
454
+ merged.MEMBER_ID_LENGTH = merged.idProvider.byteLength;
455
+ }
456
+
457
+ // Auto-sync ECIES.MULTIPLE.RECIPIENT_ID_SIZE with idProvider.byteLength if provider changed
458
+ if (merged.idProvider && merged.idProvider !== base.idProvider) {
459
+ merged.ECIES = {
460
+ ...merged.ECIES,
461
+ MULTIPLE: {
462
+ ...merged.ECIES.MULTIPLE,
463
+ RECIPIENT_ID_SIZE: merged.idProvider.byteLength,
464
+ },
465
+ };
466
+ }
467
+
468
+ // Validate individual properties
469
+ validateConstants(merged);
470
+
471
+ // Validate all invariants (relationships between properties)
472
+ InvariantValidator.validateAll(merged);
473
+
474
+ return deepFreeze(merged);
475
+ }
476
+
477
+ export class ConstantsRegistry {
478
+ public static readonly DEFAULT_KEY = DEFAULT_CONFIGURATION_KEY;
479
+
480
+ public static listKeys(): ConfigurationKey[] {
481
+ return Array.from(configurationRegistry.keys());
482
+ }
483
+
484
+ public static has(key: ConfigurationKey): boolean {
485
+ return configurationRegistry.has(key);
486
+ }
487
+
488
+ public static get(
489
+ key: ConfigurationKey = DEFAULT_CONFIGURATION_KEY,
490
+ ): IConstants {
491
+ return (
492
+ configurationRegistry.get(key) ??
493
+ configurationRegistry.get(DEFAULT_CONFIGURATION_KEY)!
494
+ );
495
+ }
496
+
497
+ /**
498
+ * Get provenance information for a configuration
499
+ */
500
+ public static getProvenance(
501
+ key: ConfigurationKey = DEFAULT_CONFIGURATION_KEY,
502
+ ): IConfigurationProvenance | undefined {
503
+ return provenanceRegistry.get(key);
504
+ }
505
+
506
+ /**
507
+ * List all configurations with their provenance
508
+ */
509
+ public static listWithProvenance(): Array<{
510
+ key: ConfigurationKey;
511
+ config: IConstants;
512
+ provenance?: IConfigurationProvenance;
513
+ }> {
514
+ return Array.from(configurationRegistry.entries()).map(([key, config]) => ({
515
+ key,
516
+ config,
517
+ provenance: provenanceRegistry.get(key),
518
+ }));
519
+ }
520
+
521
+ public static create(
522
+ overrides?: DeepPartial<IConstants>,
523
+ baseKey: ConfigurationKey = DEFAULT_CONFIGURATION_KEY,
524
+ ): IConstants {
525
+ const baseConfig = ConstantsRegistry.get(baseKey);
526
+ return createRuntimeConfiguration(overrides, baseConfig);
527
+ }
528
+
529
+ public static register(
530
+ key: ConfigurationKey,
531
+ configOrOverrides?: DeepPartial<IConstants> | IConstants,
532
+ options?: { baseKey?: ConfigurationKey; description?: string },
533
+ ): IConstants {
534
+ if (key === DEFAULT_CONFIGURATION_KEY) {
535
+ const engine = getEciesI18nEngine();
536
+ throw new Error(
537
+ engine.translate(
538
+ EciesComponentId,
539
+ EciesStringKey.Error_ECIESError_CannotOverwriteDefaultConfiguration,
540
+ ),
541
+ );
542
+ }
543
+
544
+ const baseKey = options?.baseKey ?? DEFAULT_CONFIGURATION_KEY;
545
+ const baseConfig = ConstantsRegistry.get(baseKey);
546
+
547
+ const isFullConfig = isFullConstantsConfig(configOrOverrides);
548
+ const configuration = isFullConfig
549
+ ? createRuntimeConfiguration(undefined, configOrOverrides)
550
+ : createRuntimeConfiguration(configOrOverrides, baseConfig);
551
+
552
+ // Track provenance
553
+ const provenance: IConfigurationProvenance = {
554
+ baseConfigKey: typeof baseKey === 'symbol' ? baseKey.toString() : baseKey,
555
+ overrides: isFullConfig ? {} : configOrOverrides ?? {},
556
+ timestamp: new Date(),
557
+ source: isFullConfig ? 'custom' : 'runtime',
558
+ checksum: calculateConfigChecksum(configuration),
559
+ description: options?.description,
560
+ creationStack: captureCreationStack(),
561
+ };
562
+
563
+ configurationRegistry.set(key, configuration);
564
+ provenanceRegistry.set(key, provenance);
565
+ return configuration;
566
+ }
567
+
568
+ public static unregister(key: ConfigurationKey): boolean {
569
+ if (key === DEFAULT_CONFIGURATION_KEY) {
570
+ return false;
571
+ }
572
+ provenanceRegistry.delete(key);
573
+ return configurationRegistry.delete(key);
574
+ }
575
+
576
+ public static clear(): void {
577
+ const defaultProvenance = provenanceRegistry.get(DEFAULT_CONFIGURATION_KEY);
578
+ configurationRegistry.clear();
579
+ provenanceRegistry.clear();
580
+ configurationRegistry.set(DEFAULT_CONFIGURATION_KEY, Constants);
581
+ if (defaultProvenance) {
582
+ provenanceRegistry.set(DEFAULT_CONFIGURATION_KEY, defaultProvenance);
583
+ }
584
+ }
585
+ }
586
+
587
+ export function getRuntimeConfiguration(
588
+ key: ConfigurationKey = DEFAULT_CONFIGURATION_KEY,
589
+ ): IConstants {
590
+ return ConstantsRegistry.get(key);
591
+ }
592
+
593
+ export function registerRuntimeConfiguration(
594
+ key: ConfigurationKey,
595
+ configOrOverrides?: DeepPartial<IConstants> | IConstants,
596
+ options?: { baseKey?: ConfigurationKey },
597
+ ): IConstants {
598
+ return ConstantsRegistry.register(key, configOrOverrides, options);
599
+ }
600
+
601
+ export function unregisterRuntimeConfiguration(key: ConfigurationKey): boolean {
602
+ return ConstantsRegistry.unregister(key);
603
+ }
604
+
605
+ export function clearRuntimeConfigurations(): void {
606
+ ConstantsRegistry.clear();
607
+ }
608
+
609
+ export { MNEMONIC_REGEX, PASSWORD_REGEX } from './regexes';
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Unified error class for all crypto operations
3
+ * Consolidates ECIESError, MemberError, Pbkdf2Error, etc.
4
+ */
5
+
6
+ import { EciesStringKey } from '../../enumerations/ecies-string-key';
7
+ import { EciesComponentId, getEciesI18nEngine } from '../../i18n-setup';
8
+
9
+ export enum CryptoErrorCode {
10
+ // ECIES Errors
11
+ DECRYPTION_FAILED = 'DECRYPTION_FAILED',
12
+ INVALID_KEY_SIZE = 'INVALID_KEY_SIZE',
13
+ INVALID_ENCRYPTION_TYPE = 'INVALID_ENCRYPTION_TYPE',
14
+ INVALID_PUBLIC_KEY = 'INVALID_PUBLIC_KEY',
15
+ RECIPIENT_NOT_FOUND = 'RECIPIENT_NOT_FOUND',
16
+ TOO_MANY_RECIPIENTS = 'TOO_MANY_RECIPIENTS',
17
+
18
+ // Member Errors
19
+ MISSING_MEMBER_NAME = 'MISSING_MEMBER_NAME',
20
+ INVALID_EMAIL = 'INVALID_EMAIL',
21
+ WALLET_NOT_LOADED = 'WALLET_NOT_LOADED',
22
+ INVALID_MNEMONIC = 'INVALID_MNEMONIC',
23
+
24
+ // PBKDF2 Errors
25
+ INVALID_PROFILE = 'INVALID_PROFILE',
26
+ INVALID_SALT_LENGTH = 'INVALID_SALT_LENGTH',
27
+ INVALID_HASH_LENGTH = 'INVALID_HASH_LENGTH',
28
+
29
+ // Storage Errors
30
+ VALUE_IS_NULL = 'VALUE_IS_NULL',
31
+ CHECKSUM_MISMATCH = 'CHECKSUM_MISMATCH',
32
+
33
+ // Password Login Errors
34
+ PASSWORD_LOGIN_NOT_SETUP = 'PASSWORD_LOGIN_NOT_SETUP',
35
+ FAILED_TO_STORE_LOGIN_DATA = 'FAILED_TO_STORE_LOGIN_DATA',
36
+ }
37
+
38
+ export class CryptoError extends Error {
39
+ constructor(
40
+ public readonly code: CryptoErrorCode,
41
+ public readonly stringKey: EciesStringKey,
42
+ public override readonly metadata?: Record<string, string | number>,
43
+ ) {
44
+ const engine = getEciesI18nEngine();
45
+ const message = engine.translate(EciesComponentId, stringKey, metadata);
46
+ super(message);
47
+ this.name = 'CryptoError';
48
+ Object.setPrototypeOf(this, CryptoError.prototype);
49
+ }
50
+
51
+ static decryptionFailed(
52
+ metadata?: Record<string, string | number>,
53
+ ): CryptoError {
54
+ return new CryptoError(
55
+ CryptoErrorCode.DECRYPTION_FAILED,
56
+ EciesStringKey.Error_ECIESError_DecryptionFailed,
57
+ metadata,
58
+ );
59
+ }
60
+
61
+ static invalidProfile(
62
+ metadata?: Record<string, string | number>,
63
+ ): CryptoError {
64
+ return new CryptoError(
65
+ CryptoErrorCode.INVALID_PROFILE,
66
+ EciesStringKey.Error_Pbkdf2Error_InvalidProfile,
67
+ metadata,
68
+ );
69
+ }
70
+
71
+ static invalidEmail(metadata?: Record<string, string | number>): CryptoError {
72
+ return new CryptoError(
73
+ CryptoErrorCode.INVALID_EMAIL,
74
+ EciesStringKey.Error_MemberError_InvalidEmail,
75
+ metadata,
76
+ );
77
+ }
78
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Core exports for v2 architecture
3
3
  */
4
+
4
5
  export * from './errors/crypto-error';
5
6
  export * from './types/result';
6
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Result pattern for better error handling
3
+ */
4
+
5
+ import { CryptoError } from '../errors/crypto-error';
6
+
7
+ export type CryptoResult<T> =
8
+ | { success: true; data: T }
9
+ | { success: false; error: CryptoError };
10
+
11
+ export class ResultBuilder {
12
+ static success<T>(data: T): CryptoResult<T> {
13
+ return { success: true, data };
14
+ }
15
+
16
+ static failure<T>(error: CryptoError): CryptoResult<T> {
17
+ return { success: false, error };
18
+ }
19
+ }