curtain-web-api 1.0.36 → 1.0.38
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 +2 -1
- package/build/classes/curtain-api.js +16 -5
- package/build/classes/curtain-encryption.d.ts +20 -0
- package/build/classes/curtain-encryption.js +127 -0
- package/build/index.d.ts +2 -1
- package/build/index.js +13 -1
- package/package.json +1 -1
- package/src/classes/curtain-api.ts +16 -5
- package/src/classes/curtain-encryption.ts +106 -0
- package/src/index.ts +24 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { User } from "./curtain-user";
|
|
2
|
+
import { CurtainEncryption } from "./curtain-encryption";
|
|
2
3
|
export declare const replacer: (key: any, value: any) => any;
|
|
3
4
|
export declare const reviver: (key: any, value: any) => any;
|
|
4
5
|
export declare class CurtainWebAPI {
|
|
@@ -20,7 +21,7 @@ export declare class CurtainWebAPI {
|
|
|
20
21
|
ORCIDLogin(authorizationCode: string, redirectURI: string): Promise<User>;
|
|
21
22
|
checkIfRefreshTokenExpired(): boolean;
|
|
22
23
|
deleteCurtainLink(curtainLinkID: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
23
|
-
putSettings(settings: any, enable?: boolean, description?: string, sessionType?: string,
|
|
24
|
+
putSettings(settings: any, enable?: boolean, description?: string, sessionType?: string, encryption?: CurtainEncryption, onUploadProgress?: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
24
25
|
postSettings(id: string, token: string, onDownloadProgress?: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
25
26
|
getPrideData(accession: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
26
27
|
generateTemporarySession(linkId: string, lifetime: number): Promise<import("axios").AxiosResponse<any, any>>;
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.CurtainWebAPI = exports.reviver = exports.replacer = void 0;
|
|
27
27
|
const curtain_user_1 = require("./curtain-user");
|
|
28
28
|
const axios_1 = __importStar(require("axios"));
|
|
29
|
+
const curtain_encryption_1 = require("./curtain-encryption");
|
|
29
30
|
const base = "https://celsus.muttsu.xyz/";
|
|
30
31
|
const replacer = (key, value) => {
|
|
31
32
|
if (value instanceof Map) {
|
|
@@ -208,28 +209,38 @@ class CurtainWebAPI {
|
|
|
208
209
|
return response;
|
|
209
210
|
});
|
|
210
211
|
}
|
|
211
|
-
putSettings(settings, enable = true, description = "", sessionType = "TP",
|
|
212
|
+
putSettings(settings, enable = true, description = "", sessionType = "TP", encryption = {
|
|
213
|
+
encrypted: false,
|
|
214
|
+
e2e: false,
|
|
215
|
+
}, onUploadProgress = undefined) {
|
|
212
216
|
let form = new FormData();
|
|
213
|
-
|
|
217
|
+
let data = JSON.stringify(settings, exports.replacer);
|
|
214
218
|
if (enable) {
|
|
215
219
|
form.append("enable", "True");
|
|
216
220
|
}
|
|
217
221
|
else {
|
|
218
222
|
form.append("enable", "False");
|
|
219
223
|
}
|
|
220
|
-
if (encrypted) {
|
|
224
|
+
if (encryption.encrypted) {
|
|
221
225
|
form.append("encrypted", "True");
|
|
222
226
|
}
|
|
223
227
|
else {
|
|
224
228
|
form.append("encrypted", "False");
|
|
225
229
|
}
|
|
226
|
-
|
|
227
|
-
if (e2e) {
|
|
230
|
+
if (encryption.e2e) {
|
|
228
231
|
form.append("e2e", "True");
|
|
229
232
|
}
|
|
230
233
|
else {
|
|
231
234
|
form.append("e2e", "False");
|
|
232
235
|
}
|
|
236
|
+
if (encryption.encrypted && encryption.e2e && encryption.publicKey !== undefined) {
|
|
237
|
+
(0, curtain_encryption_1.encryptDataRSA)(data, encryption.publicKey).then((response) => {
|
|
238
|
+
form.append("file", new Blob([response], { type: 'text/json' }), "curtain-settings.json");
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
form.append("file", new Blob([data], { type: 'text/json' }), "curtain-settings.json");
|
|
243
|
+
}
|
|
233
244
|
form.append("description", description);
|
|
234
245
|
form.append("curtain_type", sessionType);
|
|
235
246
|
let headers = new axios_1.AxiosHeaders();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function encryptDataRSA(data: string, publicKey: CryptoKey): Promise<ArrayBuffer>;
|
|
2
|
+
export declare function decryptDataRSA(data: string, privateKey: CryptoKey): Promise<ArrayBuffer>;
|
|
3
|
+
export declare function importPublicKey(key: ArrayBuffer): Promise<CryptoKey>;
|
|
4
|
+
export declare function importPrivateKey(key: ArrayBuffer): Promise<CryptoKey>;
|
|
5
|
+
export declare function generateKeyPair(modulusLength?: number, publicExponent?: Uint8Array): Promise<CryptoKeyPair>;
|
|
6
|
+
export declare function exportPublicKey(key: CryptoKey): Promise<ArrayBuffer>;
|
|
7
|
+
export declare function exportPrivateKey(key: CryptoKey): Promise<ArrayBuffer>;
|
|
8
|
+
export declare function importKey(key: ArrayBuffer, type: "public" | "private"): Promise<CryptoKey>;
|
|
9
|
+
export declare function exportKeyString(key: CryptoKey, type: "public" | "private"): Promise<string>;
|
|
10
|
+
export declare function saveToLocalStorage(key: CryptoKey, type: "public" | "private"): Promise<void>;
|
|
11
|
+
export declare function loadFromLocalStorage(type: "public" | "private"): Promise<CryptoKey | undefined>;
|
|
12
|
+
export interface CurtainEncryption {
|
|
13
|
+
encrypted: boolean;
|
|
14
|
+
publicKey?: CryptoKey;
|
|
15
|
+
e2e: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function arrayBufferToBase64String(arrayBuffer: ArrayBuffer): string;
|
|
18
|
+
export declare function removeLines(str_data: string): string;
|
|
19
|
+
export declare function base64ToArrayBuffer(b64: string): Uint8Array;
|
|
20
|
+
export declare function pemToArrayBuffer(pem: string): Uint8Array;
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
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
|
+
function encryptDataRSA(data, publicKey) {
|
|
14
|
+
return crypto.subtle.encrypt({ name: 'RSA-OAEP' }, publicKey, new TextEncoder().encode(data));
|
|
15
|
+
}
|
|
16
|
+
exports.encryptDataRSA = encryptDataRSA;
|
|
17
|
+
function decryptDataRSA(data, privateKey) {
|
|
18
|
+
return crypto.subtle.decrypt({ name: 'RSA-OAEP' }, privateKey, new TextEncoder().encode(data));
|
|
19
|
+
}
|
|
20
|
+
exports.decryptDataRSA = decryptDataRSA;
|
|
21
|
+
function importPublicKey(key) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return yield crypto.subtle.importKey('spki', key, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.importPublicKey = importPublicKey;
|
|
27
|
+
function importPrivateKey(key) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return yield crypto.subtle.importKey('pkcs8', key, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['decrypt']);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.importPrivateKey = importPrivateKey;
|
|
33
|
+
function generateKeyPair(modulusLength = 2048, publicExponent = new Uint8Array([1, 0, 1])) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return yield crypto.subtle.generateKey({
|
|
36
|
+
name: "RSA-OAEP",
|
|
37
|
+
modulusLength: modulusLength,
|
|
38
|
+
publicExponent: publicExponent,
|
|
39
|
+
hash: "SHA-256",
|
|
40
|
+
}, true, ["encrypt", "decrypt"]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.generateKeyPair = generateKeyPair;
|
|
44
|
+
function exportPublicKey(key) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
return yield crypto.subtle.exportKey('spki', key);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.exportPublicKey = exportPublicKey;
|
|
50
|
+
function exportPrivateKey(key) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return yield crypto.subtle.exportKey('pkcs8', key);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.exportPrivateKey = exportPrivateKey;
|
|
56
|
+
function importKey(key, type) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (type === "public") {
|
|
59
|
+
return yield importPublicKey(key);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return yield importPrivateKey(key);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.importKey = importKey;
|
|
67
|
+
function exportKeyString(key, type) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (type === "public") {
|
|
70
|
+
const k = yield exportPublicKey(key);
|
|
71
|
+
return arrayBufferToBase64String(k);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const k = yield exportPrivateKey(key);
|
|
75
|
+
return arrayBufferToBase64String(k);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.exportKeyString = exportKeyString;
|
|
80
|
+
function saveToLocalStorage(key, type) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const k = yield exportKeyString(key, type);
|
|
83
|
+
localStorage.setItem(type + "_key", k);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.saveToLocalStorage = saveToLocalStorage;
|
|
87
|
+
function loadFromLocalStorage(type) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const k = localStorage.getItem(type + "_key");
|
|
90
|
+
if (k) {
|
|
91
|
+
return yield importKey(pemToArrayBuffer(k), type);
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.loadFromLocalStorage = loadFromLocalStorage;
|
|
97
|
+
function arrayBufferToBase64String(arrayBuffer) {
|
|
98
|
+
const byteArray = new Uint8Array(arrayBuffer);
|
|
99
|
+
let byteString = '';
|
|
100
|
+
for (let i = 0; i < byteArray.byteLength; i++) {
|
|
101
|
+
byteString += String.fromCharCode(byteArray[i]);
|
|
102
|
+
}
|
|
103
|
+
return btoa(byteString);
|
|
104
|
+
}
|
|
105
|
+
exports.arrayBufferToBase64String = arrayBufferToBase64String;
|
|
106
|
+
function removeLines(str_data) {
|
|
107
|
+
return str_data.replace("\n", "");
|
|
108
|
+
}
|
|
109
|
+
exports.removeLines = removeLines;
|
|
110
|
+
function base64ToArrayBuffer(b64) {
|
|
111
|
+
const byteString = atob(b64);
|
|
112
|
+
const byteArray = new Uint8Array(byteString.length);
|
|
113
|
+
for (let i = 0; i < byteString.length; i++) {
|
|
114
|
+
byteArray[i] = byteString.charCodeAt(i);
|
|
115
|
+
}
|
|
116
|
+
return byteArray;
|
|
117
|
+
}
|
|
118
|
+
exports.base64ToArrayBuffer = base64ToArrayBuffer;
|
|
119
|
+
function pemToArrayBuffer(pem) {
|
|
120
|
+
const b64Lines = removeLines(pem);
|
|
121
|
+
let b64Prefix = b64Lines.replace('-----BEGIN PRIVATE KEY-----', '');
|
|
122
|
+
b64Prefix = b64Prefix.replace('-----BEGIN PUBLIC KEY-----', '');
|
|
123
|
+
let b64Final = b64Prefix.replace('-----END PRIVATE KEY-----', '');
|
|
124
|
+
b64Final = b64Final.replace('-----END PUBLIC KEY-----', '');
|
|
125
|
+
return base64ToArrayBuffer(b64Final);
|
|
126
|
+
}
|
|
127
|
+
exports.pemToArrayBuffer = pemToArrayBuffer;
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CurtainWebAPI, replacer, reviver } from "./classes/curtain-api";
|
|
2
2
|
import { User } from "./classes/curtain-user";
|
|
3
3
|
import { getProteomicsData, getPrideData, getEBIAlpha, getInteractomeAtlas, getStringDBInteractions } from "./utilities";
|
|
4
|
-
|
|
4
|
+
import { importKey, importPrivateKey, exportPrivateKey, exportKeyString, exportPublicKey, importPublicKey, CurtainEncryption, generateKeyPair, encryptDataRSA, decryptDataRSA, loadFromLocalStorage, saveToLocalStorage } from "./classes/curtain-encryption";
|
|
5
|
+
export { CurtainWebAPI, User, getProteomicsData, getPrideData, getEBIAlpha, getInteractomeAtlas, getStringDBInteractions, replacer, reviver, importKey, importPrivateKey, exportPrivateKey, exportKeyString, exportPublicKey, importPublicKey, CurtainEncryption, generateKeyPair, encryptDataRSA, decryptDataRSA, loadFromLocalStorage, saveToLocalStorage };
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reviver = exports.replacer = exports.getStringDBInteractions = exports.getInteractomeAtlas = exports.getEBIAlpha = exports.getPrideData = exports.getProteomicsData = exports.User = exports.CurtainWebAPI = void 0;
|
|
3
|
+
exports.saveToLocalStorage = exports.loadFromLocalStorage = exports.decryptDataRSA = exports.encryptDataRSA = exports.generateKeyPair = exports.importPublicKey = exports.exportPublicKey = exports.exportKeyString = exports.exportPrivateKey = exports.importPrivateKey = exports.importKey = exports.reviver = exports.replacer = exports.getStringDBInteractions = exports.getInteractomeAtlas = exports.getEBIAlpha = exports.getPrideData = exports.getProteomicsData = exports.User = exports.CurtainWebAPI = void 0;
|
|
4
4
|
const curtain_api_1 = require("./classes/curtain-api");
|
|
5
5
|
Object.defineProperty(exports, "CurtainWebAPI", { enumerable: true, get: function () { return curtain_api_1.CurtainWebAPI; } });
|
|
6
6
|
Object.defineProperty(exports, "replacer", { enumerable: true, get: function () { return curtain_api_1.replacer; } });
|
|
@@ -13,3 +13,15 @@ Object.defineProperty(exports, "getPrideData", { enumerable: true, get: function
|
|
|
13
13
|
Object.defineProperty(exports, "getEBIAlpha", { enumerable: true, get: function () { return utilities_1.getEBIAlpha; } });
|
|
14
14
|
Object.defineProperty(exports, "getInteractomeAtlas", { enumerable: true, get: function () { return utilities_1.getInteractomeAtlas; } });
|
|
15
15
|
Object.defineProperty(exports, "getStringDBInteractions", { enumerable: true, get: function () { return utilities_1.getStringDBInteractions; } });
|
|
16
|
+
const curtain_encryption_1 = require("./classes/curtain-encryption");
|
|
17
|
+
Object.defineProperty(exports, "importKey", { enumerable: true, get: function () { return curtain_encryption_1.importKey; } });
|
|
18
|
+
Object.defineProperty(exports, "importPrivateKey", { enumerable: true, get: function () { return curtain_encryption_1.importPrivateKey; } });
|
|
19
|
+
Object.defineProperty(exports, "exportPrivateKey", { enumerable: true, get: function () { return curtain_encryption_1.exportPrivateKey; } });
|
|
20
|
+
Object.defineProperty(exports, "exportKeyString", { enumerable: true, get: function () { return curtain_encryption_1.exportKeyString; } });
|
|
21
|
+
Object.defineProperty(exports, "exportPublicKey", { enumerable: true, get: function () { return curtain_encryption_1.exportPublicKey; } });
|
|
22
|
+
Object.defineProperty(exports, "importPublicKey", { enumerable: true, get: function () { return curtain_encryption_1.importPublicKey; } });
|
|
23
|
+
Object.defineProperty(exports, "generateKeyPair", { enumerable: true, get: function () { return curtain_encryption_1.generateKeyPair; } });
|
|
24
|
+
Object.defineProperty(exports, "encryptDataRSA", { enumerable: true, get: function () { return curtain_encryption_1.encryptDataRSA; } });
|
|
25
|
+
Object.defineProperty(exports, "decryptDataRSA", { enumerable: true, get: function () { return curtain_encryption_1.decryptDataRSA; } });
|
|
26
|
+
Object.defineProperty(exports, "loadFromLocalStorage", { enumerable: true, get: function () { return curtain_encryption_1.loadFromLocalStorage; } });
|
|
27
|
+
Object.defineProperty(exports, "saveToLocalStorage", { enumerable: true, get: function () { return curtain_encryption_1.saveToLocalStorage; } });
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {User} from "./curtain-user";
|
|
2
2
|
import axios, {AxiosHeaders} from "axios";
|
|
3
|
+
import {CurtainEncryption, encryptDataRSA} from "./curtain-encryption";
|
|
3
4
|
|
|
4
5
|
const base: string = "https://celsus.muttsu.xyz/"
|
|
5
6
|
|
|
@@ -198,26 +199,36 @@ export class CurtainWebAPI {
|
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
|
|
201
|
-
putSettings(settings: any, enable: boolean = true, description: string = "", sessionType: string = "TP",
|
|
202
|
+
putSettings(settings: any, enable: boolean = true, description: string = "", sessionType: string = "TP", encryption: CurtainEncryption = {
|
|
203
|
+
encrypted: false,
|
|
204
|
+
e2e: false,
|
|
205
|
+
}, onUploadProgress: any = undefined) {
|
|
202
206
|
let form: FormData = new FormData();
|
|
203
|
-
|
|
207
|
+
let data = JSON.stringify(settings, replacer)
|
|
204
208
|
if (enable) {
|
|
205
209
|
form.append("enable", "True")
|
|
206
210
|
} else {
|
|
207
211
|
form.append("enable", "False")
|
|
208
212
|
}
|
|
209
|
-
if (encrypted) {
|
|
213
|
+
if (encryption.encrypted) {
|
|
210
214
|
form.append("encrypted", "True")
|
|
211
215
|
} else {
|
|
212
216
|
form.append("encrypted", "False")
|
|
213
217
|
}
|
|
214
|
-
|
|
215
|
-
if (e2e) {
|
|
218
|
+
if (encryption.e2e) {
|
|
216
219
|
form.append("e2e", "True")
|
|
217
220
|
} else {
|
|
218
221
|
form.append("e2e", "False")
|
|
219
222
|
}
|
|
220
223
|
|
|
224
|
+
if (encryption.encrypted && encryption.e2e && encryption.publicKey !== undefined) {
|
|
225
|
+
encryptDataRSA(data, encryption.publicKey).then((response) => {
|
|
226
|
+
form.append("file", new Blob([response], {type: 'text/json'}), "curtain-settings.json")
|
|
227
|
+
})
|
|
228
|
+
} else {
|
|
229
|
+
form.append("file", new Blob([data], {type: 'text/json'}), "curtain-settings.json")
|
|
230
|
+
}
|
|
231
|
+
|
|
221
232
|
form.append("description", description)
|
|
222
233
|
form.append("curtain_type", sessionType)
|
|
223
234
|
let headers = new AxiosHeaders();
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export function encryptDataRSA(data: string, publicKey: CryptoKey) {
|
|
2
|
+
return crypto.subtle.encrypt({name: 'RSA-OAEP'}, publicKey, new TextEncoder().encode(data))
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function decryptDataRSA(data: string, privateKey: CryptoKey) {
|
|
6
|
+
return crypto.subtle.decrypt({name: 'RSA-OAEP'}, privateKey, new TextEncoder().encode(data))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function importPublicKey(key: ArrayBuffer) {
|
|
10
|
+
return await crypto.subtle.importKey('spki', key, {name: 'RSA-OAEP', hash: 'SHA-256'}, true, ['encrypt'])
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function importPrivateKey(key: ArrayBuffer) {
|
|
14
|
+
return await crypto.subtle.importKey('pkcs8', key, {name: 'RSA-OAEP', hash: 'SHA-256'}, true, ['decrypt'])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function generateKeyPair(modulusLength: number = 2048, publicExponent: Uint8Array = new Uint8Array([1, 0, 1])) {
|
|
18
|
+
return await crypto.subtle.generateKey(
|
|
19
|
+
{
|
|
20
|
+
name: "RSA-OAEP",
|
|
21
|
+
modulusLength: modulusLength,
|
|
22
|
+
publicExponent: publicExponent,
|
|
23
|
+
hash: "SHA-256",
|
|
24
|
+
},
|
|
25
|
+
true,
|
|
26
|
+
["encrypt", "decrypt"],
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function exportPublicKey(key: CryptoKey) {
|
|
31
|
+
return await crypto.subtle.exportKey('spki', key)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function exportPrivateKey(key: CryptoKey) {
|
|
35
|
+
return await crypto.subtle.exportKey('pkcs8', key)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function importKey(key: ArrayBuffer, type: "public"|"private") {
|
|
39
|
+
if (type === "public") {
|
|
40
|
+
return await importPublicKey(key)
|
|
41
|
+
} else {
|
|
42
|
+
return await importPrivateKey(key)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function exportKeyString(key: CryptoKey, type: "public"|"private"): Promise<string> {
|
|
47
|
+
if (type === "public") {
|
|
48
|
+
const k = await exportPublicKey(key)
|
|
49
|
+
return arrayBufferToBase64String(k)
|
|
50
|
+
} else {
|
|
51
|
+
const k = await exportPrivateKey(key)
|
|
52
|
+
return arrayBufferToBase64String(k)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function saveToLocalStorage(key: CryptoKey, type: "public"|"private") {
|
|
57
|
+
const k = await exportKeyString(key, type)
|
|
58
|
+
localStorage.setItem(type + "_key", k)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function loadFromLocalStorage(type: "public"|"private") {
|
|
62
|
+
const k = localStorage.getItem(type + "_key")
|
|
63
|
+
if (k) {
|
|
64
|
+
return await importKey(pemToArrayBuffer(k), type)
|
|
65
|
+
}
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface CurtainEncryption {
|
|
70
|
+
encrypted: boolean,
|
|
71
|
+
publicKey?: CryptoKey,
|
|
72
|
+
e2e: boolean,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function arrayBufferToBase64String(arrayBuffer: ArrayBuffer) {
|
|
76
|
+
const byteArray = new Uint8Array(arrayBuffer)
|
|
77
|
+
let byteString = ''
|
|
78
|
+
for (let i=0; i<byteArray.byteLength; i++) {
|
|
79
|
+
byteString += String.fromCharCode(byteArray[i])
|
|
80
|
+
}
|
|
81
|
+
return btoa(byteString)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function removeLines(str_data: string) {
|
|
85
|
+
return str_data.replace("\n", "");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function base64ToArrayBuffer(b64: string) {
|
|
89
|
+
const byteString = atob(b64);
|
|
90
|
+
const byteArray = new Uint8Array(byteString.length);
|
|
91
|
+
for(let i=0; i < byteString.length; i++) {
|
|
92
|
+
byteArray[i] = byteString.charCodeAt(i);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return byteArray;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function pemToArrayBuffer(pem: string) {
|
|
99
|
+
const b64Lines = removeLines(pem);
|
|
100
|
+
let b64Prefix = b64Lines.replace('-----BEGIN PRIVATE KEY-----', '');
|
|
101
|
+
b64Prefix = b64Prefix.replace('-----BEGIN PUBLIC KEY-----', '');
|
|
102
|
+
let b64Final = b64Prefix.replace('-----END PRIVATE KEY-----', '');
|
|
103
|
+
b64Final = b64Final.replace('-----END PUBLIC KEY-----', '');
|
|
104
|
+
|
|
105
|
+
return base64ToArrayBuffer(b64Final);
|
|
106
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import {CurtainWebAPI, replacer, reviver} from "./classes/curtain-api";
|
|
2
2
|
import {User} from "./classes/curtain-user";
|
|
3
3
|
import {getProteomicsData, getPrideData, getEBIAlpha, getInteractomeAtlas, getStringDBInteractions} from "./utilities";
|
|
4
|
-
|
|
5
|
-
export {
|
|
4
|
+
import {importKey, importPrivateKey, exportPrivateKey, exportKeyString, exportPublicKey, importPublicKey, CurtainEncryption, generateKeyPair, encryptDataRSA, decryptDataRSA, loadFromLocalStorage, saveToLocalStorage} from "./classes/curtain-encryption";
|
|
5
|
+
export {
|
|
6
|
+
CurtainWebAPI,
|
|
7
|
+
User,
|
|
8
|
+
getProteomicsData,
|
|
9
|
+
getPrideData,
|
|
10
|
+
getEBIAlpha,
|
|
11
|
+
getInteractomeAtlas,
|
|
12
|
+
getStringDBInteractions,
|
|
13
|
+
replacer,
|
|
14
|
+
reviver,
|
|
15
|
+
importKey,
|
|
16
|
+
importPrivateKey,
|
|
17
|
+
exportPrivateKey,
|
|
18
|
+
exportKeyString,
|
|
19
|
+
exportPublicKey,
|
|
20
|
+
importPublicKey,
|
|
21
|
+
CurtainEncryption,
|
|
22
|
+
generateKeyPair,
|
|
23
|
+
encryptDataRSA,
|
|
24
|
+
decryptDataRSA,
|
|
25
|
+
loadFromLocalStorage,
|
|
26
|
+
saveToLocalStorage
|
|
27
|
+
};
|