@digitaldefiance/node-ecies-lib 4.4.9 → 4.4.10

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 (385) hide show
  1. package/package.json +6 -5
  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.ts → index.d.ts} +1 -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 +183 -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.ts → index.d.ts} +1 -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 +2 -0
  31. package/src/enumerations/index.d.ts.map +1 -0
  32. package/src/enumerations/index.js +5 -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/i18n/ecies-i18n-factory.d.ts +28 -0
  39. package/src/i18n/ecies-i18n-factory.d.ts.map +1 -0
  40. package/src/i18n/ecies-i18n-factory.js +89 -0
  41. package/src/i18n/ecies-i18n-factory.js.map +1 -0
  42. package/src/i18n/{index.ts → index.d.ts} +1 -3
  43. package/src/i18n/index.d.ts.map +1 -0
  44. package/src/i18n/index.js +8 -0
  45. package/src/i18n/index.js.map +1 -0
  46. package/src/i18n/node-ecies-i18n-setup.d.ts +5 -0
  47. package/src/i18n/node-ecies-i18n-setup.d.ts.map +1 -0
  48. package/src/i18n/node-ecies-i18n-setup.js +46 -0
  49. package/src/i18n/node-ecies-i18n-setup.js.map +1 -0
  50. package/src/i18n/node-keys.d.ts +57 -0
  51. package/src/i18n/node-keys.d.ts.map +1 -0
  52. package/src/i18n/node-keys.js +67 -0
  53. package/src/i18n/node-keys.js.map +1 -0
  54. package/src/i18n/translations/de.d.ts +3 -0
  55. package/src/i18n/translations/de.d.ts.map +1 -0
  56. package/src/i18n/translations/de.js +57 -0
  57. package/src/i18n/translations/de.js.map +1 -0
  58. package/src/i18n/translations/en-GB.d.ts +3 -0
  59. package/src/i18n/translations/en-GB.d.ts.map +1 -0
  60. package/src/i18n/translations/en-GB.js +61 -0
  61. package/src/i18n/translations/en-GB.js.map +1 -0
  62. package/src/i18n/translations/en-US.d.ts +6 -0
  63. package/src/i18n/translations/en-US.d.ts.map +1 -0
  64. package/src/i18n/translations/en-US.js +65 -0
  65. package/src/i18n/translations/en-US.js.map +1 -0
  66. package/src/i18n/translations/es.d.ts +3 -0
  67. package/src/i18n/translations/es.d.ts.map +1 -0
  68. package/src/i18n/translations/es.js +57 -0
  69. package/src/i18n/translations/es.js.map +1 -0
  70. package/src/i18n/translations/fr.d.ts +3 -0
  71. package/src/i18n/translations/fr.d.ts.map +1 -0
  72. package/src/i18n/translations/fr.js +57 -0
  73. package/src/i18n/translations/fr.js.map +1 -0
  74. package/src/i18n/translations/{index.ts → index.d.ts} +1 -0
  75. package/src/i18n/translations/index.d.ts.map +1 -0
  76. package/src/i18n/translations/index.js +20 -0
  77. package/src/i18n/translations/index.js.map +1 -0
  78. package/src/i18n/translations/ja.d.ts +3 -0
  79. package/src/i18n/translations/ja.d.ts.map +1 -0
  80. package/src/i18n/translations/ja.js +57 -0
  81. package/src/i18n/translations/ja.js.map +1 -0
  82. package/src/i18n/translations/uk.d.ts +3 -0
  83. package/src/i18n/translations/uk.d.ts.map +1 -0
  84. package/src/i18n/translations/uk.js +57 -0
  85. package/src/i18n/translations/uk.js.map +1 -0
  86. package/src/i18n/translations/zh-cn.d.ts +3 -0
  87. package/src/i18n/translations/zh-cn.d.ts.map +1 -0
  88. package/src/i18n/translations/zh-cn.js +57 -0
  89. package/src/i18n/translations/zh-cn.js.map +1 -0
  90. package/src/{index.ts → index.d.ts} +1 -5
  91. package/src/index.d.ts.map +1 -0
  92. package/src/index.js +31 -0
  93. package/src/index.js.map +1 -0
  94. package/src/interfaces/authenticated-cipher.d.ts +12 -0
  95. package/src/interfaces/authenticated-cipher.d.ts.map +1 -0
  96. package/src/interfaces/authenticated-cipher.js +3 -0
  97. package/src/interfaces/authenticated-cipher.js.map +1 -0
  98. package/src/interfaces/authenticated-decipher.d.ts +11 -0
  99. package/src/interfaces/authenticated-decipher.d.ts.map +1 -0
  100. package/src/interfaces/authenticated-decipher.js +3 -0
  101. package/src/interfaces/authenticated-decipher.js.map +1 -0
  102. package/src/interfaces/backend-member-operational.d.ts +48 -0
  103. package/src/interfaces/backend-member-operational.d.ts.map +1 -0
  104. package/src/interfaces/backend-member-operational.js +3 -0
  105. package/src/interfaces/backend-member-operational.js.map +1 -0
  106. package/src/interfaces/checksum-config.d.ts +5 -0
  107. package/src/interfaces/checksum-config.d.ts.map +1 -0
  108. package/src/interfaces/checksum-config.js +3 -0
  109. package/src/interfaces/checksum-config.js.map +1 -0
  110. package/src/interfaces/checksum-consts.d.ts +11 -0
  111. package/src/interfaces/checksum-consts.d.ts.map +1 -0
  112. package/src/interfaces/checksum-consts.js +3 -0
  113. package/src/interfaces/checksum-consts.js.map +1 -0
  114. package/src/interfaces/constants.d.ts +52 -0
  115. package/src/interfaces/constants.d.ts.map +1 -0
  116. package/src/interfaces/constants.js +3 -0
  117. package/src/interfaces/constants.js.map +1 -0
  118. package/src/interfaces/ecies-consts.d.ts +88 -0
  119. package/src/interfaces/ecies-consts.d.ts.map +1 -0
  120. package/src/interfaces/ecies-consts.js +3 -0
  121. package/src/interfaces/ecies-consts.js.map +1 -0
  122. package/src/interfaces/encrypted-chunk.d.ts +12 -0
  123. package/src/interfaces/encrypted-chunk.d.ts.map +1 -0
  124. package/src/interfaces/encrypted-chunk.js +3 -0
  125. package/src/interfaces/encrypted-chunk.js.map +1 -0
  126. package/src/interfaces/encryption-consts.d.ts +11 -0
  127. package/src/interfaces/encryption-consts.d.ts.map +1 -0
  128. package/src/interfaces/encryption-consts.js +3 -0
  129. package/src/interfaces/encryption-consts.js.map +1 -0
  130. package/src/interfaces/{index.ts → index.d.ts} +1 -0
  131. package/src/interfaces/index.d.ts.map +1 -0
  132. package/src/interfaces/index.js +30 -0
  133. package/src/interfaces/index.js.map +1 -0
  134. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
  135. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
  136. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js +3 -0
  137. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
  138. package/src/interfaces/keyring-consts.d.ts +6 -0
  139. package/src/interfaces/keyring-consts.d.ts.map +1 -0
  140. package/src/interfaces/keyring-consts.js +3 -0
  141. package/src/interfaces/keyring-consts.js.map +1 -0
  142. package/src/interfaces/{member-with-mnemonic.ts → member-with-mnemonic.d.ts} +3 -3
  143. package/src/interfaces/member-with-mnemonic.d.ts.map +1 -0
  144. package/src/interfaces/member-with-mnemonic.js +3 -0
  145. package/src/interfaces/member-with-mnemonic.js.map +1 -0
  146. package/src/interfaces/member.d.ts +47 -0
  147. package/src/interfaces/member.d.ts.map +1 -0
  148. package/src/interfaces/member.js +3 -0
  149. package/src/interfaces/member.js.map +1 -0
  150. package/src/interfaces/{multi-encrypted-message.ts → multi-encrypted-message.d.ts} +5 -5
  151. package/src/interfaces/multi-encrypted-message.d.ts.map +1 -0
  152. package/src/interfaces/multi-encrypted-message.js +3 -0
  153. package/src/interfaces/multi-encrypted-message.js.map +1 -0
  154. package/src/interfaces/multi-encrypted-parsed-header.d.ts +27 -0
  155. package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
  156. package/src/interfaces/multi-encrypted-parsed-header.js +3 -0
  157. package/src/interfaces/multi-encrypted-parsed-header.js.map +1 -0
  158. package/src/interfaces/multi-recipient-chunk.d.ts +26 -0
  159. package/src/interfaces/multi-recipient-chunk.d.ts.map +1 -0
  160. package/src/interfaces/multi-recipient-chunk.js +13 -0
  161. package/src/interfaces/multi-recipient-chunk.js.map +1 -0
  162. package/src/interfaces/{pbkdf-profiles.ts → pbkdf-profiles.d.ts} +2 -2
  163. package/src/interfaces/pbkdf-profiles.d.ts.map +1 -0
  164. package/src/interfaces/pbkdf-profiles.js +3 -0
  165. package/src/interfaces/pbkdf-profiles.js.map +1 -0
  166. package/src/interfaces/pbkdf2-result.d.ts +6 -0
  167. package/src/interfaces/pbkdf2-result.d.ts.map +1 -0
  168. package/src/interfaces/pbkdf2-result.js +3 -0
  169. package/src/interfaces/pbkdf2-result.js.map +1 -0
  170. package/src/interfaces/signing-key-private-key-info.d.ts +11 -0
  171. package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -0
  172. package/src/interfaces/signing-key-private-key-info.js +3 -0
  173. package/src/interfaces/signing-key-private-key-info.js.map +1 -0
  174. package/src/interfaces/{simple-keypair-buffer.ts → simple-keypair-buffer.d.ts} +3 -3
  175. package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -0
  176. package/src/interfaces/simple-keypair-buffer.js +3 -0
  177. package/src/interfaces/simple-keypair-buffer.js.map +1 -0
  178. package/src/interfaces/{simple-keypair.ts → simple-keypair.d.ts} +3 -3
  179. package/src/interfaces/simple-keypair.d.ts.map +1 -0
  180. package/src/interfaces/simple-keypair.js +3 -0
  181. package/src/interfaces/simple-keypair.js.map +1 -0
  182. package/src/interfaces/simple-public-key-only-buffer.d.ts +4 -0
  183. package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
  184. package/src/interfaces/simple-public-key-only-buffer.js +3 -0
  185. package/src/interfaces/simple-public-key-only-buffer.js.map +1 -0
  186. package/src/interfaces/simple-public-key-only.d.ts +4 -0
  187. package/src/interfaces/simple-public-key-only.d.ts.map +1 -0
  188. package/src/interfaces/simple-public-key-only.js +3 -0
  189. package/src/interfaces/simple-public-key-only.js.map +1 -0
  190. package/src/interfaces/single-encrypted-parsed-header.d.ts +35 -0
  191. package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
  192. package/src/interfaces/single-encrypted-parsed-header.js +3 -0
  193. package/src/interfaces/single-encrypted-parsed-header.js.map +1 -0
  194. package/src/interfaces/stream-config.d.ts +6 -0
  195. package/src/interfaces/stream-config.d.ts.map +1 -0
  196. package/src/interfaces/stream-config.js +8 -0
  197. package/src/interfaces/stream-config.js.map +1 -0
  198. package/src/interfaces/stream-progress.d.ts +8 -0
  199. package/src/interfaces/stream-progress.d.ts.map +1 -0
  200. package/src/interfaces/stream-progress.js +3 -0
  201. package/src/interfaces/stream-progress.js.map +1 -0
  202. package/src/interfaces/{wallet-seed.ts → wallet-seed.d.ts} +3 -3
  203. package/src/interfaces/wallet-seed.d.ts.map +1 -0
  204. package/src/interfaces/wallet-seed.js +3 -0
  205. package/src/interfaces/wallet-seed.js.map +1 -0
  206. package/src/interfaces/wrapped-key-consts.d.ts +7 -0
  207. package/src/interfaces/wrapped-key-consts.d.ts.map +1 -0
  208. package/src/interfaces/wrapped-key-consts.js +3 -0
  209. package/src/interfaces/wrapped-key-consts.js.map +1 -0
  210. package/src/lib/crypto-container.d.ts +13 -0
  211. package/src/lib/crypto-container.d.ts.map +1 -0
  212. package/src/lib/crypto-container.js +29 -0
  213. package/src/lib/crypto-container.js.map +1 -0
  214. package/src/lib/{index.ts → index.d.ts} +1 -0
  215. package/src/lib/index.d.ts.map +1 -0
  216. package/src/lib/index.js +7 -0
  217. package/src/lib/index.js.map +1 -0
  218. package/src/lib/invariant-validator.d.ts +62 -0
  219. package/src/lib/invariant-validator.d.ts.map +1 -0
  220. package/src/lib/invariant-validator.js +108 -0
  221. package/src/lib/invariant-validator.js.map +1 -0
  222. package/src/lib/invariants/{index.ts → index.d.ts} +2 -2
  223. package/src/lib/invariants/index.d.ts.map +1 -0
  224. package/src/lib/invariants/index.js +12 -0
  225. package/src/lib/invariants/index.js.map +1 -0
  226. package/src/lib/invariants/recipient-id-consistency.d.ts +22 -0
  227. package/src/lib/invariants/recipient-id-consistency.d.ts.map +1 -0
  228. package/src/lib/invariants/recipient-id-consistency.js +62 -0
  229. package/src/lib/invariants/recipient-id-consistency.js.map +1 -0
  230. package/src/member.d.ts +81 -0
  231. package/src/member.d.ts.map +1 -0
  232. package/src/member.js +285 -0
  233. package/src/member.js.map +1 -0
  234. package/src/services/aes-gcm.d.ts +66 -0
  235. package/src/services/aes-gcm.d.ts.map +1 -0
  236. package/src/services/aes-gcm.js +158 -0
  237. package/src/services/aes-gcm.js.map +1 -0
  238. package/src/services/chunk-processor.d.ts +15 -0
  239. package/src/services/chunk-processor.d.ts.map +1 -0
  240. package/src/services/chunk-processor.js +36 -0
  241. package/src/services/chunk-processor.js.map +1 -0
  242. package/src/services/ecies/crypto-core.d.ts +104 -0
  243. package/src/services/ecies/crypto-core.d.ts.map +1 -0
  244. package/src/services/ecies/crypto-core.js +237 -0
  245. package/src/services/ecies/crypto-core.js.map +1 -0
  246. package/src/services/ecies/file.d.ts +30 -0
  247. package/src/services/ecies/file.d.ts.map +1 -0
  248. package/src/services/ecies/file.js +112 -0
  249. package/src/services/ecies/file.js.map +1 -0
  250. package/src/services/ecies/{index.ts → index.d.ts} +1 -0
  251. package/src/services/ecies/index.d.ts.map +1 -0
  252. package/src/services/ecies/index.js +11 -0
  253. package/src/services/ecies/index.js.map +1 -0
  254. package/src/services/ecies/multi-recipient.d.ts +84 -0
  255. package/src/services/ecies/multi-recipient.d.ts.map +1 -0
  256. package/src/services/ecies/multi-recipient.js +496 -0
  257. package/src/services/ecies/multi-recipient.js.map +1 -0
  258. package/src/services/ecies/service.d.ts +69 -0
  259. package/src/services/ecies/service.d.ts.map +1 -0
  260. package/src/services/ecies/service.js +144 -0
  261. package/src/services/ecies/service.js.map +1 -0
  262. package/src/services/ecies/signature.d.ts +38 -0
  263. package/src/services/ecies/signature.d.ts.map +1 -0
  264. package/src/services/ecies/signature.js +69 -0
  265. package/src/services/ecies/signature.js.map +1 -0
  266. package/src/services/ecies/single-recipient.d.ts +83 -0
  267. package/src/services/ecies/single-recipient.d.ts.map +1 -0
  268. package/src/services/ecies/single-recipient.js +447 -0
  269. package/src/services/ecies/single-recipient.js.map +1 -0
  270. package/src/services/ecies/utilities.d.ts +33 -0
  271. package/src/services/ecies/utilities.d.ts.map +1 -0
  272. package/src/services/ecies/utilities.js +91 -0
  273. package/src/services/ecies/utilities.js.map +1 -0
  274. package/src/services/encryption-stream.d.ts +33 -0
  275. package/src/services/encryption-stream.d.ts.map +1 -0
  276. package/src/services/encryption-stream.js +207 -0
  277. package/src/services/encryption-stream.js.map +1 -0
  278. package/src/services/{index.ts → index.d.ts} +1 -0
  279. package/src/services/index.d.ts.map +1 -0
  280. package/src/services/index.js +11 -0
  281. package/src/services/index.js.map +1 -0
  282. package/src/services/multi-recipient-processor.d.ts +72 -0
  283. package/src/services/multi-recipient-processor.d.ts.map +1 -0
  284. package/src/services/multi-recipient-processor.js +322 -0
  285. package/src/services/multi-recipient-processor.js.map +1 -0
  286. package/src/services/pbkdf2.d.ts +105 -0
  287. package/src/services/pbkdf2.d.ts.map +1 -0
  288. package/src/services/pbkdf2.js +189 -0
  289. package/src/services/pbkdf2.js.map +1 -0
  290. package/src/services/progress-tracker.d.ts +9 -0
  291. package/src/services/progress-tracker.d.ts.map +1 -0
  292. package/src/services/progress-tracker.js +41 -0
  293. package/src/services/progress-tracker.js.map +1 -0
  294. package/src/test-mocks/index.d.ts +2 -0
  295. package/src/test-mocks/index.d.ts.map +1 -0
  296. package/src/test-mocks/index.js +5 -0
  297. package/src/test-mocks/index.js.map +1 -0
  298. package/src/test-mocks/mock-backend-member.d.ts +71 -0
  299. package/src/test-mocks/mock-backend-member.d.ts.map +1 -0
  300. package/src/test-mocks/mock-backend-member.js +133 -0
  301. package/src/test-mocks/mock-backend-member.js.map +1 -0
  302. package/src/testing.d.ts +2 -0
  303. package/src/testing.d.ts.map +1 -0
  304. package/src/testing.js +6 -0
  305. package/src/testing.js.map +1 -0
  306. package/src/types/id-guards.d.ts +39 -0
  307. package/src/types/id-guards.d.ts.map +1 -0
  308. package/src/types/id-guards.js +91 -0
  309. package/src/types/id-guards.js.map +1 -0
  310. package/src/types/index.d.ts +2 -0
  311. package/src/types/index.d.ts.map +1 -0
  312. package/src/types/index.js +5 -0
  313. package/src/types/index.js.map +1 -0
  314. package/src/{types.ts → types.d.ts} +9 -28
  315. package/src/types.d.ts.map +1 -0
  316. package/src/types.js +6 -0
  317. package/src/types.js.map +1 -0
  318. package/src/utils.d.ts +11 -0
  319. package/src/utils.d.ts.map +1 -0
  320. package/src/utils.js +82 -0
  321. package/src/utils.js.map +1 -0
  322. package/LICENSE +0 -21
  323. package/src/builders/ecies-builder.ts +0 -27
  324. package/src/builders/member-builder.ts +0 -158
  325. package/src/constants.ts +0 -251
  326. package/src/core/errors/crypto-error.ts +0 -10
  327. package/src/core/types/result.ts +0 -3
  328. package/src/enumerations/index.ts +0 -2
  329. package/src/enumerations/pbkdf2-profile.ts +0 -8
  330. package/src/i18n/ecies-i18n-factory.ts +0 -111
  331. package/src/i18n/node-ecies-i18n-setup.ts +0 -56
  332. package/src/i18n/node-keys.ts +0 -69
  333. package/src/i18n/translations/de.ts +0 -54
  334. package/src/i18n/translations/en-GB.ts +0 -83
  335. package/src/i18n/translations/en-US.ts +0 -88
  336. package/src/i18n/translations/es.ts +0 -54
  337. package/src/i18n/translations/fr.ts +0 -54
  338. package/src/i18n/translations/ja.ts +0 -54
  339. package/src/i18n/translations/uk.ts +0 -54
  340. package/src/i18n/translations/zh-cn.ts +0 -54
  341. package/src/interfaces/authenticated-cipher.ts +0 -10
  342. package/src/interfaces/authenticated-decipher.ts +0 -9
  343. package/src/interfaces/backend-member-operational.ts +0 -75
  344. package/src/interfaces/checksum-config.ts +0 -4
  345. package/src/interfaces/checksum-consts.ts +0 -13
  346. package/src/interfaces/constants.ts +0 -54
  347. package/src/interfaces/ecies-consts.ts +0 -99
  348. package/src/interfaces/encrypted-chunk.ts +0 -12
  349. package/src/interfaces/encryption-consts.ts +0 -10
  350. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +0 -7
  351. package/src/interfaces/keyring-consts.ts +0 -5
  352. package/src/interfaces/member.ts +0 -76
  353. package/src/interfaces/multi-encrypted-parsed-header.ts +0 -28
  354. package/src/interfaces/multi-recipient-chunk.ts +0 -35
  355. package/src/interfaces/pbkdf2-result.ts +0 -5
  356. package/src/interfaces/signing-key-private-key-info.ts +0 -12
  357. package/src/interfaces/simple-public-key-only-buffer.ts +0 -3
  358. package/src/interfaces/simple-public-key-only.ts +0 -3
  359. package/src/interfaces/single-encrypted-parsed-header.ts +0 -35
  360. package/src/interfaces/stream-config.ts +0 -9
  361. package/src/interfaces/stream-progress.ts +0 -7
  362. package/src/interfaces/wrapped-key-consts.ts +0 -6
  363. package/src/lib/crypto-container.ts +0 -32
  364. package/src/lib/invariant-validator.ts +0 -124
  365. package/src/lib/invariants/recipient-id-consistency.ts +0 -77
  366. package/src/member.ts +0 -511
  367. package/src/services/aes-gcm.ts +0 -260
  368. package/src/services/chunk-processor.ts +0 -47
  369. package/src/services/ecies/crypto-core.ts +0 -319
  370. package/src/services/ecies/file.ts +0 -171
  371. package/src/services/ecies/multi-recipient.ts +0 -782
  372. package/src/services/ecies/service.ts +0 -316
  373. package/src/services/ecies/signature.ts +0 -91
  374. package/src/services/ecies/single-recipient.ts +0 -743
  375. package/src/services/ecies/utilities.ts +0 -128
  376. package/src/services/encryption-stream.ts +0 -432
  377. package/src/services/multi-recipient-processor.ts +0 -505
  378. package/src/services/pbkdf2.ts +0 -304
  379. package/src/services/progress-tracker.ts +0 -43
  380. package/src/test-mocks/index.ts +0 -1
  381. package/src/test-mocks/mock-backend-member.ts +0 -195
  382. package/src/testing.ts +0 -2
  383. package/src/types/id-guards.ts +0 -91
  384. package/src/types/index.ts +0 -1
  385. package/src/utils.ts +0 -124
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptionStream = void 0;
4
+ const ecies_i18n_factory_1 = require("../i18n/ecies-i18n-factory");
5
+ const node_ecies_i18n_setup_1 = require("../i18n/node-ecies-i18n-setup");
6
+ const stream_config_1 = require("../interfaces/stream-config");
7
+ const chunk_processor_1 = require("./chunk-processor");
8
+ const multi_recipient_processor_1 = require("./multi-recipient-processor");
9
+ const progress_tracker_1 = require("./progress-tracker");
10
+ class EncryptionStream {
11
+ ecies;
12
+ config;
13
+ processor;
14
+ multiRecipientProcessor;
15
+ engine = (0, node_ecies_i18n_setup_1.getNodeEciesI18nEngine)();
16
+ constructor(ecies, config = stream_config_1.DEFAULT_STREAM_CONFIG, processor, multiRecipientProcessor) {
17
+ this.ecies = ecies;
18
+ this.config = config;
19
+ // Use injected dependencies or create defaults
20
+ this.processor = processor ?? new chunk_processor_1.ChunkProcessor(ecies);
21
+ this.multiRecipientProcessor =
22
+ multiRecipientProcessor ??
23
+ new multi_recipient_processor_1.MultiRecipientProcessor(ecies.core, ecies.core.consts);
24
+ }
25
+ async *encryptStream(source, publicKey, options = {}) {
26
+ if (!publicKey || (publicKey.length !== 65 && publicKey.length !== 33)) {
27
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_InvalidPublicKeyLength));
28
+ }
29
+ const chunkSize = options.chunkSize ?? this.config.chunkSize;
30
+ const includeChecksums = options.includeChecksums ?? this.config.includeChecksums;
31
+ const signal = options.signal;
32
+ const onProgress = options.onProgress;
33
+ let buffer = Buffer.alloc(0);
34
+ let chunkIndex = 0;
35
+ let lastYieldedChunk = null;
36
+ let tracker;
37
+ const maxSingleChunk = 100 * 1024 * 1024;
38
+ for await (const data of source) {
39
+ if (signal?.aborted) {
40
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_EncryptionCancelled));
41
+ }
42
+ if (data.length > maxSingleChunk) {
43
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_BufferOverflow));
44
+ }
45
+ buffer = Buffer.concat([buffer, data]);
46
+ if (!tracker && onProgress) {
47
+ tracker = new progress_tracker_1.ProgressTracker();
48
+ }
49
+ while (buffer.length >= chunkSize) {
50
+ if (signal?.aborted) {
51
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_EncryptionCancelled));
52
+ }
53
+ const chunkData = buffer.subarray(0, chunkSize);
54
+ buffer = buffer.subarray(chunkSize);
55
+ const encryptedChunk = await this.processor.encryptChunk(chunkData, publicKey, chunkIndex++, false, includeChecksums);
56
+ lastYieldedChunk = encryptedChunk;
57
+ yield encryptedChunk;
58
+ if (tracker && onProgress) {
59
+ onProgress(tracker.update(chunkSize));
60
+ }
61
+ }
62
+ }
63
+ if (buffer.length > 0) {
64
+ if (signal?.aborted) {
65
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_EncryptionCancelled));
66
+ }
67
+ const encryptedChunk = await this.processor.encryptChunk(buffer, publicKey, chunkIndex, true, includeChecksums);
68
+ yield encryptedChunk;
69
+ if (tracker && onProgress) {
70
+ onProgress(tracker.update(buffer.length));
71
+ }
72
+ }
73
+ else if (chunkIndex === 0) {
74
+ return;
75
+ }
76
+ else if (lastYieldedChunk) {
77
+ lastYieldedChunk.isLast = true;
78
+ }
79
+ }
80
+ async *encryptStreamMultiple(source, recipients, options = {}) {
81
+ if (recipients.length === 0) {
82
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_AtLeastOneRecipientRequired));
83
+ }
84
+ if (recipients.length > 65535) {
85
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_MaxRecipientsExceeded));
86
+ }
87
+ for (const recipient of recipients) {
88
+ if (!recipient.publicKey ||
89
+ (recipient.publicKey.length !== 65 && recipient.publicKey.length !== 33)) {
90
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_InvalidRecipientPublicKeyLength));
91
+ }
92
+ if (!recipient.id ||
93
+ recipient.id.length !==
94
+ this.ecies.core.consts.MULTIPLE.RECIPIENT_ID_SIZE) {
95
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_InvalidRecipientIdLength));
96
+ }
97
+ }
98
+ const chunkSize = options.chunkSize ?? this.config.chunkSize;
99
+ const signal = options.signal;
100
+ const onProgress = options.onProgress;
101
+ const symmetricKey = Buffer.from(require('crypto').randomBytes(32));
102
+ let buffer = Buffer.alloc(0);
103
+ let chunkIndex = 0;
104
+ let tracker;
105
+ const maxSingleChunk = 100 * 1024 * 1024;
106
+ for await (const data of source) {
107
+ if (signal?.aborted) {
108
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_EncryptionCancelled));
109
+ }
110
+ if (data.length > maxSingleChunk) {
111
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_BufferOverflow));
112
+ }
113
+ buffer = Buffer.concat([buffer, data]);
114
+ if (!tracker && onProgress) {
115
+ tracker = new progress_tracker_1.ProgressTracker();
116
+ }
117
+ while (buffer.length >= chunkSize) {
118
+ if (signal?.aborted) {
119
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_EncryptionCancelled));
120
+ }
121
+ const chunkData = buffer.subarray(0, chunkSize);
122
+ buffer = buffer.subarray(chunkSize);
123
+ const encryptedChunk = await this.multiRecipientProcessor.encryptChunk(chunkData, recipients, chunkIndex++, false, symmetricKey);
124
+ yield encryptedChunk;
125
+ if (tracker && onProgress) {
126
+ onProgress(tracker.update(chunkSize));
127
+ }
128
+ }
129
+ }
130
+ if (buffer.length > 0) {
131
+ if (signal?.aborted) {
132
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_EncryptionCancelled));
133
+ }
134
+ const encryptedChunk = await this.multiRecipientProcessor.encryptChunk(buffer, recipients, chunkIndex, true, symmetricKey);
135
+ yield encryptedChunk;
136
+ if (tracker && onProgress) {
137
+ onProgress(tracker.update(buffer.length));
138
+ }
139
+ }
140
+ }
141
+ async *decryptStream(source, privateKey, options = {}) {
142
+ if (!privateKey || privateKey.length !== 32) {
143
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_InvalidPrivateKeyLength));
144
+ }
145
+ const signal = options.signal;
146
+ const onProgress = options.onProgress;
147
+ let expectedIndex = 0;
148
+ let tracker;
149
+ if (onProgress) {
150
+ tracker = new progress_tracker_1.ProgressTracker();
151
+ }
152
+ for await (const chunkData of source) {
153
+ if (signal?.aborted) {
154
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_DecryptionCancelled));
155
+ }
156
+ const { data, header } = await this.processor.decryptChunk(chunkData, privateKey);
157
+ if (header.index !== expectedIndex) {
158
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_ChunkSequenceError));
159
+ }
160
+ expectedIndex++;
161
+ yield data;
162
+ if (tracker && onProgress) {
163
+ onProgress(tracker.update(data.length));
164
+ }
165
+ const isLast = (header.flags & 0x01) !== 0;
166
+ if (isLast) {
167
+ break;
168
+ }
169
+ }
170
+ }
171
+ async *decryptStreamMultiple(source, recipientId, privateKey, options = {}) {
172
+ if (!recipientId ||
173
+ recipientId.length !== this.ecies.core.consts.MULTIPLE.RECIPIENT_ID_SIZE) {
174
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_InvalidRecipientIdLength));
175
+ }
176
+ if (!privateKey || privateKey.length !== 32) {
177
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_InvalidPrivateKeyLength));
178
+ }
179
+ const signal = options.signal;
180
+ const onProgress = options.onProgress;
181
+ let expectedIndex = 0;
182
+ let tracker;
183
+ if (onProgress) {
184
+ tracker = new progress_tracker_1.ProgressTracker();
185
+ }
186
+ for await (const chunkData of source) {
187
+ if (signal?.aborted) {
188
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_DecryptionCancelled));
189
+ }
190
+ const { data, header } = await this.multiRecipientProcessor.decryptChunk(chunkData, recipientId, privateKey);
191
+ if (header.chunkIndex !== expectedIndex) {
192
+ throw new Error(this.engine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_Stream_ChunkSequenceError));
193
+ }
194
+ expectedIndex++;
195
+ yield data;
196
+ if (tracker && onProgress) {
197
+ onProgress(tracker.update(data.length));
198
+ }
199
+ const isLast = (header.flags & 0x01) !== 0;
200
+ if (isLast) {
201
+ break;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ exports.EncryptionStream = EncryptionStream;
207
+ //# sourceMappingURL=encryption-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-stream.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/encryption-stream.ts"],"names":[],"mappings":";;;AAAA,mEAGoC;AACpC,yEAAuE;AAGvE,+DAGqC;AAErC,uDAAmD;AAEnD,2EAAsE;AACtE,yDAAqD;AAcrD,MAAa,gBAAgB;IAMR;IACA;IANF,SAAS,CAAiB;IAC1B,uBAAuB,CAA0B;IACjD,MAAM,GAAG,IAAA,8CAAsB,GAAE,CAAC;IAEnD,YACmB,KAAmB,EACnB,SAAwB,qCAAqB,EAC9D,SAA0B,EAC1B,uBAAiD;QAHhC,UAAK,GAAL,KAAK,CAAc;QACnB,WAAM,GAAN,MAAM,CAAuC;QAI9D,+CAA+C;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAI,gCAAc,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,CAAC,uBAAuB;YAC1B,uBAAuB;gBACvB,IAAI,mDAAuB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;IAEM,KAAK,CAAC,CAAC,aAAa,CACzB,MAA6B,EAC7B,SAAiB,EACjB,UAAiC,EAAE;QAEnC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,IAAI,SAAS,CAAC,MAAM,KA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,CACtE,SAAS,EACT,WAAW,EACX,UAAU,CACX,CAAC;YAEF,IAAI,MAAM,CAAC,UAAU,KAAK,aAAa,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CACb,IAAI,CAAC,MAAM,CAAC,SAAS,CACnB,yCAAoB,EACpB,uCAAkB,CAAC,+BAA+B,CACnD,CACF,CAAC;YACJ,CAAC;YAED,aAAa,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC;YAEX,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;gBAC1B,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1C,CAAC;YAED,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3C,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlZD,4CAkZC"}
@@ -5,3 +5,4 @@ export * from './chunk-processor';
5
5
  export * from './encryption-stream';
6
6
  export * from './multi-recipient-processor';
7
7
  export * from './progress-tracker';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./aes-gcm"), exports);
5
+ tslib_1.__exportStar(require("./ecies"), exports);
6
+ tslib_1.__exportStar(require("./pbkdf2"), exports);
7
+ tslib_1.__exportStar(require("./chunk-processor"), exports);
8
+ tslib_1.__exportStar(require("./encryption-stream"), exports);
9
+ tslib_1.__exportStar(require("./multi-recipient-processor"), exports);
10
+ tslib_1.__exportStar(require("./progress-tracker"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,kDAAwB;AACxB,mDAAyB;AACzB,4DAAkC;AAClC,8DAAoC;AACpC,sEAA4C;AAC5C,6DAAmC"}
@@ -0,0 +1,72 @@
1
+ import { IECIESConstants } from '@digitaldefiance/ecies-lib';
2
+ import { IMultiRecipientChunk, IMultiRecipientChunkHeader } from '../interfaces/multi-recipient-chunk';
3
+ import { AESGCMService } from './aes-gcm';
4
+ import { EciesCryptoCore } from './ecies/crypto-core';
5
+ import { EciesMultiRecipient } from './ecies/multi-recipient';
6
+ export interface IMultiRecipient {
7
+ id: Buffer;
8
+ publicKey: Buffer;
9
+ }
10
+ export interface IMultiEncryptedMessage {
11
+ dataLength: number;
12
+ recipientCount: number;
13
+ recipientIds: Buffer[];
14
+ recipientKeys: Buffer[];
15
+ encryptedMessage: Buffer;
16
+ headerSize: number;
17
+ ephemeralPublicKey?: Buffer;
18
+ }
19
+ export declare class MultiRecipientProcessor {
20
+ private readonly aesGcm;
21
+ private readonly cryptoCore;
22
+ private readonly consts;
23
+ private readonly eciesMultiRecipient;
24
+ private readonly constants;
25
+ private readonly recipientIdSize;
26
+ constructor(cryptoCore: EciesCryptoCore, consts?: IECIESConstants, aesGcm?: AESGCMService, eciesMultiRecipient?: EciesMultiRecipient);
27
+ /**
28
+ * Encrypts a message for multiple recipients.
29
+ * Wrapper around EciesMultiRecipient.encryptMultiple for backward compatibility.
30
+ */
31
+ encryptMultiple(recipients: IMultiRecipient[], message: Buffer, preamble?: Buffer): Promise<IMultiEncryptedMessage>;
32
+ /**
33
+ * Builds the header for a message encrypted for multiple recipients.
34
+ * Wrapper around EciesMultiRecipient.buildECIESMultipleRecipientHeader for backward compatibility.
35
+ */
36
+ buildHeader(data: IMultiEncryptedMessage): Buffer;
37
+ encryptChunk(data: Buffer, recipients: IMultiRecipient[], chunkIndex: number, isLast: boolean, symmetricKey: Buffer, senderPrivateKey?: Buffer): Promise<IMultiRecipientChunk>;
38
+ decryptChunk(chunkData: Buffer, recipientId: Buffer, privateKey: Buffer, senderPublicKey?: Buffer): Promise<{
39
+ data: Buffer;
40
+ header: IMultiRecipientChunkHeader;
41
+ }>;
42
+ /**
43
+ * Decrypts a message encrypted with multiple ECIE for a recipient.
44
+ * Wrapper around EciesMultiRecipient.decryptMultipleECIEForRecipient for backward compatibility.
45
+ */
46
+ decryptMultipleForRecipient(encryptedData: IMultiEncryptedMessage, recipientId: Buffer, privateKey: Buffer, senderPublicKey?: Buffer): Promise<Buffer>;
47
+ /**
48
+ * Parses a multi-encrypted header.
49
+ * Wrapper around EciesMultiRecipient.parseMultiEncryptedHeader for backward compatibility.
50
+ */
51
+ parseHeader(data: Buffer): Omit<IMultiEncryptedMessage, 'encryptedMessage'> & {
52
+ headerSize: number;
53
+ };
54
+ /**
55
+ * Parses a multi-encrypted buffer into its components.
56
+ * Wrapper around EciesMultiRecipient.parseMultiEncryptedBuffer for backward compatibility.
57
+ */
58
+ parseMessage(data: Buffer): IMultiEncryptedMessage;
59
+ /**
60
+ * Encrypts a symmetric key for a recipient.
61
+ * Generates a new ephemeral key pair.
62
+ * Returns [EphemeralPublicKey][EncryptedKey]
63
+ */
64
+ encryptKey(recipientPublicKey: Buffer, symmetricKey: Buffer): Promise<Buffer>;
65
+ /**
66
+ * Decrypts a symmetric key.
67
+ * Expects [EphemeralPublicKey][EncryptedKey]
68
+ */
69
+ decryptKey(privateKey: Buffer, encryptedData: Buffer): Promise<Buffer>;
70
+ getHeaderSize(recipientCount: number): number;
71
+ }
72
+ //# sourceMappingURL=multi-recipient-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-recipient-processor.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/multi-recipient-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAWpC,OAAO,EAEL,oBAAoB,EACpB,0BAA0B,EAE3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAsB;IAC1D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAGvC,UAAU,EAAE,eAAe,EAC3B,MAAM,GAAE,eAAiC,EACzC,MAAM,CAAC,EAAE,aAAa,EACtB,mBAAmB,CAAC,EAAE,mBAAmB;IAY3C;;;OAGG;IACU,eAAe,CAC1B,UAAU,EAAE,eAAe,EAAE,EA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+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiRecipientProcessor = void 0;
4
+ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
+ const crypto_1 = require("crypto");
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
+ const encrypted = cipher.update(dataToEncrypt);
134
+ const final = cipher.final();
135
+ const authTag = cipher.getAuthTag();
136
+ // Write IV
137
+ iv.copy(chunk, offset);
138
+ offset += 12;
139
+ // Write encrypted data
140
+ encrypted.copy(chunk, offset);
141
+ offset += encrypted.length;
142
+ final.copy(chunk, offset); // Should be empty usually
143
+ offset += final.length;
144
+ // Write auth tag
145
+ authTag.copy(chunk, offset);
146
+ const header = {
147
+ chunkIndex,
148
+ flags: isLast ? 1 : 0,
149
+ recipientCount: recipients.length,
150
+ magic: this.constants.MAGIC,
151
+ version: this.constants.VERSION,
152
+ originalSize: dataToEncrypt.length,
153
+ encryptedSize,
154
+ };
155
+ return {
156
+ header,
157
+ data: chunk,
158
+ };
159
+ }
160
+ async decryptChunk(chunkData, recipientId, privateKey, senderPublicKey) {
161
+ if (chunkData.length < this.constants.HEADER_SIZE) {
162
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
163
+ }
164
+ let offset = 0;
165
+ // Parse header
166
+ const magic = chunkData.readUInt32BE(offset);
167
+ offset += 4;
168
+ if (magic !== this.constants.MAGIC) {
169
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength); // Invalid Magic
170
+ }
171
+ const version = chunkData.readUInt16BE(offset);
172
+ offset += 2;
173
+ if (version !== this.constants.VERSION) {
174
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidVersion);
175
+ }
176
+ const recipientCount = chunkData.readUInt16BE(offset);
177
+ offset += 2;
178
+ const chunkIndex = chunkData.readUInt32BE(offset);
179
+ offset += 4;
180
+ const originalSize = chunkData.readUInt32BE(offset);
181
+ offset += 4;
182
+ const encryptedSize = chunkData.readUInt32BE(offset);
183
+ offset += 4;
184
+ const flags = chunkData.readUInt8(offset);
185
+ offset += 1;
186
+ // Read Ephemeral Public Key (33 bytes)
187
+ const ephemeralPublicKey = chunkData.subarray(offset, offset + 33);
188
+ offset += 33;
189
+ offset = this.constants.HEADER_SIZE;
190
+ // Find recipient header and decrypt symmetric key
191
+ let symmetricKey = null;
192
+ let tempOffset = offset;
193
+ for (let i = 0; i < recipientCount; i++) {
194
+ const id = chunkData.subarray(tempOffset, tempOffset + this.recipientIdSize);
195
+ tempOffset += this.recipientIdSize;
196
+ const keySize = chunkData.readUInt16BE(tempOffset);
197
+ tempOffset += this.constants.KEY_SIZE_BYTES;
198
+ const encryptedKey = chunkData.subarray(tempOffset, tempOffset + keySize);
199
+ tempOffset += keySize;
200
+ // Check if this is our recipient
201
+ if (id.equals(recipientId)) {
202
+ // Use Recipient ID as AAD for key decryption
203
+ symmetricKey = this.eciesMultiRecipient.decryptKey(privateKey, encryptedKey, ephemeralPublicKey, id);
204
+ }
205
+ }
206
+ if (!symmetricKey) {
207
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.RecipientNotFound);
208
+ }
209
+ // Update offset to after all recipient headers
210
+ offset = tempOffset;
211
+ // Extract header bytes for AAD
212
+ const headerBytes = chunkData.subarray(0, offset);
213
+ // Read IV
214
+ const iv = chunkData.subarray(offset, offset + 12);
215
+ offset += 12;
216
+ // Read encrypted data (includes tag)
217
+ const encryptedWithTag = chunkData.subarray(offset, offset + encryptedSize);
218
+ offset += encryptedSize;
219
+ // Extract tag from end of encrypted data
220
+ const authTag = encryptedWithTag.subarray(encryptedWithTag.length - 16);
221
+ const encrypted = encryptedWithTag.subarray(0, encryptedWithTag.length - 16);
222
+ // Decrypt with AAD
223
+ const decipher = (0, crypto_1.createDecipheriv)(this.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
224
+ decipher.setAuthTag(authTag);
225
+ decipher.setAAD(headerBytes);
226
+ const decrypted = decipher.update(encrypted);
227
+ const final = decipher.final();
228
+ const decryptedMessage = Buffer.concat([decrypted, final]);
229
+ // Verify signature if sender public key provided
230
+ let finalData = decryptedMessage;
231
+ if (senderPublicKey) {
232
+ if (decryptedMessage.length < 64) {
233
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature);
234
+ }
235
+ const signature = decryptedMessage.subarray(0, 64);
236
+ const message = decryptedMessage.subarray(64);
237
+ const isValid = this.cryptoCore.verify(senderPublicKey, message, signature);
238
+ if (!isValid) {
239
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature);
240
+ }
241
+ finalData = message;
242
+ }
243
+ return {
244
+ data: finalData,
245
+ header: {
246
+ chunkIndex,
247
+ flags,
248
+ recipientCount,
249
+ magic,
250
+ version,
251
+ originalSize,
252
+ encryptedSize,
253
+ },
254
+ };
255
+ }
256
+ /**
257
+ * Decrypts a message encrypted with multiple ECIE for a recipient.
258
+ * Wrapper around EciesMultiRecipient.decryptMultipleECIEForRecipient for backward compatibility.
259
+ */
260
+ async decryptMultipleForRecipient(encryptedData, recipientId, privateKey, senderPublicKey) {
261
+ // Create a mock IMember with minimal required properties
262
+ const member = {
263
+ id: recipientId,
264
+ privateKey: { value: privateKey },
265
+ };
266
+ return this.eciesMultiRecipient.decryptMultipleECIEForRecipient(encryptedData, member, senderPublicKey);
267
+ }
268
+ /**
269
+ * Parses a multi-encrypted header.
270
+ * Wrapper around EciesMultiRecipient.parseMultiEncryptedHeader for backward compatibility.
271
+ */
272
+ parseHeader(data) {
273
+ const result = this.eciesMultiRecipient.parseMultiEncryptedHeader(data);
274
+ return result;
275
+ }
276
+ /**
277
+ * Parses a multi-encrypted buffer into its components.
278
+ * Wrapper around EciesMultiRecipient.parseMultiEncryptedBuffer for backward compatibility.
279
+ */
280
+ parseMessage(data) {
281
+ const result = this.eciesMultiRecipient.parseMultiEncryptedBuffer(data);
282
+ return result;
283
+ }
284
+ /**
285
+ * Encrypts a symmetric key for a recipient.
286
+ * Generates a new ephemeral key pair.
287
+ * Returns [EphemeralPublicKey][EncryptedKey]
288
+ */
289
+ async encryptKey(recipientPublicKey, symmetricKey) {
290
+ // Generate ephemeral key pair
291
+ const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
292
+ ecdh.generateKeys();
293
+ const ephemeralPrivateKey = ecdh.getPrivateKey();
294
+ let ephemeralPublicKey = ecdh.getPublicKey(null, 'compressed');
295
+ // Ensure public key has 0x04 prefix
296
+ if (ephemeralPublicKey.length === this.cryptoCore.consts.RAW_PUBLIC_KEY_LENGTH) {
297
+ ephemeralPublicKey = Buffer.concat([
298
+ Buffer.from([this.cryptoCore.consts.PUBLIC_KEY_MAGIC]),
299
+ ephemeralPublicKey,
300
+ ]);
301
+ }
302
+ const encryptedKey = this.eciesMultiRecipient.encryptKey(recipientPublicKey, symmetricKey, ephemeralPrivateKey, Buffer.alloc(0) // No AAD for simple key encryption? Or use recipient ID?
303
+ );
304
+ return Buffer.concat([ephemeralPublicKey, encryptedKey]);
305
+ }
306
+ /**
307
+ * Decrypts a symmetric key.
308
+ * Expects [EphemeralPublicKey][EncryptedKey]
309
+ */
310
+ async decryptKey(privateKey, encryptedData) {
311
+ // Extract ephemeral public key
312
+ const pubKeyLength = this.cryptoCore.consts.PUBLIC_KEY_LENGTH; // 33
313
+ const ephemeralPublicKey = encryptedData.subarray(0, 33);
314
+ const encryptedKey = encryptedData.subarray(33);
315
+ return this.eciesMultiRecipient.decryptKey(privateKey, encryptedKey, ephemeralPublicKey, Buffer.alloc(0));
316
+ }
317
+ getHeaderSize(recipientCount) {
318
+ return this.eciesMultiRecipient.getHeaderSize(recipientCount);
319
+ }
320
+ }
321
+ exports.MultiRecipientProcessor = MultiRecipientProcessor;
322
+ //# sourceMappingURL=multi-recipient-processor.js.map