@icure/api 8.6.19 → 8.7.1

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 (326) hide show
  1. package/icc-api/api/IccDocumentApi.d.ts +10 -2
  2. package/icc-api/api/IccDocumentApi.js +22 -4
  3. package/icc-api/api/IccDocumentApi.js.map +1 -1
  4. package/icc-api/api/IccReceiptApi.d.ts +17 -0
  5. package/icc-api/api/IccReceiptApi.js +52 -0
  6. package/icc-api/api/IccReceiptApi.js.map +1 -1
  7. package/icc-api/model/DataAttachment.d.ts +22 -0
  8. package/icc-api/model/DataAttachment.js.map +1 -1
  9. package/icc-api/model/Document.d.ts +6 -0
  10. package/icc-api/model/Document.js.map +1 -1
  11. package/icc-api/model/Receipt.d.ts +6 -0
  12. package/icc-api/model/Receipt.js.map +1 -1
  13. package/icc-x-api/crypto/BaseExchangeDataManager.js +2 -2
  14. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  15. package/icc-x-api/crypto/ExchangeDataManager.js +3 -3
  16. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  17. package/icc-x-api/crypto/ExtendedApisUtils.d.ts +1 -1
  18. package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -1
  19. package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +1 -1
  20. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +8 -2
  21. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  22. package/icc-x-api/crypto/RecoveryDataEncryption.js.map +1 -1
  23. package/icc-x-api/icc-accesslog-x-api.js +7 -7
  24. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  25. package/icc-x-api/icc-calendar-item-x-api.js +7 -7
  26. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  27. package/icc-x-api/icc-classification-x-api.js +4 -5
  28. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  29. package/icc-x-api/icc-code-x-api.d.ts +2 -2
  30. package/icc-x-api/icc-code-x-api.js +3 -33
  31. package/icc-x-api/icc-code-x-api.js.map +1 -1
  32. package/icc-x-api/icc-contact-x-api.js +20 -33
  33. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  34. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  35. package/icc-x-api/icc-document-x-api.d.ts +8 -7
  36. package/icc-x-api/icc-document-x-api.js +64 -22
  37. package/icc-x-api/icc-document-x-api.js.map +1 -1
  38. package/icc-x-api/icc-form-x-api.js +3 -4
  39. package/icc-x-api/icc-form-x-api.js.map +1 -1
  40. package/icc-x-api/icc-helement-x-api.js +11 -11
  41. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  42. package/icc-x-api/icc-invoice-x-api.js +3 -4
  43. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  44. package/icc-x-api/icc-maintenance-task-x-api.js +3 -3
  45. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  46. package/icc-x-api/icc-patient-x-api.js +29 -29
  47. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  48. package/icc-x-api/icc-receipt-x-api.d.ts +40 -0
  49. package/icc-x-api/icc-receipt-x-api.js +79 -1
  50. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  51. package/icc-x-api/icc-topic-x-api.js.map +1 -1
  52. package/icc-x-api/utils/code-util.d.ts +23 -0
  53. package/icc-x-api/utils/code-util.js +39 -2
  54. package/icc-x-api/utils/code-util.js.map +1 -1
  55. package/icc-x-api/utils/collection-utils.d.ts +13 -0
  56. package/icc-x-api/utils/collection-utils.js +79 -0
  57. package/icc-x-api/utils/collection-utils.js.map +1 -1
  58. package/icc-x-api/utils/compression-utils.d.ts +28 -0
  59. package/icc-x-api/utils/compression-utils.js +106 -0
  60. package/icc-x-api/utils/compression-utils.js.map +1 -0
  61. package/icc-x-api/utils/crypto-utils.js +7 -7
  62. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  63. package/icc-x-api/utils/formatting-util.d.ts +3 -3
  64. package/icc-x-api/utils/formatting-util.js +22 -23
  65. package/icc-x-api/utils/formatting-util.js.map +1 -1
  66. package/icc-x-api/utils/hcp-util.js +2 -3
  67. package/icc-x-api/utils/hcp-util.js.map +1 -1
  68. package/icc-x-api/utils/insurability-util.js +10 -8
  69. package/icc-x-api/utils/insurability-util.js.map +1 -1
  70. package/icc-x-api/utils/lzma-wasm.d.ts +6 -0
  71. package/icc-x-api/utils/lzma-wasm.js +81 -0
  72. package/icc-x-api/utils/lzma-wasm.js.map +1 -0
  73. package/icc-x-api/utils/mutex.d.ts +12 -0
  74. package/icc-x-api/utils/mutex.js +26 -0
  75. package/icc-x-api/utils/mutex.js.map +1 -0
  76. package/icc-x-api/utils/websocket.js +7 -7
  77. package/icc-x-api/utils/websocket.js.map +1 -1
  78. package/icc-x-api/wasm/lzma/lzma.js +2 -0
  79. package/icc-x-api/wasm/lzma/lzma.wasm +0 -0
  80. package/package.json +2 -11
  81. package/icc-x-api/utils/uuid-encoder.d.ts +0 -44
  82. package/icc-x-api/utils/uuid-encoder.js +0 -114
  83. package/icc-x-api/utils/uuid-encoder.js.map +0 -1
  84. package/test/icc-api/api/IccAgendaApi.d.ts +0 -1
  85. package/test/icc-api/api/IccAgendaApi.js +0 -64
  86. package/test/icc-api/api/IccAgendaApi.js.map +0 -1
  87. package/test/icc-api/api/IccAnonymousAccessApi.d.ts +0 -1
  88. package/test/icc-api/api/IccAnonymousAccessApi.js +0 -58
  89. package/test/icc-api/api/IccAnonymousAccessApi.js.map +0 -1
  90. package/test/icc-api/api/IccCalendarItemApi.d.ts +0 -1
  91. package/test/icc-api/api/IccCalendarItemApi.js +0 -67
  92. package/test/icc-api/api/IccCalendarItemApi.js.map +0 -1
  93. package/test/icc-api/api/IccCalendarItemTypeApi.d.ts +0 -1
  94. package/test/icc-api/api/IccCalendarItemTypeApi.js +0 -96
  95. package/test/icc-api/api/IccCalendarItemTypeApi.js.map +0 -1
  96. package/test/icc-api/api/IccCodeApi.d.ts +0 -1
  97. package/test/icc-api/api/IccCodeApi.js +0 -38
  98. package/test/icc-api/api/IccCodeApi.js.map +0 -1
  99. package/test/icc-api/api/IccDocumentApi.d.ts +0 -1
  100. package/test/icc-api/api/IccDocumentApi.js +0 -199
  101. package/test/icc-api/api/IccDocumentApi.js.map +0 -1
  102. package/test/icc-api/api/IccGroupApi.d.ts +0 -1
  103. package/test/icc-api/api/IccGroupApi.js +0 -50
  104. package/test/icc-api/api/IccGroupApi.js.map +0 -1
  105. package/test/icc-api/api/IccKeywordApi.d.ts +0 -1
  106. package/test/icc-api/api/IccKeywordApi.js +0 -64
  107. package/test/icc-api/api/IccKeywordApi.js.map +0 -1
  108. package/test/icc-api/api/IccMedicalLocationApi.d.ts +0 -1
  109. package/test/icc-api/api/IccMedicalLocationApi.js +0 -64
  110. package/test/icc-api/api/IccMedicalLocationApi.js.map +0 -1
  111. package/test/icc-api/api/IccPlaceApi.d.ts +0 -1
  112. package/test/icc-api/api/IccPlaceApi.js +0 -64
  113. package/test/icc-api/api/IccPlaceApi.js.map +0 -1
  114. package/test/icc-api/api/IccRecoveryDataApi.d.ts +0 -1
  115. package/test/icc-api/api/IccRecoveryDataApi.js +0 -95
  116. package/test/icc-api/api/IccRecoveryDataApi.js.map +0 -1
  117. package/test/icc-api/api/IccRoleApi.d.ts +0 -1
  118. package/test/icc-api/api/IccRoleApi.js +0 -34
  119. package/test/icc-api/api/IccRoleApi.js.map +0 -1
  120. package/test/icc-api/api/IccUserApi.d.ts +0 -1
  121. package/test/icc-api/api/IccUserApi.js +0 -96
  122. package/test/icc-api/api/IccUserApi.js.map +0 -1
  123. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +0 -1
  124. package/test/icc-api/e2e/IccCalendarItemApi.js +0 -46
  125. package/test/icc-api/e2e/IccCalendarItemApi.js.map +0 -1
  126. package/test/icc-api/model/modelHelpersTest.d.ts +0 -1
  127. package/test/icc-api/model/modelHelpersTest.js +0 -45
  128. package/test/icc-api/model/modelHelpersTest.js.map +0 -1
  129. package/test/icc-x-api/auth/group-switch-test.d.ts +0 -1
  130. package/test/icc-x-api/auth/group-switch-test.js +0 -81
  131. package/test/icc-x-api/auth/group-switch-test.js.map +0 -1
  132. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +0 -2
  133. package/test/icc-x-api/auth/jwt-concurrency-test.js +0 -112
  134. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +0 -1
  135. package/test/icc-x-api/auth/jwt-provider-test.d.ts +0 -1
  136. package/test/icc-x-api/auth/jwt-provider-test.js +0 -197
  137. package/test/icc-x-api/auth/jwt-provider-test.js.map +0 -1
  138. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +0 -1
  139. package/test/icc-x-api/auth/smart-auth-provider-test.js +0 -224
  140. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +0 -1
  141. package/test/icc-x-api/autofix-anonymity-test.d.ts +0 -1
  142. package/test/icc-x-api/autofix-anonymity-test.js +0 -122
  143. package/test/icc-x-api/autofix-anonymity-test.js.map +0 -1
  144. package/test/icc-x-api/confidential-entities-test.d.ts +0 -1
  145. package/test/icc-x-api/confidential-entities-test.js +0 -168
  146. package/test/icc-x-api/confidential-entities-test.js.map +0 -1
  147. package/test/icc-x-api/crud/comprehensive-crud-test.d.ts +0 -1
  148. package/test/icc-x-api/crud/comprehensive-crud-test.js +0 -276
  149. package/test/icc-x-api/crud/comprehensive-crud-test.js.map +0 -1
  150. package/test/icc-x-api/crud/entities-crud-test-interface.d.ts +0 -16
  151. package/test/icc-x-api/crud/entities-crud-test-interface.js +0 -408
  152. package/test/icc-x-api/crud/entities-crud-test-interface.js.map +0 -1
  153. package/test/icc-x-api/crypto/anonymous-delegations-test.d.ts +0 -1
  154. package/test/icc-x-api/crypto/anonymous-delegations-test.js +0 -587
  155. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +0 -1
  156. package/test/icc-x-api/crypto/concurrency.d.ts +0 -1
  157. package/test/icc-x-api/crypto/concurrency.js +0 -35
  158. package/test/icc-x-api/crypto/concurrency.js.map +0 -1
  159. package/test/icc-x-api/crypto/crypto-utils.d.ts +0 -1
  160. package/test/icc-x-api/crypto/crypto-utils.js +0 -79
  161. package/test/icc-x-api/crypto/crypto-utils.js.map +0 -1
  162. package/test/icc-x-api/crypto/cryptoTest.d.ts +0 -2
  163. package/test/icc-x-api/crypto/cryptoTest.js +0 -402
  164. package/test/icc-x-api/crypto/cryptoTest.js.map +0 -1
  165. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +0 -1
  166. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +0 -166
  167. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +0 -1
  168. package/test/icc-x-api/crypto/exchange-data-manager-test.d.ts +0 -1
  169. package/test/icc-x-api/crypto/exchange-data-manager-test.js +0 -674
  170. package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +0 -1
  171. package/test/icc-x-api/crypto/full-crypto-test.d.ts +0 -1
  172. package/test/icc-x-api/crypto/full-crypto-test.js +0 -454
  173. package/test/icc-x-api/crypto/full-crypto-test.js.map +0 -1
  174. package/test/icc-x-api/crypto/legacy-metadata-migration-test.d.ts +0 -1
  175. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js +0 -379
  176. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js.map +0 -1
  177. package/test/icc-x-api/crypto/secure-delegations-manager-test.d.ts +0 -1
  178. package/test/icc-x-api/crypto/secure-delegations-manager-test.js +0 -278
  179. package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +0 -1
  180. package/test/icc-x-api/crypto/shamir.d.ts +0 -2
  181. package/test/icc-x-api/crypto/shamir.js +0 -167
  182. package/test/icc-x-api/crypto/shamir.js.map +0 -1
  183. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +0 -1
  184. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +0 -71
  185. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +0 -1
  186. package/test/icc-x-api/crypto/soft-deleted-data-owners.d.ts +0 -2
  187. package/test/icc-x-api/crypto/soft-deleted-data-owners.js +0 -113
  188. package/test/icc-x-api/crypto/soft-deleted-data-owners.js.map +0 -1
  189. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.d.ts +0 -1
  190. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js +0 -246
  191. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js.map +0 -1
  192. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +0 -1
  193. package/test/icc-x-api/entity-with-attachments-api-test.js +0 -142
  194. package/test/icc-x-api/entity-with-attachments-api-test.js.map +0 -1
  195. package/test/icc-x-api/filters/filters.d.ts +0 -1
  196. package/test/icc-x-api/filters/filters.js +0 -49
  197. package/test/icc-x-api/filters/filters.js.map +0 -1
  198. package/test/icc-x-api/filters/healthelement.d.ts +0 -1
  199. package/test/icc-x-api/filters/healthelement.js +0 -333
  200. package/test/icc-x-api/filters/healthelement.js.map +0 -1
  201. package/test/icc-x-api/icc-accesslog-x-api.d.ts +0 -1
  202. package/test/icc-x-api/icc-accesslog-x-api.js +0 -106
  203. package/test/icc-x-api/icc-accesslog-x-api.js.map +0 -1
  204. package/test/icc-x-api/icc-application-settings-x-api.d.ts +0 -1
  205. package/test/icc-x-api/icc-application-settings-x-api.js +0 -91
  206. package/test/icc-x-api/icc-application-settings-x-api.js.map +0 -1
  207. package/test/icc-x-api/icc-auth-api.d.ts +0 -1
  208. package/test/icc-x-api/icc-auth-api.js +0 -47
  209. package/test/icc-x-api/icc-auth-api.js.map +0 -1
  210. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +0 -1
  211. package/test/icc-x-api/icc-calendar-item-x-api.js +0 -150
  212. package/test/icc-x-api/icc-calendar-item-x-api.js.map +0 -1
  213. package/test/icc-x-api/icc-contact-x-api.d.ts +0 -1
  214. package/test/icc-x-api/icc-contact-x-api.js +0 -355
  215. package/test/icc-x-api/icc-contact-x-api.js.map +0 -1
  216. package/test/icc-x-api/icc-document-x-api.d.ts +0 -1
  217. package/test/icc-x-api/icc-document-x-api.js +0 -76
  218. package/test/icc-x-api/icc-document-x-api.js.map +0 -1
  219. package/test/icc-x-api/icc-form-x-api.d.ts +0 -1
  220. package/test/icc-x-api/icc-form-x-api.js +0 -413
  221. package/test/icc-x-api/icc-form-x-api.js.map +0 -1
  222. package/test/icc-x-api/icc-hcparty-x-api-test.d.ts +0 -1
  223. package/test/icc-x-api/icc-hcparty-x-api-test.js +0 -43
  224. package/test/icc-x-api/icc-hcparty-x-api-test.js.map +0 -1
  225. package/test/icc-x-api/icc-helement-x-api-test.d.ts +0 -1
  226. package/test/icc-x-api/icc-helement-x-api-test.js +0 -155
  227. package/test/icc-x-api/icc-helement-x-api-test.js.map +0 -1
  228. package/test/icc-x-api/icc-invoice-x-api.d.ts +0 -1
  229. package/test/icc-x-api/icc-invoice-x-api.js +0 -99
  230. package/test/icc-x-api/icc-invoice-x-api.js.map +0 -1
  231. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +0 -1
  232. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +0 -222
  233. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +0 -1
  234. package/test/icc-x-api/icc-message-x-api.d.ts +0 -1
  235. package/test/icc-x-api/icc-message-x-api.js +0 -54
  236. package/test/icc-x-api/icc-message-x-api.js.map +0 -1
  237. package/test/icc-x-api/icc-patient-x-api-test.d.ts +0 -1
  238. package/test/icc-x-api/icc-patient-x-api-test.js +0 -165
  239. package/test/icc-x-api/icc-patient-x-api-test.js.map +0 -1
  240. package/test/icc-x-api/icc-recovery-x-api.d.ts +0 -1
  241. package/test/icc-x-api/icc-recovery-x-api.js +0 -175
  242. package/test/icc-x-api/icc-recovery-x-api.js.map +0 -1
  243. package/test/icc-x-api/icc-topic-x-api.d.ts +0 -1
  244. package/test/icc-x-api/icc-topic-x-api.js +0 -269
  245. package/test/icc-x-api/icc-topic-x-api.js.map +0 -1
  246. package/test/icc-x-api/icc-user-x-api-test.d.ts +0 -1
  247. package/test/icc-x-api/icc-user-x-api-test.js +0 -99
  248. package/test/icc-x-api/icc-user-x-api-test.js.map +0 -1
  249. package/test/icc-x-api/keyless-api.d.ts +0 -1
  250. package/test/icc-x-api/keyless-api.js +0 -125
  251. package/test/icc-x-api/keyless-api.js.map +0 -1
  252. package/test/icc-x-api/patient-user.d.ts +0 -2
  253. package/test/icc-x-api/patient-user.js +0 -103
  254. package/test/icc-x-api/patient-user.js.map +0 -1
  255. package/test/icc-x-api/storage/storage.d.ts +0 -1
  256. package/test/icc-x-api/storage/storage.js +0 -48
  257. package/test/icc-x-api/storage/storage.js.map +0 -1
  258. package/test/icc-x-api/test-api-no-parent.d.ts +0 -1
  259. package/test/icc-x-api/test-api-no-parent.js +0 -79
  260. package/test/icc-x-api/test-api-no-parent.js.map +0 -1
  261. package/test/icc-x-api/test-legacy-data-support.d.ts +0 -1
  262. package/test/icc-x-api/test-legacy-data-support.js +0 -375
  263. package/test/icc-x-api/test-legacy-data-support.js.map +0 -1
  264. package/test/icc-x-api/utils/graph-test.d.ts +0 -1
  265. package/test/icc-x-api/utils/graph-test.js +0 -54
  266. package/test/icc-x-api/utils/graph-test.js.map +0 -1
  267. package/test/icc-x-api/utils/lru-temporised-async-cache-test.d.ts +0 -1
  268. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js +0 -364
  269. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js.map +0 -1
  270. package/test/support/CSM-185.d.ts +0 -1
  271. package/test/support/CSM-185.js +0 -124
  272. package/test/support/CSM-185.js.map +0 -1
  273. package/test/support/CSM-243.d.ts +0 -1
  274. package/test/support/CSM-243.js +0 -120
  275. package/test/support/CSM-243.js.map +0 -1
  276. package/test/support/CSM-543.d.ts +0 -1
  277. package/test/support/CSM-543.js +0 -164
  278. package/test/support/CSM-543.js.map +0 -1
  279. package/test/support/CSM-729.d.ts +0 -1
  280. package/test/support/CSM-729.js +0 -225
  281. package/test/support/CSM-729.js.map +0 -1
  282. package/test/support/CSM-87.d.ts +0 -0
  283. package/test/support/CSM-87.js +0 -21
  284. package/test/support/CSM-87.js.map +0 -1
  285. package/test/support/CSM-93.d.ts +0 -1
  286. package/test/support/CSM-93.js +0 -112
  287. package/test/support/CSM-93.js.map +0 -1
  288. package/test/utils/FakeDataOwnerApi.d.ts +0 -32
  289. package/test/utils/FakeDataOwnerApi.js +0 -136
  290. package/test/utils/FakeDataOwnerApi.js.map +0 -1
  291. package/test/utils/FakeEncryptionKeysManager.d.ts +0 -36
  292. package/test/utils/FakeEncryptionKeysManager.js +0 -98
  293. package/test/utils/FakeEncryptionKeysManager.js.map +0 -1
  294. package/test/utils/FakeExchangeDataApi.d.ts +0 -32
  295. package/test/utils/FakeExchangeDataApi.js +0 -92
  296. package/test/utils/FakeExchangeDataApi.js.map +0 -1
  297. package/test/utils/FakeExchangeDataManager.d.ts +0 -48
  298. package/test/utils/FakeExchangeDataManager.js +0 -82
  299. package/test/utils/FakeExchangeDataManager.js.map +0 -1
  300. package/test/utils/FakeExchangeDataMapManager.d.ts +0 -12
  301. package/test/utils/FakeExchangeDataMapManager.js +0 -38
  302. package/test/utils/FakeExchangeDataMapManager.js.map +0 -1
  303. package/test/utils/FakeGenericApi.d.ts +0 -16
  304. package/test/utils/FakeGenericApi.js +0 -65
  305. package/test/utils/FakeGenericApi.js.map +0 -1
  306. package/test/utils/KeylessCryptoStrategies.d.ts +0 -23
  307. package/test/utils/KeylessCryptoStrategies.js +0 -26
  308. package/test/utils/KeylessCryptoStrategies.js.map +0 -1
  309. package/test/utils/TestApi.d.ts +0 -3
  310. package/test/utils/TestApi.js +0 -30
  311. package/test/utils/TestApi.js.map +0 -1
  312. package/test/utils/TestCollectionUtils.d.ts +0 -1
  313. package/test/utils/TestCollectionUtils.js +0 -109
  314. package/test/utils/TestCollectionUtils.js.map +0 -1
  315. package/test/utils/TestCryptoStrategies.d.ts +0 -42
  316. package/test/utils/TestCryptoStrategies.js +0 -80
  317. package/test/utils/TestCryptoStrategies.js.map +0 -1
  318. package/test/utils/TestStorage.d.ts +0 -23
  319. package/test/utils/TestStorage.js +0 -61
  320. package/test/utils/TestStorage.js.map +0 -1
  321. package/test/utils/roles.d.ts +0 -14
  322. package/test/utils/roles.js +0 -345
  323. package/test/utils/roles.js.map +0 -1
  324. package/test/utils/test_utils.d.ts +0 -87
  325. package/test/utils/test_utils.js +0 -452
  326. package/test/utils/test_utils.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ExchangeDataManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;AAuBA,4GAmCC;AApDD,mCAAgH;AAEhH,oCAAsE;AACtE,yEAA6E;AAC7E,+BAAkC;AAClC,6CAAmC;AACnC,gEAA0D;AAO1D;;;GAGG;AACH,SAAsB,gDAAgD;yDACpE,IAA6B,EAC7B,cAAyC,EACzC,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,CAAC;YACxE,MAAM,GAAG,GAAG,IAAI,8BAA8B,CAC5C,IAAI,EACJ,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,aAAa,CACd,CAAA;YACD,MAAM,GAAG,CAAC,sBAAsB,EAAE,CAAA;YAClC,OAAO,GAAG,CAAA;QACZ,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,kCAAkC,CAC3C,IAAI,EACJ,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,aAAa,EACb,kBAAkB,C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,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC;YAC3G,IAAI,CAAC,kCAAkC,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC;IAED,yBAAyB;QACvB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;IAED,oBAAoB;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;IAEe,yBAAyB,CACvC,mBAMG;;YAEH,KAAK,MAAM,OAAO,IAAI,mBAAmB,EAAE,CAAC;gBAC1C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,0BAA0B,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;gBACrG,MAAM,IAAI,GAAG;oBACX,YAAY,EAAE,OAAO,CAAC,YAAY;oBAClC,SAAS,EAAE;wBACT,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;wBAChD,WAAW,EAAE,OAAO,CAAC,WAAW;wBAChC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;wBAC9C,QAAQ,EAAE,OAAO,CAAC,QAAQ;qBAC3B;oBACD,MAAM;iBACP,CAAA;gBACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC;QACH,CAAC;KAAA;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 { AccessControlSecretUtils } from './AccessControlSecretUtils'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { fingerprintV1, getShaVersionForKey, hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from './utils'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { EntityWithDelegationTypeName, hex2ua, ua2ab } from '../utils'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { ShaVersion } from './RSA'\nimport { Mutex } from 'async-mutex'\nimport { SimpleLruCache } from '../utils/simple-lru-cache'\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 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 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 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 sharedSignatureKey: CryptoKey\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.\n * @param delegateId the id of the delegate.\n * @param options\n * - allowCreationWithoutDelegatorKey if true, when creating new exchange data, even if no verified key is available for the delegator the method\n * will create the new exchange data anyway (will not be usable by the delegate without additional steps).\n * - allowCreationWithoutDelegateKey if true, when creating new exchange data, even if no verified key is available for the delegate the method\n * will create the new exchange data anyway (will not be usable by the delegate without additional steps).\n * @return the access control secret and key of the data to use for encryption.\n */\n getOrCreateEncryptionDataTo(\n delegateId: string,\n options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }>\n\n /**\n * Retrieve the cached decrypted exchange data key associated with any of the provided hashes/entry keys of secure delegations.\n * @param hashes hashes of access control secrets for a specific entity, as they appear in the key of secure delegation entries\n * @return the exchange data and decrypted key associated to that hash if cached\n */\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: 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 * and attempts to decrypt it, then caches the result.\n * @param ids ids of the exchange datas to retrieve\n * @param retrieveIfNotCached if false only cached data will be returned, and the access control hases options will be\n * ignored\n * @return a map containing the exchange data id associated with:\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 * - accessControlSecret: the access control secret corresponding to the provided exchange data if it could be decrypted, else undefined\n */\n getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{ [id: string]: { exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; exchangeData: ExchangeData } }>\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 /**\n * Injects already decrypted exchange data, allowing it to be used by the sdk.\n * @param exchangeDataDetails the exchange data to inject, with the decrypted content and verified status.\n * Note that the SDK won't verify that the provided decrypted content actually matches what is stored in the exchange\n * data.\n * @param reEncryptWithOwnKeys if true all the provided exchange data that is not encrypted with any of the self\n * verified keys of the user will be re-encrypted with them. In case the user is also the delegator and the data is\n * verified the delegator signature will be updated.\n */\n injectDecryptedExchangeData(\n exchangeDataDetails: {\n exchangeDataId: string\n accessControlSecret: ArrayBuffer\n exchangeKey: ArrayBuffer\n sharedSignatureKey: ArrayBuffer\n verified: boolean\n }[],\n reEncryptWithOwnKeys: boolean\n ): Promise<void>\n}\n\nabstract class AbstractExchangeDataManager implements ExchangeDataManager {\n constructor(\n readonly base: BaseExchangeDataManager,\n protected readonly encryptionKeys: UserEncryptionKeysManager,\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 sharedSignatureKey: CryptoKey\n }\n | undefined\n > {\n const decryptionKeys = this.encryptionKeys.getDecryptionKeys()\n const encryptionKeys = Object.fromEntries(\n this.encryptionKeys.getSelfVerifiedKeys().map((x): [string, CryptoKey] => [x.fingerprint, x.pair.privateKey])\n )\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 sharedSignatureKey: decryptedSharedSignatureKey,\n verified: await this.base.verifyExchangeData(\n {\n exchangeData: data,\n decryptedAccessControlSecret,\n decryptedExchangeKey,\n decryptedSharedSignatureKey,\n },\n encryptionKeys,\n true\n ),\n }\n }\n\n protected async createNewExchangeData(\n delegateId: string,\n options: {\n newDataId?: string\n allowNoDelegatorKeys?: boolean\n allowNoDelegateKeys?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n if (options.allowNoDelegateKeys && options.allowNoDelegatorKeys)\n throw new Error('Illegal arguments: allow no delegator and no delegate keys should never both be true')\n const encryptionKeys: { [fp: string]: CryptoKey } = {}\n const selfVerifiedKeys = this.encryptionKeys.getSelfVerifiedKeys()\n if (selfVerifiedKeys.length <= 0 && !options.allowNoDelegatorKeys)\n throw new Error('If the sdk is initialized in keyless mode you must create exchange data explicitly')\n selfVerifiedKeys.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 (!sha256KeysOfDelegate.size && !sha1KeysOfDelegate.size) {\n if (!options.allowNoDelegateKeys)\n throw new Error(`Could not create exchange data to ${delegateId} as no public key for the delegate was found.`)\n allVerifiedDelegateKeys = []\n } else 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 && !options.allowNoDelegateKeys)\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(\n 'spki',\n ua2ab(hex2ua(delegateKey)),\n ['encrypt'],\n ShaVersion.Sha1\n )\n } else if (sha256KeysOfDelegate.has(delegateKey)) {\n encryptionKeys[fingerprintV1(delegateKey)] = await this.primitives.RSA.importKey(\n 'spki',\n ua2ab(hex2ua(delegateKey)),\n ['encrypt'],\n ShaVersion.Sha256\n )\n } else throw new Error('Illegal state: verified keys should contain only keys for OAPE-SHA1 or OAPE-SHA256.')\n }\n }\n const newData = await this.base.createExchangeData(\n delegateId,\n Object.fromEntries(selfVerifiedKeys.map((x): [string, CryptoKey] => [x.fingerprint, x.pair.privateKey])),\n encryptionKeys,\n options.newDataId ? { id: options.newDataId } : {}\n )\n return {\n exchangeData: newData.exchangeData,\n accessControlSecret: newData.accessControlSecret,\n exchangeKey: newData.exchangeKey,\n sharedSignatureKey: newData.sharedSignatureKey,\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', ua2ab(hex2ua(newDataOwnerPublicKey)), ['encrypt'], newKeyHashVersion)\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 options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n throw new Error('Implemented by concrete class')\n }\n\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n throw new Error('Implemented by concrete class')\n }\n\n getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n }> {\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 async injectDecryptedExchangeData(\n exchangeDataDetails: {\n exchangeDataId: string\n accessControlSecret: ArrayBuffer\n exchangeKey: ArrayBuffer\n sharedSignatureKey: ArrayBuffer\n verified: boolean\n }[],\n reEncryptWithOwnKeys: boolean\n ): Promise<void> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const retrievedExchangeData = await this.base.getExchangeDataByIds(exchangeDataDetails.map((x) => x.exchangeDataId))\n if (retrievedExchangeData.some((x) => x.delegator != self && x.delegate != self))\n throw new Error('Should only inject exchange date from/to the current user')\n const exchangeDataById: { [id: string]: ExchangeData } = {}\n retrievedExchangeData.forEach((x) => (exchangeDataById[x.id!] = x))\n if (reEncryptWithOwnKeys) {\n const selfVerifiedKeys = this.encryptionKeys.getSelfVerifiedKeys()\n if (selfVerifiedKeys.length <= 0) throw new Error(\"Can't re-encrypt injected exchange data with own keys if in keyless mode\")\n const encryptionKeys: { [fp: string]: CryptoKey } = {}\n selfVerifiedKeys.forEach(({ fingerprint, pair }) => {\n encryptionKeys[fingerprint] = pair.publicKey\n })\n const signatureKeys = Object.fromEntries(selfVerifiedKeys.map((x): [string, CryptoKey] => [x.fingerprint, x.pair.privateKey]))\n for (const details of exchangeDataDetails) {\n const exchangeData = exchangeDataById[details.exchangeDataId]\n if (exchangeData != null)\n await this.base.updateExchangeDataWithRawDecryptedContent({\n exchangeData,\n newEncryptionKeys: encryptionKeys,\n newDelegatorSignatureKeys: exchangeData.delegator == self && details.verified ? signatureKeys : {},\n rawExchangeKey: details.exchangeKey,\n rawAccessControlSecret: details.accessControlSecret,\n rawSharedSignatureKey: details.sharedSignatureKey,\n })\n }\n }\n const importedDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[] = []\n for (const details of exchangeDataDetails) {\n const exchangeData = exchangeDataById[details.exchangeDataId]\n if (exchangeData != undefined)\n importedDetails.push({\n exchangeData: exchangeData,\n accessControlSecret: await this.base.importAccessControlSecret(details.accessControlSecret),\n exchangeKey: await this.base.importExchangeKey(details.exchangeKey),\n sharedSignatureKey: await this.base.importSharedSignatureKey(details.sharedSignatureKey),\n verified: details.verified,\n })\n }\n await this.cacheInjectedExchangeData(importedDetails)\n }\n\n protected abstract cacheInjectedExchangeData(\n exchangeDataDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[]\n ): Promise<void>\n}\n\nclass FullyCachedExchangeDataManager extends AbstractExchangeDataManager {\n private caches: Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: { [hash: string]: string }\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string }\n }> = Promise.resolve({ dataById: {}, hashToId: {}, delegateToVerifiedEncryptionDataId: {}, entityTypeToAccessControlKeysValue: {} })\n private createExchangeDataMutex = new Mutex()\n\n async clearOrRepopulateCache(): Promise<void> {\n this.caches = this.doRepopulateCache()\n await this.caches\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n function retrieveByHashesFromCaches(caches: {\n dataById: { [id: string]: CachedExchangeData }\n hashToId: { [hash: 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[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 return retrieveByHashesFromCaches(await this.caches)\n }\n\n private async getCachedEncryptionDataTo(\n delegateId: string\n ): Promise<{ exchangeKey: CryptoKey; accessControlSecret: string; exchangeData: ExchangeData; sharedSignatureKey: CryptoKey } | undefined> {\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 sharedSignatureKey: cached.decrypted.sharedSignatureKey,\n }\n } else {\n return undefined\n }\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n const initialCached = await this.getCachedEncryptionDataTo(delegateId)\n if (initialCached) return initialCached\n const release = await this.createExchangeDataMutex.acquire()\n try {\n const cachedAfterMutex = await this.getCachedEncryptionDataTo(delegateId)\n if (cachedAfterMutex) return cachedAfterMutex\n const created = await this.createNewExchangeData(delegateId, {\n allowNoDelegateKeys: options?.allowCreationWithoutDelegateKey ?? false,\n allowNoDelegatorKeys: options?.allowCreationWithoutDelegatorKey ?? false,\n })\n this.cacheData(created.exchangeData, true, {\n accessControlSecret: created.accessControlSecret,\n exchangeKey: created.exchangeKey,\n sharedSignatureKey: created.sharedSignatureKey,\n verified: true,\n })\n return created\n } finally {\n release()\n }\n }\n\n async getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n }> {\n const caches = await this.caches\n const res: {\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n } = {}\n for (const id of ids) {\n const data = caches.dataById[id]\n if (data) {\n res[id] = {\n exchangeData: data.exchangeData,\n exchangeKey: data.decrypted?.exchangeKey,\n accessControlSecret: data.decrypted?.accessControlSecret,\n }\n }\n }\n return res\n }\n\n private cacheData(\n exchangeData: ExchangeData,\n isNewData: boolean,\n decrypted: { accessControlSecret: string; exchangeKey: CryptoKey; verified: boolean; sharedSignatureKey: CryptoKey } | undefined\n ): void {\n this.caches = this.caches.then(async (caches) => {\n caches.dataById[exchangeData.id!] = { exchangeData, decrypted }\n if (decrypted) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(decrypted.accessControlSecret)\n hashes.forEach((hash) => {\n caches.hashToId[hash] = exchangeData.id!\n })\n if (decrypted.verified) {\n caches.delegateToVerifiedEncryptionDataId[exchangeData.delegate] = exchangeData.id!\n }\n }\n if (isNewData) caches.entityTypeToAccessControlKeysValue = {}\n return caches\n })\n }\n\n private async doRepopulateCache(): Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: { [hash: 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: { [hash: 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 if (currDecrypted?.accessControlSecret) {\n for (const h of await this.accessControlSecret.allSecureDelegationKeysFor(currDecrypted!.accessControlSecret)) {\n hashToId[h] = currData.id!\n }\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))\n }\n return res\n }\n\n protected async cacheInjectedExchangeData(\n exchangeDataDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[]\n ): Promise<void> {\n for (const details of exchangeDataDetails) {\n this.cacheData(details.exchangeData, true, {\n accessControlSecret: details.accessControlSecret,\n exchangeKey: details.exchangeKey,\n sharedSignatureKey: details.sharedSignatureKey,\n verified: details.verified,\n })\n }\n }\n}\n\nclass LimitedLruCacheExchangeDataManager extends AbstractExchangeDataManager {\n private readonly idToData: SimpleLruCache<string, CachedExchangeData & { hashes: string[] }> = new SimpleLruCache()\n private readonly hashToId: Map<string, string> = new Map()\n private readonly delegateToVerifiedEncryptionDataId: Map<string, string> = new Map()\n private readonly maxCachedExchangeData: number\n private readonly cacheMutex = new Mutex()\n\n constructor(\n base: BaseExchangeDataManager,\n encryptionKeys: UserEncryptionKeysManager,\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, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys)\n this.maxCachedExchangeData = optionalParameters.lruCacheSize ?? 2000\n }\n\n async clearOrRepopulateCache(): Promise<void> {\n this.idToData.clear()\n this.hashToId.clear()\n this.delegateToVerifiedEncryptionDataId.clear()\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n const release = await this.cacheMutex.acquire()\n try {\n const res: {\n [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string }\n } = {}\n for (const hash of hashes) {\n const dataId = this.hashToId.get(hash)\n if (dataId) {\n const retrieved = this.idToData.getCached(dataId)\n if (!retrieved) throw new Error(`Data with id ${dataId} should have been already cached.`)\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 } finally {\n release()\n }\n }\n\n async getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n }> {\n const release = await this.cacheMutex.acquire()\n try {\n const res: {\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n } = {}\n const uncached: string[] = []\n for (const id of ids) {\n const cached: (CachedExchangeData & { hashes: string[] }) | null = this.idToData.getCached(id)\n if (cached) {\n res[id] = {\n exchangeKey: cached.decrypted?.exchangeKey,\n accessControlSecret: cached.decrypted?.accessControlSecret,\n exchangeData: cached.exchangeData,\n }\n } else if (retrieveIfNotCached) {\n uncached.push(id)\n }\n }\n if (uncached.length > 0) {\n const retrieved = await this.base.getExchangeDataByIds(uncached)\n for (const data of retrieved) {\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(decrypted.accessControlSecret)\n this.addToCache({ exchangeData: data, hashes, decrypted })\n } else {\n this.addToCache({ exchangeData: data, hashes: [] })\n }\n res[data.id!] = {\n exchangeKey: decrypted?.exchangeKey,\n accessControlSecret: decrypted?.accessControlSecret,\n exchangeData: data,\n }\n }\n }\n return res\n } finally {\n release()\n }\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n const release = await this.cacheMutex.acquire()\n try {\n let existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n if (!existingId) {\n await this.populateCacheToDelegate(delegateId)\n existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n }\n if (existingId) {\n const cached = this.idToData.getCached(existingId)\n if (!cached) throw new Error(`Illegal state: data with id ${existingId} should have been in cache`)\n if (cached.decrypted) {\n return {\n exchangeData: cached.exchangeData,\n exchangeKey: cached.decrypted.exchangeKey,\n accessControlSecret: cached.decrypted.accessControlSecret,\n sharedSignatureKey: cached.decrypted.sharedSignatureKey,\n }\n } else throw new Error(`Illegal state: cached verified data should be decrypted.`)\n } else {\n const created = await this.createNewExchangeData(delegateId, {\n allowNoDelegateKeys: options?.allowCreationWithoutDelegateKey ?? false,\n allowNoDelegatorKeys: options?.allowCreationWithoutDelegatorKey ?? false,\n })\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(created.accessControlSecret)\n const data = {\n exchangeData: created.exchangeData,\n decrypted: {\n accessControlSecret: created.accessControlSecret,\n exchangeKey: created.exchangeKey,\n sharedSignatureKey: created.sharedSignatureKey,\n verified: true,\n },\n hashes,\n }\n this.addToCache(data)\n return {\n exchangeData: data.exchangeData,\n exchangeKey: data.decrypted.exchangeKey,\n accessControlSecret: data.decrypted.accessControlSecret,\n sharedSignatureKey: data.decrypted.sharedSignatureKey,\n }\n }\n } finally {\n release()\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(delegateId: string): Promise<void> {\n const dataToDelegate = await this.base.getExchangeDataByDelegatorDelegatePair(await this.dataOwnerApi.getCurrentDataOwnerId(), delegateId)\n for (const data of dataToDelegate) {\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(decrypted.accessControlSecret)\n this.addToCache({ exchangeData: data, hashes, decrypted })\n } else {\n this.addToCache({ exchangeData: data, hashes: [] })\n }\n }\n }\n\n private addToCache(data: CachedExchangeData & { hashes: string[] }) {\n if (this.idToData.size >= this.maxCachedExchangeData) {\n this.evictOneEntry()\n }\n data.hashes.forEach((hash) => this.hashToId.set(hash, data.exchangeData.id!))\n if (data.decrypted?.verified && !this.delegateToVerifiedEncryptionDataId.has(data.exchangeData.delegate)) {\n this.delegateToVerifiedEncryptionDataId.set(data.exchangeData.delegate, data.exchangeData.id!)\n }\n this.idToData.set(data.exchangeData.id!, data)\n }\n\n private evictOneEntry() {\n const evicted = this.idToData.evictLeastRecentlyUsed()\n evicted.hashes.forEach((hash) => this.hashToId.delete(hash))\n if (this.delegateToVerifiedEncryptionDataId.get(evicted.exchangeData.delegate) === evicted.exchangeData.id) {\n this.delegateToVerifiedEncryptionDataId.delete(evicted.exchangeData.delegate)\n }\n }\n\n getAccessControlKeysValue(): Promise<string | undefined> {\n return Promise.resolve(undefined)\n }\n\n getAllDelegationKeys(): Promise<string[] | undefined> {\n return Promise.resolve(undefined)\n }\n\n protected async cacheInjectedExchangeData(\n exchangeDataDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[]\n ): Promise<void> {\n for (const details of exchangeDataDetails) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(details.accessControlSecret)\n const data = {\n exchangeData: details.exchangeData,\n decrypted: {\n accessControlSecret: details.accessControlSecret,\n exchangeKey: details.exchangeKey,\n sharedSignatureKey: details.sharedSignatureKey,\n verified: details.verified,\n },\n hashes,\n }\n this.addToCache(data)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ExchangeDataManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;AAuBA,4GAmCC;AApDD,mCAAgH;AAEhH,oCAAsE;AACtE,yEAA6E;AAC7E,+BAAkC;AAClC,0CAAsC;AACtC,gEAA0D;AAO1D;;;GAGG;AACH,SAAsB,gDAAgD;yDACpE,IAA6B,EAC7B,cAAyC,EACzC,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,YAA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KAAA;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 { AccessControlSecretUtils } from './AccessControlSecretUtils'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { fingerprintV1, getShaVersionForKey, hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from './utils'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { EntityWithDelegationTypeName, hex2ua, ua2ab } from '../utils'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { ShaVersion } from './RSA'\nimport { Mutex } from '../utils/mutex'\nimport { SimpleLruCache } from '../utils/simple-lru-cache'\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 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 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 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 sharedSignatureKey: CryptoKey\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.\n * @param delegateId the id of the delegate.\n * @param options\n * - allowCreationWithoutDelegatorKey if true, when creating new exchange data, even if no verified key is available for the delegator the method\n * will create the new exchange data anyway (will not be usable by the delegate without additional steps).\n * - allowCreationWithoutDelegateKey if true, when creating new exchange data, even if no verified key is available for the delegate the method\n * will create the new exchange data anyway (will not be usable by the delegate without additional steps).\n * @return the access control secret and key of the data to use for encryption.\n */\n getOrCreateEncryptionDataTo(\n delegateId: string,\n options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }>\n\n /**\n * Retrieve the cached decrypted exchange data key associated with any of the provided hashes/entry keys of secure delegations.\n * @param hashes hashes of access control secrets for a specific entity, as they appear in the key of secure delegation entries\n * @return the exchange data and decrypted key associated to that hash if cached\n */\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: 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 * and attempts to decrypt it, then caches the result.\n * @param ids ids of the exchange datas to retrieve\n * @param retrieveIfNotCached if false only cached data will be returned, and the access control hases options will be\n * ignored\n * @return a map containing the exchange data id associated with:\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 * - accessControlSecret: the access control secret corresponding to the provided exchange data if it could be decrypted, else undefined\n */\n getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{ [id: string]: { exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; exchangeData: ExchangeData } }>\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 /**\n * Injects already decrypted exchange data, allowing it to be used by the sdk.\n * @param exchangeDataDetails the exchange data to inject, with the decrypted content and verified status.\n * Note that the SDK won't verify that the provided decrypted content actually matches what is stored in the exchange\n * data.\n * @param reEncryptWithOwnKeys if true all the provided exchange data that is not encrypted with any of the self\n * verified keys of the user will be re-encrypted with them. In case the user is also the delegator and the data is\n * verified the delegator signature will be updated.\n */\n injectDecryptedExchangeData(\n exchangeDataDetails: {\n exchangeDataId: string\n accessControlSecret: ArrayBuffer\n exchangeKey: ArrayBuffer\n sharedSignatureKey: ArrayBuffer\n verified: boolean\n }[],\n reEncryptWithOwnKeys: boolean\n ): Promise<void>\n}\n\nabstract class AbstractExchangeDataManager implements ExchangeDataManager {\n constructor(\n readonly base: BaseExchangeDataManager,\n protected readonly encryptionKeys: UserEncryptionKeysManager,\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 sharedSignatureKey: CryptoKey\n }\n | undefined\n > {\n const decryptionKeys = this.encryptionKeys.getDecryptionKeys()\n const encryptionKeys = Object.fromEntries(\n this.encryptionKeys.getSelfVerifiedKeys().map((x): [string, CryptoKey] => [x.fingerprint, x.pair.privateKey])\n )\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 sharedSignatureKey: decryptedSharedSignatureKey,\n verified: await this.base.verifyExchangeData(\n {\n exchangeData: data,\n decryptedAccessControlSecret,\n decryptedExchangeKey,\n decryptedSharedSignatureKey,\n },\n encryptionKeys,\n true\n ),\n }\n }\n\n protected async createNewExchangeData(\n delegateId: string,\n options: {\n newDataId?: string\n allowNoDelegatorKeys?: boolean\n allowNoDelegateKeys?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n if (options.allowNoDelegateKeys && options.allowNoDelegatorKeys)\n throw new Error('Illegal arguments: allow no delegator and no delegate keys should never both be true')\n const encryptionKeys: { [fp: string]: CryptoKey } = {}\n const selfVerifiedKeys = this.encryptionKeys.getSelfVerifiedKeys()\n if (selfVerifiedKeys.length <= 0 && !options.allowNoDelegatorKeys)\n throw new Error('If the sdk is initialized in keyless mode you must create exchange data explicitly')\n selfVerifiedKeys.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 (!sha256KeysOfDelegate.size && !sha1KeysOfDelegate.size) {\n if (!options.allowNoDelegateKeys)\n throw new Error(`Could not create exchange data to ${delegateId} as no public key for the delegate was found.`)\n allVerifiedDelegateKeys = []\n } else 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 && !options.allowNoDelegateKeys)\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(\n 'spki',\n ua2ab(hex2ua(delegateKey)),\n ['encrypt'],\n ShaVersion.Sha1\n )\n } else if (sha256KeysOfDelegate.has(delegateKey)) {\n encryptionKeys[fingerprintV1(delegateKey)] = await this.primitives.RSA.importKey(\n 'spki',\n ua2ab(hex2ua(delegateKey)),\n ['encrypt'],\n ShaVersion.Sha256\n )\n } else throw new Error('Illegal state: verified keys should contain only keys for OAPE-SHA1 or OAPE-SHA256.')\n }\n }\n const newData = await this.base.createExchangeData(\n delegateId,\n Object.fromEntries(selfVerifiedKeys.map((x): [string, CryptoKey] => [x.fingerprint, x.pair.privateKey])),\n encryptionKeys,\n options.newDataId ? { id: options.newDataId } : {}\n )\n return {\n exchangeData: newData.exchangeData,\n accessControlSecret: newData.accessControlSecret,\n exchangeKey: newData.exchangeKey,\n sharedSignatureKey: newData.sharedSignatureKey,\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', ua2ab(hex2ua(newDataOwnerPublicKey)), ['encrypt'], newKeyHashVersion)\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 options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n throw new Error('Implemented by concrete class')\n }\n\n getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n throw new Error('Implemented by concrete class')\n }\n\n getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n }> {\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 async injectDecryptedExchangeData(\n exchangeDataDetails: {\n exchangeDataId: string\n accessControlSecret: ArrayBuffer\n exchangeKey: ArrayBuffer\n sharedSignatureKey: ArrayBuffer\n verified: boolean\n }[],\n reEncryptWithOwnKeys: boolean\n ): Promise<void> {\n const self = await this.dataOwnerApi.getCurrentDataOwnerId()\n const retrievedExchangeData = await this.base.getExchangeDataByIds(exchangeDataDetails.map((x) => x.exchangeDataId))\n if (retrievedExchangeData.some((x) => x.delegator != self && x.delegate != self))\n throw new Error('Should only inject exchange date from/to the current user')\n const exchangeDataById: { [id: string]: ExchangeData } = {}\n retrievedExchangeData.forEach((x) => (exchangeDataById[x.id!] = x))\n if (reEncryptWithOwnKeys) {\n const selfVerifiedKeys = this.encryptionKeys.getSelfVerifiedKeys()\n if (selfVerifiedKeys.length <= 0) throw new Error(\"Can't re-encrypt injected exchange data with own keys if in keyless mode\")\n const encryptionKeys: { [fp: string]: CryptoKey } = {}\n selfVerifiedKeys.forEach(({ fingerprint, pair }) => {\n encryptionKeys[fingerprint] = pair.publicKey\n })\n const signatureKeys = Object.fromEntries(selfVerifiedKeys.map((x): [string, CryptoKey] => [x.fingerprint, x.pair.privateKey]))\n for (const details of exchangeDataDetails) {\n const exchangeData = exchangeDataById[details.exchangeDataId]\n if (exchangeData != null)\n await this.base.updateExchangeDataWithRawDecryptedContent({\n exchangeData,\n newEncryptionKeys: encryptionKeys,\n newDelegatorSignatureKeys: exchangeData.delegator == self && details.verified ? signatureKeys : {},\n rawExchangeKey: details.exchangeKey,\n rawAccessControlSecret: details.accessControlSecret,\n rawSharedSignatureKey: details.sharedSignatureKey,\n })\n }\n }\n const importedDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[] = []\n for (const details of exchangeDataDetails) {\n const exchangeData = exchangeDataById[details.exchangeDataId]\n if (exchangeData != undefined)\n importedDetails.push({\n exchangeData: exchangeData,\n accessControlSecret: await this.base.importAccessControlSecret(details.accessControlSecret),\n exchangeKey: await this.base.importExchangeKey(details.exchangeKey),\n sharedSignatureKey: await this.base.importSharedSignatureKey(details.sharedSignatureKey),\n verified: details.verified,\n })\n }\n await this.cacheInjectedExchangeData(importedDetails)\n }\n\n protected abstract cacheInjectedExchangeData(\n exchangeDataDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[]\n ): Promise<void>\n}\n\nclass FullyCachedExchangeDataManager extends AbstractExchangeDataManager {\n private caches: Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: { [hash: string]: string }\n delegateToVerifiedEncryptionDataId: { [delegate: string]: string }\n entityTypeToAccessControlKeysValue: { [entityType in EntityWithDelegationTypeName]?: string }\n }> = Promise.resolve({ dataById: {}, hashToId: {}, delegateToVerifiedEncryptionDataId: {}, entityTypeToAccessControlKeysValue: {} })\n private createExchangeDataMutex = new Mutex()\n\n async clearOrRepopulateCache(): Promise<void> {\n this.caches = this.doRepopulateCache()\n await this.caches\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n function retrieveByHashesFromCaches(caches: {\n dataById: { [id: string]: CachedExchangeData }\n hashToId: { [hash: 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[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 return retrieveByHashesFromCaches(await this.caches)\n }\n\n private async getCachedEncryptionDataTo(\n delegateId: string\n ): Promise<{ exchangeKey: CryptoKey; accessControlSecret: string; exchangeData: ExchangeData; sharedSignatureKey: CryptoKey } | undefined> {\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 sharedSignatureKey: cached.decrypted.sharedSignatureKey,\n }\n } else {\n return undefined\n }\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n const initialCached = await this.getCachedEncryptionDataTo(delegateId)\n if (initialCached) return initialCached\n const release = await this.createExchangeDataMutex.acquire()\n try {\n const cachedAfterMutex = await this.getCachedEncryptionDataTo(delegateId)\n if (cachedAfterMutex) return cachedAfterMutex\n const created = await this.createNewExchangeData(delegateId, {\n allowNoDelegateKeys: options?.allowCreationWithoutDelegateKey ?? false,\n allowNoDelegatorKeys: options?.allowCreationWithoutDelegatorKey ?? false,\n })\n this.cacheData(created.exchangeData, true, {\n accessControlSecret: created.accessControlSecret,\n exchangeKey: created.exchangeKey,\n sharedSignatureKey: created.sharedSignatureKey,\n verified: true,\n })\n return created\n } finally {\n release()\n }\n }\n\n async getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n }> {\n const caches = await this.caches\n const res: {\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n } = {}\n for (const id of ids) {\n const data = caches.dataById[id]\n if (data) {\n res[id] = {\n exchangeData: data.exchangeData,\n exchangeKey: data.decrypted?.exchangeKey,\n accessControlSecret: data.decrypted?.accessControlSecret,\n }\n }\n }\n return res\n }\n\n private cacheData(\n exchangeData: ExchangeData,\n isNewData: boolean,\n decrypted: { accessControlSecret: string; exchangeKey: CryptoKey; verified: boolean; sharedSignatureKey: CryptoKey } | undefined\n ): void {\n this.caches = this.caches.then(async (caches) => {\n caches.dataById[exchangeData.id!] = { exchangeData, decrypted }\n if (decrypted) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(decrypted.accessControlSecret)\n hashes.forEach((hash) => {\n caches.hashToId[hash] = exchangeData.id!\n })\n if (decrypted.verified) {\n caches.delegateToVerifiedEncryptionDataId[exchangeData.delegate] = exchangeData.id!\n }\n }\n if (isNewData) caches.entityTypeToAccessControlKeysValue = {}\n return caches\n })\n }\n\n private async doRepopulateCache(): Promise<{\n dataById: { [id: string]: CachedExchangeData }\n hashToId: { [hash: 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: { [hash: 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 if (currDecrypted?.accessControlSecret) {\n for (const h of await this.accessControlSecret.allSecureDelegationKeysFor(currDecrypted!.accessControlSecret)) {\n hashToId[h] = currData.id!\n }\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))\n }\n return res\n }\n\n protected async cacheInjectedExchangeData(\n exchangeDataDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[]\n ): Promise<void> {\n for (const details of exchangeDataDetails) {\n this.cacheData(details.exchangeData, true, {\n accessControlSecret: details.accessControlSecret,\n exchangeKey: details.exchangeKey,\n sharedSignatureKey: details.sharedSignatureKey,\n verified: details.verified,\n })\n }\n }\n}\n\nclass LimitedLruCacheExchangeDataManager extends AbstractExchangeDataManager {\n private readonly idToData: SimpleLruCache<string, CachedExchangeData & { hashes: string[] }> = new SimpleLruCache()\n private readonly hashToId: Map<string, string> = new Map()\n private readonly delegateToVerifiedEncryptionDataId: Map<string, string> = new Map()\n private readonly maxCachedExchangeData: number\n private readonly cacheMutex = new Mutex()\n\n constructor(\n base: BaseExchangeDataManager,\n encryptionKeys: UserEncryptionKeysManager,\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, accessControlSecret, cryptoStrategies, dataOwnerApi, primitives, useParentKeys)\n this.maxCachedExchangeData = optionalParameters.lruCacheSize ?? 2000\n }\n\n async clearOrRepopulateCache(): Promise<void> {\n this.idToData.clear()\n this.hashToId.clear()\n this.delegateToVerifiedEncryptionDataId.clear()\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n const release = await this.cacheMutex.acquire()\n try {\n const res: {\n [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string }\n } = {}\n for (const hash of hashes) {\n const dataId = this.hashToId.get(hash)\n if (dataId) {\n const retrieved = this.idToData.getCached(dataId)\n if (!retrieved) throw new Error(`Data with id ${dataId} should have been already cached.`)\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 } finally {\n release()\n }\n }\n\n async getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n }> {\n const release = await this.cacheMutex.acquire()\n try {\n const res: {\n [p: string]: {\n exchangeKey: CryptoKey | undefined\n accessControlSecret: string | undefined\n exchangeData: ExchangeData\n }\n } = {}\n const uncached: string[] = []\n for (const id of ids) {\n const cached: (CachedExchangeData & { hashes: string[] }) | null = this.idToData.getCached(id)\n if (cached) {\n res[id] = {\n exchangeKey: cached.decrypted?.exchangeKey,\n accessControlSecret: cached.decrypted?.accessControlSecret,\n exchangeData: cached.exchangeData,\n }\n } else if (retrieveIfNotCached) {\n uncached.push(id)\n }\n }\n if (uncached.length > 0) {\n const retrieved = await this.base.getExchangeDataByIds(uncached)\n for (const data of retrieved) {\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(decrypted.accessControlSecret)\n this.addToCache({ exchangeData: data, hashes, decrypted })\n } else {\n this.addToCache({ exchangeData: data, hashes: [] })\n }\n res[data.id!] = {\n exchangeKey: decrypted?.exchangeKey,\n accessControlSecret: decrypted?.accessControlSecret,\n exchangeData: data,\n }\n }\n }\n return res\n } finally {\n release()\n }\n }\n\n async getOrCreateEncryptionDataTo(\n delegateId: string,\n options?: {\n allowCreationWithoutDelegatorKey?: boolean\n allowCreationWithoutDelegateKey?: boolean\n }\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n const release = await this.cacheMutex.acquire()\n try {\n let existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n if (!existingId) {\n await this.populateCacheToDelegate(delegateId)\n existingId = this.delegateToVerifiedEncryptionDataId.get(delegateId)\n }\n if (existingId) {\n const cached = this.idToData.getCached(existingId)\n if (!cached) throw new Error(`Illegal state: data with id ${existingId} should have been in cache`)\n if (cached.decrypted) {\n return {\n exchangeData: cached.exchangeData,\n exchangeKey: cached.decrypted.exchangeKey,\n accessControlSecret: cached.decrypted.accessControlSecret,\n sharedSignatureKey: cached.decrypted.sharedSignatureKey,\n }\n } else throw new Error(`Illegal state: cached verified data should be decrypted.`)\n } else {\n const created = await this.createNewExchangeData(delegateId, {\n allowNoDelegateKeys: options?.allowCreationWithoutDelegateKey ?? false,\n allowNoDelegatorKeys: options?.allowCreationWithoutDelegatorKey ?? false,\n })\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(created.accessControlSecret)\n const data = {\n exchangeData: created.exchangeData,\n decrypted: {\n accessControlSecret: created.accessControlSecret,\n exchangeKey: created.exchangeKey,\n sharedSignatureKey: created.sharedSignatureKey,\n verified: true,\n },\n hashes,\n }\n this.addToCache(data)\n return {\n exchangeData: data.exchangeData,\n exchangeKey: data.decrypted.exchangeKey,\n accessControlSecret: data.decrypted.accessControlSecret,\n sharedSignatureKey: data.decrypted.sharedSignatureKey,\n }\n }\n } finally {\n release()\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(delegateId: string): Promise<void> {\n const dataToDelegate = await this.base.getExchangeDataByDelegatorDelegatePair(await this.dataOwnerApi.getCurrentDataOwnerId(), delegateId)\n for (const data of dataToDelegate) {\n const decrypted = await this.decryptData(data)\n if (decrypted) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(decrypted.accessControlSecret)\n this.addToCache({ exchangeData: data, hashes, decrypted })\n } else {\n this.addToCache({ exchangeData: data, hashes: [] })\n }\n }\n }\n\n private addToCache(data: CachedExchangeData & { hashes: string[] }) {\n if (this.idToData.size >= this.maxCachedExchangeData) {\n this.evictOneEntry()\n }\n data.hashes.forEach((hash) => this.hashToId.set(hash, data.exchangeData.id!))\n if (data.decrypted?.verified && !this.delegateToVerifiedEncryptionDataId.has(data.exchangeData.delegate)) {\n this.delegateToVerifiedEncryptionDataId.set(data.exchangeData.delegate, data.exchangeData.id!)\n }\n this.idToData.set(data.exchangeData.id!, data)\n }\n\n private evictOneEntry() {\n const evicted = this.idToData.evictLeastRecentlyUsed()\n evicted.hashes.forEach((hash) => this.hashToId.delete(hash))\n if (this.delegateToVerifiedEncryptionDataId.get(evicted.exchangeData.delegate) === evicted.exchangeData.id) {\n this.delegateToVerifiedEncryptionDataId.delete(evicted.exchangeData.delegate)\n }\n }\n\n getAccessControlKeysValue(): Promise<string | undefined> {\n return Promise.resolve(undefined)\n }\n\n getAllDelegationKeys(): Promise<string[] | undefined> {\n return Promise.resolve(undefined)\n }\n\n protected async cacheInjectedExchangeData(\n exchangeDataDetails: {\n exchangeData: ExchangeData\n accessControlSecret: string\n exchangeKey: CryptoKey\n sharedSignatureKey: CryptoKey\n verified: boolean\n }[]\n ): Promise<void> {\n for (const details of exchangeDataDetails) {\n const hashes = await this.accessControlSecret.allSecureDelegationKeysFor(details.accessControlSecret)\n const data = {\n exchangeData: details.exchangeData,\n decrypted: {\n accessControlSecret: details.accessControlSecret,\n exchangeKey: details.exchangeKey,\n sharedSignatureKey: details.sharedSignatureKey,\n verified: details.verified,\n },\n hashes,\n }\n this.addToCache(data)\n }\n }\n}\n"]}
@@ -259,7 +259,7 @@ export interface ExtendedApisUtils {
259
259
  * @throws if the provided data owner can't access any encryption keys for the entity, or if no key could be found which provided valid decrypted
260
260
  * content according to the validator.
261
261
  */
262
- tryDecryptDataOf(entity: EncryptedEntityWithType, content: ArrayBuffer | Uint8Array, validator: (decryptedData: ArrayBuffer) => Promise<boolean> | undefined): Promise<{
262
+ tryDecryptDataOf(entity: EncryptedEntityWithType, content: ArrayBuffer | Uint8Array, postProcessor?: (decryptedData: ArrayBuffer) => Promise<ArrayBuffer | undefined>): Promise<{
263
263
  data: ArrayBuffer;
264
264
  wasDecrypted: boolean;
265
265
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"ExtendedApisUtils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExtendedApisUtils.ts"],"names":[],"mappings":"","sourcesContent":["import { EncryptedEntity, EncryptedEntityStub } from '../../icc-api/model/models'\nimport { EncryptedEntityWithType, EntityWithDelegationTypeName } from '../utils/EntityWithDelegationTypeName'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { EntityShareOrMetadataUpdateRequest } from '../../icc-api/model/requests/EntityShareOrMetadataUpdateRequest'\nimport { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest'\nimport { EntityBulkShareResult } from '../../icc-api/model/requests/EntityBulkShareResult'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { ShareMetadataBehaviour } from './ShareMetadataBehaviour'\nimport { ShareResult } from '../utils/ShareResult'\nimport { MinimalEntityBulkShareResult } from '../../icc-api/model/requests/MinimalEntityBulkShareResult'\nimport { EncryptedFieldsManifest } from '../utils'\nimport { BulkShareOrUpdateMetadataParams } from '../../icc-api/model/requests/BulkShareOrUpdateMetadataParams'\nimport { SecretIdUseOption } from './SecretIdUseOption'\n\n/**\n * @internal this interface is meant only for internal use and may be changed without notice.\n * Gives access to several functions to access encrypted entities metadata.\n */\nexport interface ExtendedApisUtils {\n // region metadata decryption\n /**\n * Get the encryption keys of an entity that the provided data owner can access, potentially using the keys for his parent.\n * There should only be one encryption key for each entity, but the method supports more to allow to deal with conflicts and merged duplicate data.\n * @param entity an encrypted entity.\n * @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.\n * @return the encryption keys that the provided data owner can decrypt, deduplicated.\n */\n encryptionKeysOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>\n\n /**\n * Get the encryption keys of an entity that the current data owner and his parents can access. The resulting array contains the keys for each data\n * owner in the hierarchy which can be decrypted using only that data owner keys (excludes keys accessible through the parent keys). The order of\n * the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.\n * Note that different data owners may have access to the same keys, but the keys extracted for each data owner are deduplicated.\n * There should only be one encryption key for each entity, but the method supports more to allow to deal with conflicts and merged duplicate data.\n * @param entity an encrypted entity.\n * @return the encryption keys that each member of the current data owner hierarchy can decrypt using only his keys and not keys of his parents.\n */\n encryptionKeysForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{ ownerId: string; extracted: string[] }[]>\n\n /**\n * Get the secret ids (SFKs) of an entity that the provided data owner can access, potentially using the keys for his parent.\n * @param entity an encrypted entity.\n * @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.\n * @return the secret ids (SFKs) that the provided data owner can decrypt, deduplicated.\n */\n secretIdsOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>\n\n /**\n * Get the secret ids (SFKs) of an entity that the current data owner and his parents can access. The resulting array contains the ids for each data\n * owner in the hierarchy which can be decrypted using only that data owner keys (excludes ids accessible through the parent keys). The order of\n * the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.\n * Note that different data owners may have access to the same secret ids, but the secret ids extracted for each data owner are deduplicated.\n * @param entity an encrypted entity.\n * @return the secret ids that each member of the current data owner hierarchy can decrypt using only his keys and not keys of his parents.\n */\n secretIdsForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{ ownerId: string; extracted: string[] }[]>\n\n /**\n * Get the decrypted owning entity ids (formerly CFKs) for the provided entity that can be decrypted using the private keys of the current data\n * owner and his parents. The owning entity id would be, for example, the id of a patient for contact and healthcare elements, or the id of a\n * message for documents.\n * There should only be one owning entity id for each entity, but the method supports more to allow to deal with conflicts and merged duplicate\n * data.\n * @param entity an encrypted entity.\n * @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.\n * @return the owning entity ids (CFKs) that the provided data owner can decrypt, deduplicated.\n */\n owningEntityIdsOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>\n\n /**\n * Get the decrypted owning entity ids (formerly CFKs) for the provided entity that can be decrypted using the private keys of the current data\n * owner and his parents. The owning entity id would be, for example, the id of a patient for contact and healthcare elements, or the id of a\n * message for documents.\n * The resulting array contains the ids for each data owner in the hierarchy which can be decrypted using only that data owner keys (excludes ids\n * accessible through the parent keys). The order of the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.\n * Note that different data owners may have access to the same owning entity ids, but the owning entity ids extracted for each data owner are\n * deduplicated in case they could be accessed through different delegations.\n * There should only be one owning entity id for each entity, but the method supports more to allow to deal with conflicts and merged duplicate\n * data.\n * @param entity an encrypted entity.\n * @return the owning entity ids that each member of the current data owner hierarchy can decrypt using only his keys and not keys of his parents.\n */\n owningEntityIdsForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{ ownerId: string; extracted: string[] }[]>\n\n /**\n * Get if the current data owner has write access to the content of the entity.\n * @param entity an entity\n * @return if the current data owner (or one of his parents) has write access to the content of the entity.\n */\n hasWriteAccess(entity: EncryptedEntityWithType): Promise<boolean>\n\n /**\n * @param entity an entity\n * @return if the entity has no encryption metadata and can be safely initialised using .\n */\n hasEmptyEncryptionMetadata(entity: EncryptedEntity): boolean\n // endregion\n\n // region metadata initialisation and share\n resolveSecretIdUseOptions(entity: EncryptedEntityWithType, option: SecretIdUseOption): Promise<string[]>\n\n /**\n * Initializes encryption metadata for an entity. This includes the encrypted secret id, owning entity id, encryption key for the entity, and\n * the clear text secret foreign key of the parent entity.\n * This method returns a modified copy of the entity and DOES NOT SAVE the entity to the cloud/DB: you will have to save the entity manually.\n * @param entity entity which requires encryption metadata initialisation.\n * @param entityType type of the entity.\n * @param owningEntity id of the owning entity, if any (e.g. patient id for Contact/HealtchareElement, message id for Document, ...).\n * @param owningEntitySecretIds secret id of the parent entity, to use in the secret foreign keys for the provided entity, if any.\n * @param initialiseEncryptionKey if false this method will not initialize an encryption key for the entity. Use only for entities which use\n * delegations for access control but don't actually have any encrypted content.\n * HealthcareElement).\n * @param autoDelegations automatically shares the metadata with the provided data owners, with the provided access level.\n * @param alternateRootDelegation by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @throws if the entity already has non-empty values for encryption metadata.\n * @return an updated copy of the entity.\n */\n entityWithInitialisedEncryptedMetadata<T extends EncryptedEntity>(\n entity: T,\n entityType: EntityWithDelegationTypeName,\n owningEntity: string | undefined,\n owningEntitySecretIds: string[] | undefined,\n initialiseEncryptionKey: boolean,\n autoDelegations: { [p: string]: SecureDelegation.AccessLevelEnum },\n alternateRootDelegation: string | undefined\n ): Promise<{ updatedEntity: T; rawEncryptionKey: string | undefined; secretId: string | undefined }>\n\n /**\n * Updates encryption metadata for an entity in order to share it with a delegate or in order to add additional encrypted metadata for an existing\n * delegate.\n * The first time this method is used for a specific delegate it will give access to all unencrypted content of the entity to the delegate data\n * owner. Additionally, this method also allows to share new or existing secret ids (shareSecretId), encryption keys (shareEncryptionKeys) and\n * owning entity ids (shareOwningEntityIds) for the entity.\n * You can use methods like {@link secretIdsOf}, {@link secretIdsForHcpHierarchyOf}, {@link encryptionKeysOf}, ... to retrieve the data you want to\n * share. In most cases you may want to share everything related to the entity, but note that if you use confidential delegations for patients you\n * may want to avoid sharing the confidential secret ids of the current user with other hcps.\n * This updates the entity in the cloud/DB (the updated entities in the returned promise are already saved in the DB). NOTE: this method can only\n * be used with entities which already exist in the cloud (the entities must have been saved).\n * @param entitiesType type of entities to update\n * @param entitiesUpdates share/update requests for each entity. An array of objects containing:\n * - The entity to share/update (or at least its encrypted metadata)\n * - The data to share/update for each delegate. An object associating to each delegate id the data to share/update for that delegate, and the\n * permissions requested for the delegate (ignored if the request will only update already existing shared metadata).\n * @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).\n * @throws if there are duplicate entities in the requested updates.\n * @return a promise which will be completed with an object containing:\n * - the updated entities, only for entities were at least one update was successful\n * - information on the individual requests failed, containing the id of the entity, id of the delegate that the request was for, the content,\n * an error code mirroring an http status code, and a human-friendly description of the error (but not necessarily end-user friendly).\n */\n bulkShareOrUpdateEncryptedEntityMetadata<T extends EncryptedEntityStub>(\n entitiesType: EntityWithDelegationTypeName,\n entitiesUpdates: {\n entity: EncryptedEntityStub\n dataForDelegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n shareEncryptionKeys: string[]\n shareOwningEntityIds: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n }\n }[],\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>\n ): Promise<{\n updatedEntities: T[]\n unmodifiedEntitiesIds: string[]\n updateErrors: {\n entityId: string\n delegateId: string\n request?: {\n shareSecretIds?: string[]\n shareEncryptionKeys?: string[]\n shareOwningEntityIds?: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n updatedForMigration: boolean\n code?: number\n reason?: string\n }[]\n }>\n\n bulkShareOrUpdateEncryptedEntityMetadataNoEntities(\n entitiesType: EntityWithDelegationTypeName,\n entitiesUpdates: {\n entity: EncryptedEntityStub\n dataForDelegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n shareEncryptionKeys: string[]\n shareOwningEntityIds: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n }\n }[],\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<MinimalEntityBulkShareResult[]>\n ): Promise<{\n unmodifiedEntitiesIds: string[]\n successfulUpdates: { entityId: string; delegateId: string }[]\n updateErrors: {\n entityId: string\n delegateId: string\n request?: {\n shareSecretIds?: string[]\n shareEncryptionKeys?: string[]\n shareOwningEntityIds?: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n updatedForMigration: boolean\n code?: number\n reason?: string\n }[]\n }>\n\n /**\n * Simplified version of {@link bulkShareOrUpdateEncryptedEntityMetadata} for a single entity and with automatic retrieval of the encryption keys\n * and owning entity ids if requested. NOTE: this method can only be used with entities which already exist in the cloud (the entity must have\n * been saved).\n * @param entity an entity.\n * versions. If true the method expects `shareSecretIds` options to always be undefined and will always share any available secret ids. If false\n * it expects `shareSecretIds` options to always be defined and will only share the secret ids specified in the options.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKeys specifies if the encryption keys of the entity should be shared. Defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}.\n * - shareOwningEntityIds specifies if the owning entity ids of the entity should be shared. Defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}.\n * - shareSecretIds specifies which secret ids of the entity should be shared. Should be defined only if {@link unusedSecretIds} is false.\n * - requestedPermissions requested permissions for the delegate. Defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).\n * @return a promise which will be completed with the result of the operation\n * @throws if shareEncryptionKeys or shareOwningEntityIds is {@link ShareMetadataBehaviour.REQUIRED} and the current data owner can't access any\n * value for the required metadata.\n */\n simpleShareOrUpdateEncryptedEntityMetadata<T extends EncryptedEntityStub>(\n entity: { entity: T; type: EntityWithDelegationTypeName },\n delegates: {\n [p: string]: {\n shareSecretIds: string[] | undefined\n shareEncryptionKeys: ShareMetadataBehaviour | undefined\n shareOwningEntityIds: ShareMetadataBehaviour | undefined\n requestedPermissions: EntityShareRequest.RequestedPermissionEnum | undefined\n }\n },\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>\n ): Promise<ShareResult<T>>\n // endregion\n\n // region content encryption and decryption\n /**\n * Encrypts data using a key of the entity that the provided data owner can access (current data owner by default). If the provided data owner can\n * access multiple encryption keys of the entity there is no guarantee on which key will be used.\n * Note: you should not use this method to encrypt the `encryptedSelf` of iCure entities, since that will be automatically handled by the extended\n * apis. You should use this method only to encrypt additional data, such as document attachments.\n * @param entity an entity.\n * @param type type of the entity.\n * @param content data of the entity which you want to encrypt.\n * @param saveEntity a function which saves the entity to the cloud/DB. Used only if a new encryption key needed to be initialised for the entity.\n * @return the encrypted data and, if a new encryption key was initialised for the entity, the updated entity.\n * @throws if the provided data owner can't access any encryption keys for the entity.\n */\n encryptDataOf<T extends EncryptedEntityStub>(\n entity: T,\n type: EntityWithDelegationTypeName,\n content: ArrayBuffer | Uint8Array,\n saveEntity: (entity: T) => Promise<T>\n ): Promise<{ encryptedData: ArrayBuffer; updatedEntity: T | undefined }>\n\n /**\n * Decrypts data using a key of the entity that the provided data owner can access (current data owner by default). If the provided data owner can\n * access multiple encryption keys each of them will be tried for decryption until one of them gives a result that is valid according to the\n * provided validator.\n * Note: you should not use this method to decrypt the `encryptedSelf` of iCure entities, since that will be automatically handled by the extended\n * apis. You should use this method only to decrypt additional data, such as document attachments.\n * @param entity an entity.\n * @param content data of the entity which you want to decrypt.\n * @param validator a function which verifies the correctness of decrypted content: helps to identify decryption with the wrong key without relying\n * solely on padding.\n * @return the decrypted data.\n * @throws if the provided data owner can't access any encryption keys for the entity, or if no key could be found which provided valid decrypted\n * content according to the validator.\n */\n tryDecryptDataOf(\n entity: EncryptedEntityWithType,\n content: ArrayBuffer | Uint8Array,\n validator: (decryptedData: ArrayBuffer) => Promise<boolean> | undefined\n ): Promise<{ data: ArrayBuffer; wasDecrypted: boolean }>\n\n tryDecryptEntities<T extends EncryptedEntity>(\n entities: T[],\n entityType: EntityWithDelegationTypeName,\n constructor: (json: any) => T\n ): Promise<{ entity: T; decrypted: boolean }[]>\n\n /**\n * Tries to decrypt data to a json object using the provided keys.\n */\n tryDecryptJson(potentialKeys: { key: CryptoKey; raw: string }[], encrypted: Uint8Array, truncateTrailingDecryptedNulls: boolean): Promise<{} | null>\n\n /**\n * Tries to encrypt the content of an encrypted entity.\n * 1. If valid key for encryption is found the method returns the entity with the encrypted fields specified by cryptedKeys\n * 2. If requireEncryption is true and no key could be found for encryption of the entity the method fails.\n * 3. If requireEncryption is false and no key could be found for encryption the method will only check that the entity does not specify any value\n * for fields which should be encrypted according to cryptedKeys (e.g. note in a patient using the default configuration). If the entity specifies\n * a value for any field which should be encrypted the method throws an error, otherwise the method returns the original entity.\n */\n tryEncryptEntities<T extends EncryptedEntity>(\n entities: T[],\n entityType: EntityWithDelegationTypeName,\n fieldsToEncrypt: EncryptedFieldsManifest,\n encodeBinaryData: boolean,\n requireEncryption: boolean,\n constructor: (json: any) => T\n ): Promise<T[]>\n\n /**\n * Verifies if the entity has valid encryption keys (regardless of whether the current data owner has access to them or not). If not this method\n * will throw an error, otherwise it will return undefined. For pre-2018 users there are some cases where the data may have been encrypted with a\n * key not safe for encryption anymore, in which case this method will return the entity with a new and safe encryption key.\n * After this method is called, if it returns an entity it should also be re-encrypted (using the new key) and saved to the cloud.\n */\n ensureEncryptionKeysInitialised<T extends EncryptedEntity>(entity: T, entityType: EntityWithDelegationTypeName): Promise<T | undefined>\n\n /**\n * Attempts to do the action providing \"incrementally decrypted\" keys as input; stops the first time the action\n * completes successfully.\n * The method tries to decrypt encryption keys for the entity \"incrementally\", trying first to decrypt keys that\n * require less effort for decryption (e.g. using already cached exchange data or using exchange data for which the\n * id is known without going through the exchange data map). Each time one or more new keys are decrypted the action\n * is called providing ALL keys decrypted up to that point.\n * If no key can be decrypted at all the method returns null without ever attempting the action (the action always\n * receives at least a key in input or is not called).\n * @param entity the entity from which to decrypt the encryption keys.\n * @param entityType the type of entity\n * @param action the action that consumes the encryption key.\n * @return the wrapped result of the first successful action invocation, or null if the action never succeeded or if\n * no key could be decrypted\n */\n doIncrementallyDecryptingKeys<E extends EncryptedEntity | EncryptedEntityStub, T>(\n entity: E,\n entityType: EntityWithDelegationTypeName,\n action: (entity: E, entityType: EntityWithDelegationTypeName, keys: { key: CryptoKey; raw: string }[]) => Promise<{ success: T } | null>\n ): Promise<{ success: T } | null>\n\n /**\n * Bulk version of {@link doIncrementallyDecryptingKeys}.\n * Differences:\n * - The action is called until it succeeds for all entities or until all decryptable keys have been tried.\n * - For each input the action must return an entry for that entity id with the result if successful or not include\n * the entity id in the result keys if unsuccessful.\n * - An attempt on the action is done only if new keys could be decrypted for all the entities.\n * Additionally, there will be a final attempt after attempting all decryption steps if at least a new key could be\n * decrypted for an entity since the last attempt.\n * In this case entities for which no new key could be decrypted are omitted from the input.\n * @param entities\n * @param entitiesType\n * @param action\n * @return all entities id for which the action completed successfully associated to the result.\n */\n doManyIncrementallyDecryptingKeys<E extends EncryptedEntity | EncryptedEntityStub, T>(\n entities: E[],\n entitiesType: EntityWithDelegationTypeName,\n action: (entity: E, entityType: EntityWithDelegationTypeName, keys: { key: CryptoKey; raw: string }[]) => Promise<{ success: T } | null>\n ): Promise<Map<string, T>>\n // endregion\n\n // region confidential ids\n\n /**\n * Ensures that the current data owner has access to a confidential secret id for the provided entity: this is an id that is known to the data owner\n * but is not known by any of his parents. If there is currently no confidential secret id for this entity the method returns a copy of the entity\n * with a new confidential secret id for the current data owner (the entity in the database won't be updated), else this method returns undefined.\n * New confidential secret ids will have an appropriate tag, but existing confidential secret ids may not necessarily have it.\n * @param entity an entity which needs to have a confidential secret id for the current data owner\n * @param entityType the type of the entity\n * @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).\n * @return undefined if the entity already had a confidential secret id for the current user, or the updated AND SAVED entity with the new\n * confidential secret id.\n */\n initialiseConfidentialSecretId<T extends EncryptedEntity>(\n entity: T,\n entityType: EntityWithDelegationTypeName,\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>\n ): Promise<T | undefined>\n\n /**\n * Get an existing confidential secret id of the provided entity for the provided data owner (current data owner by default). A confidential secret\n * id is a secret id known by the data owner but not known by any of his parents: note however that children will know confidential secret ids.\n * @param entity an entity for which you want to retrieve the confidential secret id.\n * @param dataOwnerId (current data owner by default) a data owner for which you want to get a confidential secret id.\n * @return the confidential secret id or undefined if there is no confidential secret id for the provided data owner.\n */\n getConfidentialSecretId(entity: EncryptedEntityWithType, dataOwnerId?: string): Promise<string | undefined>\n\n /**\n * Get all existing confidential secret ids of the provided entity for the provided data owner (current data owner by default). A confidential secret\n * id is a secret id known by the data owner but not known by any of his parents: note however that children will know confidential secret ids.\n * @param entity an entity for which you want to retrieve the confidential secret id.\n * @param dataOwnerId (current data owner by default) a data owner for which you want to get a confidential secret id.\n * @return the confidential secret ids for the data owner (may be empty).\n */\n getConfidentialSecretIds(entity: EncryptedEntityWithType, dataOwnerId?: string): Promise<string[]>\n\n /**\n * Gets a secret id known by the topmost parent of the current data owner hierarchy. If there is multiple secret ids shared with the topmost parent\n * there is no guarantee on which one will be chosen.\n * @param entity an entity.\n * @return a secret id known by the topmost parent of the current data owner hierarchy, or undefined if there is no secret id currently available\n * for the topmost parent.\n */\n getAnySecretIdSharedWithParents(entity: EncryptedEntityWithType): Promise<string | undefined>\n\n /**\n * Gets all secret ids known by the topmost parent of the current data owner hierarchy (or all secret ids known by the current data owner if he is\n * not part of any data owner hierarchy).\n * @param entity an entity.\n * @return all secret ids known by the topmost parent of the current data owner hierarchy, may be empty.\n */\n getSecretIdsSharedWithParents(entity: EncryptedEntityWithType): Promise<string[]>\n // endregion\n}\n"]}
1
+ {"version":3,"file":"ExtendedApisUtils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExtendedApisUtils.ts"],"names":[],"mappings":"","sourcesContent":["import { EncryptedEntity, EncryptedEntityStub } from '../../icc-api/model/models'\nimport { EncryptedEntityWithType, EntityWithDelegationTypeName } from '../utils/EntityWithDelegationTypeName'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { EntityShareOrMetadataUpdateRequest } from '../../icc-api/model/requests/EntityShareOrMetadataUpdateRequest'\nimport { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest'\nimport { EntityBulkShareResult } from '../../icc-api/model/requests/EntityBulkShareResult'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\nimport { ShareMetadataBehaviour } from './ShareMetadataBehaviour'\nimport { ShareResult } from '../utils/ShareResult'\nimport { MinimalEntityBulkShareResult } from '../../icc-api/model/requests/MinimalEntityBulkShareResult'\nimport { EncryptedFieldsManifest } from '../utils'\nimport { BulkShareOrUpdateMetadataParams } from '../../icc-api/model/requests/BulkShareOrUpdateMetadataParams'\nimport { SecretIdUseOption } from './SecretIdUseOption'\n\n/**\n * @internal this interface is meant only for internal use and may be changed without notice.\n * Gives access to several functions to access encrypted entities metadata.\n */\nexport interface ExtendedApisUtils {\n // region metadata decryption\n /**\n * Get the encryption keys of an entity that the provided data owner can access, potentially using the keys for his parent.\n * There should only be one encryption key for each entity, but the method supports more to allow to deal with conflicts and merged duplicate data.\n * @param entity an encrypted entity.\n * @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.\n * @return the encryption keys that the provided data owner can decrypt, deduplicated.\n */\n encryptionKeysOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>\n\n /**\n * Get the encryption keys of an entity that the current data owner and his parents can access. The resulting array contains the keys for each data\n * owner in the hierarchy which can be decrypted using only that data owner keys (excludes keys accessible through the parent keys). The order of\n * the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.\n * Note that different data owners may have access to the same keys, but the keys extracted for each data owner are deduplicated.\n * There should only be one encryption key for each entity, but the method supports more to allow to deal with conflicts and merged duplicate data.\n * @param entity an encrypted entity.\n * @return the encryption keys that each member of the current data owner hierarchy can decrypt using only his keys and not keys of his parents.\n */\n encryptionKeysForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{ ownerId: string; extracted: string[] }[]>\n\n /**\n * Get the secret ids (SFKs) of an entity that the provided data owner can access, potentially using the keys for his parent.\n * @param entity an encrypted entity.\n * @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.\n * @return the secret ids (SFKs) that the provided data owner can decrypt, deduplicated.\n */\n secretIdsOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>\n\n /**\n * Get the secret ids (SFKs) of an entity that the current data owner and his parents can access. The resulting array contains the ids for each data\n * owner in the hierarchy which can be decrypted using only that data owner keys (excludes ids accessible through the parent keys). The order of\n * the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.\n * Note that different data owners may have access to the same secret ids, but the secret ids extracted for each data owner are deduplicated.\n * @param entity an encrypted entity.\n * @return the secret ids that each member of the current data owner hierarchy can decrypt using only his keys and not keys of his parents.\n */\n secretIdsForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{ ownerId: string; extracted: string[] }[]>\n\n /**\n * Get the decrypted owning entity ids (formerly CFKs) for the provided entity that can be decrypted using the private keys of the current data\n * owner and his parents. The owning entity id would be, for example, the id of a patient for contact and healthcare elements, or the id of a\n * message for documents.\n * There should only be one owning entity id for each entity, but the method supports more to allow to deal with conflicts and merged duplicate\n * data.\n * @param entity an encrypted entity.\n * @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.\n * @return the owning entity ids (CFKs) that the provided data owner can decrypt, deduplicated.\n */\n owningEntityIdsOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>\n\n /**\n * Get the decrypted owning entity ids (formerly CFKs) for the provided entity that can be decrypted using the private keys of the current data\n * owner and his parents. The owning entity id would be, for example, the id of a patient for contact and healthcare elements, or the id of a\n * message for documents.\n * The resulting array contains the ids for each data owner in the hierarchy which can be decrypted using only that data owner keys (excludes ids\n * accessible through the parent keys). The order of the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.\n * Note that different data owners may have access to the same owning entity ids, but the owning entity ids extracted for each data owner are\n * deduplicated in case they could be accessed through different delegations.\n * There should only be one owning entity id for each entity, but the method supports more to allow to deal with conflicts and merged duplicate\n * data.\n * @param entity an encrypted entity.\n * @return the owning entity ids that each member of the current data owner hierarchy can decrypt using only his keys and not keys of his parents.\n */\n owningEntityIdsForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{ ownerId: string; extracted: string[] }[]>\n\n /**\n * Get if the current data owner has write access to the content of the entity.\n * @param entity an entity\n * @return if the current data owner (or one of his parents) has write access to the content of the entity.\n */\n hasWriteAccess(entity: EncryptedEntityWithType): Promise<boolean>\n\n /**\n * @param entity an entity\n * @return if the entity has no encryption metadata and can be safely initialised using .\n */\n hasEmptyEncryptionMetadata(entity: EncryptedEntity): boolean\n // endregion\n\n // region metadata initialisation and share\n resolveSecretIdUseOptions(entity: EncryptedEntityWithType, option: SecretIdUseOption): Promise<string[]>\n\n /**\n * Initializes encryption metadata for an entity. This includes the encrypted secret id, owning entity id, encryption key for the entity, and\n * the clear text secret foreign key of the parent entity.\n * This method returns a modified copy of the entity and DOES NOT SAVE the entity to the cloud/DB: you will have to save the entity manually.\n * @param entity entity which requires encryption metadata initialisation.\n * @param entityType type of the entity.\n * @param owningEntity id of the owning entity, if any (e.g. patient id for Contact/HealtchareElement, message id for Document, ...).\n * @param owningEntitySecretIds secret id of the parent entity, to use in the secret foreign keys for the provided entity, if any.\n * @param initialiseEncryptionKey if false this method will not initialize an encryption key for the entity. Use only for entities which use\n * delegations for access control but don't actually have any encrypted content.\n * HealthcareElement).\n * @param autoDelegations automatically shares the metadata with the provided data owners, with the provided access level.\n * @param alternateRootDelegation by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible,\n * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation.\n * @throws if the entity already has non-empty values for encryption metadata.\n * @return an updated copy of the entity.\n */\n entityWithInitialisedEncryptedMetadata<T extends EncryptedEntity>(\n entity: T,\n entityType: EntityWithDelegationTypeName,\n owningEntity: string | undefined,\n owningEntitySecretIds: string[] | undefined,\n initialiseEncryptionKey: boolean,\n autoDelegations: { [p: string]: SecureDelegation.AccessLevelEnum },\n alternateRootDelegation: string | undefined\n ): Promise<{ updatedEntity: T; rawEncryptionKey: string | undefined; secretId: string | undefined }>\n\n /**\n * Updates encryption metadata for an entity in order to share it with a delegate or in order to add additional encrypted metadata for an existing\n * delegate.\n * The first time this method is used for a specific delegate it will give access to all unencrypted content of the entity to the delegate data\n * owner. Additionally, this method also allows to share new or existing secret ids (shareSecretId), encryption keys (shareEncryptionKeys) and\n * owning entity ids (shareOwningEntityIds) for the entity.\n * You can use methods like {@link secretIdsOf}, {@link secretIdsForHcpHierarchyOf}, {@link encryptionKeysOf}, ... to retrieve the data you want to\n * share. In most cases you may want to share everything related to the entity, but note that if you use confidential delegations for patients you\n * may want to avoid sharing the confidential secret ids of the current user with other hcps.\n * This updates the entity in the cloud/DB (the updated entities in the returned promise are already saved in the DB). NOTE: this method can only\n * be used with entities which already exist in the cloud (the entities must have been saved).\n * @param entitiesType type of entities to update\n * @param entitiesUpdates share/update requests for each entity. An array of objects containing:\n * - The entity to share/update (or at least its encrypted metadata)\n * - The data to share/update for each delegate. An object associating to each delegate id the data to share/update for that delegate, and the\n * permissions requested for the delegate (ignored if the request will only update already existing shared metadata).\n * @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).\n * @throws if there are duplicate entities in the requested updates.\n * @return a promise which will be completed with an object containing:\n * - the updated entities, only for entities were at least one update was successful\n * - information on the individual requests failed, containing the id of the entity, id of the delegate that the request was for, the content,\n * an error code mirroring an http status code, and a human-friendly description of the error (but not necessarily end-user friendly).\n */\n bulkShareOrUpdateEncryptedEntityMetadata<T extends EncryptedEntityStub>(\n entitiesType: EntityWithDelegationTypeName,\n entitiesUpdates: {\n entity: EncryptedEntityStub\n dataForDelegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n shareEncryptionKeys: string[]\n shareOwningEntityIds: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n }\n }[],\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>\n ): Promise<{\n updatedEntities: T[]\n unmodifiedEntitiesIds: string[]\n updateErrors: {\n entityId: string\n delegateId: string\n request?: {\n shareSecretIds?: string[]\n shareEncryptionKeys?: string[]\n shareOwningEntityIds?: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n updatedForMigration: boolean\n code?: number\n reason?: string\n }[]\n }>\n\n bulkShareOrUpdateEncryptedEntityMetadataNoEntities(\n entitiesType: EntityWithDelegationTypeName,\n entitiesUpdates: {\n entity: EncryptedEntityStub\n dataForDelegates: {\n [delegateId: string]: {\n shareSecretIds: string[]\n shareEncryptionKeys: string[]\n shareOwningEntityIds: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n }\n }[],\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<MinimalEntityBulkShareResult[]>\n ): Promise<{\n unmodifiedEntitiesIds: string[]\n successfulUpdates: { entityId: string; delegateId: string }[]\n updateErrors: {\n entityId: string\n delegateId: string\n request?: {\n shareSecretIds?: string[]\n shareEncryptionKeys?: string[]\n shareOwningEntityIds?: string[]\n requestedPermissions: RequestedPermissionEnum\n }\n updatedForMigration: boolean\n code?: number\n reason?: string\n }[]\n }>\n\n /**\n * Simplified version of {@link bulkShareOrUpdateEncryptedEntityMetadata} for a single entity and with automatic retrieval of the encryption keys\n * and owning entity ids if requested. NOTE: this method can only be used with entities which already exist in the cloud (the entity must have\n * been saved).\n * @param entity an entity.\n * versions. If true the method expects `shareSecretIds` options to always be undefined and will always share any available secret ids. If false\n * it expects `shareSecretIds` options to always be defined and will only share the secret ids specified in the options.\n * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:\n * - shareEncryptionKeys specifies if the encryption keys of the entity should be shared. Defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}.\n * - shareOwningEntityIds specifies if the owning entity ids of the entity should be shared. Defaults to\n * {@link ShareMetadataBehaviour.IF_AVAILABLE}.\n * - shareSecretIds specifies which secret ids of the entity should be shared. Should be defined only if {@link unusedSecretIds} is false.\n * - requestedPermissions requested permissions for the delegate. Defaults to {@link RequestedPermissionEnum.MAX_WRITE}.\n * @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).\n * @return a promise which will be completed with the result of the operation\n * @throws if shareEncryptionKeys or shareOwningEntityIds is {@link ShareMetadataBehaviour.REQUIRED} and the current data owner can't access any\n * value for the required metadata.\n */\n simpleShareOrUpdateEncryptedEntityMetadata<T extends EncryptedEntityStub>(\n entity: { entity: T; type: EntityWithDelegationTypeName },\n delegates: {\n [p: string]: {\n shareSecretIds: string[] | undefined\n shareEncryptionKeys: ShareMetadataBehaviour | undefined\n shareOwningEntityIds: ShareMetadataBehaviour | undefined\n requestedPermissions: EntityShareRequest.RequestedPermissionEnum | undefined\n }\n },\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>\n ): Promise<ShareResult<T>>\n // endregion\n\n // region content encryption and decryption\n /**\n * Encrypts data using a key of the entity that the provided data owner can access (current data owner by default). If the provided data owner can\n * access multiple encryption keys of the entity there is no guarantee on which key will be used.\n * Note: you should not use this method to encrypt the `encryptedSelf` of iCure entities, since that will be automatically handled by the extended\n * apis. You should use this method only to encrypt additional data, such as document attachments.\n * @param entity an entity.\n * @param type type of the entity.\n * @param content data of the entity which you want to encrypt.\n * @param saveEntity a function which saves the entity to the cloud/DB. Used only if a new encryption key needed to be initialised for the entity.\n * @return the encrypted data and, if a new encryption key was initialised for the entity, the updated entity.\n * @throws if the provided data owner can't access any encryption keys for the entity.\n */\n encryptDataOf<T extends EncryptedEntityStub>(\n entity: T,\n type: EntityWithDelegationTypeName,\n content: ArrayBuffer | Uint8Array,\n saveEntity: (entity: T) => Promise<T>\n ): Promise<{ encryptedData: ArrayBuffer; updatedEntity: T | undefined }>\n\n /**\n * Decrypts data using a key of the entity that the provided data owner can access (current data owner by default). If the provided data owner can\n * access multiple encryption keys each of them will be tried for decryption until one of them gives a result that is valid according to the\n * provided validator.\n * Note: you should not use this method to decrypt the `encryptedSelf` of iCure entities, since that will be automatically handled by the extended\n * apis. You should use this method only to decrypt additional data, such as document attachments.\n * @param entity an entity.\n * @param content data of the entity which you want to decrypt.\n * @param validator a function which verifies the correctness of decrypted content: helps to identify decryption with the wrong key without relying\n * solely on padding.\n * @return the decrypted data.\n * @throws if the provided data owner can't access any encryption keys for the entity, or if no key could be found which provided valid decrypted\n * content according to the validator.\n */\n tryDecryptDataOf(\n entity: EncryptedEntityWithType,\n content: ArrayBuffer | Uint8Array,\n postProcessor?: (decryptedData: ArrayBuffer) => Promise<ArrayBuffer | undefined>\n ): Promise<{ data: ArrayBuffer; wasDecrypted: boolean }>\n\n tryDecryptEntities<T extends EncryptedEntity>(\n entities: T[],\n entityType: EntityWithDelegationTypeName,\n constructor: (json: any) => T\n ): Promise<{ entity: T; decrypted: boolean }[]>\n\n /**\n * Tries to decrypt data to a json object using the provided keys.\n */\n tryDecryptJson(potentialKeys: { key: CryptoKey; raw: string }[], encrypted: Uint8Array, truncateTrailingDecryptedNulls: boolean): Promise<{} | null>\n\n /**\n * Tries to encrypt the content of an encrypted entity.\n * 1. If valid key for encryption is found the method returns the entity with the encrypted fields specified by cryptedKeys\n * 2. If requireEncryption is true and no key could be found for encryption of the entity the method fails.\n * 3. If requireEncryption is false and no key could be found for encryption the method will only check that the entity does not specify any value\n * for fields which should be encrypted according to cryptedKeys (e.g. note in a patient using the default configuration). If the entity specifies\n * a value for any field which should be encrypted the method throws an error, otherwise the method returns the original entity.\n */\n tryEncryptEntities<T extends EncryptedEntity>(\n entities: T[],\n entityType: EntityWithDelegationTypeName,\n fieldsToEncrypt: EncryptedFieldsManifest,\n encodeBinaryData: boolean,\n requireEncryption: boolean,\n constructor: (json: any) => T\n ): Promise<T[]>\n\n /**\n * Verifies if the entity has valid encryption keys (regardless of whether the current data owner has access to them or not). If not this method\n * will throw an error, otherwise it will return undefined. For pre-2018 users there are some cases where the data may have been encrypted with a\n * key not safe for encryption anymore, in which case this method will return the entity with a new and safe encryption key.\n * After this method is called, if it returns an entity it should also be re-encrypted (using the new key) and saved to the cloud.\n */\n ensureEncryptionKeysInitialised<T extends EncryptedEntity>(entity: T, entityType: EntityWithDelegationTypeName): Promise<T | undefined>\n\n /**\n * Attempts to do the action providing \"incrementally decrypted\" keys as input; stops the first time the action\n * completes successfully.\n * The method tries to decrypt encryption keys for the entity \"incrementally\", trying first to decrypt keys that\n * require less effort for decryption (e.g. using already cached exchange data or using exchange data for which the\n * id is known without going through the exchange data map). Each time one or more new keys are decrypted the action\n * is called providing ALL keys decrypted up to that point.\n * If no key can be decrypted at all the method returns null without ever attempting the action (the action always\n * receives at least a key in input or is not called).\n * @param entity the entity from which to decrypt the encryption keys.\n * @param entityType the type of entity\n * @param action the action that consumes the encryption key.\n * @return the wrapped result of the first successful action invocation, or null if the action never succeeded or if\n * no key could be decrypted\n */\n doIncrementallyDecryptingKeys<E extends EncryptedEntity | EncryptedEntityStub, T>(\n entity: E,\n entityType: EntityWithDelegationTypeName,\n action: (entity: E, entityType: EntityWithDelegationTypeName, keys: { key: CryptoKey; raw: string }[]) => Promise<{ success: T } | null>\n ): Promise<{ success: T } | null>\n\n /**\n * Bulk version of {@link doIncrementallyDecryptingKeys}.\n * Differences:\n * - The action is called until it succeeds for all entities or until all decryptable keys have been tried.\n * - For each input the action must return an entry for that entity id with the result if successful or not include\n * the entity id in the result keys if unsuccessful.\n * - An attempt on the action is done only if new keys could be decrypted for all the entities.\n * Additionally, there will be a final attempt after attempting all decryption steps if at least a new key could be\n * decrypted for an entity since the last attempt.\n * In this case entities for which no new key could be decrypted are omitted from the input.\n * @param entities\n * @param entitiesType\n * @param action\n * @return all entities id for which the action completed successfully associated to the result.\n */\n doManyIncrementallyDecryptingKeys<E extends EncryptedEntity | EncryptedEntityStub, T>(\n entities: E[],\n entitiesType: EntityWithDelegationTypeName,\n action: (entity: E, entityType: EntityWithDelegationTypeName, keys: { key: CryptoKey; raw: string }[]) => Promise<{ success: T } | null>\n ): Promise<Map<string, T>>\n // endregion\n\n // region confidential ids\n\n /**\n * Ensures that the current data owner has access to a confidential secret id for the provided entity: this is an id that is known to the data owner\n * but is not known by any of his parents. If there is currently no confidential secret id for this entity the method returns a copy of the entity\n * with a new confidential secret id for the current data owner (the entity in the database won't be updated), else this method returns undefined.\n * New confidential secret ids will have an appropriate tag, but existing confidential secret ids may not necessarily have it.\n * @param entity an entity which needs to have a confidential secret id for the current data owner\n * @param entityType the type of the entity\n * @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).\n * @return undefined if the entity already had a confidential secret id for the current user, or the updated AND SAVED entity with the new\n * confidential secret id.\n */\n initialiseConfidentialSecretId<T extends EncryptedEntity>(\n entity: T,\n entityType: EntityWithDelegationTypeName,\n doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>\n ): Promise<T | undefined>\n\n /**\n * Get an existing confidential secret id of the provided entity for the provided data owner (current data owner by default). A confidential secret\n * id is a secret id known by the data owner but not known by any of his parents: note however that children will know confidential secret ids.\n * @param entity an entity for which you want to retrieve the confidential secret id.\n * @param dataOwnerId (current data owner by default) a data owner for which you want to get a confidential secret id.\n * @return the confidential secret id or undefined if there is no confidential secret id for the provided data owner.\n */\n getConfidentialSecretId(entity: EncryptedEntityWithType, dataOwnerId?: string): Promise<string | undefined>\n\n /**\n * Get all existing confidential secret ids of the provided entity for the provided data owner (current data owner by default). A confidential secret\n * id is a secret id known by the data owner but not known by any of his parents: note however that children will know confidential secret ids.\n * @param entity an entity for which you want to retrieve the confidential secret id.\n * @param dataOwnerId (current data owner by default) a data owner for which you want to get a confidential secret id.\n * @return the confidential secret ids for the data owner (may be empty).\n */\n getConfidentialSecretIds(entity: EncryptedEntityWithType, dataOwnerId?: string): Promise<string[]>\n\n /**\n * Gets a secret id known by the topmost parent of the current data owner hierarchy. If there is multiple secret ids shared with the topmost parent\n * there is no guarantee on which one will be chosen.\n * @param entity an entity.\n * @return a secret id known by the topmost parent of the current data owner hierarchy, or undefined if there is no secret id currently available\n * for the topmost parent.\n */\n getAnySecretIdSharedWithParents(entity: EncryptedEntityWithType): Promise<string | undefined>\n\n /**\n * Gets all secret ids known by the topmost parent of the current data owner hierarchy (or all secret ids known by the current data owner if he is\n * not part of any data owner hierarchy).\n * @param entity an entity.\n * @return all secret ids known by the topmost parent of the current data owner hierarchy, may be empty.\n */\n getSecretIdsSharedWithParents(entity: EncryptedEntityWithType): Promise<string[]>\n // endregion\n}\n"]}
@@ -121,7 +121,7 @@ export declare class ExtendedApisUtilsImpl implements ExtendedApisUtils {
121
121
  }, doRequestBulkShareOrUpdate: (request: BulkShareOrUpdateMetadataParams) => Promise<EntityBulkShareResult<T>[]>): Promise<ShareResult<T>>;
122
122
  private makeMigrationRequestsIfNeeded;
123
123
  private makeMigrationRequestForMemberOfHierarchy;
124
- tryDecryptDataOf(entity: EncryptedEntityWithType, content: ArrayBuffer | Uint8Array, validator: (decryptedData: ArrayBuffer) => Promise<boolean> | undefined): Promise<{
124
+ tryDecryptDataOf(entity: EncryptedEntityWithType, content: ArrayBuffer | Uint8Array, postProcessor?: (decryptedData: ArrayBuffer) => Promise<ArrayBuffer | undefined>): Promise<{
125
125
  data: ArrayBuffer;
126
126
  wasDecrypted: boolean;
127
127
  }>;
@@ -314,7 +314,7 @@ class ExtendedApisUtilsImpl {
314
314
  return undefined;
315
315
  });
316
316
  }
317
- tryDecryptDataOf(entity, content, validator) {
317
+ tryDecryptDataOf(entity, content, postProcessor) {
318
318
  return __awaiter(this, void 0, void 0, function* () {
319
319
  const triedKeys = new Set();
320
320
  const result = yield this.doIncrementallyDecryptingKeys(entity.entity, entity.type, (e, t, keys) => __awaiter(this, void 0, void 0, function* () {
@@ -323,8 +323,14 @@ class ExtendedApisUtilsImpl {
323
323
  triedKeys.add(k.raw);
324
324
  try {
325
325
  const decrypted = yield this.primitives.AES.decrypt(k.key, content);
326
- if (!validator || (yield validator(decrypted)))
326
+ if (postProcessor) {
327
+ const processed = yield postProcessor(decrypted);
328
+ if (processed !== undefined)
329
+ return { success: processed };
330
+ }
331
+ else {
327
332
  return { success: decrypted };
333
+ }
328
334
  }
329
335
  catch (e) {
330
336
  console.warn(`Error while attempting to decrypt attachment of ${entity.entity.id} with raw key ${k.raw}: ${e}`);