@icure/api 5.2.35 → 5.3.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-calendar-item-x-api.js +10 -5
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.js +6 -1
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.js +4 -3
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +3 -5
- package/icc-x-api/icc-crypto-x-api.js +46 -50
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.js +9 -4
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.js +9 -7
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.js +10 -5
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.js +12 -7
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.js +6 -1
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/index.js +42 -0
- package/icc-x-api/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -407,13 +407,11 @@ export declare class IccCryptoXApi {
|
|
|
407
407
|
* 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
|
|
408
408
|
* AES key using the new user public key.
|
|
409
409
|
*
|
|
410
|
-
* @param
|
|
411
|
-
* @param ownerId Id of the data owner to which we would like to
|
|
410
|
+
* @param accessGiver User, in charge of giving access back to the person who previously gave him some access (should be the current user)
|
|
411
|
+
* @param ownerId Id of the data owner to which we would like to get access back
|
|
412
412
|
* @param ownerNewPublicKey New Data Owner Public Key we want to use to re-encrypt previously created AES key
|
|
413
|
-
*
|
|
414
|
-
* @return The DataOwner, updated by the delegateUser to add the new encrypted AES Key using the new provided public key
|
|
415
413
|
*/
|
|
416
|
-
giveAccessBackTo(
|
|
414
|
+
giveAccessBackTo(accessGiver: User, ownerId: string, ownerNewPublicKey: string): Promise<void>;
|
|
417
415
|
addNewKeyPairForOwnerId(maintenanceTasksApi: IccMaintenanceTaskXApi, user: User, ownerId: string, generateTransferKey?: boolean, sendMaintenanceTasks?: boolean): Promise<{
|
|
418
416
|
dataOwner: HealthcareParty | Patient | Device;
|
|
419
417
|
publicKey: string;
|
|
@@ -1287,60 +1287,56 @@ class IccCryptoXApi {
|
|
|
1287
1287
|
* 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
|
|
1288
1288
|
* AES key using the new user public key.
|
|
1289
1289
|
*
|
|
1290
|
-
* @param
|
|
1291
|
-
* @param ownerId Id of the data owner to which we would like to
|
|
1290
|
+
* @param accessGiver User, in charge of giving access back to the person who previously gave him some access (should be the current user)
|
|
1291
|
+
* @param ownerId Id of the data owner to which we would like to get access back
|
|
1292
1292
|
* @param ownerNewPublicKey New Data Owner Public Key we want to use to re-encrypt previously created AES key
|
|
1293
|
-
*
|
|
1294
|
-
* @return The DataOwner, updated by the delegateUser to add the new encrypted AES Key using the new provided public key
|
|
1295
1293
|
*/
|
|
1296
|
-
giveAccessBackTo(
|
|
1297
|
-
var _a, _b
|
|
1294
|
+
giveAccessBackTo(accessGiver, ownerId, ownerNewPublicKey) {
|
|
1295
|
+
var _a, _b;
|
|
1298
1296
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1301
|
-
|
|
1297
|
+
const newPubKeyCryptoKey = yield this._RSA.importKey('spki', (0, binary_utils_1.hex2ua)(ownerNewPublicKey), ['encrypt']);
|
|
1298
|
+
const giverDoId = (_b = (_a = accessGiver.healthcarePartyId) !== null && _a !== void 0 ? _a : accessGiver.patientId) !== null && _b !== void 0 ? _b : accessGiver.deviceId;
|
|
1299
|
+
if (!giverDoId) {
|
|
1300
|
+
throw new Error(`Access giver ${accessGiver.id} must be a data Owner`);
|
|
1302
1301
|
}
|
|
1303
|
-
const
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
if (
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
.then((encrAesInfo) => {
|
|
1319
|
-
return { pubKeyUsedToEncryptAes: Object.keys(encrAesInfo)[0], encryptedAes: Object.values(encrAesInfo)[0] };
|
|
1320
|
-
});
|
|
1321
|
-
}));
|
|
1322
|
-
delKeys[encrAesKeyInfo.pubKeyUsedToEncryptAes] = encrAesKeyInfo.encryptedAes;
|
|
1323
|
-
}
|
|
1324
|
-
catch (e) {
|
|
1325
|
-
console.log(`${delegateId} could not re-encrypt AES Key of ${dataOwnerToUpdate.dataOwner.id}`);
|
|
1326
|
-
}
|
|
1327
|
-
finally {
|
|
1328
|
-
delAcc[delId] = delKeys;
|
|
1302
|
+
const giverDoKeys = yield this.getDataOwner(giverDoId).then((doData) => { var _a; return [doData.dataOwner.publicKey, ...Object.keys((_a = doData.dataOwner.aesExchangeKeys) !== null && _a !== void 0 ? _a : {})].filter((x) => !!x); });
|
|
1303
|
+
const giveAccessBackToExchangeKey = (exchangeKeys, delegatorId, // Getter for getter exchange keys, giver for giver exchange keys
|
|
1304
|
+
delegateId // Giver for getter exchange keys, getter for giver exchange keys
|
|
1305
|
+
) => __awaiter(this, void 0, void 0, function* () {
|
|
1306
|
+
const updatedExchangeKeys = _.cloneDeep(exchangeKeys);
|
|
1307
|
+
for (const [publicKey, mapsByDelegate] of Object.entries(updatedExchangeKeys)) {
|
|
1308
|
+
const mapOfDelegate = mapsByDelegate[delegateId];
|
|
1309
|
+
if (!!mapOfDelegate && !mapOfDelegate[ownerNewPublicKey.slice(-32)]) {
|
|
1310
|
+
const decryptedKey = yield this.decryptHcPartyKey(giverDoId, delegatorId, delegateId, publicKey, mapOfDelegate, giverDoKeys)
|
|
1311
|
+
.then((x) => x === null || x === void 0 ? void 0 : x.rawKey)
|
|
1312
|
+
.catch(() => undefined);
|
|
1313
|
+
if (decryptedKey) {
|
|
1314
|
+
mapOfDelegate[ownerNewPublicKey.slice(-32)] = yield this.encryptAesKeyOnlyForProvidedKeys(decryptedKey, delegateId, [
|
|
1315
|
+
newPubKeyCryptoKey,
|
|
1316
|
+
]).then((encrAes) => Object.values(Object.values(encrAes)[0])[0]);
|
|
1329
1317
|
}
|
|
1330
1318
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
delAcc[delId] = delKeys;
|
|
1334
|
-
}
|
|
1335
|
-
return delAcc;
|
|
1336
|
-
}));
|
|
1337
|
-
return pubAcc;
|
|
1338
|
-
}));
|
|
1339
|
-
// After adding the potential new aesExchangeKeys, we save the updated data owner
|
|
1340
|
-
return this._saveDataOwner({
|
|
1341
|
-
type: dataOwnerToUpdate.type,
|
|
1342
|
-
dataOwner: Object.assign(Object.assign({}, dataOwnerToUpdate.dataOwner), { aesExchangeKeys: newAesExchangeKeys }),
|
|
1319
|
+
}
|
|
1320
|
+
return updatedExchangeKeys;
|
|
1343
1321
|
});
|
|
1322
|
+
yield (0, utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
1323
|
+
var _c;
|
|
1324
|
+
const getterDo = yield this.getDataOwner(ownerId);
|
|
1325
|
+
const updatedGetterKeys = yield giveAccessBackToExchangeKey((_c = getterDo.dataOwner.aesExchangeKeys) !== null && _c !== void 0 ? _c : {}, ownerId, giverDoId);
|
|
1326
|
+
yield this._saveDataOwner({
|
|
1327
|
+
type: getterDo.type,
|
|
1328
|
+
dataOwner: Object.assign(Object.assign({}, getterDo.dataOwner), { aesExchangeKeys: updatedGetterKeys }),
|
|
1329
|
+
});
|
|
1330
|
+
}), 3, 5000, 1);
|
|
1331
|
+
yield (0, utils_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
1332
|
+
var _d;
|
|
1333
|
+
const giverDo = yield this.getDataOwner(giverDoId);
|
|
1334
|
+
const updatedGiverKeys = yield giveAccessBackToExchangeKey((_d = giverDo.dataOwner.aesExchangeKeys) !== null && _d !== void 0 ? _d : {}, giverDoId, ownerId);
|
|
1335
|
+
yield this._saveDataOwner({
|
|
1336
|
+
type: giverDo.type,
|
|
1337
|
+
dataOwner: Object.assign(Object.assign({}, giverDo.dataOwner), { aesExchangeKeys: updatedGiverKeys }),
|
|
1338
|
+
});
|
|
1339
|
+
}), 3, 5000, 1);
|
|
1344
1340
|
});
|
|
1345
1341
|
}
|
|
1346
1342
|
addNewKeyPairForOwnerId(maintenanceTasksApi, user, ownerId, generateTransferKey = true, sendMaintenanceTasks = true) {
|
|
@@ -1442,16 +1438,16 @@ class IccCryptoXApi {
|
|
|
1442
1438
|
encryptAesKeyFor(aesKey, dataOwner, doNewPublicKey) {
|
|
1443
1439
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1444
1440
|
const dataOwnerAllPubKeys = [doNewPublicKey].concat(yield this.getDataOwnerPublicKeys(dataOwner));
|
|
1445
|
-
return this.encryptAesKeyOnlyForProvidedKeys(aesKey, dataOwner, dataOwnerAllPubKeys);
|
|
1441
|
+
return this.encryptAesKeyOnlyForProvidedKeys(aesKey, dataOwner.id, dataOwnerAllPubKeys);
|
|
1446
1442
|
});
|
|
1447
1443
|
}
|
|
1448
|
-
encryptAesKeyOnlyForProvidedKeys(aesKey,
|
|
1444
|
+
encryptAesKeyOnlyForProvidedKeys(aesKey, dataOwnerId, dataOwnerPubKeys) {
|
|
1449
1445
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1450
1446
|
const encryptedAesForDataOwner = yield (0, utils_1.foldAsync)(dataOwnerPubKeys, {}, (encrAes, pubKey) => __awaiter(this, void 0, void 0, function* () {
|
|
1451
1447
|
encrAes[(0, binary_utils_1.ua2hex)(yield this.RSA.exportKey(pubKey, 'spki')).slice(-32)] = (0, binary_utils_1.ua2hex)(yield this._RSA.encrypt(pubKey, (0, binary_utils_1.hex2ua)(aesKey)));
|
|
1452
1448
|
return encrAes;
|
|
1453
1449
|
}));
|
|
1454
|
-
return { [
|
|
1450
|
+
return { [dataOwnerId]: encryptedAesForDataOwner };
|
|
1455
1451
|
});
|
|
1456
1452
|
}
|
|
1457
1453
|
retrieveDataOwnerInfoAfterPotentialUpdate(dataOwnerToUpdate) {
|