internxt-crypto 0.0.10-alpha → 0.0.11

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 (148) hide show
  1. package/README.md +3 -4
  2. package/dist/asymmetric-crypto-BORmLhnx.js +143 -0
  3. package/dist/asymmetric-crypto-BORmLhnx.js.map +1 -0
  4. package/dist/asymmetric-crypto-CyXsV4XT.mjs +102 -0
  5. package/dist/asymmetric-crypto-CyXsV4XT.mjs.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +9 -3
  7. package/dist/asymmetric-crypto.d.ts +9 -3
  8. package/dist/asymmetric-crypto.js +8 -92
  9. package/dist/asymmetric-crypto.mjs +2 -84
  10. package/dist/chunk-DWirmd9C.mjs +18 -0
  11. package/dist/chunk-Dt-PWiN7.js +60 -0
  12. package/dist/constants-Ccp21E03.js +208 -0
  13. package/dist/constants-Ccp21E03.js.map +1 -0
  14. package/dist/constants-kTeX-2T0.mjs +34 -0
  15. package/dist/constants-kTeX-2T0.mjs.map +1 -0
  16. package/dist/constants.d.mts +5 -11
  17. package/dist/constants.d.ts +5 -11
  18. package/dist/constants.js +30 -79
  19. package/dist/constants.mjs +2 -41
  20. package/dist/derive-key-Be7hS-cN.mjs +751 -0
  21. package/dist/derive-key-Be7hS-cN.mjs.map +1 -0
  22. package/dist/derive-key-CBf2WxJd.js +2513 -0
  23. package/dist/derive-key-CBf2WxJd.js.map +1 -0
  24. package/dist/derive-key.d.mts +14 -8
  25. package/dist/derive-key.d.ts +14 -8
  26. package/dist/derive-key.js +15 -795
  27. package/dist/derive-key.mjs +5 -783
  28. package/dist/email-crypto-BrT98taw.js +617 -0
  29. package/dist/email-crypto-BrT98taw.js.map +1 -0
  30. package/dist/email-crypto-DJUEjTxA.mjs +534 -0
  31. package/dist/email-crypto-DJUEjTxA.mjs.map +1 -0
  32. package/dist/email-crypto.d.mts +58 -78
  33. package/dist/email-crypto.d.ts +58 -78
  34. package/dist/email-crypto.js +17 -1409
  35. package/dist/email-crypto.mjs +8 -1381
  36. package/dist/email-search.d.mts +39 -32
  37. package/dist/email-search.d.ts +39 -32
  38. package/dist/email-search.js +572 -540
  39. package/dist/email-search.js.map +1 -1
  40. package/dist/email-search.mjs +567 -539
  41. package/dist/email-search.mjs.map +1 -1
  42. package/dist/hash-BoqwNkcd.js +190 -0
  43. package/dist/hash-BoqwNkcd.js.map +1 -0
  44. package/dist/hash-CXeGAwai.mjs +131 -0
  45. package/dist/hash-CXeGAwai.mjs.map +1 -0
  46. package/dist/hash.d.mts +21 -15
  47. package/dist/hash.d.ts +21 -15
  48. package/dist/hash.js +11 -95
  49. package/dist/hash.mjs +2 -84
  50. package/dist/index-CQqgKsbX.d.ts +50 -0
  51. package/dist/index-CintVUbp.d.ts +97 -0
  52. package/dist/index-D5pBU_A5.d.mts +50 -0
  53. package/dist/index-MaOov-ag.d.mts +97 -0
  54. package/dist/index.d.mts +35 -18
  55. package/dist/index.d.ts +35 -18
  56. package/dist/index.js +103 -2685
  57. package/dist/index.mjs +15 -2538
  58. package/dist/keystore-crypto-B4yCVo9l.js +182 -0
  59. package/dist/keystore-crypto-B4yCVo9l.js.map +1 -0
  60. package/dist/keystore-crypto-Bjgriq9h.mjs +159 -0
  61. package/dist/keystore-crypto-Bjgriq9h.mjs.map +1 -0
  62. package/dist/keystore-crypto.d.mts +20 -46
  63. package/dist/keystore-crypto.d.ts +20 -46
  64. package/dist/keystore-crypto.js +11 -530
  65. package/dist/keystore-crypto.mjs +9 -501
  66. package/dist/keystore-service.d.mts +44 -78
  67. package/dist/keystore-service.d.ts +44 -78
  68. package/dist/keystore-service.js +113 -340
  69. package/dist/keystore-service.js.map +1 -1
  70. package/dist/keystore-service.mjs +107 -335
  71. package/dist/keystore-service.mjs.map +1 -1
  72. package/dist/post-quantum-crypto-CAi-cEkV.js +189 -0
  73. package/dist/post-quantum-crypto-CAi-cEkV.js.map +1 -0
  74. package/dist/post-quantum-crypto-Vv34t6gX.mjs +154 -0
  75. package/dist/post-quantum-crypto-Vv34t6gX.mjs.map +1 -0
  76. package/dist/post-quantum-crypto.d.mts +2 -72
  77. package/dist/post-quantum-crypto.d.ts +2 -72
  78. package/dist/post-quantum-crypto.js +13 -92
  79. package/dist/post-quantum-crypto.mjs +2 -89
  80. package/dist/storage-service-BgIK2aYZ.js +82 -0
  81. package/dist/storage-service-BgIK2aYZ.js.map +1 -0
  82. package/dist/storage-service-CubCbhY2.mjs +65 -0
  83. package/dist/storage-service-CubCbhY2.mjs.map +1 -0
  84. package/dist/storage-service.d.mts +2 -53
  85. package/dist/storage-service.d.ts +2 -53
  86. package/dist/storage-service.js +12 -68
  87. package/dist/storage-service.mjs +2 -66
  88. package/dist/symmetric-crypto-CrdS1Che.mjs +197 -0
  89. package/dist/symmetric-crypto-CrdS1Che.mjs.map +1 -0
  90. package/dist/symmetric-crypto-D65zB396.js +244 -0
  91. package/dist/symmetric-crypto-D65zB396.js.map +1 -0
  92. package/dist/symmetric-crypto.d.mts +12 -8
  93. package/dist/symmetric-crypto.d.ts +12 -8
  94. package/dist/symmetric-crypto.js +10 -142
  95. package/dist/symmetric-crypto.mjs +3 -133
  96. package/dist/types-52g887Zi.js +16 -0
  97. package/dist/types-52g887Zi.js.map +1 -0
  98. package/dist/types-BiEoleqw.mjs +10 -0
  99. package/dist/types-BiEoleqw.mjs.map +1 -0
  100. package/dist/types-Ds3ivE9W.d.ts +104 -0
  101. package/dist/types-DwQJtrTx.d.mts +104 -0
  102. package/dist/types.d.mts +2 -102
  103. package/dist/types.d.ts +2 -102
  104. package/dist/types.js +2 -13
  105. package/dist/types.mjs +2 -11
  106. package/dist/utils-CNs3cyDj.js +263 -0
  107. package/dist/utils-CNs3cyDj.js.map +1 -0
  108. package/dist/utils-DS04iUcX.mjs +173 -0
  109. package/dist/utils-DS04iUcX.mjs.map +1 -0
  110. package/dist/utils.d.mts +37 -78
  111. package/dist/utils.d.ts +37 -78
  112. package/dist/utils.js +16 -313
  113. package/dist/utils.mjs +2 -272
  114. package/package.json +15 -90
  115. package/dist/asymmetric-crypto.js.map +0 -1
  116. package/dist/asymmetric-crypto.mjs.map +0 -1
  117. package/dist/constants.js.map +0 -1
  118. package/dist/constants.mjs.map +0 -1
  119. package/dist/derive-key.js.map +0 -1
  120. package/dist/derive-key.mjs.map +0 -1
  121. package/dist/email-crypto.js.map +0 -1
  122. package/dist/email-crypto.mjs.map +0 -1
  123. package/dist/email-service.d.mts +0 -38
  124. package/dist/email-service.d.ts +0 -38
  125. package/dist/email-service.js +0 -154
  126. package/dist/email-service.js.map +0 -1
  127. package/dist/email-service.mjs +0 -147
  128. package/dist/email-service.mjs.map +0 -1
  129. package/dist/hash.js.map +0 -1
  130. package/dist/hash.mjs.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/index.mjs.map +0 -1
  133. package/dist/keystore-crypto.js.map +0 -1
  134. package/dist/keystore-crypto.mjs.map +0 -1
  135. package/dist/kyber768-B87rMQ7u.d.mts +0 -30
  136. package/dist/kyber768-B87rMQ7u.d.ts +0 -30
  137. package/dist/post-quantum-crypto.js.map +0 -1
  138. package/dist/post-quantum-crypto.mjs.map +0 -1
  139. package/dist/storage-service.js.map +0 -1
  140. package/dist/storage-service.mjs.map +0 -1
  141. package/dist/symmetric-crypto.js.map +0 -1
  142. package/dist/symmetric-crypto.mjs.map +0 -1
  143. package/dist/types.js.map +0 -1
  144. package/dist/types.mjs.map +0 -1
  145. package/dist/utils-BDaK_d6T.d.ts +0 -114
  146. package/dist/utils-v34IRTIx.d.mts +0 -114
  147. package/dist/utils.js.map +0 -1
  148. package/dist/utils.mjs.map +0 -1
@@ -1,82 +1,48 @@
1
- import { AxiosResponse } from 'axios';
2
- import { KeystoreType, EncryptedKeystore, PublicKeys } from './types.js';
1
+ import { c as EncryptedKeystore, d as KeystoreType, g as PublicKeysBase64, h as PublicKeys } from "./types-Ds3ivE9W.js";
2
+ import { AxiosResponse } from "axios";
3
3
 
4
+ //#region src/keystore-service/api.d.ts
4
5
  declare class KeyServiceAPI {
5
- private readonly baseUrl;
6
- constructor(baseUrl: string);
7
- /**
8
- * Converts the specific client error into a proprietary error for our apps
9
- * @param error
10
- * @private
11
- */
12
- private normalizeError;
13
- /**
14
- * Sends a user's encrypted keystore to the server
15
- * @param keystore - The encrypted keystore
16
- * @param url - The user specific part of the url
17
- * @returns Server response
18
- */
19
- sendEncryptedKeystoreToServer(encryptedKeystore: string, url: string): Promise<AxiosResponse>;
20
- /**
21
- * Requests a user's encrypted keystore from the server
22
- * @param url - The user-specific part of the url
23
- * @returns The user's encrypted keystore as base64 string
24
- */
25
- requestEncryptedKeystore(userID: string, keystoreType: KeystoreType): Promise<string>;
26
- /**
27
- * Uploads encrypted keystore to the server
28
- *
29
- * @param encryptedKeystore - The encrypted keystore
30
- * @param type - The keystore's type
31
- * @returns Server response
32
- */
33
- uploadKeystoreToServer(encryptedKeystore: EncryptedKeystore): Promise<AxiosResponse>;
34
- /**
35
- * Gets a user's encrypted keystore containing encryption keys from the server
36
- *
37
- * @returns Encrypted keystore containing encryption keys
38
- */
39
- getEncryptionKeystoreFromServer(): Promise<EncryptedKeystore>;
40
- /**
41
- * Gets a user's encrypted Identity Keystore from the server
42
- *
43
- * @returns Encrypted Identity Keystore
44
- */
45
- getIdentityKeystoreFromServer(): Promise<EncryptedKeystore>;
46
- /**
47
- * Gets a user's encrypted Recovery Keystore from the server
48
- *
49
- * @returns Encrypted Recovery Keystore
50
- */
51
- getRecoveryKeystoreFromServer(): Promise<EncryptedKeystore>;
52
- /**
53
- * Gets a user's encrypted Index Keystore from the server
54
- *
55
- * @returns Encrypted Index Keytore
56
- */
57
- getIndexKeystoreFromServer(): Promise<EncryptedKeystore>;
58
- /**
59
- * Gets a user's encrypted keystore from the server
60
- *
61
- * @param type - The requested keystore's type
62
- * @returns Encrypted Keytore
63
- */
64
- getKeystoreFromServer(type: KeystoreType): Promise<EncryptedKeystore>;
65
- /**
66
- * Obtains recipients public keys from the server
67
- *
68
- * @param emails - The recipients' emails
69
- * @returns The list of recipients' public keys
70
- */
71
- getRecipientsPublicKeysFromServer(emails: string[]): Promise<string[]>;
72
- /**
73
- * Obtains the recipient public keys from the server
74
- *
75
- * @param email - The recipients' emails
76
- * @returns The list of recipients' public keys
77
- */
78
- getRecipientsPublicKeys(emails: string[]): Promise<PublicKeys[]>;
6
+ private readonly baseUrl;
7
+ constructor(baseUrl: string);
8
+ /**
9
+ * Converts the specific client error into a proprietary error for our apps
10
+ * @param error
11
+ * @private
12
+ */
13
+ private normalizeError;
14
+ /**
15
+ * Sends a user's encrypted keystore to the server
16
+ * @param keystore - The encrypted keystore
17
+ * @param url - The user specific part of the url
18
+ * @returns Server response
19
+ */
20
+ uploadKeystoreToServer(encryptedKeystore: EncryptedKeystore): Promise<AxiosResponse>;
21
+ /**
22
+ * Requests a user's encrypted keystore from the server
23
+ * @param url - The user-specific part of the url
24
+ * @returns The user's encrypted keystore as base64 string
25
+ */
26
+ getKeystoreFromServer(userID: string, keystoreType: KeystoreType): Promise<EncryptedKeystore>;
27
+ /**
28
+ * Obtains recipients public keys from the server
29
+ *
30
+ * @param emails - The recipients' emails
31
+ * @returns The list of recipients' public keys
32
+ */
33
+ getRecipientsPublicKeysFromServer(emails: string[]): Promise<PublicKeysBase64[]>;
34
+ /**
35
+ * Obtains the recipient public keys from the server
36
+ *
37
+ * @param email - The recipients' emails
38
+ * @returns The list of recipients' public keys
39
+ */
40
+ getRecipientsPublicKeys(emails: string[]): Promise<PublicKeys[]>;
79
41
  }
80
42
  declare function getKeyServiceAPI(baseUrl: string): KeyServiceAPI;
81
-
82
- export { KeyServiceAPI, getKeyServiceAPI };
43
+ declare namespace index_d_exports {
44
+ export { KeyServiceAPI, getKeyServiceAPI };
45
+ }
46
+ //#endregion
47
+ export { KeyServiceAPI, getKeyServiceAPI, index_d_exports as t };
48
+ //# sourceMappingURL=keystore-service.d.ts.map
@@ -1,349 +1,122 @@
1
- 'use strict';
1
+ const require_chunk = require('./chunk-Dt-PWiN7.js');
2
+ const require_utils = require('./utils-CNs3cyDj.js');
3
+ let axios = require("axios");
4
+ axios = require_chunk.__toESM(axios);
2
5
 
3
- var axios = require('axios');
4
- require('@noble/hashes/utils.js');
5
-
6
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
-
8
- var axios__default = /*#__PURE__*/_interopDefault(axios);
9
-
10
- // src/keystore-service/api.ts
11
-
12
- // src/constants.ts
13
- var ECC_ALGORITHM = "X25519";
14
- function uint8ArrayToBase64(buffer) {
15
- const array = Uint16Array.from(buffer);
16
- const binaryString = new TextDecoder("UTF-16").decode(array);
17
- return btoa(binaryString);
18
- }
19
- function base64ToUint8Array(str) {
20
- const binaryString = atob(str);
21
- const len = binaryString.length;
22
- const array = new Uint8Array(len);
23
- for (let i = 0; i < len; i++) {
24
- array[i] = binaryString.charCodeAt(i);
25
- }
26
- return new Uint8Array(array.buffer);
27
- }
28
-
29
- // src/asymmetric-crypto/keys.ts
30
- async function importPublicKey(spkiKeyData) {
31
- try {
32
- return await crypto.subtle.importKey(
33
- "spki",
34
- spkiKeyData,
35
- {
36
- name: ECC_ALGORITHM
37
- },
38
- true,
39
- []
40
- );
41
- } catch (error) {
42
- throw new Error("Failed to import public key", { cause: error });
43
- }
44
- }
45
-
46
- // src/utils/aesConverters.ts
47
- function ciphertextToBase64(encryptedMessage) {
48
- try {
49
- const ivBase64 = uint8ArrayToBase64(encryptedMessage.iv);
50
- const ciphertextBase64 = uint8ArrayToBase64(encryptedMessage.ciphertext);
51
- const json = JSON.stringify({ ciphertext: ciphertextBase64, iv: ivBase64 });
52
- const base64 = btoa(json);
53
- return base64;
54
- } catch (error) {
55
- throw new Error("Failed to convert ciphertext to base64", { cause: error });
56
- }
57
- }
58
- function base64ToCiphertext(base64) {
59
- try {
60
- const json = atob(base64);
61
- const obj = JSON.parse(json);
62
- const iv = base64ToUint8Array(obj.iv);
63
- const ciphertext = base64ToUint8Array(obj.ciphertext);
64
- const result = {
65
- ciphertext,
66
- iv
67
- };
68
- return result;
69
- } catch (error) {
70
- throw new Error("Failed to convert base64 to ciphertext", { cause: error });
71
- }
72
- }
73
-
74
- // src/utils/keyConverters.ts
75
- function encryptedKeystoreToBase64(keystore) {
76
- try {
77
- const ciphertext = ciphertextToBase64(keystore.encryptedKeys);
78
- const json = JSON.stringify({
79
- userID: keystore.userID,
80
- type: keystore.type.toString(),
81
- encryptedKeys: ciphertext
82
- });
83
- const base64 = btoa(json);
84
- return base64;
85
- } catch (error) {
86
- throw new Error("Failed to convert encrypted keystore to base64", { cause: error });
87
- }
88
- }
89
- function base64ToEncryptedKeystore(base64) {
90
- try {
91
- const json = atob(base64);
92
- const obj = JSON.parse(json);
93
- const ciphertext = base64ToCiphertext(obj.encryptedKeys);
94
- const result = {
95
- userID: obj.userID,
96
- type: obj.type,
97
- encryptedKeys: ciphertext
98
- };
99
- return result;
100
- } catch (error) {
101
- throw new Error("Failed to convert base64 to encrypted keystore", { cause: error });
102
- }
103
- }
104
- async function base64ToPublicKey(base64) {
105
- try {
106
- const json = atob(base64);
107
- const obj = JSON.parse(json);
108
- const eccPublicKeyBytes = base64ToUint8Array(obj.eccPublicKey);
109
- const eccPublicKey = await importPublicKey(eccPublicKeyBytes);
110
- const kyberPublicKey = base64ToUint8Array(obj.kyberPublicKey);
111
- return {
112
- eccPublicKey,
113
- kyberPublicKey
114
- };
115
- } catch (error) {
116
- throw new Error("Failed to convert base64 to PublicKeys", { cause: error });
117
- }
118
- }
119
-
120
- // src/storage-service/sessionStorageService.ts
121
- function get(key) {
122
- return sessionStorage.getItem(key);
123
- }
124
- function set(key, value) {
125
- return sessionStorage.setItem(key, value);
126
- }
127
- function removeItem(key) {
128
- sessionStorage.removeItem(key);
129
- }
130
- function exists(key) {
131
- return !!sessionStorage.getItem(key);
132
- }
133
- function clear() {
134
- sessionStorage.clear();
135
- }
136
- var sessionStorageService = {
137
- set,
138
- get,
139
- removeItem,
140
- exists,
141
- clear
142
- };
143
- var sessionStorageService_default = sessionStorageService;
144
-
145
- // src/keystore-crypto/core.ts
146
- function getUserID() {
147
- try {
148
- const userID = sessionStorageService_default.get("userID");
149
- if (!userID) {
150
- throw new Error("No UserID");
151
- }
152
- return userID;
153
- } catch (error) {
154
- throw new Error("Failed to get UserID from session storage", { cause: error });
155
- }
156
- }
157
-
158
- // src/keystore-service/api.ts
6
+ //#region src/keystore-service/api.ts
159
7
  var KeyServiceAPI = class {
160
- baseUrl;
161
- constructor(baseUrl) {
162
- this.baseUrl = baseUrl;
163
- }
164
- /**
165
- * Converts the specific client error into a proprietary error for our apps
166
- * @param error
167
- * @private
168
- */
169
- normalizeError(error) {
170
- let errorMessage;
171
- if (error.response?.status === 401) {
172
- errorMessage = "Unauthorized: Invalid or expired token";
173
- } else if (error.response?.status === 403) {
174
- errorMessage = "Forbidden: Insufficient permissions";
175
- } else if (error.response?.status === 404) {
176
- errorMessage = "Keystore not found for the specified user";
177
- } else {
178
- errorMessage = "AxiosError:" + (error.message ?? "Unknown error");
179
- }
180
- throw new Error(errorMessage);
181
- }
182
- /**
183
- * Sends a user's encrypted keystore to the server
184
- * @param keystore - The encrypted keystore
185
- * @param url - The user specific part of the url
186
- * @returns Server response
187
- */
188
- async sendEncryptedKeystoreToServer(encryptedKeystore, url) {
189
- try {
190
- const response = await axios__default.default.post(
191
- this.baseUrl + `${url}`,
192
- { encryptedKeystore },
193
- {
194
- withCredentials: true,
195
- headers: {
196
- "Content-Type": "application/json"
197
- }
198
- }
199
- );
200
- return response;
201
- } catch (error) {
202
- if (axios__default.default.isAxiosError(error)) {
203
- this.normalizeError(error);
204
- }
205
- throw new Error("Failed to send keystore", { cause: error });
206
- }
207
- }
208
- /**
209
- * Requests a user's encrypted keystore from the server
210
- * @param url - The user-specific part of the url
211
- * @returns The user's encrypted keystore as base64 string
212
- */
213
- async requestEncryptedKeystore(userID, keystoreType) {
214
- try {
215
- const url = `/downloadKeystore/${userID}/${keystoreType.toString()}`;
216
- const response = await axios__default.default.get(this.baseUrl + `${url}`, {
217
- withCredentials: true,
218
- headers: {
219
- "Content-Type": "application/json"
220
- }
221
- });
222
- return response.data;
223
- } catch (error) {
224
- if (axios__default.default.isAxiosError(error)) {
225
- this.normalizeError(error);
226
- }
227
- throw new Error("Failed to retrive keystore", { cause: error });
228
- }
229
- }
230
- /**
231
- * Uploads encrypted keystore to the server
232
- *
233
- * @param encryptedKeystore - The encrypted keystore
234
- * @param type - The keystore's type
235
- * @returns Server response
236
- */
237
- async uploadKeystoreToServer(encryptedKeystore) {
238
- try {
239
- const userID = getUserID();
240
- const keystoreType = encryptedKeystore.type;
241
- const url = `/uploadKeystore/${userID}/${keystoreType}`;
242
- const ciphertextBase64 = encryptedKeystoreToBase64(encryptedKeystore);
243
- const result = await this.sendEncryptedKeystoreToServer(ciphertextBase64, url);
244
- return result;
245
- } catch (error) {
246
- throw new Error("Failed to upload keystore to the server", { cause: error });
247
- }
248
- }
249
- /**
250
- * Gets a user's encrypted keystore containing encryption keys from the server
251
- *
252
- * @returns Encrypted keystore containing encryption keys
253
- */
254
- async getEncryptionKeystoreFromServer() {
255
- return this.getKeystoreFromServer("encryption" /* ENCRYPTION */);
256
- }
257
- /**
258
- * Gets a user's encrypted Identity Keystore from the server
259
- *
260
- * @returns Encrypted Identity Keystore
261
- */
262
- async getIdentityKeystoreFromServer() {
263
- return this.getKeystoreFromServer("identity" /* IDENTITY */);
264
- }
265
- /**
266
- * Gets a user's encrypted Recovery Keystore from the server
267
- *
268
- * @returns Encrypted Recovery Keystore
269
- */
270
- async getRecoveryKeystoreFromServer() {
271
- return this.getKeystoreFromServer("recovery" /* RECOVERY */);
272
- }
273
- /**
274
- * Gets a user's encrypted Index Keystore from the server
275
- *
276
- * @returns Encrypted Index Keytore
277
- */
278
- async getIndexKeystoreFromServer() {
279
- return this.getKeystoreFromServer("index" /* INDEX */);
280
- }
281
- /**
282
- * Gets a user's encrypted keystore from the server
283
- *
284
- * @param type - The requested keystore's type
285
- * @returns Encrypted Keytore
286
- */
287
- async getKeystoreFromServer(type) {
288
- try {
289
- const userID = getUserID();
290
- const response = await this.requestEncryptedKeystore(userID, type);
291
- const result = base64ToEncryptedKeystore(response);
292
- return result;
293
- } catch (error) {
294
- throw new Error("Failed to retrieve keystore from the server", { cause: error });
295
- }
296
- }
297
- /**
298
- * Obtains recipients public keys from the server
299
- *
300
- * @param emails - The recipients' emails
301
- * @returns The list of recipients' public keys
302
- */
303
- async getRecipientsPublicKeysFromServer(emails) {
304
- try {
305
- const response = await axios__default.default.get("/api/getPublicKeys", {
306
- params: {
307
- emails
308
- },
309
- withCredentials: true,
310
- headers: {
311
- "Content-Type": "application/json"
312
- }
313
- });
314
- return response.data;
315
- } catch (error) {
316
- if (axios__default.default.isAxiosError(error)) {
317
- this.normalizeError(error);
318
- }
319
- throw new Error("Failed to retrieve public keys", { cause: error });
320
- }
321
- }
322
- /**
323
- * Obtains the recipient public keys from the server
324
- *
325
- * @param email - The recipients' emails
326
- * @returns The list of recipients' public keys
327
- */
328
- async getRecipientsPublicKeys(emails) {
329
- try {
330
- const publicKeysBase64 = await this.getRecipientsPublicKeysFromServer(emails);
331
- const result = [];
332
- for (const keyBase64 of publicKeysBase64) {
333
- const publicKeys = await base64ToPublicKey(keyBase64);
334
- result.push(publicKeys);
335
- }
336
- return result;
337
- } catch (error) {
338
- throw new Error("Failed to get recipients public keys", { cause: error });
339
- }
340
- }
8
+ constructor(baseUrl) {
9
+ this.baseUrl = baseUrl;
10
+ }
11
+ /**
12
+ * Converts the specific client error into a proprietary error for our apps
13
+ * @param error
14
+ * @private
15
+ */
16
+ normalizeError(error) {
17
+ let errorMessage;
18
+ if (error.response?.status === 401) errorMessage = "Unauthorized: Invalid or expired token";
19
+ else if (error.response?.status === 403) errorMessage = "Forbidden: Insufficient permissions";
20
+ else if (error.response?.status === 404) errorMessage = "Keystore not found for the specified user";
21
+ else errorMessage = "AxiosError:" + (error.message ?? "Unknown error");
22
+ throw new Error(errorMessage);
23
+ }
24
+ /**
25
+ * Sends a user's encrypted keystore to the server
26
+ * @param keystore - The encrypted keystore
27
+ * @param url - The user specific part of the url
28
+ * @returns Server response
29
+ */
30
+ async uploadKeystoreToServer(encryptedKeystore) {
31
+ try {
32
+ const url = `${this.baseUrl}/uploadKeystore`;
33
+ return await axios.default.post(url, { encryptedKeystore }, {
34
+ withCredentials: true,
35
+ headers: { "Content-Type": "application/json" }
36
+ });
37
+ } catch (error) {
38
+ if (axios.default.isAxiosError(error)) this.normalizeError(error);
39
+ throw new Error("Failed to send keystore", { cause: error });
40
+ }
41
+ }
42
+ /**
43
+ * Requests a user's encrypted keystore from the server
44
+ * @param url - The user-specific part of the url
45
+ * @returns The user's encrypted keystore as base64 string
46
+ */
47
+ async getKeystoreFromServer(userID, keystoreType) {
48
+ try {
49
+ const url = `${this.baseUrl}/downloadKeystore`;
50
+ return (await axios.default.get(url, {
51
+ params: {
52
+ userID,
53
+ keystoreType
54
+ },
55
+ withCredentials: true,
56
+ headers: { "Content-Type": "application/json" }
57
+ })).data;
58
+ } catch (error) {
59
+ if (axios.default.isAxiosError(error)) this.normalizeError(error);
60
+ throw new Error("Failed to retrive keystore", { cause: error });
61
+ }
62
+ }
63
+ /**
64
+ * Obtains recipients public keys from the server
65
+ *
66
+ * @param emails - The recipients' emails
67
+ * @returns The list of recipients' public keys
68
+ */
69
+ async getRecipientsPublicKeysFromServer(emails) {
70
+ try {
71
+ const url = `${this.baseUrl}/getPublicKeys`;
72
+ return (await axios.default.get(url, {
73
+ params: { emails },
74
+ withCredentials: true,
75
+ headers: { "Content-Type": "application/json" }
76
+ })).data;
77
+ } catch (error) {
78
+ if (axios.default.isAxiosError(error)) this.normalizeError(error);
79
+ throw new Error("Failed to retrieve public keys", { cause: error });
80
+ }
81
+ }
82
+ /**
83
+ * Obtains the recipient public keys from the server
84
+ *
85
+ * @param email - The recipients' emails
86
+ * @returns The list of recipients' public keys
87
+ */
88
+ async getRecipientsPublicKeys(emails) {
89
+ try {
90
+ const publicKeysBase64 = await this.getRecipientsPublicKeysFromServer(emails);
91
+ const result = [];
92
+ for (const keyBase64 of publicKeysBase64) {
93
+ const publicKeys = await require_utils.base64ToPublicKey(keyBase64);
94
+ result.push(publicKeys);
95
+ }
96
+ return result;
97
+ } catch (error) {
98
+ throw new Error("Failed to get recipients public keys", { cause: error });
99
+ }
100
+ }
341
101
  };
342
102
  function getKeyServiceAPI(baseUrl) {
343
- return new KeyServiceAPI(baseUrl);
103
+ return new KeyServiceAPI(baseUrl);
344
104
  }
345
105
 
106
+ //#endregion
107
+ //#region src/keystore-service/index.ts
108
+ var keystore_service_exports = /* @__PURE__ */ require_chunk.__exportAll({
109
+ KeyServiceAPI: () => KeyServiceAPI,
110
+ getKeyServiceAPI: () => getKeyServiceAPI
111
+ });
112
+
113
+ //#endregion
346
114
  exports.KeyServiceAPI = KeyServiceAPI;
347
115
  exports.getKeyServiceAPI = getKeyServiceAPI;
348
- //# sourceMappingURL=keystore-service.js.map
116
+ Object.defineProperty(exports, 'keystore_service_exports', {
117
+ enumerable: true,
118
+ get: function () {
119
+ return keystore_service_exports;
120
+ }
121
+ });
349
122
  //# sourceMappingURL=keystore-service.js.map