curtain-web-api 1.0.43 → 1.0.45
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/build/classes/curtain-api.d.ts +1 -1
- package/build/classes/curtain-api.js +47 -16
- package/build/classes/curtain-encryption.d.ts +1 -0
- package/build/classes/curtain-encryption.js +11 -1
- package/package.json +1 -1
- package/src/classes/curtain-api.ts +37 -9
- package/src/classes/curtain-encryption.ts +7 -1
|
@@ -25,7 +25,7 @@ export declare class CurtainWebAPI {
|
|
|
25
25
|
postSettings(id: string, token: string, onDownloadProgress?: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
26
26
|
getPrideData(accession: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
27
27
|
generateTemporarySession(linkId: string, lifetime: number): Promise<import("axios").AxiosResponse<any, any>>;
|
|
28
|
-
updateSession(sessionData: any, linkId: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
28
|
+
updateSession(sessionData: any, linkId: string, encryption?: CurtainEncryption): Promise<import("axios").AxiosResponse<any, any>>;
|
|
29
29
|
getSessionSettings(linkId: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
30
30
|
getOwnership(linkId: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
31
31
|
getOwners(linkId: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
@@ -312,25 +312,56 @@ class CurtainWebAPI {
|
|
|
312
312
|
return response;
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
|
-
updateSession(sessionData, linkId
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
315
|
+
updateSession(sessionData, linkId, encryption = {
|
|
316
|
+
encrypted: false,
|
|
317
|
+
e2e: false,
|
|
318
|
+
}) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
let form = new FormData();
|
|
321
|
+
if ("file" in sessionData) {
|
|
322
|
+
let data = JSON.stringify(sessionData["file"], exports.replacer);
|
|
323
|
+
if (encryption.encrypted && encryption.e2e && encryption.publicKey !== undefined) {
|
|
324
|
+
const aesKey = yield (0, curtain_encryption_1.generateAESKey)();
|
|
325
|
+
const encryptedData = yield (0, curtain_encryption_1.encryptAESData)(aesKey, data);
|
|
326
|
+
const encryptedKey = yield (0, curtain_encryption_1.encryptAESKey)(encryption.publicKey, yield (0, curtain_encryption_1.exportAESKey)(aesKey));
|
|
327
|
+
const encryptedIV = yield (0, curtain_encryption_1.encryptAESKey)(encryption.publicKey, (0, curtain_encryption_1.base64ToArrayBuffer)(encryptedData.iv));
|
|
328
|
+
const payload = {
|
|
329
|
+
encryptedData: encryptedData.encrypted,
|
|
330
|
+
encryptedKey: (0, curtain_encryption_1.arrayBufferToBase64String)(encryptedKey),
|
|
331
|
+
encryptedIV: (0, curtain_encryption_1.arrayBufferToBase64String)(encryptedIV)
|
|
332
|
+
};
|
|
333
|
+
form.append("encryptedKey", payload.encryptedKey);
|
|
334
|
+
form.append("encryptedIV", payload.encryptedIV);
|
|
335
|
+
form.append("file", new Blob([payload.encryptedData], { type: 'text/json' }), "curtain-settings.json");
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
form.append("file", new Blob([data], { type: 'text/json' }), "curtain-settings.json");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if ("enable" in sessionData) {
|
|
342
|
+
if (sessionData["enable"]) {
|
|
343
|
+
form.append("enable", "True");
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
form.append("enable", "False");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (encryption.encrypted) {
|
|
350
|
+
form.append("encrypted", "True");
|
|
324
351
|
}
|
|
325
352
|
else {
|
|
326
|
-
|
|
353
|
+
form.append("encrypted", "False");
|
|
327
354
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
355
|
+
if (encryption.e2e) {
|
|
356
|
+
form.append("e2e", "True");
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
form.append("e2e", "False");
|
|
360
|
+
}
|
|
361
|
+
let headers = new axios_1.AxiosHeaders();
|
|
362
|
+
headers["Accept"] = "application/json";
|
|
363
|
+
headers["Content-Type"] = "multipart/form-data";
|
|
364
|
+
return this.axiosInstance.patch(this.baseURL + "curtain/" + linkId + "/", form, { responseType: "json" });
|
|
334
365
|
});
|
|
335
366
|
}
|
|
336
367
|
getSessionSettings(linkId) {
|
|
@@ -36,3 +36,4 @@ export declare function encryptDataAES(data: string, publicKey: CryptoKey): Prom
|
|
|
36
36
|
};
|
|
37
37
|
}>;
|
|
38
38
|
export declare function decryptDataAES(encryptedKey: ArrayBuffer, encryptedData: string, iv: string, privateKey: CryptoKey): Promise<string>;
|
|
39
|
+
export declare function hashData(data: string): Promise<string>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.decryptDataAES = exports.encryptDataAES = exports.importAESKey = exports.exportAESKey = exports.decryptAESKey = exports.decryptAESData = exports.encryptAESData = exports.generateAESKey = exports.encryptAESKey = exports.pemToArrayBuffer = exports.base64ToArrayBuffer = exports.removeLines = exports.arrayBufferToBase64String = exports.loadFromLocalStorage = exports.saveToLocalStorage = exports.exportKeyString = exports.importKey = exports.exportPrivateKey = exports.exportPublicKey = exports.generateKeyPair = exports.importPrivateKey = exports.importPublicKey = exports.decryptDataRSA = exports.encryptDataRSA = void 0;
|
|
12
|
+
exports.hashData = exports.decryptDataAES = exports.encryptDataAES = exports.importAESKey = exports.exportAESKey = exports.decryptAESKey = exports.decryptAESData = exports.encryptAESData = exports.generateAESKey = exports.encryptAESKey = exports.pemToArrayBuffer = exports.base64ToArrayBuffer = exports.removeLines = exports.arrayBufferToBase64String = exports.loadFromLocalStorage = exports.saveToLocalStorage = exports.exportKeyString = exports.importKey = exports.exportPrivateKey = exports.exportPublicKey = exports.generateKeyPair = exports.importPrivateKey = exports.importPublicKey = exports.decryptDataRSA = exports.encryptDataRSA = void 0;
|
|
13
13
|
function encryptDataRSA(data, publicKey) {
|
|
14
14
|
return crypto.subtle.encrypt({ name: 'RSA-OAEP' }, publicKey, new TextEncoder().encode(data));
|
|
15
15
|
}
|
|
@@ -202,3 +202,13 @@ function decryptDataAES(encryptedKey, encryptedData, iv, privateKey) {
|
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
204
|
exports.decryptDataAES = decryptDataAES;
|
|
205
|
+
// a function to calculate sha-256 hash of a large string
|
|
206
|
+
function hashData(data) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
const enc = new TextEncoder();
|
|
209
|
+
const encoded = enc.encode(data);
|
|
210
|
+
const hash = yield crypto.subtle.digest("SHA-256", encoded);
|
|
211
|
+
return arrayBufferToBase64String(hash);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
exports.hashData = hashData;
|
package/package.json
CHANGED
|
@@ -299,27 +299,55 @@ export class CurtainWebAPI {
|
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
updateSession(sessionData: any, linkId: string
|
|
303
|
-
|
|
302
|
+
async updateSession(sessionData: any, linkId: string, encryption: CurtainEncryption = {
|
|
303
|
+
encrypted: false,
|
|
304
|
+
e2e: false,
|
|
305
|
+
}) {
|
|
306
|
+
let form: FormData = new FormData();
|
|
304
307
|
if ("file" in sessionData) {
|
|
305
|
-
|
|
306
|
-
|
|
308
|
+
let data = JSON.stringify(sessionData["file"], replacer)
|
|
309
|
+
if (encryption.encrypted && encryption.e2e && encryption.publicKey !== undefined) {
|
|
310
|
+
const aesKey = await generateAESKey()
|
|
311
|
+
const encryptedData = await encryptAESData(aesKey, data)
|
|
312
|
+
const encryptedKey = await encryptAESKey(encryption.publicKey, await exportAESKey(aesKey))
|
|
313
|
+
const encryptedIV = await encryptAESKey(encryption.publicKey, base64ToArrayBuffer(encryptedData.iv))
|
|
314
|
+
const payload = {
|
|
315
|
+
encryptedData: encryptedData.encrypted,
|
|
316
|
+
encryptedKey: arrayBufferToBase64String(encryptedKey),
|
|
317
|
+
encryptedIV: arrayBufferToBase64String(encryptedIV)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
form.append("encryptedKey", payload.encryptedKey)
|
|
321
|
+
form.append("encryptedIV", payload.encryptedIV)
|
|
322
|
+
form.append("file", new Blob([payload.encryptedData], {type: 'text/json'}), "curtain-settings.json")
|
|
323
|
+
} else {
|
|
324
|
+
form.append("file", new Blob([data], {type: 'text/json'}), "curtain-settings.json")
|
|
325
|
+
}
|
|
307
326
|
}
|
|
308
327
|
if ("enable" in sessionData) {
|
|
309
328
|
if (sessionData["enable"]) {
|
|
310
|
-
|
|
329
|
+
form.append("enable", "True")
|
|
311
330
|
} else {
|
|
312
|
-
|
|
331
|
+
form.append("enable", "False")
|
|
313
332
|
}
|
|
314
333
|
}
|
|
315
334
|
|
|
335
|
+
if (encryption.encrypted) {
|
|
336
|
+
form.append("encrypted", "True")
|
|
337
|
+
} else {
|
|
338
|
+
form.append("encrypted", "False")
|
|
339
|
+
}
|
|
340
|
+
if (encryption.e2e) {
|
|
341
|
+
form.append("e2e", "True")
|
|
342
|
+
} else {
|
|
343
|
+
form.append("e2e", "False")
|
|
344
|
+
}
|
|
345
|
+
|
|
316
346
|
let headers = new AxiosHeaders();
|
|
317
347
|
headers["Accept"] = "application/json";
|
|
318
348
|
headers["Content-Type"] = "multipart/form-data";
|
|
319
349
|
|
|
320
|
-
return this.axiosInstance.patch(this.baseURL + "curtain/" + linkId + "/",
|
|
321
|
-
return response;
|
|
322
|
-
});
|
|
350
|
+
return this.axiosInstance.patch(this.baseURL + "curtain/" + linkId + "/", form, {responseType:"json"})
|
|
323
351
|
}
|
|
324
352
|
|
|
325
353
|
getSessionSettings(linkId: string) {
|
|
@@ -167,4 +167,10 @@ export async function decryptDataAES(encryptedKey: ArrayBuffer, encryptedData: s
|
|
|
167
167
|
return await decryptAESData(await importAESKey(aesKey), encryptedData, iv)
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
// a function to calculate sha-256 hash of a large string
|
|
171
|
+
export async function hashData(data: string) {
|
|
172
|
+
const enc = new TextEncoder()
|
|
173
|
+
const encoded = enc.encode(data)
|
|
174
|
+
const hash = await crypto.subtle.digest("SHA-256", encoded)
|
|
175
|
+
return arrayBufferToBase64String(hash)
|
|
176
|
+
}
|