@internxt/sdk 1.15.6 → 1.15.8
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.
- package/dist/mail/api.d.ts +61 -0
- package/dist/mail/api.js +201 -0
- package/dist/mail/crypto.d.ts +66 -0
- package/dist/mail/crypto.js +156 -0
- package/dist/mail/index.d.ts +2 -132
- package/dist/mail/index.js +14 -375
- package/dist/mail/mail.d.ts +104 -0
- package/dist/mail/mail.js +302 -0
- package/dist/mail/schema.d.ts +675 -0
- package/dist/mail/schema.js +6 -0
- package/dist/mail/types.d.ts +11 -0
- package/dist/mail/types.js +2 -0
- package/dist/shared/types/errors.js +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,61 @@
|
|
|
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 } 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
|
+
getMailboxes(): Promise<MailboxResponse[]>;
|
|
50
|
+
listEmails(query?: ListEmailsQuery): Promise<EmailListResponse>;
|
|
51
|
+
getEmail(id: string): Promise<EmailResponse>;
|
|
52
|
+
deleteEmail(id: string): Promise<void>;
|
|
53
|
+
updateEmail(id: string, body: UpdateEmailRequest): Promise<void>;
|
|
54
|
+
sendEmail(body: SendEmailRequest): Promise<EmailCreatedResponse>;
|
|
55
|
+
saveDraft(body: DraftEmailRequest): Promise<EmailCreatedResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the needed headers for the module requests
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
private headers;
|
|
61
|
+
}
|
package/dist/mail/api.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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("".concat(this.apiUrl, "/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("".concat(this.apiUrl, "/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("".concat(this.apiUrl, "/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("".concat(this.apiUrl, "/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("".concat(this.apiUrl, "/emails"), { email: email, params: params }, this.headers())];
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
MailApi.prototype.getMailboxes = function () {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
return [2 /*return*/, this.client.get("".concat(this.apiUrl, "/email/mailboxes"), this.headers())];
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
MailApi.prototype.listEmails = function (query) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
return [2 /*return*/, this.client.getWithParams("".concat(this.apiUrl, "/email"), query !== null && query !== void 0 ? query : {}, this.headers())];
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
MailApi.prototype.getEmail = function (id) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
return [2 /*return*/, this.client.get("".concat(this.apiUrl, "/email/").concat(id), this.headers())];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
MailApi.prototype.deleteEmail = function (id) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
return [2 /*return*/, this.client.delete("".concat(this.apiUrl, "/email/").concat(id), this.headers())];
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
MailApi.prototype.updateEmail = function (id, body) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
return [2 /*return*/, this.client.patch("".concat(this.apiUrl, "/email/").concat(id), body, this.headers())];
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
MailApi.prototype.sendEmail = function (body) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
return __generator(this, function (_a) {
|
|
175
|
+
return [2 /*return*/, this.client.post("".concat(this.apiUrl, "/email/send"), body, this.headers())];
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
MailApi.prototype.saveDraft = function (body) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
return [2 /*return*/, this.client.post("".concat(this.apiUrl, "/email/drafts"), body, this.headers())];
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Returns the needed headers for the module requests
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
MailApi.prototype.headers = function () {
|
|
191
|
+
return (0, headers_1.headersWithToken)({
|
|
192
|
+
clientName: this.appDetails.clientName,
|
|
193
|
+
clientVersion: this.appDetails.clientVersion,
|
|
194
|
+
token: this.apiSecurity.token,
|
|
195
|
+
desktopToken: this.appDetails.desktopHeader,
|
|
196
|
+
customHeaders: this.appDetails.customHeaders,
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
return MailApi;
|
|
200
|
+
}());
|
|
201
|
+
exports.MailApi = MailApi;
|
|
@@ -0,0 +1,66 @@
|
|
|
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>;
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
}
|
package/dist/mail/index.d.ts
CHANGED
|
@@ -1,132 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare class Mail {
|
|
4
|
-
private readonly client;
|
|
5
|
-
private readonly appDetails;
|
|
6
|
-
private readonly apiSecurity;
|
|
7
|
-
private readonly apiUrl;
|
|
8
|
-
static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): Mail;
|
|
9
|
-
private constructor();
|
|
10
|
-
/**
|
|
11
|
-
* Uploads encrypted keystore to the server
|
|
12
|
-
*
|
|
13
|
-
* @param encryptedKeystore - The encrypted keystore
|
|
14
|
-
* @returns Server response
|
|
15
|
-
*/
|
|
16
|
-
uploadKeystoreToServer(encryptedKeystore: EncryptedKeystore): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Creates recovery and encryption keystores and uploads them to the server
|
|
19
|
-
*
|
|
20
|
-
* @param userEmail - The email of the user
|
|
21
|
-
* @param baseKey - The secret key of the user
|
|
22
|
-
* @returns The recovery codes for opening recovery keystore
|
|
23
|
-
*/
|
|
24
|
-
createAndUploadKeystores(userEmail: string, baseKey: Uint8Array): Promise<string>;
|
|
25
|
-
/**
|
|
26
|
-
* Requests encrypted keystore from the server
|
|
27
|
-
*
|
|
28
|
-
* @param userEmail - The email of the user
|
|
29
|
-
* @param keystoreType - The type of the keystore
|
|
30
|
-
* @returns The encrypted keystore
|
|
31
|
-
*/
|
|
32
|
-
downloadKeystoreFromServer(userEmail: string, keystoreType: KeystoreType): Promise<EncryptedKeystore>;
|
|
33
|
-
/**
|
|
34
|
-
* Requests encrypted keystore from the server and opens it
|
|
35
|
-
*
|
|
36
|
-
* @param userEmail - The email of the user
|
|
37
|
-
* @param baseKey - The secret key of the user
|
|
38
|
-
* @returns The email keys of the user
|
|
39
|
-
*/
|
|
40
|
-
getUserEmailKeys(userEmail: string, baseKey: Uint8Array): Promise<EmailKeys>;
|
|
41
|
-
/**
|
|
42
|
-
* Requests recovery keystore from the server and opens it
|
|
43
|
-
*
|
|
44
|
-
* @param userEmail - The email of the user
|
|
45
|
-
* @param recoveryCodes - The recovery codes of the user
|
|
46
|
-
* @returns The email keys of the user
|
|
47
|
-
*/
|
|
48
|
-
recoverUserEmailKeys(userEmail: string, recoveryCodes: string): Promise<EmailKeys>;
|
|
49
|
-
/**
|
|
50
|
-
* Request user with corresponding public keys from the server
|
|
51
|
-
*
|
|
52
|
-
* @param userEmail - The email of the user
|
|
53
|
-
* @returns User with corresponding public keys
|
|
54
|
-
*/
|
|
55
|
-
getUserWithPublicKeys(userEmail: string): Promise<UserWithPublicKeys>;
|
|
56
|
-
/**
|
|
57
|
-
* Request users with corresponding public keys from the server
|
|
58
|
-
*
|
|
59
|
-
* @param emails - The emails of the users
|
|
60
|
-
* @returns Users with corresponding public keys
|
|
61
|
-
*/
|
|
62
|
-
getSeveralUsersWithPublicKeys(emails: string[]): Promise<UserWithPublicKeys[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Sends the encrypted email to the server
|
|
65
|
-
*
|
|
66
|
-
* @param email - The encrypted email
|
|
67
|
-
* @returns Server response
|
|
68
|
-
*/
|
|
69
|
-
sendEncryptedEmail(email: HybridEncryptedEmail): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Encrypts email and sends it to the server
|
|
72
|
-
*
|
|
73
|
-
* @param email - The message to encrypt
|
|
74
|
-
* @param senderPrivateKeys - The private keys of the sender
|
|
75
|
-
* @param isSubjectEncrypted - Indicates if the subject field should be encrypted
|
|
76
|
-
* @returns Server response
|
|
77
|
-
*/
|
|
78
|
-
encryptAndSendEmail(email: Email, senderPrivateKeys: PrivateKeys, isSubjectEncrypted?: boolean): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Sends the encrypted emails for multiple recipients to the server
|
|
81
|
-
*
|
|
82
|
-
* @param emails - The encrypted emails
|
|
83
|
-
* @returns Server response
|
|
84
|
-
*/
|
|
85
|
-
sendEncryptedEmailToMultipleRecipients(emails: HybridEncryptedEmail[]): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Encrypts emails for multiple recipients and sends emails to the server
|
|
88
|
-
*
|
|
89
|
-
* @param email - The message to encrypt
|
|
90
|
-
* @param senderPrivateKeys - The private keys of the sender
|
|
91
|
-
* @param isSubjectEncrypted - Indicates if the subject field should be encrypted
|
|
92
|
-
* @returns Server response
|
|
93
|
-
*/
|
|
94
|
-
encryptAndSendEmailToMultipleRecipients(email: Email, senderPrivateKeys: PrivateKeys, isSubjectEncrypted?: boolean): Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* Sends the password-protected email to the server
|
|
97
|
-
*
|
|
98
|
-
* @param email - The password-protected email
|
|
99
|
-
* @returns Server response
|
|
100
|
-
*/
|
|
101
|
-
sendPasswordProtectedEmail(email: PwdProtectedEmail): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Creates the password-protected email and sends it to the server
|
|
104
|
-
*
|
|
105
|
-
* @param email - The email
|
|
106
|
-
* @param pwd - The password
|
|
107
|
-
* @param isSubjectEncrypted - Indicates if the subject field should be encrypted
|
|
108
|
-
* @returns Server response
|
|
109
|
-
*/
|
|
110
|
-
passwordProtectAndSendEmail(email: Email, pwd: string, isSubjectEncrypted?: boolean): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Opens the password-protected email
|
|
113
|
-
*
|
|
114
|
-
* @param email - The password-protected email
|
|
115
|
-
* @param pwd - The shared password
|
|
116
|
-
* @returns The decrypted email
|
|
117
|
-
*/
|
|
118
|
-
openPasswordProtectedEmail(email: PwdProtectedEmail, pwd: string): Promise<Email>;
|
|
119
|
-
/**
|
|
120
|
-
* Decrypt the email
|
|
121
|
-
*
|
|
122
|
-
* @param email - The encrypted email
|
|
123
|
-
* @param recipientPrivateKeys - The private keys of the email recipient
|
|
124
|
-
* @returns The decrypted email
|
|
125
|
-
*/
|
|
126
|
-
decryptEmail(email: HybridEncryptedEmail, recipientPrivateKeys: PrivateKeys): Promise<Email>;
|
|
127
|
-
/**
|
|
128
|
-
* Returns the needed headers for the module requests
|
|
129
|
-
* @private
|
|
130
|
-
*/
|
|
131
|
-
private headers;
|
|
132
|
-
}
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './mail';
|