@icure/api 5.0.37 → 6.0.0
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/icc-x-api/icc-crypto-x-api.d.ts +5 -5
- package/icc-x-api/icc-crypto-x-api.js +28 -24
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/storage/KeyStorageFacade.d.ts +6 -6
- package/icc-x-api/storage/KeyStorageFacade.js.map +1 -1
- package/icc-x-api/storage/KeyStorageImpl.d.ts +6 -6
- package/icc-x-api/storage/KeyStorageImpl.js +27 -10
- package/icc-x-api/storage/KeyStorageImpl.js.map +1 -1
- package/icc-x-api/storage/LocalStorageImpl.d.ts +3 -7
- package/icc-x-api/storage/LocalStorageImpl.js +22 -11
- package/icc-x-api/storage/LocalStorageImpl.js.map +1 -1
- package/icc-x-api/storage/StorageFacade.d.ts +3 -3
- package/icc-x-api/storage/StorageFacade.js.map +1 -1
- package/package.json +1 -1
|
@@ -379,9 +379,9 @@ export declare class IccCryptoXApi {
|
|
|
379
379
|
remote: boolean;
|
|
380
380
|
local: boolean;
|
|
381
381
|
}>;
|
|
382
|
-
getKeychainInBrowserLocalStorageAsBase64(id: string): string | undefined
|
|
383
|
-
getKeychainValidityDateInBrowserLocalStorage(id: string): string | undefined
|
|
384
|
-
loadKeychainFromBrowserLocalStorage(id: string): Uint8Array[] | null
|
|
382
|
+
getKeychainInBrowserLocalStorageAsBase64(id: string): Promise<string | undefined>;
|
|
383
|
+
getKeychainValidityDateInBrowserLocalStorage(id: string): Promise<string | undefined>;
|
|
384
|
+
loadKeychainFromBrowserLocalStorage(id: string): Promise<Uint8Array[] | null>;
|
|
385
385
|
/**
|
|
386
386
|
* loads the RSA key pair (hcparty) in JWK from local storage, not imported
|
|
387
387
|
*
|
|
@@ -389,10 +389,10 @@ export declare class IccCryptoXApi {
|
|
|
389
389
|
* @param publicKeyFingerPrint the 32 last characters of public key this private key is associated with
|
|
390
390
|
* @returns {Object} it is in JWK - not imported
|
|
391
391
|
*/
|
|
392
|
-
loadKeyPairNotImported(id: string, publicKeyFingerPrint?: string): {
|
|
392
|
+
loadKeyPairNotImported(id: string, publicKeyFingerPrint?: string): Promise<{
|
|
393
393
|
publicKey: JsonWebKey;
|
|
394
394
|
privateKey: JsonWebKey;
|
|
395
|
-
}
|
|
395
|
+
}>;
|
|
396
396
|
/**
|
|
397
397
|
* Loads and imports the RSA key pair (hcparty) from local storage
|
|
398
398
|
*
|
|
@@ -89,7 +89,7 @@ class IccCryptoXApi {
|
|
|
89
89
|
for (const pk of pubKeys) {
|
|
90
90
|
const fingerprint = pk.slice(-32);
|
|
91
91
|
if (!this.rsaKeyPairs[fingerprint]) {
|
|
92
|
-
yield this.cacheKeyPair(this.loadKeyPairNotImported(dataOwnerId, fingerprint));
|
|
92
|
+
yield this.cacheKeyPair(yield this.loadKeyPairNotImported(dataOwnerId, fingerprint));
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
});
|
|
@@ -98,7 +98,7 @@ class IccCryptoXApi {
|
|
|
98
98
|
var _a;
|
|
99
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
100
|
const fingerprint = pubKeyOrFingerprint.slice(-32);
|
|
101
|
-
return (_a = this.rsaKeyPairs[fingerprint]) !== null && _a !== void 0 ? _a : (yield this.cacheKeyPair(this.loadKeyPairNotImported(dataOwnerId, fingerprint)));
|
|
101
|
+
return (_a = this.rsaKeyPairs[fingerprint]) !== null && _a !== void 0 ? _a : (yield this.cacheKeyPair(yield this.loadKeyPairNotImported(dataOwnerId, fingerprint)));
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
getPublicKeys() {
|
|
@@ -189,7 +189,7 @@ class IccCryptoXApi {
|
|
|
189
189
|
const importedPrivateKey = yield this._RSA.importKey('pkcs8', (0, binary_utils_1.hex2ua)(decryptedPrivatedKey), ['decrypt']);
|
|
190
190
|
const importedPublicKey = yield this._RSA.importKey('spki', (0, binary_utils_1.hex2ua)(hcp.publicKey), ['encrypt']);
|
|
191
191
|
const exportedKeyPair = yield this._RSA.exportKeys({ publicKey: importedPublicKey, privateKey: importedPrivateKey }, 'jwk', 'jwk');
|
|
192
|
-
this._keyStorage.storeKeyPair(`${this.rsaLocalStoreIdPrefix}${hcp.id}`, exportedKeyPair);
|
|
192
|
+
yield this._keyStorage.storeKeyPair(`${this.rsaLocalStoreIdPrefix}${hcp.id}`, exportedKeyPair);
|
|
193
193
|
}
|
|
194
194
|
catch (e) {
|
|
195
195
|
console.log('Cannot decrypt shamir RSA key');
|
|
@@ -232,7 +232,7 @@ class IccCryptoXApi {
|
|
|
232
232
|
return delegatorAndKeys;
|
|
233
233
|
}
|
|
234
234
|
const fingerprint = pk.slice(-32);
|
|
235
|
-
const keyPair = (_b = this.rsaKeyPairs[fingerprint]) !== null && _b !== void 0 ? _b : (yield this.cacheKeyPair(this.loadKeyPairNotImported(loggedHcPartyId, fingerprint)));
|
|
235
|
+
const keyPair = (_b = this.rsaKeyPairs[fingerprint]) !== null && _b !== void 0 ? _b : (yield this.cacheKeyPair(yield this.loadKeyPairNotImported(loggedHcPartyId, fingerprint)));
|
|
236
236
|
if (!keyPair) {
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
@@ -1055,7 +1055,7 @@ class IccCryptoXApi {
|
|
|
1055
1055
|
const keyPair = yield this._RSA.importKeyPair('jwk', privateKeyInJwk, 'jwk', (0, utils_1.spkiToJwk)((0, binary_utils_1.hex2ua)(publicKey)));
|
|
1056
1056
|
this.rsaKeyPairs[publicKey.slice(-32)] = keyPair;
|
|
1057
1057
|
const exportedKeyPair = yield this._RSA.exportKeys(keyPair, 'jwk', 'jwk');
|
|
1058
|
-
return this._keyStorage.storeKeyPair(`${this.rsaLocalStoreIdPrefix}${healthcarePartyId}.${publicKey.slice(-32)}`, exportedKeyPair);
|
|
1058
|
+
return yield this._keyStorage.storeKeyPair(`${this.rsaLocalStoreIdPrefix}${healthcarePartyId}.${publicKey.slice(-32)}`, exportedKeyPair);
|
|
1059
1059
|
});
|
|
1060
1060
|
}
|
|
1061
1061
|
loadKeyPairsAsJwkInBrowserLocalStorage(healthcarePartyId, privateKey) {
|
|
@@ -1072,7 +1072,7 @@ class IccCryptoXApi {
|
|
|
1072
1072
|
const keyPair = yield this._RSA.importKeyPair('jwk', privateKey, 'jwk', (0, utils_1.spkiToJwk)((0, binary_utils_1.hex2ua)(publicKey)));
|
|
1073
1073
|
this.rsaKeyPairs[publicKey.slice(-32)] = keyPair;
|
|
1074
1074
|
const exportedKeyPair = yield this._RSA.exportKeys(keyPair, 'jwk', 'jwk');
|
|
1075
|
-
return this._keyStorage.storeKeyPair(`${this.rsaLocalStoreIdPrefix}${healthcarePartyId}.${publicKey.slice(-32)}`, exportedKeyPair);
|
|
1075
|
+
return yield this._keyStorage.storeKeyPair(`${this.rsaLocalStoreIdPrefix}${healthcarePartyId}.${publicKey.slice(-32)}`, exportedKeyPair);
|
|
1076
1076
|
});
|
|
1077
1077
|
}
|
|
1078
1078
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -1129,7 +1129,7 @@ class IccCryptoXApi {
|
|
|
1129
1129
|
console.error('No encryption key!');
|
|
1130
1130
|
}
|
|
1131
1131
|
const opts = hcp.options || {};
|
|
1132
|
-
const crt = this.getKeychainInBrowserLocalStorageAsBase64(hcp.id);
|
|
1132
|
+
const crt = yield this.getKeychainInBrowserLocalStorageAsBase64(hcp.id);
|
|
1133
1133
|
if (!!aesKey && !!crt) {
|
|
1134
1134
|
let crtEncrypted = null;
|
|
1135
1135
|
try {
|
|
@@ -1219,8 +1219,10 @@ class IccCryptoXApi {
|
|
|
1219
1219
|
}
|
|
1220
1220
|
// noinspection JSUnusedGlobalSymbols
|
|
1221
1221
|
loadKeychainFromBrowserLocalStorage(id) {
|
|
1222
|
-
|
|
1223
|
-
|
|
1222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1223
|
+
const lsItem = yield this._storage.getItem(this.keychainLocalStoreIdPrefix + id);
|
|
1224
|
+
return lsItem !== undefined ? (0, binary_utils_1.b64_2uas)(lsItem) : null;
|
|
1225
|
+
});
|
|
1224
1226
|
}
|
|
1225
1227
|
/**
|
|
1226
1228
|
* loads the RSA key pair (hcparty) in JWK from local storage, not imported
|
|
@@ -1231,18 +1233,20 @@ class IccCryptoXApi {
|
|
|
1231
1233
|
*/
|
|
1232
1234
|
loadKeyPairNotImported(id, publicKeyFingerPrint) {
|
|
1233
1235
|
var _a;
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1237
|
+
if (typeof Storage === 'undefined') {
|
|
1238
|
+
console.log('Your browser does not support HTML5 Browser Local Storage !');
|
|
1239
|
+
throw 'Your browser does not support HTML5 Browser Local Storage !';
|
|
1240
|
+
}
|
|
1241
|
+
//TODO decryption
|
|
1242
|
+
const item = publicKeyFingerPrint
|
|
1243
|
+
? (_a = (yield this._keyStorage.getKeypair(this.rsaLocalStoreIdPrefix + id + '.' + publicKeyFingerPrint.slice(-32)))) !== null && _a !== void 0 ? _a : (yield this._keyStorage.getKeypair(this.rsaLocalStoreIdPrefix + id))
|
|
1244
|
+
: yield this._keyStorage.getKeypair(this.rsaLocalStoreIdPrefix + id);
|
|
1245
|
+
if (!item) {
|
|
1246
|
+
console.warn(`No key can be found in local storage for id ${id} and publicKeyFingerPrint ${publicKeyFingerPrint}`);
|
|
1247
|
+
}
|
|
1248
|
+
return item;
|
|
1249
|
+
});
|
|
1246
1250
|
}
|
|
1247
1251
|
/**
|
|
1248
1252
|
* Loads and imports the RSA key pair (hcparty) from local storage
|
|
@@ -1251,9 +1255,9 @@ class IccCryptoXApi {
|
|
|
1251
1255
|
* @returns {Promise} -> {CryptoKey} - imported RSA
|
|
1252
1256
|
*/
|
|
1253
1257
|
loadKeyPairImported(id) {
|
|
1254
|
-
return new Promise((resolve, reject) => {
|
|
1258
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
1255
1259
|
try {
|
|
1256
|
-
const jwkKeyPair = this._keyStorage.getKeypair(this.rsaLocalStoreIdPrefix + id);
|
|
1260
|
+
const jwkKeyPair = yield this._keyStorage.getKeypair(this.rsaLocalStoreIdPrefix + id);
|
|
1257
1261
|
if (jwkKeyPair !== undefined) {
|
|
1258
1262
|
if (jwkKeyPair.publicKey && jwkKeyPair.privateKey) {
|
|
1259
1263
|
this._RSA.importKeyPair('jwk', jwkKeyPair.privateKey, 'jwk', jwkKeyPair.publicKey).then(resolve, (err) => {
|
|
@@ -1276,7 +1280,7 @@ class IccCryptoXApi {
|
|
|
1276
1280
|
catch (err) {
|
|
1277
1281
|
reject(err);
|
|
1278
1282
|
}
|
|
1279
|
-
});
|
|
1283
|
+
}));
|
|
1280
1284
|
}
|
|
1281
1285
|
/**
|
|
1282
1286
|
* When a user lost his keys, people to whom he shared information may call this method to give access back to him, re-encrypting their common
|