internxt-crypto 0.0.13 → 1.0.0

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 (154) hide show
  1. package/README.md +44 -72
  2. package/dist/aes-B8TA-JKq.mjs +49 -0
  3. package/dist/aes-B8TA-JKq.mjs.map +1 -0
  4. package/dist/aes-CuW_SPl-.js +67 -0
  5. package/dist/aes-CuW_SPl-.js.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +8 -31
  7. package/dist/asymmetric-crypto.d.mts.map +1 -1
  8. package/dist/asymmetric-crypto.d.ts +8 -31
  9. package/dist/asymmetric-crypto.d.ts.map +1 -1
  10. package/dist/asymmetric-crypto.js +30 -7
  11. package/dist/asymmetric-crypto.js.map +1 -0
  12. package/dist/asymmetric-crypto.mjs +28 -2
  13. package/dist/asymmetric-crypto.mjs.map +1 -0
  14. package/dist/constants.d.mts +7 -14
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.d.ts +7 -14
  17. package/dist/constants.d.ts.map +1 -1
  18. package/dist/constants.js +11 -25
  19. package/dist/constants.js.map +1 -1
  20. package/dist/constants.mjs +7 -14
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/core-Bj26rNdA.js +227 -0
  23. package/dist/core-Bj26rNdA.js.map +1 -0
  24. package/dist/core-pEGygy6S.mjs +173 -0
  25. package/dist/core-pEGygy6S.mjs.map +1 -0
  26. package/dist/derive-key.d.mts +1 -74
  27. package/dist/derive-key.d.mts.map +1 -1
  28. package/dist/derive-key.d.ts +1 -74
  29. package/dist/derive-key.d.ts.map +1 -1
  30. package/dist/derive-key.js +3 -11
  31. package/dist/derive-key.mjs +2 -2
  32. package/dist/derive-password.d.mts +22 -0
  33. package/dist/derive-password.d.mts.map +1 -0
  34. package/dist/derive-password.d.ts +22 -0
  35. package/dist/derive-password.d.ts.map +1 -0
  36. package/dist/derive-password.js +5 -0
  37. package/dist/derive-password.mjs +3 -0
  38. package/dist/deriveKeysFromKey-C4McqO6_.js +47 -0
  39. package/dist/deriveKeysFromKey-C4McqO6_.js.map +1 -0
  40. package/dist/deriveKeysFromKey-DPU_h7wr.mjs +35 -0
  41. package/dist/deriveKeysFromKey-DPU_h7wr.mjs.map +1 -0
  42. package/dist/{deriveKeysFromPassword-Ko7NxkHM.js → deriveKeysFromPassword-C7xAGGsh.js} +5 -177
  43. package/dist/deriveKeysFromPassword-C7xAGGsh.js.map +1 -0
  44. package/dist/{deriveKeysFromPassword-DJRWZ8Rw.mjs → deriveKeysFromPassword-DXgSvTNC.mjs} +7 -131
  45. package/dist/deriveKeysFromPassword-DXgSvTNC.mjs.map +1 -0
  46. package/dist/email-crypto.d.mts +24 -46
  47. package/dist/email-crypto.d.mts.map +1 -1
  48. package/dist/email-crypto.d.ts +24 -46
  49. package/dist/email-crypto.d.ts.map +1 -1
  50. package/dist/email-crypto.js +121 -12
  51. package/dist/email-crypto.js.map +1 -0
  52. package/dist/email-crypto.mjs +115 -2
  53. package/dist/email-crypto.mjs.map +1 -0
  54. package/dist/email-search.d.mts +18 -18
  55. package/dist/email-search.d.mts.map +1 -1
  56. package/dist/email-search.d.ts +18 -18
  57. package/dist/email-search.d.ts.map +1 -1
  58. package/dist/email-search.js +25 -597
  59. package/dist/email-search.mjs +2 -573
  60. package/dist/{emailEncryptionKey-27mIHh18.mjs → emailEncryptionKey-BtSPYd9M.mjs} +23 -46
  61. package/dist/emailEncryptionKey-BtSPYd9M.mjs.map +1 -0
  62. package/dist/{emailEncryptionKey-DbaDAdoW.js → emailEncryptionKey-C4X1Bwy4.js} +22 -45
  63. package/dist/emailEncryptionKey-C4X1Bwy4.js.map +1 -0
  64. package/dist/{genID-3Er5IowC.mjs → genID-D08K7JPr.mjs} +4 -40
  65. package/dist/genID-D08K7JPr.mjs.map +1 -0
  66. package/dist/{genID-YJSl3YhL.js → genID-cWOPmspk.js} +2 -50
  67. package/dist/genID-cWOPmspk.js.map +1 -0
  68. package/dist/hash.d.mts +24 -36
  69. package/dist/hash.d.mts.map +1 -1
  70. package/dist/hash.d.ts +24 -36
  71. package/dist/hash.d.ts.map +1 -1
  72. package/dist/hash.js +88 -10
  73. package/dist/hash.js.map +1 -0
  74. package/dist/hash.mjs +82 -2
  75. package/dist/hash.mjs.map +1 -0
  76. package/dist/index.d.mts +17 -16
  77. package/dist/index.d.mts.map +1 -1
  78. package/dist/index.d.ts +17 -16
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +60 -83
  81. package/dist/index.mjs +13 -11
  82. package/dist/keystore-crypto.d.mts +6 -6
  83. package/dist/keystore-crypto.d.mts.map +1 -1
  84. package/dist/keystore-crypto.d.ts +6 -6
  85. package/dist/keystore-crypto.d.ts.map +1 -1
  86. package/dist/keystore-crypto.js +1 -1
  87. package/dist/keystore-crypto.mjs +1 -1
  88. package/dist/post-quantum-crypto.d.mts +5 -41
  89. package/dist/post-quantum-crypto.d.mts.map +1 -1
  90. package/dist/post-quantum-crypto.d.ts +5 -41
  91. package/dist/post-quantum-crypto.d.ts.map +1 -1
  92. package/dist/post-quantum-crypto.js +49 -16
  93. package/dist/post-quantum-crypto.js.map +1 -0
  94. package/dist/post-quantum-crypto.mjs +46 -2
  95. package/dist/post-quantum-crypto.mjs.map +1 -0
  96. package/dist/search-B9YM3XAA.mjs +587 -0
  97. package/dist/search-B9YM3XAA.mjs.map +1 -0
  98. package/dist/search-DUTm4-rN.js +731 -0
  99. package/dist/search-DUTm4-rN.js.map +1 -0
  100. package/dist/symmetric-crypto.d.mts +13 -42
  101. package/dist/symmetric-crypto.d.mts.map +1 -1
  102. package/dist/symmetric-crypto.d.ts +13 -42
  103. package/dist/symmetric-crypto.d.ts.map +1 -1
  104. package/dist/symmetric-crypto.js +2 -6
  105. package/dist/symmetric-crypto.mjs +2 -2
  106. package/dist/types.d.mts +16 -39
  107. package/dist/types.d.mts.map +1 -1
  108. package/dist/types.d.ts +16 -39
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/types.js.map +1 -1
  111. package/dist/types.mjs.map +1 -1
  112. package/dist/utils.d.mts +1 -19
  113. package/dist/utils.d.mts.map +1 -1
  114. package/dist/utils.d.ts +1 -19
  115. package/dist/utils.d.ts.map +1 -1
  116. package/dist/utils.js +1 -3
  117. package/dist/utils.mjs +2 -2
  118. package/dist/xwing-CQmQX6hn.mjs +16 -0
  119. package/dist/xwing-CQmQX6hn.mjs.map +1 -0
  120. package/dist/xwing-iRWVRtNE.js +34 -0
  121. package/dist/xwing-iRWVRtNE.js.map +1 -0
  122. package/package.json +4 -2
  123. package/dist/aes-DSDxP8uF.mjs +0 -184
  124. package/dist/aes-DSDxP8uF.mjs.map +0 -1
  125. package/dist/aes-bOrKZuUC.js +0 -226
  126. package/dist/aes-bOrKZuUC.js.map +0 -1
  127. package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs.map +0 -1
  128. package/dist/deriveKeysFromPassword-Ko7NxkHM.js.map +0 -1
  129. package/dist/email-search.js.map +0 -1
  130. package/dist/email-search.mjs.map +0 -1
  131. package/dist/emailEncryptionKey-27mIHh18.mjs.map +0 -1
  132. package/dist/emailEncryptionKey-DbaDAdoW.js.map +0 -1
  133. package/dist/emailKeys-BJGdkLrg.js +0 -593
  134. package/dist/emailKeys-BJGdkLrg.js.map +0 -1
  135. package/dist/emailKeys-Fp9WR3wl.mjs +0 -509
  136. package/dist/emailKeys-Fp9WR3wl.mjs.map +0 -1
  137. package/dist/genID-3Er5IowC.mjs.map +0 -1
  138. package/dist/genID-YJSl3YhL.js.map +0 -1
  139. package/dist/keys-BfcaiAOv.mjs +0 -90
  140. package/dist/keys-BfcaiAOv.mjs.map +0 -1
  141. package/dist/keys-CinT7kEY.js +0 -125
  142. package/dist/keys-CinT7kEY.js.map +0 -1
  143. package/dist/kyber1024-PpwE1rki.mjs +0 -144
  144. package/dist/kyber1024-PpwE1rki.mjs.map +0 -1
  145. package/dist/kyber1024-jeKS8CXf.js +0 -173
  146. package/dist/kyber1024-jeKS8CXf.js.map +0 -1
  147. package/dist/kyber768-DGBB_RS7.d.ts +0 -32
  148. package/dist/kyber768-DGBB_RS7.d.ts.map +0 -1
  149. package/dist/kyber768-DzIcGg1i.d.mts +0 -32
  150. package/dist/kyber768-DzIcGg1i.d.mts.map +0 -1
  151. package/dist/mac-BMb1F0dN.js +0 -170
  152. package/dist/mac-BMb1F0dN.js.map +0 -1
  153. package/dist/mac-ZpRlx8Fs.mjs +0 -116
  154. package/dist/mac-ZpRlx8Fs.mjs.map +0 -1
@@ -1,35 +1,33 @@
1
- import { Email, EmailKeys, EmailPublicParameters, HybridEncryptedEmail, PrivateKeys, PublicKeys, PwdProtectedEmail, User, UserWithPublicKeys } from "./types.mjs";
1
+ import { EmailBody, HybridEncryptedEmail, HybridKeyPair, PwdProtectedEmail, RecipientWithPublicKey } from "./types.mjs";
2
2
 
3
3
  //#region src/email-crypto/hybridEncyptedEmail.d.ts
4
4
  /**
5
- * Encrypts the email using hybrid encryption.
5
+ * Encrypts the email body using hybrid encryption.
6
6
  *
7
- * @param email - The email to encrypt.
7
+ * @param body - The email body to encrypt.
8
8
  * @param recipientPublicKeys - The public keys of the recipient.
9
- * @param senderPrivateKey - The private key of the sender.
10
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
11
- * @returns The encrypted email
9
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
10
+ * @returns The encrypted email body
12
11
  */
13
- declare function encryptEmailHybrid(email: Email, recipient: UserWithPublicKeys, senderPrivateKey: PrivateKeys, isSubjectEncrypted?: boolean): Promise<HybridEncryptedEmail>;
12
+ declare function encryptEmailHybrid(body: EmailBody, recipient: RecipientWithPublicKey, aux?: Uint8Array): Promise<HybridEncryptedEmail>;
14
13
  /**
15
- * Encrypts the email using hybrid encryption for multiple recipients.
14
+ * Encrypts the email body using hybrid encryption for multiple recipients.
16
15
  *
17
- * @param email - The email to encrypt.
16
+ * @param body - The email body to encrypt for multiple recipients.
18
17
  * @param recipients - The recipients with corresponding public keys.
19
- * @param senderPrivateKey - The private key of the sender.
20
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
21
- * @returns The set of encrypted email
18
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
19
+ * @returns The set of encrypted email bodies
22
20
  */
23
- declare function encryptEmailHybridForMultipleRecipients(email: Email, recipients: UserWithPublicKeys[], senderPrivateKey: PrivateKeys, isSubjectEncrypted?: boolean): Promise<HybridEncryptedEmail[]>;
21
+ declare function encryptEmailHybridForMultipleRecipients(body: EmailBody, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<HybridEncryptedEmail[]>;
24
22
  /**
25
23
  * Decrypts the email using hybrid encryption.
26
24
  *
27
- * @param encryptedEmail - The encrypted email.
28
- * @param senderPublicKeys - The public key of the sender.
29
- * @param recipientPrivateKeys - The private key of the recipient.
30
- * @returns The decrypted email
25
+ * @param encEmailBody - The encrypted email.
26
+ * @param recipientPrivateHybridKeys - The private key of the recipient.
27
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
28
+ * @returns The decrypted email body
31
29
  */
32
- declare function decryptEmailHybrid(encryptedEmail: HybridEncryptedEmail, senderPublicKeys: PublicKeys, recipientPrivateKeys: PrivateKeys): Promise<Email>;
30
+ declare function decryptEmailHybrid(encEmailBody: HybridEncryptedEmail, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<EmailBody>;
33
31
  //#endregion
34
32
  //#region src/email-crypto/pwdProtectedEmail.d.ts
35
33
  /**
@@ -37,47 +35,27 @@ declare function decryptEmailHybrid(encryptedEmail: HybridEncryptedEmail, sender
37
35
  *
38
36
  * @param email - The email to password-protect
39
37
  * @param password - The secret password shared among recipients
40
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
38
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
41
39
  * @returns The password-protected email
42
40
  */
43
- declare function createPwdProtectedEmail(email: Email, password: string, isSubjectEncrypted?: boolean): Promise<PwdProtectedEmail>;
41
+ declare function createPwdProtectedEmail(emailBody: EmailBody, password: string, aux?: Uint8Array): Promise<PwdProtectedEmail>;
44
42
  /**
45
43
  * Opens a password-protected email.
46
44
  *
47
45
  * @param encryptedEmail - The encrypted email
48
46
  * @param password - The secret password shared among recipients.
49
- * @returns The decrypted email
47
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
48
+ * @returns The decrypted email body
50
49
  */
51
- declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string): Promise<Email>;
52
- //#endregion
53
- //#region src/email-crypto/converters.d.ts
54
- declare function userToBytes(user: User): Uint8Array;
55
- declare function recipientsToBytes(recipients: User[]): Uint8Array;
56
- /**
57
- * Converts an Email type into a Uint8Array array.
58
- *
59
- * @param email - The email.
60
- * @returns The Uint8Array array representation of the Email type.
61
- */
62
- declare function emailToBinary(email: Email): Uint8Array;
50
+ declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string, aux?: Uint8Array): Promise<EmailBody>;
63
51
  //#endregion
64
52
  //#region src/email-crypto/emailKeys.d.ts
65
53
  /**
66
- * Generates public and private keys for email service.
54
+ * Generates public and private keys for email encryption.
67
55
  *
68
56
  * @returns The user's private and public keys
69
57
  */
70
- declare function generateEmailKeys(): Promise<EmailKeys>;
71
- //#endregion
72
- //#region src/email-crypto/utils.d.ts
73
- /**
74
- * Creates an auxiliary string from public fields of the email.
75
- *
76
- * @param params - The email public parameters.
77
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
78
- * @returns The resulting auxiliary string
79
- */
80
- declare function getAux(params: EmailPublicParameters, isSubjectEncrypted: boolean): Uint8Array;
58
+ declare function generateEmailKeys(): Promise<HybridKeyPair>;
81
59
  //#endregion
82
- export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, emailToBinary, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys, getAux, recipientsToBytes, userToBytes };
60
+ export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys };
83
61
  //# 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/converters.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/utils.ts"],"mappings":";;;;;AAYA;;;;;;;iBAAsB,kBAAA,CACpB,KAAA,EAAO,KAAA,EACP,SAAA,EAAW,kBAAA,EACX,gBAAA,EAAkB,WAAA,EAClB,kBAAA,aACC,OAAA,CAAQ,oBAAA;;;;;;;;;;iBAmBW,uCAAA,CACpB,KAAA,EAAO,KAAA,EACP,UAAA,EAAY,kBAAA,IACZ,gBAAA,EAAkB,WAAA,EAClB,kBAAA,aACC,OAAA,CAAQ,oBAAA;;;;AALX;;;;;iBAmCsB,kBAAA,CACpB,cAAA,EAAgB,oBAAA,EAChB,gBAAA,EAAkB,UAAA,EAClB,oBAAA,EAAsB,WAAA,GACrB,OAAA,CAAQ,KAAA;;;;;AA/DX;;;;;;iBCDsB,uBAAA,CACpB,KAAA,EAAO,KAAA,EACP,QAAA,UACA,kBAAA,aACC,OAAA,CAAQ,iBAAA;;;;;;;;iBAqBW,wBAAA,CAAyB,cAAA,EAAgB,iBAAA,EAAmB,QAAA,WAAmB,OAAA,CAAQ,KAAA;;;iBChC7F,WAAA,CAAY,IAAA,EAAM,IAAA,GAAO,UAAA;AAAA,iBASzB,iBAAA,CAAkB,UAAA,EAAY,IAAA,KAAS,UAAA;AFDvD;;;;;;AAAA,iBEgBgB,aAAA,CAAc,KAAA,EAAO,KAAA,GAAQ,UAAA;;;;;AFhB7C;;;iBGHsB,iBAAA,CAAA,GAAqB,OAAA,CAAQ,SAAA;;;;;AHGnD;;;;;iBIAgB,MAAA,CAAO,MAAA,EAAQ,qBAAA,EAAuB,kBAAA,YAA8B,UAAA"}
1
+ {"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;;;;;iBCAsB,uBAAA,CACpB,SAAA,EAAW,SAAA,EACX,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAmBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AD3BX;;;iBEHsB,iBAAA,CAAA,GAAqB,OAAA,CAAQ,aAAA"}
@@ -1,35 +1,33 @@
1
- import { Email, EmailKeys, EmailPublicParameters, HybridEncryptedEmail, PrivateKeys, PublicKeys, PwdProtectedEmail, User, UserWithPublicKeys } from "./types.js";
1
+ import { EmailBody, HybridEncryptedEmail, HybridKeyPair, PwdProtectedEmail, RecipientWithPublicKey } from "./types.js";
2
2
 
3
3
  //#region src/email-crypto/hybridEncyptedEmail.d.ts
4
4
  /**
5
- * Encrypts the email using hybrid encryption.
5
+ * Encrypts the email body using hybrid encryption.
6
6
  *
7
- * @param email - The email to encrypt.
7
+ * @param body - The email body to encrypt.
8
8
  * @param recipientPublicKeys - The public keys of the recipient.
9
- * @param senderPrivateKey - The private key of the sender.
10
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
11
- * @returns The encrypted email
9
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
10
+ * @returns The encrypted email body
12
11
  */
13
- declare function encryptEmailHybrid(email: Email, recipient: UserWithPublicKeys, senderPrivateKey: PrivateKeys, isSubjectEncrypted?: boolean): Promise<HybridEncryptedEmail>;
12
+ declare function encryptEmailHybrid(body: EmailBody, recipient: RecipientWithPublicKey, aux?: Uint8Array): Promise<HybridEncryptedEmail>;
14
13
  /**
15
- * Encrypts the email using hybrid encryption for multiple recipients.
14
+ * Encrypts the email body using hybrid encryption for multiple recipients.
16
15
  *
17
- * @param email - The email to encrypt.
16
+ * @param body - The email body to encrypt for multiple recipients.
18
17
  * @param recipients - The recipients with corresponding public keys.
19
- * @param senderPrivateKey - The private key of the sender.
20
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
21
- * @returns The set of encrypted email
18
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
19
+ * @returns The set of encrypted email bodies
22
20
  */
23
- declare function encryptEmailHybridForMultipleRecipients(email: Email, recipients: UserWithPublicKeys[], senderPrivateKey: PrivateKeys, isSubjectEncrypted?: boolean): Promise<HybridEncryptedEmail[]>;
21
+ declare function encryptEmailHybridForMultipleRecipients(body: EmailBody, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<HybridEncryptedEmail[]>;
24
22
  /**
25
23
  * Decrypts the email using hybrid encryption.
26
24
  *
27
- * @param encryptedEmail - The encrypted email.
28
- * @param senderPublicKeys - The public key of the sender.
29
- * @param recipientPrivateKeys - The private key of the recipient.
30
- * @returns The decrypted email
25
+ * @param encEmailBody - The encrypted email.
26
+ * @param recipientPrivateHybridKeys - The private key of the recipient.
27
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
28
+ * @returns The decrypted email body
31
29
  */
32
- declare function decryptEmailHybrid(encryptedEmail: HybridEncryptedEmail, senderPublicKeys: PublicKeys, recipientPrivateKeys: PrivateKeys): Promise<Email>;
30
+ declare function decryptEmailHybrid(encEmailBody: HybridEncryptedEmail, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<EmailBody>;
33
31
  //#endregion
34
32
  //#region src/email-crypto/pwdProtectedEmail.d.ts
35
33
  /**
@@ -37,47 +35,27 @@ declare function decryptEmailHybrid(encryptedEmail: HybridEncryptedEmail, sender
37
35
  *
38
36
  * @param email - The email to password-protect
39
37
  * @param password - The secret password shared among recipients
40
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
38
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
41
39
  * @returns The password-protected email
42
40
  */
43
- declare function createPwdProtectedEmail(email: Email, password: string, isSubjectEncrypted?: boolean): Promise<PwdProtectedEmail>;
41
+ declare function createPwdProtectedEmail(emailBody: EmailBody, password: string, aux?: Uint8Array): Promise<PwdProtectedEmail>;
44
42
  /**
45
43
  * Opens a password-protected email.
46
44
  *
47
45
  * @param encryptedEmail - The encrypted email
48
46
  * @param password - The secret password shared among recipients.
49
- * @returns The decrypted email
47
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
48
+ * @returns The decrypted email body
50
49
  */
51
- declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string): Promise<Email>;
52
- //#endregion
53
- //#region src/email-crypto/converters.d.ts
54
- declare function userToBytes(user: User): Uint8Array;
55
- declare function recipientsToBytes(recipients: User[]): Uint8Array;
56
- /**
57
- * Converts an Email type into a Uint8Array array.
58
- *
59
- * @param email - The email.
60
- * @returns The Uint8Array array representation of the Email type.
61
- */
62
- declare function emailToBinary(email: Email): Uint8Array;
50
+ declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string, aux?: Uint8Array): Promise<EmailBody>;
63
51
  //#endregion
64
52
  //#region src/email-crypto/emailKeys.d.ts
65
53
  /**
66
- * Generates public and private keys for email service.
54
+ * Generates public and private keys for email encryption.
67
55
  *
68
56
  * @returns The user's private and public keys
69
57
  */
70
- declare function generateEmailKeys(): Promise<EmailKeys>;
71
- //#endregion
72
- //#region src/email-crypto/utils.d.ts
73
- /**
74
- * Creates an auxiliary string from public fields of the email.
75
- *
76
- * @param params - The email public parameters.
77
- * @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
78
- * @returns The resulting auxiliary string
79
- */
80
- declare function getAux(params: EmailPublicParameters, isSubjectEncrypted: boolean): Uint8Array;
58
+ declare function generateEmailKeys(): Promise<HybridKeyPair>;
81
59
  //#endregion
82
- export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, emailToBinary, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys, getAux, recipientsToBytes, userToBytes };
60
+ export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys };
83
61
  //# sourceMappingURL=email-crypto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"email-crypto.d.ts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/converters.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/utils.ts"],"mappings":";;;;;AAYA;;;;;;;iBAAsB,kBAAA,CACpB,KAAA,EAAO,KAAA,EACP,SAAA,EAAW,kBAAA,EACX,gBAAA,EAAkB,WAAA,EAClB,kBAAA,aACC,OAAA,CAAQ,oBAAA;;;;;;;;;;iBAmBW,uCAAA,CACpB,KAAA,EAAO,KAAA,EACP,UAAA,EAAY,kBAAA,IACZ,gBAAA,EAAkB,WAAA,EAClB,kBAAA,aACC,OAAA,CAAQ,oBAAA;;;;AALX;;;;;iBAmCsB,kBAAA,CACpB,cAAA,EAAgB,oBAAA,EAChB,gBAAA,EAAkB,UAAA,EAClB,oBAAA,EAAsB,WAAA,GACrB,OAAA,CAAQ,KAAA;;;;;AA/DX;;;;;;iBCDsB,uBAAA,CACpB,KAAA,EAAO,KAAA,EACP,QAAA,UACA,kBAAA,aACC,OAAA,CAAQ,iBAAA;;;;;;;;iBAqBW,wBAAA,CAAyB,cAAA,EAAgB,iBAAA,EAAmB,QAAA,WAAmB,OAAA,CAAQ,KAAA;;;iBChC7F,WAAA,CAAY,IAAA,EAAM,IAAA,GAAO,UAAA;AAAA,iBASzB,iBAAA,CAAkB,UAAA,EAAY,IAAA,KAAS,UAAA;AFDvD;;;;;;AAAA,iBEgBgB,aAAA,CAAc,KAAA,EAAO,KAAA,GAAQ,UAAA;;;;;AFhB7C;;;iBGHsB,iBAAA,CAAA,GAAqB,OAAA,CAAQ,SAAA;;;;;AHGnD;;;;;iBIAgB,MAAA,CAAO,MAAA,EAAQ,qBAAA,EAAuB,kBAAA,YAA8B,UAAA"}
1
+ {"version":3,"file":"email-crypto.d.ts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;;;;;iBCAsB,uBAAA,CACpB,SAAA,EAAW,SAAA,EACX,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAmBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AD3BX;;;iBEHsB,iBAAA,CAAA,GAAqB,OAAA,CAAQ,aAAA"}
@@ -1,13 +1,122 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_emailKeys = require('./emailKeys-BJGdkLrg.js');
3
-
4
- exports.createPwdProtectedEmail = require_emailKeys.createPwdProtectedEmail;
5
- exports.decryptEmailHybrid = require_emailKeys.decryptEmailHybrid;
6
- exports.decryptPwdProtectedEmail = require_emailKeys.decryptPwdProtectedEmail;
7
- exports.emailToBinary = require_emailKeys.emailToBinary;
8
- exports.encryptEmailHybrid = require_emailKeys.encryptEmailHybrid;
9
- exports.encryptEmailHybridForMultipleRecipients = require_emailKeys.encryptEmailHybridForMultipleRecipients;
10
- exports.generateEmailKeys = require_emailKeys.generateEmailKeys;
11
- exports.getAux = require_emailKeys.getAux;
12
- exports.recipientsToBytes = require_emailKeys.recipientsToBytes;
13
- exports.userToBytes = require_emailKeys.userToBytes;
2
+ const require_xwing = require('./xwing-iRWVRtNE.js');
3
+ const require_core = require('./core-Bj26rNdA.js');
4
+
5
+ //#region src/email-crypto/hybridEncyptedEmail.ts
6
+ /**
7
+ * Encrypts the email body using hybrid encryption.
8
+ *
9
+ * @param body - The email body to encrypt.
10
+ * @param recipientPublicKeys - The public keys of the recipient.
11
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
12
+ * @returns The encrypted email body
13
+ */
14
+ async function encryptEmailHybrid(body, recipient, aux) {
15
+ try {
16
+ const { encryptionKey, encEmailBody } = await require_core.encryptEmailBody(body, aux);
17
+ return {
18
+ encEmailBody,
19
+ encryptedKey: await require_core.encryptKeysHybrid(encryptionKey, recipient)
20
+ };
21
+ } catch (error) {
22
+ throw new Error("Failed to encrypt email body with hybrid encryption", { cause: error });
23
+ }
24
+ }
25
+ /**
26
+ * Encrypts the email body using hybrid encryption for multiple recipients.
27
+ *
28
+ * @param body - The email body to encrypt for multiple recipients.
29
+ * @param recipients - The recipients with corresponding public keys.
30
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
31
+ * @returns The set of encrypted email bodies
32
+ */
33
+ async function encryptEmailHybridForMultipleRecipients(body, recipients, aux) {
34
+ try {
35
+ const { encryptionKey, encEmailBody } = await require_core.encryptEmailBody(body, aux);
36
+ const encryptedEmails = [];
37
+ for (const recipient of recipients) {
38
+ const encryptedKey = await require_core.encryptKeysHybrid(encryptionKey, recipient);
39
+ encryptedEmails.push({
40
+ encEmailBody,
41
+ encryptedKey
42
+ });
43
+ }
44
+ return encryptedEmails;
45
+ } catch (error) {
46
+ throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
47
+ }
48
+ }
49
+ /**
50
+ * Decrypts the email using hybrid encryption.
51
+ *
52
+ * @param encEmailBody - The encrypted email.
53
+ * @param recipientPrivateHybridKeys - The private key of the recipient.
54
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
55
+ * @returns The decrypted email body
56
+ */
57
+ async function decryptEmailHybrid(encEmailBody, recipientPrivateHybridKeys, aux) {
58
+ try {
59
+ const encryptionKey = await require_core.decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);
60
+ return await require_core.decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);
61
+ } catch (error) {
62
+ throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
63
+ }
64
+ }
65
+
66
+ //#endregion
67
+ //#region src/email-crypto/pwdProtectedEmail.ts
68
+ /**
69
+ * Creates a password-protected email.
70
+ *
71
+ * @param email - The email to password-protect
72
+ * @param password - The secret password shared among recipients
73
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
74
+ * @returns The password-protected email
75
+ */
76
+ async function createPwdProtectedEmail(emailBody, password, aux) {
77
+ try {
78
+ const { encryptionKey, encEmailBody } = await require_core.encryptEmailBody(emailBody, aux);
79
+ return {
80
+ encEmailBody,
81
+ encryptedKey: await require_core.passwordProtectKey(encryptionKey, password)
82
+ };
83
+ } catch (error) {
84
+ throw new Error("Failed to password-protect email", { cause: error });
85
+ }
86
+ }
87
+ /**
88
+ * Opens a password-protected email.
89
+ *
90
+ * @param encryptedEmail - The encrypted email
91
+ * @param password - The secret password shared among recipients.
92
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
93
+ * @returns The decrypted email body
94
+ */
95
+ async function decryptPwdProtectedEmail(encryptedEmail, password, aux) {
96
+ try {
97
+ const encryptionKey = await require_core.removePasswordProtection(encryptedEmail.encryptedKey, password);
98
+ return await require_core.decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);
99
+ } catch (error) {
100
+ throw new Error("Failed to decrypt password-protect email", { cause: error });
101
+ }
102
+ }
103
+
104
+ //#endregion
105
+ //#region src/email-crypto/emailKeys.ts
106
+ /**
107
+ * Generates public and private keys for email encryption.
108
+ *
109
+ * @returns The user's private and public keys
110
+ */
111
+ async function generateEmailKeys() {
112
+ return require_xwing.genHybridKeys();
113
+ }
114
+
115
+ //#endregion
116
+ exports.createPwdProtectedEmail = createPwdProtectedEmail;
117
+ exports.decryptEmailHybrid = decryptEmailHybrid;
118
+ exports.decryptPwdProtectedEmail = decryptPwdProtectedEmail;
119
+ exports.encryptEmailHybrid = encryptEmailHybrid;
120
+ exports.encryptEmailHybridForMultipleRecipients = encryptEmailHybridForMultipleRecipients;
121
+ exports.generateEmailKeys = generateEmailKeys;
122
+ //# sourceMappingURL=email-crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-crypto.js","names":["encryptEmailBody","encryptKeysHybrid","decryptKeysHybrid","decryptEmailBody","encryptEmailBody","passwordProtectKey","removePasswordProtection","decryptEmailBody","genHybridKeys"],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"sourcesContent":["import { HybridEncryptedEmail, EmailBody, RecipientWithPublicKey } from '../types';\nimport { decryptEmailBody, encryptKeysHybrid, decryptKeysHybrid, encryptEmailBody } from './core';\n\n/**\n * Encrypts the email body using hybrid encryption.\n *\n * @param body - The email body to encrypt.\n * @param recipientPublicKeys - The public keys of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The encrypted email body\n */\nexport async function encryptEmailHybrid(\n body: EmailBody,\n recipient: RecipientWithPublicKey,\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to encrypt email body with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Encrypts the email body using hybrid encryption for multiple recipients.\n *\n * @param body - The email body 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 email bodies\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n body: EmailBody,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail[]> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n\n const encryptedEmails: HybridEncryptedEmail[] = [];\n for (const recipient of recipients) {\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n encryptedEmails.push({\n encEmailBody: encEmailBody,\n encryptedKey,\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 encEmailBody - The encrypted email.\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 body\n */\nexport async function decryptEmailHybrid(\n encEmailBody: HybridEncryptedEmail,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);\n const body = await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt email with hybrid encryption', { cause: error });\n }\n}\n","import { PwdProtectedEmail, EmailBody } 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 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 emailBody: EmailBody,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmailBody, encryptedKey };\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 * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n const body = await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt password-protect email', { cause: error });\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\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"],"mappings":";;;;;;;;;;;;;AAWA,eAAsB,mBACpB,MACA,WACA,KAC+B;AAC/B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAMA,8BAAiB,MAAM,IAAI;AAEzE,SAAO;GAAE;GAAc,cADF,MAAMC,+BAAkB,eAAe,UAAU;GACjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,uDAAuD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY5F,eAAsB,wCACpB,MACA,YACA,KACiC;AACjC,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAMD,8BAAiB,MAAM,IAAI;EAEzE,MAAM,kBAA0C,EAAE;AAClD,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,eAAe,MAAMC,+BAAkB,eAAe,UAAU;AACtE,mBAAgB,KAAK;IACL;IACd;IACD,CAAC;;AAEJ,SAAO;UACA,OAAO;AACd,QAAM,IAAI,MAAM,yEAAyE,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY9G,eAAsB,mBACpB,cACA,4BACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAMC,+BAAkB,aAAa,cAAc,2BAA2B;AAEpG,SADa,MAAMC,8BAAiB,aAAa,cAAc,eAAe,IAAI;UAE3E,OAAO;AACd,QAAM,IAAI,MAAM,kDAAkD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;AC9DvF,eAAsB,wBACpB,WACA,UACA,KAC4B;AAC5B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAMC,8BAAiB,WAAW,IAAI;AAG9E,SAAO;GAAE;GAAc,cAFF,MAAMC,gCAAmB,eAAe,SAAS;GAEjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAYzE,eAAsB,yBACpB,gBACA,UACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAMC,sCAAyB,eAAe,cAAc,SAAS;AAE3F,SADa,MAAMC,8BAAiB,eAAe,cAAc,eAAe,IAAI;UAE7E,OAAO;AACd,QAAM,IAAI,MAAM,4CAA4C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACpCjF,eAAsB,oBAA4C;AAChE,QAAOC,6BAAe"}
@@ -1,3 +1,116 @@
1
- import { a as encryptEmailHybrid, d as recipientsToBytes, f as userToBytes, i as decryptEmailHybrid, l as getAux, n as createPwdProtectedEmail, o as encryptEmailHybridForMultipleRecipients, r as decryptPwdProtectedEmail, t as generateEmailKeys, u as emailToBinary } from "./emailKeys-Fp9WR3wl.mjs";
1
+ import { r as genHybridKeys } from "./xwing-CQmQX6hn.mjs";
2
+ import { a as encryptKeysHybrid, n as decryptKeysHybrid, o as passwordProtectKey, r as encryptEmailBody, s as removePasswordProtection, t as decryptEmailBody } from "./core-pEGygy6S.mjs";
2
3
 
3
- export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, emailToBinary, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys, getAux, recipientsToBytes, userToBytes };
4
+ //#region src/email-crypto/hybridEncyptedEmail.ts
5
+ /**
6
+ * Encrypts the email body using hybrid encryption.
7
+ *
8
+ * @param body - The email body to encrypt.
9
+ * @param recipientPublicKeys - The public keys of the recipient.
10
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
11
+ * @returns The encrypted email body
12
+ */
13
+ async function encryptEmailHybrid(body, recipient, aux) {
14
+ try {
15
+ const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);
16
+ return {
17
+ encEmailBody,
18
+ encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
19
+ };
20
+ } catch (error) {
21
+ throw new Error("Failed to encrypt email body with hybrid encryption", { cause: error });
22
+ }
23
+ }
24
+ /**
25
+ * Encrypts the email body using hybrid encryption for multiple recipients.
26
+ *
27
+ * @param body - The email body to encrypt for multiple recipients.
28
+ * @param recipients - The recipients with corresponding public keys.
29
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
30
+ * @returns The set of encrypted email bodies
31
+ */
32
+ async function encryptEmailHybridForMultipleRecipients(body, recipients, aux) {
33
+ try {
34
+ const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);
35
+ const encryptedEmails = [];
36
+ for (const recipient of recipients) {
37
+ const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);
38
+ encryptedEmails.push({
39
+ encEmailBody,
40
+ encryptedKey
41
+ });
42
+ }
43
+ return encryptedEmails;
44
+ } catch (error) {
45
+ throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
46
+ }
47
+ }
48
+ /**
49
+ * Decrypts the email using hybrid encryption.
50
+ *
51
+ * @param encEmailBody - The encrypted email.
52
+ * @param recipientPrivateHybridKeys - The private key of the recipient.
53
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
54
+ * @returns The decrypted email body
55
+ */
56
+ async function decryptEmailHybrid(encEmailBody, recipientPrivateHybridKeys, aux) {
57
+ try {
58
+ const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);
59
+ return await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);
60
+ } catch (error) {
61
+ throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
62
+ }
63
+ }
64
+
65
+ //#endregion
66
+ //#region src/email-crypto/pwdProtectedEmail.ts
67
+ /**
68
+ * Creates a password-protected email.
69
+ *
70
+ * @param email - The email to password-protect
71
+ * @param password - The secret password shared among recipients
72
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
73
+ * @returns The password-protected email
74
+ */
75
+ async function createPwdProtectedEmail(emailBody, password, aux) {
76
+ try {
77
+ const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);
78
+ return {
79
+ encEmailBody,
80
+ encryptedKey: await passwordProtectKey(encryptionKey, password)
81
+ };
82
+ } catch (error) {
83
+ throw new Error("Failed to password-protect email", { cause: error });
84
+ }
85
+ }
86
+ /**
87
+ * Opens a password-protected email.
88
+ *
89
+ * @param encryptedEmail - The encrypted email
90
+ * @param password - The secret password shared among recipients.
91
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
92
+ * @returns The decrypted email body
93
+ */
94
+ async function decryptPwdProtectedEmail(encryptedEmail, password, aux) {
95
+ try {
96
+ const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);
97
+ return await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);
98
+ } catch (error) {
99
+ throw new Error("Failed to decrypt password-protect email", { cause: error });
100
+ }
101
+ }
102
+
103
+ //#endregion
104
+ //#region src/email-crypto/emailKeys.ts
105
+ /**
106
+ * Generates public and private keys for email encryption.
107
+ *
108
+ * @returns The user's private and public keys
109
+ */
110
+ async function generateEmailKeys() {
111
+ return genHybridKeys();
112
+ }
113
+
114
+ //#endregion
115
+ export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys };
116
+ //# sourceMappingURL=email-crypto.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-crypto.mjs","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"sourcesContent":["import { HybridEncryptedEmail, EmailBody, RecipientWithPublicKey } from '../types';\nimport { decryptEmailBody, encryptKeysHybrid, decryptKeysHybrid, encryptEmailBody } from './core';\n\n/**\n * Encrypts the email body using hybrid encryption.\n *\n * @param body - The email body to encrypt.\n * @param recipientPublicKeys - The public keys of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The encrypted email body\n */\nexport async function encryptEmailHybrid(\n body: EmailBody,\n recipient: RecipientWithPublicKey,\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to encrypt email body with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Encrypts the email body using hybrid encryption for multiple recipients.\n *\n * @param body - The email body 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 email bodies\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n body: EmailBody,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail[]> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n\n const encryptedEmails: HybridEncryptedEmail[] = [];\n for (const recipient of recipients) {\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n encryptedEmails.push({\n encEmailBody: encEmailBody,\n encryptedKey,\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 encEmailBody - The encrypted email.\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 body\n */\nexport async function decryptEmailHybrid(\n encEmailBody: HybridEncryptedEmail,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);\n const body = await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt email with hybrid encryption', { cause: error });\n }\n}\n","import { PwdProtectedEmail, EmailBody } 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 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 emailBody: EmailBody,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmailBody, encryptedKey };\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 * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n const body = await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt password-protect email', { cause: error });\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\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"],"mappings":";;;;;;;;;;;;AAWA,eAAsB,mBACpB,MACA,WACA,KAC+B;AAC/B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAM,iBAAiB,MAAM,IAAI;AAEzE,SAAO;GAAE;GAAc,cADF,MAAM,kBAAkB,eAAe,UAAU;GACjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,uDAAuD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY5F,eAAsB,wCACpB,MACA,YACA,KACiC;AACjC,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAM,iBAAiB,MAAM,IAAI;EAEzE,MAAM,kBAA0C,EAAE;AAClD,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,eAAe,MAAM,kBAAkB,eAAe,UAAU;AACtE,mBAAgB,KAAK;IACL;IACd;IACD,CAAC;;AAEJ,SAAO;UACA,OAAO;AACd,QAAM,IAAI,MAAM,yEAAyE,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY9G,eAAsB,mBACpB,cACA,4BACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAM,kBAAkB,aAAa,cAAc,2BAA2B;AAEpG,SADa,MAAM,iBAAiB,aAAa,cAAc,eAAe,IAAI;UAE3E,OAAO;AACd,QAAM,IAAI,MAAM,kDAAkD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;AC9DvF,eAAsB,wBACpB,WACA,UACA,KAC4B;AAC5B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAM,iBAAiB,WAAW,IAAI;AAG9E,SAAO;GAAE;GAAc,cAFF,MAAM,mBAAmB,eAAe,SAAS;GAEjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAYzE,eAAsB,yBACpB,gBACA,UACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAM,yBAAyB,eAAe,cAAc,SAAS;AAE3F,SADa,MAAM,iBAAiB,eAAe,cAAc,eAAe,IAAI;UAE7E,OAAO;AACd,QAAM,IAAI,MAAM,4CAA4C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACpCjF,eAAsB,oBAA4C;AAChE,QAAO,eAAe"}
@@ -37,42 +37,42 @@ declare const deleteDatabase: (userID: string) => Promise<void>;
37
37
  * Derives database encryption key for the given user
38
38
  *
39
39
  * @param userID - The user ID
40
- * @returns The symmetric CryptoKey for protecting database
40
+ * @returns The symmetric key for protecting database
41
41
  */
42
- declare const deriveIndexKey: (baseKey: Uint8Array) => Promise<CryptoKey>;
42
+ declare const deriveIndexKey: (baseKey: Uint8Array) => Promise<Uint8Array>;
43
43
  /**
44
44
  * Encrypts the given email and stores it in the IndexedDB database
45
45
  *
46
46
  * @param newEmailToStore - The email for storing
47
- * @param indexKey - The symmetric CryptoKey key for protecting database
47
+ * @param indexKey - The symmetric key for protecting database
48
48
  * @param esDB - The database
49
49
  */
50
- declare const encryptAndStoreEmail: (newEmailToStore: Email, indexKey: CryptoKey, esDB: MailDB) => Promise<void>;
50
+ declare const encryptAndStoreEmail: (newEmailToStore: Email, indexKey: Uint8Array, esDB: MailDB) => Promise<void>;
51
51
  /**
52
52
  * Encrypts the given set of emails and stores it in the IndexedDB database
53
53
  *
54
54
  * @param newEmailsToStore - The set of emails for storing
55
- * @param indexKey - The symmetric CryptoKey key for protecting database
55
+ * @param indexKey - The symmetric key key for protecting database
56
56
  * @param esDB - The database
57
57
  */
58
- declare const encryptAndStoreManyEmail: (newEmailsToStore: Email[], indexKey: CryptoKey, esDB: MailDB) => Promise<void>;
58
+ declare const encryptAndStoreManyEmail: (newEmailsToStore: Email[], indexKey: Uint8Array, esDB: MailDB) => Promise<void>;
59
59
  /**
60
60
  * Fetches the email from the database and decrypts it
61
61
  *
62
62
  * @param emailID - The email identifier
63
- * @param indexKey - The symmetric CryptoKey key for protecting database
63
+ * @param indexKey - The symmetric key key for protecting database
64
64
  * @param encryptedEmail - The encrypted email
65
65
  * @returns The decrypted email
66
66
  */
67
- declare const getAndDecryptEmail: (emailID: string, indexKey: CryptoKey, esDB: MailDB) => Promise<Email>;
67
+ declare const getAndDecryptEmail: (emailID: string, indexKey: Uint8Array, esDB: MailDB) => Promise<Email>;
68
68
  /**
69
69
  * Fetches all email from the database and decrypts them
70
70
  *
71
- * @param indexKey - The symmetric CryptoKey key for protecting database
71
+ * @param indexKey - The symmetric key key for protecting database
72
72
  * @param esDB - The database
73
73
  * @returns The decrypted emails
74
74
  */
75
- declare const getAndDecryptAllEmails: (indexKey: CryptoKey, esDB: MailDB) => Promise<Email[]>;
75
+ declare const getAndDecryptAllEmails: (indexKey: Uint8Array, esDB: MailDB) => Promise<Email[]>;
76
76
  /**
77
77
  * Deletes the email from the database
78
78
  *
@@ -105,28 +105,28 @@ declare const enforceMaxEmailNumber: (esDB: MailDB, max: number) => Promise<void
105
105
  * Fetches all emails from the database, decrypts them and sortes the results based on the creation time (newest first)
106
106
  *
107
107
  * @param esDB - The database
108
- * @param indexKey - The symmetric CryptoKey key for protecting database
108
+ * @param indexKey - The symmetric Uint8Array key for protecting database
109
109
  * @returns The number of stored emails
110
110
  */
111
- declare const getAllEmailsSortedNewestFirst: (esDB: MailDB, indexKey: CryptoKey) => Promise<Email[]>;
111
+ declare const getAllEmailsSortedNewestFirst: (esDB: MailDB, indexKey: Uint8Array) => Promise<Email[]>;
112
112
  /**
113
113
  * Fetches all emails from the database, decrypts them and sortes the results based on the creation time (oldest first)
114
114
  *
115
115
  * @param esDB - The database
116
- * @param indexKey - The symmetric CryptoKey key for protecting database
116
+ * @param indexKey - The symmetric key for protecting database
117
117
  * @returns The number of stored emails
118
118
  */
119
- declare const getAllEmailsSortedOldestFirst: (esDB: MailDB, indexKey: CryptoKey) => Promise<Email[]>;
119
+ declare const getAllEmailsSortedOldestFirst: (esDB: MailDB, indexKey: Uint8Array) => Promise<Email[]>;
120
120
  /**
121
121
  * Fetches a batch of emails from the database, decrypts them and sortes the results based on the creation time (newest first)
122
122
  *
123
123
  * @param esDB - The database
124
- * @param indexKey - The symmetric CryptoKey key for protecting database
124
+ * @param indexKey - The symmetric key for protecting database
125
125
  * @param batchSize - The size of the batch
126
126
  * @param startCursor - The starting point (optional). If not given, starts from the beginning
127
127
  * @returns The number of stored emails
128
128
  */
129
- declare const getEmailBatch: (esDB: MailDB, indexKey: CryptoKey, batchSize: number, startCursor?: IDBValidKey) => Promise<{
129
+ declare const getEmailBatch: (esDB: MailDB, indexKey: Uint8Array, batchSize: number, startCursor?: IDBValidKey) => Promise<{
130
130
  emails: Email[];
131
131
  nextCursor?: IDBValidKey;
132
132
  }>;
@@ -135,11 +135,11 @@ declare const getEmailBatch: (esDB: MailDB, indexKey: CryptoKey, batchSize: numb
135
135
  /**
136
136
  * Fetches all emails from the database in batches and cahces them
137
137
  *
138
- * @param indexKey - The symmetric CryptoKey key for protecting database
138
+ * @param indexKey - The symmetric key for protecting database
139
139
  * @param esCache - The cache to add emails too
140
140
  * @param esDB - The database
141
141
  */
142
- declare const createCacheFromDB: (indexKey: CryptoKey, esDB: MailDB) => Promise<MailCache<Email>>;
142
+ declare const createCacheFromDB: (indexKey: Uint8Array, esDB: MailDB) => Promise<MailCache<Email>>;
143
143
  /**
144
144
  * Gets an email from the cache
145
145
  *