curtain-web-api 1.0.43 → 1.0.44

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.
@@ -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
- let payload = new FormData();
317
- if ("file" in sessionData) {
318
- payload.append("file", new Blob([JSON.stringify(sessionData["file"], exports.replacer)], { type: 'text/json' }), "curtain-settings.json");
319
- payload.append("description", sessionData["file"]["settings"]["description"]);
320
- }
321
- if ("enable" in sessionData) {
322
- if (sessionData["enable"]) {
323
- payload.append("enable", "True");
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
- payload.append("enable", "False");
353
+ form.append("encrypted", "False");
327
354
  }
328
- }
329
- let headers = new axios_1.AxiosHeaders();
330
- headers["Accept"] = "application/json";
331
- headers["Content-Type"] = "multipart/form-data";
332
- return this.axiosInstance.patch(this.baseURL + "curtain/" + linkId + "/", payload, { responseType: "json" }).then((response) => {
333
- return response;
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "curtain-web-api",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -299,27 +299,55 @@ export class CurtainWebAPI {
299
299
  });
300
300
  }
301
301
 
302
- updateSession(sessionData: any, linkId: string) {
303
- let payload: FormData = new FormData();
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
- payload.append("file", new Blob([JSON.stringify(sessionData["file"], replacer)], {type: 'text/json'}), "curtain-settings.json")
306
- payload.append("description", sessionData["file"]["settings"]["description"])
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
- payload.append("enable", "True")
329
+ form.append("enable", "True")
311
330
  } else {
312
- payload.append("enable", "False")
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 + "/", payload, {responseType:"json"}).then((response) => {
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) {