@digitaldefiance/node-ecies-lib 4.5.19 → 4.6.3

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 (353) hide show
  1. package/package.json +2 -2
  2. package/src/builders/ecies-builder.d.ts +11 -0
  3. package/src/builders/ecies-builder.d.ts.map +1 -0
  4. package/src/builders/ecies-builder.js +26 -0
  5. package/src/builders/ecies-builder.js.map +1 -0
  6. package/src/builders/index.d.ts +3 -0
  7. package/src/builders/index.d.ts.map +1 -0
  8. package/src/builders/index.js +6 -0
  9. package/src/builders/index.js.map +1 -0
  10. package/src/builders/member-builder.d.ts +47 -0
  11. package/src/builders/member-builder.d.ts.map +1 -0
  12. package/src/builders/member-builder.js +99 -0
  13. package/src/builders/member-builder.js.map +1 -0
  14. package/src/constants.d.ts +38 -0
  15. package/src/constants.d.ts.map +1 -0
  16. package/src/constants.js +191 -0
  17. package/src/constants.js.map +1 -0
  18. package/src/core/errors/crypto-error.d.ts +6 -0
  19. package/src/core/errors/crypto-error.d.ts.map +1 -0
  20. package/src/core/errors/crypto-error.js +15 -0
  21. package/src/core/errors/crypto-error.js.map +1 -0
  22. package/src/core/index.d.ts +3 -0
  23. package/src/core/index.d.ts.map +1 -0
  24. package/src/core/index.js +6 -0
  25. package/src/core/index.js.map +1 -0
  26. package/src/core/types/result.d.ts +8 -0
  27. package/src/core/types/result.d.ts.map +1 -0
  28. package/src/core/types/result.js +3 -0
  29. package/src/core/types/result.js.map +1 -0
  30. package/src/enumerations/index.d.ts +3 -0
  31. package/src/enumerations/index.d.ts.map +1 -0
  32. package/src/enumerations/index.js +6 -0
  33. package/src/enumerations/index.js.map +1 -0
  34. package/src/enumerations/pbkdf2-profile.d.ts +9 -0
  35. package/src/enumerations/pbkdf2-profile.d.ts.map +1 -0
  36. package/src/enumerations/pbkdf2-profile.js +13 -0
  37. package/src/enumerations/pbkdf2-profile.js.map +1 -0
  38. package/src/enumerations/voting-error-type.d.ts +37 -0
  39. package/src/enumerations/voting-error-type.d.ts.map +1 -0
  40. package/src/enumerations/voting-error-type.js +48 -0
  41. package/src/enumerations/voting-error-type.js.map +1 -0
  42. package/src/errors/index.d.ts +2 -0
  43. package/src/errors/index.d.ts.map +1 -0
  44. package/src/errors/index.js +5 -0
  45. package/src/errors/index.js.map +1 -0
  46. package/src/errors/voting.d.ts +16 -0
  47. package/src/errors/voting.d.ts.map +1 -0
  48. package/src/errors/voting.js +27 -0
  49. package/src/errors/voting.js.map +1 -0
  50. package/src/i18n/ecies-i18n-factory.d.ts +28 -0
  51. package/src/i18n/ecies-i18n-factory.d.ts.map +1 -0
  52. package/src/i18n/ecies-i18n-factory.js +90 -0
  53. package/src/i18n/ecies-i18n-factory.js.map +1 -0
  54. package/src/i18n/index.d.ts +3 -0
  55. package/src/i18n/index.d.ts.map +1 -0
  56. package/src/i18n/index.js +8 -0
  57. package/src/i18n/index.js.map +1 -0
  58. package/src/i18n/node-ecies-i18n-setup.d.ts +5 -0
  59. package/src/i18n/node-ecies-i18n-setup.d.ts.map +1 -0
  60. package/src/i18n/node-ecies-i18n-setup.js +48 -0
  61. package/src/i18n/node-ecies-i18n-setup.js.map +1 -0
  62. package/src/i18n/node-keys.d.ts +57 -0
  63. package/src/i18n/node-keys.d.ts.map +1 -0
  64. package/src/i18n/node-keys.js +67 -0
  65. package/src/i18n/node-keys.js.map +1 -0
  66. package/src/i18n/translations/de.d.ts +3 -0
  67. package/src/i18n/translations/de.d.ts.map +1 -0
  68. package/src/i18n/translations/de.js +57 -0
  69. package/src/i18n/translations/de.js.map +1 -0
  70. package/src/i18n/translations/en-GB.d.ts +3 -0
  71. package/src/i18n/translations/en-GB.d.ts.map +1 -0
  72. package/src/i18n/translations/en-GB.js +61 -0
  73. package/src/i18n/translations/en-GB.js.map +1 -0
  74. package/src/i18n/translations/en-US.d.ts +6 -0
  75. package/src/i18n/translations/en-US.d.ts.map +1 -0
  76. package/src/i18n/translations/en-US.js +65 -0
  77. package/src/i18n/translations/en-US.js.map +1 -0
  78. package/src/i18n/translations/es.d.ts +3 -0
  79. package/src/i18n/translations/es.d.ts.map +1 -0
  80. package/src/i18n/translations/es.js +57 -0
  81. package/src/i18n/translations/es.js.map +1 -0
  82. package/src/i18n/translations/fr.d.ts +3 -0
  83. package/src/i18n/translations/fr.d.ts.map +1 -0
  84. package/src/i18n/translations/fr.js +57 -0
  85. package/src/i18n/translations/fr.js.map +1 -0
  86. package/src/i18n/translations/index.d.ts +9 -0
  87. package/src/i18n/translations/index.d.ts.map +1 -0
  88. package/src/i18n/translations/index.js +20 -0
  89. package/src/i18n/translations/index.js.map +1 -0
  90. package/src/i18n/translations/ja.d.ts +3 -0
  91. package/src/i18n/translations/ja.d.ts.map +1 -0
  92. package/src/i18n/translations/ja.js +57 -0
  93. package/src/i18n/translations/ja.js.map +1 -0
  94. package/src/i18n/translations/uk.d.ts +3 -0
  95. package/src/i18n/translations/uk.d.ts.map +1 -0
  96. package/src/i18n/translations/uk.js +57 -0
  97. package/src/i18n/translations/uk.js.map +1 -0
  98. package/src/i18n/translations/zh-cn.d.ts +3 -0
  99. package/src/i18n/translations/zh-cn.d.ts.map +1 -0
  100. package/src/i18n/translations/zh-cn.js +57 -0
  101. package/src/i18n/translations/zh-cn.js.map +1 -0
  102. package/src/i18n-setup.d.ts +26 -0
  103. package/src/i18n-setup.d.ts.map +1 -0
  104. package/src/i18n-setup.js +111 -0
  105. package/src/i18n-setup.js.map +1 -0
  106. package/src/index.d.ts +21 -0
  107. package/src/index.d.ts.map +1 -0
  108. package/src/index.js +36 -0
  109. package/src/index.js.map +1 -0
  110. package/src/interfaces/authenticated-cipher.d.ts +12 -0
  111. package/src/interfaces/authenticated-cipher.d.ts.map +1 -0
  112. package/src/interfaces/authenticated-cipher.js +3 -0
  113. package/src/interfaces/authenticated-cipher.js.map +1 -0
  114. package/src/interfaces/authenticated-decipher.d.ts +11 -0
  115. package/src/interfaces/authenticated-decipher.d.ts.map +1 -0
  116. package/src/interfaces/authenticated-decipher.js +3 -0
  117. package/src/interfaces/authenticated-decipher.js.map +1 -0
  118. package/src/interfaces/backend-member-operational.d.ts +48 -0
  119. package/src/interfaces/backend-member-operational.d.ts.map +1 -0
  120. package/src/interfaces/backend-member-operational.js +3 -0
  121. package/src/interfaces/backend-member-operational.js.map +1 -0
  122. package/src/interfaces/checksum-config.d.ts +5 -0
  123. package/src/interfaces/checksum-config.d.ts.map +1 -0
  124. package/src/interfaces/checksum-config.js +3 -0
  125. package/src/interfaces/checksum-config.js.map +1 -0
  126. package/src/interfaces/checksum-consts.d.ts +11 -0
  127. package/src/interfaces/checksum-consts.d.ts.map +1 -0
  128. package/src/interfaces/checksum-consts.js +3 -0
  129. package/src/interfaces/checksum-consts.js.map +1 -0
  130. package/src/interfaces/constants.d.ts +52 -0
  131. package/src/interfaces/constants.d.ts.map +1 -0
  132. package/src/interfaces/constants.js +3 -0
  133. package/src/interfaces/constants.js.map +1 -0
  134. package/src/interfaces/ecies-consts.d.ts +88 -0
  135. package/src/interfaces/ecies-consts.d.ts.map +1 -0
  136. package/src/interfaces/ecies-consts.js +3 -0
  137. package/src/interfaces/ecies-consts.js.map +1 -0
  138. package/src/interfaces/encrypted-chunk.d.ts +12 -0
  139. package/src/interfaces/encrypted-chunk.d.ts.map +1 -0
  140. package/src/interfaces/encrypted-chunk.js +3 -0
  141. package/src/interfaces/encrypted-chunk.js.map +1 -0
  142. package/src/interfaces/encryption-consts.d.ts +11 -0
  143. package/src/interfaces/encryption-consts.d.ts.map +1 -0
  144. package/src/interfaces/encryption-consts.js +3 -0
  145. package/src/interfaces/encryption-consts.js.map +1 -0
  146. package/src/interfaces/index.d.ts +31 -0
  147. package/src/interfaces/index.d.ts.map +1 -0
  148. package/src/interfaces/index.js +33 -0
  149. package/src/interfaces/index.js.map +1 -0
  150. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
  151. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
  152. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js +3 -0
  153. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
  154. package/src/interfaces/keyring-consts.d.ts +6 -0
  155. package/src/interfaces/keyring-consts.d.ts.map +1 -0
  156. package/src/interfaces/keyring-consts.js +3 -0
  157. package/src/interfaces/keyring-consts.js.map +1 -0
  158. package/src/interfaces/member-with-mnemonic.d.ts +7 -0
  159. package/src/interfaces/member-with-mnemonic.d.ts.map +1 -0
  160. package/src/interfaces/member-with-mnemonic.js +3 -0
  161. package/src/interfaces/member-with-mnemonic.js.map +1 -0
  162. package/src/interfaces/member.d.ts +47 -0
  163. package/src/interfaces/member.d.ts.map +1 -0
  164. package/src/interfaces/member.js +3 -0
  165. package/src/interfaces/member.js.map +1 -0
  166. package/src/interfaces/multi-encrypted-message.d.ts +8 -0
  167. package/src/interfaces/multi-encrypted-message.d.ts.map +1 -0
  168. package/src/interfaces/multi-encrypted-message.js +3 -0
  169. package/src/interfaces/multi-encrypted-message.js.map +1 -0
  170. package/src/interfaces/multi-encrypted-parsed-header.d.ts +27 -0
  171. package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
  172. package/src/interfaces/multi-encrypted-parsed-header.js +3 -0
  173. package/src/interfaces/multi-encrypted-parsed-header.js.map +1 -0
  174. package/src/interfaces/multi-recipient-chunk.d.ts +26 -0
  175. package/src/interfaces/multi-recipient-chunk.d.ts.map +1 -0
  176. package/src/interfaces/multi-recipient-chunk.js +15 -0
  177. package/src/interfaces/multi-recipient-chunk.js.map +1 -0
  178. package/src/interfaces/pbkdf-profiles.d.ts +6 -0
  179. package/src/interfaces/pbkdf-profiles.d.ts.map +1 -0
  180. package/src/interfaces/pbkdf-profiles.js +3 -0
  181. package/src/interfaces/pbkdf-profiles.js.map +1 -0
  182. package/src/interfaces/pbkdf2-result.d.ts +6 -0
  183. package/src/interfaces/pbkdf2-result.d.ts.map +1 -0
  184. package/src/interfaces/pbkdf2-result.js +3 -0
  185. package/src/interfaces/pbkdf2-result.js.map +1 -0
  186. package/src/interfaces/signing-key-private-key-info.d.ts +11 -0
  187. package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -0
  188. package/src/interfaces/signing-key-private-key-info.js +3 -0
  189. package/src/interfaces/signing-key-private-key-info.js.map +1 -0
  190. package/src/interfaces/simple-keypair-buffer.d.ts +6 -0
  191. package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -0
  192. package/src/interfaces/simple-keypair-buffer.js +3 -0
  193. package/src/interfaces/simple-keypair-buffer.js.map +1 -0
  194. package/src/interfaces/simple-keypair.d.ts +6 -0
  195. package/src/interfaces/simple-keypair.d.ts.map +1 -0
  196. package/src/interfaces/simple-keypair.js +3 -0
  197. package/src/interfaces/simple-keypair.js.map +1 -0
  198. package/src/interfaces/simple-public-key-only-buffer.d.ts +4 -0
  199. package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
  200. package/src/interfaces/simple-public-key-only-buffer.js +3 -0
  201. package/src/interfaces/simple-public-key-only-buffer.js.map +1 -0
  202. package/src/interfaces/simple-public-key-only.d.ts +4 -0
  203. package/src/interfaces/simple-public-key-only.d.ts.map +1 -0
  204. package/src/interfaces/simple-public-key-only.js +3 -0
  205. package/src/interfaces/simple-public-key-only.js.map +1 -0
  206. package/src/interfaces/single-encrypted-parsed-header.d.ts +35 -0
  207. package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
  208. package/src/interfaces/single-encrypted-parsed-header.js +3 -0
  209. package/src/interfaces/single-encrypted-parsed-header.js.map +1 -0
  210. package/src/interfaces/stream-config.d.ts +6 -0
  211. package/src/interfaces/stream-config.d.ts.map +1 -0
  212. package/src/interfaces/stream-config.js +8 -0
  213. package/src/interfaces/stream-config.js.map +1 -0
  214. package/src/interfaces/stream-progress.d.ts +22 -0
  215. package/src/interfaces/stream-progress.d.ts.map +1 -0
  216. package/src/interfaces/stream-progress.js +3 -0
  217. package/src/interfaces/stream-progress.js.map +1 -0
  218. package/src/interfaces/voting-consts.d.ts +86 -0
  219. package/src/interfaces/voting-consts.d.ts.map +1 -0
  220. package/src/interfaces/voting-consts.js +27 -0
  221. package/src/interfaces/voting-consts.js.map +1 -0
  222. package/src/interfaces/wallet-seed.d.ts +7 -0
  223. package/src/interfaces/wallet-seed.d.ts.map +1 -0
  224. package/src/interfaces/wallet-seed.js +3 -0
  225. package/src/interfaces/wallet-seed.js.map +1 -0
  226. package/src/interfaces/wrapped-key-consts.d.ts +7 -0
  227. package/src/interfaces/wrapped-key-consts.d.ts.map +1 -0
  228. package/src/interfaces/wrapped-key-consts.js +3 -0
  229. package/src/interfaces/wrapped-key-consts.js.map +1 -0
  230. package/src/isolated-private.d.ts +62 -0
  231. package/src/isolated-private.d.ts.map +1 -0
  232. package/src/isolated-private.js +139 -0
  233. package/src/isolated-private.js.map +1 -0
  234. package/src/isolated-public.d.ts +118 -0
  235. package/src/isolated-public.d.ts.map +1 -0
  236. package/src/isolated-public.js +317 -0
  237. package/src/isolated-public.js.map +1 -0
  238. package/src/lib/crypto-container.d.ts +13 -0
  239. package/src/lib/crypto-container.d.ts.map +1 -0
  240. package/src/lib/crypto-container.js +32 -0
  241. package/src/lib/crypto-container.js.map +1 -0
  242. package/src/lib/index.d.ts +4 -0
  243. package/src/lib/index.d.ts.map +1 -0
  244. package/src/lib/index.js +7 -0
  245. package/src/lib/index.js.map +1 -0
  246. package/src/lib/invariant-validator.d.ts +69 -0
  247. package/src/lib/invariant-validator.d.ts.map +1 -0
  248. package/src/lib/invariant-validator.js +98 -0
  249. package/src/lib/invariant-validator.js.map +1 -0
  250. package/src/lib/invariants/index.d.ts +8 -0
  251. package/src/lib/invariants/index.d.ts.map +1 -0
  252. package/src/lib/invariants/index.js +12 -0
  253. package/src/lib/invariants/index.js.map +1 -0
  254. package/src/lib/invariants/recipient-id-consistency.d.ts +41 -0
  255. package/src/lib/invariants/recipient-id-consistency.d.ts.map +1 -0
  256. package/src/lib/invariants/recipient-id-consistency.js +75 -0
  257. package/src/lib/invariants/recipient-id-consistency.js.map +1 -0
  258. package/src/member.d.ts +100 -0
  259. package/src/member.d.ts.map +1 -0
  260. package/src/member.js +345 -0
  261. package/src/member.js.map +1 -0
  262. package/src/services/aes-gcm.d.ts +66 -0
  263. package/src/services/aes-gcm.d.ts.map +1 -0
  264. package/src/services/aes-gcm.js +161 -0
  265. package/src/services/aes-gcm.js.map +1 -0
  266. package/src/services/chunk-processor.d.ts +15 -0
  267. package/src/services/chunk-processor.d.ts.map +1 -0
  268. package/src/services/chunk-processor.js +36 -0
  269. package/src/services/chunk-processor.js.map +1 -0
  270. package/src/services/ecies/crypto-core.d.ts +104 -0
  271. package/src/services/ecies/crypto-core.d.ts.map +1 -0
  272. package/src/services/ecies/crypto-core.js +234 -0
  273. package/src/services/ecies/crypto-core.js.map +1 -0
  274. package/src/services/ecies/file.d.ts +30 -0
  275. package/src/services/ecies/file.d.ts.map +1 -0
  276. package/src/services/ecies/file.js +112 -0
  277. package/src/services/ecies/file.js.map +1 -0
  278. package/src/services/ecies/index.d.ts +8 -0
  279. package/src/services/ecies/index.d.ts.map +1 -0
  280. package/src/services/ecies/index.js +11 -0
  281. package/src/services/ecies/index.js.map +1 -0
  282. package/src/services/ecies/multi-recipient.d.ts +84 -0
  283. package/src/services/ecies/multi-recipient.d.ts.map +1 -0
  284. package/src/services/ecies/multi-recipient.js +502 -0
  285. package/src/services/ecies/multi-recipient.js.map +1 -0
  286. package/src/services/ecies/service.d.ts +75 -0
  287. package/src/services/ecies/service.d.ts.map +1 -0
  288. package/src/services/ecies/service.js +152 -0
  289. package/src/services/ecies/service.js.map +1 -0
  290. package/src/services/ecies/signature.d.ts +38 -0
  291. package/src/services/ecies/signature.d.ts.map +1 -0
  292. package/src/services/ecies/signature.js +70 -0
  293. package/src/services/ecies/signature.js.map +1 -0
  294. package/src/services/ecies/single-recipient.d.ts +83 -0
  295. package/src/services/ecies/single-recipient.d.ts.map +1 -0
  296. package/src/services/ecies/single-recipient.js +452 -0
  297. package/src/services/ecies/single-recipient.js.map +1 -0
  298. package/src/services/ecies/utilities.d.ts +33 -0
  299. package/src/services/ecies/utilities.d.ts.map +1 -0
  300. package/src/services/ecies/utilities.js +91 -0
  301. package/src/services/ecies/utilities.js.map +1 -0
  302. package/src/services/encryption-stream.d.ts +33 -0
  303. package/src/services/encryption-stream.d.ts.map +1 -0
  304. package/src/services/encryption-stream.js +211 -0
  305. package/src/services/encryption-stream.js.map +1 -0
  306. package/src/services/index.d.ts +9 -0
  307. package/src/services/index.d.ts.map +1 -0
  308. package/src/services/index.js +14 -0
  309. package/src/services/index.js.map +1 -0
  310. package/src/services/multi-recipient-processor.d.ts +72 -0
  311. package/src/services/multi-recipient-processor.d.ts.map +1 -0
  312. package/src/services/multi-recipient-processor.js +325 -0
  313. package/src/services/multi-recipient-processor.js.map +1 -0
  314. package/src/services/pbkdf2.d.ts +105 -0
  315. package/src/services/pbkdf2.d.ts.map +1 -0
  316. package/src/services/pbkdf2.js +191 -0
  317. package/src/services/pbkdf2.js.map +1 -0
  318. package/src/services/progress-tracker.d.ts +14 -0
  319. package/src/services/progress-tracker.d.ts.map +1 -0
  320. package/src/services/progress-tracker.js +94 -0
  321. package/src/services/progress-tracker.js.map +1 -0
  322. package/src/services/voting.service.d.ts +262 -0
  323. package/src/services/voting.service.d.ts.map +1 -0
  324. package/src/services/voting.service.js +791 -0
  325. package/src/services/voting.service.js.map +1 -0
  326. package/src/test-mocks/index.d.ts +2 -0
  327. package/src/test-mocks/index.d.ts.map +1 -0
  328. package/src/test-mocks/index.js +5 -0
  329. package/src/test-mocks/index.js.map +1 -0
  330. package/src/test-mocks/mock-backend-member.d.ts +76 -0
  331. package/src/test-mocks/mock-backend-member.d.ts.map +1 -0
  332. package/src/test-mocks/mock-backend-member.js +139 -0
  333. package/src/test-mocks/mock-backend-member.js.map +1 -0
  334. package/src/testing.d.ts +2 -0
  335. package/src/testing.d.ts.map +1 -0
  336. package/src/testing.js +6 -0
  337. package/src/testing.js.map +1 -0
  338. package/src/types/id-guards.d.ts +39 -0
  339. package/src/types/id-guards.d.ts.map +1 -0
  340. package/src/types/id-guards.js +91 -0
  341. package/src/types/id-guards.js.map +1 -0
  342. package/src/types/index.d.ts +2 -0
  343. package/src/types/index.d.ts.map +1 -0
  344. package/src/types/index.js +5 -0
  345. package/src/types/index.js.map +1 -0
  346. package/src/types.d.ts +26 -0
  347. package/src/types.d.ts.map +1 -0
  348. package/src/types.js +6 -0
  349. package/src/types.js.map +1 -0
  350. package/src/utils.d.ts +11 -0
  351. package/src/utils.d.ts.map +1 -0
  352. package/src/utils.js +82 -0
  353. package/src/utils.js.map +1 -0
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiRecipientProcessor = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
6
+ const constants_1 = require("../constants");
7
+ const multi_recipient_chunk_1 = require("../interfaces/multi-recipient-chunk");
8
+ const aes_gcm_1 = require("./aes-gcm");
9
+ const multi_recipient_1 = require("./ecies/multi-recipient");
10
+ class MultiRecipientProcessor {
11
+ aesGcm;
12
+ cryptoCore;
13
+ consts;
14
+ eciesMultiRecipient;
15
+ constants;
16
+ recipientIdSize;
17
+ constructor(cryptoCore, consts = constants_1.Constants.ECIES, aesGcm, eciesMultiRecipient) {
18
+ this.cryptoCore = cryptoCore;
19
+ this.consts = consts;
20
+ // Use injected dependencies or create defaults
21
+ this.aesGcm = aesGcm ?? new aes_gcm_1.AESGCMService();
22
+ this.eciesMultiRecipient =
23
+ eciesMultiRecipient ?? new multi_recipient_1.EciesMultiRecipient(cryptoCore);
24
+ this.recipientIdSize = consts.MULTIPLE.RECIPIENT_ID_SIZE;
25
+ this.constants = (0, multi_recipient_chunk_1.getMultiRecipientConstants)(this.recipientIdSize);
26
+ }
27
+ /**
28
+ * Encrypts a message for multiple recipients.
29
+ * Wrapper around EciesMultiRecipient.encryptMultiple for backward compatibility.
30
+ */
31
+ async encryptMultiple(recipients, message, preamble = Buffer.alloc(0)) {
32
+ // Convert IMultiRecipient to IMember-like objects
33
+ // EciesMultiRecipient expects IMember[] which has id: Buffer and publicKey: Buffer
34
+ // IMultiRecipient already matches this structure, so we can safely cast
35
+ const members = recipients;
36
+ const result = this.eciesMultiRecipient.encryptMultiple(members, message, preamble);
37
+ return result;
38
+ }
39
+ /**
40
+ * Builds the header for a message encrypted for multiple recipients.
41
+ * Wrapper around EciesMultiRecipient.buildECIESMultipleRecipientHeader for backward compatibility.
42
+ */
43
+ buildHeader(data) {
44
+ return this.eciesMultiRecipient.buildECIESMultipleRecipientHeader(data);
45
+ }
46
+ async encryptChunk(data, recipients, chunkIndex, isLast, symmetricKey, senderPrivateKey) {
47
+ if (chunkIndex < 0 || chunkIndex > 0xffffffff) {
48
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
49
+ }
50
+ // Sign-then-Encrypt
51
+ let dataToEncrypt = data;
52
+ if (senderPrivateKey) {
53
+ const signature = this.cryptoCore.sign(senderPrivateKey, data);
54
+ dataToEncrypt = Buffer.concat([signature, data]);
55
+ }
56
+ if (dataToEncrypt.length > this.consts.MAX_RAW_DATA_SIZE) {
57
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.FileSizeTooLarge);
58
+ }
59
+ // Generate ONE ephemeral key pair for all recipients
60
+ const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
61
+ ecdh.generateKeys();
62
+ const ephemeralPrivateKey = ecdh.getPrivateKey();
63
+ let ephemeralPublicKey = ecdh.getPublicKey(null, 'compressed');
64
+ // Ensure public key has 0x04 prefix
65
+ if (ephemeralPublicKey.length === this.cryptoCore.consts.RAW_PUBLIC_KEY_LENGTH) {
66
+ ephemeralPublicKey = Buffer.concat([
67
+ Buffer.from([this.cryptoCore.consts.PUBLIC_KEY_MAGIC]),
68
+ ephemeralPublicKey,
69
+ ]);
70
+ }
71
+ // Build recipient headers
72
+ const recipientHeaders = [];
73
+ for (const recipient of recipients) {
74
+ // Use Recipient ID as AAD for key encryption
75
+ const encryptedKey = this.eciesMultiRecipient.encryptKey(recipient.publicKey, symmetricKey, ephemeralPrivateKey, recipient.id);
76
+ recipientHeaders.push({
77
+ id: recipient.id,
78
+ keySize: encryptedKey.length,
79
+ encryptedKey,
80
+ });
81
+ }
82
+ // Calculate encrypted size (Data + Tag)
83
+ // AES-GCM tag is 16 bytes
84
+ const encryptedSize = dataToEncrypt.length + 16;
85
+ // Calculate total size
86
+ let recipientHeadersSize = 0;
87
+ for (const h of recipientHeaders) {
88
+ recipientHeadersSize +=
89
+ this.recipientIdSize + this.constants.KEY_SIZE_BYTES + h.keySize;
90
+ }
91
+ const totalSize = this.constants.HEADER_SIZE +
92
+ recipientHeadersSize +
93
+ 12 + // IV
94
+ encryptedSize;
95
+ // Build chunk buffer
96
+ const chunk = Buffer.alloc(totalSize);
97
+ let offset = 0;
98
+ // Write header
99
+ chunk.writeUInt32BE(this.constants.MAGIC, offset);
100
+ offset += 4;
101
+ chunk.writeUInt16BE(this.constants.VERSION, offset);
102
+ offset += 2;
103
+ chunk.writeUInt16BE(recipients.length, offset);
104
+ offset += 2;
105
+ chunk.writeUInt32BE(chunkIndex, offset);
106
+ offset += 4;
107
+ chunk.writeUInt32BE(dataToEncrypt.length, offset); // Original Size
108
+ offset += 4;
109
+ chunk.writeUInt32BE(encryptedSize, offset);
110
+ offset += 4;
111
+ chunk.writeUInt8(isLast ? this.constants.FLAG_IS_LAST : 0, offset);
112
+ offset += 1;
113
+ // Write Ephemeral Public Key (33 bytes)
114
+ ephemeralPublicKey.copy(chunk, offset);
115
+ offset += 33;
116
+ // Padding to HEADER_SIZE (64 bytes)
117
+ offset = this.constants.HEADER_SIZE;
118
+ // Write recipient headers
119
+ for (const header of recipientHeaders) {
120
+ header.id.copy(chunk, offset);
121
+ offset += this.recipientIdSize;
122
+ chunk.writeUInt16BE(header.keySize, offset);
123
+ offset += this.constants.KEY_SIZE_BYTES;
124
+ header.encryptedKey.copy(chunk, offset);
125
+ offset += header.keySize;
126
+ }
127
+ // Extract the full header (including recipient headers) to use as AAD
128
+ const headerBytes = chunk.subarray(0, offset);
129
+ // Encrypt data with AES-256-GCM using Header as AAD
130
+ const iv = (0, crypto_1.randomBytes)(this.consts.IV_SIZE);
131
+ const cipher = (0, crypto_1.createCipheriv)(this.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
132
+ cipher.setAAD(headerBytes);
133
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
134
+ const encrypted = cipher.update(dataToEncrypt);
135
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
136
+ const final = cipher.final();
137
+ const authTag = cipher.getAuthTag();
138
+ // Write IV
139
+ iv.copy(chunk, offset);
140
+ offset += 12;
141
+ // Write encrypted data
142
+ encrypted.copy(chunk, offset);
143
+ offset += encrypted.length;
144
+ final.copy(chunk, offset); // Should be empty usually
145
+ offset += final.length;
146
+ // Write auth tag
147
+ authTag.copy(chunk, offset);
148
+ const header = {
149
+ chunkIndex,
150
+ flags: isLast ? 1 : 0,
151
+ recipientCount: recipients.length,
152
+ magic: this.constants.MAGIC,
153
+ version: this.constants.VERSION,
154
+ originalSize: dataToEncrypt.length,
155
+ encryptedSize,
156
+ };
157
+ return {
158
+ header,
159
+ data: chunk,
160
+ };
161
+ }
162
+ async decryptChunk(chunkData, recipientId, privateKey, senderPublicKey) {
163
+ if (chunkData.length < this.constants.HEADER_SIZE) {
164
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
165
+ }
166
+ let offset = 0;
167
+ // Parse header
168
+ const magic = chunkData.readUInt32BE(offset);
169
+ offset += 4;
170
+ if (magic !== this.constants.MAGIC) {
171
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength); // Invalid Magic
172
+ }
173
+ const version = chunkData.readUInt16BE(offset);
174
+ offset += 2;
175
+ if (version !== this.constants.VERSION) {
176
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidVersion);
177
+ }
178
+ const recipientCount = chunkData.readUInt16BE(offset);
179
+ offset += 2;
180
+ const chunkIndex = chunkData.readUInt32BE(offset);
181
+ offset += 4;
182
+ const originalSize = chunkData.readUInt32BE(offset);
183
+ offset += 4;
184
+ const encryptedSize = chunkData.readUInt32BE(offset);
185
+ offset += 4;
186
+ const flags = chunkData.readUInt8(offset);
187
+ offset += 1;
188
+ // Read Ephemeral Public Key (33 bytes)
189
+ const ephemeralPublicKey = chunkData.subarray(offset, offset + 33);
190
+ offset += 33;
191
+ offset = this.constants.HEADER_SIZE;
192
+ // Find recipient header and decrypt symmetric key
193
+ let symmetricKey = null;
194
+ let tempOffset = offset;
195
+ for (let i = 0; i < recipientCount; i++) {
196
+ const id = chunkData.subarray(tempOffset, tempOffset + this.recipientIdSize);
197
+ tempOffset += this.recipientIdSize;
198
+ const keySize = chunkData.readUInt16BE(tempOffset);
199
+ tempOffset += this.constants.KEY_SIZE_BYTES;
200
+ const encryptedKey = chunkData.subarray(tempOffset, tempOffset + keySize);
201
+ tempOffset += keySize;
202
+ // Check if this is our recipient
203
+ if (id.equals(recipientId)) {
204
+ // Use Recipient ID as AAD for key decryption
205
+ symmetricKey = this.eciesMultiRecipient.decryptKey(privateKey, encryptedKey, ephemeralPublicKey, id);
206
+ }
207
+ }
208
+ if (!symmetricKey) {
209
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.RecipientNotFound);
210
+ }
211
+ // Update offset to after all recipient headers
212
+ offset = tempOffset;
213
+ // Extract header bytes for AAD
214
+ const headerBytes = chunkData.subarray(0, offset);
215
+ // Read IV
216
+ const iv = chunkData.subarray(offset, offset + 12);
217
+ offset += 12;
218
+ // Read encrypted data (includes tag)
219
+ const encryptedWithTag = chunkData.subarray(offset, offset + encryptedSize);
220
+ offset += encryptedSize;
221
+ // Extract tag from end of encrypted data
222
+ const authTag = encryptedWithTag.subarray(encryptedWithTag.length - 16);
223
+ const encrypted = encryptedWithTag.subarray(0, encryptedWithTag.length - 16);
224
+ // Decrypt with AAD
225
+ const decipher = (0, crypto_1.createDecipheriv)(this.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
226
+ decipher.setAuthTag(authTag);
227
+ decipher.setAAD(headerBytes);
228
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
229
+ const decrypted = decipher.update(encrypted);
230
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
231
+ const final = decipher.final();
232
+ const decryptedMessage = Buffer.concat([decrypted, final]);
233
+ // Verify signature if sender public key provided
234
+ let finalData = decryptedMessage;
235
+ if (senderPublicKey) {
236
+ if (decryptedMessage.length < 64) {
237
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature);
238
+ }
239
+ const signature = decryptedMessage.subarray(0, 64);
240
+ const message = decryptedMessage.subarray(64);
241
+ const isValid = this.cryptoCore.verify(senderPublicKey, message, signature);
242
+ if (!isValid) {
243
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature);
244
+ }
245
+ finalData = message;
246
+ }
247
+ return {
248
+ data: finalData,
249
+ header: {
250
+ chunkIndex,
251
+ flags,
252
+ recipientCount,
253
+ magic,
254
+ version,
255
+ originalSize,
256
+ encryptedSize,
257
+ },
258
+ };
259
+ }
260
+ /**
261
+ * Decrypts a message encrypted with multiple ECIE for a recipient.
262
+ * Wrapper around EciesMultiRecipient.decryptMultipleECIEForRecipient for backward compatibility.
263
+ */
264
+ async decryptMultipleForRecipient(encryptedData, recipientId, privateKey, senderPublicKey) {
265
+ // Create a partial IMember with only the properties needed for decryption
266
+ const member = {
267
+ id: recipientId,
268
+ privateKey: new ecies_lib_1.SecureBuffer(privateKey),
269
+ };
270
+ return this.eciesMultiRecipient.decryptMultipleECIEForRecipient(encryptedData, member, senderPublicKey);
271
+ }
272
+ /**
273
+ * Parses a multi-encrypted header.
274
+ * Wrapper around EciesMultiRecipient.parseMultiEncryptedHeader for backward compatibility.
275
+ */
276
+ parseHeader(data) {
277
+ const result = this.eciesMultiRecipient.parseMultiEncryptedHeader(data);
278
+ return result;
279
+ }
280
+ /**
281
+ * Parses a multi-encrypted buffer into its components.
282
+ * Wrapper around EciesMultiRecipient.parseMultiEncryptedBuffer for backward compatibility.
283
+ */
284
+ parseMessage(data) {
285
+ const result = this.eciesMultiRecipient.parseMultiEncryptedBuffer(data);
286
+ return result;
287
+ }
288
+ /**
289
+ * Encrypts a symmetric key for a recipient.
290
+ * Generates a new ephemeral key pair.
291
+ * Returns [EphemeralPublicKey][EncryptedKey]
292
+ */
293
+ async encryptKey(recipientPublicKey, symmetricKey) {
294
+ // Generate ephemeral key pair
295
+ const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
296
+ ecdh.generateKeys();
297
+ const ephemeralPrivateKey = ecdh.getPrivateKey();
298
+ let ephemeralPublicKey = ecdh.getPublicKey(null, 'compressed');
299
+ // Ensure public key has 0x04 prefix
300
+ if (ephemeralPublicKey.length === this.cryptoCore.consts.RAW_PUBLIC_KEY_LENGTH) {
301
+ ephemeralPublicKey = Buffer.concat([
302
+ Buffer.from([this.cryptoCore.consts.PUBLIC_KEY_MAGIC]),
303
+ ephemeralPublicKey,
304
+ ]);
305
+ }
306
+ const encryptedKey = this.eciesMultiRecipient.encryptKey(recipientPublicKey, symmetricKey, ephemeralPrivateKey, Buffer.alloc(0));
307
+ return Buffer.concat([ephemeralPublicKey, encryptedKey]);
308
+ }
309
+ /**
310
+ * Decrypts a symmetric key.
311
+ * Expects [EphemeralPublicKey][EncryptedKey]
312
+ */
313
+ async decryptKey(privateKey, encryptedData) {
314
+ // Extract ephemeral public key
315
+ // const pubKeyLength = this.cryptoCore.consts.PUBLIC_KEY_LENGTH; // 33
316
+ const ephemeralPublicKey = encryptedData.subarray(0, 33);
317
+ const encryptedKey = encryptedData.subarray(33);
318
+ return this.eciesMultiRecipient.decryptKey(privateKey, encryptedKey, ephemeralPublicKey, Buffer.alloc(0));
319
+ }
320
+ getHeaderSize(recipientCount) {
321
+ return this.eciesMultiRecipient.getHeaderSize(recipientCount);
322
+ }
323
+ }
324
+ exports.MultiRecipientProcessor = MultiRecipientProcessor;
325
+ //# sourceMappingURL=multi-recipient-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-recipient-processor.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/multi-recipient-processor.ts"],"names":[],"mappings":";;;AAAA,mCAKgB;AAEhB,0DAKoC;AAEpC,4CAAyC;AAIzC,+EAK6C;AAE7C,uCAA0C;AAE1C,6DAA8D;AAiB9D,MAAa,uBAAuB;IACjB,MAAM,CAAgB;IACtB,UAAU,CAAkB;IAC5B,MAAM,CAAkB;IACxB,mBAAmB,CAAsB;IACzC,SAAS,CAA2B;IACpC,eAAe,CAAS;IAEzC,YACE,UAA2B,EAC3B,SAA0B,qBAAS,CAAC,KAAK,EACzC,MAAsB,EACtB,mBAAyC;QAEzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,+CAA+C;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,uBAAa,EAAE,CAAC;QAC5C,IAAI,CAAC,mBAAmB;YACtB,mBAAmB,IAAI,IAAI,qCAAmB,CAAC,UAAU,CAAC,CAAC;QAC7D,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,IAAA,kDAA0B,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACpE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nB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAChB,CAAC;QAEF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,UAAU,CACrB,UAAkB,EAClB,aAAqB;QAErB,+BAA+B;QAC/B,uEAAuE;QAEvE,MAAM,kBAAkB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACzD,MAAM,YAAY,GAAG,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEhD,OAAO,IAAI,CAAC,mBAAmB,CAAC,UAAU,CACxC,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAChB,CAAC;IACJ,CAAC;IAEM,aAAa,CAAC,cAAsB;QACzC,OAAO,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAChE,CAAC;CACF;AApdD,0DAodC"}
@@ -0,0 +1,105 @@
1
+ import { IPbkdf2Config, IPBkdf2Consts, Pbkdf2ErrorType } from '@digitaldefiance/ecies-lib';
2
+ import { CoreLanguageCode } from '@digitaldefiance/i18n-lib';
3
+ import { Pbkdf2ProfileEnum } from '../enumerations/pbkdf2-profile';
4
+ import { IConstants } from '../interfaces/constants';
5
+ import { IECIESConsts } from '../interfaces/ecies-consts';
6
+ import { IPbkdf2Result } from '../interfaces/pbkdf2-result';
7
+ /**
8
+ * Custom PBKDF2 error class that works with the plugin i18n system
9
+ */
10
+ export declare class NodePbkdf2Error extends Error {
11
+ readonly type: Pbkdf2ErrorType;
12
+ constructor(message: string, type: Pbkdf2ErrorType);
13
+ }
14
+ /**
15
+ * Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
16
+ * This service provides functionality for:
17
+ * - Generating secure key derivation configurations
18
+ * - Deriving cryptographic keys from passwords
19
+ * - Managing salt and iteration parameters
20
+ * - Both synchronous and asynchronous key derivation
21
+ */
22
+ export declare class Pbkdf2Service<TLanguage extends CoreLanguageCode = CoreLanguageCode> {
23
+ protected readonly profiles: Record<string, IPbkdf2Config>;
24
+ protected readonly eciesConsts: IECIESConsts;
25
+ protected readonly pbkdf2Consts: IPBkdf2Consts;
26
+ constructor(profiles?: Record<string, IPbkdf2Config>, eciesParams?: IECIESConsts, pbkdf2Params?: IPBkdf2Consts);
27
+ /**
28
+ * Register a new PBKDF2 profile
29
+ * @param profileName The name of the profile
30
+ * @param config The configuration for the profile
31
+ */
32
+ registerProfile(profileName: string, config: IPbkdf2Config): void;
33
+ /**
34
+ * Get all registered profile names
35
+ * @returns Array of profile names
36
+ */
37
+ getRegisteredProfiles(): string[];
38
+ /**
39
+ * Check if a profile is registered
40
+ * @param profileName The name of the profile to check
41
+ * @returns True if the profile exists
42
+ */
43
+ hasProfile(profileName: string): boolean;
44
+ /**
45
+ * Create a Pbkdf2Service instance from IConstants (for backward compatibility)
46
+ * @param constants The constants object
47
+ * @returns A new Pbkdf2Service instance
48
+ */
49
+ static fromConstants(constants: IConstants): Pbkdf2Service;
50
+ /**
51
+ * Get a predefined configuration profile for common use cases
52
+ * @param profile The name of the profile to use
53
+ * @returns Configuration object for the specified profile
54
+ */
55
+ getProfileConfig(profile: string): IPbkdf2Config;
56
+ /**
57
+ * Generate an options object for pbkdf2
58
+ * @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
59
+ * @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
60
+ * @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
61
+ * @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
62
+ * @returns Configuration object for PBKDF2
63
+ */
64
+ getConfig(iterations?: number, saltBytes?: number, hashBytes?: number, algorithm?: string): IPbkdf2Config;
65
+ /**
66
+ * Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
67
+ * @param password The password to derive a key from
68
+ * @param salt Optional salt (will be randomly generated if not provided)
69
+ * @param iterations Optional number of iterations
70
+ * @param saltBytes Optional salt size in bytes
71
+ * @param keySize Optional key size in bytes
72
+ * @param algorithm Optional hash algorithm
73
+ * @returns Object containing the derived key, salt, and iteration count
74
+ */
75
+ deriveKeyFromPassword(password: Buffer, salt?: Buffer, iterations?: number, saltBytes?: number, keySize?: number, algorithm?: string): IPbkdf2Result;
76
+ /**
77
+ * Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
78
+ * to avoid blocking the event loop during password verification.
79
+ * @param password The password to derive a key from
80
+ * @param salt Optional salt (will be randomly generated if not provided)
81
+ * @param iterations Optional number of iterations
82
+ * @param saltBytes Optional salt size in bytes
83
+ * @param keySize Optional key size in bytes
84
+ * @param algorithm Optional hash algorithm
85
+ * @returns Promise resolving to object containing the derived key, salt, and iteration count
86
+ */
87
+ deriveKeyFromPasswordAsync(password: Buffer, salt?: Buffer, iterations?: number, saltBytes?: number, keySize?: number, algorithm?: string): Promise<IPbkdf2Result>;
88
+ /**
89
+ * Derive a key using a predefined configuration profile
90
+ * @param password The password to derive a key from
91
+ * @param profile The configuration profile to use
92
+ * @param salt Optional salt (will be randomly generated if not provided)
93
+ * @returns Object containing the derived key, salt, and iteration count
94
+ */
95
+ deriveKeyFromPasswordWithProfile(password: Buffer, profile: Pbkdf2ProfileEnum, salt?: Buffer): IPbkdf2Result;
96
+ /**
97
+ * Async version of deriveKeyFromPasswordWithProfile
98
+ * @param password The password to derive a key from
99
+ * @param profile The configuration profile to use
100
+ * @param salt Optional salt (will be randomly generated if not provided)
101
+ * @returns Promise resolving to object containing the derived key, salt, and iteration count
102
+ */
103
+ deriveKeyFromPasswordWithProfileAsync(password: Buffer, profile: Pbkdf2ProfileEnum, salt?: Buffer): Promise<IPbkdf2Result>;
104
+ }
105
+ //# sourceMappingURL=pbkdf2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbkdf2.d.ts","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E,MAAM,GAAG,aAAa;IAkBvD;;;;;;;OAOG;IACI,SAAS,CACd,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa;IAkBhB;;;;;;;;;OASG;IACI,qBAAqB,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa;IAqChB;;;;;;;;;;OAUG;IACU,0BAA0B,CACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAsCzB;;;;;;OAMG;IACI,gCAAgC,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,aAAa;IAYhB;;;;;;OAMG;IACU,qCAAqC,CAChD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,CAAC;CAW1B"}
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pbkdf2Service = exports.NodePbkdf2Error = void 0;
4
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
6
+ const crypto_1 = require("crypto");
7
+ const util_1 = require("util");
8
+ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
9
+ const constants_1 = require("../constants");
10
+ const ecies_i18n_factory_1 = require("../i18n/ecies-i18n-factory");
11
+ /**
12
+ * Custom PBKDF2 error class that works with the plugin i18n system
13
+ */
14
+ class NodePbkdf2Error extends Error {
15
+ type;
16
+ constructor(message, type) {
17
+ super(message);
18
+ this.type = type;
19
+ this.name = 'NodePbkdf2Error';
20
+ }
21
+ }
22
+ exports.NodePbkdf2Error = NodePbkdf2Error;
23
+ /**
24
+ * Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
25
+ * This service provides functionality for:
26
+ * - Generating secure key derivation configurations
27
+ * - Deriving cryptographic keys from passwords
28
+ * - Managing salt and iteration parameters
29
+ * - Both synchronous and asynchronous key derivation
30
+ */
31
+ class Pbkdf2Service {
32
+ profiles;
33
+ eciesConsts;
34
+ pbkdf2Consts;
35
+ constructor(profiles = constants_1.Constants.PBKDF2_PROFILES, eciesParams = constants_1.Constants.ECIES, pbkdf2Params = constants_1.Constants.PBKDF2) {
36
+ this.profiles = profiles;
37
+ this.eciesConsts = eciesParams;
38
+ this.pbkdf2Consts = pbkdf2Params;
39
+ }
40
+ /**
41
+ * Register a new PBKDF2 profile
42
+ * @param profileName The name of the profile
43
+ * @param config The configuration for the profile
44
+ */
45
+ registerProfile(profileName, config) {
46
+ this.profiles[profileName] = { ...config };
47
+ }
48
+ /**
49
+ * Get all registered profile names
50
+ * @returns Array of profile names
51
+ */
52
+ getRegisteredProfiles() {
53
+ return Object.keys(this.profiles);
54
+ }
55
+ /**
56
+ * Check if a profile is registered
57
+ * @param profileName The name of the profile to check
58
+ * @returns True if the profile exists
59
+ */
60
+ hasProfile(profileName) {
61
+ return profileName in this.profiles;
62
+ }
63
+ /**
64
+ * Create a Pbkdf2Service instance from IConstants (for backward compatibility)
65
+ * @param constants The constants object
66
+ * @returns A new Pbkdf2Service instance
67
+ */
68
+ static fromConstants(constants) {
69
+ return new Pbkdf2Service(constants.PBKDF2_PROFILES, constants.ECIES, constants.PBKDF2);
70
+ }
71
+ /**
72
+ * Get a predefined configuration profile for common use cases
73
+ * @param profile The name of the profile to use
74
+ * @returns Configuration object for the specified profile
75
+ */
76
+ getProfileConfig(profile) {
77
+ const profileConfig = this.profiles[profile];
78
+ if (!profileConfig) {
79
+ throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidProfile);
80
+ }
81
+ return {
82
+ hashBytes: profileConfig.hashBytes,
83
+ saltBytes: profileConfig.saltBytes,
84
+ iterations: profileConfig.iterations,
85
+ algorithm: profileConfig.algorithm,
86
+ };
87
+ }
88
+ /**
89
+ * Generate an options object for pbkdf2
90
+ * @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
91
+ * @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
92
+ * @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
93
+ * @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
94
+ * @returns Configuration object for PBKDF2
95
+ */
96
+ getConfig(iterations, saltBytes, hashBytes, algorithm) {
97
+ // larger numbers mean better security, less
98
+ return {
99
+ // size of the generated hash
100
+ hashBytes: hashBytes ?? this.eciesConsts.SYMMETRIC.KEY_SIZE,
101
+ // larger salt means hashed passwords are more resistant to rainbow table, but
102
+ // you get diminishing returns pretty fast
103
+ saltBytes: saltBytes ?? this.pbkdf2Consts.SALT_BYTES,
104
+ // more iterations means an attacker has to take longer to brute force an
105
+ // individual password, so larger is better. however, larger also means longer
106
+ // to hash the password. tune so that hashing the password takes about a
107
+ // second
108
+ iterations: iterations ?? this.pbkdf2Consts.ITERATIONS_PER_SECOND,
109
+ // hash algorithm
110
+ algorithm: algorithm ?? this.pbkdf2Consts.ALGORITHM,
111
+ };
112
+ }
113
+ /**
114
+ * Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
115
+ * @param password The password to derive a key from
116
+ * @param salt Optional salt (will be randomly generated if not provided)
117
+ * @param iterations Optional number of iterations
118
+ * @param saltBytes Optional salt size in bytes
119
+ * @param keySize Optional key size in bytes
120
+ * @param algorithm Optional hash algorithm
121
+ * @returns Object containing the derived key, salt, and iteration count
122
+ */
123
+ deriveKeyFromPassword(password, salt, iterations, saltBytes, keySize, algorithm) {
124
+ const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
125
+ const saltBytes_ = salt ?? (0, crypto_1.randomBytes)(config.saltBytes);
126
+ if (saltBytes_.length !== config.saltBytes) {
127
+ throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidSaltLength);
128
+ }
129
+ const hashBytes = (0, crypto_1.pbkdf2Sync)(password, saltBytes_, config.iterations, config.hashBytes, config.algorithm);
130
+ if (hashBytes.length !== config.hashBytes) {
131
+ throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength), ecies_lib_1.Pbkdf2ErrorType.InvalidHashLength);
132
+ }
133
+ return {
134
+ salt: saltBytes_,
135
+ hash: hashBytes,
136
+ iterations: config.iterations,
137
+ };
138
+ }
139
+ /**
140
+ * Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
141
+ * to avoid blocking the event loop during password verification.
142
+ * @param password The password to derive a key from
143
+ * @param salt Optional salt (will be randomly generated if not provided)
144
+ * @param iterations Optional number of iterations
145
+ * @param saltBytes Optional salt size in bytes
146
+ * @param keySize Optional key size in bytes
147
+ * @param algorithm Optional hash algorithm
148
+ * @returns Promise resolving to object containing the derived key, salt, and iteration count
149
+ */
150
+ async deriveKeyFromPasswordAsync(password, salt, iterations, saltBytes, keySize, algorithm) {
151
+ const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
152
+ const saltBytes_ = salt ?? (0, crypto_1.randomBytes)(config.saltBytes);
153
+ if (saltBytes_.length !== config.saltBytes) {
154
+ throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidSaltLength);
155
+ }
156
+ const pbkdf2 = (0, util_1.promisify)(crypto_1.pbkdf2);
157
+ const hashBytes = (await pbkdf2(password, saltBytes_, config.iterations, config.hashBytes, config.algorithm));
158
+ if (hashBytes.length !== config.hashBytes) {
159
+ throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength), ecies_lib_1.Pbkdf2ErrorType.InvalidHashLength);
160
+ }
161
+ return {
162
+ salt: saltBytes_,
163
+ hash: hashBytes,
164
+ iterations: config.iterations,
165
+ };
166
+ }
167
+ /**
168
+ * Derive a key using a predefined configuration profile
169
+ * @param password The password to derive a key from
170
+ * @param profile The configuration profile to use
171
+ * @param salt Optional salt (will be randomly generated if not provided)
172
+ * @returns Object containing the derived key, salt, and iteration count
173
+ */
174
+ deriveKeyFromPasswordWithProfile(password, profile, salt) {
175
+ const config = this.getProfileConfig(profile);
176
+ return this.deriveKeyFromPassword(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
177
+ }
178
+ /**
179
+ * Async version of deriveKeyFromPasswordWithProfile
180
+ * @param password The password to derive a key from
181
+ * @param profile The configuration profile to use
182
+ * @param salt Optional salt (will be randomly generated if not provided)
183
+ * @returns Promise resolving to object containing the derived key, salt, and iteration count
184
+ */
185
+ async deriveKeyFromPasswordWithProfileAsync(password, profile, salt) {
186
+ const config = this.getProfileConfig(profile);
187
+ return this.deriveKeyFromPasswordAsync(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
188
+ }
189
+ }
190
+ exports.Pbkdf2Service = Pbkdf2Service;
191
+ //# sourceMappingUR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