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
package/dist/constants.js CHANGED
@@ -1,14 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  //#region src/constants.ts
4
- const AES_ALGORITHM = "AES-GCM";
5
- const AES_KEY_BIT_LENGTH = 256;
6
- const AUX_BYTE_LEN = 16;
7
- const IV_LEN_BYTES = 16;
8
- const KEY_WRAPPING_ALGORITHM = "AES-KW";
9
- const KEY_FORMAT = "raw";
10
- const CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
11
- const ECC_ALGORITHM = "X25519";
4
+ const AES_KEY_BYTE_LENGTH = 32;
5
+ const IV_LEN_BYTES = 12;
12
6
  const CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
13
7
  const CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
14
8
  const CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
@@ -18,47 +12,39 @@ const ARGON2ID_ITERATIONS = 4;
18
12
  const ARGON2ID_MEMORY_SIZE = 65536;
19
13
  const ARGON2ID_SALT_BYTE_LENGTH = 16;
20
14
  const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
21
- const KYBER512_PUBLIC_KEY_LENGTH = 800;
22
- const KYBER512_SECRET_KEY_LENGTH = 1632;
23
15
  const KYBER768_PUBLIC_KEY_LENGTH = 1184;
24
16
  const KYBER768_SECRET_KEY_LENGTH = 2400;
25
- const KYBER1024_PUBLIC_KEY_LENGTH = 1568;
26
- const KYBER1024_SECRET_KEY_LENGTH = 3168;
27
17
  const KYBER_SEED_LENGTH = 64;
28
- const HASH_BIT_LEN = 256;
29
18
  const MAX_CACHE_SIZE = 6e8;
30
19
  const MAX_EMAIL_PER_BATCH = 100;
31
20
  const DB_LABEL = "email";
32
21
  const DB_VERSION = 1;
22
+ const XWING_PUBLIC_KEY_LENGTH = 1216;
23
+ const XWING_SECRET_KEY_LENGTH = 32;
24
+ const XWING_SEED_BYTE_LENGTH = 32;
25
+ const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;
33
26
 
34
27
  //#endregion
35
- exports.AES_ALGORITHM = AES_ALGORITHM;
36
- exports.AES_KEY_BIT_LENGTH = AES_KEY_BIT_LENGTH;
28
+ exports.AES_KEY_BYTE_LENGTH = AES_KEY_BYTE_LENGTH;
37
29
  exports.ARGON2ID_ITERATIONS = ARGON2ID_ITERATIONS;
38
30
  exports.ARGON2ID_MEMORY_SIZE = ARGON2ID_MEMORY_SIZE;
39
31
  exports.ARGON2ID_OUTPUT_BYTE_LENGTH = ARGON2ID_OUTPUT_BYTE_LENGTH;
40
32
  exports.ARGON2ID_PARALLELISM = ARGON2ID_PARALLELISM;
41
33
  exports.ARGON2ID_SALT_BYTE_LENGTH = ARGON2ID_SALT_BYTE_LENGTH;
42
- exports.AUX_BYTE_LEN = AUX_BYTE_LEN;
43
34
  exports.CONTEXT_DERIVE = CONTEXT_DERIVE;
44
35
  exports.CONTEXT_ENC_KEYSTORE = CONTEXT_ENC_KEYSTORE;
45
36
  exports.CONTEXT_INDEX = CONTEXT_INDEX;
46
37
  exports.CONTEXT_RECOVERY = CONTEXT_RECOVERY;
47
- exports.CONTEXT_WRAPPING = CONTEXT_WRAPPING;
48
38
  exports.DB_LABEL = DB_LABEL;
49
39
  exports.DB_VERSION = DB_VERSION;
50
- exports.ECC_ALGORITHM = ECC_ALGORITHM;
51
- exports.HASH_BIT_LEN = HASH_BIT_LEN;
52
40
  exports.IV_LEN_BYTES = IV_LEN_BYTES;
53
- exports.KEY_FORMAT = KEY_FORMAT;
54
- exports.KEY_WRAPPING_ALGORITHM = KEY_WRAPPING_ALGORITHM;
55
- exports.KYBER1024_PUBLIC_KEY_LENGTH = KYBER1024_PUBLIC_KEY_LENGTH;
56
- exports.KYBER1024_SECRET_KEY_LENGTH = KYBER1024_SECRET_KEY_LENGTH;
57
- exports.KYBER512_PUBLIC_KEY_LENGTH = KYBER512_PUBLIC_KEY_LENGTH;
58
- exports.KYBER512_SECRET_KEY_LENGTH = KYBER512_SECRET_KEY_LENGTH;
59
41
  exports.KYBER768_PUBLIC_KEY_LENGTH = KYBER768_PUBLIC_KEY_LENGTH;
60
42
  exports.KYBER768_SECRET_KEY_LENGTH = KYBER768_SECRET_KEY_LENGTH;
61
43
  exports.KYBER_SEED_LENGTH = KYBER_SEED_LENGTH;
62
44
  exports.MAX_CACHE_SIZE = MAX_CACHE_SIZE;
63
45
  exports.MAX_EMAIL_PER_BATCH = MAX_EMAIL_PER_BATCH;
46
+ exports.XWING_CIPHERTEXT_BYTE_LENGTH = XWING_CIPHERTEXT_BYTE_LENGTH;
47
+ exports.XWING_PUBLIC_KEY_LENGTH = XWING_PUBLIC_KEY_LENGTH;
48
+ exports.XWING_SECRET_KEY_LENGTH = XWING_SECRET_KEY_LENGTH;
49
+ exports.XWING_SEED_BYTE_LENGTH = XWING_SEED_BYTE_LENGTH;
64
50
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const AES_ALGORITHM = 'AES-GCM';\nexport const AES_KEY_BIT_LENGTH = 256;\nexport const AUX_BYTE_LEN = 16;\nexport const IV_LEN_BYTES = 16;\n\nexport const KEY_WRAPPING_ALGORITHM = 'AES-KW';\nexport const KEY_FORMAT = 'raw';\nexport const CONTEXT_WRAPPING = 'CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets';\n\nexport const ECC_ALGORITHM = 'X25519';\n\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const KYBER512_PUBLIC_KEY_LENGTH = 800;\nexport const KYBER512_SECRET_KEY_LENGTH = 1632;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\n\nexport const KYBER1024_PUBLIC_KEY_LENGTH = 1568;\nexport const KYBER1024_SECRET_KEY_LENGTH = 3168;\n\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const HASH_BIT_LEN = 256;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n"],"mappings":";;;AAAA,MAAa,gBAAgB;AAC7B,MAAa,qBAAqB;AAClC,MAAa,eAAe;AAC5B,MAAa,eAAe;AAE5B,MAAa,yBAAyB;AACtC,MAAa,aAAa;AAC1B,MAAa,mBAAmB;AAEhC,MAAa,gBAAgB;AAE7B,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAG9B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAE3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAE1C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAE1C,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAE3C,MAAa,oBAAoB;AAEjC,MAAa,eAAe;AAE5B,MAAa,iBAAiB;AAC9B,MAAa,sBAAsB;AACnC,MAAa,WAAW;AACxB,MAAa,aAAa"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const AES_KEY_BYTE_LENGTH = 32;\nexport const IV_LEN_BYTES = 12;\n\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n\nexport const XWING_PUBLIC_KEY_LENGTH = 1216;\nexport const XWING_SECRET_KEY_LENGTH = 32;\nexport const XWING_SEED_BYTE_LENGTH = 32;\nexport const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;\n"],"mappings":";;;AAAA,MAAa,sBAAsB;AACnC,MAAa,eAAe;AAE5B,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAG9B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAE3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAC1C,MAAa,oBAAoB;AAEjC,MAAa,iBAAiB;AAC9B,MAAa,sBAAsB;AACnC,MAAa,WAAW;AACxB,MAAa,aAAa;AAE1B,MAAa,0BAA0B;AACvC,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;AACtC,MAAa,+BAA+B"}
@@ -1,12 +1,6 @@
1
1
  //#region src/constants.ts
2
- const AES_ALGORITHM = "AES-GCM";
3
- const AES_KEY_BIT_LENGTH = 256;
4
- const AUX_BYTE_LEN = 16;
5
- const IV_LEN_BYTES = 16;
6
- const KEY_WRAPPING_ALGORITHM = "AES-KW";
7
- const KEY_FORMAT = "raw";
8
- const CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
9
- const ECC_ALGORITHM = "X25519";
2
+ const AES_KEY_BYTE_LENGTH = 32;
3
+ const IV_LEN_BYTES = 12;
10
4
  const CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
11
5
  const CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
12
6
  const CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
@@ -16,19 +10,18 @@ const ARGON2ID_ITERATIONS = 4;
16
10
  const ARGON2ID_MEMORY_SIZE = 65536;
17
11
  const ARGON2ID_SALT_BYTE_LENGTH = 16;
18
12
  const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
19
- const KYBER512_PUBLIC_KEY_LENGTH = 800;
20
- const KYBER512_SECRET_KEY_LENGTH = 1632;
21
13
  const KYBER768_PUBLIC_KEY_LENGTH = 1184;
22
14
  const KYBER768_SECRET_KEY_LENGTH = 2400;
23
- const KYBER1024_PUBLIC_KEY_LENGTH = 1568;
24
- const KYBER1024_SECRET_KEY_LENGTH = 3168;
25
15
  const KYBER_SEED_LENGTH = 64;
26
- const HASH_BIT_LEN = 256;
27
16
  const MAX_CACHE_SIZE = 6e8;
28
17
  const MAX_EMAIL_PER_BATCH = 100;
29
18
  const DB_LABEL = "email";
30
19
  const DB_VERSION = 1;
20
+ const XWING_PUBLIC_KEY_LENGTH = 1216;
21
+ const XWING_SECRET_KEY_LENGTH = 32;
22
+ const XWING_SEED_BYTE_LENGTH = 32;
23
+ const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;
31
24
 
32
25
  //#endregion
33
- export { AES_ALGORITHM, AES_KEY_BIT_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, AUX_BYTE_LEN, CONTEXT_DERIVE, CONTEXT_ENC_KEYSTORE, CONTEXT_INDEX, CONTEXT_RECOVERY, CONTEXT_WRAPPING, DB_LABEL, DB_VERSION, ECC_ALGORITHM, HASH_BIT_LEN, IV_LEN_BYTES, KEY_FORMAT, KEY_WRAPPING_ALGORITHM, KYBER1024_PUBLIC_KEY_LENGTH, KYBER1024_SECRET_KEY_LENGTH, KYBER512_PUBLIC_KEY_LENGTH, KYBER512_SECRET_KEY_LENGTH, KYBER768_PUBLIC_KEY_LENGTH, KYBER768_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH, MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH };
26
+ export { AES_KEY_BYTE_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, CONTEXT_DERIVE, CONTEXT_ENC_KEYSTORE, CONTEXT_INDEX, CONTEXT_RECOVERY, DB_LABEL, DB_VERSION, IV_LEN_BYTES, KYBER768_PUBLIC_KEY_LENGTH, KYBER768_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH, MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH, XWING_CIPHERTEXT_BYTE_LENGTH, XWING_PUBLIC_KEY_LENGTH, XWING_SECRET_KEY_LENGTH, XWING_SEED_BYTE_LENGTH };
34
27
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const AES_ALGORITHM = 'AES-GCM';\nexport const AES_KEY_BIT_LENGTH = 256;\nexport const AUX_BYTE_LEN = 16;\nexport const IV_LEN_BYTES = 16;\n\nexport const KEY_WRAPPING_ALGORITHM = 'AES-KW';\nexport const KEY_FORMAT = 'raw';\nexport const CONTEXT_WRAPPING = 'CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets';\n\nexport const ECC_ALGORITHM = 'X25519';\n\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const KYBER512_PUBLIC_KEY_LENGTH = 800;\nexport const KYBER512_SECRET_KEY_LENGTH = 1632;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\n\nexport const KYBER1024_PUBLIC_KEY_LENGTH = 1568;\nexport const KYBER1024_SECRET_KEY_LENGTH = 3168;\n\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const HASH_BIT_LEN = 256;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n"],"mappings":";AAAA,MAAa,gBAAgB;AAC7B,MAAa,qBAAqB;AAClC,MAAa,eAAe;AAC5B,MAAa,eAAe;AAE5B,MAAa,yBAAyB;AACtC,MAAa,aAAa;AAC1B,MAAa,mBAAmB;AAEhC,MAAa,gBAAgB;AAE7B,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAG9B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAE3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAE1C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAE1C,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAE3C,MAAa,oBAAoB;AAEjC,MAAa,eAAe;AAE5B,MAAa,iBAAiB;AAC9B,MAAa,sBAAsB;AACnC,MAAa,WAAW;AACxB,MAAa,aAAa"}
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const AES_KEY_BYTE_LENGTH = 32;\nexport const IV_LEN_BYTES = 12;\n\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n\nexport const XWING_PUBLIC_KEY_LENGTH = 1216;\nexport const XWING_SECRET_KEY_LENGTH = 32;\nexport const XWING_SEED_BYTE_LENGTH = 32;\nexport const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;\n"],"mappings":";AAAA,MAAa,sBAAsB;AACnC,MAAa,eAAe;AAE5B,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAG9B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAE3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAC1C,MAAa,oBAAoB;AAEjC,MAAa,iBAAiB;AAC9B,MAAa,sBAAsB;AACnC,MAAa,WAAW;AACxB,MAAa,aAAa;AAE1B,MAAa,0BAA0B;AACvC,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;AACtC,MAAa,+BAA+B"}
@@ -0,0 +1,227 @@
1
+ const require_chunk = require('./chunk-EbLFQX5m.js');
2
+ const require_genID = require('./genID-cWOPmspk.js');
3
+ const require_deriveKeysFromPassword = require('./deriveKeysFromPassword-C7xAGGsh.js');
4
+ const require_aes = require('./aes-CuW_SPl-.js');
5
+ const require_xwing = require('./xwing-iRWVRtNE.js');
6
+ let _noble_ciphers_aes_js = require("@noble/ciphers/aes.js");
7
+
8
+ //#region src/key-wrapper/aesWrapper.ts
9
+ /**
10
+ * Unwraps the given wrapped key
11
+ *
12
+ * @param encryptedKey - The wrapped key
13
+ * @param wrappingKey - The secret key used for unwrapping
14
+ * @returns The resulting key
15
+ */
16
+ async function unwrapKey(encryptedKey, wrappingKey) {
17
+ return (0, _noble_ciphers_aes_js.aeskw)(wrappingKey).decrypt(encryptedKey);
18
+ }
19
+ /**
20
+ * Wraps the given key
21
+ *
22
+ * @param key - The key to be wrapped
23
+ * @param wrappingKey - The secret key used for wrapping
24
+ * @returns The resulting ciphertext
25
+ */
26
+ async function wrapKey(key, wrappingKey) {
27
+ return (0, _noble_ciphers_aes_js.aeskw)(wrappingKey).encrypt(key);
28
+ }
29
+
30
+ //#endregion
31
+ //#region src/email-crypto/core.ts
32
+ /**
33
+ * Symmetrically encrypts email body.
34
+ *
35
+ * @param body - The email body to encrypt.
36
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
37
+ * @returns The resulting encrypted email body and symmetric key used for encryption
38
+ */
39
+ async function encryptEmailBody(body, aux) {
40
+ try {
41
+ if (!body.text || !body.subject) throw new Error("Invalid input");
42
+ const encryptionKey = require_aes.genSymmetricKey();
43
+ return {
44
+ encEmailBody: await encryptEmailBodyWithKey(body, encryptionKey, aux),
45
+ encryptionKey
46
+ };
47
+ } catch (error) {
48
+ throw new Error("Failed to symmetrically encrypt email body", { cause: error });
49
+ }
50
+ }
51
+ /**
52
+ * Symmetrically encrypts email body with the given key.
53
+ *
54
+ * @param body - The email body to encrypt.
55
+ * @param encryptionKey - The symmetric key to encrypt the email.
56
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
57
+ * @returns The resulting encrypted email body and symmetric key used for encryption
58
+ */
59
+ async function encryptEmailBodyWithKey(body, encryptionKey, aux) {
60
+ try {
61
+ const text = require_genID.UTF8ToUint8(body.text);
62
+ const subjectEnc = await require_aes.encryptSymmetrically(encryptionKey, require_genID.UTF8ToUint8(body.subject), aux);
63
+ const enc = {
64
+ encText: require_genID.uint8ArrayToBase64(await require_aes.encryptSymmetrically(encryptionKey, text, aux)),
65
+ encSubject: require_genID.uint8ArrayToBase64(subjectEnc)
66
+ };
67
+ if (body.attachments) {
68
+ const promises = body.attachments.map((attachment) => {
69
+ return require_aes.encryptSymmetrically(encryptionKey, require_genID.UTF8ToUint8(attachment), aux);
70
+ });
71
+ enc.encAttachments = (await Promise.all(promises))?.map(require_genID.uint8ArrayToBase64);
72
+ }
73
+ return enc;
74
+ } catch (error) {
75
+ throw new Error("Failed to encrypt email body", { cause: error });
76
+ }
77
+ }
78
+ /**
79
+ * Decrypts symmetrically encrypted email body.
80
+ *
81
+ * @param encEmailBody - The email body to decrypt.
82
+ * @param encryptionKey - The symmetric key to decrypt the email.
83
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
84
+ * @returns The resulting decrypted email body
85
+ */
86
+ async function decryptEmailBody(encEmailBody, encryptionKey, aux) {
87
+ try {
88
+ const subject = require_genID.uint8ToUTF8(await require_aes.decryptSymmetrically(encryptionKey, require_genID.base64ToUint8Array(encEmailBody.encSubject), aux));
89
+ const body = {
90
+ text: require_genID.uint8ToUTF8(await require_aes.decryptSymmetrically(encryptionKey, require_genID.base64ToUint8Array(encEmailBody.encText), aux)),
91
+ subject
92
+ };
93
+ if (encEmailBody.encAttachments) {
94
+ const promises = (encEmailBody.encAttachments?.map(require_genID.base64ToUint8Array))?.map((encAtt) => require_aes.decryptSymmetrically(encryptionKey, encAtt, aux));
95
+ body.attachments = (await Promise.all(promises))?.map((att) => require_genID.uint8ToUTF8(att));
96
+ }
97
+ return body;
98
+ } catch (error) {
99
+ throw new Error("Failed to symmetrically decrypt email body", { cause: error });
100
+ }
101
+ }
102
+ /**
103
+ * Encrypts the email symmetric key using hybrid encryption.
104
+ *
105
+ * @param emailEncryptionKey - The symmetric key used for email encryption.
106
+ * @param recipient - The recipient with a public hybrid key.
107
+ * @returns The encrypted email symmetric key
108
+ */
109
+ async function encryptKeysHybrid(emailEncryptionKey, recipient) {
110
+ try {
111
+ const { cipherText, sharedSecret } = require_xwing.encapsulateHybrid(recipient.publicHybridKey);
112
+ return {
113
+ encryptedKey: require_genID.uint8ArrayToBase64(await wrapKey(emailEncryptionKey, sharedSecret)),
114
+ hybridCiphertext: require_genID.uint8ArrayToBase64(cipherText),
115
+ encryptedForEmail: recipient.email
116
+ };
117
+ } catch (error) {
118
+ throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
119
+ }
120
+ }
121
+ /**
122
+ * Decrypts the email symmetric key encrypted via hybrid encryption.
123
+ *
124
+ * @param encryptedKey - The encrypted email key.
125
+ * @param recipientPrivateKey - The private key of the recipient.
126
+ * @returns The email encryption key
127
+ */
128
+ async function decryptKeysHybrid(encryptedKey, recipientPrivateKey) {
129
+ try {
130
+ const kyberCiphertext = require_genID.base64ToUint8Array(encryptedKey.hybridCiphertext);
131
+ return await unwrapKey(require_genID.base64ToUint8Array(encryptedKey.encryptedKey), require_xwing.decapsulateHybrid(kyberCiphertext, recipientPrivateKey));
132
+ } catch (error) {
133
+ throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
134
+ }
135
+ }
136
+ /**
137
+ * Password-protects the email symmetric key.
138
+ *
139
+ * @param emailEncryptionKey - The symmetric key used for email encryption.
140
+ * @param password - The secret password for key protection.
141
+ * @returns The password-protected email symmetric key
142
+ */
143
+ async function passwordProtectKey(emailEncryptionKey, password) {
144
+ try {
145
+ const { key, salt } = await require_deriveKeysFromPassword.getKeyFromPassword(password);
146
+ const encryptedKey = await wrapKey(emailEncryptionKey, key);
147
+ const saltStr = require_genID.uint8ArrayToBase64(salt);
148
+ return {
149
+ encryptedKey: require_genID.uint8ArrayToBase64(encryptedKey),
150
+ salt: saltStr
151
+ };
152
+ } catch (error) {
153
+ throw new Error("Failed to password-protect email key", { cause: error });
154
+ }
155
+ }
156
+ /**
157
+ * Removes passoword-protection and exposes the email symmetric key.
158
+ *
159
+ * @param emailEncryptionKey - The password-protected email key.
160
+ * @param password - The secret password for key protection.
161
+ * @returns The email encryption key
162
+ */
163
+ async function removePasswordProtection(emailEncryptionKey, password) {
164
+ try {
165
+ const salt = require_genID.base64ToUint8Array(emailEncryptionKey.salt);
166
+ return await unwrapKey(require_genID.base64ToUint8Array(emailEncryptionKey.encryptedKey), await require_deriveKeysFromPassword.getKeyFromPasswordAndSalt(password, salt));
167
+ } catch (error) {
168
+ throw new Error("Failed to remove password-protection from email key", { cause: error });
169
+ }
170
+ }
171
+
172
+ //#endregion
173
+ Object.defineProperty(exports, 'decryptEmailBody', {
174
+ enumerable: true,
175
+ get: function () {
176
+ return decryptEmailBody;
177
+ }
178
+ });
179
+ Object.defineProperty(exports, 'decryptKeysHybrid', {
180
+ enumerable: true,
181
+ get: function () {
182
+ return decryptKeysHybrid;
183
+ }
184
+ });
185
+ Object.defineProperty(exports, 'encryptEmailBody', {
186
+ enumerable: true,
187
+ get: function () {
188
+ return encryptEmailBody;
189
+ }
190
+ });
191
+ Object.defineProperty(exports, 'encryptEmailBodyWithKey', {
192
+ enumerable: true,
193
+ get: function () {
194
+ return encryptEmailBodyWithKey;
195
+ }
196
+ });
197
+ Object.defineProperty(exports, 'encryptKeysHybrid', {
198
+ enumerable: true,
199
+ get: function () {
200
+ return encryptKeysHybrid;
201
+ }
202
+ });
203
+ Object.defineProperty(exports, 'passwordProtectKey', {
204
+ enumerable: true,
205
+ get: function () {
206
+ return passwordProtectKey;
207
+ }
208
+ });
209
+ Object.defineProperty(exports, 'removePasswordProtection', {
210
+ enumerable: true,
211
+ get: function () {
212
+ return removePasswordProtection;
213
+ }
214
+ });
215
+ Object.defineProperty(exports, 'unwrapKey', {
216
+ enumerable: true,
217
+ get: function () {
218
+ return unwrapKey;
219
+ }
220
+ });
221
+ Object.defineProperty(exports, 'wrapKey', {
222
+ enumerable: true,
223
+ get: function () {
224
+ return wrapKey;
225
+ }
226
+ });
227
+ //# sourceMappingURL=core-Bj26rNdA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-Bj26rNdA.js","names":["genSymmetricKey","UTF8ToUint8","encryptSymmetrically","uint8ArrayToBase64","uint8ToUTF8","decryptSymmetrically","base64ToUint8Array","encapsulateHybrid","decapsulateHybrid","getKeyFromPassword","getKeyFromPasswordAndSalt"],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/core.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","import { HybridEncKey, PwdProtectedKey, EmailBody, EmailBodyEncrypted, RecipientWithPublicKey } 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';\n\n/**\n * Symmetrically encrypts email body.\n *\n * @param body - The email body to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBody(\n body: EmailBody,\n aux?: Uint8Array,\n): Promise<{\n encEmailBody: EmailBodyEncrypted;\n encryptionKey: Uint8Array;\n}> {\n try {\n if (!body.text || !body.subject) {\n throw new Error('Invalid input');\n }\n const encryptionKey = genSymmetricKey();\n const encEmailBody = await encryptEmailBodyWithKey(body, encryptionKey, aux);\n\n return { encEmailBody, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email body', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts email body with the given key.\n *\n * @param body - The email body 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 body and symmetric key used for encryption\n */\nexport async function encryptEmailBodyWithKey(\n body: EmailBody,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBodyEncrypted> {\n try {\n const text = UTF8ToUint8(body.text);\n const subject = UTF8ToUint8(body.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n const enc: EmailBodyEncrypted = { encText, encSubject };\n\n if (body.attachments) {\n const promises = body.attachments.map((attachment) => {\n const binaryAttachment = UTF8ToUint8(attachment);\n return encryptSymmetrically(encryptionKey, binaryAttachment, aux);\n });\n const encryptedAttachments = await Promise.all(promises);\n enc.encAttachments = encryptedAttachments?.map(uint8ArrayToBase64);\n }\n\n return enc;\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email body.\n *\n * @param encEmailBody - The email body 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 body\n */\nexport async function decryptEmailBody(\n encEmailBody: EmailBodyEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encSubject = base64ToUint8Array(encEmailBody.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const encText = base64ToUint8Array(encEmailBody.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n const body: EmailBody = { text, subject };\n\n if (encEmailBody.encAttachments) {\n const encAttachments = encEmailBody.encAttachments?.map(base64ToUint8Array);\n const promises = encAttachments?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));\n const decryptedAttachments = await Promise.all(promises);\n body.attachments = decryptedAttachments?.map((att) => uint8ToUTF8(att));\n }\n\n return body;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email body', { cause: 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 Error('Failed to encrypt email key using hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email symmetric key encrypted via hybrid encryption.\n *\n * @param encryptedKey - The encrypted email key.\n * @param 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 Error('Failed to decrypt email key encrypted via hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric 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 Error('Failed to password-protect email key', { cause: error });\n }\n}\n\n/**\n * Removes passoword-protection and exposes the email symmetric key.\n *\n * @param emailEncryptionKey - The password-protected email key.\n * @param password - The secret password for key protection.\n * @returns The email encryption 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 Error('Failed to remove password-protection from email key', { cause: error });\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1,173 @@
1
+ import { c as base64ToUint8Array, f as uint8ToUTF8, s as UTF8ToUint8, u as uint8ArrayToBase64 } from "./genID-D08K7JPr.mjs";
2
+ import { n as getKeyFromPasswordAndSalt, t as getKeyFromPassword } from "./deriveKeysFromPassword-DXgSvTNC.mjs";
3
+ import { n as encryptSymmetrically, r as genSymmetricKey, t as decryptSymmetrically } from "./aes-B8TA-JKq.mjs";
4
+ import { n as encapsulateHybrid, t as decapsulateHybrid } from "./xwing-CQmQX6hn.mjs";
5
+ import { aeskw } from "@noble/ciphers/aes.js";
6
+
7
+ //#region src/key-wrapper/aesWrapper.ts
8
+ /**
9
+ * Unwraps the given wrapped key
10
+ *
11
+ * @param encryptedKey - The wrapped key
12
+ * @param wrappingKey - The secret key used for unwrapping
13
+ * @returns The resulting key
14
+ */
15
+ async function unwrapKey(encryptedKey, wrappingKey) {
16
+ return aeskw(wrappingKey).decrypt(encryptedKey);
17
+ }
18
+ /**
19
+ * Wraps the given key
20
+ *
21
+ * @param key - The key to be wrapped
22
+ * @param wrappingKey - The secret key used for wrapping
23
+ * @returns The resulting ciphertext
24
+ */
25
+ async function wrapKey(key, wrappingKey) {
26
+ return aeskw(wrappingKey).encrypt(key);
27
+ }
28
+
29
+ //#endregion
30
+ //#region src/email-crypto/core.ts
31
+ /**
32
+ * Symmetrically encrypts email body.
33
+ *
34
+ * @param body - The email body to encrypt.
35
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
36
+ * @returns The resulting encrypted email body and symmetric key used for encryption
37
+ */
38
+ async function encryptEmailBody(body, aux) {
39
+ try {
40
+ if (!body.text || !body.subject) throw new Error("Invalid input");
41
+ const encryptionKey = genSymmetricKey();
42
+ return {
43
+ encEmailBody: await encryptEmailBodyWithKey(body, encryptionKey, aux),
44
+ encryptionKey
45
+ };
46
+ } catch (error) {
47
+ throw new Error("Failed to symmetrically encrypt email body", { cause: error });
48
+ }
49
+ }
50
+ /**
51
+ * Symmetrically encrypts email body with the given key.
52
+ *
53
+ * @param body - The email body to encrypt.
54
+ * @param encryptionKey - The symmetric key to encrypt the email.
55
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
56
+ * @returns The resulting encrypted email body and symmetric key used for encryption
57
+ */
58
+ async function encryptEmailBodyWithKey(body, encryptionKey, aux) {
59
+ try {
60
+ const text = UTF8ToUint8(body.text);
61
+ const subjectEnc = await encryptSymmetrically(encryptionKey, UTF8ToUint8(body.subject), aux);
62
+ const enc = {
63
+ encText: uint8ArrayToBase64(await encryptSymmetrically(encryptionKey, text, aux)),
64
+ encSubject: uint8ArrayToBase64(subjectEnc)
65
+ };
66
+ if (body.attachments) {
67
+ const promises = body.attachments.map((attachment) => {
68
+ return encryptSymmetrically(encryptionKey, UTF8ToUint8(attachment), aux);
69
+ });
70
+ enc.encAttachments = (await Promise.all(promises))?.map(uint8ArrayToBase64);
71
+ }
72
+ return enc;
73
+ } catch (error) {
74
+ throw new Error("Failed to encrypt email body", { cause: error });
75
+ }
76
+ }
77
+ /**
78
+ * Decrypts symmetrically encrypted email body.
79
+ *
80
+ * @param encEmailBody - The email body to decrypt.
81
+ * @param encryptionKey - The symmetric key to decrypt the email.
82
+ * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
83
+ * @returns The resulting decrypted email body
84
+ */
85
+ async function decryptEmailBody(encEmailBody, encryptionKey, aux) {
86
+ try {
87
+ const subject = uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailBody.encSubject), aux));
88
+ const body = {
89
+ text: uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailBody.encText), aux)),
90
+ subject
91
+ };
92
+ if (encEmailBody.encAttachments) {
93
+ const promises = (encEmailBody.encAttachments?.map(base64ToUint8Array))?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));
94
+ body.attachments = (await Promise.all(promises))?.map((att) => uint8ToUTF8(att));
95
+ }
96
+ return body;
97
+ } catch (error) {
98
+ throw new Error("Failed to symmetrically decrypt email body", { cause: error });
99
+ }
100
+ }
101
+ /**
102
+ * Encrypts the email symmetric key using hybrid encryption.
103
+ *
104
+ * @param emailEncryptionKey - The symmetric key used for email encryption.
105
+ * @param recipient - The recipient with a public hybrid key.
106
+ * @returns The encrypted email symmetric key
107
+ */
108
+ async function encryptKeysHybrid(emailEncryptionKey, recipient) {
109
+ try {
110
+ const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);
111
+ return {
112
+ encryptedKey: uint8ArrayToBase64(await wrapKey(emailEncryptionKey, sharedSecret)),
113
+ hybridCiphertext: uint8ArrayToBase64(cipherText),
114
+ encryptedForEmail: recipient.email
115
+ };
116
+ } catch (error) {
117
+ throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
118
+ }
119
+ }
120
+ /**
121
+ * Decrypts the email symmetric key encrypted via hybrid encryption.
122
+ *
123
+ * @param encryptedKey - The encrypted email key.
124
+ * @param recipientPrivateKey - The private key of the recipient.
125
+ * @returns The email encryption key
126
+ */
127
+ async function decryptKeysHybrid(encryptedKey, recipientPrivateKey) {
128
+ try {
129
+ const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);
130
+ return await unwrapKey(base64ToUint8Array(encryptedKey.encryptedKey), decapsulateHybrid(kyberCiphertext, recipientPrivateKey));
131
+ } catch (error) {
132
+ throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
133
+ }
134
+ }
135
+ /**
136
+ * Password-protects the email symmetric key.
137
+ *
138
+ * @param emailEncryptionKey - The symmetric key used for email encryption.
139
+ * @param password - The secret password for key protection.
140
+ * @returns The password-protected email symmetric key
141
+ */
142
+ async function passwordProtectKey(emailEncryptionKey, password) {
143
+ try {
144
+ const { key, salt } = await getKeyFromPassword(password);
145
+ const encryptedKey = await wrapKey(emailEncryptionKey, key);
146
+ const saltStr = uint8ArrayToBase64(salt);
147
+ return {
148
+ encryptedKey: uint8ArrayToBase64(encryptedKey),
149
+ salt: saltStr
150
+ };
151
+ } catch (error) {
152
+ throw new Error("Failed to password-protect email key", { cause: error });
153
+ }
154
+ }
155
+ /**
156
+ * Removes passoword-protection and exposes the email symmetric key.
157
+ *
158
+ * @param emailEncryptionKey - The password-protected email key.
159
+ * @param password - The secret password for key protection.
160
+ * @returns The email encryption key
161
+ */
162
+ async function removePasswordProtection(emailEncryptionKey, password) {
163
+ try {
164
+ const salt = base64ToUint8Array(emailEncryptionKey.salt);
165
+ return await unwrapKey(base64ToUint8Array(emailEncryptionKey.encryptedKey), await getKeyFromPasswordAndSalt(password, salt));
166
+ } catch (error) {
167
+ throw new Error("Failed to remove password-protection from email key", { cause: error });
168
+ }
169
+ }
170
+
171
+ //#endregion
172
+ export { encryptKeysHybrid as a, unwrapKey as c, encryptEmailBodyWithKey as i, wrapKey as l, decryptKeysHybrid as n, passwordProtectKey as o, encryptEmailBody as r, removePasswordProtection as s, decryptEmailBody as t };
173
+ //# sourceMappingURL=core-pEGygy6S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-pEGygy6S.mjs","names":[],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/core.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","import { HybridEncKey, PwdProtectedKey, EmailBody, EmailBodyEncrypted, RecipientWithPublicKey } 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';\n\n/**\n * Symmetrically encrypts email body.\n *\n * @param body - The email body to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBody(\n body: EmailBody,\n aux?: Uint8Array,\n): Promise<{\n encEmailBody: EmailBodyEncrypted;\n encryptionKey: Uint8Array;\n}> {\n try {\n if (!body.text || !body.subject) {\n throw new Error('Invalid input');\n }\n const encryptionKey = genSymmetricKey();\n const encEmailBody = await encryptEmailBodyWithKey(body, encryptionKey, aux);\n\n return { encEmailBody, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email body', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts email body with the given key.\n *\n * @param body - The email body 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 body and symmetric key used for encryption\n */\nexport async function encryptEmailBodyWithKey(\n body: EmailBody,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBodyEncrypted> {\n try {\n const text = UTF8ToUint8(body.text);\n const subject = UTF8ToUint8(body.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n const enc: EmailBodyEncrypted = { encText, encSubject };\n\n if (body.attachments) {\n const promises = body.attachments.map((attachment) => {\n const binaryAttachment = UTF8ToUint8(attachment);\n return encryptSymmetrically(encryptionKey, binaryAttachment, aux);\n });\n const encryptedAttachments = await Promise.all(promises);\n enc.encAttachments = encryptedAttachments?.map(uint8ArrayToBase64);\n }\n\n return enc;\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email body.\n *\n * @param encEmailBody - The email body 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 body\n */\nexport async function decryptEmailBody(\n encEmailBody: EmailBodyEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encSubject = base64ToUint8Array(encEmailBody.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const encText = base64ToUint8Array(encEmailBody.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n const body: EmailBody = { text, subject };\n\n if (encEmailBody.encAttachments) {\n const encAttachments = encEmailBody.encAttachments?.map(base64ToUint8Array);\n const promises = encAttachments?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));\n const decryptedAttachments = await Promise.all(promises);\n body.attachments = decryptedAttachments?.map((att) => uint8ToUTF8(att));\n }\n\n return body;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email body', { cause: 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 Error('Failed to encrypt email key using hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email symmetric key encrypted via hybrid encryption.\n *\n * @param encryptedKey - The encrypted email key.\n * @param 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 Error('Failed to decrypt email key encrypted via hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric 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 Error('Failed to password-protect email key', { cause: error });\n }\n}\n\n/**\n * Removes passoword-protection and exposes the email symmetric key.\n *\n * @param emailEncryptionKey - The password-protected email key.\n * @param password - The secret password for key protection.\n * @returns The email encryption 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 Error('Failed to remove password-protection from email key', { cause: error });\n }\n}\n"],"mappings":"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"}