@icure/api 7.1.16 → 8.0.0-RC.2

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 (363) hide show
  1. package/icc-api/api/IccAccesslogApi.d.ts +12 -1
  2. package/icc-api/api/IccAccesslogApi.js +142 -98
  3. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  4. package/icc-api/api/IccBemikronoApi.d.ts +81 -0
  5. package/icc-api/api/IccBemikronoApi.js +163 -0
  6. package/icc-api/api/IccBemikronoApi.js.map +1 -0
  7. package/icc-api/api/IccCalendarItemApi.d.ts +21 -1
  8. package/icc-api/api/IccCalendarItemApi.js +183 -117
  9. package/icc-api/api/IccCalendarItemApi.js.map +1 -1
  10. package/icc-api/api/IccClassificationApi.d.ts +21 -1
  11. package/icc-api/api/IccClassificationApi.js +119 -63
  12. package/icc-api/api/IccClassificationApi.js.map +1 -1
  13. package/icc-api/api/IccContactApi.d.ts +21 -1
  14. package/icc-api/api/IccContactApi.js +385 -294
  15. package/icc-api/api/IccContactApi.js.map +1 -1
  16. package/icc-api/api/IccDocumentApi.d.ts +38 -25
  17. package/icc-api/api/IccDocumentApi.js +279 -212
  18. package/icc-api/api/IccDocumentApi.js.map +1 -1
  19. package/icc-api/api/IccExchangeDataApi.d.ts +19 -0
  20. package/icc-api/api/IccExchangeDataApi.js +85 -0
  21. package/icc-api/api/IccExchangeDataApi.js.map +1 -0
  22. package/icc-api/api/IccExchangeDataMapApi.d.ts +18 -0
  23. package/icc-api/api/IccExchangeDataMapApi.js +65 -0
  24. package/icc-api/api/IccExchangeDataMapApi.js.map +1 -0
  25. package/icc-api/api/IccFormApi.d.ts +21 -1
  26. package/icc-api/api/IccFormApi.js +321 -229
  27. package/icc-api/api/IccFormApi.js.map +1 -1
  28. package/icc-api/api/IccHelementApi.d.ts +21 -1
  29. package/icc-api/api/IccHelementApi.js +207 -137
  30. package/icc-api/api/IccHelementApi.js.map +1 -1
  31. package/icc-api/api/IccInvoiceApi.d.ts +21 -1
  32. package/icc-api/api/IccInvoiceApi.js +404 -298
  33. package/icc-api/api/IccInvoiceApi.js.map +1 -1
  34. package/icc-api/api/IccMaintenanceTaskApi.d.ts +12 -1
  35. package/icc-api/api/IccMaintenanceTaskApi.js +79 -43
  36. package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -1
  37. package/icc-api/api/IccMessageApi.d.ts +28 -1
  38. package/icc-api/api/IccMessageApi.js +294 -191
  39. package/icc-api/api/IccMessageApi.js.map +1 -1
  40. package/icc-api/api/IccPatientApi.d.ts +12 -1
  41. package/icc-api/api/IccPatientApi.js +447 -351
  42. package/icc-api/api/IccPatientApi.js.map +1 -1
  43. package/icc-api/api/IccReceiptApi.d.ts +22 -8
  44. package/icc-api/api/IccReceiptApi.js +121 -64
  45. package/icc-api/api/IccReceiptApi.js.map +1 -1
  46. package/icc-api/api/IccRestApiPath.js +1 -1
  47. package/icc-api/api/IccRestApiPath.js.map +1 -1
  48. package/icc-api/api/IccSecureDelegationKeyMapApi.d.ts +26 -0
  49. package/icc-api/api/IccSecureDelegationKeyMapApi.js +71 -0
  50. package/icc-api/api/IccSecureDelegationKeyMapApi.js.map +1 -0
  51. package/icc-api/api/IccTimeTableApi.d.ts +12 -1
  52. package/icc-api/api/IccTimeTableApi.js +86 -48
  53. package/icc-api/api/IccTimeTableApi.js.map +1 -1
  54. package/icc-api/api/IccTopicApi.d.ts +90 -0
  55. package/icc-api/api/IccTopicApi.js +193 -0
  56. package/icc-api/api/IccTopicApi.js.map +1 -0
  57. package/icc-api/index.d.ts +2 -0
  58. package/icc-api/index.js +2 -0
  59. package/icc-api/index.js.map +1 -1
  60. package/icc-api/model/AbstractFilterMessage.d.ts +15 -0
  61. package/icc-api/model/AbstractFilterMessage.js +21 -0
  62. package/icc-api/model/AbstractFilterMessage.js.map +1 -0
  63. package/icc-api/model/AbstractFilterTopic.d.ts +15 -0
  64. package/icc-api/model/AbstractFilterTopic.js +21 -0
  65. package/icc-api/model/AbstractFilterTopic.js.map +1 -0
  66. package/icc-api/model/AccessLog.d.ts +2 -0
  67. package/icc-api/model/AccessLog.js.map +1 -1
  68. package/icc-api/model/Article.d.ts +2 -0
  69. package/icc-api/model/Article.js.map +1 -1
  70. package/icc-api/model/CalendarItem.d.ts +2 -0
  71. package/icc-api/model/CalendarItem.js.map +1 -1
  72. package/icc-api/model/Classification.d.ts +2 -0
  73. package/icc-api/model/Classification.js.map +1 -1
  74. package/icc-api/model/ClassificationTemplate.d.ts +2 -0
  75. package/icc-api/model/ClassificationTemplate.js.map +1 -1
  76. package/icc-api/model/Connection.d.ts +1 -1
  77. package/icc-api/model/Connection.js.map +1 -1
  78. package/icc-api/model/Contact.d.ts +2 -0
  79. package/icc-api/model/Contact.js.map +1 -1
  80. package/icc-api/model/Device.d.ts +4 -4
  81. package/icc-api/model/Device.js.map +1 -1
  82. package/icc-api/model/Document.d.ts +2 -0
  83. package/icc-api/model/Document.js.map +1 -1
  84. package/icc-api/model/ExchangeDataMapCreationBatch.d.ts +13 -0
  85. package/icc-api/model/ExchangeDataMapCreationBatch.js +10 -0
  86. package/icc-api/model/ExchangeDataMapCreationBatch.js.map +1 -0
  87. package/icc-api/model/FilterChainMessage.d.ts +19 -0
  88. package/icc-api/model/FilterChainMessage.js +11 -0
  89. package/icc-api/model/FilterChainMessage.js.map +1 -0
  90. package/icc-api/model/FilterChainTopic.d.ts +19 -0
  91. package/icc-api/model/FilterChainTopic.js +11 -0
  92. package/icc-api/model/FilterChainTopic.js.map +1 -0
  93. package/icc-api/model/Form.d.ts +2 -0
  94. package/icc-api/model/Form.js.map +1 -1
  95. package/icc-api/model/HealthElement.d.ts +2 -0
  96. package/icc-api/model/HealthElement.js.map +1 -1
  97. package/icc-api/model/HealthcareParty.d.ts +2 -2
  98. package/icc-api/model/HealthcareParty.js +13 -1
  99. package/icc-api/model/HealthcareParty.js.map +1 -1
  100. package/icc-api/model/IcureStub.d.ts +2 -0
  101. package/icc-api/model/IcureStub.js.map +1 -1
  102. package/icc-api/model/Invoice.d.ts +2 -0
  103. package/icc-api/model/Invoice.js.map +1 -1
  104. package/icc-api/model/MaintenanceTask.d.ts +13 -10
  105. package/icc-api/model/MaintenanceTask.js +13 -11
  106. package/icc-api/model/MaintenanceTask.js.map +1 -1
  107. package/icc-api/model/Message.d.ts +2 -0
  108. package/icc-api/model/Message.js.map +1 -1
  109. package/icc-api/model/PaginatedListExchangeData.d.ts +9 -0
  110. package/icc-api/model/PaginatedListExchangeData.js +10 -0
  111. package/icc-api/model/PaginatedListExchangeData.js.map +1 -0
  112. package/icc-api/model/PaginatedListTopic.d.ts +20 -0
  113. package/icc-api/model/PaginatedListTopic.js +10 -0
  114. package/icc-api/model/PaginatedListTopic.js.map +1 -0
  115. package/icc-api/model/Patient.d.ts +4 -2
  116. package/icc-api/model/Patient.js.map +1 -1
  117. package/icc-api/model/PatientByHcPartyGenderEducationProfession.d.ts +31 -0
  118. package/icc-api/model/PatientByHcPartyGenderEducationProfession.js +32 -0
  119. package/icc-api/model/PatientByHcPartyGenderEducationProfession.js.map +1 -0
  120. package/icc-api/model/Receipt.d.ts +2 -0
  121. package/icc-api/model/Receipt.js.map +1 -1
  122. package/icc-api/model/SecureDelegation.d.ts +52 -0
  123. package/icc-api/model/SecureDelegation.js +16 -0
  124. package/icc-api/model/SecureDelegation.js.map +1 -0
  125. package/icc-api/model/SecurityMetadata.d.ts +33 -0
  126. package/icc-api/model/SecurityMetadata.js +13 -0
  127. package/icc-api/model/SecurityMetadata.js.map +1 -0
  128. package/icc-api/model/Service.d.ts +2 -0
  129. package/icc-api/model/Service.js.map +1 -1
  130. package/icc-api/model/TimeTable.d.ts +2 -0
  131. package/icc-api/model/TimeTable.js.map +1 -1
  132. package/icc-api/model/Topic.d.ts +95 -0
  133. package/icc-api/model/Topic.js +16 -0
  134. package/icc-api/model/Topic.js.map +1 -0
  135. package/icc-api/model/internal/ExchangeData.d.ts +64 -0
  136. package/icc-api/model/internal/ExchangeData.js +15 -0
  137. package/icc-api/model/internal/ExchangeData.js.map +1 -0
  138. package/icc-api/model/internal/ExchangeDataMap.d.ts +24 -0
  139. package/icc-api/model/internal/ExchangeDataMap.js +13 -0
  140. package/icc-api/model/internal/ExchangeDataMap.js.map +1 -0
  141. package/icc-api/model/internal/SecureDelegationKeyMap.d.ts +14 -0
  142. package/icc-api/model/internal/SecureDelegationKeyMap.js +13 -0
  143. package/icc-api/model/internal/SecureDelegationKeyMap.js.map +1 -0
  144. package/icc-api/model/models.d.ts +26 -40
  145. package/icc-api/model/models.js +19 -37
  146. package/icc-api/model/models.js.map +1 -1
  147. package/icc-api/model/requests/EntityBulkShareResult.d.ts +28 -0
  148. package/icc-api/model/requests/EntityBulkShareResult.js +16 -0
  149. package/icc-api/model/requests/EntityBulkShareResult.js.map +1 -0
  150. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.d.ts +10 -0
  151. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js +17 -0
  152. package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js.map +1 -0
  153. package/icc-api/model/requests/EntityShareRequest.d.ts +110 -0
  154. package/icc-api/model/requests/EntityShareRequest.js +63 -0
  155. package/icc-api/model/requests/EntityShareRequest.js.map +1 -0
  156. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.d.ts +54 -0
  157. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js +24 -0
  158. package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js.map +1 -0
  159. package/icc-api/model/requests/MinimalEntityBulkShareResult.d.ts +23 -0
  160. package/icc-api/model/requests/MinimalEntityBulkShareResult.js +13 -0
  161. package/icc-api/model/requests/MinimalEntityBulkShareResult.js.map +1 -0
  162. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.d.ts +21 -0
  163. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js +14 -0
  164. package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js.map +1 -0
  165. package/icc-x-api/basexapi/EncryptedEntityXApi.d.ts +55 -6
  166. package/icc-x-api/basexapi/EncryptedEntityXApi.js.map +1 -1
  167. package/icc-x-api/crypto/AES.js +1 -1
  168. package/icc-x-api/crypto/AES.js.map +1 -1
  169. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.d.ts +18 -0
  170. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js +50 -0
  171. package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js.map +1 -0
  172. package/icc-x-api/crypto/AccessControlSecretUtils.d.ts +43 -0
  173. package/icc-x-api/crypto/AccessControlSecretUtils.js +97 -0
  174. package/icc-x-api/crypto/AccessControlSecretUtils.js.map +1 -0
  175. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +146 -0
  176. package/icc-x-api/crypto/BaseExchangeDataManager.js +342 -0
  177. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -0
  178. package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +0 -18
  179. package/icc-x-api/crypto/BaseExchangeKeysManager.js +11 -85
  180. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  181. package/icc-x-api/crypto/ConfidentialEntities.d.ts +26 -16
  182. package/icc-x-api/crypto/ConfidentialEntities.js +30 -17
  183. package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -1
  184. package/icc-x-api/crypto/CryptoStrategies.d.ts +8 -1
  185. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
  186. package/icc-x-api/crypto/DelegationsDeAnonymization.d.ts +44 -0
  187. package/icc-x-api/crypto/DelegationsDeAnonymization.js +235 -0
  188. package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -0
  189. package/icc-x-api/crypto/ExchangeDataManager.d.ts +97 -0
  190. package/icc-x-api/crypto/ExchangeDataManager.js +501 -0
  191. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -0
  192. package/icc-x-api/crypto/ExchangeDataMapManager.d.ts +32 -0
  193. package/icc-x-api/crypto/ExchangeDataMapManager.js +70 -0
  194. package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -0
  195. package/icc-x-api/crypto/ExchangeKeysManager.d.ts +4 -16
  196. package/icc-x-api/crypto/ExchangeKeysManager.js +4 -62
  197. package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
  198. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +326 -0
  199. package/icc-x-api/crypto/ExtendedApisUtils.js +3 -0
  200. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -0
  201. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +174 -0
  202. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +559 -0
  203. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -0
  204. package/icc-x-api/crypto/KeyRecovery.d.ts +5 -2
  205. package/icc-x-api/crypto/KeyRecovery.js +59 -29
  206. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  207. package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +7 -2
  208. package/icc-x-api/crypto/LegacyCryptoStrategies.js +8 -1
  209. package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -1
  210. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.d.ts +33 -0
  211. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js +141 -0
  212. package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js.map +1 -0
  213. package/icc-x-api/crypto/RSA.d.ts +34 -8
  214. package/icc-x-api/crypto/RSA.js +80 -13
  215. package/icc-x-api/crypto/RSA.js.map +1 -1
  216. package/icc-x-api/crypto/SecureDelegationsEncryption.d.ts +54 -0
  217. package/icc-x-api/crypto/SecureDelegationsEncryption.js +178 -0
  218. package/icc-x-api/crypto/SecureDelegationsEncryption.js.map +1 -0
  219. package/icc-x-api/crypto/SecureDelegationsManager.d.ts +66 -0
  220. package/icc-x-api/crypto/SecureDelegationsManager.js +261 -0
  221. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -0
  222. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.d.ts +46 -0
  223. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js +312 -0
  224. package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js.map +1 -0
  225. package/icc-x-api/crypto/SecurityMetadataDecryptor.d.ts +97 -0
  226. package/icc-x-api/crypto/SecurityMetadataDecryptor.js +79 -0
  227. package/icc-x-api/crypto/SecurityMetadataDecryptor.js.map +1 -0
  228. package/icc-x-api/crypto/ShamirKeysManager.d.ts +5 -5
  229. package/icc-x-api/crypto/ShamirKeysManager.js +6 -9
  230. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  231. package/icc-x-api/crypto/TransferKeysManager.d.ts +8 -6
  232. package/icc-x-api/crypto/TransferKeysManager.js +75 -52
  233. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  234. package/icc-x-api/crypto/{KeyManager.d.ts → UserEncryptionKeysManager.d.ts} +4 -6
  235. package/icc-x-api/crypto/{KeyManager.js → UserEncryptionKeysManager.js} +43 -23
  236. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -0
  237. package/icc-x-api/crypto/UserSignatureKeysManager.d.ts +26 -0
  238. package/icc-x-api/crypto/UserSignatureKeysManager.js +74 -0
  239. package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -0
  240. package/icc-x-api/crypto/utils.d.ts +61 -11
  241. package/icc-x-api/crypto/utils.js +113 -44
  242. package/icc-x-api/crypto/utils.js.map +1 -1
  243. package/icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter.d.ts +8 -0
  244. package/icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter.js +13 -0
  245. package/icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter.js.map +1 -0
  246. package/icc-x-api/filters/MessageByHcPartyFilter.d.ts +7 -0
  247. package/icc-x-api/filters/MessageByHcPartyFilter.js +13 -0
  248. package/icc-x-api/filters/MessageByHcPartyFilter.js.map +1 -0
  249. package/icc-x-api/filters/MessageByHcPartyTransportGuidFilter.d.ts +8 -0
  250. package/icc-x-api/filters/MessageByHcPartyTransportGuidFilter.js +13 -0
  251. package/icc-x-api/filters/MessageByHcPartyTransportGuidFilter.js.map +1 -0
  252. package/icc-x-api/filters/TopicByHcPartyFilter.d.ts +7 -0
  253. package/icc-x-api/filters/TopicByHcPartyFilter.js +13 -0
  254. package/icc-x-api/filters/TopicByHcPartyFilter.js.map +1 -0
  255. package/icc-x-api/filters/TopicByParticipantFilter.d.ts +7 -0
  256. package/icc-x-api/filters/TopicByParticipantFilter.js +13 -0
  257. package/icc-x-api/filters/TopicByParticipantFilter.js.map +1 -0
  258. package/icc-x-api/filters/filters.d.ts +5 -0
  259. package/icc-x-api/filters/filters.js +5 -0
  260. package/icc-x-api/filters/filters.js.map +1 -1
  261. package/icc-x-api/icc-accesslog-x-api.d.ts +49 -12
  262. package/icc-x-api/icc-accesslog-x-api.js +81 -44
  263. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  264. package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -15
  265. package/icc-x-api/icc-calendar-item-x-api.js +105 -51
  266. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  267. package/icc-x-api/icc-classification-x-api.d.ts +47 -10
  268. package/icc-x-api/icc-classification-x-api.js +62 -33
  269. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  270. package/icc-x-api/icc-contact-x-api.d.ts +59 -33
  271. package/icc-x-api/icc-contact-x-api.js +101 -66
  272. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  273. package/icc-x-api/icc-crypto-x-api.d.ts +33 -333
  274. package/icc-x-api/icc-crypto-x-api.js +47 -764
  275. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  276. package/icc-x-api/icc-data-owner-x-api.d.ts +20 -8
  277. package/icc-x-api/icc-data-owner-x-api.js +31 -10
  278. package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
  279. package/icc-x-api/icc-document-x-api.d.ts +51 -12
  280. package/icc-x-api/icc-document-x-api.js +117 -66
  281. package/icc-x-api/icc-document-x-api.js.map +1 -1
  282. package/icc-x-api/icc-form-x-api.d.ts +48 -11
  283. package/icc-x-api/icc-form-x-api.js +71 -37
  284. package/icc-x-api/icc-form-x-api.js.map +1 -1
  285. package/icc-x-api/icc-hcparty-x-api.d.ts +2 -2
  286. package/icc-x-api/icc-hcparty-x-api.js +3 -3
  287. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  288. package/icc-x-api/icc-helement-x-api.d.ts +59 -20
  289. package/icc-x-api/icc-helement-x-api.js +78 -43
  290. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  291. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +7 -2
  292. package/icc-x-api/icc-icure-maintenance-x-api.js +38 -27
  293. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  294. package/icc-x-api/icc-invoice-x-api.d.ts +53 -16
  295. package/icc-x-api/icc-invoice-x-api.js +69 -35
  296. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  297. package/icc-x-api/icc-maintenance-task-x-api.d.ts +56 -22
  298. package/icc-x-api/icc-maintenance-task-x-api.js +77 -36
  299. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  300. package/icc-x-api/icc-message-x-api.d.ts +75 -19
  301. package/icc-x-api/icc-message-x-api.js +126 -37
  302. package/icc-x-api/icc-message-x-api.js.map +1 -1
  303. package/icc-x-api/icc-patient-x-api.d.ts +86 -29
  304. package/icc-x-api/icc-patient-x-api.js +318 -379
  305. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  306. package/icc-x-api/icc-receipt-x-api.d.ts +47 -13
  307. package/icc-x-api/icc-receipt-x-api.js +72 -36
  308. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  309. package/icc-x-api/icc-time-table-x-api.d.ts +46 -13
  310. package/icc-x-api/icc-time-table-x-api.js +61 -27
  311. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  312. package/icc-x-api/icc-topic-x-api.d.ts +191 -0
  313. package/icc-x-api/icc-topic-x-api.js +307 -0
  314. package/icc-x-api/icc-topic-x-api.js.map +1 -0
  315. package/icc-x-api/icc-user-x-api.d.ts +2 -2
  316. package/icc-x-api/icc-user-x-api.js +3 -3
  317. package/icc-x-api/icc-user-x-api.js.map +1 -1
  318. package/icc-x-api/index.d.ts +18 -2
  319. package/icc-x-api/index.js +203 -156
  320. package/icc-x-api/index.js.map +1 -1
  321. package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +1 -1
  322. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +2 -0
  323. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +9 -2
  324. package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -1
  325. package/icc-x-api/storage/IcureStorageFacade.d.ts +23 -2
  326. package/icc-x-api/storage/IcureStorageFacade.js +36 -2
  327. package/icc-x-api/storage/IcureStorageFacade.js.map +1 -1
  328. package/icc-x-api/storage/KeyStorageFacade.d.ts +12 -0
  329. package/icc-x-api/storage/KeyStorageFacade.js.map +1 -1
  330. package/icc-x-api/storage/KeyStorageImpl.d.ts +2 -0
  331. package/icc-x-api/storage/KeyStorageImpl.js +10 -0
  332. package/icc-x-api/storage/KeyStorageImpl.js.map +1 -1
  333. package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +14 -1
  334. package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -1
  335. package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +32 -0
  336. package/icc-x-api/utils/EntityWithDelegationTypeName.js +75 -0
  337. package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -0
  338. package/icc-x-api/utils/ShareResult.d.ts +74 -0
  339. package/icc-x-api/utils/ShareResult.js +61 -0
  340. package/icc-x-api/utils/ShareResult.js.map +1 -0
  341. package/icc-x-api/utils/binary-utils.d.ts +1 -0
  342. package/icc-x-api/utils/binary-utils.js +8 -1
  343. package/icc-x-api/utils/binary-utils.js.map +1 -1
  344. package/icc-x-api/utils/collection-utils.d.ts +5 -0
  345. package/icc-x-api/utils/collection-utils.js +26 -1
  346. package/icc-x-api/utils/collection-utils.js.map +1 -1
  347. package/icc-x-api/utils/crypto-utils.d.ts +4 -3
  348. package/icc-x-api/utils/crypto-utils.js +5 -4
  349. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  350. package/icc-x-api/utils/lru-temporised-async-cache.d.ts +26 -3
  351. package/icc-x-api/utils/lru-temporised-async-cache.js +75 -15
  352. package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -1
  353. package/icc-x-api/utils/websocket.d.ts +14 -10
  354. package/icc-x-api/utils/websocket.js +26 -9
  355. package/icc-x-api/utils/websocket.js.map +1 -1
  356. package/index.d.ts +1 -1
  357. package/index.js +3 -1
  358. package/index.js.map +1 -1
  359. package/package.json +2 -3
  360. package/icc-x-api/crypto/EntitiesEncryption.d.ts +0 -275
  361. package/icc-x-api/crypto/EntitiesEncryption.js +0 -734
  362. package/icc-x-api/crypto/EntitiesEncryption.js.map +0 -1
  363. package/icc-x-api/crypto/KeyManager.js.map +0 -1
@@ -0,0 +1,501 @@
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.initialiseExchangeDataManagerForCurrentDataOwner = void 0;
13
+ const utils_1 = require("./utils");
14
+ const utils_2 = require("../utils");
15
+ const lru_temporised_async_cache_1 = require("../utils/lru-temporised-async-cache");
16
+ const EntityWithDelegationTypeName_1 = require("../utils/EntityWithDelegationTypeName");
17
+ const CryptoActorStub_1 = require("../../icc-api/model/CryptoActorStub");
18
+ /**
19
+ * @internal this function is for internal use only and may be changed without notice.
20
+ * Initialises and returns the exchange data manager which is most appropriate for the current data owner.
21
+ */
22
+ function initialiseExchangeDataManagerForCurrentDataOwner(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys, optionalParameters = {}) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const currentOwner = CryptoActorStub_1.CryptoActorStubWithType.fromDataOwner(yield dataOwnerApi.getCurrentDataOwner());
25
+ if (cryptoStrategies.dataOwnerRequiresAnonymousDelegation(currentOwner)) {
26
+ const res = new FullyCachedExchangeDataManager(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys);
27
+ yield res.clearOrRepopulateCache();
28
+ return res;
29
+ }
30
+ else {
31
+ return new LimitedLruCacheExchangeDataManager(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys, optionalParameters);
32
+ }
33
+ });
34
+ }
35
+ exports.initialiseExchangeDataManagerForCurrentDataOwner = initialiseExchangeDataManagerForCurrentDataOwner;
36
+ class AbstractExchangeDataManager {
37
+ constructor(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys) {
38
+ this.base = base;
39
+ this.encryptionKeys = encryptionKeys;
40
+ this.signatureKeys = signatureKeys;
41
+ this.accessControlSecret = accessControlSecret;
42
+ this.cryptoStrategies = cryptoStrategies;
43
+ this.dataOwnerApi = dataOwnerApi;
44
+ this.primitives = primitives;
45
+ this.useParentKeys = useParentKeys;
46
+ }
47
+ decryptData(data) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const decryptionKeys = this.encryptionKeys.getDecryptionKeys();
50
+ const decryptedKey = (yield this.base.tryDecryptExchangeKeys([data], decryptionKeys)).successfulDecryptions[0];
51
+ if (!decryptedKey)
52
+ return undefined;
53
+ const decryptedAccessControlSecret = (yield this.base.tryDecryptAccessControlSecret([data], decryptionKeys)).successfulDecryptions[0];
54
+ if (!decryptedAccessControlSecret)
55
+ throw new Error(`Decryption key could be decrypted but access control secret could not for data ${data}`);
56
+ return {
57
+ accessControlSecret: decryptedAccessControlSecret,
58
+ exchangeKey: decryptedKey,
59
+ verified: yield this.base.verifyExchangeData(data, (fp) => this.signatureKeys.getSignatureVerificationKey(fp)),
60
+ };
61
+ });
62
+ }
63
+ createNewExchangeData(delegateId, newDataId) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const encryptionKeys = {};
66
+ this.encryptionKeys.getSelfVerifiedKeys().forEach(({ fingerprint, pair }) => {
67
+ encryptionKeys[fingerprint] = pair.publicKey;
68
+ });
69
+ if (delegateId != (yield this.dataOwnerApi.getCurrentDataOwnerId())) {
70
+ const delegate = yield this.dataOwnerApi.getCryptoActorStub(delegateId);
71
+ const sha256KeysOfDelegate = (0, utils_1.hexPublicKeysWithSha256Of)(delegate.stub);
72
+ const sha1KeysOfDelegate = (0, utils_1.hexPublicKeysWithSha1Of)(delegate.stub);
73
+ let allVerifiedDelegateKeys;
74
+ if (this.useParentKeys && (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()).includes(delegateId)) {
75
+ allVerifiedDelegateKeys = yield this.encryptionKeys.getVerifiedPublicKeysFor(delegate.stub);
76
+ }
77
+ else {
78
+ allVerifiedDelegateKeys = yield this.cryptoStrategies.verifyDelegatePublicKeys(delegate, [...Array.from(sha256KeysOfDelegate), ...Array.from(sha1KeysOfDelegate)], this.primitives);
79
+ }
80
+ if (!allVerifiedDelegateKeys.length)
81
+ throw new Error(`Could not create exchange data to ${delegateId} as no public key for the delegate could be verified.`);
82
+ for (const delegateKey of allVerifiedDelegateKeys) {
83
+ if (sha1KeysOfDelegate.has(delegateKey)) {
84
+ encryptionKeys[(0, utils_1.fingerprintV1)(delegateKey)] = yield this.primitives.RSA.importKey('spki', (0, utils_2.hex2ua)(delegateKey), ['encrypt'], 'sha-1');
85
+ }
86
+ else if (sha256KeysOfDelegate.has(delegateKey)) {
87
+ encryptionKeys[(0, utils_1.fingerprintV1)(delegateKey)] = yield this.primitives.RSA.importKey('spki', (0, utils_2.hex2ua)(delegateKey), ['encrypt'], 'sha-256');
88
+ }
89
+ else
90
+ throw new Error('Illegal state: verified keys should contain only keys for OAPE-SHA1 or OAPE-SHA256.');
91
+ }
92
+ }
93
+ const signatureKey = yield this.signatureKeys.getOrCreateSignatureKeyPair();
94
+ const newData = yield this.base.createExchangeData(delegateId, { [signatureKey.fingerprint]: signatureKey.keyPair.privateKey }, encryptionKeys, newDataId ? { id: newDataId } : {});
95
+ return {
96
+ exchangeData: newData.exchangeData,
97
+ accessControlSecret: newData.accessControlSecret,
98
+ exchangeKey: newData.exchangeKey,
99
+ };
100
+ });
101
+ }
102
+ giveAccessBackTo(otherDataOwner, newDataOwnerPublicKey) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const self = yield this.dataOwnerApi.getCurrentDataOwnerId();
105
+ const newKeyFp = (0, utils_1.fingerprintV1)(newDataOwnerPublicKey);
106
+ const other = yield this.dataOwnerApi.getCryptoActorStub(otherDataOwner);
107
+ const newKeyHashVersion = (0, utils_1.getShaVersionForKey)(other.stub, newDataOwnerPublicKey);
108
+ if (!newKeyHashVersion)
109
+ throw new Error(`Public key not found for data owner ${otherDataOwner}`);
110
+ const importedNewKey = yield this.primitives.RSA.importKey('spki', (0, utils_2.hex2ua)(newDataOwnerPublicKey), ['encrypt'], newKeyHashVersion);
111
+ const signatureKey = yield this.signatureKeys.getOrCreateSignatureKeyPair();
112
+ const decryptionKeys = this.encryptionKeys.getDecryptionKeys();
113
+ const allExchangeDataToUpdate = self == otherDataOwner
114
+ ? yield this.base.getExchangeDataByDelegatorDelegatePair(self, self)
115
+ : [
116
+ ...(yield this.base.getExchangeDataByDelegatorDelegatePair(self, otherDataOwner)),
117
+ ...(yield this.base.getExchangeDataByDelegatorDelegatePair(otherDataOwner, self)),
118
+ ];
119
+ for (const dataToUpdate of allExchangeDataToUpdate) {
120
+ 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));
122
+ if (!updated) {
123
+ console.warn(`Failed to give access back to exchanged data ${JSON.stringify(dataToUpdate)}`);
124
+ }
125
+ }
126
+ }
127
+ });
128
+ }
129
+ clearOrRepopulateCache() {
130
+ throw new Error('Implemented by concrete class');
131
+ }
132
+ getOrCreateEncryptionDataTo(delegateId, entityType, entitySecretForeignKeys) {
133
+ throw new Error('Implemented by concrete class');
134
+ }
135
+ getCachedDecryptionDataKeyByAccessControlHash(hashes, entityType, entitySecretForeignKeys) {
136
+ throw new Error('Implemented by concrete class');
137
+ }
138
+ getDecryptionDataKeyById(id, entityType, entitySecretForeignKeys, retrieveIfNotCached) {
139
+ throw new Error('Implemented by concrete class');
140
+ }
141
+ getAccessControlKeysValue(entityType) {
142
+ throw new Error('Implemented by concrete class');
143
+ }
144
+ getAllDelegationKeys(entityType) {
145
+ throw new Error('Implemented by concrete class');
146
+ }
147
+ }
148
+ class FullyCachedExchangeDataManager extends AbstractExchangeDataManager {
149
+ constructor() {
150
+ super(...arguments);
151
+ this.caches = Promise.resolve({ dataById: {}, hashToId: new Map(), delegateToVerifiedEncryptionDataId: {}, entityTypeToAccessControlKeysValue: {} });
152
+ }
153
+ clearOrRepopulateCache() {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ this.caches = this.doRepopulateCache();
156
+ yield this.caches;
157
+ });
158
+ }
159
+ getCachedDecryptionDataKeyByAccessControlHash(hashes, entityType, entitySecretForeignKeys) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ function retrieveByHashesFromCaches(caches) {
162
+ return hashes.reduce((res, hash) => {
163
+ const id = caches.hashToId.get(hash);
164
+ if (id) {
165
+ const cached = caches.dataById[id];
166
+ if (cached === null || cached === void 0 ? void 0 : cached.decrypted) {
167
+ res[hash] = {
168
+ exchangeData: cached.exchangeData,
169
+ exchangeKey: cached.decrypted.exchangeKey,
170
+ accessControlSecret: cached.decrypted.accessControlSecret,
171
+ };
172
+ }
173
+ }
174
+ return res;
175
+ }, {});
176
+ }
177
+ const retrievedFromHashesCache = retrieveByHashesFromCaches(yield this.caches);
178
+ if (Object.keys(retrievedFromHashesCache).length) {
179
+ return retrievedFromHashesCache;
180
+ }
181
+ else {
182
+ this.caches = this.caches.then((caches) => __awaiter(this, void 0, void 0, function* () {
183
+ for (const currData of Object.values(caches.dataById)) {
184
+ if (currData.decrypted) {
185
+ const currDataHashes = yield this.accessControlSecret.secureDelegationKeysFor(currData.decrypted.accessControlSecret, entityType, entitySecretForeignKeys);
186
+ currDataHashes.forEach((hash) => caches.hashToId.set(hash, currData.exchangeData.id));
187
+ }
188
+ }
189
+ return caches;
190
+ }));
191
+ return retrieveByHashesFromCaches(yield this.caches);
192
+ }
193
+ });
194
+ }
195
+ getOrCreateEncryptionDataTo(delegateId, entityType, entitySecretForeignKeys) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ const caches = yield this.caches;
198
+ const dataId = caches.delegateToVerifiedEncryptionDataId[delegateId];
199
+ const cached = dataId ? caches.dataById[dataId] : undefined;
200
+ if (cached && (cached === null || cached === void 0 ? void 0 : cached.decrypted)) {
201
+ return {
202
+ exchangeData: cached.exchangeData,
203
+ accessControlSecret: cached.decrypted.accessControlSecret,
204
+ exchangeKey: cached.decrypted.exchangeKey,
205
+ };
206
+ }
207
+ const created = yield this.createNewExchangeData(delegateId);
208
+ this.cacheData(created.exchangeData, { accessControlSecret: created.accessControlSecret, exchangeKey: created.exchangeKey, verified: true }, entityType, entitySecretForeignKeys);
209
+ return created;
210
+ });
211
+ }
212
+ getDecryptionDataKeyById(id, entityType, entitySecretForeignKeys, retrieveIfNotCached) {
213
+ var _a, _b;
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ const caches = yield this.caches;
216
+ const cachedData = caches.dataById[id];
217
+ if (cachedData) {
218
+ return {
219
+ exchangeData: cachedData.exchangeData,
220
+ exchangeKey: (_a = cachedData.decrypted) === null || _a === void 0 ? void 0 : _a.exchangeKey,
221
+ accessControlSecret: (_b = cachedData.decrypted) === null || _b === void 0 ? void 0 : _b.accessControlSecret,
222
+ };
223
+ }
224
+ else if (retrieveIfNotCached) {
225
+ const data = yield this.base.getExchangeDataById(id);
226
+ if (!data)
227
+ throw new Error(`Could not find exchange data with id ${id}`);
228
+ const decrypted = yield this.decryptData(data);
229
+ this.cacheData(data, decrypted, entityType, entitySecretForeignKeys);
230
+ return { exchangeData: data, exchangeKey: decrypted === null || decrypted === void 0 ? void 0 : decrypted.exchangeKey, accessControlSecret: decrypted === null || decrypted === void 0 ? void 0 : decrypted.accessControlSecret };
231
+ }
232
+ else
233
+ return undefined;
234
+ });
235
+ }
236
+ cacheData(exchangeData, decrypted, entityType, entitySecretForeignKeys) {
237
+ this.caches = this.caches.then((caches) => __awaiter(this, void 0, void 0, function* () {
238
+ caches.dataById[exchangeData.id] = { exchangeData, decrypted };
239
+ if (decrypted) {
240
+ // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact
241
+ // `secureDelegationKeysFor` is currently ignoring the sfks
242
+ if (entityType && entitySecretForeignKeys) {
243
+ const hashes = yield this.accessControlSecret.secureDelegationKeysFor(decrypted.accessControlSecret, entityType, entitySecretForeignKeys);
244
+ hashes.forEach((hash) => {
245
+ caches.hashToId.set(hash, exchangeData.id);
246
+ });
247
+ }
248
+ if (decrypted.verified) {
249
+ caches.delegateToVerifiedEncryptionDataId[exchangeData.delegate] = exchangeData.id;
250
+ }
251
+ }
252
+ return caches;
253
+ }));
254
+ }
255
+ doRepopulateCache() {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ const allData = yield this.base.getAllExchangeDataForCurrentDataOwnerIfAllowed();
258
+ if (!allData)
259
+ throw new Error('Impossible to use fully cached exchange data manager for current data owner.');
260
+ const dataById = {};
261
+ const hashToId = new Map();
262
+ const delegateToVerifiedEncryptionDataId = {};
263
+ for (const currData of allData) {
264
+ const currDecrypted = yield this.decryptData(currData);
265
+ dataById[currData.id] = { exchangeData: currData, decrypted: currDecrypted };
266
+ if (currDecrypted === null || currDecrypted === void 0 ? void 0 : currDecrypted.verified) {
267
+ delegateToVerifiedEncryptionDataId[currData.delegate] = currData.id;
268
+ }
269
+ }
270
+ const entityTypeToAccessControlKeysValue = {};
271
+ return { dataById, hashToId, delegateToVerifiedEncryptionDataId, entityTypeToAccessControlKeysValue };
272
+ });
273
+ }
274
+ getAccessControlKeysValue(entityType) {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ const caches = yield this.caches;
277
+ const cached = caches.entityTypeToAccessControlKeysValue[entityType];
278
+ if (cached)
279
+ return cached;
280
+ const accessControlSecrets = Object.values(caches.dataById).flatMap((x) => (x.decrypted ? [x.decrypted.accessControlSecret] : []));
281
+ const fullData = yield this.accessControlSecret.getEncodedAccessControlKeys(accessControlSecrets, entityType);
282
+ caches.entityTypeToAccessControlKeysValue[entityType] = fullData;
283
+ return fullData;
284
+ });
285
+ }
286
+ getAllDelegationKeys(entityType) {
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ const caches = yield this.caches;
289
+ const accessControlSecrets = Object.values(caches.dataById).flatMap((x) => (x.decrypted ? [x.decrypted.accessControlSecret] : []));
290
+ const res = [];
291
+ for (const accessControlSecret of accessControlSecrets) {
292
+ // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact
293
+ res.push(yield this.accessControlSecret.secureDelegationKeyFor(accessControlSecret, entityType, undefined));
294
+ }
295
+ return res;
296
+ });
297
+ }
298
+ }
299
+ class LimitedLruCacheExchangeDataManager extends AbstractExchangeDataManager {
300
+ constructor(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys, optionalParameters) {
301
+ var _a;
302
+ super(base, encryptionKeys, signatureKeys, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys);
303
+ this.hashToId = new Map();
304
+ this.delegateToVerifiedEncryptionDataId = new Map();
305
+ this.idToDataCache = new lru_temporised_async_cache_1.LruTemporisedAsyncCache((_a = optionalParameters.lruCacheSize) !== null && _a !== void 0 ? _a : 2000, () => -1);
306
+ }
307
+ clearOrRepopulateCache() {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ this.idToDataCache.clear(false);
310
+ this.hashToId.clear();
311
+ this.delegateToVerifiedEncryptionDataId.clear();
312
+ });
313
+ }
314
+ getCachedDecryptionDataKeyByAccessControlHash(hashes, entityType, entitySecretForeignKeys) {
315
+ return __awaiter(this, void 0, void 0, function* () {
316
+ const res = {};
317
+ for (const hash of hashes) {
318
+ const dataId = this.hashToId.get(hash);
319
+ if (dataId) {
320
+ const retrieved = yield this.idToDataCache.get(dataId, () => {
321
+ throw new Error(`Data with id ${dataId} should have been already cached.`);
322
+ });
323
+ if (retrieved.decrypted) {
324
+ res[hash] = {
325
+ exchangeData: retrieved.exchangeData,
326
+ exchangeKey: retrieved.decrypted.exchangeKey,
327
+ accessControlSecret: retrieved.decrypted.accessControlSecret,
328
+ };
329
+ }
330
+ }
331
+ }
332
+ return res;
333
+ });
334
+ }
335
+ secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(accessControlSecret, entityType, entitySecretForeignKeys) {
336
+ return __awaiter(this, void 0, void 0, function* () {
337
+ const noSfkDelegationKeys = yield Promise.all([...EntityWithDelegationTypeName_1.entityWithDelegationTypeNames].map((t) => this.accessControlSecret.secureDelegationKeyFor(accessControlSecret, t, undefined)));
338
+ if (entityType && (entitySecretForeignKeys === null || entitySecretForeignKeys === void 0 ? void 0 : entitySecretForeignKeys.length)) {
339
+ // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users and it has some performance impact
340
+ // `secureDelegationKeysFor` is currently ignoring the sfks
341
+ return [
342
+ ...noSfkDelegationKeys,
343
+ ...(yield this.accessControlSecret.secureDelegationKeysFor(accessControlSecret, entityType, entitySecretForeignKeys)),
344
+ ];
345
+ }
346
+ else {
347
+ return noSfkDelegationKeys;
348
+ }
349
+ });
350
+ }
351
+ getDecryptionDataKeyById(id, entityType, entitySecretForeignKeys, retrieveIfNotCached) {
352
+ var _a, _b;
353
+ return __awaiter(this, void 0, void 0, function* () {
354
+ const cached = yield this.idToDataCache.getIfCachedJob(id);
355
+ if (cached) {
356
+ const updated = yield this.idToDataCache.get(id, (prevData) => __awaiter(this, void 0, void 0, function* () {
357
+ const toUpdate = prevData !== null && prevData !== void 0 ? prevData : cached.item;
358
+ if (toUpdate.decrypted) {
359
+ // Usage of sfks in secure delegation key should be configurable: it is not necessary for all users, and it has some performance impact
360
+ // `secureDelegationKeysFor` is currently ignoring the sfks
361
+ if (entityType && entitySecretForeignKeys) {
362
+ const hashes = yield this.accessControlSecret.secureDelegationKeysFor(toUpdate.decrypted.accessControlSecret, entityType, entitySecretForeignKeys);
363
+ hashes.forEach((hash) => {
364
+ this.hashToId.set(hash, toUpdate.exchangeData.id);
365
+ });
366
+ toUpdate.hashes.push(...hashes);
367
+ }
368
+ }
369
+ return { item: toUpdate, onEviction: (b) => this.doOnEvictionJob(b, toUpdate) };
370
+ }), () => true);
371
+ return {
372
+ exchangeData: updated.exchangeData,
373
+ exchangeKey: (_a = updated.decrypted) === null || _a === void 0 ? void 0 : _a.exchangeKey,
374
+ accessControlSecret: (_b = updated.decrypted) === null || _b === void 0 ? void 0 : _b.accessControlSecret,
375
+ };
376
+ }
377
+ else if (retrieveIfNotCached) {
378
+ return yield this.idToDataCache
379
+ .get(id, () => __awaiter(this, void 0, void 0, function* () {
380
+ return this.cacheJob(() => __awaiter(this, void 0, void 0, function* () {
381
+ const data = yield this.base.getExchangeDataById(id);
382
+ if (!data)
383
+ throw new Error(`Could not find exchange data with id ${id}`);
384
+ const decrypted = yield this.decryptData(data);
385
+ if (decrypted) {
386
+ const hashes = yield this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(decrypted.accessControlSecret, entityType, entitySecretForeignKeys);
387
+ return { exchangeData: data, hashes, decrypted, verified: decrypted.verified };
388
+ }
389
+ else {
390
+ return { exchangeData: data, hashes: [], verified: false };
391
+ }
392
+ }));
393
+ }))
394
+ .then((x) => { var _a, _b; return ({ exchangeData: x.exchangeData, exchangeKey: (_a = x.decrypted) === null || _a === void 0 ? void 0 : _a.exchangeKey, accessControlSecret: (_b = x.decrypted) === null || _b === void 0 ? void 0 : _b.accessControlSecret }); });
395
+ }
396
+ else
397
+ return undefined;
398
+ });
399
+ }
400
+ getOrCreateEncryptionDataTo(delegateId, entityType, entitySecretForeignKeys) {
401
+ return __awaiter(this, void 0, void 0, function* () {
402
+ let existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId);
403
+ if (!existingId) {
404
+ yield this.populateCacheToDelegate(delegateId, entityType, entitySecretForeignKeys);
405
+ existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId);
406
+ }
407
+ if (existingId) {
408
+ const cached = yield this.idToDataCache.getIfCachedJob(existingId);
409
+ if (!cached)
410
+ throw new Error(`Illegal state: data with id ${existingId} should have been in cache`);
411
+ if (cached.item.decrypted) {
412
+ return {
413
+ exchangeData: cached.item.exchangeData,
414
+ exchangeKey: cached.item.decrypted.exchangeKey,
415
+ accessControlSecret: cached.item.decrypted.accessControlSecret,
416
+ };
417
+ }
418
+ else
419
+ throw new Error(`Illegal state: cached verified data should be decrypted.`);
420
+ }
421
+ else {
422
+ const newDataId = this.primitives.randomUuid();
423
+ this.delegateToVerifiedEncryptionDataId.set(delegateId, newDataId);
424
+ const createdAndCachedData = yield this.idToDataCache.get(newDataId, () => this.cacheJob(() => __awaiter(this, void 0, void 0, function* () {
425
+ const created = yield this.createNewExchangeData(delegateId, newDataId);
426
+ const hashes = yield this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(created.accessControlSecret, entityType, entitySecretForeignKeys);
427
+ return {
428
+ exchangeData: created.exchangeData,
429
+ decrypted: {
430
+ accessControlSecret: created.accessControlSecret,
431
+ exchangeKey: created.exchangeKey,
432
+ verified: true,
433
+ },
434
+ hashes,
435
+ };
436
+ })));
437
+ if (!createdAndCachedData)
438
+ throw new Error('Data should have been successfully created');
439
+ return {
440
+ exchangeData: createdAndCachedData.exchangeData,
441
+ exchangeKey: createdAndCachedData.decrypted.exchangeKey,
442
+ accessControlSecret: createdAndCachedData.decrypted.accessControlSecret,
443
+ };
444
+ }
445
+ });
446
+ }
447
+ // 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
448
+ // the current data owner to the delegate which is good for encryption.
449
+ populateCacheToDelegate(delegateId, entityType, entitySecretForeignKeys) {
450
+ return __awaiter(this, void 0, void 0, function* () {
451
+ const dataToDelegate = yield this.base.getExchangeDataByDelegatorDelegatePair(yield this.dataOwnerApi.getCurrentDataOwnerId(), delegateId);
452
+ yield Promise.all(dataToDelegate.map((data) => __awaiter(this, void 0, void 0, function* () {
453
+ yield this.idToDataCache.get(data.id, () => this.cacheJob(() => __awaiter(this, void 0, void 0, function* () {
454
+ const decrypted = yield this.decryptData(data);
455
+ if (decrypted) {
456
+ const hashes = yield this.secureDelegationKeysForAllEntitiesNoSfkAndSpecificEntitySfksPairs(decrypted.accessControlSecret, entityType, entitySecretForeignKeys);
457
+ return { exchangeData: data, hashes, decrypted };
458
+ }
459
+ else {
460
+ return { exchangeData: data, hashes: [] };
461
+ }
462
+ })));
463
+ })));
464
+ });
465
+ }
466
+ cacheJob(retrieveDecryptedDataInfo) {
467
+ var _a;
468
+ return __awaiter(this, void 0, void 0, function* () {
469
+ const info = yield retrieveDecryptedDataInfo();
470
+ info.hashes.forEach((hash) => this.hashToId.set(hash, info === null || info === void 0 ? void 0 : info.exchangeData.id));
471
+ if ((_a = info.decrypted) === null || _a === void 0 ? void 0 : _a.verified)
472
+ this.delegateToVerifiedEncryptionDataId.set(info.exchangeData.delegate, info.exchangeData.id);
473
+ const item = {
474
+ exchangeData: info.exchangeData,
475
+ hashes: info.hashes,
476
+ decrypted: info.decrypted,
477
+ };
478
+ return {
479
+ item,
480
+ onEviction: (b) => this.doOnEvictionJob(b, item),
481
+ };
482
+ });
483
+ }
484
+ doOnEvictionJob(isReplacement, item) {
485
+ return __awaiter(this, void 0, void 0, function* () {
486
+ if (!isReplacement) {
487
+ item.hashes.forEach((hash) => this.hashToId.delete(hash));
488
+ if (this.delegateToVerifiedEncryptionDataId.get(item.exchangeData.delegate) === item.exchangeData.id) {
489
+ this.delegateToVerifiedEncryptionDataId.delete(item.exchangeData.delegate);
490
+ }
491
+ }
492
+ });
493
+ }
494
+ getAccessControlKeysValue(entityType) {
495
+ return Promise.resolve(undefined);
496
+ }
497
+ getAllDelegationKeys(entityType) {
498
+ return Promise.resolve(undefined);
499
+ }
500
+ }
501
+ //# sourceMappingURL=ExchangeDataManager.js.map
@@ -0,0 +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,CA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AY;gBAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B,CAAA;YACD,OAAO;gBACL,IAAI;gBACJ,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC;aACjD,CAAA;;KACF;IAEa,eAAe,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"]}