@internxt/sdk 1.15.13 → 1.16.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 (39) hide show
  1. package/dist/auth/index.js +180 -262
  2. package/dist/auth/types.js +2 -22
  3. package/dist/drive/backups/index.js +34 -32
  4. package/dist/drive/payments/index.js +96 -149
  5. package/dist/drive/payments/object-storage.js +34 -36
  6. package/dist/drive/referrals/index.js +19 -17
  7. package/dist/drive/share/index.js +168 -235
  8. package/dist/drive/storage/index.js +213 -302
  9. package/dist/drive/trash/index.js +40 -84
  10. package/dist/drive/users/index.js +95 -140
  11. package/dist/mail/index.d.ts +124 -2
  12. package/dist/mail/index.js +170 -16
  13. package/dist/mail/types.d.ts +50 -0
  14. package/dist/mail/types.js +6 -0
  15. package/dist/meet/index.js +31 -99
  16. package/dist/misc/location/index.js +10 -50
  17. package/dist/network/download.js +38 -107
  18. package/dist/network/errors/codes.js +8 -24
  19. package/dist/network/errors/context.js +9 -26
  20. package/dist/network/errors/download.js +6 -24
  21. package/dist/network/errors/upload.js +21 -48
  22. package/dist/network/index.js +120 -277
  23. package/dist/network/types.js +3 -4
  24. package/dist/network/upload.js +63 -133
  25. package/dist/payments/checkout.js +57 -69
  26. package/dist/send/send.js +17 -27
  27. package/dist/shared/headers/index.js +56 -42
  28. package/dist/shared/http/client.d.ts +7 -0
  29. package/dist/shared/http/client.js +101 -188
  30. package/dist/shared/http/retryWithBackoff.js +36 -110
  31. package/dist/shared/types/errors.js +37 -51
  32. package/dist/workspaces/index.js +224 -264
  33. package/package.json +14 -15
  34. package/dist/mail/api.d.ts +0 -126
  35. package/dist/mail/api.js +0 -288
  36. package/dist/mail/crypto.d.ts +0 -66
  37. package/dist/mail/crypto.js +0 -156
  38. package/dist/mail/mail.d.ts +0 -162
  39. package/dist/mail/mail.js +0 -382
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@internxt/sdk",
3
3
  "author": "Internxt <hello@internxt.com>",
4
- "version": "1.15.13",
4
+ "version": "1.16.0",
5
5
  "description": "An sdk for interacting with Internxt's services",
6
6
  "repository": {
7
7
  "type": "git",
@@ -29,22 +29,21 @@
29
29
  "swagger:mail": "openapi-typescript http://localhost:3100/api-json -o ./src/mail/schema.ts && yarn format"
30
30
  },
31
31
  "devDependencies": {
32
- "@internxt/eslint-config-internxt": "2.1.0",
33
- "@internxt/prettier-config": "internxt/prettier-config#v2.0.0",
34
- "@types/node": "25.6.0",
35
- "@vitest/coverage-istanbul": "4.1.4",
36
- "eslint": "10.2.0",
37
- "husky": "9.1.7",
38
- "lint-staged": "16.4.0",
39
- "openapi-typescript": "7.13.0",
40
- "prettier": "3.8.2",
41
- "rimraf": "6.1.3",
42
- "typescript": "5.9.3",
43
- "vitest": "4.1.4"
32
+ "@internxt/eslint-config-internxt": "^2.1.0",
33
+ "@internxt/prettier-config": "^2.0.1",
34
+ "@types/node": "^25.6.0",
35
+ "@vitest/coverage-istanbul": "^4.1.5",
36
+ "eslint": "^10.3.0",
37
+ "husky": "^9.1.7",
38
+ "lint-staged": "^17.0.2",
39
+ "openapi-typescript": "^7.13.0",
40
+ "prettier": "^3.8.3",
41
+ "rimraf": "^6.1.3",
42
+ "typescript": "^6.0.3",
43
+ "vitest": "^4.1.5"
44
44
  },
45
45
  "dependencies": {
46
- "axios": "1.15.0",
47
- "internxt-crypto": "1.0.2"
46
+ "axios": "^1.16.0"
48
47
  },
49
48
  "lint-staged": {
50
49
  "*.{js,jsx,tsx,ts}": [
@@ -1,126 +0,0 @@
1
- import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
2
- import { EncryptedKeystore, KeystoreType, HybridEncryptedEmail, PwdProtectedEmail, RecipientWithPublicKey, EmailPublicParameters } from 'internxt-crypto';
3
- import { MailboxResponse, EmailListResponse, EmailResponse, EmailCreatedResponse, SendEmailRequest, DraftEmailRequest, UpdateEmailRequest, ListEmailsQuery, EmailDomainsResponse, SetupMailAccountPayload, SearchFiltersQuery, MailAccountKeysResponse } from './types';
4
- export declare class MailApi {
5
- private readonly client;
6
- private readonly appDetails;
7
- private readonly apiSecurity;
8
- private readonly apiUrl;
9
- static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): MailApi;
10
- private constructor();
11
- /**
12
- * Uploads encrypted keystore to the server
13
- *
14
- * @param keystore - The encrypted keystore
15
- * @returns Server response
16
- */
17
- uploadKeystore(keystore: EncryptedKeystore): Promise<void>;
18
- /**
19
- * Requests encrypted keystore from the server
20
- *
21
- * @param userEmail - The email of the user
22
- * @param keystoreType - The type of the keystore
23
- * @returns The encrypted keystore
24
- */
25
- downloadKeystore(userEmail: string, keystoreType: KeystoreType): Promise<EncryptedKeystore>;
26
- /**
27
- * Requests users with corresponding public keys from the server
28
- *
29
- * @param emails - The emails of the users
30
- * @returns Users with corresponding public keys
31
- */
32
- getUsersWithPublicKeys(emails: string[]): Promise<RecipientWithPublicKey[]>;
33
- /**
34
- * Sends the encrypted emails to the server
35
- *
36
- * @param emails - The encrypted emails
37
- * @param params - The public parameters of the email
38
- * @returns Server response
39
- */
40
- sendE2EEmails(emails: HybridEncryptedEmail[], params: EmailPublicParameters): Promise<void>;
41
- /**
42
- * Sends the password-protected email to the server
43
- *
44
- * @param email - The password-protected email
45
- * @param params - The public parameters of the email
46
- * @returns Server response
47
- */
48
- sendE2EPasswordProtectedEmail(email: PwdProtectedEmail, params: EmailPublicParameters): Promise<void>;
49
- search(filters: SearchFiltersQuery): Promise<EmailListResponse>;
50
- /**
51
- * Gets the mailboxes of the user
52
- *
53
- * @returns The mailboxes of the user - `MailboxResponse[]`
54
- */
55
- getMailboxes(): Promise<MailboxResponse[]>;
56
- /**
57
- * Lists emails of the user
58
- *
59
- * @param query - The query to filter emails (e.g. mailbox, limit, etc.)
60
- * @returns The list of emails - `EmailListResponse`
61
- */
62
- listEmails(query?: ListEmailsQuery): Promise<EmailListResponse>;
63
- /**
64
- * Gets the email with the corresponding id
65
- *
66
- * @param id - The id of the email
67
- * @returns The email with the corresponding id - `EmailResponse`
68
- */
69
- getEmail(id: string): Promise<EmailResponse>;
70
- /**
71
- * Deletes the email with the corresponding id
72
- *
73
- * @param id - The id of the email to delete
74
- * @returns A promise that resolves when the email is deleted
75
- */
76
- deleteEmail(id: string): Promise<void>;
77
- /**
78
- * Updates the email with the corresponding id
79
- *
80
- * @param id - The id of the email to update
81
- * @param body - The new body of the email
82
- * @returns A promise that resolves when the email is updated
83
- */
84
- updateEmail(id: string, body: UpdateEmailRequest): Promise<void>;
85
- /**
86
- * Sends an email to the specified recipients
87
- *
88
- * @param body - The body of the email to send
89
- * @returns The created email
90
- */
91
- sendEmail(body: SendEmailRequest): Promise<EmailCreatedResponse>;
92
- /**
93
- * Saves a draft email
94
- *
95
- * @param body - The body of the draft email to save
96
- * @returns The created email - `EmailCreatedResponse`
97
- */
98
- saveDraft(body: DraftEmailRequest): Promise<EmailCreatedResponse>;
99
- /**
100
- * Returns the list of active domains for the email gateway
101
- *
102
- * @returns The list of active domains - `ActiveDomainsResponse`
103
- */
104
- getActiveDomains(): Promise<EmailDomainsResponse>;
105
- /**
106
- * Sets up a mail account for the user
107
- *
108
- * @param payload - Set of details for mail account setup
109
- * @returns A promise that resolves with the created mail account address
110
- */
111
- setupMailAccount(payload: SetupMailAccountPayload): Promise<{
112
- address: string;
113
- }>;
114
- /**
115
- * Gets the mail account keys for the given address
116
- *
117
- * @param address - The mail address whose keys should be retrieved
118
- * @returns The public, encrypted private and recovery keys plus the salt
119
- */
120
- getMailAccountKeys(address: string): Promise<MailAccountKeysResponse>;
121
- /**
122
- * Returns the needed headers for the module requests
123
- * @private
124
- */
125
- private headers;
126
- }
package/dist/mail/api.js DELETED
@@ -1,288 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.MailApi = void 0;
40
- var headers_1 = require("../shared/headers");
41
- var client_1 = require("../shared/http/client");
42
- var internxt_crypto_1 = require("internxt-crypto");
43
- var MailApi = /** @class */ (function () {
44
- function MailApi(apiUrl, appDetails, apiSecurity) {
45
- this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
46
- this.appDetails = appDetails;
47
- this.apiSecurity = apiSecurity;
48
- this.apiUrl = apiUrl;
49
- }
50
- MailApi.client = function (apiUrl, appDetails, apiSecurity) {
51
- return new MailApi(apiUrl, appDetails, apiSecurity);
52
- };
53
- /**
54
- * Uploads encrypted keystore to the server
55
- *
56
- * @param keystore - The encrypted keystore
57
- * @returns Server response
58
- */
59
- MailApi.prototype.uploadKeystore = function (keystore) {
60
- return __awaiter(this, void 0, void 0, function () {
61
- return __generator(this, function (_a) {
62
- return [2 /*return*/, this.client.post('/keystore', { encryptedKeystore: keystore }, this.headers())];
63
- });
64
- });
65
- };
66
- /**
67
- * Requests encrypted keystore from the server
68
- *
69
- * @param userEmail - The email of the user
70
- * @param keystoreType - The type of the keystore
71
- * @returns The encrypted keystore
72
- */
73
- MailApi.prototype.downloadKeystore = function (userEmail, keystoreType) {
74
- return __awaiter(this, void 0, void 0, function () {
75
- return __generator(this, function (_a) {
76
- return [2 /*return*/, this.client.getWithParams('/user/keystore', { userEmail: userEmail, keystoreType: keystoreType }, this.headers())];
77
- });
78
- });
79
- };
80
- /**
81
- * Requests users with corresponding public keys from the server
82
- *
83
- * @param emails - The emails of the users
84
- * @returns Users with corresponding public keys
85
- */
86
- MailApi.prototype.getUsersWithPublicKeys = function (emails) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- var response, result;
89
- var _this = this;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, this.client.post('/users/public-keys', { emails: emails }, this.headers())];
93
- case 1:
94
- response = _a.sent();
95
- return [4 /*yield*/, Promise.all(response.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
96
- var publicHybridKey;
97
- return __generator(this, function (_a) {
98
- publicHybridKey = (0, internxt_crypto_1.base64ToUint8Array)(item.publicKey);
99
- return [2 /*return*/, { email: item.email, publicHybridKey: publicHybridKey }];
100
- });
101
- }); }))];
102
- case 2:
103
- result = _a.sent();
104
- return [2 /*return*/, result];
105
- }
106
- });
107
- });
108
- };
109
- /**
110
- * Sends the encrypted emails to the server
111
- *
112
- * @param emails - The encrypted emails
113
- * @param params - The public parameters of the email
114
- * @returns Server response
115
- */
116
- MailApi.prototype.sendE2EEmails = function (emails, params) {
117
- return __awaiter(this, void 0, void 0, function () {
118
- return __generator(this, function (_a) {
119
- return [2 /*return*/, this.client.post('/emails', { emails: emails, params: params }, this.headers())];
120
- });
121
- });
122
- };
123
- /**
124
- * Sends the password-protected email to the server
125
- *
126
- * @param email - The password-protected email
127
- * @param params - The public parameters of the email
128
- * @returns Server response
129
- */
130
- MailApi.prototype.sendE2EPasswordProtectedEmail = function (email, params) {
131
- return __awaiter(this, void 0, void 0, function () {
132
- return __generator(this, function (_a) {
133
- return [2 /*return*/, this.client.post('/emails', { email: email, params: params }, this.headers())];
134
- });
135
- });
136
- };
137
- MailApi.prototype.search = function (filters) {
138
- return __awaiter(this, void 0, void 0, function () {
139
- return __generator(this, function (_a) {
140
- return [2 /*return*/, this.client.post('/email/search', filters, this.headers())];
141
- });
142
- });
143
- };
144
- /**
145
- * Gets the mailboxes of the user
146
- *
147
- * @returns The mailboxes of the user - `MailboxResponse[]`
148
- */
149
- MailApi.prototype.getMailboxes = function () {
150
- return __awaiter(this, void 0, void 0, function () {
151
- return __generator(this, function (_a) {
152
- return [2 /*return*/, this.client.get('/email/mailboxes', this.headers())];
153
- });
154
- });
155
- };
156
- /**
157
- * Lists emails of the user
158
- *
159
- * @param query - The query to filter emails (e.g. mailbox, limit, etc.)
160
- * @returns The list of emails - `EmailListResponse`
161
- */
162
- MailApi.prototype.listEmails = function (query) {
163
- return __awaiter(this, void 0, void 0, function () {
164
- return __generator(this, function (_a) {
165
- return [2 /*return*/, this.client.getWithParams('/email', query !== null && query !== void 0 ? query : {}, this.headers())];
166
- });
167
- });
168
- };
169
- /**
170
- * Gets the email with the corresponding id
171
- *
172
- * @param id - The id of the email
173
- * @returns The email with the corresponding id - `EmailResponse`
174
- */
175
- MailApi.prototype.getEmail = function (id) {
176
- return __awaiter(this, void 0, void 0, function () {
177
- return __generator(this, function (_a) {
178
- return [2 /*return*/, this.client.get("/email/".concat(id), this.headers())];
179
- });
180
- });
181
- };
182
- /**
183
- * Deletes the email with the corresponding id
184
- *
185
- * @param id - The id of the email to delete
186
- * @returns A promise that resolves when the email is deleted
187
- */
188
- MailApi.prototype.deleteEmail = function (id) {
189
- return __awaiter(this, void 0, void 0, function () {
190
- return __generator(this, function (_a) {
191
- return [2 /*return*/, this.client.delete("/email/".concat(id), this.headers())];
192
- });
193
- });
194
- };
195
- /**
196
- * Updates the email with the corresponding id
197
- *
198
- * @param id - The id of the email to update
199
- * @param body - The new body of the email
200
- * @returns A promise that resolves when the email is updated
201
- */
202
- MailApi.prototype.updateEmail = function (id, body) {
203
- return __awaiter(this, void 0, void 0, function () {
204
- return __generator(this, function (_a) {
205
- return [2 /*return*/, this.client.patch("/email/".concat(id), body, this.headers())];
206
- });
207
- });
208
- };
209
- /**
210
- * Sends an email to the specified recipients
211
- *
212
- * @param body - The body of the email to send
213
- * @returns The created email
214
- */
215
- MailApi.prototype.sendEmail = function (body) {
216
- return __awaiter(this, void 0, void 0, function () {
217
- return __generator(this, function (_a) {
218
- return [2 /*return*/, this.client.post('/email/send', body, this.headers())];
219
- });
220
- });
221
- };
222
- /**
223
- * Saves a draft email
224
- *
225
- * @param body - The body of the draft email to save
226
- * @returns The created email - `EmailCreatedResponse`
227
- */
228
- MailApi.prototype.saveDraft = function (body) {
229
- return __awaiter(this, void 0, void 0, function () {
230
- return __generator(this, function (_a) {
231
- return [2 /*return*/, this.client.post('/email/drafts', body, this.headers())];
232
- });
233
- });
234
- };
235
- /**
236
- * Returns the list of active domains for the email gateway
237
- *
238
- * @returns The list of active domains - `ActiveDomainsResponse`
239
- */
240
- MailApi.prototype.getActiveDomains = function () {
241
- return __awaiter(this, void 0, void 0, function () {
242
- return __generator(this, function (_a) {
243
- return [2 /*return*/, this.client.get('/email/domains', this.headers())];
244
- });
245
- });
246
- };
247
- /**
248
- * Sets up a mail account for the user
249
- *
250
- * @param payload - Set of details for mail account setup
251
- * @returns A promise that resolves with the created mail account address
252
- */
253
- MailApi.prototype.setupMailAccount = function (payload) {
254
- return __awaiter(this, void 0, void 0, function () {
255
- return __generator(this, function (_a) {
256
- return [2 /*return*/, this.client.post('/users/me/mail-account', payload, this.headers())];
257
- });
258
- });
259
- };
260
- /**
261
- * Gets the mail account keys for the given address
262
- *
263
- * @param address - The mail address whose keys should be retrieved
264
- * @returns The public, encrypted private and recovery keys plus the salt
265
- */
266
- MailApi.prototype.getMailAccountKeys = function (address) {
267
- return __awaiter(this, void 0, void 0, function () {
268
- return __generator(this, function (_a) {
269
- return [2 /*return*/, this.client.getWithParams('/users/me/mail-account/keys', { address: address }, this.headers())];
270
- });
271
- });
272
- };
273
- /**
274
- * Returns the needed headers for the module requests
275
- * @private
276
- */
277
- MailApi.prototype.headers = function () {
278
- return (0, headers_1.headersWithToken)({
279
- clientName: this.appDetails.clientName,
280
- clientVersion: this.appDetails.clientVersion,
281
- token: this.apiSecurity.token,
282
- desktopToken: this.appDetails.desktopHeader,
283
- customHeaders: this.appDetails.customHeaders,
284
- });
285
- };
286
- return MailApi;
287
- }());
288
- exports.MailApi = MailApi;
@@ -1,66 +0,0 @@
1
- import { EncryptedKeystore, HybridEncryptedEmail, PwdProtectedEmail, HybridKeyPair, Email, EmailBody, RecipientWithPublicKey } from 'internxt-crypto';
2
- /**
3
- * Creates recovery and encryption keystores for a user
4
- *
5
- * @param userEmail - The email of the user
6
- * @param baseKey - The secret key of the user
7
- * @returns The created keystores, keys and recovery codes for opening recovery keystore
8
- */
9
- export declare function createKeystores(userEmail: string, baseKey: Uint8Array): Promise<{
10
- encryptionKeystore: EncryptedKeystore;
11
- recoveryKeystore: EncryptedKeystore;
12
- recoveryCodes: string;
13
- keys: HybridKeyPair;
14
- }>;
15
- /**
16
- * Opens user's keystore and returns the keys
17
- *
18
- * @param keystore - The encrypted keystore
19
- * @param baseKey - The secret key of the user
20
- * @returns The keys of the user
21
- */
22
- export declare function openKeystore(keystore: EncryptedKeystore, baseKey: Uint8Array): Promise<HybridKeyPair>;
23
- /**
24
- * Recovery of user's keys using recovery keystore
25
- *
26
- * @param keystore - The recovery keystore
27
- * @param recoveryCodes - The recovery codes of the user
28
- * @returns The keys of the user
29
- */
30
- export declare function recoverKeys(keystore: EncryptedKeystore, recoveryCodes: string): Promise<HybridKeyPair>;
31
- /**
32
- * Encrypts the email
33
- *
34
- * @param email - The email to encrypt
35
- * @param recipients - The recipients of the email
36
- * @param aux - The optional auxilary data to encrypt together with the email (e.g. email sender)
37
- * @returns The encrypted emails for each recipient
38
- */
39
- export declare function encryptEmail(email: Email, recipients: RecipientWithPublicKey[], aux?: string): Promise<HybridEncryptedEmail[]>;
40
- /**
41
- * Password-protects the email
42
- *
43
- * @param email - The email to password-protect
44
- * @param pwd - The password to protect the email with
45
- * @param aux - The optional auxilary data to encrypt together with the email (e.g. email sender)
46
- * @returns The password-protected email
47
- */
48
- export declare function passwordProtectAndSendEmail(email: Email, pwd: string, aux?: string): Promise<PwdProtectedEmail>;
49
- /**
50
- * Opens the password-protected email
51
- *
52
- * @param email - The password-protected email
53
- * @param pwd - The shared password
54
- * @param aux - The optional auxilary data that was encrypted together with the email (e.g. email sender)
55
- * @returns The decrypted email body
56
- */
57
- export declare function openPasswordProtectedEmail(email: PwdProtectedEmail, pwd: string, aux?: string): Promise<EmailBody>;
58
- /**
59
- * Decrypt the email
60
- *
61
- * @param email - The encrypted email
62
- * @param recipientPrivateKeys - The private keys of the email recipient
63
- * @param aux - The optional auxilary data that was encrypted together with the email (e.g. email sender)
64
- * @returns The decrypted email body
65
- */
66
- export declare function decryptEmail(email: HybridEncryptedEmail, recipientPrivateKeys: Uint8Array, aux?: string): Promise<EmailBody>;
@@ -1,156 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createKeystores = createKeystores;
40
- exports.openKeystore = openKeystore;
41
- exports.recoverKeys = recoverKeys;
42
- exports.encryptEmail = encryptEmail;
43
- exports.passwordProtectAndSendEmail = passwordProtectAndSendEmail;
44
- exports.openPasswordProtectedEmail = openPasswordProtectedEmail;
45
- exports.decryptEmail = decryptEmail;
46
- var internxt_crypto_1 = require("internxt-crypto");
47
- /**
48
- * Creates recovery and encryption keystores for a user
49
- *
50
- * @param userEmail - The email of the user
51
- * @param baseKey - The secret key of the user
52
- * @returns The created keystores, keys and recovery codes for opening recovery keystore
53
- */
54
- function createKeystores(userEmail, baseKey) {
55
- return __awaiter(this, void 0, void 0, function () {
56
- return __generator(this, function (_a) {
57
- return [2 /*return*/, (0, internxt_crypto_1.createEncryptionAndRecoveryKeystores)(userEmail, baseKey)];
58
- });
59
- });
60
- }
61
- /**
62
- * Opens user's keystore and returns the keys
63
- *
64
- * @param keystore - The encrypted keystore
65
- * @param baseKey - The secret key of the user
66
- * @returns The keys of the user
67
- */
68
- function openKeystore(keystore, baseKey) {
69
- return __awaiter(this, void 0, void 0, function () {
70
- return __generator(this, function (_a) {
71
- return [2 /*return*/, (0, internxt_crypto_1.openEncryptionKeystore)(keystore, baseKey)];
72
- });
73
- });
74
- }
75
- /**
76
- * Recovery of user's keys using recovery keystore
77
- *
78
- * @param keystore - The recovery keystore
79
- * @param recoveryCodes - The recovery codes of the user
80
- * @returns The keys of the user
81
- */
82
- function recoverKeys(keystore, recoveryCodes) {
83
- return __awaiter(this, void 0, void 0, function () {
84
- return __generator(this, function (_a) {
85
- return [2 /*return*/, (0, internxt_crypto_1.openRecoveryKeystore)(recoveryCodes, keystore)];
86
- });
87
- });
88
- }
89
- /**
90
- * Encrypts the email
91
- *
92
- * @param email - The email to encrypt
93
- * @param recipients - The recipients of the email
94
- * @param aux - The optional auxilary data to encrypt together with the email (e.g. email sender)
95
- * @returns The encrypted emails for each recipient
96
- */
97
- function encryptEmail(email, recipients, aux) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var auxArray;
100
- return __generator(this, function (_a) {
101
- auxArray = aux ? (0, internxt_crypto_1.UTF8ToUint8)(aux) : new Uint8Array();
102
- return [2 /*return*/, (0, internxt_crypto_1.encryptEmailHybridForMultipleRecipients)(email.body, recipients, auxArray)];
103
- });
104
- });
105
- }
106
- /**
107
- * Password-protects the email
108
- *
109
- * @param email - The email to password-protect
110
- * @param pwd - The password to protect the email with
111
- * @param aux - The optional auxilary data to encrypt together with the email (e.g. email sender)
112
- * @returns The password-protected email
113
- */
114
- function passwordProtectAndSendEmail(email, pwd, aux) {
115
- return __awaiter(this, void 0, void 0, function () {
116
- var auxArray;
117
- return __generator(this, function (_a) {
118
- auxArray = aux ? (0, internxt_crypto_1.UTF8ToUint8)(aux) : new Uint8Array();
119
- return [2 /*return*/, (0, internxt_crypto_1.createPwdProtectedEmail)(email.body, pwd, auxArray)];
120
- });
121
- });
122
- }
123
- /**
124
- * Opens the password-protected email
125
- *
126
- * @param email - The password-protected email
127
- * @param pwd - The shared password
128
- * @param aux - The optional auxilary data that was encrypted together with the email (e.g. email sender)
129
- * @returns The decrypted email body
130
- */
131
- function openPasswordProtectedEmail(email, pwd, aux) {
132
- return __awaiter(this, void 0, void 0, function () {
133
- var auxArray;
134
- return __generator(this, function (_a) {
135
- auxArray = aux ? (0, internxt_crypto_1.UTF8ToUint8)(aux) : new Uint8Array();
136
- return [2 /*return*/, (0, internxt_crypto_1.decryptPwdProtectedEmail)(email, pwd, auxArray)];
137
- });
138
- });
139
- }
140
- /**
141
- * Decrypt the email
142
- *
143
- * @param email - The encrypted email
144
- * @param recipientPrivateKeys - The private keys of the email recipient
145
- * @param aux - The optional auxilary data that was encrypted together with the email (e.g. email sender)
146
- * @returns The decrypted email body
147
- */
148
- function decryptEmail(email, recipientPrivateKeys, aux) {
149
- return __awaiter(this, void 0, void 0, function () {
150
- var auxArray;
151
- return __generator(this, function (_a) {
152
- auxArray = aux ? (0, internxt_crypto_1.UTF8ToUint8)(aux) : new Uint8Array();
153
- return [2 /*return*/, (0, internxt_crypto_1.decryptEmailHybrid)(email, recipientPrivateKeys, auxArray)];
154
- });
155
- });
156
- }