@icure/api 8.0.0-RC.2 → 8.0.0-RC.4

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.
Files changed (213) hide show
  1. package/icc-api/api/IccAccesslogApi.d.ts +12 -4
  2. package/icc-api/api/IccAccesslogApi.js +23 -18
  3. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  4. package/icc-api/api/IccAgendaApi.d.ts +13 -4
  5. package/icc-api/api/IccAgendaApi.js +42 -19
  6. package/icc-api/api/IccAgendaApi.js.map +1 -1
  7. package/icc-api/api/IccApplicationsettingsApi.d.ts +1 -1
  8. package/icc-api/api/IccApplicationsettingsApi.js +2 -2
  9. package/icc-api/api/IccApplicationsettingsApi.js.map +1 -1
  10. package/icc-api/api/IccArticleApi.d.ts +13 -4
  11. package/icc-api/api/IccArticleApi.js +50 -26
  12. package/icc-api/api/IccArticleApi.js.map +1 -1
  13. package/icc-api/api/IccAuthApi.d.ts +1 -1
  14. package/icc-api/api/IccAuthApi.js +2 -2
  15. package/icc-api/api/IccAuthApi.js.map +1 -1
  16. package/icc-api/api/IccCalendarItemApi.d.ts +8 -4
  17. package/icc-api/api/IccCalendarItemApi.js +15 -22
  18. package/icc-api/api/IccCalendarItemApi.js.map +1 -1
  19. package/icc-api/api/IccCalendarItemTypeApi.d.ts +6 -4
  20. package/icc-api/api/IccCalendarItemTypeApi.js +60 -45
  21. package/icc-api/api/IccCalendarItemTypeApi.js.map +1 -1
  22. package/icc-api/api/IccClassificationApi.d.ts +14 -5
  23. package/icc-api/api/IccClassificationApi.js +22 -12
  24. package/icc-api/api/IccClassificationApi.js.map +1 -1
  25. package/icc-api/api/IccClassificationTemplateApi.d.ts +14 -5
  26. package/icc-api/api/IccClassificationTemplateApi.js +102 -70
  27. package/icc-api/api/IccClassificationTemplateApi.js.map +1 -1
  28. package/icc-api/api/IccCodeApi.d.ts +1 -1
  29. package/icc-api/api/IccCodeApi.js +2 -2
  30. package/icc-api/api/IccCodeApi.js.map +1 -1
  31. package/icc-api/api/IccContactApi.d.ts +11 -4
  32. package/icc-api/api/IccContactApi.js +20 -13
  33. package/icc-api/api/IccContactApi.js.map +1 -1
  34. package/icc-api/api/IccDataownerApi.d.ts +1 -1
  35. package/icc-api/api/IccDataownerApi.js +44 -27
  36. package/icc-api/api/IccDataownerApi.js.map +1 -1
  37. package/icc-api/api/IccDeviceApi.d.ts +1 -1
  38. package/icc-api/api/IccDeviceApi.js +43 -32
  39. package/icc-api/api/IccDeviceApi.js.map +1 -1
  40. package/icc-api/api/IccDoctemplateApi.d.ts +10 -8
  41. package/icc-api/api/IccDoctemplateApi.js +121 -101
  42. package/icc-api/api/IccDoctemplateApi.js.map +1 -1
  43. package/icc-api/api/IccDocumentApi.d.ts +13 -5
  44. package/icc-api/api/IccDocumentApi.js +24 -14
  45. package/icc-api/api/IccDocumentApi.js.map +1 -1
  46. package/icc-api/api/IccEntityrefApi.d.ts +1 -1
  47. package/icc-api/api/IccEntityrefApi.js +27 -16
  48. package/icc-api/api/IccEntityrefApi.js.map +1 -1
  49. package/icc-api/api/IccEntitytemplateApi.d.ts +6 -4
  50. package/icc-api/api/IccEntitytemplateApi.js +118 -97
  51. package/icc-api/api/IccEntitytemplateApi.js.map +1 -1
  52. package/icc-api/api/IccFormApi.d.ts +13 -5
  53. package/icc-api/api/IccFormApi.js +24 -18
  54. package/icc-api/api/IccFormApi.js.map +1 -1
  55. package/icc-api/api/IccFrontendmigrationApi.d.ts +1 -1
  56. package/icc-api/api/IccFrontendmigrationApi.js +19 -10
  57. package/icc-api/api/IccFrontendmigrationApi.js.map +1 -1
  58. package/icc-api/api/IccGroupApi.d.ts +16 -2
  59. package/icc-api/api/IccGroupApi.js +29 -3
  60. package/icc-api/api/IccGroupApi.js.map +1 -1
  61. package/icc-api/api/IccHcpartyApi.d.ts +25 -10
  62. package/icc-api/api/IccHcpartyApi.js +84 -53
  63. package/icc-api/api/IccHcpartyApi.js.map +1 -1
  64. package/icc-api/api/IccHelementApi.d.ts +13 -5
  65. package/icc-api/api/IccHelementApi.js +25 -21
  66. package/icc-api/api/IccHelementApi.js.map +1 -1
  67. package/icc-api/api/IccIcureApi.d.ts +1 -1
  68. package/icc-api/api/IccIcureApi.js +2 -2
  69. package/icc-api/api/IccIcureApi.js.map +1 -1
  70. package/icc-api/api/IccInsuranceApi.d.ts +3 -1
  71. package/icc-api/api/IccInsuranceApi.js +76 -47
  72. package/icc-api/api/IccInsuranceApi.js.map +1 -1
  73. package/icc-api/api/IccInvoiceApi.d.ts +1 -1
  74. package/icc-api/api/IccInvoiceApi.js +5 -11
  75. package/icc-api/api/IccInvoiceApi.js.map +1 -1
  76. package/icc-api/api/IccKeywordApi.d.ts +6 -5
  77. package/icc-api/api/IccKeywordApi.js +59 -45
  78. package/icc-api/api/IccKeywordApi.js.map +1 -1
  79. package/icc-api/api/IccMaintenanceTaskApi.d.ts +13 -4
  80. package/icc-api/api/IccMaintenanceTaskApi.js +22 -12
  81. package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -1
  82. package/icc-api/api/IccMedexApi.d.ts +1 -1
  83. package/icc-api/api/IccMedexApi.js +19 -10
  84. package/icc-api/api/IccMedexApi.js.map +1 -1
  85. package/icc-api/api/IccMedicallocationApi.d.ts +6 -4
  86. package/icc-api/api/IccMedicallocationApi.js +52 -39
  87. package/icc-api/api/IccMedicallocationApi.js.map +1 -1
  88. package/icc-api/api/IccMessageApi.d.ts +9 -7
  89. package/icc-api/api/IccMessageApi.js +14 -21
  90. package/icc-api/api/IccMessageApi.js.map +1 -1
  91. package/icc-api/api/IccPatientApi.d.ts +13 -5
  92. package/icc-api/api/IccPatientApi.js +23 -13
  93. package/icc-api/api/IccPatientApi.js.map +1 -1
  94. package/icc-api/api/IccPermissionApi.d.ts +1 -1
  95. package/icc-api/api/IccPermissionApi.js +19 -10
  96. package/icc-api/api/IccPermissionApi.js.map +1 -1
  97. package/icc-api/api/IccPlaceApi.d.ts +7 -5
  98. package/icc-api/api/IccPlaceApi.js +53 -40
  99. package/icc-api/api/IccPlaceApi.js.map +1 -1
  100. package/icc-api/api/IccReceiptApi.d.ts +13 -4
  101. package/icc-api/api/IccReceiptApi.js +23 -13
  102. package/icc-api/api/IccReceiptApi.js.map +1 -1
  103. package/icc-api/api/IccReplicationApi.d.ts +1 -1
  104. package/icc-api/api/IccReplicationApi.js +3 -5
  105. package/icc-api/api/IccReplicationApi.js.map +1 -1
  106. package/icc-api/api/IccRoleApi.d.ts +16 -0
  107. package/icc-api/api/IccRoleApi.js +42 -0
  108. package/icc-api/api/IccRoleApi.js.map +1 -0
  109. package/icc-api/api/IccTarificationApi.d.ts +1 -1
  110. package/icc-api/api/IccTarificationApi.js +19 -10
  111. package/icc-api/api/IccTarificationApi.js.map +1 -1
  112. package/icc-api/api/IccTimeTableApi.d.ts +13 -4
  113. package/icc-api/api/IccTimeTableApi.js +21 -9
  114. package/icc-api/api/IccTimeTableApi.js.map +1 -1
  115. package/icc-api/api/IccTopicApi.d.ts +13 -6
  116. package/icc-api/api/IccTopicApi.js +18 -3
  117. package/icc-api/api/IccTopicApi.js.map +1 -1
  118. package/icc-api/api/IccUserApi.d.ts +31 -1
  119. package/icc-api/api/IccUserApi.js +65 -2
  120. package/icc-api/api/IccUserApi.js.map +1 -1
  121. package/icc-api/api/{IccExchangeDataApi.d.ts → internal/IccExchangeDataApi.d.ts} +4 -4
  122. package/icc-api/api/internal/IccExchangeDataApi.js +106 -0
  123. package/icc-api/api/internal/IccExchangeDataApi.js.map +1 -0
  124. package/icc-api/api/{IccExchangeDataMapApi.d.ts → internal/IccExchangeDataMapApi.d.ts} +4 -4
  125. package/icc-api/api/internal/IccExchangeDataMapApi.js +84 -0
  126. package/icc-api/api/internal/IccExchangeDataMapApi.js.map +1 -0
  127. package/icc-api/api/internal/IccRecoveryDataApi.d.ts +19 -0
  128. package/icc-api/api/internal/IccRecoveryDataApi.js +83 -0
  129. package/icc-api/api/internal/IccRecoveryDataApi.js.map +1 -0
  130. package/icc-api/api/{IccSecureDelegationKeyMapApi.d.ts → internal/IccSecureDelegationKeyMapApi.d.ts} +6 -6
  131. package/icc-api/api/{IccSecureDelegationKeyMapApi.js → internal/IccSecureDelegationKeyMapApi.js} +5 -5
  132. package/icc-api/api/internal/IccSecureDelegationKeyMapApi.js.map +1 -0
  133. package/icc-api/model/Group.d.ts +4 -0
  134. package/icc-api/model/Group.js.map +1 -1
  135. package/icc-api/model/Message.d.ts +5 -0
  136. package/icc-api/model/Message.js.map +1 -1
  137. package/icc-api/model/MessageAttachment.d.ts +10 -0
  138. package/icc-api/model/MessageAttachment.js +10 -0
  139. package/icc-api/model/MessageAttachment.js.map +1 -0
  140. package/icc-api/model/PaginatedListInsurance.d.ts +20 -0
  141. package/icc-api/model/PaginatedListInsurance.js +10 -0
  142. package/icc-api/model/PaginatedListInsurance.js.map +1 -0
  143. package/icc-api/model/Role.d.ts +11 -0
  144. package/icc-api/model/Role.js +10 -0
  145. package/icc-api/model/Role.js.map +1 -0
  146. package/icc-api/model/RoleConfiguration.d.ts +6 -0
  147. package/icc-api/model/RoleConfiguration.js +10 -0
  148. package/icc-api/model/RoleConfiguration.js.map +1 -0
  149. package/icc-api/model/RoleSourceEnum.d.ts +11 -0
  150. package/icc-api/model/RoleSourceEnum.js +16 -0
  151. package/icc-api/model/RoleSourceEnum.js.map +1 -0
  152. package/icc-api/model/User.d.ts +19 -0
  153. package/icc-api/model/User.js +6 -0
  154. package/icc-api/model/User.js.map +1 -1
  155. package/icc-api/model/UserTypeEnum.d.ts +9 -0
  156. package/icc-api/model/UserTypeEnum.js +14 -0
  157. package/icc-api/model/UserTypeEnum.js.map +1 -0
  158. package/icc-api/model/internal/ExchangeData.d.ts +20 -4
  159. package/icc-api/model/internal/ExchangeData.js +8 -2
  160. package/icc-api/model/internal/ExchangeData.js.map +1 -1
  161. package/icc-api/model/internal/RecoveryData.d.ts +47 -0
  162. package/icc-api/model/internal/RecoveryData.js +34 -0
  163. package/icc-api/model/internal/RecoveryData.js.map +1 -0
  164. package/icc-api/model/models.d.ts +6 -1
  165. package/icc-api/model/models.js +5 -0
  166. package/icc-api/model/models.js.map +1 -1
  167. package/icc-x-api/auth/JwtBridgedAuthService.d.ts +1 -0
  168. package/icc-x-api/auth/JwtBridgedAuthService.js +10 -3
  169. package/icc-x-api/auth/JwtBridgedAuthService.js.map +1 -1
  170. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +37 -25
  171. package/icc-x-api/crypto/BaseExchangeDataManager.js +123 -64
  172. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  173. package/icc-x-api/crypto/CryptoPrimitives.d.ts +3 -0
  174. package/icc-x-api/crypto/CryptoPrimitives.js +5 -0
  175. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -1
  176. package/icc-x-api/crypto/DelegationsDeAnonymization.js +1 -1
  177. package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -1
  178. package/icc-x-api/crypto/ExchangeDataManager.js +14 -6
  179. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  180. package/icc-x-api/crypto/ExchangeDataMapManager.d.ts +1 -1
  181. package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -1
  182. package/icc-x-api/crypto/HMACUtils.d.ts +10 -0
  183. package/icc-x-api/crypto/HMACUtils.js +48 -0
  184. package/icc-x-api/crypto/HMACUtils.js.map +1 -0
  185. package/icc-x-api/crypto/SecureDelegationsManager.js +3 -0
  186. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  187. package/icc-x-api/crypto/UserSignatureKeysManager.d.ts +1 -1
  188. package/icc-x-api/crypto/UserSignatureKeysManager.js +2 -2
  189. package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -1
  190. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  191. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +1 -1
  192. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  193. package/icc-x-api/icc-maintenance-task-x-api.d.ts +5 -3
  194. package/icc-x-api/icc-maintenance-task-x-api.js +7 -1
  195. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  196. package/icc-x-api/icc-recovery-x-api.d.ts +0 -0
  197. package/icc-x-api/icc-recovery-x-api.js +2 -0
  198. package/icc-x-api/icc-recovery-x-api.js.map +1 -0
  199. package/icc-x-api/index.d.ts +2 -0
  200. package/icc-x-api/index.js +7 -2
  201. package/icc-x-api/index.js.map +1 -1
  202. package/icc-x-api/storage/KeyStorageImpl.d.ts +1 -0
  203. package/icc-x-api/storage/KeyStorageImpl.js +20 -12
  204. package/icc-x-api/storage/KeyStorageImpl.js.map +1 -1
  205. package/package.json +1 -1
  206. package/icc-api/api/IccDocumentTemplateApi.d.ts +0 -106
  207. package/icc-api/api/IccDocumentTemplateApi.js +0 -223
  208. package/icc-api/api/IccDocumentTemplateApi.js.map +0 -1
  209. package/icc-api/api/IccExchangeDataApi.js +0 -85
  210. package/icc-api/api/IccExchangeDataApi.js.map +0 -1
  211. package/icc-api/api/IccExchangeDataMapApi.js +0 -65
  212. package/icc-api/api/IccExchangeDataMapApi.js.map +0 -1
  213. package/icc-api/api/IccSecureDelegationKeyMapApi.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationsDeAnonymization.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/DelegationsDeAnonymization.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2EAAuE;AACvE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AAEzD,gGAA4F;AAE5F,qEAAiE;AACjE,wFAAoF;AACpF,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,uBAAuB,CAAA;AAE3E,oCAAwE;AACxE,iGAA6F;AAC7F,+CAA2C;AAC3C,2EAAiG;AACjG,yFAAiH;AAIjH,6CAA6C;AAC7C,MAAa,0BAA0B;IAIrC,YACmB,YAA8B,EAC9B,kCAA8E,EAC9E,KAAwB,EACxB,gBAAkC,EAClC,wBAAkD,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AAC;KAAA;CACF;AA3QD,gEA2QC","sourcesContent":["import { EncryptedEntityWithType, EntityWithDelegationTypeName } from '../utils/EntityWithDelegationTypeName'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { DelegationMembersDetails, SecureDelegationsSecurityMetadataDecryptor } from './SecureDelegationsSecurityMetadataDecryptor'\nimport { SecureDelegationKeyMap } from '../../icc-api/model/internal/SecureDelegationKeyMap'\nimport { ExtendedApisUtils } from './ExtendedApisUtils'\nimport { ShareMetadataBehaviour } from './ShareMetadataBehaviour'\nimport { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { EncryptedFieldsManifest, parseEncryptedFields } from '../utils'\nimport { IccSecureDelegationKeyMapApi } from '../../icc-api/api/IccSecureDelegationKeyMapApi'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { AuthenticationProvider, NoAuthenticationProvider } from '../auth/AuthenticationProvider'\nimport { ACCESS_CONTROL_KEYS_HEADER, AccessControlKeysHeadersProvider } from './AccessControlKeysHeadersProvider'\nimport { AccessControlSecretUtils } from './AccessControlSecretUtils'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\n\n// TODO could be optimised using bulk methods\nexport class DelegationsDeAnonymization {\n private readonly delegationKeyMapFieldsToEncrypt: EncryptedFieldsManifest\n private readonly delegationKeyMapApi: IccSecureDelegationKeyMapApi\n\n constructor(\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly secureDelegationsMetadataDecryptor: SecureDelegationsSecurityMetadataDecryptor,\n private readonly xapis: ExtendedApisUtils,\n private readonly cryptoPrimitives: CryptoPrimitives,\n private readonly accessControlSecretUtils: AccessControlSecretUtils,\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch,\n private readonly accessControlKeysHeadersProvider: AccessControlKeysHeadersProvider\n ) {\n this.delegationKeyMapFieldsToEncrypt = parseEncryptedFields(['delegate', 'delegator'], 'SecureDelegationKeyMap')\n this.delegationKeyMapApi = new IccSecureDelegationKeyMapApi(host, headers, authenticationProvider, fetchImpl)\n }\n\n /**\n * Creates / updates information to allow the data owners in {@link shareWithDataOwners} to de-anonymize the delegations contained within\n * {@link entity}.\n * Note that the delegation de-anonymization information may be used also with other entities of the same type.\n */\n async createOrUpdateDeAnonymizationInfo(entityWithType: EncryptedEntityWithType, shareWithDataOwners: string[]) {\n const delegationsDetails = Object.entries(await this.secureDelegationsMetadataDecryptor.getDelegationMemberDetails(entityWithType)).flatMap(\n ([canonicalKey, delegation]) => {\n const aliases = Object.entries(entityWithType.entity.securityMetadata?.keysEquivalences ?? {}).flatMap(([alias, canon]) => {\n if (canon == canonicalKey) {\n return [alias]\n } else {\n return []\n }\n })\n return [[canonicalKey, delegation], ...aliases.map((alias) => [alias, delegation])] as [string, DelegationMembersDetails][]\n }\n )\n const delegationsForDeanonInfoSharing = delegationsDetails.filter(([_, delegationInfo]) => {\n // Drop fully explicit ones: they don't need de-anonymization info\n return !delegationInfo.fullyExplicit\n })\n // A subset of delegations for which deanon info is relevant AND for which we can also create new info instead of sharing only existing one.\n const delegationsForNewDeanonInfoCreation = delegationsForDeanonInfoSharing.filter(([_, delegationInfo]) => {\n // Drop those for which we don't have the full information needed for the creation of new data.\n return !!delegationInfo.delegate && !!delegationInfo.delegator && !!delegationInfo.accessControlSecret\n })\n const existingDelegationsMap = await this.getDecryptedSecureDelegationKeyMaps(\n delegationsForDeanonInfoSharing.map((x) => x[0]),\n entityWithType.type\n )\n for (const delMapToShare of existingDelegationsMap) {\n await this.ensureDelegationKeyMapSharedWith(entityWithType.type, delMapToShare, shareWithDataOwners)\n }\n const existingDelegationsMapKeys = new Set(existingDelegationsMap.map((x) => x.delegationKey))\n const delegationsToCreate = delegationsForNewDeanonInfoCreation.filter(([k, _]) => !existingDelegationsMapKeys.has(k))\n for (const [delKey, membersDetails] of delegationsToCreate) {\n await this.createSecureDelegationKeyMap(entityWithType.type, delKey, membersDetails, shareWithDataOwners)\n }\n }\n\n /**\n * Get the data owners which can access the entity. See {@link EncryptedEntityXApi.getDataOwnersWithAccessTo} for more details.\n * @param entityWithType an entity.\n */\n async getDataOwnersWithAccessTo(entityWithType: EncryptedEntityWithType): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n return this.mergePermissions([\n await this.getDataOwnersWithAccessToSecureDelegations(entityWithType),\n {\n permissionsByDataOwnerId: Object.fromEntries(Object.keys(entityWithType.entity.delegations ?? {}).map((k) => [k, AccessLevelEnum.WRITE])),\n hasUnknownAnonymousDataOwners: false,\n },\n ])\n }\n\n private async getDataOwnersWithAccessToSecureDelegations(entityWithType: EncryptedEntityWithType): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n const secureDelegationDetails = await this.secureDelegationsMetadataDecryptor.getDelegationMemberDetails(entityWithType)\n const secureDelegationWithUnknownMembers = Object.entries(secureDelegationDetails).flatMap(([canonicalKey, delegation]) => {\n if (!delegation.delegate || !delegation.delegator) {\n const aliases = Object.entries(entityWithType.entity.securityMetadata?.keysEquivalences ?? {}).flatMap(([alias, canon]) => {\n if (canon == canonicalKey) {\n return [alias]\n } else {\n return []\n }\n })\n return [{ keys: [canonicalKey, ...aliases], delegation }]\n } else {\n return []\n }\n })\n const secureDelegationKeyMapsByDelegationKey = Object.fromEntries(\n (\n await this.getDecryptedSecureDelegationKeyMaps(\n secureDelegationWithUnknownMembers.flatMap(({ keys }) => keys),\n entityWithType.type\n )\n ).map((x) => [x.delegationKey, x])\n )\n const permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum } = {}\n let hasUnknownAnonymousDataOwners = false\n function addAccess(dataOwnerId: string, level: AccessLevelEnum) {\n if (permissionsByDataOwnerId[dataOwnerId] !== AccessLevelEnum.WRITE) {\n permissionsByDataOwnerId[dataOwnerId] = level\n }\n }\n for (const delegation of Object.values(secureDelegationDetails)) {\n if (delegation.delegate) addAccess(delegation.delegate, delegation.accessLevel)\n if (delegation.delegator) addAccess(delegation.delegator, delegation.accessLevel)\n }\n for (const { keys, delegation } of secureDelegationWithUnknownMembers) {\n const bestKey = keys.find((k) => {\n const currMap = secureDelegationKeyMapsByDelegationKey[k]\n return currMap && !!currMap.delegator && !!currMap.delegate\n })\n if (bestKey) {\n const keyMap = secureDelegationKeyMapsByDelegationKey[bestKey]\n addAccess(keyMap.delegate!, delegation.accessLevel)\n addAccess(keyMap.delegator!, delegation.accessLevel)\n } else {\n hasUnknownAnonymousDataOwners = true\n }\n }\n return { permissionsByDataOwnerId, hasUnknownAnonymousDataOwners }\n }\n\n private async mergePermissions(\n values: {\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }[]\n ): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n const accumulatedPermissions: { [dataOwnerId: string]: AccessLevelEnum } = {}\n let hasUnknownAnonymousDataOwners = false\n for (const v of values) {\n hasUnknownAnonymousDataOwners = hasUnknownAnonymousDataOwners || v.hasUnknownAnonymousDataOwners\n for (const [dataOwnerId, level] of Object.entries(v.permissionsByDataOwnerId)) {\n if (accumulatedPermissions[dataOwnerId] !== AccessLevelEnum.WRITE) {\n accumulatedPermissions[dataOwnerId] = level\n }\n }\n }\n return {\n permissionsByDataOwnerId: accumulatedPermissions,\n hasUnknownAnonymousDataOwners,\n }\n }\n\n private async getDecryptedSecureDelegationKeyMaps(\n delegationIds: string[],\n entityType: EntityWithDelegationTypeName\n ): Promise<SecureDelegationKeyMap[]> {\n if (delegationIds.length) {\n const encryptedMaps = await this.delegationKeyMapApi.getByDelegationKeys(\n { ids: delegationIds },\n await this.accessControlKeysHeadersProvider.getAccessControlKeysHeaders(entityType)\n )\n const res: SecureDelegationKeyMap[] = []\n for (const encryptedMap of encryptedMaps) {\n // Use the original entity type\n const decryptionResult = await this.xapis.decryptEntity(encryptedMap, entityType, (x) => new SecureDelegationKeyMap(x))\n if (decryptionResult.decrypted) {\n res.push(decryptionResult.entity)\n }\n }\n return res\n } else return []\n }\n\n // Important: to avoid potentially leaking links between entities of different types the key map calculates the secure delegation keys using the\n // same entity type as the delegation key for which they are mapping information.\n private async ensureDelegationKeyMapSharedWith(entityType: EntityWithDelegationTypeName, keyMap: SecureDelegationKeyMap, delegates: string[]) {\n if (!keyMap.delegator || !keyMap.delegate) throw new Error('Illegal state: key map is missing delegator or delegate info.')\n const dataOwnersWithAccessToMapThroughDelegation = Object.values(\n await this.secureDelegationsMetadataDecryptor.getDelegationMemberDetails({\n type: entityType,\n entity: keyMap,\n })\n )\n .flatMap((x) => [x.delegate, x.delegator])\n .filter((x) => !!x) as string[]\n // Delegator and delegate got access to the entity when it was first created: no need to share with them ever.\n const dataOwnersWithAccessToMap = new Set([keyMap.delegate, keyMap.delegator, ...dataOwnersWithAccessToMapThroughDelegation])\n const dataOwnersNeedingShare = delegates.filter((x) => !dataOwnersWithAccessToMap.has(x))\n if (dataOwnersNeedingShare.length) {\n ;(\n await this.xapis.simpleShareOrUpdateEncryptedEntityMetadata(\n { entity: keyMap, type: entityType },\n false,\n Object.fromEntries(\n dataOwnersNeedingShare.map((x) => [\n x,\n {\n shareSecretIds: [],\n shareEncryptionKeys: ShareMetadataBehaviour.REQUIRED,\n shareOwningEntityIds: ShareMetadataBehaviour.NEVER,\n requestedPermissions: RequestedPermissionEnum.FULL_READ,\n },\n ])\n ),\n async (request) =>\n this.delegationKeyMapApi.bulkShareSecureDelegationKeyMap(\n request,\n await this.accessControlKeysHeadersProvider.getAccessControlKeysHeaders(entityType)\n )\n )\n ).updatedEntityOrThrow\n }\n }\n\n // Important: to avoid potentially leaking links between entities of different types the key map calculates the secure delegation keys using the\n // same entity type as the delegation key for which they are mapping information.\n private async createSecureDelegationKeyMap(\n entityType: EntityWithDelegationTypeName,\n delegationKey: string,\n delegationMembersDetails: DelegationMembersDetails,\n delegates: string[]\n ) {\n if (!delegationMembersDetails.delegate || !delegationMembersDetails.delegator || !delegationMembersDetails.accessControlSecret)\n throw new Error('Illegal state: delegation members details are missing delegate, delegator or access control secret info.')\n const selfDoId = await this.dataOwnerApi.getCurrentDataOwnerId()\n // Ensure that both the delegator and delegate of the delegation this map refers tho can share it later on, even if they did not create it.\n // Usually either the delegator or delegate are the current data owner, but sometimes also the child of the delegator or delegate can do it.\n const initialDelegates = [delegationMembersDetails.delegate, delegationMembersDetails.delegator, ...delegates].filter((x) => x != selfDoId)\n const initalisedMapInfo = await this.xapis.entityWithInitialisedEncryptedMetadata<SecureDelegationKeyMap>(\n {\n id: this.cryptoPrimitives.crypto.randomUUID(),\n delegate: delegationMembersDetails.delegate,\n delegator: delegationMembersDetails.delegator,\n delegationKey: delegationKey,\n },\n entityType,\n undefined,\n undefined,\n true,\n false,\n Object.fromEntries(initialDelegates.map((x) => [x, AccessLevelEnum.READ]))\n )\n const encryptedKeyMap = await this.xapis.tryEncryptEntity(\n initalisedMapInfo.updatedEntity,\n entityType,\n this.delegationKeyMapFieldsToEncrypt,\n false,\n true,\n (x) => new SecureDelegationKeyMap(x)\n )\n await this.delegationKeyMapApi.create(\n encryptedKeyMap,\n new XHR.Header(\n ACCESS_CONTROL_KEYS_HEADER,\n await this.accessControlSecretUtils.getEncodedAccessControlKeys([delegationMembersDetails.accessControlSecret], entityType)\n )\n )\n }\n}\n"]}
1
+ {"version":3,"file":"DelegationsDeAnonymization.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/DelegationsDeAnonymization.ts"],"names":[],"mappings":";;;;;;;;;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,EACV,IAAI,CAAC,+BAA+B,EACpC,KAAK,EACL,IAAI,EACJ,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,+CAAsB,CAAC,CAAC,CAAC,CACrC,CAAA;YACD,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CACnC,eAAe,EACf,IAAI,SAAG,CAAC,MAAM,CACZ,6DAA0B,EAC1B,MAAM,IAAI,CAAC,wBAAwB,CAAC,2BAA2B,CAAC,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,EAAE,UAAU,CAAC,CAC5H,CACF,CAAA;QACH,CAAC;KAAA;CACF;AA3QD,gEA2QC","sourcesContent":["import { EncryptedEntityWithType, EntityWithDelegationTypeName } from '../utils/EntityWithDelegationTypeName'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { DelegationMembersDetails, SecureDelegationsSecurityMetadataDecryptor } from './SecureDelegationsSecurityMetadataDecryptor'\nimport { SecureDelegationKeyMap } from '../../icc-api/model/internal/SecureDelegationKeyMap'\nimport { ExtendedApisUtils } from './ExtendedApisUtils'\nimport { ShareMetadataBehaviour } from './ShareMetadataBehaviour'\nimport { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { EncryptedFieldsManifest, parseEncryptedFields } from '../utils'\nimport { IccSecureDelegationKeyMapApi } from '../../icc-api/api/internal/IccSecureDelegationKeyMapApi'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { AuthenticationProvider, NoAuthenticationProvider } from '../auth/AuthenticationProvider'\nimport { ACCESS_CONTROL_KEYS_HEADER, AccessControlKeysHeadersProvider } from './AccessControlKeysHeadersProvider'\nimport { AccessControlSecretUtils } from './AccessControlSecretUtils'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\n\n// TODO could be optimised using bulk methods\nexport class DelegationsDeAnonymization {\n private readonly delegationKeyMapFieldsToEncrypt: EncryptedFieldsManifest\n private readonly delegationKeyMapApi: IccSecureDelegationKeyMapApi\n\n constructor(\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly secureDelegationsMetadataDecryptor: SecureDelegationsSecurityMetadataDecryptor,\n private readonly xapis: ExtendedApisUtils,\n private readonly cryptoPrimitives: CryptoPrimitives,\n private readonly accessControlSecretUtils: AccessControlSecretUtils,\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch,\n private readonly accessControlKeysHeadersProvider: AccessControlKeysHeadersProvider\n ) {\n this.delegationKeyMapFieldsToEncrypt = parseEncryptedFields(['delegate', 'delegator'], 'SecureDelegationKeyMap')\n this.delegationKeyMapApi = new IccSecureDelegationKeyMapApi(host, headers, authenticationProvider, fetchImpl)\n }\n\n /**\n * Creates / updates information to allow the data owners in {@link shareWithDataOwners} to de-anonymize the delegations contained within\n * {@link entity}.\n * Note that the delegation de-anonymization information may be used also with other entities of the same type.\n */\n async createOrUpdateDeAnonymizationInfo(entityWithType: EncryptedEntityWithType, shareWithDataOwners: string[]) {\n const delegationsDetails = Object.entries(await this.secureDelegationsMetadataDecryptor.getDelegationMemberDetails(entityWithType)).flatMap(\n ([canonicalKey, delegation]) => {\n const aliases = Object.entries(entityWithType.entity.securityMetadata?.keysEquivalences ?? {}).flatMap(([alias, canon]) => {\n if (canon == canonicalKey) {\n return [alias]\n } else {\n return []\n }\n })\n return [[canonicalKey, delegation], ...aliases.map((alias) => [alias, delegation])] as [string, DelegationMembersDetails][]\n }\n )\n const delegationsForDeanonInfoSharing = delegationsDetails.filter(([_, delegationInfo]) => {\n // Drop fully explicit ones: they don't need de-anonymization info\n return !delegationInfo.fullyExplicit\n })\n // A subset of delegations for which deanon info is relevant AND for which we can also create new info instead of sharing only existing one.\n const delegationsForNewDeanonInfoCreation = delegationsForDeanonInfoSharing.filter(([_, delegationInfo]) => {\n // Drop those for which we don't have the full information needed for the creation of new data.\n return !!delegationInfo.delegate && !!delegationInfo.delegator && !!delegationInfo.accessControlSecret\n })\n const existingDelegationsMap = await this.getDecryptedSecureDelegationKeyMaps(\n delegationsForDeanonInfoSharing.map((x) => x[0]),\n entityWithType.type\n )\n for (const delMapToShare of existingDelegationsMap) {\n await this.ensureDelegationKeyMapSharedWith(entityWithType.type, delMapToShare, shareWithDataOwners)\n }\n const existingDelegationsMapKeys = new Set(existingDelegationsMap.map((x) => x.delegationKey))\n const delegationsToCreate = delegationsForNewDeanonInfoCreation.filter(([k, _]) => !existingDelegationsMapKeys.has(k))\n for (const [delKey, membersDetails] of delegationsToCreate) {\n await this.createSecureDelegationKeyMap(entityWithType.type, delKey, membersDetails, shareWithDataOwners)\n }\n }\n\n /**\n * Get the data owners which can access the entity. See {@link EncryptedEntityXApi.getDataOwnersWithAccessTo} for more details.\n * @param entityWithType an entity.\n */\n async getDataOwnersWithAccessTo(entityWithType: EncryptedEntityWithType): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n return this.mergePermissions([\n await this.getDataOwnersWithAccessToSecureDelegations(entityWithType),\n {\n permissionsByDataOwnerId: Object.fromEntries(Object.keys(entityWithType.entity.delegations ?? {}).map((k) => [k, AccessLevelEnum.WRITE])),\n hasUnknownAnonymousDataOwners: false,\n },\n ])\n }\n\n private async getDataOwnersWithAccessToSecureDelegations(entityWithType: EncryptedEntityWithType): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n const secureDelegationDetails = await this.secureDelegationsMetadataDecryptor.getDelegationMemberDetails(entityWithType)\n const secureDelegationWithUnknownMembers = Object.entries(secureDelegationDetails).flatMap(([canonicalKey, delegation]) => {\n if (!delegation.delegate || !delegation.delegator) {\n const aliases = Object.entries(entityWithType.entity.securityMetadata?.keysEquivalences ?? {}).flatMap(([alias, canon]) => {\n if (canon == canonicalKey) {\n return [alias]\n } else {\n return []\n }\n })\n return [{ keys: [canonicalKey, ...aliases], delegation }]\n } else {\n return []\n }\n })\n const secureDelegationKeyMapsByDelegationKey = Object.fromEntries(\n (\n await this.getDecryptedSecureDelegationKeyMaps(\n secureDelegationWithUnknownMembers.flatMap(({ keys }) => keys),\n entityWithType.type\n )\n ).map((x) => [x.delegationKey, x])\n )\n const permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum } = {}\n let hasUnknownAnonymousDataOwners = false\n function addAccess(dataOwnerId: string, level: AccessLevelEnum) {\n if (permissionsByDataOwnerId[dataOwnerId] !== AccessLevelEnum.WRITE) {\n permissionsByDataOwnerId[dataOwnerId] = level\n }\n }\n for (const delegation of Object.values(secureDelegationDetails)) {\n if (delegation.delegate) addAccess(delegation.delegate, delegation.accessLevel)\n if (delegation.delegator) addAccess(delegation.delegator, delegation.accessLevel)\n }\n for (const { keys, delegation } of secureDelegationWithUnknownMembers) {\n const bestKey = keys.find((k) => {\n const currMap = secureDelegationKeyMapsByDelegationKey[k]\n return currMap && !!currMap.delegator && !!currMap.delegate\n })\n if (bestKey) {\n const keyMap = secureDelegationKeyMapsByDelegationKey[bestKey]\n addAccess(keyMap.delegate!, delegation.accessLevel)\n addAccess(keyMap.delegator!, delegation.accessLevel)\n } else {\n hasUnknownAnonymousDataOwners = true\n }\n }\n return { permissionsByDataOwnerId, hasUnknownAnonymousDataOwners }\n }\n\n private async mergePermissions(\n values: {\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }[]\n ): Promise<{\n permissionsByDataOwnerId: { [dataOwnerId: string]: AccessLevelEnum }\n hasUnknownAnonymousDataOwners: boolean\n }> {\n const accumulatedPermissions: { [dataOwnerId: string]: AccessLevelEnum } = {}\n let hasUnknownAnonymousDataOwners = false\n for (const v of values) {\n hasUnknownAnonymousDataOwners = hasUnknownAnonymousDataOwners || v.hasUnknownAnonymousDataOwners\n for (const [dataOwnerId, level] of Object.entries(v.permissionsByDataOwnerId)) {\n if (accumulatedPermissions[dataOwnerId] !== AccessLevelEnum.WRITE) {\n accumulatedPermissions[dataOwnerId] = level\n }\n }\n }\n return {\n permissionsByDataOwnerId: accumulatedPermissions,\n hasUnknownAnonymousDataOwners,\n }\n }\n\n private async getDecryptedSecureDelegationKeyMaps(\n delegationIds: string[],\n entityType: EntityWithDelegationTypeName\n ): Promise<SecureDelegationKeyMap[]> {\n if (delegationIds.length) {\n const encryptedMaps = await this.delegationKeyMapApi.getByDelegationKeys(\n { ids: delegationIds },\n await this.accessControlKeysHeadersProvider.getAccessControlKeysHeaders(entityType)\n )\n const res: SecureDelegationKeyMap[] = []\n for (const encryptedMap of encryptedMaps) {\n // Use the original entity type\n const decryptionResult = await this.xapis.decryptEntity(encryptedMap, entityType, (x) => new SecureDelegationKeyMap(x))\n if (decryptionResult.decrypted) {\n res.push(decryptionResult.entity)\n }\n }\n return res\n } else return []\n }\n\n // Important: to avoid potentially leaking links between entities of different types the key map calculates the secure delegation keys using the\n // same entity type as the delegation key for which they are mapping information.\n private async ensureDelegationKeyMapSharedWith(entityType: EntityWithDelegationTypeName, keyMap: SecureDelegationKeyMap, delegates: string[]) {\n if (!keyMap.delegator || !keyMap.delegate) throw new Error('Illegal state: key map is missing delegator or delegate info.')\n const dataOwnersWithAccessToMapThroughDelegation = Object.values(\n await this.secureDelegationsMetadataDecryptor.getDelegationMemberDetails({\n type: entityType,\n entity: keyMap,\n })\n )\n .flatMap((x) => [x.delegate, x.delegator])\n .filter((x) => !!x) as string[]\n // Delegator and delegate got access to the entity when it was first created: no need to share with them ever.\n const dataOwnersWithAccessToMap = new Set([keyMap.delegate, keyMap.delegator, ...dataOwnersWithAccessToMapThroughDelegation])\n const dataOwnersNeedingShare = delegates.filter((x) => !dataOwnersWithAccessToMap.has(x))\n if (dataOwnersNeedingShare.length) {\n ;(\n await this.xapis.simpleShareOrUpdateEncryptedEntityMetadata(\n { entity: keyMap, type: entityType },\n false,\n Object.fromEntries(\n dataOwnersNeedingShare.map((x) => [\n x,\n {\n shareSecretIds: [],\n shareEncryptionKeys: ShareMetadataBehaviour.REQUIRED,\n shareOwningEntityIds: ShareMetadataBehaviour.NEVER,\n requestedPermissions: RequestedPermissionEnum.FULL_READ,\n },\n ])\n ),\n async (request) =>\n this.delegationKeyMapApi.bulkShareSecureDelegationKeyMap(\n request,\n await this.accessControlKeysHeadersProvider.getAccessControlKeysHeaders(entityType)\n )\n )\n ).updatedEntityOrThrow\n }\n }\n\n // Important: to avoid potentially leaking links between entities of different types the key map calculates the secure delegation keys using the\n // same entity type as the delegation key for which they are mapping information.\n private async createSecureDelegationKeyMap(\n entityType: EntityWithDelegationTypeName,\n delegationKey: string,\n delegationMembersDetails: DelegationMembersDetails,\n delegates: string[]\n ) {\n if (!delegationMembersDetails.delegate || !delegationMembersDetails.delegator || !delegationMembersDetails.accessControlSecret)\n throw new Error('Illegal state: delegation members details are missing delegate, delegator or access control secret info.')\n const selfDoId = await this.dataOwnerApi.getCurrentDataOwnerId()\n // Ensure that both the delegator and delegate of the delegation this map refers tho can share it later on, even if they did not create it.\n // Usually either the delegator or delegate are the current data owner, but sometimes also the child of the delegator or delegate can do it.\n const initialDelegates = [delegationMembersDetails.delegate, delegationMembersDetails.delegator, ...delegates].filter((x) => x != selfDoId)\n const initalisedMapInfo = await this.xapis.entityWithInitialisedEncryptedMetadata<SecureDelegationKeyMap>(\n {\n id: this.cryptoPrimitives.crypto.randomUUID(),\n delegate: delegationMembersDetails.delegate,\n delegator: delegationMembersDetails.delegator,\n delegationKey: delegationKey,\n },\n entityType,\n undefined,\n undefined,\n true,\n false,\n Object.fromEntries(initialDelegates.map((x) => [x, AccessLevelEnum.READ]))\n )\n const encryptedKeyMap = await this.xapis.tryEncryptEntity(\n initalisedMapInfo.updatedEntity,\n entityType,\n this.delegationKeyMapFieldsToEncrypt,\n false,\n true,\n (x) => new SecureDelegationKeyMap(x)\n )\n await this.delegationKeyMapApi.create(\n encryptedKeyMap,\n new XHR.Header(\n ACCESS_CONTROL_KEYS_HEADER,\n await this.accessControlSecretUtils.getEncodedAccessControlKeys([delegationMembersDetails.accessControlSecret], entityType)\n )\n )\n }\n}\n"]}
@@ -47,16 +47,24 @@ class AbstractExchangeDataManager {
47
47
  decryptData(data) {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
49
  const decryptionKeys = this.encryptionKeys.getDecryptionKeys();
50
- const decryptedKey = (yield this.base.tryDecryptExchangeKeys([data], decryptionKeys)).successfulDecryptions[0];
51
- if (!decryptedKey)
50
+ const decryptedExchangeKey = (yield this.base.tryDecryptExchangeKeys([data], decryptionKeys)).successfulDecryptions[0];
51
+ if (!decryptedExchangeKey)
52
52
  return undefined;
53
53
  const decryptedAccessControlSecret = (yield this.base.tryDecryptAccessControlSecret([data], decryptionKeys)).successfulDecryptions[0];
54
54
  if (!decryptedAccessControlSecret)
55
- throw new Error(`Decryption key could be decrypted but access control secret could not for data ${data}`);
55
+ throw new Error(`Decryption key could be decrypted but access control secret could not for data ${JSON.stringify(data)}`);
56
+ const decryptedSharedSignatureKey = (yield this.base.tryDecryptSharedSignatureKeys([data], decryptionKeys)).successfulDecryptions[0];
57
+ if (!decryptedSharedSignatureKey)
58
+ throw new Error(`Decryption key could be decrypted but shared signature key could not for data ${JSON.stringify(data)}`);
56
59
  return {
57
60
  accessControlSecret: decryptedAccessControlSecret,
58
- exchangeKey: decryptedKey,
59
- verified: yield this.base.verifyExchangeData(data, (fp) => this.signatureKeys.getSignatureVerificationKey(fp)),
61
+ exchangeKey: decryptedExchangeKey,
62
+ verified: yield this.base.verifyExchangeData({
63
+ exchangeData: data,
64
+ decryptedAccessControlSecret,
65
+ decryptedExchangeKey,
66
+ decryptedSharedSignatureKey,
67
+ }, (fp) => this.signatureKeys.getSignatureVerificationKey(fp), true),
60
68
  };
61
69
  });
62
70
  }
@@ -118,7 +126,7 @@ class AbstractExchangeDataManager {
118
126
  ];
119
127
  for (const dataToUpdate of allExchangeDataToUpdate) {
120
128
  if (!Object.keys(dataToUpdate.exchangeKey).find((fp) => fp == newKeyFp)) {
121
- const updated = yield this.base.tryUpdateExchangeData(dataToUpdate, decryptionKeys, { [newKeyFp]: importedNewKey }, { [signatureKey.fingerprint]: signatureKey.keyPair.privateKey }, (verificationFp) => this.signatureKeys.getSignatureVerificationKey(verificationFp));
129
+ const updated = yield this.base.tryUpdateExchangeData(dataToUpdate, decryptionKeys, { [newKeyFp]: importedNewKey });
122
130
  if (!updated) {
123
131
  console.warn(`Failed to give access back to exchanged data ${JSON.stringify(dataToUpdate)}`);
124
132
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ExchangeDataManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,mCAAgH;AAEhH,oCAAyC;AACzC,oFAA6E;AAC7E,wFAAmH;AACnH,yEAA6E;AAO7E;;;GAGG;AACH,SAAsB,gDAAgD,CACpE,IAA6B,EAC7B,cAAyC,EACzC,aAAuC,EACvC,mBAA6C,EAC7C,gBAAkC,EAClC,YAA8B,EAC9B,UAA4B,EAC5B,aAAsB,EACtB,qBAA4D,EAAE;;QAE9D,MAAM,YAAY,GAAG,yCAAuB,CAAC,aAAa,CAAC,MAAM,YAAY,CAAC,mBAAmB,EAAE,CAAC,CAAA;QACpG,IAAI,gBAAgB,CAAC,oCAAoC,CAAC,YAAY,CAAC,EAAE;YACvE,MAAM,GAAG,GAAG,IAAI,8BAA8B,CAC5C,IAAI,EACJ,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,aAAa,CACd,CAAA;YACD,MAAM,GAAG,CAAC,sBAAsB,EAAE,CAAA;YAClC,OAAO,GAAG,CAAA;SACX;a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CAAC,aAAsB,EAAE,IAA+C;;YACnG,IAAI,CAAC,aAAa,EAAE;gBAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;gBACzD,IAAI,IAAI,CAAC,kCAAkC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE;oBACpG,IAAI,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;iBAC3E;aACF;QACH,CAAC;KAAA;IAED,yBAAyB,CAAC,UAAwC;QAChE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;IAED,oBAAoB,CAAC,UAAwC;QAC3D,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import { ExchangeData } from '../../icc-api/model/internal/ExchangeData'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { BaseExchangeDataManager } from './BaseExchangeDataManager'\nimport { UserEncryptionKeysManager } from './UserEncryptionKeysManager'\nimport { UserSignatureKeysManager } from './UserSignatureKeysManager'\nimport { AccessControlSecretUtils } from './AccessControlSecretUtils'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { fingerprintV1, getShaVersionForKey, hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from './utils'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { hex2ua, ua2b64 } from '../utils'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { EntityWithDelegationTypeName, entityWithDelegationTypeNames } from '../utils/EntityWithDelegationTypeName'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\n\nexport type ExchangeDataManagerOptionalParameters = {\n // Only for not fully cached implementation (data owner can't request all his exchange data), amount of exchange data which can be cached\n lruCacheSize?: number // default = 2000\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice.\n * Initialises and returns the exchange data manager which is most appropriate for the current data owner.\n */\nexport async function initialiseExchangeDataManagerForCurrentDataOwner(\n base: BaseExchangeDataManager,\n encryptionKeys: UserEncryptionKeysManager,\n signatureKeys: UserSignatureKeysManager,\n accessControlSecret: AccessControlSecretUtils,\n cryptoStrategies: CryptoStrategies,\n dataOwnerApi: IccDataOwnerXApi,\n primitives: CryptoPrimitives,\n useParentKeys: boolean,\n optionalParameters: ExchangeDataManagerOptionalParameters = {}\n): Promise<ExchangeDataManager> {\n const currentOwner = CryptoActorStubWithType.fromDataOwner(await dataOwnerApi.getCurrentDataOwner())\n if (cryptoStrategies.dataOwnerRequiresAnonymousDelegation(currentOwner)) {\n const res = new FullyCachedExchangeDataManager(\n base,\n encryptionKeys,\n signatureKeys,\n accessControlSecret,\n cryptoStrategies,\n dataOwnerApi,\n primitives,\n useParentKeys\n )\n await res.clearOrRepopulateCache()\n return res\n } else {\n return new LimitedLruCacheExchangeDataManager(\n base,\n encryptionKeys,\n signatureKeys,\n accessControlSecret,\n cryptoStrategies,\n dataOwnerApi,\n primitives,\n useParentKeys,\n optionalParameters\n )\n }\n}\n\ntype CachedExchangeData = {\n exchangeData: ExchangeData\n decrypted?: {\n accessControlSecret: string\n exchangeKey: CryptoKey\n verified: boolean\n }\n}\n\n/**\n * @internal this class is intended for internal use only and may be changed without notice.\n * Exchange data manager which automatically handles decryption and cache\n */\nexport interface ExchangeDataManager {\n readonly base: BaseExchangeDataManager\n\n /**\n * Updates all exchange data between the current data owner and another data owner to allow the other data owner to access existing exchange data\n * using a new public key. Note that this will make existing exchange keys from the other data owner to the current data owner unverified, therefore\n * invalid for encryption.\n * @param otherDataOwner the other data owner.\n * @param newDataOwnerPublicKey a new public key of the other data owner.\n */\n giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string): Promise<void>\n\n /**\n * Gets any existing and verified exchange data from the current data owner to the provided delegate or creates new data if no verified data is\n * available, then caches it. The {@link entityType} and {@link entitySecretForeignKeys} will be used for the secure-delegation-hash-based cache\n * of the exchange data and not for actually creating the exchange data.\n * @param delegateId the id of the delegate.\n * @param entityType type of the entity for which you want to create new metadata.\n * @param entitySecretForeignKeys the secret foreign keys of the entity which you want to create new metadata.\n * @return the access control secret and key of the data to use for encryption.\n */\n getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }>\n\n /**\n * Retrieve the cached decrypted exchange data key associated with any of the provided hashes/entry keys of secure delegations. Depending on the\n * implementation the {@link entityType} and {@link entitySecretForeignKeys} may be used to improve the secure-delegation-hash-based cache of\n * exchange data from the other available exchange data caches.\n * @param hashes hashes of access control secrets for a specific entity, as they appear in the key of secure delegation entries\n * @param entityType type of the entity containing the metadata for which you are retrieving the encryption key.\n * @param entitySecretForeignKeys the secret foreign keys of the entity containing the metadata for which you are retrieving the encryption key.\n * @return the exchange data and decrypted key associated to that hash if cached\n */\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [hash: string]: { exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey } }>\n\n /**\n * Retrieves the exchange data with the provided id (from the cache if available or from the server otherwise if allowed by\n * {@link retrieveIfNotCached}) and attempts to decrypt it, then caches the result. The {@link entityType} and {@link entitySecretForeignKeys} will\n * be used for the secure-delegation-hash-based cache of the exchange data.\n * @param id id of the exchange data\n * @param entityType type of the entity containing the metadata for which you are retrieving the encryption key.\n * @param entitySecretForeignKeys the secret foreign keys of the entity containing the metadata for which you are retrieving the encryption key.\n * @param retrieveIfNotCached if false and there is no cached exchange data with the provided id the method returns undefined, else the method will\n * attempt to load the exchange data from the server.\n * @return undefined if the exchange data is not cached and {@link retrieveIfNotCached} is false. Else an object containing:\n * - exchangeData: the exchange data with the provided id\n * - exchangeKey: the exchange key corresponding to the provided exchange data if it could be decrypted, else undefined\n * @throws if no exchange data with the given id is cached and {@link retrieveIfNotCached} is true and the data could not be found in the server\n * either.\n */\n getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; exchangeData: ExchangeData } | undefined>\n\n /**\n * Clears the cache or fully repopulates the cache if the current data owner can retrieve all of his exchange data according to the crypto\n * strategies.\n */\n clearOrRepopulateCache(): Promise<void>\n\n /**\n * If the current data owner requires anonymous delegations this returns the base64 representation of the concatenation of all available access\n * control keys for the current data owner.\n */\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined>\n\n /**\n * If the current data owner requires anonymous delegations this returns the access control keys which may be used in secure delegations for the\n * data owner, which can be used to search for data.\n */\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined>\n}\n\nabstract class AbstractExchangeDataManager implements ExchangeDataManager {\n constructor(\n readonly base: BaseExchangeDataManager,\n protected readonly encryptionKeys: UserEncryptionKeysManager,\n protected readonly signatureKeys: UserSignatureKeysManager,\n protected readonly accessControlSecret: AccessControlSecretUtils,\n protected readonly cryptoStrategies: CryptoStrategies,\n protected readonly dataOwnerApi: IccDataOwnerXApi,\n protected readonly primitives: CryptoPrimitives,\n private readonly useParentKeys: boolean\n ) {}\n\n protected async decryptData(data: ExchangeData): Promise<\n | {\n accessControlSecret: string\n exchangeKey: CryptoKey\n verified: boolean\n }\n | undefined\n > {\n const decryptionKeys = this.encryptionKeys.getDecryptionKeys()\n const decryptedKey = (await this.base.tryDecryptExchangeKeys([data], decryptionKeys)).successfulDecryptions[0]\n if (!decryptedKey) return undefined\n const decryptedAccessControlSecret = (await this.base.tryDecryptAccessControlSecret([data], decryptionKeys)).successfulDecryptions[0]\n if (!decryptedAccessControlSecret) throw new Error(`Decryption key could be decrypted but access control secret could not for data ${data}`)\n return {\n accessControlSecret: decryptedAccessControlSecret,\n exchangeKey: decryptedKey,\n verified: await this.base.verifyExchangeData(data, (fp) => this.signatureKeys.getSignatureVerificationKey(fp)),\n }\n }\n\n protected async createNewExchangeData(\n delegateId: string,\n newDataId?: string\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n const encryptionKeys: { [fp: string]: CryptoKey } = {}\n this.encryptionKeys.getSelfVerifiedKeys().forEach(({ fingerprint, pair }) => {\n encryptionKeys[fingerprint] = pair.publicKey\n })\n if (delegateId != (await this.dataOwnerApi.getCurrentDataOwnerId())) {\n const delegate = await this.dataOwnerApi.getCryptoActorStub(delegateId)\n const sha256KeysOfDelegate = hexPublicKeysWithSha256Of(delegate.stub)\n const sha1KeysOfDelegate = hexPublicKeysWithSha1Of(delegate.stub)\n let allVerifiedDelegateKeys: string[]\n if (this.useParentKeys && (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()).includes(delegateId)) {\n allVerifiedDelegateKeys = await this.encryptionKeys.getVerifiedPublicKeysFor(delegate.stub)\n } else {\n allVerifiedDelegateKeys = await this.cryptoStrategies.verifyDelegatePublicKeys(\n delegate,\n [...Array.from(sha256KeysOfDelegate), ...Array.from(sha1KeysOfDelegate)],\n this.primitives\n )\n }\n if (!allVerifiedDelegateKeys.length)\n throw new Error(`Could not create exchange data to ${delegateId} as no public key for the delegate could be verified.`)\n for (const delegateKey of allVerifiedDelegateKeys) {\n if (sha1KeysOfDelegate.has(delegateKey)) {\n encryptionKeys[fingerprintV1(delegateKey)] = await this.primitives.RSA.importKey('spki', hex2ua(delegateKey), ['encrypt'], 'sha-1')\n } else if (sha256KeysOfDelegate.has(delegateKey)) {\n encryptionKeys[fingerprintV1(delegateKey)] = await this.primitives.RSA.importKey('spki', hex2ua(delegateKey), ['encrypt'], 'sha-256')\n } else throw new Error('Illegal state: verified keys should contain only keys for OAPE-SHA1 or OAPE-SHA256.')\n }\n }\n const signatureKey = await this.signatureKeys.getOrCreateSignatureKeyPair()\n const newData = await this.base.createExchangeData(\n delegateId,\n { [signatureKey.fingerprint]: signatureKey.keyPair.privateKey },\n encryptionKeys,\n newDataId ? { id: newDataId } : {}\n )\n return {\n exchangeData: newData.exchangeData,\n accessControlSecret: newData.accessControlSecret,\n exchangeKey: newData.exchangeKey,\n }\n }\n\n async giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string) {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const newKeyFp = fingerprintV1(newDataOwnerPublicKey)\n const other = await this.dataOwnerApi.getCryptoActorStub(otherDataOwner)\n const newKeyHashVersion = getShaVersionForKey(other.stub, newDataOwnerPublicKey)\n if (!newKeyHashVersion) throw new Error(`Public key not found for data owner ${otherDataOwner}`)\n const importedNewKey = await this.primitives.RSA.importKey('spki', hex2ua(newDataOwnerPublicKey), ['encrypt'], newKeyHashVersion)\n const signatureKey = await this.signatureKeys.getOrCreateSignatureKeyPair()\n const decryptionKeys = this.encryptionKeys.getDecryptionKeys()\n const allExchangeDataToUpdate =\n self == otherDataOwner\n ? await this.base.getExchangeDataByDelegatorDelegatePair(self, self)\n : [\n ...(await this.base.getExchangeDataByDelegatorDelegatePair(self, otherDataOwner)),\n ...(await this.base.getExchangeDataByDelegatorDelegatePair(otherDataOwner, self)),\n ]\n for (const dataToUpdate of allExchangeDataToUpdate) {\n if (!Object.keys(dataToUpdate.exchangeKey).find((fp) => fp == newKeyFp)) {\n const updated = await this.base.tryUpdateExchangeData(\n dataToUpdate,\n decryptionKeys,\n { [newKeyFp]: importedNewKey },\n { [signatureKey.fingerprint]: signatureKey.keyPair.privateKey },\n (verificationFp) => this.signatureKeys.getSignatureVerificationKey(verificationFp)\n )\n if (!updated) {\n console.warn(`Failed to give access back to exchanged data ${JSON.stringify(dataToUpdate)}`)\n }\n }\n }\n }\n\n clearOrRepopulateCache(): Promise<void> {\n throw new Error('Implemented by concrete class')\n }\n\n getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n throw new Error('Implemented by concrete class')\n }\n\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n throw new Error('Implemented by concrete class')\n }\n\n getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined } | undefined> {\n throw new Error('Implemented by concrete class')\n }\n\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n throw new Error('Implemented by concrete class')\n }\n\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n throw new Error('Implemented by concrete class')\n }\n}\n\nclass FullyCachedExchangeDataManager extends AbstractExchangeDataManager {\n private caches: Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: Map<string, string>\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string }\n }> = Promise.resolve({ dataById: {}, hashToId: new Map(), delegateToVerifiedEncryptionDataId: {}, entityTypeToAccessControlKeysValue: {} })\n\n async clearOrRepopulateCache(): Promise<void> {\n this.caches = this.doRepopulateCache()\n await this.caches\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n function retrieveByHashesFromCaches(caches: {\n dataById: { [id: string]: CachedExchangeData }\n hashToId: Map<string, string>\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n }): { [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } } {\n return hashes.reduce((res, hash) => {\n const id = caches.hashToId.get(hash)\n if (id) {\n const cached = caches.dataById[id]\n if (cached?.decrypted) {\n res[hash] = {\n exchangeData: cached.exchangeData,\n exchangeKey: cached.decrypted.exchangeKey,\n accessControlSecret: cached.decrypted.accessControlSecret,\n }\n }\n }\n return res\n }, {} as { [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } })\n }\n\n const retrievedFromHashesCache = retrieveByHashesFromCaches(await this.caches)\n if (Object.keys(retrievedFromHashesCache).length) {\n return retrievedFromHashesCache\n } else {\n this.caches = this.caches.then(async (caches) => {\n for (const currData of Object.values(caches.dataById)) {\n if (currData.decrypted) {\n const currDataHashes = await this.accessControlSecret.secureDelegationKeysFor(\n currData.decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n currDataHashes.forEach((hash) => caches.hashToId.set(hash, currData.exchangeData.id!))\n }\n }\n return caches\n })\n return retrieveByHashesFromCaches(await this.caches)\n }\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n const caches = await this.caches\n const dataId = caches.delegateToVerifiedEncryptionDataId[delegateId]\n const cached = dataId ? caches.dataById[dataId] : undefined\n if (cached && cached?.decrypted) {\n return {\n exchangeData: cached.exchangeData,\n accessControlSecret: cached.decrypted.accessControlSecret,\n exchangeKey: cached.decrypted.exchangeKey,\n }\n }\n const created = await this.createNewExchangeData(delegateId)\n this.cacheData(\n created.exchangeData,\n { accessControlSecret: created.accessControlSecret, exchangeKey: created.exchangeKey, verified: true },\n entityType,\n entitySecretForeignKeys\n )\n return created\n }\n\n async getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined } | undefined> {\n const caches = await this.caches\n const cachedData = caches.dataById[id]\n if (cachedData) {\n return {\n exchangeData: cachedData.exchangeData,\n exchangeKey: cachedData.decrypted?.exchangeKey,\n accessControlSecret: cachedData.decrypted?.accessControlSecret,\n }\n } else if (retrieveIfNotCached) {\n const data = await this.base.getExchangeDataById(id)\n if (!data) throw new Error(`Could not find exchange data with id ${id}`)\n const decrypted = await this.decryptData(data)\n this.cacheData(data, decrypted, entityType, entitySecretForeignKeys)\n return { exchangeData: data, exchangeKey: decrypted?.exchangeKey, accessControlSecret: decrypted?.accessControlSecret }\n } else return undefined\n }\n\n private cacheData(\n exchangeData: ExchangeData,\n decrypted: { accessControlSecret: string; exchangeKey: CryptoKey; verified: boolean } | undefined,\n entityType?: EntityWithDelegationTypeName,\n entitySecretForeignKeys?: string[]\n ): void {\n this.caches = this.caches.then(async (caches) => {\n caches.dataById[exchangeData.id!] = { exchangeData, decrypted }\n if (decrypted) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact\n // `secureDelegationKeysFor` is currently ignoring the sfks\n if (entityType && entitySecretForeignKeys) {\n const hashes = await this.accessControlSecret.secureDelegationKeysFor(decrypted.accessControlSecret, entityType, entitySecretForeignKeys)\n hashes.forEach((hash) => {\n caches.hashToId.set(hash, exchangeData.id!)\n })\n }\n if (decrypted.verified) {\n caches.delegateToVerifiedEncryptionDataId[exchangeData.delegate] = exchangeData.id!\n }\n }\n return caches\n })\n }\n\n private async doRepopulateCache(): Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: Map<string, string>\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string }\n }> {\n const allData = await this.base.getAllExchangeDataForCurrentDataOwnerIfAllowed()\n if (!allData) throw new Error('Impossible to use fully cached exchange data manager for current data owner.')\n const dataById: { [id: string]: CachedExchangeData } = {}\n const hashToId = new Map<string, string>()\n const delegateToVerifiedEncryptionDataId: { [delegate: string]: string } = {}\n for (const currData of allData) {\n const currDecrypted = await this.decryptData(currData)\n dataById[currData.id!] = { exchangeData: currData, decrypted: currDecrypted }\n if (currDecrypted?.verified) {\n delegateToVerifiedEncryptionDataId[currData.delegate] = currData.id!\n }\n }\n const entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string } = {}\n return { dataById, hashToId, delegateToVerifiedEncryptionDataId, entityTypeToAccessControlKeysValue }\n }\n\n async getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n const caches = await this.caches\n const cached = caches.entityTypeToAccessControlKeysValue[entityType]\n if (cached) return cached\n const accessControlSecrets = Object.values(caches.dataById).flatMap((x) => (x.decrypted ? [x.decrypted.accessControlSecret] : []))\n const fullData = await this.accessControlSecret.getEncodedAccessControlKeys(accessControlSecrets, entityType)\n caches.entityTypeToAccessControlKeysValue[entityType] = fullData\n return fullData\n }\n\n async getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n const caches = await this.caches\n const accessControlSecrets = Object.values(caches.dataById).flatMap((x) => (x.decrypted ? [x.decrypted.accessControlSecret] : []))\n const res: string[] = []\n for (const accessControlSecret of accessControlSecrets) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact\n res.push(await this.accessControlSecret.secureDelegationKeyFor(accessControlSecret, entityType, undefined))\n }\n return res\n }\n}\n\nclass LimitedLruCacheExchangeDataManager extends AbstractExchangeDataManager {\n private readonly idToDataCache: LruTemporisedAsyncCache<string, CachedExchangeData & { hashes: string[] }>\n private readonly hashToId: Map<string, string> = new Map()\n private readonly delegateToVerifiedEncryptionDataId: Map<string, string> = new Map()\n\n constructor(\n base: BaseExchangeDataManager,\n encryptionKeys: UserEncryptionKeysManager,\n signatureKeys: UserSignatureKeysManager,\n accessControlSecret: AccessControlSecretUtils,\n cryptoStrategies: CryptoStrategies,\n dataOwnerApi: IccDataOwnerXApi,\n primitives: CryptoPrimitives,\n useParentKeys: boolean,\n optionalParameters: {\n lruCacheSize?: number\n }\n ) {\n super(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys)\n this.idToDataCache = new LruTemporisedAsyncCache(optionalParameters.lruCacheSize ?? 2000, () => -1)\n }\n\n async clearOrRepopulateCache(): Promise<void> {\n this.idToDataCache.clear(false)\n this.hashToId.clear()\n this.delegateToVerifiedEncryptionDataId.clear()\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n const res: { [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } } = {}\n for (const hash of hashes) {\n const dataId = this.hashToId.get(hash)\n if (dataId) {\n const retrieved = await this.idToDataCache.get(dataId, () => {\n throw new Error(`Data with id ${dataId} should have been already cached.`)\n })\n if (retrieved.decrypted) {\n res[hash] = {\n exchangeData: retrieved.exchangeData,\n exchangeKey: retrieved.decrypted.exchangeKey,\n accessControlSecret: retrieved.decrypted.accessControlSecret,\n }\n }\n }\n }\n return res\n }\n\n private async secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n accessControlSecret: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<string[]> {\n const noSfkDelegationKeys = await Promise.all(\n [...entityWithDelegationTypeNames].map((t) => this.accessControlSecret.secureDelegationKeyFor(accessControlSecret, t, undefined))\n )\n if (entityType && entitySecretForeignKeys?.length) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact\n // `secureDelegationKeysFor` is currently ignoring the sfks\n return [\n ...noSfkDelegationKeys,\n ...(await this.accessControlSecret.secureDelegationKeysFor(accessControlSecret, entityType, entitySecretForeignKeys)),\n ]\n } else {\n return noSfkDelegationKeys\n }\n }\n\n async getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined } | undefined> {\n const cached = await this.idToDataCache.getIfCachedJob(id)\n if (cached) {\n const updated = await this.idToDataCache.get(\n id,\n async (prevData) => {\n const toUpdate = prevData ?? cached.item\n if (toUpdate.decrypted) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users, and it has some performance impact\n // `secureDelegationKeysFor` is currently ignoring the sfks\n if (entityType && entitySecretForeignKeys) {\n const hashes = await this.accessControlSecret.secureDelegationKeysFor(\n toUpdate.decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n hashes.forEach((hash) => {\n this.hashToId.set(hash, toUpdate.exchangeData.id!)\n })\n toUpdate.hashes.push(...hashes)\n }\n }\n return { item: toUpdate, onEviction: (b) => this.doOnEvictionJob(b, toUpdate) }\n },\n () => true\n )\n return {\n exchangeData: updated.exchangeData,\n exchangeKey: updated.decrypted?.exchangeKey,\n accessControlSecret: updated.decrypted?.accessControlSecret,\n }\n } else if (retrieveIfNotCached) {\n return await this.idToDataCache\n .get(id, async () =>\n this.cacheJob(async () => {\n const data = await this.base.getExchangeDataById(id)\n if (!data) throw new Error(`Could not find exchange data with id ${id}`)\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n return { exchangeData: data, hashes, decrypted, verified: decrypted.verified }\n } else {\n return { exchangeData: data, hashes: [], verified: false }\n }\n })\n )\n .then((x) => ({ exchangeData: x.exchangeData, exchangeKey: x.decrypted?.exchangeKey, accessControlSecret: x.decrypted?.accessControlSecret }))\n } else return undefined\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n let existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n if (!existingId) {\n await this.populateCacheToDelegate(delegateId, entityType, entitySecretForeignKeys)\n existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n }\n if (existingId) {\n const cached = await this.idToDataCache.getIfCachedJob(existingId)\n if (!cached) throw new Error(`Illegal state: data with id ${existingId} should have been in cache`)\n if (cached.item.decrypted) {\n return {\n exchangeData: cached.item.exchangeData,\n exchangeKey: cached.item.decrypted.exchangeKey,\n accessControlSecret: cached.item.decrypted.accessControlSecret,\n }\n } else throw new Error(`Illegal state: cached verified data should be decrypted.`)\n } else {\n const newDataId = this.primitives.randomUuid()\n this.delegateToVerifiedEncryptionDataId.set(delegateId, newDataId)\n const createdAndCachedData = await this.idToDataCache.get(newDataId, () =>\n this.cacheJob(async () => {\n const created = await this.createNewExchangeData(delegateId, newDataId)\n const hashes = await this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n created.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n return {\n exchangeData: created.exchangeData,\n decrypted: {\n accessControlSecret: created.accessControlSecret,\n exchangeKey: created.exchangeKey,\n verified: true,\n },\n hashes,\n }\n })\n )\n if (!createdAndCachedData) throw new Error('Data should have been successfully created')\n return {\n exchangeData: createdAndCachedData.exchangeData,\n exchangeKey: createdAndCachedData.decrypted!.exchangeKey,\n accessControlSecret: createdAndCachedData.decrypted!.accessControlSecret,\n }\n }\n }\n\n // Loads and adds to the cache all exchange data from the current data owner to the given delegate. Allows to check if there is already data from\n // the current data owner to the delegate which is good for encryption.\n private async populateCacheToDelegate(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<void> {\n const dataToDelegate = await this.base.getExchangeDataByDelegatorDelegatePair(await this.dataOwnerApi.getCurrentDataOwnerId(), delegateId)\n await Promise.all(\n dataToDelegate.map(async (data) => {\n await this.idToDataCache.get(data.id!, () =>\n this.cacheJob(async () => {\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n return { exchangeData: data, hashes, decrypted }\n } else {\n return { exchangeData: data, hashes: [] }\n }\n })\n )\n })\n )\n }\n\n private async cacheJob(\n retrieveDecryptedDataInfo: () => Promise<CachedExchangeData & { hashes: string[] }>\n ): Promise<{ item: CachedExchangeData & { hashes: string[] }; onEviction: (isReplacement: boolean) => void }> {\n const info = await retrieveDecryptedDataInfo()\n info.hashes.forEach((hash) => this.hashToId.set(hash, info?.exchangeData.id!))\n if (info.decrypted?.verified) this.delegateToVerifiedEncryptionDataId.set(info.exchangeData.delegate, info.exchangeData.id!)\n const item = {\n exchangeData: info.exchangeData,\n hashes: info.hashes,\n decrypted: info.decrypted,\n }\n return {\n item,\n onEviction: (b) => this.doOnEvictionJob(b, item),\n }\n }\n\n private async doOnEvictionJob(isReplacement: boolean, item: CachedExchangeData & { hashes: string[] }) {\n if (!isReplacement) {\n item.hashes.forEach((hash) => this.hashToId.delete(hash))\n if (this.delegateToVerifiedEncryptionDataId.get(item.exchangeData.delegate) === item.exchangeData.id) {\n this.delegateToVerifiedEncryptionDataId.delete(item.exchangeData.delegate)\n }\n }\n }\n\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n return Promise.resolve(undefined)\n }\n\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n return Promise.resolve(undefined)\n }\n}\n"]}
1
+ {"version":3,"file":"ExchangeDataManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,mCAAgH;AAEhH,oCAAyC;AACzC,oFAA6E;AAC7E,wFAAmH;AACnH,yEAA6E;AAO7E;;;GAGG;AACH,SAAsB,gDAAgD,CACpE,IAA6B,EAC7B,cAAyC,EACzC,aAAuC,EACvC,mBAA6C,EAC7C,gBAAkC,EAClC,YAA8B,EAC9B,UAA4B,EAC5B,aAAsB,EACtB,qBAA4D,EAAE;;QAE9D,MAAM,YAAY,GAAG,yCAAuB,CAAC,aAAa,CAAC,MAAM,YAAY,CAAC,mBAAmB,EAAE,CAAC,CAAA;QACpG,IAAI,gBAAgB,CAAC,oCAAoC,CAAC,YAAY,CAAC,EAAE;YACvE,MAAM,GAAG,GAAG,IAAI,8BAA8B,CAC5C,IAAI,EACJ,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,aAAa,CACd,CAAA;YACD,MAAM,GAAG,CAAC,sBAAsB,EAAE,CAAA;YAClC,OAAO,GAAG,CAAA;SACX;aAAM;YACL,OAAO,IAAI,kCAAkC,CAC3C,IAAI,EACJ,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,aAAa,EACb,kBAAkB,CACnB,CAAA;SACF;IACH,CAAC;CAAA;AAtCD,4GAsCC;AAkGD,MAAe,2BAA2B;IACxC,YACW,IAA6B,EACnB,cAAyC,EACzC,aAAuC,EACvC,mBAA6C,EAC7C,gBAAkC,EAClC,YAA8B,EAC9B,UAA4B,EAC9B,aAAsB;QAP9B,SAAI,GAAJ,IAAI,CAAyB;QACnB,mBAAc,GAAd,cAAc,CAA2B;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AAC,IAAI,CAAC,CAAC,CAAA;gBACzD,IAAI,IAAI,CAAC,kCAAkC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE;oBACpG,IAAI,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;iBAC3E;aACF;QACH,CAAC;KAAA;IAED,yBAAyB,CAAC,UAAwC;QAChE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;IAED,oBAAoB,CAAC,UAAwC;QAC3D,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import { ExchangeData } from '../../icc-api/model/internal/ExchangeData'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { BaseExchangeDataManager } from './BaseExchangeDataManager'\nimport { UserEncryptionKeysManager } from './UserEncryptionKeysManager'\nimport { UserSignatureKeysManager } from './UserSignatureKeysManager'\nimport { AccessControlSecretUtils } from './AccessControlSecretUtils'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { fingerprintV1, getShaVersionForKey, hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from './utils'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { hex2ua, ua2b64 } from '../utils'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { EntityWithDelegationTypeName, entityWithDelegationTypeNames } from '../utils/EntityWithDelegationTypeName'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\n\nexport type ExchangeDataManagerOptionalParameters = {\n // Only for not fully cached implementation (data owner can't request all his exchange data), amount of exchange data which can be cached\n lruCacheSize?: number // default = 2000\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice.\n * Initialises and returns the exchange data manager which is most appropriate for the current data owner.\n */\nexport async function initialiseExchangeDataManagerForCurrentDataOwner(\n base: BaseExchangeDataManager,\n encryptionKeys: UserEncryptionKeysManager,\n signatureKeys: UserSignatureKeysManager,\n accessControlSecret: AccessControlSecretUtils,\n cryptoStrategies: CryptoStrategies,\n dataOwnerApi: IccDataOwnerXApi,\n primitives: CryptoPrimitives,\n useParentKeys: boolean,\n optionalParameters: ExchangeDataManagerOptionalParameters = {}\n): Promise<ExchangeDataManager> {\n const currentOwner = CryptoActorStubWithType.fromDataOwner(await dataOwnerApi.getCurrentDataOwner())\n if (cryptoStrategies.dataOwnerRequiresAnonymousDelegation(currentOwner)) {\n const res = new FullyCachedExchangeDataManager(\n base,\n encryptionKeys,\n signatureKeys,\n accessControlSecret,\n cryptoStrategies,\n dataOwnerApi,\n primitives,\n useParentKeys\n )\n await res.clearOrRepopulateCache()\n return res\n } else {\n return new LimitedLruCacheExchangeDataManager(\n base,\n encryptionKeys,\n signatureKeys,\n accessControlSecret,\n cryptoStrategies,\n dataOwnerApi,\n primitives,\n useParentKeys,\n optionalParameters\n )\n }\n}\n\ntype CachedExchangeData = {\n exchangeData: ExchangeData\n decrypted?: {\n accessControlSecret: string\n exchangeKey: CryptoKey\n verified: boolean\n }\n}\n\n/**\n * @internal this class is intended for internal use only and may be changed without notice.\n * Exchange data manager which automatically handles decryption and cache\n */\nexport interface ExchangeDataManager {\n readonly base: BaseExchangeDataManager\n\n /**\n * Updates all exchange data between the current data owner and another data owner to allow the other data owner to access existing exchange data\n * using a new public key. Note that this will make existing exchange keys from the other data owner to the current data owner unverified, therefore\n * invalid for encryption.\n * @param otherDataOwner the other data owner.\n * @param newDataOwnerPublicKey a new public key of the other data owner.\n */\n giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string): Promise<void>\n\n /**\n * Gets any existing and verified exchange data from the current data owner to the provided delegate or creates new data if no verified data is\n * available, then caches it. The {@link entityType} and {@link entitySecretForeignKeys} will be used for the secure-delegation-hash-based cache\n * of the exchange data and not for actually creating the exchange data.\n * @param delegateId the id of the delegate.\n * @param entityType type of the entity for which you want to create new metadata.\n * @param entitySecretForeignKeys the secret foreign keys of the entity which you want to create new metadata.\n * @return the access control secret and key of the data to use for encryption.\n */\n getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }>\n\n /**\n * Retrieve the cached decrypted exchange data key associated with any of the provided hashes/entry keys of secure delegations. Depending on the\n * implementation the {@link entityType} and {@link entitySecretForeignKeys} may be used to improve the secure-delegation-hash-based cache of\n * exchange data from the other available exchange data caches.\n * @param hashes hashes of access control secrets for a specific entity, as they appear in the key of secure delegation entries\n * @param entityType type of the entity containing the metadata for which you are retrieving the encryption key.\n * @param entitySecretForeignKeys the secret foreign keys of the entity containing the metadata for which you are retrieving the encryption key.\n * @return the exchange data and decrypted key associated to that hash if cached\n */\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [hash: string]: { exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey } }>\n\n /**\n * Retrieves the exchange data with the provided id (from the cache if available or from the server otherwise if allowed by\n * {@link retrieveIfNotCached}) and attempts to decrypt it, then caches the result. The {@link entityType} and {@link entitySecretForeignKeys} will\n * be used for the secure-delegation-hash-based cache of the exchange data.\n * @param id id of the exchange data\n * @param entityType type of the entity containing the metadata for which you are retrieving the encryption key.\n * @param entitySecretForeignKeys the secret foreign keys of the entity containing the metadata for which you are retrieving the encryption key.\n * @param retrieveIfNotCached if false and there is no cached exchange data with the provided id the method returns undefined, else the method will\n * attempt to load the exchange data from the server.\n * @return undefined if the exchange data is not cached and {@link retrieveIfNotCached} is false. Else an object containing:\n * - exchangeData: the exchange data with the provided id\n * - exchangeKey: the exchange key corresponding to the provided exchange data if it could be decrypted, else undefined\n * @throws if no exchange data with the given id is cached and {@link retrieveIfNotCached} is true and the data could not be found in the server\n * either.\n */\n getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; exchangeData: ExchangeData } | undefined>\n\n /**\n * Clears the cache or fully repopulates the cache if the current data owner can retrieve all of his exchange data according to the crypto\n * strategies.\n */\n clearOrRepopulateCache(): Promise<void>\n\n /**\n * If the current data owner requires anonymous delegations this returns the base64 representation of the concatenation of all available access\n * control keys for the current data owner.\n */\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined>\n\n /**\n * If the current data owner requires anonymous delegations this returns the access control keys which may be used in secure delegations for the\n * data owner, which can be used to search for data.\n */\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined>\n}\n\nabstract class AbstractExchangeDataManager implements ExchangeDataManager {\n constructor(\n readonly base: BaseExchangeDataManager,\n protected readonly encryptionKeys: UserEncryptionKeysManager,\n protected readonly signatureKeys: UserSignatureKeysManager,\n protected readonly accessControlSecret: AccessControlSecretUtils,\n protected readonly cryptoStrategies: CryptoStrategies,\n protected readonly dataOwnerApi: IccDataOwnerXApi,\n protected readonly primitives: CryptoPrimitives,\n private readonly useParentKeys: boolean\n ) {}\n\n protected async decryptData(data: ExchangeData): Promise<\n | {\n accessControlSecret: string\n exchangeKey: CryptoKey\n verified: boolean\n }\n | undefined\n > {\n const decryptionKeys = this.encryptionKeys.getDecryptionKeys()\n const decryptedExchangeKey = (await this.base.tryDecryptExchangeKeys([data], decryptionKeys)).successfulDecryptions[0]\n if (!decryptedExchangeKey) return undefined\n const decryptedAccessControlSecret = (await this.base.tryDecryptAccessControlSecret([data], decryptionKeys)).successfulDecryptions[0]\n if (!decryptedAccessControlSecret)\n throw new Error(`Decryption key could be decrypted but access control secret could not for data ${JSON.stringify(data)}`)\n const decryptedSharedSignatureKey = (await this.base.tryDecryptSharedSignatureKeys([data], decryptionKeys)).successfulDecryptions[0]\n if (!decryptedSharedSignatureKey)\n throw new Error(`Decryption key could be decrypted but shared signature key could not for data ${JSON.stringify(data)}`)\n return {\n accessControlSecret: decryptedAccessControlSecret,\n exchangeKey: decryptedExchangeKey,\n verified: await this.base.verifyExchangeData(\n {\n exchangeData: data,\n decryptedAccessControlSecret,\n decryptedExchangeKey,\n decryptedSharedSignatureKey,\n },\n (fp) => this.signatureKeys.getSignatureVerificationKey(fp),\n true\n ),\n }\n }\n\n protected async createNewExchangeData(\n delegateId: string,\n newDataId?: string\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n const encryptionKeys: { [fp: string]: CryptoKey } = {}\n this.encryptionKeys.getSelfVerifiedKeys().forEach(({ fingerprint, pair }) => {\n encryptionKeys[fingerprint] = pair.publicKey\n })\n if (delegateId != (await this.dataOwnerApi.getCurrentDataOwnerId())) {\n const delegate = await this.dataOwnerApi.getCryptoActorStub(delegateId)\n const sha256KeysOfDelegate = hexPublicKeysWithSha256Of(delegate.stub)\n const sha1KeysOfDelegate = hexPublicKeysWithSha1Of(delegate.stub)\n let allVerifiedDelegateKeys: string[]\n if (this.useParentKeys && (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()).includes(delegateId)) {\n allVerifiedDelegateKeys = await this.encryptionKeys.getVerifiedPublicKeysFor(delegate.stub)\n } else {\n allVerifiedDelegateKeys = await this.cryptoStrategies.verifyDelegatePublicKeys(\n delegate,\n [...Array.from(sha256KeysOfDelegate), ...Array.from(sha1KeysOfDelegate)],\n this.primitives\n )\n }\n if (!allVerifiedDelegateKeys.length)\n throw new Error(`Could not create exchange data to ${delegateId} as no public key for the delegate could be verified.`)\n for (const delegateKey of allVerifiedDelegateKeys) {\n if (sha1KeysOfDelegate.has(delegateKey)) {\n encryptionKeys[fingerprintV1(delegateKey)] = await this.primitives.RSA.importKey('spki', hex2ua(delegateKey), ['encrypt'], 'sha-1')\n } else if (sha256KeysOfDelegate.has(delegateKey)) {\n encryptionKeys[fingerprintV1(delegateKey)] = await this.primitives.RSA.importKey('spki', hex2ua(delegateKey), ['encrypt'], 'sha-256')\n } else throw new Error('Illegal state: verified keys should contain only keys for OAPE-SHA1 or OAPE-SHA256.')\n }\n }\n const signatureKey = await this.signatureKeys.getOrCreateSignatureKeyPair()\n const newData = await this.base.createExchangeData(\n delegateId,\n { [signatureKey.fingerprint]: signatureKey.keyPair.privateKey },\n encryptionKeys,\n newDataId ? { id: newDataId } : {}\n )\n return {\n exchangeData: newData.exchangeData,\n accessControlSecret: newData.accessControlSecret,\n exchangeKey: newData.exchangeKey,\n }\n }\n\n async giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string) {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const newKeyFp = fingerprintV1(newDataOwnerPublicKey)\n const other = await this.dataOwnerApi.getCryptoActorStub(otherDataOwner)\n const newKeyHashVersion = getShaVersionForKey(other.stub, newDataOwnerPublicKey)\n if (!newKeyHashVersion) throw new Error(`Public key not found for data owner ${otherDataOwner}`)\n const importedNewKey = await this.primitives.RSA.importKey('spki', hex2ua(newDataOwnerPublicKey), ['encrypt'], newKeyHashVersion)\n const signatureKey = await this.signatureKeys.getOrCreateSignatureKeyPair()\n const decryptionKeys = this.encryptionKeys.getDecryptionKeys()\n const allExchangeDataToUpdate =\n self == otherDataOwner\n ? await this.base.getExchangeDataByDelegatorDelegatePair(self, self)\n : [\n ...(await this.base.getExchangeDataByDelegatorDelegatePair(self, otherDataOwner)),\n ...(await this.base.getExchangeDataByDelegatorDelegatePair(otherDataOwner, self)),\n ]\n for (const dataToUpdate of allExchangeDataToUpdate) {\n if (!Object.keys(dataToUpdate.exchangeKey).find((fp) => fp == newKeyFp)) {\n const updated = await this.base.tryUpdateExchangeData(dataToUpdate, decryptionKeys, { [newKeyFp]: importedNewKey })\n if (!updated) {\n console.warn(`Failed to give access back to exchanged data ${JSON.stringify(dataToUpdate)}`)\n }\n }\n }\n }\n\n clearOrRepopulateCache(): Promise<void> {\n throw new Error('Implemented by concrete class')\n }\n\n getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n throw new Error('Implemented by concrete class')\n }\n\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n throw new Error('Implemented by concrete class')\n }\n\n getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined } | undefined> {\n throw new Error('Implemented by concrete class')\n }\n\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n throw new Error('Implemented by concrete class')\n }\n\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n throw new Error('Implemented by concrete class')\n }\n}\n\nclass FullyCachedExchangeDataManager extends AbstractExchangeDataManager {\n private caches: Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: Map<string, string>\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string }\n }> = Promise.resolve({ dataById: {}, hashToId: new Map(), delegateToVerifiedEncryptionDataId: {}, entityTypeToAccessControlKeysValue: {} })\n\n async clearOrRepopulateCache(): Promise<void> {\n this.caches = this.doRepopulateCache()\n await this.caches\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n function retrieveByHashesFromCaches(caches: {\n dataById: { [id: string]: CachedExchangeData }\n hashToId: Map<string, string>\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n }): { [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } } {\n return hashes.reduce((res, hash) => {\n const id = caches.hashToId.get(hash)\n if (id) {\n const cached = caches.dataById[id]\n if (cached?.decrypted) {\n res[hash] = {\n exchangeData: cached.exchangeData,\n exchangeKey: cached.decrypted.exchangeKey,\n accessControlSecret: cached.decrypted.accessControlSecret,\n }\n }\n }\n return res\n }, {} as { [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } })\n }\n\n const retrievedFromHashesCache = retrieveByHashesFromCaches(await this.caches)\n if (Object.keys(retrievedFromHashesCache).length) {\n return retrievedFromHashesCache\n } else {\n this.caches = this.caches.then(async (caches) => {\n for (const currData of Object.values(caches.dataById)) {\n if (currData.decrypted) {\n const currDataHashes = await this.accessControlSecret.secureDelegationKeysFor(\n currData.decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n currDataHashes.forEach((hash) => caches.hashToId.set(hash, currData.exchangeData.id!))\n }\n }\n return caches\n })\n return retrieveByHashesFromCaches(await this.caches)\n }\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n const caches = await this.caches\n const dataId = caches.delegateToVerifiedEncryptionDataId[delegateId]\n const cached = dataId ? caches.dataById[dataId] : undefined\n if (cached && cached?.decrypted) {\n return {\n exchangeData: cached.exchangeData,\n accessControlSecret: cached.decrypted.accessControlSecret,\n exchangeKey: cached.decrypted.exchangeKey,\n }\n }\n const created = await this.createNewExchangeData(delegateId)\n this.cacheData(\n created.exchangeData,\n { accessControlSecret: created.accessControlSecret, exchangeKey: created.exchangeKey, verified: true },\n entityType,\n entitySecretForeignKeys\n )\n return created\n }\n\n async getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined } | undefined> {\n const caches = await this.caches\n const cachedData = caches.dataById[id]\n if (cachedData) {\n return {\n exchangeData: cachedData.exchangeData,\n exchangeKey: cachedData.decrypted?.exchangeKey,\n accessControlSecret: cachedData.decrypted?.accessControlSecret,\n }\n } else if (retrieveIfNotCached) {\n const data = await this.base.getExchangeDataById(id)\n if (!data) throw new Error(`Could not find exchange data with id ${id}`)\n const decrypted = await this.decryptData(data)\n this.cacheData(data, decrypted, entityType, entitySecretForeignKeys)\n return { exchangeData: data, exchangeKey: decrypted?.exchangeKey, accessControlSecret: decrypted?.accessControlSecret }\n } else return undefined\n }\n\n private cacheData(\n exchangeData: ExchangeData,\n decrypted: { accessControlSecret: string; exchangeKey: CryptoKey; verified: boolean } | undefined,\n entityType?: EntityWithDelegationTypeName,\n entitySecretForeignKeys?: string[]\n ): void {\n this.caches = this.caches.then(async (caches) => {\n caches.dataById[exchangeData.id!] = { exchangeData, decrypted }\n if (decrypted) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact\n // `secureDelegationKeysFor` is currently ignoring the sfks\n if (entityType && entitySecretForeignKeys) {\n const hashes = await this.accessControlSecret.secureDelegationKeysFor(decrypted.accessControlSecret, entityType, entitySecretForeignKeys)\n hashes.forEach((hash) => {\n caches.hashToId.set(hash, exchangeData.id!)\n })\n }\n if (decrypted.verified) {\n caches.delegateToVerifiedEncryptionDataId[exchangeData.delegate] = exchangeData.id!\n }\n }\n return caches\n })\n }\n\n private async doRepopulateCache(): Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: Map<string, string>\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string }\n }> {\n const allData = await this.base.getAllExchangeDataForCurrentDataOwnerIfAllowed()\n if (!allData) throw new Error('Impossible to use fully cached exchange data manager for current data owner.')\n const dataById: { [id: string]: CachedExchangeData } = {}\n const hashToId = new Map<string, string>()\n const delegateToVerifiedEncryptionDataId: { [delegate: string]: string } = {}\n for (const currData of allData) {\n const currDecrypted = await this.decryptData(currData)\n dataById[currData.id!] = { exchangeData: currData, decrypted: currDecrypted }\n if (currDecrypted?.verified) {\n delegateToVerifiedEncryptionDataId[currData.delegate] = currData.id!\n }\n }\n const entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string } = {}\n return { dataById, hashToId, delegateToVerifiedEncryptionDataId, entityTypeToAccessControlKeysValue }\n }\n\n async getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n const caches = await this.caches\n const cached = caches.entityTypeToAccessControlKeysValue[entityType]\n if (cached) return cached\n const accessControlSecrets = Object.values(caches.dataById).flatMap((x) => (x.decrypted ? [x.decrypted.accessControlSecret] : []))\n const fullData = await this.accessControlSecret.getEncodedAccessControlKeys(accessControlSecrets, entityType)\n caches.entityTypeToAccessControlKeysValue[entityType] = fullData\n return fullData\n }\n\n async getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n const caches = await this.caches\n const accessControlSecrets = Object.values(caches.dataById).flatMap((x) => (x.decrypted ? [x.decrypted.accessControlSecret] : []))\n const res: string[] = []\n for (const accessControlSecret of accessControlSecrets) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact\n res.push(await this.accessControlSecret.secureDelegationKeyFor(accessControlSecret, entityType, undefined))\n }\n return res\n }\n}\n\nclass LimitedLruCacheExchangeDataManager extends AbstractExchangeDataManager {\n private readonly idToDataCache: LruTemporisedAsyncCache<string, CachedExchangeData & { hashes: string[] }>\n private readonly hashToId: Map<string, string> = new Map()\n private readonly delegateToVerifiedEncryptionDataId: Map<string, string> = new Map()\n\n constructor(\n base: BaseExchangeDataManager,\n encryptionKeys: UserEncryptionKeysManager,\n signatureKeys: UserSignatureKeysManager,\n accessControlSecret: AccessControlSecretUtils,\n cryptoStrategies: CryptoStrategies,\n dataOwnerApi: IccDataOwnerXApi,\n primitives: CryptoPrimitives,\n useParentKeys: boolean,\n optionalParameters: {\n lruCacheSize?: number\n }\n ) {\n super(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys)\n this.idToDataCache = new LruTemporisedAsyncCache(optionalParameters.lruCacheSize ?? 2000, () => -1)\n }\n\n async clearOrRepopulateCache(): Promise<void> {\n this.idToDataCache.clear(false)\n this.hashToId.clear()\n this.delegateToVerifiedEncryptionDataId.clear()\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[],\n entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n const res: { [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } } = {}\n for (const hash of hashes) {\n const dataId = this.hashToId.get(hash)\n if (dataId) {\n const retrieved = await this.idToDataCache.get(dataId, () => {\n throw new Error(`Data with id ${dataId} should have been already cached.`)\n })\n if (retrieved.decrypted) {\n res[hash] = {\n exchangeData: retrieved.exchangeData,\n exchangeKey: retrieved.decrypted.exchangeKey,\n accessControlSecret: retrieved.decrypted.accessControlSecret,\n }\n }\n }\n }\n return res\n }\n\n private async secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n accessControlSecret: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<string[]> {\n const noSfkDelegationKeys = await Promise.all(\n [...entityWithDelegationTypeNames].map((t) => this.accessControlSecret.secureDelegationKeyFor(accessControlSecret, t, undefined))\n )\n if (entityType && entitySecretForeignKeys?.length) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact\n // `secureDelegationKeysFor` is currently ignoring the sfks\n return [\n ...noSfkDelegationKeys,\n ...(await this.accessControlSecret.secureDelegationKeysFor(accessControlSecret, entityType, entitySecretForeignKeys)),\n ]\n } else {\n return noSfkDelegationKeys\n }\n }\n\n async getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined } | undefined> {\n const cached = await this.idToDataCache.getIfCachedJob(id)\n if (cached) {\n const updated = await this.idToDataCache.get(\n id,\n async (prevData) => {\n const toUpdate = prevData ?? cached.item\n if (toUpdate.decrypted) {\n // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users, and it has some performance impact\n // `secureDelegationKeysFor` is currently ignoring the sfks\n if (entityType && entitySecretForeignKeys) {\n const hashes = await this.accessControlSecret.secureDelegationKeysFor(\n toUpdate.decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n hashes.forEach((hash) => {\n this.hashToId.set(hash, toUpdate.exchangeData.id!)\n })\n toUpdate.hashes.push(...hashes)\n }\n }\n return { item: toUpdate, onEviction: (b) => this.doOnEvictionJob(b, toUpdate) }\n },\n () => true\n )\n return {\n exchangeData: updated.exchangeData,\n exchangeKey: updated.decrypted?.exchangeKey,\n accessControlSecret: updated.decrypted?.accessControlSecret,\n }\n } else if (retrieveIfNotCached) {\n return await this.idToDataCache\n .get(id, async () =>\n this.cacheJob(async () => {\n const data = await this.base.getExchangeDataById(id)\n if (!data) throw new Error(`Could not find exchange data with id ${id}`)\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n return { exchangeData: data, hashes, decrypted, verified: decrypted.verified }\n } else {\n return { exchangeData: data, hashes: [], verified: false }\n }\n })\n )\n .then((x) => ({ exchangeData: x.exchangeData, exchangeKey: x.decrypted?.exchangeKey, accessControlSecret: x.decrypted?.accessControlSecret }))\n } else return undefined\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey }> {\n let existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n if (!existingId) {\n await this.populateCacheToDelegate(delegateId, entityType, entitySecretForeignKeys)\n existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n }\n if (existingId) {\n const cached = await this.idToDataCache.getIfCachedJob(existingId)\n if (!cached) throw new Error(`Illegal state: data with id ${existingId} should have been in cache`)\n if (cached.item.decrypted) {\n return {\n exchangeData: cached.item.exchangeData,\n exchangeKey: cached.item.decrypted.exchangeKey,\n accessControlSecret: cached.item.decrypted.accessControlSecret,\n }\n } else throw new Error(`Illegal state: cached verified data should be decrypted.`)\n } else {\n const newDataId = this.primitives.randomUuid()\n this.delegateToVerifiedEncryptionDataId.set(delegateId, newDataId)\n const createdAndCachedData = await this.idToDataCache.get(newDataId, () =>\n this.cacheJob(async () => {\n const created = await this.createNewExchangeData(delegateId, newDataId)\n const hashes = await this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n created.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n return {\n exchangeData: created.exchangeData,\n decrypted: {\n accessControlSecret: created.accessControlSecret,\n exchangeKey: created.exchangeKey,\n verified: true,\n },\n hashes,\n }\n })\n )\n if (!createdAndCachedData) throw new Error('Data should have been successfully created')\n return {\n exchangeData: createdAndCachedData.exchangeData,\n exchangeKey: createdAndCachedData.decrypted!.exchangeKey,\n accessControlSecret: createdAndCachedData.decrypted!.accessControlSecret,\n }\n }\n }\n\n // Loads and adds to the cache all exchange data from the current data owner to the given delegate. Allows to check if there is already data from\n // the current data owner to the delegate which is good for encryption.\n private async populateCacheToDelegate(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<void> {\n const dataToDelegate = await this.base.getExchangeDataByDelegatorDelegatePair(await this.dataOwnerApi.getCurrentDataOwnerId(), delegateId)\n await Promise.all(\n dataToDelegate.map(async (data) => {\n await this.idToDataCache.get(data.id!, () =>\n this.cacheJob(async () => {\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(\n decrypted.accessControlSecret,\n entityType,\n entitySecretForeignKeys\n )\n return { exchangeData: data, hashes, decrypted }\n } else {\n return { exchangeData: data, hashes: [] }\n }\n })\n )\n })\n )\n }\n\n private async cacheJob(\n retrieveDecryptedDataInfo: () => Promise<CachedExchangeData & { hashes: string[] }>\n ): Promise<{ item: CachedExchangeData & { hashes: string[] }; onEviction: (isReplacement: boolean) => void }> {\n const info = await retrieveDecryptedDataInfo()\n info.hashes.forEach((hash) => this.hashToId.set(hash, info?.exchangeData.id!))\n if (info.decrypted?.verified) this.delegateToVerifiedEncryptionDataId.set(info.exchangeData.delegate, info.exchangeData.id!)\n const item = {\n exchangeData: info.exchangeData,\n hashes: info.hashes,\n decrypted: info.decrypted,\n }\n return {\n item,\n onEviction: (b) => this.doOnEvictionJob(b, item),\n }\n }\n\n private async doOnEvictionJob(isReplacement: boolean, item: CachedExchangeData & { hashes: string[] }) {\n if (!isReplacement) {\n item.hashes.forEach((hash) => this.hashToId.delete(hash))\n if (this.delegateToVerifiedEncryptionDataId.get(item.exchangeData.delegate) === item.exchangeData.id) {\n this.delegateToVerifiedEncryptionDataId.delete(item.exchangeData.delegate)\n }\n }\n }\n\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n return Promise.resolve(undefined)\n }\n\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n return Promise.resolve(undefined)\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { IccExchangeDataMapApi } from '../../icc-api/api/IccExchangeDataMapApi';
1
+ import { IccExchangeDataMapApi } from '../../icc-api/api/internal/IccExchangeDataMapApi';
2
2
  import { ExchangeDataMap } from '../../icc-api/model/internal/ExchangeDataMap';
3
3
  /**
4
4
  * @internal this class is intended for internal use only and may be modified without notice
@@ -1 +1 @@
1
- {"version":3,"file":"ExchangeDataMapManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataMapManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oFAA6E;AAE7E,mGAA+F;AAE/F;;;GAGG;AACH,MAAa,sBAAsB;IACjC,YAA6B,GAA0B;QAA1B,QAAG,GAAH,GAAG,CAAuB;QAE/C,yBAAoB,GAA0C,IAAI,oDAAuB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAFvD,CAAC;IAI3D;;;;;OAKG;IACG,sBAAsB,CAAC,KAA+D;;YAC1F,MAAM,eAAe,GAA6D,EAAE,CAAA;YACpF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC1C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE;oBACxD,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;iBACvB;aACF;YACD,MAAM,IAAI,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,2DAA4B,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;YACvG,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAO,KAAK,EAAE,EAAE;gBAC/C,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YACnF,CAAC,CAAA,CAAC,CACH,CAAA;QACH,CAAC;KAAA;IAED;;;OAGG;IACG,kBAAkB,CAAC,oBAA4B;;YACnD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAA;YACnF,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YAC9F,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;IAED;;;OAGG;IACG,uBAAuB,CAAC,sBAAgC;;YAC5D,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAA;YACzF,MAAM,OAAO,CAAC,GAAG,CACf,gBAAgB,CAAC,GAAG,CAAC,CAAO,KAAK,EAAE,EAAE;gBACnC,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YACtF,CAAC,CAAA,CAAC,CACH,CAAA;YACD,OAAO,gBAAgB,CAAA;QACzB,CAAC;KAAA;CACF;AAjDD,wDAiDC","sourcesContent":["import { IccExchangeDataMapApi } from '../../icc-api/api/IccExchangeDataMapApi'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { ExchangeDataMap } from '../../icc-api/model/internal/ExchangeDataMap'\nimport { ExchangeDataMapCreationBatch } from '../../icc-api/model/ExchangeDataMapCreationBatch'\n\n/**\n * @internal this class is intended for internal use only and may be modified without notice\n * This class manages the Exchange Data Map entities, caching with an LRU cache on retrieval.\n */\nexport class ExchangeDataMapManager {\n constructor(private readonly api: IccExchangeDataMapApi) {}\n\n private exchangeDataMapCache: LruTemporisedAsyncCache<string, null> = new LruTemporisedAsyncCache(1000, () => -1)\n\n /**\n * This function creates a batch of Exchange Data Map, ignoring the one that already exist and are already present in the cache.\n * The ones that are not are created and their ids are cached.\n * @param batch a map where each key is the hex-encoded access control key to another map that associates the encoded id of an\n * Exchange Data entity to the fingerprint of the key used to encrypt it.\n */\n async createExchangeDataMaps(batch: { [accessControlKey: string]: { [fp: string]: string } }): Promise<void> {\n const entriesToCreate: { [accessControlKey: string]: { [fp: string]: string } } = {}\n for (const [k, v] of Object.entries(batch)) {\n if (!(await this.exchangeDataMapCache.getIfCachedJob(k))) {\n entriesToCreate[k] = v\n }\n }\n await this.api.createExchangeDataMapBatch(new ExchangeDataMapCreationBatch({ batch: entriesToCreate }))\n await Promise.all(\n Object.keys(entriesToCreate).map(async (entry) => {\n await this.exchangeDataMapCache.get(entry, () => Promise.resolve({ item: null }))\n })\n )\n }\n\n /**\n * Retrieves an Exchange Data Map.\n * @param accessControlKeyHash the hex-encoded hash of the Exchange Data Map to retrieve.\n */\n async getExchangeDataMap(accessControlKeyHash: string): Promise<ExchangeDataMap> {\n const exchangeDataMap = await this.api.getExchangeDataMapById(accessControlKeyHash)\n await this.exchangeDataMapCache.get(exchangeDataMap.id, () => Promise.resolve({ item: null }))\n return exchangeDataMap\n }\n\n /**\n * Retrieves a batch of Exchange Data Maps.\n * @param accessControlKeyHashes the hex-encoded hashes of the Exchange Data Maps to retrieve.\n */\n async getExchangeDataMapBatch(accessControlKeyHashes: string[]): Promise<ExchangeDataMap[]> {\n const exchangeDataMaps = await this.api.getExchangeDataMapByBatch(accessControlKeyHashes)\n await Promise.all(\n exchangeDataMaps.map(async (entry) => {\n await this.exchangeDataMapCache.get(entry.id, () => Promise.resolve({ item: null }))\n })\n )\n return exchangeDataMaps\n }\n}\n"]}
1
+ {"version":3,"file":"ExchangeDataMapManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataMapManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oFAA6E;AAE7E,mGAA+F;AAE/F;;;GAGG;AACH,MAAa,sBAAsB;IACjC,YAA6B,GAA0B;QAA1B,QAAG,GAAH,GAAG,CAAuB;QAE/C,yBAAoB,GAA0C,IAAI,oDAAuB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAFvD,CAAC;IAI3D;;;;;OAKG;IACG,sBAAsB,CAAC,KAA+D;;YAC1F,MAAM,eAAe,GAA6D,EAAE,CAAA;YACpF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC1C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE;oBACxD,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;iBACvB;aACF;YACD,MAAM,IAAI,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,2DAA4B,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;YACvG,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAO,KAAK,EAAE,EAAE;gBAC/C,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YACnF,CAAC,CAAA,CAAC,CACH,CAAA;QACH,CAAC;KAAA;IAED;;;OAGG;IACG,kBAAkB,CAAC,oBAA4B;;YACnD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAA;YACnF,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YAC9F,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;IAED;;;OAGG;IACG,uBAAuB,CAAC,sBAAgC;;YAC5D,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAA;YACzF,MAAM,OAAO,CAAC,GAAG,CACf,gBAAgB,CAAC,GAAG,CAAC,CAAO,KAAK,EAAE,EAAE;gBACnC,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YACtF,CAAC,CAAA,CAAC,CACH,CAAA;YACD,OAAO,gBAAgB,CAAA;QACzB,CAAC;KAAA;CACF;AAjDD,wDAiDC","sourcesContent":["import { IccExchangeDataMapApi } from '../../icc-api/api/internal/IccExchangeDataMapApi'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { ExchangeDataMap } from '../../icc-api/model/internal/ExchangeDataMap'\nimport { ExchangeDataMapCreationBatch } from '../../icc-api/model/ExchangeDataMapCreationBatch'\n\n/**\n * @internal this class is intended for internal use only and may be modified without notice\n * This class manages the Exchange Data Map entities, caching with an LRU cache on retrieval.\n */\nexport class ExchangeDataMapManager {\n constructor(private readonly api: IccExchangeDataMapApi) {}\n\n private exchangeDataMapCache: LruTemporisedAsyncCache<string, null> = new LruTemporisedAsyncCache(1000, () => -1)\n\n /**\n * This function creates a batch of Exchange Data Map, ignoring the one that already exist and are already present in the cache.\n * The ones that are not are created and their ids are cached.\n * @param batch a map where each key is the hex-encoded access control key to another map that associates the encoded id of an\n * Exchange Data entity to the fingerprint of the key used to encrypt it.\n */\n async createExchangeDataMaps(batch: { [accessControlKey: string]: { [fp: string]: string } }): Promise<void> {\n const entriesToCreate: { [accessControlKey: string]: { [fp: string]: string } } = {}\n for (const [k, v] of Object.entries(batch)) {\n if (!(await this.exchangeDataMapCache.getIfCachedJob(k))) {\n entriesToCreate[k] = v\n }\n }\n await this.api.createExchangeDataMapBatch(new ExchangeDataMapCreationBatch({ batch: entriesToCreate }))\n await Promise.all(\n Object.keys(entriesToCreate).map(async (entry) => {\n await this.exchangeDataMapCache.get(entry, () => Promise.resolve({ item: null }))\n })\n )\n }\n\n /**\n * Retrieves an Exchange Data Map.\n * @param accessControlKeyHash the hex-encoded hash of the Exchange Data Map to retrieve.\n */\n async getExchangeDataMap(accessControlKeyHash: string): Promise<ExchangeDataMap> {\n const exchangeDataMap = await this.api.getExchangeDataMapById(accessControlKeyHash)\n await this.exchangeDataMapCache.get(exchangeDataMap.id, () => Promise.resolve({ item: null }))\n return exchangeDataMap\n }\n\n /**\n * Retrieves a batch of Exchange Data Maps.\n * @param accessControlKeyHashes the hex-encoded hashes of the Exchange Data Maps to retrieve.\n */\n async getExchangeDataMapBatch(accessControlKeyHashes: string[]): Promise<ExchangeDataMap[]> {\n const exchangeDataMaps = await this.api.getExchangeDataMapByBatch(accessControlKeyHashes)\n await Promise.all(\n exchangeDataMaps.map(async (entry) => {\n await this.exchangeDataMapCache.get(entry.id, () => Promise.resolve({ item: null }))\n })\n )\n return exchangeDataMaps\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export declare class HMACUtils {
2
+ private readonly _crypto;
3
+ private readonly params;
4
+ constructor(crypto: Crypto);
5
+ generateKey(): Promise<CryptoKey>;
6
+ exportKey(key: CryptoKey): Promise<ArrayBuffer>;
7
+ importKey(key: ArrayBuffer): Promise<CryptoKey>;
8
+ sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>;
9
+ verify(key: CryptoKey, data: ArrayBuffer, signature: ArrayBuffer): Promise<boolean>;
10
+ }
@@ -0,0 +1,48 @@
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.HMACUtils = void 0;
13
+ class HMACUtils {
14
+ constructor(crypto) {
15
+ this.params = {
16
+ name: 'HMAC',
17
+ hash: 'SHA-512',
18
+ };
19
+ this._crypto = crypto;
20
+ }
21
+ generateKey() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return this._crypto.subtle.generateKey(Object.assign({}, this.params), true, ['sign', 'verify']);
24
+ });
25
+ }
26
+ exportKey(key) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this._crypto.subtle.exportKey('raw', key);
29
+ });
30
+ }
31
+ importKey(key) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return this._crypto.subtle.importKey('raw', key, Object.assign({}, this.params), true, ['sign', 'verify']);
34
+ });
35
+ }
36
+ sign(key, data) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return this._crypto.subtle.sign(Object.assign({}, this.params), key, data);
39
+ });
40
+ }
41
+ verify(key, data, signature) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return this._crypto.subtle.verify(Object.assign({}, this.params), key, signature, data);
44
+ });
45
+ }
46
+ }
47
+ exports.HMACUtils = HMACUtils;
48
+ //# sourceMappingURL=HMACUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HMACUtils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/HMACUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAa,SAAS;IAOpB,YAAY,MAAc;QALT,WAAM,GAAG;YACxB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,SAAS;SAChB,CAAA;QAGC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAEK,WAAW;;YACf,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,mBAAM,IAAI,CAAC,MAAM,GAAI,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;QACtF,CAAC;KAAA;IAEK,SAAS,CAAC,GAAc;;YAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAClD,CAAC;KAAA;IAEK,SAAS,CAAC,GAAgB;;YAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,oBAAO,IAAI,CAAC,MAAM,GAAI,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;QAChG,CAAC;KAAA;IAEK,IAAI,CAAC,GAAc,EAAE,IAAiB;;YAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,mBAAM,IAAI,CAAC,MAAM,GAAI,GAAG,EAAE,IAAI,CAAC,CAAA;QAChE,CAAC;KAAA;IAEK,MAAM,CAAC,GAAc,EAAE,IAAiB,EAAE,SAAsB;;YACpE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,mBAAM,IAAI,CAAC,MAAM,GAAI,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QAC7E,CAAC;KAAA;CACF;AA9BD,8BA8BC","sourcesContent":["export class HMACUtils {\n private readonly _crypto: Crypto\n private readonly params = {\n name: 'HMAC',\n hash: 'SHA-512',\n }\n\n constructor(crypto: Crypto) {\n this._crypto = crypto\n }\n\n async generateKey(): Promise<CryptoKey> {\n return this._crypto.subtle.generateKey({ ...this.params }, true, ['sign', 'verify'])\n }\n\n async exportKey(key: CryptoKey): Promise<ArrayBuffer> {\n return this._crypto.subtle.exportKey('raw', key)\n }\n\n async importKey(key: ArrayBuffer): Promise<CryptoKey> {\n return this._crypto.subtle.importKey('raw', key, { ...this.params }, true, ['sign', 'verify'])\n }\n\n async sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {\n return this._crypto.subtle.sign({ ...this.params }, key, data)\n }\n\n async verify(key: CryptoKey, data: ArrayBuffer, signature: ArrayBuffer): Promise<boolean> {\n return this._crypto.subtle.verify({ ...this.params }, key, signature, data)\n }\n}\n"]}
@@ -191,6 +191,9 @@ class SecureDelegationsManager {
191
191
  };
192
192
  }
193
193
  else if (!delegateInfo.requiresAnonymousDelegations && this.selfNeedsAnonymousDelegations) {
194
+ /**
195
+ * Important: this requires that the exchange data signature also validates the authenticity of the public keys included in there.
196
+ */
194
197
  const fingerprintsOfVerifiedExchangeData = new Set(Object.keys(exchangeData.exchangeKey));
195
198
  const delegateVerifiedKeys = {};
196
199
  for (const keyHex of [...delegateInfo.availablePublicKeysHexWithSha1, ...delegateInfo.availablePublicKeysHexWithSha256]) {