@icure/api 5.0.10 → 5.0.13

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.
@@ -56,7 +56,6 @@ class IccCryptoXApi {
56
56
  emptyHcpCache(hcpartyId) {
57
57
  delete this.hcPartyKeysRequestsCache[hcpartyId];
58
58
  delete this.dataOwnerCache[hcpartyId];
59
- delete this.dataOwnerCache[hcpartyId];
60
59
  }
61
60
  /**
62
61
  * Gets all delegate encrypted HcParty keys of the delegate with the given `delegateHcPartyId`, and for each key the delegator id
@@ -574,7 +573,10 @@ class IccCryptoXApi {
574
573
  const [publicKeyFingerprint, encryptedAesExchangeKey] = candidates[candidates.findIndex(([k, v]) => publicKeys.some((pk) => pk.endsWith(k)))];
575
574
  return Object.assign(Object.assign({}, map), { [e[0]]: { [publicKeyFingerprint]: encryptedAesExchangeKey } });
576
575
  }, {});
577
- return !owner.publicKey || mapOfAesExchangeKeys[owner.publicKey] || !((_b = owner.hcPartyKeys) === null || _b === void 0 ? void 0 : _b[delegateId]) || (publicKeys.find((p) => p == owner.publicKey) == undefined)
576
+ return !owner.publicKey ||
577
+ mapOfAesExchangeKeys[owner.publicKey] ||
578
+ !((_b = owner.hcPartyKeys) === null || _b === void 0 ? void 0 : _b[delegateId]) ||
579
+ publicKeys.find((p) => p == owner.publicKey) == undefined
578
580
  ? mapOfAesExchangeKeys
579
581
  : Object.assign(Object.assign({}, mapOfAesExchangeKeys), { [owner.publicKey]: { [owner.publicKey.slice(-32)]: owner.hcPartyKeys[delegateId][0] } });
580
582
  });
@@ -703,9 +705,9 @@ class IccCryptoXApi {
703
705
  this.throwDetailedExceptionForInvalidParameter('child.id', child.id, 'addDelegationsAndEncryptionKeys', arguments);
704
706
  return (secretDelegationKey
705
707
  ? this.extendedDelegationsAndCryptedForeignKeys(child, parent, ownerId, delegateId, secretDelegationKey)
706
- : Promise.resolve({ delegations: {}, cryptedForeignKeys: {} }))
708
+ : Promise.resolve({ modifiedObject: child, delegations: {}, cryptedForeignKeys: {}, secretId: null }))
707
709
  .then((extendedChildObjectSPKsAndCFKs) => secretEncryptionKey
708
- ? this.appendEncryptionKeys(child, ownerId, delegateId, secretEncryptionKey).then(
710
+ ? this.appendEncryptionKeys(extendedChildObjectSPKsAndCFKs.modifiedObject, ownerId, delegateId, secretEncryptionKey).then(
709
711
  //TODO: extendedDelegationsAndCryptedForeignKeys and appendEncryptionKeys can be done in parallel
710
712
  (extendedChildObjectEKs) => ({
711
713
  extendedSPKsAndCFKs: extendedChildObjectSPKsAndCFKs,
@@ -716,7 +718,7 @@ class IccCryptoXApi {
716
718
  extendedEKs: { encryptionKeys: {} },
717
719
  }))
718
720
  .then(({ extendedSPKsAndCFKs: extendedChildObjectSPKsAndCFKs, extendedEKs: extendedChildObjectEKs }) => {
719
- return _.assign(child, {
721
+ return _.assign(extendedChildObjectSPKsAndCFKs.modifiedObject, {
720
722
  // Conservative version ... We might want to be more aggressive with the deduplication of keys
721
723
  // For each delegate, we are going to concatenate to the src (the new delegations), the object in dest (the current delegations)
722
724
  // for which we do not find an equivalent delegation (same delegator, same delegate)
@@ -1361,7 +1363,7 @@ class IccCryptoXApi {
1361
1363
  if (!selectedPublicKey) {
1362
1364
  throw new Error(`Invalid owner, no public key, keypairs have not be set for ${ownerId}`);
1363
1365
  }
1364
- if ((owner.hcPartyKeys || {})[delegateId] ||
1366
+ if (((owner.hcPartyKeys || {})[delegateId] && owner.publicKey && availablePublicKeysFingerprints.includes(owner.publicKey.slice(-32))) ||
1365
1367
  Object.values(owner.aesExchangeKeys || {}).some((x) => x[delegateId] && Object.keys(x[delegateId]).some((k) => availablePublicKeysFingerprints.includes(k)))) {
1366
1368
  return owner;
1367
1369
  }