internxt-crypto 0.0.10-alpha → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +3 -4
  2. package/dist/aes-DSDxP8uF.mjs +184 -0
  3. package/dist/aes-DSDxP8uF.mjs.map +1 -0
  4. package/dist/aes-bOrKZuUC.js +226 -0
  5. package/dist/aes-bOrKZuUC.js.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +5 -2
  7. package/dist/asymmetric-crypto.d.mts.map +1 -0
  8. package/dist/asymmetric-crypto.d.ts +5 -2
  9. package/dist/asymmetric-crypto.d.ts.map +1 -0
  10. package/dist/asymmetric-crypto.js +9 -92
  11. package/dist/asymmetric-crypto.mjs +2 -84
  12. package/dist/chunk-DQk6qfdC.mjs +18 -0
  13. package/dist/chunk-EbLFQX5m.js +60 -0
  14. package/dist/constants.d.mts +5 -11
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.d.ts +5 -11
  17. package/dist/constants.d.ts.map +1 -0
  18. package/dist/constants.js +33 -49
  19. package/dist/constants.js.map +1 -1
  20. package/dist/constants.mjs +32 -40
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/derive-key.d.mts +11 -8
  23. package/dist/derive-key.d.mts.map +1 -0
  24. package/dist/derive-key.d.ts +11 -8
  25. package/dist/derive-key.d.ts.map +1 -0
  26. package/dist/derive-key.js +13 -795
  27. package/dist/derive-key.mjs +2 -783
  28. package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs +735 -0
  29. package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs.map +1 -0
  30. package/dist/deriveKeysFromPassword-Ko7NxkHM.js +2492 -0
  31. package/dist/deriveKeysFromPassword-Ko7NxkHM.js.map +1 -0
  32. package/dist/email-crypto.d.mts +55 -78
  33. package/dist/email-crypto.d.mts.map +1 -0
  34. package/dist/email-crypto.d.ts +55 -78
  35. package/dist/email-crypto.d.ts.map +1 -0
  36. package/dist/email-crypto.js +13 -1409
  37. package/dist/email-crypto.mjs +2 -1380
  38. package/dist/email-search.d.mts +36 -32
  39. package/dist/email-search.d.mts.map +1 -0
  40. package/dist/email-search.d.ts +36 -32
  41. package/dist/email-search.d.ts.map +1 -0
  42. package/dist/email-search.js +534 -540
  43. package/dist/email-search.js.map +1 -1
  44. package/dist/email-search.mjs +532 -538
  45. package/dist/email-search.mjs.map +1 -1
  46. package/dist/emailEncryptionKey-27mIHh18.mjs +150 -0
  47. package/dist/emailEncryptionKey-27mIHh18.mjs.map +1 -0
  48. package/dist/emailEncryptionKey-DbaDAdoW.js +167 -0
  49. package/dist/emailEncryptionKey-DbaDAdoW.js.map +1 -0
  50. package/dist/emailKeys-BJGdkLrg.js +593 -0
  51. package/dist/emailKeys-BJGdkLrg.js.map +1 -0
  52. package/dist/emailKeys-Fp9WR3wl.mjs +509 -0
  53. package/dist/emailKeys-Fp9WR3wl.mjs.map +1 -0
  54. package/dist/genID-3Er5IowC.mjs +153 -0
  55. package/dist/genID-3Er5IowC.mjs.map +1 -0
  56. package/dist/genID-YJSl3YhL.js +238 -0
  57. package/dist/genID-YJSl3YhL.js.map +1 -0
  58. package/dist/hash.d.mts +18 -15
  59. package/dist/hash.d.mts.map +1 -0
  60. package/dist/hash.d.ts +18 -15
  61. package/dist/hash.d.ts.map +1 -0
  62. package/dist/hash.js +12 -95
  63. package/dist/hash.mjs +2 -84
  64. package/dist/index.d.mts +15 -18
  65. package/dist/index.d.mts.map +1 -0
  66. package/dist/index.d.ts +15 -18
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +125 -2698
  69. package/dist/index.mjs +13 -2538
  70. package/dist/keys-BfcaiAOv.mjs +90 -0
  71. package/dist/keys-BfcaiAOv.mjs.map +1 -0
  72. package/dist/keys-CinT7kEY.js +125 -0
  73. package/dist/keys-CinT7kEY.js.map +1 -0
  74. package/dist/keystore-crypto.d.mts +17 -46
  75. package/dist/keystore-crypto.d.mts.map +1 -0
  76. package/dist/keystore-crypto.d.ts +17 -46
  77. package/dist/keystore-crypto.d.ts.map +1 -0
  78. package/dist/keystore-crypto.js +5 -529
  79. package/dist/keystore-crypto.mjs +2 -500
  80. package/dist/kyber1024-PpwE1rki.mjs +144 -0
  81. package/dist/kyber1024-PpwE1rki.mjs.map +1 -0
  82. package/dist/kyber1024-jeKS8CXf.js +173 -0
  83. package/dist/kyber1024-jeKS8CXf.js.map +1 -0
  84. package/dist/{kyber768-B87rMQ7u.d.mts → kyber768-DGBB_RS7.d.ts} +8 -6
  85. package/dist/kyber768-DGBB_RS7.d.ts.map +1 -0
  86. package/dist/{kyber768-B87rMQ7u.d.ts → kyber768-DzIcGg1i.d.mts} +8 -6
  87. package/dist/kyber768-DzIcGg1i.d.mts.map +1 -0
  88. package/dist/mac-BMb1F0dN.js +170 -0
  89. package/dist/mac-BMb1F0dN.js.map +1 -0
  90. package/dist/mac-ZpRlx8Fs.mjs +116 -0
  91. package/dist/mac-ZpRlx8Fs.mjs.map +1 -0
  92. package/dist/post-quantum-crypto.d.mts +23 -27
  93. package/dist/post-quantum-crypto.d.mts.map +1 -0
  94. package/dist/post-quantum-crypto.d.ts +23 -27
  95. package/dist/post-quantum-crypto.d.ts.map +1 -0
  96. package/dist/post-quantum-crypto.js +14 -92
  97. package/dist/post-quantum-crypto.mjs +2 -89
  98. package/dist/storage-service.d.mts +28 -34
  99. package/dist/storage-service.d.mts.map +1 -0
  100. package/dist/storage-service.d.ts +28 -34
  101. package/dist/storage-service.d.ts.map +1 -0
  102. package/dist/storage-service.js +51 -53
  103. package/dist/storage-service.js.map +1 -1
  104. package/dist/storage-service.mjs +40 -51
  105. package/dist/storage-service.mjs.map +1 -1
  106. package/dist/symmetric-crypto.d.mts +8 -7
  107. package/dist/symmetric-crypto.d.mts.map +1 -0
  108. package/dist/symmetric-crypto.d.ts +8 -7
  109. package/dist/symmetric-crypto.d.ts.map +1 -0
  110. package/dist/symmetric-crypto.js +10 -142
  111. package/dist/symmetric-crypto.mjs +2 -133
  112. package/dist/types.d.mts +71 -69
  113. package/dist/types.d.mts.map +1 -0
  114. package/dist/types.d.ts +71 -69
  115. package/dist/types.d.ts.map +1 -0
  116. package/dist/types.js +8 -10
  117. package/dist/types.js.map +1 -1
  118. package/dist/types.mjs +7 -9
  119. package/dist/types.mjs.map +1 -1
  120. package/dist/utils.d.mts +34 -78
  121. package/dist/utils.d.mts.map +1 -0
  122. package/dist/utils.d.ts +34 -78
  123. package/dist/utils.d.ts.map +1 -0
  124. package/dist/utils.js +17 -313
  125. package/dist/utils.mjs +2 -272
  126. package/package.json +21 -87
  127. package/dist/asymmetric-crypto.js.map +0 -1
  128. package/dist/asymmetric-crypto.mjs.map +0 -1
  129. package/dist/derive-key.js.map +0 -1
  130. package/dist/derive-key.mjs.map +0 -1
  131. package/dist/email-crypto.js.map +0 -1
  132. package/dist/email-crypto.mjs.map +0 -1
  133. package/dist/email-service.d.mts +0 -38
  134. package/dist/email-service.d.ts +0 -38
  135. package/dist/email-service.js +0 -154
  136. package/dist/email-service.js.map +0 -1
  137. package/dist/email-service.mjs +0 -147
  138. package/dist/email-service.mjs.map +0 -1
  139. package/dist/hash.js.map +0 -1
  140. package/dist/hash.mjs.map +0 -1
  141. package/dist/index.js.map +0 -1
  142. package/dist/index.mjs.map +0 -1
  143. package/dist/keystore-crypto.js.map +0 -1
  144. package/dist/keystore-crypto.mjs.map +0 -1
  145. package/dist/keystore-service.d.mts +0 -82
  146. package/dist/keystore-service.d.ts +0 -82
  147. package/dist/keystore-service.js +0 -349
  148. package/dist/keystore-service.js.map +0 -1
  149. package/dist/keystore-service.mjs +0 -342
  150. package/dist/keystore-service.mjs.map +0 -1
  151. package/dist/post-quantum-crypto.js.map +0 -1
  152. package/dist/post-quantum-crypto.mjs.map +0 -1
  153. package/dist/symmetric-crypto.js.map +0 -1
  154. package/dist/symmetric-crypto.mjs.map +0 -1
  155. package/dist/utils-BDaK_d6T.d.ts +0 -114
  156. package/dist/utils-v34IRTIx.d.mts +0 -114
  157. package/dist/utils.js.map +0 -1
  158. package/dist/utils.mjs.map +0 -1
@@ -0,0 +1,90 @@
1
+ import { AES_KEY_BIT_LENGTH, ECC_ALGORITHM } from "./constants.mjs";
2
+
3
+ //#region src/asymmetric-crypto/ellipticCurve.ts
4
+ /**
5
+ * Derives secret key from the other user's public key and own private key
6
+ *
7
+ * @param otherUserPublicKey - The public key of the other user
8
+ * @param ownPrivateKey - The private key
9
+ * @returns The derived secret key bits
10
+ */
11
+ async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
12
+ try {
13
+ const result = await crypto.subtle.deriveBits({
14
+ name: ECC_ALGORITHM,
15
+ public: otherUserPublicKey
16
+ }, ownPrivateKey, AES_KEY_BIT_LENGTH);
17
+ return new Uint8Array(result);
18
+ } catch (error) {
19
+ throw new Error("Failed to derive elliptic curve secret key", { cause: error });
20
+ }
21
+ }
22
+
23
+ //#endregion
24
+ //#region src/asymmetric-crypto/keys.ts
25
+ /**
26
+ * Generates elliptic curve key pair
27
+ *
28
+ * @returns The generated key pair
29
+ */
30
+ async function generateEccKeys() {
31
+ try {
32
+ return await crypto.subtle.generateKey({ name: ECC_ALGORITHM }, true, ["deriveBits"]);
33
+ } catch (error) {
34
+ throw new Error("Failed to generate elliptic curve key pair", { cause: error });
35
+ }
36
+ }
37
+ /**
38
+ * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
39
+ *
40
+ * @returns The Uint8Array representation of the public key
41
+ */
42
+ async function exportPublicKey(key) {
43
+ try {
44
+ const result = await crypto.subtle.exportKey("spki", key);
45
+ return new Uint8Array(result);
46
+ } catch (error) {
47
+ throw new Error("Failed to export public key", { cause: error });
48
+ }
49
+ }
50
+ /**
51
+ * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
52
+ *
53
+ * @returns The CryptoKey representation of the public key
54
+ */
55
+ async function importPublicKey(spkiKeyData) {
56
+ try {
57
+ return await crypto.subtle.importKey("spki", spkiKeyData, { name: ECC_ALGORITHM }, true, []);
58
+ } catch (error) {
59
+ throw new Error("Failed to import public key", { cause: error });
60
+ }
61
+ }
62
+ /**
63
+ * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
64
+ *
65
+ * @returns The Uint8Array representation of the private key
66
+ */
67
+ async function exportPrivateKey(key) {
68
+ try {
69
+ const result = await crypto.subtle.exportKey("pkcs8", key);
70
+ return new Uint8Array(result);
71
+ } catch (error) {
72
+ throw new Error("Failed to export private key", { cause: error });
73
+ }
74
+ }
75
+ /**
76
+ * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
77
+ *
78
+ * @returns The CryptoKey representation of the private key
79
+ */
80
+ async function importPrivateKey(pkcs8KeyData) {
81
+ try {
82
+ return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: ECC_ALGORITHM }, true, ["deriveBits"]);
83
+ } catch (error) {
84
+ throw new Error("Failed to import private key", { cause: error });
85
+ }
86
+ }
87
+
88
+ //#endregion
89
+ export { importPublicKey as a, importPrivateKey as i, exportPublicKey as n, deriveSecretKey as o, generateEccKeys as r, exportPrivateKey as t };
90
+ //# sourceMappingURL=keys-BfcaiAOv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys-BfcaiAOv.mjs","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAM;GACN,QAAQ;GACT,EACD,eACA,mBACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAM,eACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
@@ -0,0 +1,125 @@
1
+ const require_constants = require('./constants.js');
2
+
3
+ //#region src/asymmetric-crypto/ellipticCurve.ts
4
+ /**
5
+ * Derives secret key from the other user's public key and own private key
6
+ *
7
+ * @param otherUserPublicKey - The public key of the other user
8
+ * @param ownPrivateKey - The private key
9
+ * @returns The derived secret key bits
10
+ */
11
+ async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
12
+ try {
13
+ const result = await crypto.subtle.deriveBits({
14
+ name: require_constants.ECC_ALGORITHM,
15
+ public: otherUserPublicKey
16
+ }, ownPrivateKey, require_constants.AES_KEY_BIT_LENGTH);
17
+ return new Uint8Array(result);
18
+ } catch (error) {
19
+ throw new Error("Failed to derive elliptic curve secret key", { cause: error });
20
+ }
21
+ }
22
+
23
+ //#endregion
24
+ //#region src/asymmetric-crypto/keys.ts
25
+ /**
26
+ * Generates elliptic curve key pair
27
+ *
28
+ * @returns The generated key pair
29
+ */
30
+ async function generateEccKeys() {
31
+ try {
32
+ return await crypto.subtle.generateKey({ name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
33
+ } catch (error) {
34
+ throw new Error("Failed to generate elliptic curve key pair", { cause: error });
35
+ }
36
+ }
37
+ /**
38
+ * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
39
+ *
40
+ * @returns The Uint8Array representation of the public key
41
+ */
42
+ async function exportPublicKey(key) {
43
+ try {
44
+ const result = await crypto.subtle.exportKey("spki", key);
45
+ return new Uint8Array(result);
46
+ } catch (error) {
47
+ throw new Error("Failed to export public key", { cause: error });
48
+ }
49
+ }
50
+ /**
51
+ * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
52
+ *
53
+ * @returns The CryptoKey representation of the public key
54
+ */
55
+ async function importPublicKey(spkiKeyData) {
56
+ try {
57
+ return await crypto.subtle.importKey("spki", spkiKeyData, { name: require_constants.ECC_ALGORITHM }, true, []);
58
+ } catch (error) {
59
+ throw new Error("Failed to import public key", { cause: error });
60
+ }
61
+ }
62
+ /**
63
+ * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
64
+ *
65
+ * @returns The Uint8Array representation of the private key
66
+ */
67
+ async function exportPrivateKey(key) {
68
+ try {
69
+ const result = await crypto.subtle.exportKey("pkcs8", key);
70
+ return new Uint8Array(result);
71
+ } catch (error) {
72
+ throw new Error("Failed to export private key", { cause: error });
73
+ }
74
+ }
75
+ /**
76
+ * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
77
+ *
78
+ * @returns The CryptoKey representation of the private key
79
+ */
80
+ async function importPrivateKey(pkcs8KeyData) {
81
+ try {
82
+ return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
83
+ } catch (error) {
84
+ throw new Error("Failed to import private key", { cause: error });
85
+ }
86
+ }
87
+
88
+ //#endregion
89
+ Object.defineProperty(exports, 'deriveSecretKey', {
90
+ enumerable: true,
91
+ get: function () {
92
+ return deriveSecretKey;
93
+ }
94
+ });
95
+ Object.defineProperty(exports, 'exportPrivateKey', {
96
+ enumerable: true,
97
+ get: function () {
98
+ return exportPrivateKey;
99
+ }
100
+ });
101
+ Object.defineProperty(exports, 'exportPublicKey', {
102
+ enumerable: true,
103
+ get: function () {
104
+ return exportPublicKey;
105
+ }
106
+ });
107
+ Object.defineProperty(exports, 'generateEccKeys', {
108
+ enumerable: true,
109
+ get: function () {
110
+ return generateEccKeys;
111
+ }
112
+ });
113
+ Object.defineProperty(exports, 'importPrivateKey', {
114
+ enumerable: true,
115
+ get: function () {
116
+ return importPrivateKey;
117
+ }
118
+ });
119
+ Object.defineProperty(exports, 'importPublicKey', {
120
+ enumerable: true,
121
+ get: function () {
122
+ return importPublicKey;
123
+ }
124
+ });
125
+ //# sourceMappingURL=keys-CinT7kEY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys-CinT7kEY.js","names":["ECC_ALGORITHM","AES_KEY_BIT_LENGTH","ECC_ALGORITHM"],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAMA;GACN,QAAQ;GACT,EACD,eACAC,qCACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAMC,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAMA,iCACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAMA,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
@@ -1,36 +1,28 @@
1
- import { EncryptionKeys, EncryptedKeystore, IdentityKeys } from './types.mjs';
1
+ import { EmailKeys, EncryptedKeystore } from "./types.mjs";
2
2
 
3
+ //#region src/keystore-crypto/emailEncryptionKey.d.ts
3
4
  /**
4
- * Generates recovery codes
5
+ * Generates email keys and creates encrypted main and recovery keystores
6
+ * The main keystore encryption key is derived from the base key (stored in session storage)
7
+ * The recovery keystore encryption key is derived from the recovery codes
5
8
  *
6
- * @returns The generated recovery codes
9
+ * @returns The encryption and recovery keystores, recovery codes and email keys
7
10
  */
8
- declare function generateRecoveryCodes(): string;
9
- /**
10
- * Generates encryption keys
11
- *
12
- * @returns The generated encryption keys
13
- */
14
- declare function generateEncryptionKeys(): Promise<EncryptionKeys>;
15
- /**
16
- * Generates email encryption keys and creates encrypted encryption and recovery keystores
17
- * The encryption key is derived from the base key (stored in session storage)
18
- *
19
- * @returns The encryption and recovery keystores
20
- */
21
- declare function createEncryptionAndRecoveryKeystores(): Promise<{
22
- encryptionKeystore: EncryptedKeystore;
23
- recoveryKeystore: EncryptedKeystore;
24
- recoveryCodes: string;
11
+ declare function createEncryptionAndRecoveryKeystores(userEmail: string, baseKey: Uint8Array): Promise<{
12
+ encryptionKeystore: EncryptedKeystore;
13
+ recoveryKeystore: EncryptedKeystore;
14
+ recoveryCodes: string;
15
+ keys: EmailKeys;
25
16
  }>;
26
17
  /**
27
18
  * Opens the encryption keystore and returns the email encryption keys
28
19
  * The decryption key is derived from the base key (stored in session storage)
29
20
  *
30
21
  * @param encryptedKeystore - The encrypted keystore containing encryption keys
22
+ * @param baseKey - The base key from which the decryption key will be derived
31
23
  * @returns The encryption keys
32
24
  */
33
- declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): Promise<EncryptionKeys>;
25
+ declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore, baseKey: Uint8Array): Promise<EmailKeys>;
34
26
  /**
35
27
  * Opens the recovery keystore and returns the email encryption keys
36
28
  * The decryption key is derived from the base key (stored in session storage)
@@ -39,28 +31,7 @@ declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): P
39
31
  * @param encryptedKeystore - The encrypted keystore containing encryption keys
40
32
  * @returns The encryption keys
41
33
  */
42
- declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<EncryptionKeys>;
43
-
44
- /**
45
- * Generates user idenity keys
46
- *
47
- * @returns The user identity keys
48
- */
49
- declare function generateIdentityKeys(): Promise<IdentityKeys>;
50
- /**
51
- * Generates user identity keys and creates an encrypted identity keystore
52
- * The encryption key is derived from the base key (stored in session storage)
53
- *
54
- * @returns The encrypted idenity keystore
55
- */
56
- declare function createIdentityKeystore(): Promise<EncryptedKeystore>;
57
- /**
58
- * Opens the encrypted identity keystore
59
- * The decryption key is derived from the base key (stored in session storage)
60
- *
61
- * @param encryptedKeystore - The encrypted identity keystore
62
- * @returns The identity keys
63
- */
64
- declare function openIdentityKeystore(encryptedKeystore: EncryptedKeystore): Promise<IdentityKeys>;
65
-
66
- export { createEncryptionAndRecoveryKeystores, createIdentityKeystore, generateEncryptionKeys, generateIdentityKeys, generateRecoveryCodes, openEncryptionKeystore, openIdentityKeystore, openRecoveryKeystore };
34
+ declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<EmailKeys>;
35
+ //#endregion
36
+ export { createEncryptionAndRecoveryKeystores, openEncryptionKeystore, openRecoveryKeystore };
37
+ //# sourceMappingURL=keystore-crypto.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keystore-crypto.d.mts","names":[],"sources":["../src/keystore-crypto/emailEncryptionKey.ts"],"mappings":";;;;;AAYA;;;;;iBAAsB,oCAAA,CACpB,SAAA,UACA,OAAA,EAAS,UAAA,GACR,OAAA;EACD,kBAAA,EAAoB,iBAAA;EACpB,gBAAA,EAAkB,iBAAA;EAClB,aAAA;EACA,IAAA,EAAM,SAAA;AAAA;;;;;;;;;iBA0Bc,sBAAA,CACpB,iBAAA,EAAmB,iBAAA,EACnB,OAAA,EAAS,UAAA,GACR,OAAA,CAAQ,SAAA;;;;AAHX;;;;;iBAwBsB,oBAAA,CACpB,aAAA,UACA,iBAAA,EAAmB,iBAAA,GAClB,OAAA,CAAQ,SAAA"}
@@ -1,36 +1,28 @@
1
- import { EncryptionKeys, EncryptedKeystore, IdentityKeys } from './types.js';
1
+ import { EmailKeys, EncryptedKeystore } from "./types.js";
2
2
 
3
+ //#region src/keystore-crypto/emailEncryptionKey.d.ts
3
4
  /**
4
- * Generates recovery codes
5
+ * Generates email keys and creates encrypted main and recovery keystores
6
+ * The main keystore encryption key is derived from the base key (stored in session storage)
7
+ * The recovery keystore encryption key is derived from the recovery codes
5
8
  *
6
- * @returns The generated recovery codes
9
+ * @returns The encryption and recovery keystores, recovery codes and email keys
7
10
  */
8
- declare function generateRecoveryCodes(): string;
9
- /**
10
- * Generates encryption keys
11
- *
12
- * @returns The generated encryption keys
13
- */
14
- declare function generateEncryptionKeys(): Promise<EncryptionKeys>;
15
- /**
16
- * Generates email encryption keys and creates encrypted encryption and recovery keystores
17
- * The encryption key is derived from the base key (stored in session storage)
18
- *
19
- * @returns The encryption and recovery keystores
20
- */
21
- declare function createEncryptionAndRecoveryKeystores(): Promise<{
22
- encryptionKeystore: EncryptedKeystore;
23
- recoveryKeystore: EncryptedKeystore;
24
- recoveryCodes: string;
11
+ declare function createEncryptionAndRecoveryKeystores(userEmail: string, baseKey: Uint8Array): Promise<{
12
+ encryptionKeystore: EncryptedKeystore;
13
+ recoveryKeystore: EncryptedKeystore;
14
+ recoveryCodes: string;
15
+ keys: EmailKeys;
25
16
  }>;
26
17
  /**
27
18
  * Opens the encryption keystore and returns the email encryption keys
28
19
  * The decryption key is derived from the base key (stored in session storage)
29
20
  *
30
21
  * @param encryptedKeystore - The encrypted keystore containing encryption keys
22
+ * @param baseKey - The base key from which the decryption key will be derived
31
23
  * @returns The encryption keys
32
24
  */
33
- declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): Promise<EncryptionKeys>;
25
+ declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore, baseKey: Uint8Array): Promise<EmailKeys>;
34
26
  /**
35
27
  * Opens the recovery keystore and returns the email encryption keys
36
28
  * The decryption key is derived from the base key (stored in session storage)
@@ -39,28 +31,7 @@ declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): P
39
31
  * @param encryptedKeystore - The encrypted keystore containing encryption keys
40
32
  * @returns The encryption keys
41
33
  */
42
- declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<EncryptionKeys>;
43
-
44
- /**
45
- * Generates user idenity keys
46
- *
47
- * @returns The user identity keys
48
- */
49
- declare function generateIdentityKeys(): Promise<IdentityKeys>;
50
- /**
51
- * Generates user identity keys and creates an encrypted identity keystore
52
- * The encryption key is derived from the base key (stored in session storage)
53
- *
54
- * @returns The encrypted idenity keystore
55
- */
56
- declare function createIdentityKeystore(): Promise<EncryptedKeystore>;
57
- /**
58
- * Opens the encrypted identity keystore
59
- * The decryption key is derived from the base key (stored in session storage)
60
- *
61
- * @param encryptedKeystore - The encrypted identity keystore
62
- * @returns The identity keys
63
- */
64
- declare function openIdentityKeystore(encryptedKeystore: EncryptedKeystore): Promise<IdentityKeys>;
65
-
66
- export { createEncryptionAndRecoveryKeystores, createIdentityKeystore, generateEncryptionKeys, generateIdentityKeys, generateRecoveryCodes, openEncryptionKeystore, openIdentityKeystore, openRecoveryKeystore };
34
+ declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<EmailKeys>;
35
+ //#endregion
36
+ export { createEncryptionAndRecoveryKeystores, openEncryptionKeystore, openRecoveryKeystore };
37
+ //# sourceMappingURL=keystore-crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keystore-crypto.d.ts","names":[],"sources":["../src/keystore-crypto/emailEncryptionKey.ts"],"mappings":";;;;;AAYA;;;;;iBAAsB,oCAAA,CACpB,SAAA,UACA,OAAA,EAAS,UAAA,GACR,OAAA;EACD,kBAAA,EAAoB,iBAAA;EACpB,gBAAA,EAAkB,iBAAA;EAClB,aAAA;EACA,IAAA,EAAM,SAAA;AAAA;;;;;;;;;iBA0Bc,sBAAA,CACpB,iBAAA,EAAmB,iBAAA,EACnB,OAAA,EAAS,UAAA,GACR,OAAA,CAAQ,SAAA;;;;AAHX;;;;;iBAwBsB,oBAAA,CACpB,aAAA,UACA,iBAAA,EAAmB,iBAAA,GAClB,OAAA,CAAQ,SAAA"}