internxt-crypto 1.5.0 → 1.6.1

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 (158) hide show
  1. package/README.md +9 -5
  2. package/dist/asymmetric-crypto.d.mts.map +1 -1
  3. package/dist/asymmetric-crypto.d.ts.map +1 -1
  4. package/dist/asymmetric-crypto.js +12 -2
  5. package/dist/asymmetric-crypto.js.map +1 -1
  6. package/dist/asymmetric-crypto.mjs +12 -2
  7. package/dist/asymmetric-crypto.mjs.map +1 -1
  8. package/dist/{email-crypto-_Wcbvr_n.mjs → email-crypto-CoRbTphp.mjs} +73 -106
  9. package/dist/email-crypto-CoRbTphp.mjs.map +1 -0
  10. package/dist/{email-crypto-CPL8ept8.js → email-crypto-DJb-I1wm.js} +90 -117
  11. package/dist/email-crypto-DJb-I1wm.js.map +1 -0
  12. package/dist/email-crypto.d.mts +33 -27
  13. package/dist/email-crypto.d.mts.map +1 -1
  14. package/dist/email-crypto.d.ts +33 -27
  15. package/dist/email-crypto.d.ts.map +1 -1
  16. package/dist/email-crypto.js +4 -3
  17. package/dist/email-crypto.mjs +2 -2
  18. package/dist/index.d.mts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +2 -3
  21. package/dist/index.mjs +2 -2
  22. package/dist/keystore-crypto.d.mts +1 -1
  23. package/dist/keystore-crypto.d.ts +1 -1
  24. package/dist/react-native/asymmetric-crypto.d.mts +21 -0
  25. package/dist/react-native/asymmetric-crypto.d.mts.map +1 -0
  26. package/dist/react-native/asymmetric-crypto.d.ts +21 -0
  27. package/dist/react-native/asymmetric-crypto.d.ts.map +1 -0
  28. package/dist/react-native/asymmetric-crypto.js +31 -0
  29. package/dist/react-native/asymmetric-crypto.js.map +1 -0
  30. package/dist/react-native/asymmetric-crypto.mjs +28 -0
  31. package/dist/react-native/asymmetric-crypto.mjs.map +1 -0
  32. package/dist/react-native/chunk-CfYAbeIz.mjs +13 -0
  33. package/dist/react-native/chunk-DskHE4z1.js +43 -0
  34. package/dist/react-native/constants.d.mts +27 -0
  35. package/dist/react-native/constants.d.mts.map +1 -0
  36. package/dist/react-native/constants.d.ts +27 -0
  37. package/dist/react-native/constants.d.ts.map +1 -0
  38. package/dist/react-native/constants.js +51 -0
  39. package/dist/react-native/constants.js.map +1 -0
  40. package/dist/react-native/constants.mjs +28 -0
  41. package/dist/react-native/constants.mjs.map +1 -0
  42. package/dist/react-native/derive-key.d.mts +32 -0
  43. package/dist/react-native/derive-key.d.mts.map +1 -0
  44. package/dist/react-native/derive-key.d.ts +32 -0
  45. package/dist/react-native/derive-key.d.ts.map +1 -0
  46. package/dist/react-native/derive-key.js +51 -0
  47. package/dist/react-native/derive-key.js.map +1 -0
  48. package/dist/react-native/derive-key.mjs +47 -0
  49. package/dist/react-native/derive-key.mjs.map +1 -0
  50. package/dist/react-native/derive-password-Bb3R3nyh.mjs +68 -0
  51. package/dist/react-native/derive-password-Bb3R3nyh.mjs.map +1 -0
  52. package/dist/react-native/derive-password-DIPrE8Mz.js +86 -0
  53. package/dist/react-native/derive-password-DIPrE8Mz.js.map +1 -0
  54. package/dist/react-native/derive-password.d.mts +28 -0
  55. package/dist/react-native/derive-password.d.mts.map +1 -0
  56. package/dist/react-native/derive-password.d.ts +28 -0
  57. package/dist/react-native/derive-password.d.ts.map +1 -0
  58. package/dist/react-native/derive-password.js +5 -0
  59. package/dist/react-native/derive-password.mjs +2 -0
  60. package/dist/react-native/email-crypto-C3ka3aAj.js +700 -0
  61. package/dist/react-native/email-crypto-C3ka3aAj.js.map +1 -0
  62. package/dist/react-native/email-crypto-CDM4iPK8.mjs +490 -0
  63. package/dist/react-native/email-crypto-CDM4iPK8.mjs.map +1 -0
  64. package/dist/react-native/email-crypto.d.mts +253 -0
  65. package/dist/react-native/email-crypto.d.mts.map +1 -0
  66. package/dist/react-native/email-crypto.d.ts +253 -0
  67. package/dist/react-native/email-crypto.d.ts.map +1 -0
  68. package/dist/react-native/email-crypto.js +35 -0
  69. package/dist/react-native/email-crypto.mjs +2 -0
  70. package/dist/react-native/hash.d.mts +50 -0
  71. package/dist/react-native/hash.d.mts.map +1 -0
  72. package/dist/react-native/hash.d.ts +50 -0
  73. package/dist/react-native/hash.d.ts.map +1 -0
  74. package/dist/react-native/hash.js +89 -0
  75. package/dist/react-native/hash.js.map +1 -0
  76. package/dist/react-native/hash.mjs +82 -0
  77. package/dist/react-native/hash.mjs.map +1 -0
  78. package/dist/react-native/index.d.mts +32 -0
  79. package/dist/react-native/index.d.mts.map +1 -0
  80. package/dist/react-native/index.d.ts +32 -0
  81. package/dist/react-native/index.d.ts.map +1 -0
  82. package/dist/react-native/index.js +106 -0
  83. package/dist/react-native/index.mjs +12 -0
  84. package/dist/react-native/keystore-crypto-BXPEVvzq.js +238 -0
  85. package/dist/react-native/keystore-crypto-BXPEVvzq.js.map +1 -0
  86. package/dist/react-native/keystore-crypto-C6F-NQdX.mjs +185 -0
  87. package/dist/react-native/keystore-crypto-C6F-NQdX.mjs.map +1 -0
  88. package/dist/react-native/keystore-crypto.d.mts +71 -0
  89. package/dist/react-native/keystore-crypto.d.mts.map +1 -0
  90. package/dist/react-native/keystore-crypto.d.ts +71 -0
  91. package/dist/react-native/keystore-crypto.d.ts.map +1 -0
  92. package/dist/react-native/keystore-crypto.js +11 -0
  93. package/dist/react-native/keystore-crypto.mjs +2 -0
  94. package/dist/react-native/post-quantum-crypto.d.mts +32 -0
  95. package/dist/react-native/post-quantum-crypto.d.mts.map +1 -0
  96. package/dist/react-native/post-quantum-crypto.d.ts +32 -0
  97. package/dist/react-native/post-quantum-crypto.d.ts.map +1 -0
  98. package/dist/react-native/post-quantum-crypto.js +50 -0
  99. package/dist/react-native/post-quantum-crypto.js.map +1 -0
  100. package/dist/react-native/post-quantum-crypto.mjs +46 -0
  101. package/dist/react-native/post-quantum-crypto.mjs.map +1 -0
  102. package/dist/react-native/storage-service.d.mts +47 -0
  103. package/dist/react-native/storage-service.d.mts.map +1 -0
  104. package/dist/react-native/storage-service.d.ts +47 -0
  105. package/dist/react-native/storage-service.d.ts.map +1 -0
  106. package/dist/react-native/storage-service.js +66 -0
  107. package/dist/react-native/storage-service.js.map +1 -0
  108. package/dist/react-native/storage-service.mjs +54 -0
  109. package/dist/react-native/storage-service.mjs.map +1 -0
  110. package/dist/react-native/symmetric-crypto.d.mts +28 -0
  111. package/dist/react-native/symmetric-crypto.d.mts.map +1 -0
  112. package/dist/react-native/symmetric-crypto.d.ts +28 -0
  113. package/dist/react-native/symmetric-crypto.d.ts.map +1 -0
  114. package/dist/react-native/symmetric-crypto.js +52 -0
  115. package/dist/react-native/symmetric-crypto.js.map +1 -0
  116. package/dist/react-native/symmetric-crypto.mjs +48 -0
  117. package/dist/react-native/symmetric-crypto.mjs.map +1 -0
  118. package/dist/{types-fhvOo6Gw.d.ts → react-native/types-D1R4_m5r.d.mts} +6 -10
  119. package/dist/react-native/types-D1R4_m5r.d.mts.map +1 -0
  120. package/dist/{types-cEyToM9T.d.mts → react-native/types-Y0wL7HUH.d.ts} +6 -10
  121. package/dist/react-native/types-Y0wL7HUH.d.ts.map +1 -0
  122. package/dist/react-native/types.d.mts +2 -0
  123. package/dist/react-native/types.d.ts +2 -0
  124. package/dist/react-native/types.js +11 -0
  125. package/dist/react-native/types.js.map +1 -0
  126. package/dist/react-native/types.mjs +10 -0
  127. package/dist/react-native/types.mjs.map +1 -0
  128. package/dist/react-native/utils.d.mts +78 -0
  129. package/dist/react-native/utils.d.mts.map +1 -0
  130. package/dist/react-native/utils.d.ts +78 -0
  131. package/dist/react-native/utils.d.ts.map +1 -0
  132. package/dist/react-native/utils.js +123 -0
  133. package/dist/react-native/utils.js.map +1 -0
  134. package/dist/react-native/utils.mjs +109 -0
  135. package/dist/react-native/utils.mjs.map +1 -0
  136. package/dist/react-native/xwing-B34h5e3Z.mjs +15 -0
  137. package/dist/react-native/xwing-B34h5e3Z.mjs.map +1 -0
  138. package/dist/react-native/xwing-CSdiyHAt.js +33 -0
  139. package/dist/react-native/xwing-CSdiyHAt.js.map +1 -0
  140. package/dist/types-D1R4_m5r.d.mts +55 -0
  141. package/dist/types-D1R4_m5r.d.mts.map +1 -0
  142. package/dist/types-Y0wL7HUH.d.ts +55 -0
  143. package/dist/types-Y0wL7HUH.d.ts.map +1 -0
  144. package/dist/types.d.mts +2 -2
  145. package/dist/types.d.ts +2 -2
  146. package/dist/types.js.map +1 -1
  147. package/dist/types.mjs.map +1 -1
  148. package/dist/utils.d.mts.map +1 -1
  149. package/dist/utils.d.ts.map +1 -1
  150. package/dist/utils.js +3 -8
  151. package/dist/utils.js.map +1 -1
  152. package/dist/utils.mjs +3 -8
  153. package/dist/utils.mjs.map +1 -1
  154. package/package.json +4 -1
  155. package/dist/email-crypto-CPL8ept8.js.map +0 -1
  156. package/dist/email-crypto-_Wcbvr_n.mjs.map +0 -1
  157. package/dist/types-cEyToM9T.d.mts.map +0 -1
  158. package/dist/types-fhvOo6Gw.d.ts.map +0 -1
@@ -32,54 +32,70 @@ async function wrapKey(key, wrappingKey) {
32
32
  var FailedToEncryptEmail = class FailedToEncryptEmail extends Error {
33
33
  constructor(errorMsg) {
34
34
  super("Failed to encrypt email: " + errorMsg);
35
+ this.name = this.constructor.name;
35
36
  Object.setPrototypeOf(this, FailedToEncryptEmail.prototype);
36
37
  }
37
38
  };
38
39
  var EmailSymmetricEncryptionError = class EmailSymmetricEncryptionError extends Error {
39
40
  constructor(errorMsg) {
40
41
  super("Failed to symmetrically encrypt email: " + errorMsg);
42
+ this.name = this.constructor.name;
41
43
  Object.setPrototypeOf(this, EmailSymmetricEncryptionError.prototype);
42
44
  }
43
45
  };
44
46
  var EmailSymmetricDecryptionError = class EmailSymmetricDecryptionError extends Error {
45
47
  constructor(errorMsg) {
46
48
  super("Failed to symmetrically decrypt email: " + errorMsg);
49
+ this.name = this.constructor.name;
47
50
  Object.setPrototypeOf(this, EmailSymmetricDecryptionError.prototype);
48
51
  }
49
52
  };
53
+ var EmailPreviewSymmetricDecryptionError = class EmailPreviewSymmetricDecryptionError extends Error {
54
+ constructor(errorMsg) {
55
+ super("Failed to symmetrically decrypt email preview: " + errorMsg);
56
+ this.name = this.constructor.name;
57
+ Object.setPrototypeOf(this, EmailPreviewSymmetricDecryptionError.prototype);
58
+ }
59
+ };
50
60
  var EmailHybridEncryptionError = class EmailHybridEncryptionError extends Error {
51
61
  constructor(errorMsg) {
52
62
  super("Failed to hybridly encrypt the key: " + errorMsg);
63
+ this.name = this.constructor.name;
53
64
  Object.setPrototypeOf(this, EmailHybridEncryptionError.prototype);
54
65
  }
55
66
  };
56
67
  var EmailHybridDecryptionError = class EmailHybridDecryptionError extends Error {
57
68
  constructor(errorMsg) {
58
69
  super("Failed to hybridly decrypt the key: " + errorMsg);
70
+ this.name = this.constructor.name;
59
71
  Object.setPrototypeOf(this, EmailHybridDecryptionError.prototype);
60
72
  }
61
73
  };
62
74
  var EmailPasswordProtectError = class EmailPasswordProtectError extends Error {
63
75
  constructor(errorMsg) {
64
76
  super("Failed to password-protect the key: " + errorMsg);
77
+ this.name = this.constructor.name;
65
78
  Object.setPrototypeOf(this, EmailPasswordProtectError.prototype);
66
79
  }
67
80
  };
68
81
  var EmailPasswordOpenError = class EmailPasswordOpenError extends Error {
69
82
  constructor(errorMsg) {
70
83
  super("Failed to open password-protected key: " + errorMsg);
84
+ this.name = this.constructor.name;
71
85
  Object.setPrototypeOf(this, EmailPasswordOpenError.prototype);
72
86
  }
73
87
  };
74
88
  var InvalidInputEmail = class InvalidInputEmail extends Error {
75
89
  constructor() {
76
90
  super("Invalid input");
91
+ this.name = this.constructor.name;
77
92
  Object.setPrototypeOf(this, InvalidInputEmail.prototype);
78
93
  }
79
94
  };
80
95
  var FailedToDecryptEmail = class FailedToDecryptEmail extends Error {
81
96
  constructor(errorMsg) {
82
97
  super("Failed to decrypt email: " + errorMsg);
98
+ this.name = this.constructor.name;
83
99
  Object.setPrototypeOf(this, FailedToDecryptEmail.prototype);
84
100
  }
85
101
  };
@@ -114,12 +130,33 @@ async function encryptEmail(email, aux) {
114
130
  */
115
131
  async function encryptEmailWithKey(email, encryptionKey, aux) {
116
132
  try {
117
- return { encText: require_utils.uint8ArrayToBase64(await require_symmetric_crypto.encryptSymmetrically(encryptionKey, require_utils.UTF8ToUint8(email.text), aux)) };
133
+ const text = require_utils.UTF8ToUint8(email.text);
134
+ const preview = require_utils.UTF8ToUint8(email.preview);
135
+ return {
136
+ encText: require_utils.uint8ArrayToBase64(await require_symmetric_crypto.encryptSymmetrically(encryptionKey, text, aux)),
137
+ encPreview: require_utils.uint8ArrayToBase64(await require_symmetric_crypto.encryptSymmetrically(encryptionKey, preview, aux)),
138
+ encAttachmentsSessionKey: require_utils.uint8ArrayToBase64(await require_symmetric_crypto.encryptSymmetrically(encryptionKey, email.attachmentsSessionKey, aux))
139
+ };
118
140
  } catch (error) {
119
141
  throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));
120
142
  }
121
143
  }
122
144
  /**
145
+ * Decrypts symmetrically encrypted email preview.
146
+ *
147
+ * @param encEmailPreview - The email preview to decrypt.
148
+ * @param encryptionKey - The symmetric key to decrypt the email.
149
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
150
+ * @returns The resulting decrypted email
151
+ */
152
+ async function decryptPreview(encEmailPreview, encryptionKey, aux) {
153
+ try {
154
+ return require_utils.uint8ToUTF8(await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(encEmailPreview), aux));
155
+ } catch (error) {
156
+ throw new EmailPreviewSymmetricDecryptionError(error instanceof Error ? error.message : String(error));
157
+ }
158
+ }
159
+ /**
123
160
  * Decrypts symmetrically encrypted email.
124
161
  *
125
162
  * @param encEmail - The email to decrypt.
@@ -129,7 +166,11 @@ async function encryptEmailWithKey(email, encryptionKey, aux) {
129
166
  */
130
167
  async function decryptEmail(encEmail, encryptionKey, aux) {
131
168
  try {
132
- return { text: require_utils.uint8ToUTF8(await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(encEmail.encText), aux)) };
169
+ return {
170
+ text: require_utils.uint8ToUTF8(await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(encEmail.encText), aux)),
171
+ preview: require_utils.uint8ToUTF8(await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(encEmail.encPreview), aux)),
172
+ attachmentsSessionKey: await require_symmetric_crypto.decryptSymmetrically(encryptionKey, require_utils.base64ToUint8Array(encEmail.encAttachmentsSessionKey), aux)
173
+ };
133
174
  } catch (error) {
134
175
  throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(error));
135
176
  }
@@ -206,72 +247,39 @@ async function removePasswordProtection(emailEncryptionKey, password) {
206
247
  //#endregion
207
248
  //#region src/email-crypto/hybridEncyptedEmail.ts
208
249
  /**
209
- * Encrypts the email using hybrid encryption.
210
- *
211
- * @param email - The email to encrypt.
212
- * @param recipientPublicKeys - The public keys of the recipient.
213
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
214
- * @returns The encrypted email
215
- */
216
- async function encryptEmailHybrid(email, recipient, aux) {
217
- try {
218
- const { encryptionKey, encEmail } = await encryptEmail(email, aux);
219
- return {
220
- encEmail,
221
- encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
222
- };
223
- } catch (error) {
224
- if (error instanceof InvalidInputEmail) throw error;
225
- if (error instanceof EmailSymmetricEncryptionError) throw error;
226
- if (error instanceof EmailHybridEncryptionError) throw error;
227
- throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
228
- }
229
- }
230
- /**
231
250
  * Encrypts the email using hybrid encryption for multiple recipients.
232
251
  *
233
252
  * @param email - The email to encrypt for multiple recipients.
234
253
  * @param recipients - The recipients with corresponding public keys.
235
254
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
236
- * @returns The set of encrypted emails
255
+ * @returns The set of encrypted keys (one per user) and encrypted email
237
256
  */
238
257
  async function encryptEmailHybridForMultipleRecipients(email, recipients, aux) {
239
- try {
240
- if (!recipients || recipients.length === 0) throw new InvalidInputEmail();
241
- const { encryptionKey, encEmail } = await encryptEmail(email, aux);
242
- const encryptedEmails = [];
243
- for (const recipient of recipients) {
244
- const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);
245
- encryptedEmails.push({
246
- encEmail,
247
- encryptedKey
248
- });
249
- }
250
- return encryptedEmails;
251
- } catch (error) {
252
- if (error instanceof InvalidInputEmail) throw error;
253
- if (error instanceof EmailSymmetricEncryptionError) throw error;
254
- if (error instanceof EmailHybridEncryptionError) throw error;
255
- throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
256
- }
258
+ if (!recipients || recipients.length === 0) throw new InvalidInputEmail();
259
+ const { encryptionKey, encEmail } = await encryptEmail(email, aux);
260
+ return {
261
+ encryptedKeys: await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient))),
262
+ encEmail
263
+ };
257
264
  }
258
265
  /**
259
266
  * Decrypts the email using hybrid encryption.
260
267
  *
261
268
  * @param encEmail - The encrypted email.
269
+ * @param encryptedKey - The encrypted key for this recipient.
262
270
  * @param recipientPrivateHybridKeys - The private key of the recipient.
263
271
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
264
272
  * @returns The decrypted email
265
273
  */
266
- async function decryptEmailHybrid(encEmail, recipientPrivateHybridKeys, aux) {
267
- try {
268
- const encryptionKey = await decryptKeysHybrid(encEmail.encryptedKey, recipientPrivateHybridKeys);
269
- return await decryptEmail(encEmail.encEmail, encryptionKey, aux);
270
- } catch (error) {
271
- if (error instanceof EmailHybridDecryptionError) throw error;
272
- if (error instanceof EmailSymmetricDecryptionError) throw error;
273
- throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));
274
- }
274
+ async function decryptEmailHybrid(encEmail, encryptedKey, recipientPrivateHybridKeys, aux) {
275
+ return await decryptEmail(encEmail, await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys), aux);
276
+ }
277
+ async function decryptEmailPreviewHybrid(encPreview, encryptedKey, recipientPrivateHybridKeys, aux) {
278
+ const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);
279
+ return {
280
+ preview: await decryptPreview(encPreview, encryptionKey, aux),
281
+ encryptionKey
282
+ };
275
283
  }
276
284
  //#endregion
277
285
  //#region src/email-crypto/pwdProtectedEmail.ts
@@ -379,73 +387,32 @@ async function decryptEmailAndSubject(encEmail, encryptionKey, aux) {
379
387
  //#endregion
380
388
  //#region src/email-crypto/hybridEncryptedEmailAndSubject.ts
381
389
  /**
382
- * Encrypts the email and its subject using hybrid encryption.
383
- *
384
- * @param email - The email and subject to encrypt.
385
- * @param recipientPublicKeys - The public keys of the recipient.
386
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
387
- * @returns The encrypted email and subject
388
- */
389
- async function encryptEmailAndSubjectHybrid(email, recipient, aux) {
390
- try {
391
- const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);
392
- return {
393
- encEmail,
394
- encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
395
- };
396
- } catch (error) {
397
- if (error instanceof InvalidInputEmail) throw error;
398
- if (error instanceof EmailSymmetricEncryptionError) throw error;
399
- if (error instanceof EmailHybridEncryptionError) throw error;
400
- throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
401
- }
402
- }
403
- /**
404
390
  * Encrypts the email and its subject using hybrid encryption for multiple recipients.
405
391
  *
406
392
  * @param email - The email and subject to encrypt for multiple recipients.
407
393
  * @param recipients - The recipients with corresponding public keys.
408
394
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
409
- * @returns The set of encrypted emails and subjects
395
+ * @returns The set of encrypted keys and encrypted email and subject
410
396
  */
411
397
  async function encryptEmailAndSubjectHybridForMultipleRecipients(email, recipients, aux) {
412
- try {
413
- if (!recipients || recipients.length === 0) throw new InvalidInputEmail();
414
- const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);
415
- const encryptedEmails = [];
416
- for (const recipient of recipients) {
417
- const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);
418
- encryptedEmails.push({
419
- encEmail,
420
- encryptedKey
421
- });
422
- }
423
- return encryptedEmails;
424
- } catch (error) {
425
- if (error instanceof InvalidInputEmail) throw error;
426
- if (error instanceof EmailSymmetricEncryptionError) throw error;
427
- if (error instanceof EmailHybridEncryptionError) throw error;
428
- throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
429
- }
398
+ if (!recipients || recipients.length === 0) throw new InvalidInputEmail();
399
+ const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);
400
+ return {
401
+ encEmail,
402
+ encryptedKeys: await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient)))
403
+ };
430
404
  }
431
405
  /**
432
406
  * Decrypts the email and its subject using hybrid encryption.
433
407
  *
434
- * @param hybridEmail - The encrypted email and subject.
408
+ * @param encEmail - The encrypted email and subject.
409
+ * @param encryptedKey - The encrypted key for this recipient.
435
410
  * @param recipientPrivateHybridKeys - The private key of the recipient.
436
411
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
437
412
  * @returns The decrypted email and subject
438
413
  */
439
- async function decryptEmailAndSubjectHybrid(hybridEmail, recipientPrivateHybridKeys, aux) {
440
- try {
441
- const encryptionKey = await decryptKeysHybrid(hybridEmail.encryptedKey, recipientPrivateHybridKeys);
442
- return await decryptEmailAndSubject(hybridEmail.encEmail, encryptionKey, aux);
443
- } catch (error) {
444
- if (error instanceof InvalidInputEmail) throw error;
445
- if (error instanceof EmailHybridDecryptionError) throw error;
446
- if (error instanceof EmailSymmetricDecryptionError) throw error;
447
- throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));
448
- }
414
+ async function decryptEmailAndSubjectHybrid(encEmail, encryptedKey, recipientPrivateHybridKeys, aux) {
415
+ return await decryptEmailAndSubject(encEmail, await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys), aux);
449
416
  }
450
417
  //#endregion
451
418
  //#region src/email-crypto/pwdProtectedEmailAndSubject.ts
@@ -543,6 +510,12 @@ Object.defineProperty(exports, "EmailPasswordProtectError", {
543
510
  return EmailPasswordProtectError;
544
511
  }
545
512
  });
513
+ Object.defineProperty(exports, "EmailPreviewSymmetricDecryptionError", {
514
+ enumerable: true,
515
+ get: function() {
516
+ return EmailPreviewSymmetricDecryptionError;
517
+ }
518
+ });
546
519
  Object.defineProperty(exports, "EmailSymmetricDecryptionError", {
547
520
  enumerable: true,
548
521
  get: function() {
@@ -609,12 +582,24 @@ Object.defineProperty(exports, "decryptEmailHybrid", {
609
582
  return decryptEmailHybrid;
610
583
  }
611
584
  });
585
+ Object.defineProperty(exports, "decryptEmailPreviewHybrid", {
586
+ enumerable: true,
587
+ get: function() {
588
+ return decryptEmailPreviewHybrid;
589
+ }
590
+ });
612
591
  Object.defineProperty(exports, "decryptKeysHybrid", {
613
592
  enumerable: true,
614
593
  get: function() {
615
594
  return decryptKeysHybrid;
616
595
  }
617
596
  });
597
+ Object.defineProperty(exports, "decryptPreview", {
598
+ enumerable: true,
599
+ get: function() {
600
+ return decryptPreview;
601
+ }
602
+ });
618
603
  Object.defineProperty(exports, "decryptPwdProtectedEmail", {
619
604
  enumerable: true,
620
605
  get: function() {
@@ -651,12 +636,6 @@ Object.defineProperty(exports, "encryptEmailAndSubject", {
651
636
  return encryptEmailAndSubject;
652
637
  }
653
638
  });
654
- Object.defineProperty(exports, "encryptEmailAndSubjectHybrid", {
655
- enumerable: true,
656
- get: function() {
657
- return encryptEmailAndSubjectHybrid;
658
- }
659
- });
660
639
  Object.defineProperty(exports, "encryptEmailAndSubjectHybridForMultipleRecipients", {
661
640
  enumerable: true,
662
641
  get: function() {
@@ -669,12 +648,6 @@ Object.defineProperty(exports, "encryptEmailAndSubjectWithKey", {
669
648
  return encryptEmailAndSubjectWithKey;
670
649
  }
671
650
  });
672
- Object.defineProperty(exports, "encryptEmailHybrid", {
673
- enumerable: true,
674
- get: function() {
675
- return encryptEmailHybrid;
676
- }
677
- });
678
651
  Object.defineProperty(exports, "encryptEmailHybridForMultipleRecipients", {
679
652
  enumerable: true,
680
653
  get: function() {
@@ -724,4 +697,4 @@ Object.defineProperty(exports, "wrapKey", {
724
697
  }
725
698
  });
726
699
 
727
- //# sourceMappingURL=email-crypto-CPL8ept8.js.map
700
+ //# sourceMappingURL=email-crypto-DJb-I1wm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-crypto-DJb-I1wm.js","names":["genSymmetricKey","UTF8ToUint8","uint8ArrayToBase64","encryptSymmetrically","uint8ToUTF8","decryptSymmetrically","base64ToUint8Array","encapsulateHybrid","decapsulateHybrid","getKeyFromPassword","getKeyFromPasswordAndSalt","genSymmetricKey","uint8ArrayToBase64","encryptSymmetrically","UTF8ToUint8","uint8ToUTF8","decryptSymmetrically","base64ToUint8Array","genHybridKeys","deriveKeyFromMnemonic","CONTEXT_DATABASE","CONTEXT_DRAFT"],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/errors.ts","../src/email-crypto/core.ts","../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/coreSubject.ts","../src/email-crypto/hybridEncryptedEmailAndSubject.ts","../src/email-crypto/pwdProtectedEmailAndSubject.ts","../src/email-crypto/emailKeys.ts"],"sourcesContent":["import { aeskw } from '@noble/ciphers/aes.js';\n\n/**\n * Unwraps the given wrapped key\n *\n * @param encryptedKey - The wrapped key\n * @param wrappingKey - The secret key used for unwrapping\n * @returns The resulting key\n */\nexport async function unwrapKey(encryptedKey: Uint8Array, wrappingKey: Uint8Array): Promise<Uint8Array> {\n return aeskw(wrappingKey).decrypt(encryptedKey);\n}\n\n/**\n * Wraps the given key\n *\n * @param key - The key to be wrapped\n * @param wrappingKey - The secret key used for wrapping\n * @returns The resulting ciphertext\n */\nexport async function wrapKey(key: Uint8Array, wrappingKey: Uint8Array): Promise<Uint8Array> {\n return aeskw(wrappingKey).encrypt(key);\n}\n","export class FailedToEncryptEmail extends Error {\n constructor(errorMsg?: string) {\n super('Failed to encrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, FailedToEncryptEmail.prototype);\n }\n}\n\nexport class EmailSymmetricEncryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to symmetrically encrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailSymmetricEncryptionError.prototype);\n }\n}\n\nexport class EmailSymmetricDecryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to symmetrically decrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailSymmetricDecryptionError.prototype);\n }\n}\n\nexport class EmailPreviewSymmetricDecryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to symmetrically decrypt email preview: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailPreviewSymmetricDecryptionError.prototype);\n }\n}\n\nexport class EmailHybridEncryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to hybridly encrypt the key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailHybridEncryptionError.prototype);\n }\n}\n\nexport class EmailHybridDecryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to hybridly decrypt the key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailHybridDecryptionError.prototype);\n }\n}\n\nexport class EmailPasswordProtectError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to password-protect the key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailPasswordProtectError.prototype);\n }\n}\n\nexport class EmailPasswordOpenError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to open password-protected key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailPasswordOpenError.prototype);\n }\n}\n\nexport class InvalidInputEmail extends Error {\n constructor() {\n super('Invalid input');\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, InvalidInputEmail.prototype);\n }\n}\n\nexport class FailedToDecryptEmail extends Error {\n constructor(errorMsg?: string) {\n super('Failed to decrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, FailedToDecryptEmail.prototype);\n }\n}\n","import { HybridEncKey, PwdProtectedKey, Email, RecipientWithPublicKey, EmailEncrypted } from '../types';\nimport { encryptSymmetrically, decryptSymmetrically, genSymmetricKey } from '../symmetric-crypto';\nimport { encapsulateHybrid, decapsulateHybrid } from '../hybrid-crypto';\nimport { wrapKey, unwrapKey } from '../key-wrapper';\nimport { getKeyFromPassword, getKeyFromPasswordAndSalt } from '../derive-password';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8 } from '../utils';\nimport {\n EmailHybridDecryptionError,\n EmailHybridEncryptionError,\n InvalidInputEmail,\n EmailSymmetricDecryptionError,\n EmailSymmetricEncryptionError,\n EmailPasswordOpenError,\n EmailPasswordProtectError,\n EmailPreviewSymmetricDecryptionError,\n} from './errors';\n\n/**\n * Symmetrically encrypts email.\n *\n * @param email - The email to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email and symmetric key used for encryption\n */\nexport async function encryptEmail(\n email: Email,\n aux?: Uint8Array,\n): Promise<{\n encEmail: EmailEncrypted;\n encryptionKey: Uint8Array;\n}> {\n if (!email.text) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = genSymmetricKey();\n const encEmail = await encryptEmailWithKey(email, encryptionKey, aux);\n\n return { encEmail, encryptionKey };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Symmetrically encrypts email with the given key.\n *\n * @param email - The email to encrypt.\n * @param encryptionKey - The symmetric key to encrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email and symmetric key used for encryption\n */\nexport async function encryptEmailWithKey(\n email: Email,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailEncrypted> {\n try {\n const text = UTF8ToUint8(email.text);\n const preview = UTF8ToUint8(email.preview);\n\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n\n const encryptedPreview = await encryptSymmetrically(encryptionKey, preview, aux);\n const encPreview = uint8ArrayToBase64(encryptedPreview);\n\n const encryptedAttachmentsSessionKey = await encryptSymmetrically(encryptionKey, email.attachmentsSessionKey, aux);\n const encAttachmentsSessionKey = uint8ArrayToBase64(encryptedAttachmentsSessionKey);\n\n return { encText, encPreview, encAttachmentsSessionKey };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email preview.\n *\n * @param encEmailPreview - The email preview to decrypt.\n * @param encryptionKey - The symmetric key to decrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting decrypted email\n */\nexport async function decryptPreview(\n encEmailPreview: string,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<string> {\n try {\n const encPreview = base64ToUint8Array(encEmailPreview);\n const previewArray = await decryptSymmetrically(encryptionKey, encPreview, aux);\n const preview = uint8ToUTF8(previewArray);\n\n return preview;\n } catch (error) {\n throw new EmailPreviewSymmetricDecryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email.\n *\n * @param encEmail - The email to decrypt.\n * @param encryptionKey - The symmetric key to decrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting decrypted email\n */\nexport async function decryptEmail(\n encEmail: EmailEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<Email> {\n try {\n const encText = base64ToUint8Array(encEmail.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n\n const encPreview = base64ToUint8Array(encEmail.encPreview);\n const previewArray = await decryptSymmetrically(encryptionKey, encPreview, aux);\n const preview = uint8ToUTF8(previewArray);\n\n const encAttachementSessionKey = base64ToUint8Array(encEmail.encAttachmentsSessionKey);\n const attachmentsSessionKey = await decryptSymmetrically(encryptionKey, encAttachementSessionKey, aux);\n\n return { text, preview, attachmentsSessionKey };\n } catch (error) {\n throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Encrypts the email symmetric key using hybrid encryption.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param recipient - The recipient with a public hybrid key.\n * @returns The encrypted email symmetric key\n */\nexport async function encryptKeysHybrid(\n emailEncryptionKey: Uint8Array,\n recipient: RecipientWithPublicKey,\n): Promise<HybridEncKey> {\n try {\n const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);\n const encryptedKey = await wrapKey(emailEncryptionKey, sharedSecret);\n const encryptedKeyBase64 = uint8ArrayToBase64(encryptedKey);\n const kyberCiphertextBase64 = uint8ArrayToBase64(cipherText);\n\n return {\n encryptedKey: encryptedKeyBase64,\n hybridCiphertext: kyberCiphertextBase64,\n encryptedForEmail: recipient.email,\n };\n } catch (error) {\n throw new EmailHybridEncryptionError(error instanceof Error ? error.message : String(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 recipientPrivateKey - The private key of the recipient.\n * @returns The email encryption key\n */\nexport async function decryptKeysHybrid(\n encryptedKey: HybridEncKey,\n recipientPrivateKey: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);\n const encKey = base64ToUint8Array(encryptedKey.encryptedKey);\n const sharedSecret = decapsulateHybrid(kyberCiphertext, recipientPrivateKey);\n const encryptionKey = await unwrapKey(encKey, sharedSecret);\n return encryptionKey;\n } catch (error) {\n throw new EmailHybridDecryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric key 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: Uint8Array, password: string): Promise<PwdProtectedKey> {\n try {\n const { key, salt } = await getKeyFromPassword(password);\n const encryptedKey = await wrapKey(emailEncryptionKey, key);\n const saltStr = uint8ArrayToBase64(salt);\n const encryptedKeyStr = uint8ArrayToBase64(encryptedKey);\n return { encryptedKey: encryptedKeyStr, salt: saltStr };\n } catch (error) {\n throw new EmailPasswordProtectError(error instanceof Error ? error.message : String(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 key\n */\nexport async function removePasswordProtection(\n emailEncryptionKey: PwdProtectedKey,\n password: string,\n): Promise<Uint8Array> {\n try {\n const salt = base64ToUint8Array(emailEncryptionKey.salt);\n const encryptedKey = base64ToUint8Array(emailEncryptionKey.encryptedKey);\n const key = await getKeyFromPasswordAndSalt(password, salt);\n const encryptionKey = await unwrapKey(encryptedKey, key);\n return encryptionKey;\n } catch (error) {\n throw new EmailPasswordOpenError(error instanceof Error ? error.message : String(error));\n }\n}\n","import { Email, RecipientWithPublicKey, HybridEncKey, EmailEncrypted } from '../types';\nimport { decryptEmail, decryptPreview, encryptKeysHybrid, decryptKeysHybrid, encryptEmail } from './core';\nimport { InvalidInputEmail } from './errors';\n\n/**\n * Encrypts the email using hybrid encryption for multiple recipients.\n *\n * @param email - The email to encrypt for multiple recipients.\n * @param recipients - The recipients with corresponding public keys.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The set of encrypted keys (one per user) and encrypted email\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n email: Email,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<{ encryptedKeys: HybridEncKey[]; encEmail: EmailEncrypted }> {\n if (!recipients || recipients.length === 0) {\n throw new InvalidInputEmail();\n }\n const { encryptionKey, encEmail } = await encryptEmail(email, aux);\n\n const encryptedKeys = await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient)));\n\n return { encryptedKeys, encEmail };\n}\n\n/**\n * Decrypts the email using hybrid encryption.\n *\n * @param encEmail - The encrypted email.\n * @param encryptedKey - The encrypted key for this recipient.\n * @param recipientPrivateHybridKeys - The private key of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email\n */\nexport async function decryptEmailHybrid(\n encEmail: EmailEncrypted,\n encryptedKey: HybridEncKey,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<Email> {\n const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);\n return await decryptEmail(encEmail, encryptionKey, aux);\n}\n\nexport async function decryptEmailPreviewHybrid(\n encPreview: string,\n encryptedKey: HybridEncKey,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<{ preview: string; encryptionKey: Uint8Array }> {\n const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);\n const preview = await decryptPreview(encPreview, encryptionKey, aux);\n return { preview, encryptionKey };\n}\n","import { PwdProtectedEmail, Email } from '../types';\nimport { decryptEmail, passwordProtectKey, removePasswordProtection, encryptEmail } from './core';\nimport {\n EmailSymmetricEncryptionError,\n FailedToDecryptEmail,\n FailedToEncryptEmail,\n EmailPasswordProtectError,\n EmailSymmetricDecryptionError,\n EmailPasswordOpenError,\n InvalidInputEmail,\n} from './errors';\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 aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The password-protected email\n */\nexport async function createPwdProtectedEmail(\n email: Email,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmail } = await encryptEmail(email, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmail, encryptedKey };\n } catch (error) {\n if (error instanceof InvalidInputEmail) throw error;\n if (error instanceof EmailSymmetricEncryptionError) throw error;\n if (error instanceof EmailPasswordProtectError) throw error;\n throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(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 * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<Email> {\n if (!encryptedEmail?.encEmail || !encryptedEmail?.encryptedKey) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n return await decryptEmail(encryptedEmail.encEmail, encryptionKey, aux);\n } catch (error) {\n if (error instanceof EmailPasswordOpenError) throw error;\n if (error instanceof EmailSymmetricDecryptionError) throw error;\n throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));\n }\n}\n","import { EmailAndSubject, EmailAndSubjectEncrypted } from '../types';\nimport { encryptSymmetrically, decryptSymmetrically, genSymmetricKey } from '../symmetric-crypto';\nimport { encryptEmailWithKey, decryptEmail } from './core';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8 } from '../utils';\nimport { InvalidInputEmail, EmailSymmetricDecryptionError, EmailSymmetricEncryptionError } from './errors';\n\n/**\n * Symmetrically encrypts email and subject.\n *\n * @param email - The email and subject to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email and symmetric key used for encryption\n */\nexport async function encryptEmailAndSubject(\n email: EmailAndSubject,\n aux?: Uint8Array,\n): Promise<{\n encEmail: EmailAndSubjectEncrypted;\n encryptionKey: Uint8Array;\n}> {\n if (!email.text || !email.subject) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = genSymmetricKey();\n const encEmail = await encryptEmailAndSubjectWithKey(email, encryptionKey, aux);\n\n return { encEmail, encryptionKey };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Symmetrically encrypts email and subject with the given key.\n *\n * @param email - The email and subject to encrypt.\n * @param encryptionKey - The symmetric key to encrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email and symmetric key used for encryption\n */\nexport async function encryptEmailAndSubjectWithKey(\n email: EmailAndSubject,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailAndSubjectEncrypted> {\n try {\n const enc = await encryptEmailWithKey(email, encryptionKey, aux);\n const subject = UTF8ToUint8(email.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n\n return { ...enc, encSubject };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email and email subject.\n *\n * @param encEmail - The encrypted email and subject to decrypt.\n * @param encryptionKey - The symmetric key to decrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting decrypted email and subject\n */\nexport async function decryptEmailAndSubject(\n encEmail: EmailAndSubjectEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailAndSubject> {\n try {\n const encSubject = base64ToUint8Array(encEmail.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const email = await decryptEmail(encEmail, encryptionKey, aux);\n\n return { ...email, subject };\n } catch (error) {\n throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n","import { RecipientWithPublicKey, EmailAndSubject, EmailAndSubjectEncrypted, HybridEncKey } from '../types';\nimport { encryptKeysHybrid, decryptKeysHybrid } from './core';\nimport { encryptEmailAndSubject, decryptEmailAndSubject } from './coreSubject';\nimport {\n InvalidInputEmail,\n} from './errors';\n\n/**\n * Encrypts the email and its subject using hybrid encryption for multiple recipients.\n *\n * @param email - The email and subject to encrypt for multiple recipients.\n * @param recipients - The recipients with corresponding public keys.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The set of encrypted keys and encrypted email and subject\n */\nexport async function encryptEmailAndSubjectHybridForMultipleRecipients(\n email: EmailAndSubject,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<{ encryptedKeys: HybridEncKey[]; encEmail: EmailAndSubjectEncrypted }> {\n if (!recipients || recipients.length === 0) {\n throw new InvalidInputEmail();\n }\n const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);\n\n const encryptedKeys = await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient)));\n\n return { encEmail, encryptedKeys };\n}\n\n/**\n * Decrypts the email and its subject using hybrid encryption.\n *\n * @param encEmail - The encrypted email and subject.\n * @param encryptedKey - The encrypted key for this recipient.\n * @param recipientPrivateHybridKeys - The private key of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email and subject\n */\nexport async function decryptEmailAndSubjectHybrid(\n encEmail: EmailAndSubjectEncrypted,\n encryptedKey: HybridEncKey,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailAndSubject> {\n const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);\n return await decryptEmailAndSubject(encEmail, encryptionKey, aux);\n}\n","import { EmailAndSubject, PwdProtectedEmailAndSubject } from '../types';\nimport { passwordProtectKey, removePasswordProtection } from './core';\nimport { encryptEmailAndSubject, decryptEmailAndSubject } from './coreSubject';\nimport {\n FailedToDecryptEmail,\n FailedToEncryptEmail,\n InvalidInputEmail,\n EmailPasswordOpenError,\n EmailPasswordProtectError,\n EmailSymmetricDecryptionError,\n EmailSymmetricEncryptionError,\n} from './errors';\n\n/**\n * Creates a password-protected email and subject.\n *\n * @param email - The email and subject to password-protect\n * @param password - The secret password shared among recipients\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The password-protected email\n */\nexport async function createPwdProtectedEmailAndSubject(\n email: EmailAndSubject,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmailAndSubject> {\n try {\n const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmail, encryptedKey };\n } catch (error) {\n if (error instanceof InvalidInputEmail) throw error;\n if (error instanceof EmailSymmetricEncryptionError) throw error;\n if (error instanceof EmailPasswordProtectError) throw error;\n throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Opens a password-protected email and subject.\n *\n * @param encryptedEmail - The encrypted email and subject\n * @param password - The secret password shared among recipients.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email and subject\n */\nexport async function decryptPwdProtectedEmailAndSubject(\n encryptedEmail: PwdProtectedEmailAndSubject,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailAndSubject> {\n if (!encryptedEmail?.encEmail || !encryptedEmail?.encryptedKey) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n return await decryptEmailAndSubject(encryptedEmail.encEmail, encryptionKey, aux);\n } catch (error) {\n if (error instanceof EmailPasswordOpenError) throw error;\n if (error instanceof EmailSymmetricDecryptionError) throw error;\n throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\nimport { deriveKeyFromMnemonic } from '../derive-key';\nimport { CONTEXT_DATABASE, CONTEXT_DRAFT } from '../constants';\n\n/**\n * Generates public and private keys for email encryption.\n *\n * @returns The user's private and public keys\n */\nexport async function generateEmailKeys(): Promise<HybridKeyPair> {\n return genHybridKeys();\n}\n\n/**\n * Derives database encryption key for the given user\n *\n * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)\n * @returns The symmetric key for protecting database\n */\nexport const deriveDatabaseKey = async (mnemonic: string): Promise<Uint8Array> => {\n return deriveKeyFromMnemonic(mnemonic, CONTEXT_DATABASE);\n};\n\n/**\n * Derives email draft encryption key for the given user\n *\n * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)\n * @returns The symmetric key for protecting email drafts\n */\nexport const deriveEmailDraftKey = async (mnemonic: string): Promise<Uint8Array> => {\n return deriveKeyFromMnemonic(mnemonic, CONTEXT_DRAFT);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AASA,eAAsB,UAAU,cAA0B,aAA8C;AACtG,SAAA,GAAA,sBAAA,OAAa,YAAY,CAAC,QAAQ,aAAa;;;;;;;;;AAUjD,eAAsB,QAAQ,KAAiB,aAA8C;AAC3F,SAAA,GAAA,sBAAA,OAAa,YAAY,CAAC,QAAQ,IAAI;;;;ACrBxC,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC9C,YAAY,UAAmB;AAC7B,QAAM,8BAA8B,SAAS;AAE7C,OAAK,OAAO,KAAK,YAAY;AAC7B,SAAO,eAAe,MAAM,qBAAqB,UAAU;;;AAI/D,IAAa,gCAAb,MAAa,sCAAsC,MAAM;CACvD,YAAY,UAAmB;AAC7B,QAAM,4CAA4C,SAAS;AAE3D,OAAK,OAAO,KAAK,YAAY;AAC7B,SAAO,eAAe,MAAM,8BAA8B,UAAU;;;AAIxE,IAAa,gCAAb,MAAa,sCAAsC,MAAM;CACvD,YAAY,UAAmB;AAC7B,QAAM,4CAA4C,SAAS;AAE3D,OAAK,OAAO,KAAK,YAAY;AAC7B,SAA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AAM,UAAU,OAAO,MAAM,CAAC;;;;;;;;;;ACnD1F,eAAsB,oBAA4C;AAChE,QAAOC,cAAAA,eAAe;;;;;;;;AASxB,MAAa,oBAAoB,OAAO,aAA0C;AAChF,QAAOC,mBAAAA,sBAAsB,UAAUC,kBAAAA,iBAAiB;;;;;;;;AAS1D,MAAa,sBAAsB,OAAO,aAA0C;AAClF,QAAOD,mBAAAA,sBAAsB,UAAUE,kBAAAA,cAAc"}
@@ -1,33 +1,32 @@
1
- import { c as HybridEncryptedEmailAndSubject, d as PwdProtectedEmail, f as PwdProtectedEmailAndSubject, i as EmailEncrypted, l as HybridKeyPair, m as RecipientWithPublicKey, n as EmailAndSubject, o as HybridEncKey, p as PwdProtectedKey, r as EmailAndSubjectEncrypted, s as HybridEncryptedEmail, t as Email } from "./types-cEyToM9T.mjs";
1
+ import { d as PwdProtectedKey, f as RecipientWithPublicKey, i as EmailEncrypted, l as PwdProtectedEmail, n as EmailAndSubject, o as HybridEncKey, r as EmailAndSubjectEncrypted, s as HybridKeyPair, t as Email, u as PwdProtectedEmailAndSubject } from "./types-D1R4_m5r.mjs";
2
2
 
3
3
  //#region src/email-crypto/hybridEncyptedEmail.d.ts
4
- /**
5
- * Encrypts the email using hybrid encryption.
6
- *
7
- * @param email - The email to encrypt.
8
- * @param recipientPublicKeys - The public keys of the recipient.
9
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
10
- * @returns The encrypted email
11
- */
12
- declare function encryptEmailHybrid(email: Email, recipient: RecipientWithPublicKey, aux?: Uint8Array): Promise<HybridEncryptedEmail>;
13
4
  /**
14
5
  * Encrypts the email using hybrid encryption for multiple recipients.
15
6
  *
16
7
  * @param email - The email to encrypt for multiple recipients.
17
8
  * @param recipients - The recipients with corresponding public keys.
18
9
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
19
- * @returns The set of encrypted emails
10
+ * @returns The set of encrypted keys (one per user) and encrypted email
20
11
  */
21
- declare function encryptEmailHybridForMultipleRecipients(email: Email, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<HybridEncryptedEmail[]>;
12
+ declare function encryptEmailHybridForMultipleRecipients(email: Email, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<{
13
+ encryptedKeys: HybridEncKey[];
14
+ encEmail: EmailEncrypted;
15
+ }>;
22
16
  /**
23
17
  * Decrypts the email using hybrid encryption.
24
18
  *
25
19
  * @param encEmail - The encrypted email.
20
+ * @param encryptedKey - The encrypted key for this recipient.
26
21
  * @param recipientPrivateHybridKeys - The private key of the recipient.
27
22
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
28
23
  * @returns The decrypted email
29
24
  */
30
- declare function decryptEmailHybrid(encEmail: HybridEncryptedEmail, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<Email>;
25
+ declare function decryptEmailHybrid(encEmail: EmailEncrypted, encryptedKey: HybridEncKey, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<Email>;
26
+ declare function decryptEmailPreviewHybrid(encPreview: string, encryptedKey: HybridEncKey, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<{
27
+ preview: string;
28
+ encryptionKey: Uint8Array;
29
+ }>;
31
30
  //#endregion
32
31
  //#region src/email-crypto/pwdProtectedEmail.d.ts
33
32
  /**
@@ -50,33 +49,28 @@ declare function createPwdProtectedEmail(email: Email, password: string, aux?: U
50
49
  declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string, aux?: Uint8Array): Promise<Email>;
51
50
  //#endregion
52
51
  //#region src/email-crypto/hybridEncryptedEmailAndSubject.d.ts
53
- /**
54
- * Encrypts the email and its subject using hybrid encryption.
55
- *
56
- * @param email - The email and subject to encrypt.
57
- * @param recipientPublicKeys - The public keys of the recipient.
58
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
59
- * @returns The encrypted email and subject
60
- */
61
- declare function encryptEmailAndSubjectHybrid(email: EmailAndSubject, recipient: RecipientWithPublicKey, aux?: Uint8Array): Promise<HybridEncryptedEmailAndSubject>;
62
52
  /**
63
53
  * Encrypts the email and its subject using hybrid encryption for multiple recipients.
64
54
  *
65
55
  * @param email - The email and subject to encrypt for multiple recipients.
66
56
  * @param recipients - The recipients with corresponding public keys.
67
57
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
68
- * @returns The set of encrypted emails and subjects
58
+ * @returns The set of encrypted keys and encrypted email and subject
69
59
  */
70
- declare function encryptEmailAndSubjectHybridForMultipleRecipients(email: EmailAndSubject, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<HybridEncryptedEmailAndSubject[]>;
60
+ declare function encryptEmailAndSubjectHybridForMultipleRecipients(email: EmailAndSubject, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<{
61
+ encryptedKeys: HybridEncKey[];
62
+ encEmail: EmailAndSubjectEncrypted;
63
+ }>;
71
64
  /**
72
65
  * Decrypts the email and its subject using hybrid encryption.
73
66
  *
74
- * @param hybridEmail - The encrypted email and subject.
67
+ * @param encEmail - The encrypted email and subject.
68
+ * @param encryptedKey - The encrypted key for this recipient.
75
69
  * @param recipientPrivateHybridKeys - The private key of the recipient.
76
70
  * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
77
71
  * @returns The decrypted email and subject
78
72
  */
79
- declare function decryptEmailAndSubjectHybrid(hybridEmail: HybridEncryptedEmailAndSubject, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<EmailAndSubject>;
73
+ declare function decryptEmailAndSubjectHybrid(encEmail: EmailAndSubjectEncrypted, encryptedKey: HybridEncKey, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<EmailAndSubject>;
80
74
  //#endregion
81
75
  //#region src/email-crypto/pwdProtectedEmailAndSubject.d.ts
82
76
  /**
@@ -141,6 +135,15 @@ declare function encryptEmail(email: Email, aux?: Uint8Array): Promise<{
141
135
  * @returns The resulting encrypted email and symmetric key used for encryption
142
136
  */
143
137
  declare function encryptEmailWithKey(email: Email, encryptionKey: Uint8Array, aux?: Uint8Array): Promise<EmailEncrypted>;
138
+ /**
139
+ * Decrypts symmetrically encrypted email preview.
140
+ *
141
+ * @param encEmailPreview - The email preview to decrypt.
142
+ * @param encryptionKey - The symmetric key to decrypt the email.
143
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
144
+ * @returns The resulting decrypted email
145
+ */
146
+ declare function decryptPreview(encEmailPreview: string, encryptionKey: Uint8Array, aux?: Uint8Array): Promise<string>;
144
147
  /**
145
148
  * Decrypts symmetrically encrypted email.
146
149
  *
@@ -224,6 +227,9 @@ declare class EmailSymmetricEncryptionError extends Error {
224
227
  declare class EmailSymmetricDecryptionError extends Error {
225
228
  constructor(errorMsg?: string);
226
229
  }
230
+ declare class EmailPreviewSymmetricDecryptionError extends Error {
231
+ constructor(errorMsg?: string);
232
+ }
227
233
  declare class EmailHybridEncryptionError extends Error {
228
234
  constructor(errorMsg?: string);
229
235
  }
@@ -243,5 +249,5 @@ declare class FailedToDecryptEmail extends Error {
243
249
  constructor(errorMsg?: string);
244
250
  }
245
251
  //#endregion
246
- export { EmailHybridDecryptionError, EmailHybridEncryptionError, EmailPasswordOpenError, EmailPasswordProtectError, EmailSymmetricDecryptionError, EmailSymmetricEncryptionError, FailedToDecryptEmail, FailedToEncryptEmail, InvalidInputEmail, createPwdProtectedEmail, createPwdProtectedEmailAndSubject, decryptEmail, decryptEmailAndSubject, decryptEmailAndSubjectHybrid, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, decryptPwdProtectedEmailAndSubject, deriveDatabaseKey, deriveEmailDraftKey, encryptEmail, encryptEmailAndSubject, encryptEmailAndSubjectHybrid, encryptEmailAndSubjectHybridForMultipleRecipients, encryptEmailAndSubjectWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptEmailWithKey, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
252
+ export { EmailHybridDecryptionError, EmailHybridEncryptionError, EmailPasswordOpenError, EmailPasswordProtectError, EmailPreviewSymmetricDecryptionError, EmailSymmetricDecryptionError, EmailSymmetricEncryptionError, FailedToDecryptEmail, FailedToEncryptEmail, InvalidInputEmail, createPwdProtectedEmail, createPwdProtectedEmailAndSubject, decryptEmail, decryptEmailAndSubject, decryptEmailAndSubjectHybrid, decryptEmailHybrid, decryptEmailPreviewHybrid, decryptKeysHybrid, decryptPreview, decryptPwdProtectedEmail, decryptPwdProtectedEmailAndSubject, deriveDatabaseKey, deriveEmailDraftKey, encryptEmail, encryptEmailAndSubject, encryptEmailAndSubjectHybridForMultipleRecipients, encryptEmailAndSubjectWithKey, encryptEmailHybridForMultipleRecipients, encryptEmailWithKey, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
247
253
  //# sourceMappingURL=email-crypto.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/hybridEncryptedEmailAndSubject.ts","../src/email-crypto/pwdProtectedEmailAndSubject.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/core.ts","../src/email-crypto/coreSubject.ts","../src/email-crypto/errors.ts"],"mappings":";;;;;AAmBA;;;;;;iBAAsB,kBAAA,CACpB,KAAA,EAAO,KAAA,EACP,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAqBW,uCAAA,CACpB,KAAA,EAAO,KAAA,EACP,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBAoCsB,kBAAA,CACpB,QAAA,EAAU,oBAAA,EACV,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,KAAA;;;;;AAjEX;;;;;;iBCAsB,uBAAA,CAC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,SAA+B,KAAA;cAC9B,QAAA;AAAA;AAAA,cAOD,iBAAA,SAA0B,KAAA;EAAA,WAAA,CAAA;AAAA;AAAA,cAQ1B,oBAAA,SAA6B,KAAA;cAC5B,QAAA;AAAA"}
1
+ {"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/hybridEncryptedEmailAndSubject.ts","../src/email-crypto/pwdProtectedEmailAndSubject.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/core.ts","../src/email-crypto/coreSubject.ts","../src/email-crypto/errors.ts"],"mappings":";;;;;AAYA;;;;;;iBAAsB,uCAAA,CACpB,KAAA,EAAO,KAAA,EACP,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA;EAAU,aAAA,EAAe,YAAA;EAAgB,QAAA,EAAU,cAAA;AAAA;;;;;;;;;;iBAoBhC,kBAAA,CACpB,QAAA,EAAU,cAAA,EACV,YAAA,EAAc,YAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,KAAA;AAAA,iBAKW,yBAAA,CACpB,UAAA,UACA,YAAA,EAAc,YAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA;EAAU,OAAA;EAAiB,aAAA,EAAe,UAAA;AAAA;;;;;AAvC7C;;;;;;iBCOsB,uBAAA,CACpB,KAAA,EAAO,KAAA,EACP,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAsBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,KAAA;;;;;ADrCX;;;;;;iBEGsB,iDAAA,CACpB,KAAA,EAAO,eAAA,EACP,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA;EAAU,a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