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,79 +1,6 @@
1
- import { AES_KEY_BIT_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, CONTEXT_DERIVE } from "./constants.mjs";
2
- import { d as hexToUint8Array, l as UTF8ToUint8, p as uint8ArrayToHex } from "./genID-3Er5IowC.mjs";
3
- import { s as importSymmetricCryptoKey } from "./aes-DSDxP8uF.mjs";
4
- import { blake3 } from "@noble/hashes/blake3.js";
1
+ import { ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH } from "./constants.mjs";
2
+ import { randomBytes } from "@noble/hashes/utils.js";
5
3
 
6
- //#region src/derive-key/deriveKeysFromKey.ts
7
- /**
8
- * Derives a symmetric key from the base key and context string
9
- *
10
- * @param context - The context string.
11
- * The context string should be hardcoded, globally unique, and application-specific.
12
- * @param baseKey - The base key (NOT PASSWORD!)
13
- * @returns The derived secret key
14
- */
15
- function deriveSymmetricKeyFromContext(context, baseKey) {
16
- return blake3(baseKey, { context: UTF8ToUint8(context) });
17
- }
18
- /**
19
- * Derives a symmetric CryptoKey from the base key and context string
20
- *
21
- * @param context - The context string.
22
- * The context string should be hardcoded, globally unique, and application-specific.
23
- * @param baseKey - The base key (NOT PASSWORD!)
24
- * @returns The derived secret CryptoKey
25
- */
26
- async function deriveSymmetricCryptoKeyFromContext(context, baseKey) {
27
- try {
28
- if (baseKey.length != AES_KEY_BIT_LENGTH / 8) throw new Error(`Base key length must be exactly ${AES_KEY_BIT_LENGTH / 8} bytes`);
29
- if (!context) throw new Error("Context is empry");
30
- return await importSymmetricCryptoKey(deriveSymmetricKeyFromContext(context, baseKey));
31
- } catch (error) {
32
- throw new Error("Failed to derive CryptoKey from base key and context", { cause: error });
33
- }
34
- }
35
- /**
36
- * Derives a symmetric key from two keys
37
- *
38
- * @param key1 - The 32-bytes key
39
- * @param key2 - The 32-bytes key
40
- * @returns The derived secret key
41
- */
42
- function deriveSymmetricKeyFromTwoKeys(key1, key2) {
43
- return deriveSymmetricKeyFromTwoKeysAndContext(key1, key2, CONTEXT_DERIVE);
44
- }
45
- /**
46
- * Derives a symmetric CryptoKey from two keys
47
- *
48
- * @param key1 - The 32-bytes key
49
- * @param key2 - The 32-bytes key
50
- * @returns The derived secret CryptoKey
51
- */
52
- async function deriveSymmetricCryptoKeyFromTwoKeys(key1, key2) {
53
- try {
54
- return await importSymmetricCryptoKey(deriveSymmetricKeyFromTwoKeys(key1, key2));
55
- } catch (error) {
56
- throw new Error("Failed to derive symmetric CryptoKey from two keys", { cause: error });
57
- }
58
- }
59
- /**
60
- * Derives a symmetric key from two keys and context
61
- *
62
- * @param key1 - The 32-bytes key
63
- * @param key2 - The 32-bytes key
64
- * @param context - The context string
65
- * @returns The derived symmetric key
66
- */
67
- function deriveSymmetricKeyFromTwoKeysAndContext(key1, key2, context) {
68
- try {
69
- if (key2.length != AES_KEY_BIT_LENGTH / 8 || key1.length != AES_KEY_BIT_LENGTH / 8) throw new Error(`Input key length must be exactly ${AES_KEY_BIT_LENGTH / 8} bytes`);
70
- return blake3(blake3(key1, { key: key2 }), { context: UTF8ToUint8(context) });
71
- } catch (error) {
72
- throw new Error("Failed to derive symmetric key from two keys and context", { cause: error });
73
- }
74
- }
75
-
76
- //#endregion
77
4
  //#region node_modules/hash-wasm/dist/index.esm.js
78
5
  /******************************************************************************
79
6
  Copyright (c) Microsoft Corporation.
@@ -613,7 +540,7 @@ const mutex$1 = new Mutex();
613
540
  const mutex = new Mutex();
614
541
 
615
542
  //#endregion
616
- //#region src/derive-key/core.ts
543
+ //#region src/derive-password/core.ts
617
544
  /**
618
545
  * Calculates hash using the argon2id password-hashing function
619
546
  *
@@ -642,17 +569,11 @@ async function argon2(password, salt, parallelism = ARGON2ID_PARALLELISM, iterat
642
569
  * @returns The salt
643
570
  */
644
571
  function sampleSalt() {
645
- try {
646
- const salt = new Uint8Array(ARGON2ID_SALT_BYTE_LENGTH);
647
- crypto.getRandomValues(salt);
648
- return salt;
649
- } catch (error) {
650
- throw new Error("Failed to sample salt", { cause: error });
651
- }
572
+ return randomBytes(ARGON2ID_SALT_BYTE_LENGTH);
652
573
  }
653
574
 
654
575
  //#endregion
655
- //#region src/derive-key/deriveKeysFromPassword.ts
576
+ //#region src/derive-password/deriveKeysFromPassword.ts
656
577
  /**
657
578
  * Derives a symmetric key from a user's password with a randomly sampled salt
658
579
  *
@@ -661,7 +582,6 @@ function sampleSalt() {
661
582
  */
662
583
  async function getKeyFromPassword(password) {
663
584
  try {
664
- if (!password) throw new Error("No password given");
665
585
  const salt = sampleSalt();
666
586
  return {
667
587
  key: await argon2(password, salt),
@@ -680,56 +600,12 @@ async function getKeyFromPassword(password) {
680
600
  */
681
601
  async function getKeyFromPasswordAndSalt(password, salt) {
682
602
  try {
683
- if (!salt.length) throw new Error("No salt given");
684
- if (!password) throw new Error("No password given");
685
603
  return await argon2(password, salt);
686
604
  } catch (error) {
687
605
  throw new Error("Failed to derive key from password and salt", { cause: error });
688
606
  }
689
607
  }
690
- /**
691
- * Derives a HEX symmetric key from a user's password with a randomly sampled salt
692
- *
693
- * @param password - The user's password
694
- * @returns The derived HEX secret key and randomly sampled HEX salt
695
- */
696
- async function getKeyFromPasswordHex(password) {
697
- try {
698
- const { key, salt } = await getKeyFromPassword(password);
699
- return {
700
- keyHex: uint8ArrayToHex(key),
701
- saltHex: uint8ArrayToHex(salt)
702
- };
703
- } catch (error) {
704
- throw new Error("Failed to derive key from password", { cause: error });
705
- }
706
- }
707
- /**
708
- * Derives a HEX symmetric key from a user's password and salt
709
- *
710
- * @param password - The user's password
711
- * @param saltHex - The given HEX salt
712
- * @returns The derived HEX secret key
713
- */
714
- async function getKeyFromPasswordAndSaltHex(password, saltHex) {
715
- try {
716
- return uint8ArrayToHex(await getKeyFromPasswordAndSalt(password, hexToUint8Array(saltHex)));
717
- } catch (error) {
718
- throw new Error("Failed to derive key from password and salt", { cause: error });
719
- }
720
- }
721
- /**
722
- * Verifies the derived key
723
- *
724
- * @param password - The user's password
725
- * @param saltHex - The given HEX salt
726
- * @param keyHex - The derived HEX key
727
- * @returns The result of the key verification
728
- */
729
- async function verifyKeyFromPasswordHex(password, saltHex, keyHex) {
730
- return keyHex === await getKeyFromPasswordAndSaltHex(password, saltHex);
731
- }
732
608
 
733
609
  //#endregion
734
- export { verifyKeyFromPasswordHex as a, deriveSymmetricKeyFromContext as c, getKeyFromPasswordHex as i, deriveSymmetricKeyFromTwoKeys as l, getKeyFromPasswordAndSalt as n, deriveSymmetricCryptoKeyFromContext as o, getKeyFromPasswordAndSaltHex as r, deriveSymmetricCryptoKeyFromTwoKeys as s, getKeyFromPassword as t, deriveSymmetricKeyFromTwoKeysAndContext as u };
735
- //# sourceMappingURL=deriveKeysFromPassword-DJRWZ8Rw.mjs.map
610
+ export { getKeyFromPasswordAndSalt as n, getKeyFromPassword as t };
611
+ //# sourceMappingURL=deriveKeysFromPassword-DXgSvTNC.mjs.map