curtain-web-api 1.0.37 → 1.0.39
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.
|
@@ -14,3 +14,7 @@ export interface CurtainEncryption {
|
|
|
14
14
|
publicKey?: CryptoKey;
|
|
15
15
|
e2e: boolean;
|
|
16
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;
|
|
@@ -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.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.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
|
}
|
|
@@ -66,14 +66,13 @@ function importKey(key, type) {
|
|
|
66
66
|
exports.importKey = importKey;
|
|
67
67
|
function exportKeyString(key, type) {
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const decoder = new TextDecoder("utf-8");
|
|
70
69
|
if (type === "public") {
|
|
71
70
|
const k = yield exportPublicKey(key);
|
|
72
|
-
return
|
|
71
|
+
return arrayBufferToBase64String(k);
|
|
73
72
|
}
|
|
74
73
|
else {
|
|
75
74
|
const k = yield exportPrivateKey(key);
|
|
76
|
-
return
|
|
75
|
+
return arrayBufferToBase64String(k);
|
|
77
76
|
}
|
|
78
77
|
});
|
|
79
78
|
}
|
|
@@ -89,9 +88,40 @@ function loadFromLocalStorage(type) {
|
|
|
89
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
89
|
const k = localStorage.getItem(type + "_key");
|
|
91
90
|
if (k) {
|
|
92
|
-
return yield importKey(
|
|
91
|
+
return yield importKey(pemToArrayBuffer(k), type);
|
|
93
92
|
}
|
|
94
93
|
return undefined;
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
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,5 +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
|
-
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 };
|
|
4
|
+
import { importKey, importPrivateKey, exportPrivateKey, exportKeyString, exportPublicKey, importPublicKey, CurtainEncryption, generateKeyPair, encryptDataRSA, decryptDataRSA, loadFromLocalStorage, saveToLocalStorage, pemToArrayBuffer, base64ToArrayBuffer, arrayBufferToBase64String, removeLines } 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, pemToArrayBuffer, base64ToArrayBuffer, arrayBufferToBase64String, removeLines };
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.removeLines = exports.arrayBufferToBase64String = exports.base64ToArrayBuffer = exports.pemToArrayBuffer = 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; } });
|
|
@@ -25,3 +25,7 @@ Object.defineProperty(exports, "encryptDataRSA", { enumerable: true, get: functi
|
|
|
25
25
|
Object.defineProperty(exports, "decryptDataRSA", { enumerable: true, get: function () { return curtain_encryption_1.decryptDataRSA; } });
|
|
26
26
|
Object.defineProperty(exports, "loadFromLocalStorage", { enumerable: true, get: function () { return curtain_encryption_1.loadFromLocalStorage; } });
|
|
27
27
|
Object.defineProperty(exports, "saveToLocalStorage", { enumerable: true, get: function () { return curtain_encryption_1.saveToLocalStorage; } });
|
|
28
|
+
Object.defineProperty(exports, "pemToArrayBuffer", { enumerable: true, get: function () { return curtain_encryption_1.pemToArrayBuffer; } });
|
|
29
|
+
Object.defineProperty(exports, "base64ToArrayBuffer", { enumerable: true, get: function () { return curtain_encryption_1.base64ToArrayBuffer; } });
|
|
30
|
+
Object.defineProperty(exports, "arrayBufferToBase64String", { enumerable: true, get: function () { return curtain_encryption_1.arrayBufferToBase64String; } });
|
|
31
|
+
Object.defineProperty(exports, "removeLines", { enumerable: true, get: function () { return curtain_encryption_1.removeLines; } });
|
package/package.json
CHANGED
|
@@ -44,13 +44,12 @@ export async function importKey(key: ArrayBuffer, type: "public"|"private") {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export async function exportKeyString(key: CryptoKey, type: "public"|"private"): Promise<string> {
|
|
47
|
-
const decoder = new TextDecoder("utf-8")
|
|
48
47
|
if (type === "public") {
|
|
49
48
|
const k = await exportPublicKey(key)
|
|
50
|
-
return
|
|
49
|
+
return arrayBufferToBase64String(k)
|
|
51
50
|
} else {
|
|
52
51
|
const k = await exportPrivateKey(key)
|
|
53
|
-
return
|
|
52
|
+
return arrayBufferToBase64String(k)
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
|
|
@@ -62,7 +61,7 @@ export async function saveToLocalStorage(key: CryptoKey, type: "public"|"private
|
|
|
62
61
|
export async function loadFromLocalStorage(type: "public"|"private") {
|
|
63
62
|
const k = localStorage.getItem(type + "_key")
|
|
64
63
|
if (k) {
|
|
65
|
-
return await importKey(
|
|
64
|
+
return await importKey(pemToArrayBuffer(k), type)
|
|
66
65
|
}
|
|
67
66
|
return undefined
|
|
68
67
|
}
|
|
@@ -72,3 +71,36 @@ export interface CurtainEncryption {
|
|
|
72
71
|
publicKey?: CryptoKey,
|
|
73
72
|
e2e: boolean,
|
|
74
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,7 +1,7 @@
|
|
|
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
|
-
import {importKey, importPrivateKey, exportPrivateKey, exportKeyString, exportPublicKey, importPublicKey, CurtainEncryption, generateKeyPair, encryptDataRSA, decryptDataRSA, loadFromLocalStorage, saveToLocalStorage} from "./classes/curtain-encryption";
|
|
4
|
+
import {importKey, importPrivateKey, exportPrivateKey, exportKeyString, exportPublicKey, importPublicKey, CurtainEncryption, generateKeyPair, encryptDataRSA, decryptDataRSA, loadFromLocalStorage, saveToLocalStorage, pemToArrayBuffer, base64ToArrayBuffer, arrayBufferToBase64String, removeLines} from "./classes/curtain-encryption";
|
|
5
5
|
export {
|
|
6
6
|
CurtainWebAPI,
|
|
7
7
|
User,
|
|
@@ -23,5 +23,9 @@ export {
|
|
|
23
23
|
encryptDataRSA,
|
|
24
24
|
decryptDataRSA,
|
|
25
25
|
loadFromLocalStorage,
|
|
26
|
-
saveToLocalStorage
|
|
26
|
+
saveToLocalStorage,
|
|
27
|
+
pemToArrayBuffer,
|
|
28
|
+
base64ToArrayBuffer,
|
|
29
|
+
arrayBufferToBase64String,
|
|
30
|
+
removeLines
|
|
27
31
|
};
|