internxt-crypto 0.0.9-alpha → 0.0.11

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 (120) hide show
  1. package/README.md +3 -4
  2. package/dist/asymmetric-crypto-BORmLhnx.js +143 -0
  3. package/dist/asymmetric-crypto-BORmLhnx.js.map +1 -0
  4. package/dist/asymmetric-crypto-CyXsV4XT.mjs +102 -0
  5. package/dist/asymmetric-crypto-CyXsV4XT.mjs.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +47 -0
  7. package/dist/asymmetric-crypto.d.ts +47 -0
  8. package/dist/asymmetric-crypto.js +8 -0
  9. package/dist/asymmetric-crypto.mjs +3 -0
  10. package/dist/chunk-DWirmd9C.mjs +18 -0
  11. package/dist/chunk-Dt-PWiN7.js +60 -0
  12. package/dist/constants-Ccp21E03.js +208 -0
  13. package/dist/constants-Ccp21E03.js.map +1 -0
  14. package/dist/constants-kTeX-2T0.mjs +34 -0
  15. package/dist/constants-kTeX-2T0.mjs.map +1 -0
  16. package/dist/constants.d.mts +33 -0
  17. package/dist/constants.d.ts +33 -0
  18. package/dist/constants.js +31 -0
  19. package/dist/constants.mjs +3 -0
  20. package/dist/derive-key-Be7hS-cN.mjs +751 -0
  21. package/dist/derive-key-Be7hS-cN.mjs.map +1 -0
  22. package/dist/derive-key-CBf2WxJd.js +2513 -0
  23. package/dist/derive-key-CBf2WxJd.js.map +1 -0
  24. package/dist/derive-key.d.mts +97 -0
  25. package/dist/derive-key.d.ts +97 -0
  26. package/dist/derive-key.js +15 -0
  27. package/dist/derive-key.mjs +6 -0
  28. package/dist/email-crypto-BrT98taw.js +617 -0
  29. package/dist/email-crypto-BrT98taw.js.map +1 -0
  30. package/dist/email-crypto-DJUEjTxA.mjs +534 -0
  31. package/dist/email-crypto-DJUEjTxA.mjs.map +1 -0
  32. package/dist/email-crypto.d.mts +86 -0
  33. package/dist/email-crypto.d.ts +86 -0
  34. package/dist/email-crypto.js +17 -0
  35. package/dist/email-crypto.mjs +8 -0
  36. package/dist/email-search.d.mts +235 -0
  37. package/dist/email-search.d.ts +235 -0
  38. package/dist/email-search.js +637 -0
  39. package/dist/email-search.js.map +1 -0
  40. package/dist/email-search.mjs +608 -0
  41. package/dist/email-search.mjs.map +1 -0
  42. package/dist/hash-BoqwNkcd.js +190 -0
  43. package/dist/hash-BoqwNkcd.js.map +1 -0
  44. package/dist/hash-CXeGAwai.mjs +131 -0
  45. package/dist/hash-CXeGAwai.mjs.map +1 -0
  46. package/dist/hash.d.mts +65 -0
  47. package/dist/hash.d.ts +65 -0
  48. package/dist/hash.js +11 -0
  49. package/dist/hash.mjs +3 -0
  50. package/dist/index-CQqgKsbX.d.ts +50 -0
  51. package/dist/index-CintVUbp.d.ts +97 -0
  52. package/dist/index-D5pBU_A5.d.mts +50 -0
  53. package/dist/index-MaOov-ag.d.mts +97 -0
  54. package/dist/index.d.mts +52 -0
  55. package/dist/index.d.ts +52 -0
  56. package/dist/index.js +116 -2055
  57. package/dist/index.mjs +15 -8712
  58. package/dist/keystore-crypto-B4yCVo9l.js +182 -0
  59. package/dist/keystore-crypto-B4yCVo9l.js.map +1 -0
  60. package/dist/keystore-crypto-Bjgriq9h.mjs +159 -0
  61. package/dist/keystore-crypto-Bjgriq9h.mjs.map +1 -0
  62. package/dist/keystore-crypto.d.mts +40 -0
  63. package/dist/keystore-crypto.d.ts +40 -0
  64. package/dist/keystore-crypto.js +11 -0
  65. package/dist/keystore-crypto.mjs +9 -0
  66. package/dist/keystore-service.d.mts +48 -0
  67. package/dist/keystore-service.d.ts +48 -0
  68. package/dist/keystore-service.js +122 -0
  69. package/dist/keystore-service.js.map +1 -0
  70. package/dist/keystore-service.mjs +114 -0
  71. package/dist/keystore-service.mjs.map +1 -0
  72. package/dist/post-quantum-crypto-CAi-cEkV.js +189 -0
  73. package/dist/post-quantum-crypto-CAi-cEkV.js.map +1 -0
  74. package/dist/post-quantum-crypto-Vv34t6gX.mjs +154 -0
  75. package/dist/post-quantum-crypto-Vv34t6gX.mjs.map +1 -0
  76. package/dist/post-quantum-crypto.d.mts +2 -0
  77. package/dist/post-quantum-crypto.d.ts +2 -0
  78. package/dist/post-quantum-crypto.js +17 -0
  79. package/dist/post-quantum-crypto.mjs +3 -0
  80. package/dist/storage-service-BgIK2aYZ.js +82 -0
  81. package/dist/storage-service-BgIK2aYZ.js.map +1 -0
  82. package/dist/storage-service-CubCbhY2.mjs +65 -0
  83. package/dist/storage-service-CubCbhY2.mjs.map +1 -0
  84. package/dist/storage-service.d.mts +2 -0
  85. package/dist/storage-service.d.ts +2 -0
  86. package/dist/storage-service.js +14 -0
  87. package/dist/storage-service.mjs +3 -0
  88. package/dist/symmetric-crypto-CrdS1Che.mjs +197 -0
  89. package/dist/symmetric-crypto-CrdS1Che.mjs.map +1 -0
  90. package/dist/symmetric-crypto-D65zB396.js +244 -0
  91. package/dist/symmetric-crypto-D65zB396.js.map +1 -0
  92. package/dist/symmetric-crypto.d.mts +60 -0
  93. package/dist/symmetric-crypto.d.ts +60 -0
  94. package/dist/symmetric-crypto.js +10 -0
  95. package/dist/symmetric-crypto.mjs +4 -0
  96. package/dist/types-52g887Zi.js +16 -0
  97. package/dist/types-52g887Zi.js.map +1 -0
  98. package/dist/types-BiEoleqw.mjs +10 -0
  99. package/dist/types-BiEoleqw.mjs.map +1 -0
  100. package/dist/types-Ds3ivE9W.d.ts +104 -0
  101. package/dist/types-DwQJtrTx.d.mts +104 -0
  102. package/dist/types.d.mts +2 -0
  103. package/dist/types.d.ts +2 -0
  104. package/dist/types.js +3 -0
  105. package/dist/types.mjs +3 -0
  106. package/dist/utils-CNs3cyDj.js +263 -0
  107. package/dist/utils-CNs3cyDj.js.map +1 -0
  108. package/dist/utils-DS04iUcX.mjs +173 -0
  109. package/dist/utils-DS04iUcX.mjs.map +1 -0
  110. package/dist/utils.d.mts +99 -0
  111. package/dist/utils.d.ts +99 -0
  112. package/dist/utils.js +16 -0
  113. package/dist/utils.mjs +3 -0
  114. package/package.json +12 -11
  115. package/dist/__vite-browser-external-Dyvby5gX.js +0 -2
  116. package/dist/__vite-browser-external-Dyvby5gX.js.map +0 -1
  117. package/dist/__vite-browser-external-l0sNRNKZ.mjs +0 -2
  118. package/dist/__vite-browser-external-l0sNRNKZ.mjs.map +0 -1
  119. package/dist/index.js.map +0 -1
  120. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,617 @@
1
+ const require_chunk = require('./chunk-Dt-PWiN7.js');
2
+ const require_constants = require('./constants-Ccp21E03.js');
3
+ const require_asymmetric_crypto = require('./asymmetric-crypto-BORmLhnx.js');
4
+ const require_utils = require('./utils-CNs3cyDj.js');
5
+ const require_symmetric_crypto = require('./symmetric-crypto-D65zB396.js');
6
+ const require_derive_key = require('./derive-key-CBf2WxJd.js');
7
+ const require_post_quantum_crypto = require('./post-quantum-crypto-CAi-cEkV.js');
8
+ let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
9
+
10
+ //#region src/key-wrapper/aesWrapper.ts
11
+ /**
12
+ * Converts wrapping key in Uint8Array into CryptoKey
13
+ *
14
+ * @param key - The wrapping key in Uint8Array representation
15
+ * @returns The resulting CryptoKey
16
+ */
17
+ async function importWrappingKey(key) {
18
+ try {
19
+ return await crypto.subtle.importKey(require_constants.KEY_FORMAT, key, require_constants.KEY_WRAPPING_ALGORITHM, false, ["wrapKey", "unwrapKey"]);
20
+ } catch (error) {
21
+ throw new Error("Failed to import wrapping key", { cause: error });
22
+ }
23
+ }
24
+ /**
25
+ * Derives wrapping key from two secrets
26
+ *
27
+ * @param eccSecret - The secret exchanged via elliptic curves
28
+ * @param kyberSecret - The secret exchanged via Kyber KEM
29
+ * @returns The resulting wrapping CryptoKey
30
+ */
31
+ async function deriveWrappingKey(eccSecret, kyberSecret) {
32
+ try {
33
+ if (eccSecret.length !== kyberSecret.length) throw new Error("secrets must have equal length");
34
+ return await importWrappingKey(await require_derive_key.deriveSymmetricKeyFromTwoKeysAndContext(eccSecret, kyberSecret, require_constants.CONTEXT_WRAPPING));
35
+ } catch (error) {
36
+ throw new Error("Failed to derive wrapping key", { cause: error });
37
+ }
38
+ }
39
+ /**
40
+ * Unwraps the given wrapped key
41
+ *
42
+ * @param encryptedKey - The encrypted key
43
+ * @param wrappingKey - The secret key used for decryption
44
+ * @returns The resulting wrapping CryptoKey
45
+ */
46
+ async function unwrapKey(encryptedKey, wrappingKey) {
47
+ try {
48
+ return await crypto.subtle.unwrapKey(require_constants.KEY_FORMAT, encryptedKey, wrappingKey, require_constants.KEY_WRAPPING_ALGORITHM, require_constants.AES_ALGORITHM, false, ["encrypt", "decrypt"]);
49
+ } catch (error) {
50
+ throw new Error("Failed to unwrap key", { cause: error });
51
+ }
52
+ }
53
+ /**
54
+ * Wraps the given CryptoKey
55
+ *
56
+ * @param encryptionKey - The CryptoKey to be wrapped
57
+ * @param wrappingKey - The secret key used for wrapping
58
+ * @returns The resulting ciphertext
59
+ */
60
+ async function wrapKey(encryptionKey, wrappingKey) {
61
+ try {
62
+ const result = await crypto.subtle.wrapKey(require_constants.KEY_FORMAT, encryptionKey, wrappingKey, require_constants.KEY_WRAPPING_ALGORITHM);
63
+ return new Uint8Array(result);
64
+ } catch (error) {
65
+ throw new Error("Failed to wrap key", { cause: error });
66
+ }
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/key-wrapper/index.ts
71
+ var key_wrapper_exports = /* @__PURE__ */ require_chunk.__exportAll({
72
+ deriveWrappingKey: () => deriveWrappingKey,
73
+ importWrappingKey: () => importWrappingKey,
74
+ unwrapKey: () => unwrapKey,
75
+ wrapKey: () => wrapKey
76
+ });
77
+
78
+ //#endregion
79
+ //#region src/email-crypto/converters.ts
80
+ function userToBytes(user) {
81
+ try {
82
+ return require_utils.UTF8ToUint8(JSON.stringify(user));
83
+ } catch (error) {
84
+ throw new Error("Failed to convert User to bytes", { cause: error });
85
+ }
86
+ }
87
+ function recipientsToBytes(recipients) {
88
+ try {
89
+ return (0, _noble_hashes_utils_js.concatBytes)(...recipients.map((user) => userToBytes(user)));
90
+ } catch (error) {
91
+ throw new Error("Failed to convert recipients to bytes", { cause: error });
92
+ }
93
+ }
94
+ /**
95
+ * Converts an Email type into a Uint8Array array.
96
+ *
97
+ * @param email - The email.
98
+ * @returns The Uint8Array array representation of the Email type.
99
+ */
100
+ function emailToBinary(email) {
101
+ try {
102
+ return require_utils.UTF8ToUint8(JSON.stringify(email));
103
+ } catch (error) {
104
+ throw new Error("Failed to convert EmailBody to Uint8Array", { cause: error });
105
+ }
106
+ }
107
+
108
+ //#endregion
109
+ //#region src/email-crypto/utils.ts
110
+ /**
111
+ * Creates an auxiliary string from public fields of the email.
112
+ *
113
+ * @param params - The email public parameters.
114
+ * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
115
+ * @returns The resulting auxiliary string
116
+ */
117
+ function getAux(params, isSubjectEncrypted) {
118
+ try {
119
+ const { subject, replyToEmailID, sender, recipient, recipients } = params;
120
+ const replyBytes = replyToEmailID ? require_utils.uuidToBytes(replyToEmailID) : new Uint8Array();
121
+ const senderBytes = userToBytes(sender);
122
+ const recipientBytes = userToBytes(recipient);
123
+ const recipientsBytes = recipients ? recipientsToBytes(recipients) : new Uint8Array();
124
+ if (isSubjectEncrypted) return (0, _noble_hashes_utils_js.concatBytes)(replyBytes, senderBytes, recipientBytes, recipientsBytes);
125
+ else return (0, _noble_hashes_utils_js.concatBytes)(require_utils.UTF8ToUint8(subject), replyBytes, senderBytes, recipientBytes, recipientsBytes);
126
+ } catch (error) {
127
+ throw new Error("Failed to create aux", { cause: error });
128
+ }
129
+ }
130
+
131
+ //#endregion
132
+ //#region src/email-crypto/core.ts
133
+ async function encryptEmailBody(email, isSubjectEncrypted) {
134
+ try {
135
+ const aux = getAux(email.params, isSubjectEncrypted);
136
+ let enc;
137
+ let encryptionKey;
138
+ let params = email.params;
139
+ if (isSubjectEncrypted) {
140
+ const result = await encryptEmailContentAndSubjectSymmetrically(email.body, email.params.subject, aux, email.id);
141
+ enc = result.enc;
142
+ encryptionKey = result.encryptionKey;
143
+ params = {
144
+ ...email.params,
145
+ subject: result.encSubject
146
+ };
147
+ } else {
148
+ const result = await encryptEmailContentSymmetrically(email.body, aux, email.id);
149
+ enc = result.enc;
150
+ encryptionKey = result.encryptionKey;
151
+ }
152
+ return {
153
+ encryptionKey,
154
+ enc,
155
+ params
156
+ };
157
+ } catch (error) {
158
+ throw new Error("Failed to encrypt email body", { cause: error });
159
+ }
160
+ }
161
+ async function decryptEmailBody(enc, encParams, encryptionKey, isSubjectEncrypted) {
162
+ try {
163
+ const aux = getAux(encParams, isSubjectEncrypted);
164
+ let body;
165
+ let params = encParams;
166
+ if (isSubjectEncrypted) {
167
+ const result = await decryptEmailAndSubjectSymmetrically(encryptionKey, aux, encParams.subject, enc);
168
+ body = result.body;
169
+ params = {
170
+ ...encParams,
171
+ subject: result.subject
172
+ };
173
+ } else body = await decryptEmailSymmetrically(encryptionKey, aux, enc);
174
+ return {
175
+ body,
176
+ params
177
+ };
178
+ } catch (error) {
179
+ throw new Error("Failed to encrypt email body", { cause: error });
180
+ }
181
+ }
182
+ /**
183
+ * Symmetrically encrypts an email with a randomly sampled key.
184
+ *
185
+ * @param email - The email to encrypt.
186
+ * @param aux - The auxiliary data (e.g., email ID or timestamp) for AEAD.
187
+ * @param emailID - The unique identifier of the email.
188
+ * @returns The resulting ciphertext and the used symmetric key
189
+ */
190
+ async function encryptEmailContentSymmetrically(email, aux, emailID) {
191
+ try {
192
+ if (!email.text) throw new Error("Invalid input");
193
+ const encryptionKey = await require_symmetric_crypto.genSymmetricCryptoKey();
194
+ return {
195
+ enc: await encryptEmailContentSymmetricallyWithKey(email, encryptionKey, aux, emailID),
196
+ encryptionKey
197
+ };
198
+ } catch (error) {
199
+ throw new Error("Failed to symmetrically encrypt email", { cause: error });
200
+ }
201
+ }
202
+ /**
203
+ * Symmetrically encrypts an email with a randomly sampled key.
204
+ *
205
+ * @param email - The email to encrypt.
206
+ * @param subject - The email subject to encrypt.
207
+ * @param aux - The auxiliary data (e.g., email ID or timestamp) for AEAD.
208
+ * @param emailID - The unique identifier of the email.
209
+ * @returns The resulting ciphertext and the used symmetric key
210
+ */
211
+ async function encryptEmailContentAndSubjectSymmetrically(email, subject, aux, emailID) {
212
+ try {
213
+ if (!subject || !email.text) throw new Error("Invalid input");
214
+ const encryptionKey = await require_symmetric_crypto.genSymmetricCryptoKey();
215
+ return {
216
+ enc: await encryptEmailContentSymmetricallyWithKey(email, encryptionKey, aux, emailID),
217
+ encSubject: require_utils.uint8ArrayToBase64(await require_symmetric_crypto.encryptSymmetrically(encryptionKey, require_utils.UTF8ToUint8(subject), aux)),
218
+ encryptionKey
219
+ };
220
+ } catch (error) {
221
+ throw new Error("Failed to symmetrically encrypt email and subject", { cause: error });
222
+ }
223
+ }
224
+ /**
225
+ * Decrypts symmetrically encrypted email.
226
+ *
227
+ * @param encryptedEmail - The email to decrypt.
228
+ * @param encryptionKey - The symmetric CryptoKey.
229
+ * @returns The decrypted email
230
+ */
231
+ async function decryptEmailAndSubjectSymmetrically(encryptionKey, aux, encSubject, enc) {
232
+ try {
233
+ const subjectArray = await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(encSubject), aux);
234
+ return {
235
+ body: await decryptEmailSymmetrically(encryptionKey, aux, enc),
236
+ subject: require_utils.uint8ToUTF8(subjectArray)
237
+ };
238
+ } catch (error) {
239
+ throw new Error("Failed to symmetrically decrypt email and subject", { cause: error });
240
+ }
241
+ }
242
+ /**
243
+ * Symmetrically encrypts an email with a randomly sampled key.
244
+ *
245
+ * @param email - The email to encrypt.
246
+ * @returns The resulting ciphertext and the used symmetric key
247
+ */
248
+ async function encryptEmailContentSymmetricallyWithKey(emailBody, encryptionKey, aux, emailID) {
249
+ try {
250
+ const freeField = require_utils.uuidToBytes(emailID);
251
+ const result = { encText: require_utils.uint8ArrayToBase64(await require_symmetric_crypto.encryptSymmetrically(encryptionKey, require_utils.UTF8ToUint8(emailBody.text), aux, freeField)) };
252
+ if (emailBody.attachments) result.encAttachments = (await encryptEmailAttachements(emailBody.attachments, encryptionKey, aux, emailID))?.map(require_utils.uint8ArrayToBase64);
253
+ return result;
254
+ } catch (error) {
255
+ throw new Error("Failed to symmetrically encrypt email with the given key", { cause: error });
256
+ }
257
+ }
258
+ async function encryptEmailAttachements(attachments, encryptionKey, aux, emailID) {
259
+ try {
260
+ const freeField = require_utils.uuidToBytes(emailID);
261
+ return await Promise.all(attachments.map((attachment) => {
262
+ return require_symmetric_crypto.encryptSymmetrically(encryptionKey, require_utils.UTF8ToUint8(attachment), aux, freeField);
263
+ }));
264
+ } catch (error) {
265
+ throw new Error("Failed to symmetrically encrypt email attachements", { cause: error });
266
+ }
267
+ }
268
+ async function decryptEmailAttachements(encryptedAttachments, encryptionKey, aux) {
269
+ try {
270
+ return await Promise.all(encryptedAttachments.map((attachment) => {
271
+ return require_symmetric_crypto.decryptSymmetrically(encryptionKey, attachment, aux);
272
+ }));
273
+ } catch (error) {
274
+ throw new Error("Failed to symmetrically decrypt email attachements", { cause: error });
275
+ }
276
+ }
277
+ /**
278
+ * Decrypts symmetrically encrypted email.
279
+ *
280
+ * @param encryptedEmail - The email to decrypt.
281
+ * @param encryptionKey - The symmetric CryptoKey.
282
+ * @returns The decrypted email
283
+ */
284
+ async function decryptEmailSymmetrically(encryptionKey, aux, enc) {
285
+ try {
286
+ const result = { text: require_utils.uint8ToUTF8(await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(enc.encText), aux)) };
287
+ if (enc.encAttachments) {
288
+ const encAttachements = enc.encAttachments?.map(require_utils.base64ToUint8Array);
289
+ result.attachments = (await decryptEmailAttachements(encAttachements, encryptionKey, aux))?.map((att) => require_utils.uint8ToUTF8(att));
290
+ }
291
+ return result;
292
+ } catch (error) {
293
+ throw new Error("Failed to symmetrically decrypt email", { cause: error });
294
+ }
295
+ }
296
+ /**
297
+ * Encrypts the email symmetric key using hybrid encryption.
298
+ *
299
+ * @param emailEncryptionKey - The symmetric CryptoKey used for email encryption.
300
+ * @param recipientPublicKey - The public key of the recipient.
301
+ * @param senderPrivateKey - The private key of the sender.
302
+ * @returns The encrypted email symmetric key
303
+ */
304
+ async function encryptKeysHybrid(emailEncryptionKey, recipientPublicKey, senderPrivateKey) {
305
+ try {
306
+ const eccSecret = await require_asymmetric_crypto.deriveSecretKey(recipientPublicKey.eccPublicKey, senderPrivateKey.eccPrivateKey);
307
+ const { cipherText: kyberCiphertext, sharedSecret: kyberSecret } = require_post_quantum_crypto.encapsulateKyber(recipientPublicKey.kyberPublicKey);
308
+ return {
309
+ encryptedKey: require_utils.uint8ArrayToBase64(await wrapKey(emailEncryptionKey, await deriveWrappingKey(eccSecret, kyberSecret))),
310
+ kyberCiphertext: require_utils.uint8ArrayToBase64(kyberCiphertext)
311
+ };
312
+ } catch (error) {
313
+ throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
314
+ }
315
+ }
316
+ /**
317
+ * Decrypts the email symmetric key encrypted via hybrid encryption.
318
+ *
319
+ * @param encryptedKey - The encrypted email key.
320
+ * @param senderPublicKey - The public key of the sender.
321
+ * @param recipientPrivateKey - The private key of the recipient.
322
+ * @returns The email encryption CryptoKey
323
+ */
324
+ async function decryptKeysHybrid(encryptedKey, senderPublicKey, recipientPrivateKey) {
325
+ try {
326
+ const kyberCiphertext = require_utils.base64ToUint8Array(encryptedKey.kyberCiphertext);
327
+ return await unwrapKey(require_utils.base64ToUint8Array(encryptedKey.encryptedKey), await deriveWrappingKey(await require_asymmetric_crypto.deriveSecretKey(senderPublicKey.eccPublicKey, recipientPrivateKey.eccPrivateKey), require_post_quantum_crypto.decapsulateKyber(kyberCiphertext, recipientPrivateKey.kyberPrivateKey)));
328
+ } catch (error) {
329
+ throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
330
+ }
331
+ }
332
+ /**
333
+ * Password-protects the email symmetric key.
334
+ *
335
+ * @param emailEncryptionKey - The symmetric CryptoKey used for email encryption.
336
+ * @param password - The secret password for key protection.
337
+ * @returns The password-protected email symmetric key
338
+ */
339
+ async function passwordProtectKey(emailEncryptionKey, password) {
340
+ try {
341
+ const { key, salt } = await require_derive_key.getKeyFromPassword(password);
342
+ const encryptedKey = await wrapKey(emailEncryptionKey, await importWrappingKey(key));
343
+ const saltStr = require_utils.uint8ArrayToBase64(salt);
344
+ return {
345
+ encryptedKey: require_utils.uint8ArrayToBase64(encryptedKey),
346
+ salt: saltStr
347
+ };
348
+ } catch (error) {
349
+ throw new Error("Failed to password-protect email key", { cause: error });
350
+ }
351
+ }
352
+ /**
353
+ * Removes passoword-protection and exposes the email symmetric key.
354
+ *
355
+ * @param emailEncryptionKey - The password-protected email key.
356
+ * @param password - The secret password for key protection.
357
+ * @returns The email encryption CryptoKey
358
+ */
359
+ async function removePasswordProtection(emailEncryptionKey, password) {
360
+ try {
361
+ const salt = require_utils.base64ToUint8Array(emailEncryptionKey.salt);
362
+ return await unwrapKey(require_utils.base64ToUint8Array(emailEncryptionKey.encryptedKey), await importWrappingKey(await require_derive_key.getKeyFromPasswordAndSalt(password, salt)));
363
+ } catch (error) {
364
+ throw new Error("Failed to remove password-protection from email key", { cause: error });
365
+ }
366
+ }
367
+
368
+ //#endregion
369
+ //#region src/email-crypto/hybridEncyptedEmail.ts
370
+ /**
371
+ * Encrypts the email using hybrid encryption.
372
+ *
373
+ * @param email - The email to encrypt.
374
+ * @param recipientPublicKeys - The public keys of the recipient.
375
+ * @param senderPrivateKey - The private key of the sender.
376
+ * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
377
+ * @returns The encrypted email
378
+ */
379
+ async function encryptEmailHybrid(email, recipient, senderPrivateKey, isSubjectEncrypted = false) {
380
+ try {
381
+ const { encryptionKey, params, enc } = await encryptEmailBody(email, isSubjectEncrypted);
382
+ return {
383
+ enc,
384
+ encryptedKey: await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey),
385
+ recipientEmail: recipient.email,
386
+ params,
387
+ isSubjectEncrypted,
388
+ id: email.id
389
+ };
390
+ } catch (error) {
391
+ throw new Error("Failed to encrypt email with hybrid encryption", { cause: error });
392
+ }
393
+ }
394
+ /**
395
+ * Encrypts the email using hybrid encryption for multiple recipients.
396
+ *
397
+ * @param email - The email to encrypt.
398
+ * @param recipients - The recipients with corresponding public keys.
399
+ * @param senderPrivateKey - The private key of the sender.
400
+ * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
401
+ * @returns The set of encrypted email
402
+ */
403
+ async function encryptEmailHybridForMultipleRecipients(email, recipients, senderPrivateKey, isSubjectEncrypted = false) {
404
+ try {
405
+ const { encryptionKey, params, enc } = await encryptEmailBody(email, isSubjectEncrypted);
406
+ const encryptedEmails = [];
407
+ for (const recipient of recipients) {
408
+ const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);
409
+ encryptedEmails.push({
410
+ enc,
411
+ encryptedKey,
412
+ recipientEmail: recipient.email,
413
+ params,
414
+ isSubjectEncrypted,
415
+ id: email.id
416
+ });
417
+ }
418
+ return encryptedEmails;
419
+ } catch (error) {
420
+ throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
421
+ }
422
+ }
423
+ /**
424
+ * Decrypts the email using hybrid encryption.
425
+ *
426
+ * @param encryptedEmail - The encrypted email.
427
+ * @param senderPublicKeys - The public key of the sender.
428
+ * @param recipientPrivateKeys - The private key of the recipient.
429
+ * @returns The decrypted email
430
+ */
431
+ async function decryptEmailHybrid(encryptedEmail, senderPublicKeys, recipientPrivateKeys) {
432
+ try {
433
+ const { isSubjectEncrypted, params: encParams, enc, encryptedKey, id } = encryptedEmail;
434
+ const { body, params } = await decryptEmailBody(enc, encParams, await decryptKeysHybrid(encryptedKey, senderPublicKeys, recipientPrivateKeys), isSubjectEncrypted);
435
+ return {
436
+ body,
437
+ params,
438
+ id
439
+ };
440
+ } catch (error) {
441
+ throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
442
+ }
443
+ }
444
+
445
+ //#endregion
446
+ //#region src/email-crypto/pwdProtectedEmail.ts
447
+ /**
448
+ * Creates a password-protected email.
449
+ *
450
+ * @param email - The email to password-protect
451
+ * @param password - The secret password shared among recipients
452
+ * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
453
+ * @returns The password-protected email
454
+ */
455
+ async function createPwdProtectedEmail(email, password, isSubjectEncrypted = false) {
456
+ try {
457
+ if (!email?.body || !email.params) throw new Error("Failed to password-protect email: Invalid email structure");
458
+ const { encryptionKey, params, enc } = await encryptEmailBody(email, isSubjectEncrypted);
459
+ return {
460
+ enc,
461
+ encryptedKey: await passwordProtectKey(encryptionKey, password),
462
+ params,
463
+ id: email.id,
464
+ isSubjectEncrypted
465
+ };
466
+ } catch (error) {
467
+ throw new Error("Failed to password-protect email", { cause: error });
468
+ }
469
+ }
470
+ /**
471
+ * Opens a password-protected email.
472
+ *
473
+ * @param encryptedEmail - The encrypted email
474
+ * @param password - The secret password shared among recipients.
475
+ * @returns The decrypted email
476
+ */
477
+ async function decryptPwdProtectedEmail(encryptedEmail, password) {
478
+ try {
479
+ const { isSubjectEncrypted, params: encParams, enc, id } = encryptedEmail;
480
+ const { body, params } = await decryptEmailBody(enc, encParams, await removePasswordProtection(encryptedEmail.encryptedKey, password), isSubjectEncrypted);
481
+ return {
482
+ body,
483
+ params,
484
+ id
485
+ };
486
+ } catch (error) {
487
+ throw new Error("Failed to decrypt password-protect email", { cause: error });
488
+ }
489
+ }
490
+
491
+ //#endregion
492
+ //#region src/email-crypto/emailKeys.ts
493
+ /**
494
+ * Generates public and private keys for email service.
495
+ *
496
+ * @returns The user's private and public keys
497
+ */
498
+ async function generateEmailKeys() {
499
+ try {
500
+ const kyberKeys = require_post_quantum_crypto.generateKyberKeys();
501
+ const keys = await require_asymmetric_crypto.generateEccKeys();
502
+ return {
503
+ publicKeys: {
504
+ eccPublicKey: keys.publicKey,
505
+ kyberPublicKey: kyberKeys.publicKey
506
+ },
507
+ privateKeys: {
508
+ eccPrivateKey: keys.privateKey,
509
+ kyberPrivateKey: kyberKeys.secretKey
510
+ }
511
+ };
512
+ } catch (error) {
513
+ throw new Error("Failed to generate keys for email service", { cause: error });
514
+ }
515
+ }
516
+
517
+ //#endregion
518
+ //#region src/email-crypto/index.ts
519
+ var email_crypto_exports = /* @__PURE__ */ require_chunk.__exportAll({
520
+ createPwdProtectedEmail: () => createPwdProtectedEmail,
521
+ decryptEmailHybrid: () => decryptEmailHybrid,
522
+ decryptPwdProtectedEmail: () => decryptPwdProtectedEmail,
523
+ emailToBinary: () => emailToBinary,
524
+ encryptEmailHybrid: () => encryptEmailHybrid,
525
+ encryptEmailHybridForMultipleRecipients: () => encryptEmailHybridForMultipleRecipients,
526
+ generateEmailKeys: () => generateEmailKeys,
527
+ getAux: () => getAux,
528
+ recipientsToBytes: () => recipientsToBytes,
529
+ userToBytes: () => userToBytes
530
+ });
531
+
532
+ //#endregion
533
+ Object.defineProperty(exports, 'createPwdProtectedEmail', {
534
+ enumerable: true,
535
+ get: function () {
536
+ return createPwdProtectedEmail;
537
+ }
538
+ });
539
+ Object.defineProperty(exports, 'decryptEmailHybrid', {
540
+ enumerable: true,
541
+ get: function () {
542
+ return decryptEmailHybrid;
543
+ }
544
+ });
545
+ Object.defineProperty(exports, 'decryptEmailSymmetrically', {
546
+ enumerable: true,
547
+ get: function () {
548
+ return decryptEmailSymmetrically;
549
+ }
550
+ });
551
+ Object.defineProperty(exports, 'decryptPwdProtectedEmail', {
552
+ enumerable: true,
553
+ get: function () {
554
+ return decryptPwdProtectedEmail;
555
+ }
556
+ });
557
+ Object.defineProperty(exports, 'emailToBinary', {
558
+ enumerable: true,
559
+ get: function () {
560
+ return emailToBinary;
561
+ }
562
+ });
563
+ Object.defineProperty(exports, 'email_crypto_exports', {
564
+ enumerable: true,
565
+ get: function () {
566
+ return email_crypto_exports;
567
+ }
568
+ });
569
+ Object.defineProperty(exports, 'encryptEmailContentSymmetricallyWithKey', {
570
+ enumerable: true,
571
+ get: function () {
572
+ return encryptEmailContentSymmetricallyWithKey;
573
+ }
574
+ });
575
+ Object.defineProperty(exports, 'encryptEmailHybrid', {
576
+ enumerable: true,
577
+ get: function () {
578
+ return encryptEmailHybrid;
579
+ }
580
+ });
581
+ Object.defineProperty(exports, 'encryptEmailHybridForMultipleRecipients', {
582
+ enumerable: true,
583
+ get: function () {
584
+ return encryptEmailHybridForMultipleRecipients;
585
+ }
586
+ });
587
+ Object.defineProperty(exports, 'generateEmailKeys', {
588
+ enumerable: true,
589
+ get: function () {
590
+ return generateEmailKeys;
591
+ }
592
+ });
593
+ Object.defineProperty(exports, 'getAux', {
594
+ enumerable: true,
595
+ get: function () {
596
+ return getAux;
597
+ }
598
+ });
599
+ Object.defineProperty(exports, 'key_wrapper_exports', {
600
+ enumerable: true,
601
+ get: function () {
602
+ return key_wrapper_exports;
603
+ }
604
+ });
605
+ Object.defineProperty(exports, 'recipientsToBytes', {
606
+ enumerable: true,
607
+ get: function () {
608
+ return recipientsToBytes;
609
+ }
610
+ });
611
+ Object.defineProperty(exports, 'userToBytes', {
612
+ enumerable: true,
613
+ get: function () {
614
+ return userToBytes;
615
+ }
616
+ });
617
+ //# sourceMappingURL=email-crypto-BrT98taw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-crypto-BrT98taw.js","names":["KEY_FORMAT","KEY_WRAPPING_ALGORITHM","deriveSymmetricKeyFromTwoKeysAndContext","CONTEXT_WRAPPING","AES_ALGORITHM","UTF8ToUint8","uuidToBytes","UTF8ToUint8","genSymmetricCryptoKey","uint8ArrayToBase64","encryptSymmetrically","UTF8ToUint8","decryptSymmetrically","base64ToUint8Array","uint8ToUTF8","uuidToBytes","deriveSecretKey","encapsulateKyber","decapsulateKyber","getKeyFromPassword","getKeyFromPasswordAndSalt","generateKyberKeys","generateEccKeys"],"sources":["../src/key-wrapper/aesWrapper.ts","../src/key-wrapper/index.ts","../src/email-crypto/converters.ts","../src/email-crypto/utils.ts","../src/email-crypto/core.ts","../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/index.ts"],"sourcesContent":["import { KEY_WRAPPING_ALGORITHM, KEY_FORMAT, CONTEXT_WRAPPING, AES_ALGORITHM } from '../constants';\nimport { deriveSymmetricKeyFromTwoKeysAndContext } from '../derive-key';\n\n/**\n * Converts wrapping key in Uint8Array into CryptoKey\n *\n * @param key - The wrapping key in Uint8Array representation\n * @returns The resulting CryptoKey\n */\nexport async function importWrappingKey(key: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(KEY_FORMAT, key as BufferSource, KEY_WRAPPING_ALGORITHM, false, [\n 'wrapKey',\n 'unwrapKey',\n ]);\n } catch (error) {\n throw new Error('Failed to import wrapping key', { cause: error });\n }\n}\n\n/**\n * Derives wrapping key from two secrets\n *\n * @param eccSecret - The secret exchanged via elliptic curves\n * @param kyberSecret - The secret exchanged via Kyber KEM\n * @returns The resulting wrapping CryptoKey\n */\nexport async function deriveWrappingKey(eccSecret: Uint8Array, kyberSecret: Uint8Array): Promise<CryptoKey> {\n try {\n if (eccSecret.length !== kyberSecret.length) {\n throw new Error('secrets must have equal length');\n }\n const key = await deriveSymmetricKeyFromTwoKeysAndContext(eccSecret, kyberSecret, CONTEXT_WRAPPING);\n return await importWrappingKey(key);\n } catch (error) {\n throw new Error('Failed to derive wrapping key', { cause: error });\n }\n}\n\n/**\n * Unwraps the given wrapped key\n *\n * @param encryptedKey - The encrypted key\n * @param wrappingKey - The secret key used for decryption\n * @returns The resulting wrapping CryptoKey\n */\nexport async function unwrapKey(encryptedKey: Uint8Array, wrappingKey: CryptoKey): Promise<CryptoKey> {\n try {\n return await crypto.subtle.unwrapKey(\n KEY_FORMAT,\n encryptedKey as BufferSource,\n wrappingKey,\n KEY_WRAPPING_ALGORITHM,\n AES_ALGORITHM,\n false,\n ['encrypt', 'decrypt'],\n );\n } catch (error) {\n throw new Error('Failed to unwrap key', { cause: error });\n }\n}\n\n/**\n * Wraps the given CryptoKey\n *\n * @param encryptionKey - The CryptoKey to be wrapped\n * @param wrappingKey - The secret key used for wrapping\n * @returns The resulting ciphertext\n */\nexport async function wrapKey(encryptionKey: CryptoKey, wrappingKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.wrapKey(KEY_FORMAT, encryptionKey, wrappingKey, KEY_WRAPPING_ALGORITHM);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to wrap key', { cause: error });\n }\n}\n","export * from './aesWrapper';\n","import { UTF8ToUint8 } from '../utils';\nimport { User, Email } from '../types';\nimport { concatBytes } from '@noble/hashes/utils.js';\n\nexport function userToBytes(user: User): Uint8Array {\n try {\n const json = JSON.stringify(user);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert User to bytes', { cause: error });\n }\n}\n\nexport function recipientsToBytes(recipients: User[]): Uint8Array {\n try {\n const array = recipients.map((user) => userToBytes(user));\n return concatBytes(...array);\n } catch (error) {\n throw new Error('Failed to convert recipients to bytes', { cause: error });\n }\n}\n\n/**\n * Converts an Email type into a Uint8Array array.\n *\n * @param email - The email.\n * @returns The Uint8Array array representation of the Email type.\n */\nexport function emailToBinary(email: Email): Uint8Array {\n try {\n const json = JSON.stringify(email);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert EmailBody to Uint8Array', { cause: error });\n }\n}\n","import { concatBytes } from '@noble/hashes/utils.js';\nimport { EmailPublicParameters } from '../types';\nimport { UTF8ToUint8, uuidToBytes } from '../utils';\nimport { userToBytes, recipientsToBytes } from './converters';\n\n/**\n * Creates an auxiliary string from public fields of the email.\n *\n * @param params - The email public parameters.\n * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted\n * @returns The resulting auxiliary string\n */\nexport function getAux(params: EmailPublicParameters, isSubjectEncrypted: boolean): Uint8Array {\n try {\n const { subject, replyToEmailID, sender, recipient, recipients } = params;\n const replyBytes = replyToEmailID ? uuidToBytes(replyToEmailID) : new Uint8Array();\n const senderBytes = userToBytes(sender);\n const recipientBytes = userToBytes(recipient);\n const recipientsBytes = recipients ? recipientsToBytes(recipients) : new Uint8Array();\n\n if (isSubjectEncrypted) {\n return concatBytes(replyBytes, senderBytes, recipientBytes, recipientsBytes);\n } else {\n const subjectBytes = UTF8ToUint8(subject);\n return concatBytes(subjectBytes, replyBytes, senderBytes, recipientBytes, recipientsBytes);\n }\n } catch (error) {\n throw new Error('Failed to create aux', { cause: error });\n }\n}\n","import {\n HybridEncKey,\n PwdProtectedKey,\n PublicKeys,\n PrivateKeys,\n EmailBody,\n EmailBodyEncrypted,\n Email,\n EmailPublicParameters,\n} from '../types';\nimport { genSymmetricCryptoKey, encryptSymmetrically, decryptSymmetrically } from '../symmetric-crypto';\nimport { encapsulateKyber, decapsulateKyber } from '../post-quantum-crypto';\nimport { deriveWrappingKey, wrapKey, unwrapKey, importWrappingKey } from '../key-wrapper';\nimport { deriveSecretKey } from '../asymmetric-crypto';\nimport { getKeyFromPassword, getKeyFromPasswordAndSalt } from '../derive-key';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8, uuidToBytes } from '../utils';\nimport { getAux } from './utils';\n\nexport async function encryptEmailBody(\n email: Email,\n isSubjectEncrypted: boolean,\n): Promise<{\n enc: EmailBodyEncrypted;\n params: EmailPublicParameters;\n encryptionKey: CryptoKey;\n}> {\n try {\n const aux = getAux(email.params, isSubjectEncrypted);\n\n let enc: EmailBodyEncrypted;\n let encryptionKey: CryptoKey;\n let params = email.params;\n\n if (isSubjectEncrypted) {\n const result = await encryptEmailContentAndSubjectSymmetrically(email.body, email.params.subject, aux, email.id);\n enc = result.enc;\n encryptionKey = result.encryptionKey;\n params = { ...email.params, subject: result.encSubject };\n } else {\n const result = await encryptEmailContentSymmetrically(email.body, aux, email.id);\n enc = result.enc;\n encryptionKey = result.encryptionKey;\n }\n\n return { encryptionKey, enc, params };\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\nexport async function decryptEmailBody(\n enc: EmailBodyEncrypted,\n encParams: EmailPublicParameters,\n encryptionKey: CryptoKey,\n isSubjectEncrypted: boolean,\n): Promise<{\n params: EmailPublicParameters;\n body: EmailBody;\n}> {\n try {\n const aux = getAux(encParams, isSubjectEncrypted);\n let body: EmailBody;\n let params = encParams;\n if (isSubjectEncrypted) {\n const result = await decryptEmailAndSubjectSymmetrically(encryptionKey, aux, encParams.subject, enc);\n body = result.body;\n params = { ...encParams, subject: result.subject };\n } else {\n body = await decryptEmailSymmetrically(encryptionKey, aux, enc);\n }\n\n return { body, params };\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts an email with a randomly sampled key.\n *\n * @param email - The email to encrypt.\n * @param aux - The auxiliary data (e.g., email ID or timestamp) for AEAD.\n * @param emailID - The unique identifier of the email.\n * @returns The resulting ciphertext and the used symmetric key\n */\nexport async function encryptEmailContentSymmetrically(\n email: EmailBody,\n aux: Uint8Array,\n emailID: string,\n): Promise<{ enc: EmailBodyEncrypted; encryptionKey: CryptoKey }> {\n try {\n if (!email.text) {\n throw new Error('Invalid input');\n }\n const encryptionKey = await genSymmetricCryptoKey();\n const enc = await encryptEmailContentSymmetricallyWithKey(email, encryptionKey, aux, emailID);\n return { enc, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts an email with a randomly sampled key.\n *\n * @param email - The email to encrypt.\n * @param subject - The email subject to encrypt.\n * @param aux - The auxiliary data (e.g., email ID or timestamp) for AEAD.\n * @param emailID - The unique identifier of the email.\n * @returns The resulting ciphertext and the used symmetric key\n */\nexport async function encryptEmailContentAndSubjectSymmetrically(\n email: EmailBody,\n subject: string,\n aux: Uint8Array,\n emailID: string,\n): Promise<{ enc: EmailBodyEncrypted; encSubject: string; encryptionKey: CryptoKey }> {\n try {\n if (!subject || !email.text) {\n throw new Error('Invalid input');\n }\n const encryptionKey = await genSymmetricCryptoKey();\n const enc = await encryptEmailContentSymmetricallyWithKey(email, encryptionKey, aux, emailID);\n const subjectBuff = UTF8ToUint8(subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subjectBuff, aux);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n return { enc, encSubject, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email and subject', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email.\n *\n * @param encryptedEmail - The email to decrypt.\n * @param encryptionKey - The symmetric CryptoKey.\n * @returns The decrypted email\n */\nexport async function decryptEmailAndSubjectSymmetrically(\n encryptionKey: CryptoKey,\n aux: Uint8Array,\n encSubject: string,\n enc: EmailBodyEncrypted,\n): Promise<{ body: EmailBody; subject: string }> {\n try {\n const array = base64ToUint8Array(encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, array, aux);\n const body = await decryptEmailSymmetrically(encryptionKey, aux, enc);\n const subject = uint8ToUTF8(subjectArray);\n return { body, subject };\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email and subject', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts an email with a randomly sampled key.\n *\n * @param email - The email to encrypt.\n * @returns The resulting ciphertext and the used symmetric key\n */\nexport async function encryptEmailContentSymmetricallyWithKey(\n emailBody: EmailBody,\n encryptionKey: CryptoKey,\n aux: Uint8Array,\n emailID: string,\n): Promise<EmailBodyEncrypted> {\n try {\n const freeField = uuidToBytes(emailID);\n const text = UTF8ToUint8(emailBody.text);\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux, freeField);\n const encText = uint8ArrayToBase64(encryptedText);\n const result: EmailBodyEncrypted = { encText };\n\n if (emailBody.attachments) {\n const encryptedAttachements = await encryptEmailAttachements(emailBody.attachments, encryptionKey, aux, emailID);\n result.encAttachments = encryptedAttachements?.map(uint8ArrayToBase64);\n }\n return result;\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email with the given key', { cause: error });\n }\n}\n\nasync function encryptEmailAttachements(\n attachments: string[],\n encryptionKey: CryptoKey,\n aux: Uint8Array,\n emailID: string,\n): Promise<Uint8Array[]> {\n try {\n const freeField = uuidToBytes(emailID);\n const encryptedAttachments = await Promise.all(\n attachments.map((attachment) => {\n const binaryAttachment = UTF8ToUint8(attachment);\n return encryptSymmetrically(encryptionKey, binaryAttachment, aux, freeField);\n }),\n );\n return encryptedAttachments;\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email attachements', { cause: error });\n }\n}\n\nasync function decryptEmailAttachements(\n encryptedAttachments: Uint8Array[],\n encryptionKey: CryptoKey,\n aux: Uint8Array,\n): Promise<Uint8Array[]> {\n try {\n const decryptedAttachments = await Promise.all(\n encryptedAttachments.map((attachment) => {\n return decryptSymmetrically(encryptionKey, attachment, aux);\n }),\n );\n return decryptedAttachments;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email attachements', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email.\n *\n * @param encryptedEmail - The email to decrypt.\n * @param encryptionKey - The symmetric CryptoKey.\n * @returns The decrypted email\n */\nexport async function decryptEmailSymmetrically(\n encryptionKey: CryptoKey,\n aux: Uint8Array,\n enc: EmailBodyEncrypted,\n): Promise<EmailBody> {\n try {\n const cipher = base64ToUint8Array(enc.encText);\n const textArray = await decryptSymmetrically(encryptionKey, cipher, aux);\n const text = uint8ToUTF8(textArray);\n const result: EmailBody = { text };\n\n if (enc.encAttachments) {\n const encAttachements = enc.encAttachments?.map(base64ToUint8Array);\n const attachmentsArray = await decryptEmailAttachements(encAttachements, encryptionKey, aux);\n result.attachments = attachmentsArray?.map((att) => uint8ToUTF8(att));\n }\n return result;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email', { cause: error });\n }\n}\n\n/**\n * Encrypts the email symmetric key using hybrid encryption.\n *\n * @param emailEncryptionKey - The symmetric CryptoKey used for email encryption.\n * @param recipientPublicKey - The public key of the recipient.\n * @param senderPrivateKey - The private key of the sender.\n * @returns The encrypted email symmetric key\n */\nexport async function encryptKeysHybrid(\n emailEncryptionKey: CryptoKey,\n recipientPublicKey: PublicKeys,\n senderPrivateKey: PrivateKeys,\n): Promise<HybridEncKey> {\n try {\n const eccSecret = await deriveSecretKey(recipientPublicKey.eccPublicKey, senderPrivateKey.eccPrivateKey);\n const { cipherText: kyberCiphertext, sharedSecret: kyberSecret } = encapsulateKyber(\n recipientPublicKey.kyberPublicKey,\n );\n const wrappingKey = await deriveWrappingKey(eccSecret, kyberSecret);\n const encryptedKey = await wrapKey(emailEncryptionKey, wrappingKey);\n const encryptedKeyBase64 = uint8ArrayToBase64(encryptedKey);\n const kyberCiphertextBase64 = uint8ArrayToBase64(kyberCiphertext);\n\n return { encryptedKey: encryptedKeyBase64, kyberCiphertext: kyberCiphertextBase64 };\n } catch (error) {\n throw new Error('Failed to encrypt email key using hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email symmetric key encrypted via hybrid encryption.\n *\n * @param encryptedKey - The encrypted email key.\n * @param senderPublicKey - The public key of the sender.\n * @param recipientPrivateKey - The private key of the recipient.\n * @returns The email encryption CryptoKey\n */\nexport async function decryptKeysHybrid(\n encryptedKey: HybridEncKey,\n senderPublicKey: PublicKeys,\n recipientPrivateKey: PrivateKeys,\n): Promise<CryptoKey> {\n try {\n const kyberCiphertext = base64ToUint8Array(encryptedKey.kyberCiphertext);\n const encKey = base64ToUint8Array(encryptedKey.encryptedKey);\n const eccSecret = await deriveSecretKey(senderPublicKey.eccPublicKey, recipientPrivateKey.eccPrivateKey);\n const kyberSecret = decapsulateKyber(kyberCiphertext, recipientPrivateKey.kyberPrivateKey);\n const wrappingKey = await deriveWrappingKey(eccSecret, kyberSecret);\n const encryptionKey = await unwrapKey(encKey, wrappingKey);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to decrypt email key encrypted via hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric CryptoKey used for email encryption.\n * @param password - The secret password for key protection.\n * @returns The password-protected email symmetric key\n */\nexport async function passwordProtectKey(emailEncryptionKey: CryptoKey, password: string): Promise<PwdProtectedKey> {\n try {\n const { key, salt } = await getKeyFromPassword(password);\n const wrappingKey = await importWrappingKey(key);\n const encryptedKey = await wrapKey(emailEncryptionKey, wrappingKey);\n const saltStr = uint8ArrayToBase64(salt);\n const encryptedKeyStr = uint8ArrayToBase64(encryptedKey);\n return { encryptedKey: encryptedKeyStr, salt: saltStr };\n } catch (error) {\n throw new Error('Failed to password-protect email key', { cause: error });\n }\n}\n\n/**\n * Removes passoword-protection and exposes the email symmetric key.\n *\n * @param emailEncryptionKey - The password-protected email key.\n * @param password - The secret password for key protection.\n * @returns The email encryption CryptoKey\n */\nexport async function removePasswordProtection(\n emailEncryptionKey: PwdProtectedKey,\n password: string,\n): Promise<CryptoKey> {\n try {\n const salt = base64ToUint8Array(emailEncryptionKey.salt);\n const encryptedKey = base64ToUint8Array(emailEncryptionKey.encryptedKey);\n const key = await getKeyFromPasswordAndSalt(password, salt);\n const wrappingKey = await importWrappingKey(key);\n const encryptionKey = await unwrapKey(encryptedKey, wrappingKey);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to remove password-protection from email key', { cause: error });\n }\n}\n","import { PublicKeys, PrivateKeys, HybridEncryptedEmail, Email, UserWithPublicKeys } from '../types';\nimport { decryptEmailBody, encryptKeysHybrid, decryptKeysHybrid, encryptEmailBody } from './core';\n\n/**\n * Encrypts the email using hybrid encryption.\n *\n * @param email - The email to encrypt.\n * @param recipientPublicKeys - The public keys of the recipient.\n * @param senderPrivateKey - The private key of the sender.\n * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted\n * @returns The encrypted email\n */\nexport async function encryptEmailHybrid(\n email: Email,\n recipient: UserWithPublicKeys,\n senderPrivateKey: PrivateKeys,\n isSubjectEncrypted: boolean = false,\n): Promise<HybridEncryptedEmail> {\n try {\n const { encryptionKey, params, enc } = await encryptEmailBody(email, isSubjectEncrypted);\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);\n return { enc, encryptedKey, recipientEmail: recipient.email, params, isSubjectEncrypted, id: email.id };\n } catch (error) {\n throw new Error('Failed to encrypt email with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Encrypts the email using hybrid encryption for multiple recipients.\n *\n * @param email - The email to encrypt.\n * @param recipients - The recipients with corresponding public keys.\n * @param senderPrivateKey - The private key of the sender.\n * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted\n * @returns The set of encrypted email\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n email: Email,\n recipients: UserWithPublicKeys[],\n senderPrivateKey: PrivateKeys,\n isSubjectEncrypted: boolean = false,\n): Promise<HybridEncryptedEmail[]> {\n try {\n const { encryptionKey, params, enc } = await encryptEmailBody(email, isSubjectEncrypted);\n\n const encryptedEmails: HybridEncryptedEmail[] = [];\n for (const recipient of recipients) {\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);\n encryptedEmails.push({\n enc,\n encryptedKey,\n recipientEmail: recipient.email,\n params,\n isSubjectEncrypted,\n id: email.id,\n });\n }\n return encryptedEmails;\n } catch (error) {\n throw new Error('Failed to encrypt email to multiple recipients with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email using hybrid encryption.\n *\n * @param encryptedEmail - The encrypted email.\n * @param senderPublicKeys - The public key of the sender.\n * @param recipientPrivateKeys - The private key of the recipient.\n * @returns The decrypted email\n */\nexport async function decryptEmailHybrid(\n encryptedEmail: HybridEncryptedEmail,\n senderPublicKeys: PublicKeys,\n recipientPrivateKeys: PrivateKeys,\n): Promise<Email> {\n try {\n const { isSubjectEncrypted, params: encParams, enc, encryptedKey, id } = encryptedEmail;\n const encryptionKey = await decryptKeysHybrid(encryptedKey, senderPublicKeys, recipientPrivateKeys);\n const { body, params } = await decryptEmailBody(enc, encParams, encryptionKey, isSubjectEncrypted);\n return { body, params, id };\n } catch (error) {\n throw new Error('Failed to decrypt email with hybrid encryption', { cause: error });\n }\n}\n","import { PwdProtectedEmail, Email } from '../types';\nimport { decryptEmailBody, passwordProtectKey, removePasswordProtection, encryptEmailBody } from './core';\n\n/**\n * Creates a password-protected email.\n *\n * @param email - The email to password-protect\n * @param password - The secret password shared among recipients\n * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted\n * @returns The password-protected email\n */\nexport async function createPwdProtectedEmail(\n email: Email,\n password: string,\n isSubjectEncrypted: boolean = false,\n): Promise<PwdProtectedEmail> {\n try {\n if (!email?.body || !email.params) {\n throw new Error('Failed to password-protect email: Invalid email structure');\n }\n const { encryptionKey, params, enc } = await encryptEmailBody(email, isSubjectEncrypted);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { enc, encryptedKey, params, id: email.id, isSubjectEncrypted };\n } catch (error) {\n throw new Error('Failed to password-protect email', { cause: error });\n }\n}\n\n/**\n * Opens a password-protected email.\n *\n * @param encryptedEmail - The encrypted email\n * @param password - The secret password shared among recipients.\n * @returns The decrypted email\n */\nexport async function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string): Promise<Email> {\n try {\n const { isSubjectEncrypted, params: encParams, enc, id } = encryptedEmail;\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n const { body, params } = await decryptEmailBody(enc, encParams, encryptionKey, isSubjectEncrypted);\n return { body, params, id };\n } catch (error) {\n throw new Error('Failed to decrypt password-protect email', { cause: error });\n }\n}\n","import { generateEccKeys } from '../asymmetric-crypto';\nimport { generateKyberKeys } from '../post-quantum-crypto';\nimport { EmailKeys } from '../types';\n\n/**\n * Generates public and private keys for email service.\n *\n * @returns The user's private and public keys\n */\nexport async function generateEmailKeys(): Promise<EmailKeys> {\n try {\n const kyberKeys = generateKyberKeys();\n const keys = await generateEccKeys();\n\n const emailKeys: EmailKeys = {\n publicKeys: {\n eccPublicKey: keys.publicKey,\n kyberPublicKey: kyberKeys.publicKey,\n },\n privateKeys: {\n eccPrivateKey: keys.privateKey,\n kyberPrivateKey: kyberKeys.secretKey,\n },\n };\n\n return emailKeys;\n } catch (error) {\n throw new Error('Failed to generate keys for email service', { cause: error });\n }\n}\n","export * from './hybridEncyptedEmail';\nexport * from './pwdProtectedEmail';\nexport * from './converters';\nexport * from './emailKeys';\nexport * from './utils';\n"],"mappings":";;;;;;;;;;;;;;;;AASA,eAAsB,kBAAkB,KAAqC;AAC3E,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UAAUA,8BAAY,KAAqBC,0CAAwB,OAAO,CACnG,WACA,YACD,CAAC;UACK,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,eAAsB,kBAAkB,WAAuB,aAA6C;AAC1G,KAAI;AACF,MAAI,UAAU,WAAW,YAAY,OACnC,OAAM,IAAI,MAAM,iCAAiC;AAGnD,SAAO,MAAM,kBADD,MAAMC,2DAAwC,WAAW,aAAaC,mCAAiB,CAChE;UAC5B,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,eAAsB,UAAU,cAA0B,aAA4C;AACpG,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzBH,8BACA,cACA,aACAC,0CACAG,iCACA,OACA,CAAC,WAAW,UAAU,CACvB;UACM,OAAO;AACd,QAAM,IAAI,MAAM,wBAAwB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW7D,eAAsB,QAAQ,eAA0B,aAA6C;AACnG,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,QAAQJ,8BAAY,eAAe,aAAaC,yCAAuB;AAC1G,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,sBAAsB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;;AEtE3D,SAAgB,YAAY,MAAwB;AAClD,KAAI;AAEF,SAAOI,0BADM,KAAK,UAAU,KAAK,CACT;UACjB,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