@icure/api 7.1.14 → 8.0.0-RC.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.
- package/icc-api/api/IccAccesslogApi.d.ts +12 -1
- package/icc-api/api/IccAccesslogApi.js +142 -98
- package/icc-api/api/IccAccesslogApi.js.map +1 -1
- package/icc-api/api/IccBemikronoApi.d.ts +81 -0
- package/icc-api/api/IccBemikronoApi.js +163 -0
- package/icc-api/api/IccBemikronoApi.js.map +1 -0
- package/icc-api/api/IccCalendarItemApi.d.ts +21 -1
- package/icc-api/api/IccCalendarItemApi.js +183 -117
- package/icc-api/api/IccCalendarItemApi.js.map +1 -1
- package/icc-api/api/IccClassificationApi.d.ts +21 -1
- package/icc-api/api/IccClassificationApi.js +119 -63
- package/icc-api/api/IccClassificationApi.js.map +1 -1
- package/icc-api/api/IccContactApi.d.ts +21 -1
- package/icc-api/api/IccContactApi.js +385 -294
- package/icc-api/api/IccContactApi.js.map +1 -1
- package/icc-api/api/IccDocumentApi.d.ts +32 -25
- package/icc-api/api/IccDocumentApi.js +264 -212
- package/icc-api/api/IccDocumentApi.js.map +1 -1
- package/icc-api/api/IccExchangeDataApi.d.ts +19 -0
- package/icc-api/api/IccExchangeDataApi.js +85 -0
- package/icc-api/api/IccExchangeDataApi.js.map +1 -0
- package/icc-api/api/IccExchangeDataMapApi.d.ts +18 -0
- package/icc-api/api/IccExchangeDataMapApi.js +65 -0
- package/icc-api/api/IccExchangeDataMapApi.js.map +1 -0
- package/icc-api/api/IccFormApi.d.ts +21 -1
- package/icc-api/api/IccFormApi.js +321 -229
- package/icc-api/api/IccFormApi.js.map +1 -1
- package/icc-api/api/IccHelementApi.d.ts +21 -1
- package/icc-api/api/IccHelementApi.js +207 -137
- package/icc-api/api/IccHelementApi.js.map +1 -1
- package/icc-api/api/IccInvoiceApi.d.ts +21 -1
- package/icc-api/api/IccInvoiceApi.js +404 -298
- package/icc-api/api/IccInvoiceApi.js.map +1 -1
- package/icc-api/api/IccMaintenanceTaskApi.d.ts +12 -1
- package/icc-api/api/IccMaintenanceTaskApi.js +79 -43
- package/icc-api/api/IccMaintenanceTaskApi.js.map +1 -1
- package/icc-api/api/IccMessageApi.d.ts +12 -1
- package/icc-api/api/IccMessageApi.js +257 -191
- package/icc-api/api/IccMessageApi.js.map +1 -1
- package/icc-api/api/IccPatientApi.d.ts +12 -1
- package/icc-api/api/IccPatientApi.js +447 -351
- package/icc-api/api/IccPatientApi.js.map +1 -1
- package/icc-api/api/IccReceiptApi.d.ts +22 -8
- package/icc-api/api/IccReceiptApi.js +121 -64
- package/icc-api/api/IccReceiptApi.js.map +1 -1
- package/icc-api/api/IccRestApiPath.js +1 -1
- package/icc-api/api/IccRestApiPath.js.map +1 -1
- package/icc-api/api/IccTimeTableApi.d.ts +12 -1
- package/icc-api/api/IccTimeTableApi.js +86 -48
- package/icc-api/api/IccTimeTableApi.js.map +1 -1
- package/icc-api/index.d.ts +1 -0
- package/icc-api/index.js +1 -0
- package/icc-api/index.js.map +1 -1
- package/icc-api/model/AccessLog.d.ts +4 -0
- package/icc-api/model/AccessLog.js +1 -0
- package/icc-api/model/AccessLog.js.map +1 -1
- package/icc-api/model/Article.d.ts +4 -0
- package/icc-api/model/Article.js +1 -0
- package/icc-api/model/Article.js.map +1 -1
- package/icc-api/model/CalendarItem.d.ts +4 -0
- package/icc-api/model/CalendarItem.js +1 -0
- package/icc-api/model/CalendarItem.js.map +1 -1
- package/icc-api/model/Classification.d.ts +4 -0
- package/icc-api/model/Classification.js +1 -0
- package/icc-api/model/Classification.js.map +1 -1
- package/icc-api/model/ClassificationTemplate.d.ts +2 -0
- package/icc-api/model/ClassificationTemplate.js.map +1 -1
- package/icc-api/model/Contact.d.ts +4 -0
- package/icc-api/model/Contact.js +1 -0
- package/icc-api/model/Contact.js.map +1 -1
- package/icc-api/model/Device.d.ts +4 -4
- package/icc-api/model/Device.js.map +1 -1
- package/icc-api/model/Document.d.ts +4 -0
- package/icc-api/model/Document.js +1 -0
- package/icc-api/model/Document.js.map +1 -1
- package/icc-api/model/ExchangeData.d.ts +61 -0
- package/icc-api/model/ExchangeData.js +12 -0
- package/icc-api/model/ExchangeData.js.map +1 -0
- package/icc-api/model/ExchangeDataMap.d.ts +21 -0
- package/icc-api/model/ExchangeDataMap.js +10 -0
- package/icc-api/model/ExchangeDataMap.js.map +1 -0
- package/icc-api/model/ExchangeDataMapCreationBatch.d.ts +13 -0
- package/icc-api/model/ExchangeDataMapCreationBatch.js +10 -0
- package/icc-api/model/ExchangeDataMapCreationBatch.js.map +1 -0
- package/icc-api/model/Form.d.ts +4 -0
- package/icc-api/model/Form.js +1 -0
- package/icc-api/model/Form.js.map +1 -1
- package/icc-api/model/HealthElement.d.ts +4 -0
- package/icc-api/model/HealthElement.js +1 -0
- package/icc-api/model/HealthElement.js.map +1 -1
- package/icc-api/model/HealthcareParty.d.ts +2 -2
- package/icc-api/model/HealthcareParty.js.map +1 -1
- package/icc-api/model/IcureStub.d.ts +2 -0
- package/icc-api/model/IcureStub.js.map +1 -1
- package/icc-api/model/Invoice.d.ts +4 -0
- package/icc-api/model/Invoice.js +1 -0
- package/icc-api/model/Invoice.js.map +1 -1
- package/icc-api/model/MaintenanceTask.d.ts +4 -0
- package/icc-api/model/MaintenanceTask.js +1 -0
- package/icc-api/model/MaintenanceTask.js.map +1 -1
- package/icc-api/model/Message.d.ts +4 -0
- package/icc-api/model/Message.js +1 -0
- package/icc-api/model/Message.js.map +1 -1
- package/icc-api/model/PaginatedListExchangeData.d.ts +9 -0
- package/icc-api/model/PaginatedListExchangeData.js +10 -0
- package/icc-api/model/PaginatedListExchangeData.js.map +1 -0
- package/icc-api/model/Patient.d.ts +6 -2
- package/icc-api/model/Patient.js +1 -0
- package/icc-api/model/Patient.js.map +1 -1
- package/icc-api/model/PatientByHcPartyGenderEducationProfession.d.ts +31 -0
- package/icc-api/model/PatientByHcPartyGenderEducationProfession.js +32 -0
- package/icc-api/model/PatientByHcPartyGenderEducationProfession.js.map +1 -0
- package/icc-api/model/Receipt.d.ts +4 -0
- package/icc-api/model/Receipt.js +1 -0
- package/icc-api/model/Receipt.js.map +1 -1
- package/icc-api/model/SecureDelegation.d.ts +52 -0
- package/icc-api/model/SecureDelegation.js +16 -0
- package/icc-api/model/SecureDelegation.js.map +1 -0
- package/icc-api/model/SecurityMetadata.d.ts +33 -0
- package/icc-api/model/SecurityMetadata.js +13 -0
- package/icc-api/model/SecurityMetadata.js.map +1 -0
- package/icc-api/model/Service.d.ts +2 -0
- package/icc-api/model/Service.js.map +1 -1
- package/icc-api/model/TimeTable.d.ts +4 -0
- package/icc-api/model/TimeTable.js +1 -0
- package/icc-api/model/TimeTable.js.map +1 -1
- package/icc-api/model/models.d.ts +20 -39
- package/icc-api/model/models.js +15 -37
- package/icc-api/model/models.js.map +1 -1
- package/icc-api/model/requests/EntityBulkShareResult.d.ts +28 -0
- package/icc-api/model/requests/EntityBulkShareResult.js +16 -0
- package/icc-api/model/requests/EntityBulkShareResult.js.map +1 -0
- package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.d.ts +10 -0
- package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js +17 -0
- package/icc-api/model/requests/EntityShareOrMetadataUpdateRequest.js.map +1 -0
- package/icc-api/model/requests/EntityShareRequest.d.ts +110 -0
- package/icc-api/model/requests/EntityShareRequest.js +63 -0
- package/icc-api/model/requests/EntityShareRequest.js.map +1 -0
- package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.d.ts +54 -0
- package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js +24 -0
- package/icc-api/model/requests/EntitySharedMetadataUpdateRequest.js.map +1 -0
- package/icc-api/model/requests/MinimalEntityBulkShareResult.d.ts +23 -0
- package/icc-api/model/requests/MinimalEntityBulkShareResult.js +13 -0
- package/icc-api/model/requests/MinimalEntityBulkShareResult.js.map +1 -0
- package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.d.ts +21 -0
- package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js +14 -0
- package/icc-api/model/requests/RejectedShareOrMetadataUpdateRequest.js.map +1 -0
- package/icc-x-api/basexapi/EncryptedEntityXApi.d.ts +3 -2
- package/icc-x-api/basexapi/EncryptedEntityXApi.js.map +1 -1
- package/icc-x-api/crypto/AES.js +1 -1
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/crypto/AccessControlKeysHeadersProvider.d.ts +16 -0
- package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js +41 -0
- package/icc-x-api/crypto/AccessControlKeysHeadersProvider.js.map +1 -0
- package/icc-x-api/crypto/AccessControlSecretUtils.d.ts +42 -0
- package/icc-x-api/crypto/AccessControlSecretUtils.js +86 -0
- package/icc-x-api/crypto/AccessControlSecretUtils.js.map +1 -0
- package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +146 -0
- package/icc-x-api/crypto/BaseExchangeDataManager.js +342 -0
- package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +0 -18
- package/icc-x-api/crypto/BaseExchangeKeysManager.js +11 -85
- package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
- package/icc-x-api/crypto/ConfidentialEntities.d.ts +26 -16
- package/icc-x-api/crypto/ConfidentialEntities.js +30 -17
- package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -1
- package/icc-x-api/crypto/CryptoStrategies.d.ts +8 -1
- package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
- package/icc-x-api/crypto/ExchangeDataManager.d.ts +95 -0
- package/icc-x-api/crypto/ExchangeDataManager.js +493 -0
- package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -0
- package/icc-x-api/crypto/ExchangeDataMapManager.d.ts +32 -0
- package/icc-x-api/crypto/ExchangeDataMapManager.js +70 -0
- package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -0
- package/icc-x-api/crypto/ExchangeKeysManager.d.ts +4 -16
- package/icc-x-api/crypto/ExchangeKeysManager.js +4 -62
- package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
- package/icc-x-api/crypto/ExtendedApisUtils.d.ts +336 -0
- package/icc-x-api/crypto/ExtendedApisUtils.js +3 -0
- package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -0
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +181 -0
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +562 -0
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -0
- package/icc-x-api/crypto/KeyRecovery.d.ts +5 -2
- package/icc-x-api/crypto/KeyRecovery.js +59 -29
- package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
- package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +7 -2
- package/icc-x-api/crypto/LegacyCryptoStrategies.js +8 -1
- package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -1
- package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.d.ts +39 -0
- package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js +150 -0
- package/icc-x-api/crypto/LegacyDelegationSecurityMetadataDecryptor.js.map +1 -0
- package/icc-x-api/crypto/RSA.d.ts +34 -8
- package/icc-x-api/crypto/RSA.js +80 -13
- package/icc-x-api/crypto/RSA.js.map +1 -1
- package/icc-x-api/crypto/SecureDelegationsEncryption.d.ts +54 -0
- package/icc-x-api/crypto/SecureDelegationsEncryption.js +178 -0
- package/icc-x-api/crypto/SecureDelegationsEncryption.js.map +1 -0
- package/icc-x-api/crypto/SecureDelegationsManager.d.ts +66 -0
- package/icc-x-api/crypto/SecureDelegationsManager.js +261 -0
- package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -0
- package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.d.ts +37 -0
- package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js +294 -0
- package/icc-x-api/crypto/SecureDelegationsSecurityMetadataDecryptor.js.map +1 -0
- package/icc-x-api/crypto/SecurityMetadataDecryptor.d.ts +114 -0
- package/icc-x-api/crypto/SecurityMetadataDecryptor.js +98 -0
- package/icc-x-api/crypto/SecurityMetadataDecryptor.js.map +1 -0
- package/icc-x-api/crypto/ShamirKeysManager.d.ts +5 -5
- package/icc-x-api/crypto/ShamirKeysManager.js +6 -9
- package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
- package/icc-x-api/crypto/TransferKeysManager.d.ts +8 -6
- package/icc-x-api/crypto/TransferKeysManager.js +75 -52
- package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
- package/icc-x-api/crypto/{KeyManager.d.ts → UserEncryptionKeysManager.d.ts} +4 -6
- package/icc-x-api/crypto/{KeyManager.js → UserEncryptionKeysManager.js} +43 -23
- package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -0
- package/icc-x-api/crypto/UserSignatureKeysManager.d.ts +26 -0
- package/icc-x-api/crypto/UserSignatureKeysManager.js +74 -0
- package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -0
- package/icc-x-api/crypto/utils.d.ts +61 -11
- package/icc-x-api/crypto/utils.js +113 -44
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/filters/filters.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +46 -11
- package/icc-x-api/icc-accesslog-x-api.js +75 -42
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +50 -14
- package/icc-x-api/icc-calendar-item-x-api.js +99 -49
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +44 -9
- package/icc-x-api/icc-classification-x-api.js +56 -31
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +56 -32
- package/icc-x-api/icc-contact-x-api.js +95 -64
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +28 -334
- package/icc-x-api/icc-crypto-x-api.js +41 -765
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.d.ts +20 -8
- package/icc-x-api/icc-data-owner-x-api.js +31 -10
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +48 -11
- package/icc-x-api/icc-document-x-api.js +111 -64
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +45 -10
- package/icc-x-api/icc-form-x-api.js +65 -35
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.d.ts +2 -2
- package/icc-x-api/icc-hcparty-x-api.js +3 -3
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +55 -18
- package/icc-x-api/icc-helement-x-api.js +76 -41
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-icure-maintenance-x-api.d.ts +7 -2
- package/icc-x-api/icc-icure-maintenance-x-api.js +38 -27
- package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +50 -15
- package/icc-x-api/icc-invoice-x-api.js +63 -33
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +53 -21
- package/icc-x-api/icc-maintenance-task-x-api.js +72 -35
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +53 -15
- package/icc-x-api/icc-message-x-api.js +65 -36
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +84 -29
- package/icc-x-api/icc-patient-x-api.js +313 -378
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +44 -12
- package/icc-x-api/icc-receipt-x-api.js +67 -35
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +43 -12
- package/icc-x-api/icc-time-table-x-api.js +56 -26
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-user-x-api.d.ts +2 -2
- package/icc-x-api/icc-user-x-api.js +3 -3
- package/icc-x-api/icc-user-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +4 -2
- package/icc-x-api/index.js +154 -135
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +2 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +9 -2
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -1
- package/icc-x-api/storage/IcureStorageFacade.d.ts +23 -2
- package/icc-x-api/storage/IcureStorageFacade.js +36 -2
- package/icc-x-api/storage/IcureStorageFacade.js.map +1 -1
- package/icc-x-api/storage/KeyStorageFacade.d.ts +12 -0
- package/icc-x-api/storage/KeyStorageFacade.js.map +1 -1
- package/icc-x-api/storage/KeyStorageImpl.d.ts +2 -0
- package/icc-x-api/storage/KeyStorageImpl.js +10 -0
- package/icc-x-api/storage/KeyStorageImpl.js.map +1 -1
- package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +14 -1
- package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -1
- package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +32 -0
- package/icc-x-api/utils/EntityWithDelegationTypeName.js +75 -0
- package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -0
- package/icc-x-api/utils/ShareResult.d.ts +74 -0
- package/icc-x-api/utils/ShareResult.js +61 -0
- package/icc-x-api/utils/ShareResult.js.map +1 -0
- package/icc-x-api/utils/binary-utils.d.ts +1 -0
- package/icc-x-api/utils/binary-utils.js +8 -1
- package/icc-x-api/utils/binary-utils.js.map +1 -1
- package/icc-x-api/utils/collection-utils.d.ts +5 -0
- package/icc-x-api/utils/collection-utils.js +26 -1
- package/icc-x-api/utils/collection-utils.js.map +1 -1
- package/icc-x-api/utils/crypto-utils.d.ts +4 -3
- package/icc-x-api/utils/crypto-utils.js +5 -4
- package/icc-x-api/utils/crypto-utils.js.map +1 -1
- package/icc-x-api/utils/lru-temporised-async-cache.d.ts +26 -3
- package/icc-x-api/utils/lru-temporised-async-cache.js +75 -15
- package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -1
- package/icc-x-api/utils/websocket.d.ts +10 -10
- package/icc-x-api/utils/websocket.js +18 -9
- package/icc-x-api/utils/websocket.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/package.json +2 -3
- package/icc-x-api/crypto/EntitiesEncryption.d.ts +0 -275
- package/icc-x-api/crypto/EntitiesEncryption.js +0 -734
- package/icc-x-api/crypto/EntitiesEncryption.js.map +0 -1
- package/icc-x-api/crypto/KeyManager.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ExchangeDataMapManager = void 0;
|
|
13
|
+
const lru_temporised_async_cache_1 = require("../utils/lru-temporised-async-cache");
|
|
14
|
+
const ExchangeDataMapCreationBatch_1 = require("../../icc-api/model/ExchangeDataMapCreationBatch");
|
|
15
|
+
/**
|
|
16
|
+
* @internal this class is intended for internal use only and may be modified without notice
|
|
17
|
+
* This class manages the Exchange Data Map entities, caching with an LRU cache on retrieval.
|
|
18
|
+
*/
|
|
19
|
+
class ExchangeDataMapManager {
|
|
20
|
+
constructor(api) {
|
|
21
|
+
this.api = api;
|
|
22
|
+
this.exchangeDataMapCache = new lru_temporised_async_cache_1.LruTemporisedAsyncCache(1000, () => -1);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* This function creates a batch of Exchange Data Map, ignoring the one that already exist and are already present in the cache.
|
|
26
|
+
* The ones that are not are created and their ids are cached.
|
|
27
|
+
* @param batch a map where each key is the hex-encoded access control key to another map that associates the encoded id of an
|
|
28
|
+
* Exchange Data entity to the fingerprint of the key used to encrypt it.
|
|
29
|
+
*/
|
|
30
|
+
createExchangeDataMaps(batch) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const entriesToCreate = {};
|
|
33
|
+
for (const [k, v] of Object.entries(batch)) {
|
|
34
|
+
if (!(yield this.exchangeDataMapCache.getIfCachedJob(k))) {
|
|
35
|
+
entriesToCreate[k] = v;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
yield this.api.createExchangeDataMapBatch(new ExchangeDataMapCreationBatch_1.ExchangeDataMapCreationBatch({ batch: entriesToCreate }));
|
|
39
|
+
yield Promise.all(Object.keys(entriesToCreate).map((entry) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
yield this.exchangeDataMapCache.get(entry, () => Promise.resolve({ item: null }));
|
|
41
|
+
})));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves an Exchange Data Map.
|
|
46
|
+
* @param accessControlKeyHash the hex-encoded hash of the Exchange Data Map to retrieve.
|
|
47
|
+
*/
|
|
48
|
+
getExchangeDataMap(accessControlKeyHash) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const exchangeDataMap = yield this.api.getExchangeDataMapById(accessControlKeyHash);
|
|
51
|
+
yield this.exchangeDataMapCache.get(exchangeDataMap.id, () => Promise.resolve({ item: null }));
|
|
52
|
+
return exchangeDataMap;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves a batch of Exchange Data Maps.
|
|
57
|
+
* @param accessControlKeyHashes the hex-encoded hashes of the Exchange Data Maps to retrieve.
|
|
58
|
+
*/
|
|
59
|
+
getExchangeDataMapBatch(accessControlKeyHashes) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const exchangeDataMaps = yield this.api.getExchangeDataMapByBatch(accessControlKeyHashes);
|
|
62
|
+
yield Promise.all(exchangeDataMaps.map((entry) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
yield this.exchangeDataMapCache.get(entry.id, () => Promise.resolve({ item: null }));
|
|
64
|
+
})));
|
|
65
|
+
return exchangeDataMaps;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ExchangeDataMapManager = ExchangeDataMapManager;
|
|
70
|
+
//# sourceMappingURL=ExchangeDataMapManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExchangeDataMapManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeDataMapManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oFAA6E;AAE7E,mGAA+F;AAE/F;;;GAGG;AACH,MAAa,sBAAsB;IACjC,YAA6B,GAA0B;QAA1B,QAAG,GAAH,GAAG,CAAuB;QAE/C,yBAAoB,GAA0C,IAAI,oDAAuB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAFvD,CAAC;IAI3D;;;;;OAKG;IACG,sBAAsB,CAAC,KAA+D;;YAC1F,MAAM,eAAe,GAA6D,EAAE,CAAA;YACpF,KAAK,MAAM,CAAC,CAAC,EAAE,CAA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AC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YACtF,CAAC,CAAA,CAAC,CACH,CAAA;YACD,OAAO,gBAAgB,CAAA;QACzB,CAAC;KAAA;CACF;AAjDD,wDAiDC","sourcesContent":["import { IccExchangeDataMapApi } from '../../icc-api/api/IccExchangeDataMapApi'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { ExchangeDataMap } from '../../icc-api/model/ExchangeDataMap'\nimport { ExchangeDataMapCreationBatch } from '../../icc-api/model/ExchangeDataMapCreationBatch'\n\n/**\n * @internal this class is intended for internal use only and may be modified without notice\n * This class manages the Exchange Data Map entities, caching with an LRU cache on retrieval.\n */\nexport class ExchangeDataMapManager {\n constructor(private readonly api: IccExchangeDataMapApi) {}\n\n private exchangeDataMapCache: LruTemporisedAsyncCache<string, null> = new LruTemporisedAsyncCache(1000, () => -1)\n\n /**\n * This function creates a batch of Exchange Data Map, ignoring the one that already exist and are already present in the cache.\n * The ones that are not are created and their ids are cached.\n * @param batch a map where each key is the hex-encoded access control key to another map that associates the encoded id of an\n * Exchange Data entity to the fingerprint of the key used to encrypt it.\n */\n async createExchangeDataMaps(batch: { [accessControlKey: string]: { [fp: string]: string } }): Promise<void> {\n const entriesToCreate: { [accessControlKey: string]: { [fp: string]: string } } = {}\n for (const [k, v] of Object.entries(batch)) {\n if (!(await this.exchangeDataMapCache.getIfCachedJob(k))) {\n entriesToCreate[k] = v\n }\n }\n await this.api.createExchangeDataMapBatch(new ExchangeDataMapCreationBatch({ batch: entriesToCreate }))\n await Promise.all(\n Object.keys(entriesToCreate).map(async (entry) => {\n await this.exchangeDataMapCache.get(entry, () => Promise.resolve({ item: null }))\n })\n )\n }\n\n /**\n * Retrieves an Exchange Data Map.\n * @param accessControlKeyHash the hex-encoded hash of the Exchange Data Map to retrieve.\n */\n async getExchangeDataMap(accessControlKeyHash: string): Promise<ExchangeDataMap> {\n const exchangeDataMap = await this.api.getExchangeDataMapById(accessControlKeyHash)\n await this.exchangeDataMapCache.get(exchangeDataMap.id, () => Promise.resolve({ item: null }))\n return exchangeDataMap\n }\n\n /**\n * Retrieves a batch of Exchange Data Maps.\n * @param accessControlKeyHashes the hex-encoded hashes of the Exchange Data Maps to retrieve.\n */\n async getExchangeDataMapBatch(accessControlKeyHashes: string[]): Promise<ExchangeDataMap[]> {\n const exchangeDataMaps = await this.api.getExchangeDataMapByBatch(accessControlKeyHashes)\n await Promise.all(\n exchangeDataMaps.map(async (entry) => {\n await this.exchangeDataMapCache.get(entry.id, () => Promise.resolve({ item: null }))\n })\n )\n return exchangeDataMaps\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserEncryptionKeysManager } from './UserEncryptionKeysManager';
|
|
2
2
|
import { BaseExchangeKeysManager } from './BaseExchangeKeysManager';
|
|
3
3
|
import { IccDataOwnerXApi } from '../icc-data-owner-x-api';
|
|
4
4
|
import { CryptoPrimitives } from './CryptoPrimitives';
|
|
5
5
|
import { CryptoStrategies } from './CryptoStrategies';
|
|
6
|
-
import {
|
|
6
|
+
import { IcureStorageFacade } from '../storage/IcureStorageFacade';
|
|
7
7
|
/**
|
|
8
8
|
* @internal This class is meant only for internal use and may be changed without notice.
|
|
9
9
|
* More powerful version of {@link BaseExchangeKeysManager} with a simplified interface. Has the following functionalities:
|
|
@@ -19,22 +19,11 @@ export declare class ExchangeKeysManager {
|
|
|
19
19
|
private readonly baseExchangeKeysManager;
|
|
20
20
|
private readonly dataOwnerApi;
|
|
21
21
|
private readonly useParentKeys;
|
|
22
|
+
private readonly icureStorage;
|
|
22
23
|
private delegatorExchangeKeysCache;
|
|
23
24
|
private delegatedExchangeKeysCache;
|
|
24
25
|
get base(): BaseExchangeKeysManager;
|
|
25
|
-
constructor(delegatorKeysCacheSize: number, delegatedKeysCacheSize: number, delegatedKeysCacheLifetimeMsBase: number, delegatedKeysCacheLifetimeMsNoKeys: number, cryptoStrategies: CryptoStrategies, primitives: CryptoPrimitives, keyManager:
|
|
26
|
-
/**
|
|
27
|
-
* Get exchange keys from the current data owner to the provided delegate which are safe for encryption according to the locally verified keys.
|
|
28
|
-
* If currently there is no exchange key towards the provided delegate which is safe for encryption a new one will be automatically created.
|
|
29
|
-
* @param delegateId a delegate
|
|
30
|
-
* @return an object with the following fields:
|
|
31
|
-
* - keys: all available exchange keys which are safe for encryption.
|
|
32
|
-
* - updatedDelegator (optional): if a new key creation job was started when the function was invoked the updated delegator, else undefined.
|
|
33
|
-
*/
|
|
34
|
-
getOrCreateEncryptionExchangeKeysTo(delegateId: string): Promise<{
|
|
35
|
-
updatedDelegator?: CryptoActorStubWithType;
|
|
36
|
-
keys: CryptoKey[];
|
|
37
|
-
}>;
|
|
26
|
+
constructor(delegatorKeysCacheSize: number, delegatedKeysCacheSize: number, delegatedKeysCacheLifetimeMsBase: number, delegatedKeysCacheLifetimeMsNoKeys: number, cryptoStrategies: CryptoStrategies, primitives: CryptoPrimitives, keyManager: UserEncryptionKeysManager, baseExchangeKeysManager: BaseExchangeKeysManager, dataOwnerApi: IccDataOwnerXApi, useParentKeys: boolean, icureStorage: IcureStorageFacade);
|
|
38
27
|
/**
|
|
39
28
|
* Get all keys currently available for a delegator-delegate pair. At least one of the two data owners must be part of the hierarchy for the current
|
|
40
29
|
* data owner.
|
|
@@ -52,5 +41,4 @@ export declare class ExchangeKeysManager {
|
|
|
52
41
|
private forceGetExchangeKeysFor;
|
|
53
42
|
private getSelfExchangeKeysTo;
|
|
54
43
|
private forceGetSelfExchangeKeysTo;
|
|
55
|
-
private forceCreateVerifiedExchangeKeyTo;
|
|
56
44
|
}
|
|
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ExchangeKeysManager = void 0;
|
|
13
13
|
const lru_temporised_async_cache_1 = require("../utils/lru-temporised-async-cache");
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
14
|
/**
|
|
16
15
|
* @internal This class is meant only for internal use and may be changed without notice.
|
|
17
16
|
* More powerful version of {@link BaseExchangeKeysManager} with a simplified interface. Has the following functionalities:
|
|
@@ -24,53 +23,17 @@ class ExchangeKeysManager {
|
|
|
24
23
|
get base() {
|
|
25
24
|
return this.baseExchangeKeysManager;
|
|
26
25
|
}
|
|
27
|
-
constructor(delegatorKeysCacheSize, delegatedKeysCacheSize, delegatedKeysCacheLifetimeMsBase, delegatedKeysCacheLifetimeMsNoKeys, cryptoStrategies, primitives, keyManager, baseExchangeKeysManager, dataOwnerApi, useParentKeys) {
|
|
26
|
+
constructor(delegatorKeysCacheSize, delegatedKeysCacheSize, delegatedKeysCacheLifetimeMsBase, delegatedKeysCacheLifetimeMsNoKeys, cryptoStrategies, primitives, keyManager, baseExchangeKeysManager, dataOwnerApi, useParentKeys, icureStorage) {
|
|
28
27
|
this.cryptoStrategies = cryptoStrategies;
|
|
29
28
|
this.primitives = primitives;
|
|
30
29
|
this.keyManager = keyManager;
|
|
31
30
|
this.baseExchangeKeysManager = baseExchangeKeysManager;
|
|
32
31
|
this.dataOwnerApi = dataOwnerApi;
|
|
33
32
|
this.useParentKeys = useParentKeys;
|
|
33
|
+
this.icureStorage = icureStorage;
|
|
34
34
|
this.delegatedExchangeKeysCache = new lru_temporised_async_cache_1.LruTemporisedAsyncCache(delegatedKeysCacheSize, (keys) => keys.length > 0 ? delegatedKeysCacheLifetimeMsBase : delegatedKeysCacheLifetimeMsNoKeys);
|
|
35
35
|
this.delegatorExchangeKeysCache = new lru_temporised_async_cache_1.LruTemporisedAsyncCache(delegatorKeysCacheSize, () => -1);
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Get exchange keys from the current data owner to the provided delegate which are safe for encryption according to the locally verified keys.
|
|
39
|
-
* If currently there is no exchange key towards the provided delegate which is safe for encryption a new one will be automatically created.
|
|
40
|
-
* @param delegateId a delegate
|
|
41
|
-
* @return an object with the following fields:
|
|
42
|
-
* - keys: all available exchange keys which are safe for encryption.
|
|
43
|
-
* - updatedDelegator (optional): if a new key creation job was started when the function was invoked the updated delegator, else undefined.
|
|
44
|
-
*/
|
|
45
|
-
getOrCreateEncryptionExchangeKeysTo(delegateId) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const currentKeys = yield this.getSelfExchangeKeysTo(delegateId);
|
|
48
|
-
if (currentKeys.length > 0) {
|
|
49
|
-
return { keys: currentKeys };
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
while (true) {
|
|
53
|
-
let updatedDelegatorJob = undefined;
|
|
54
|
-
const keysWithNew = yield this.delegatorExchangeKeysCache.get(delegateId, (previous) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const fullJob = this.forceCreateVerifiedExchangeKeyTo(delegateId);
|
|
56
|
-
updatedDelegatorJob = fullJob.then(({ updatedDelegator }) => updatedDelegator);
|
|
57
|
-
let existingKeys = previous ? previous : yield this.forceGetSelfExchangeKeysTo(delegateId);
|
|
58
|
-
return fullJob.then(({ key }) => [...existingKeys, key]);
|
|
59
|
-
}), (v) => !v.length);
|
|
60
|
-
if (keysWithNew.length > 0) {
|
|
61
|
-
const updatedDelegator = updatedDelegatorJob ? yield updatedDelegatorJob : undefined;
|
|
62
|
-
return updatedDelegator ? { keys: keysWithNew, updatedDelegator } : { keys: keysWithNew };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/*NOTE:
|
|
66
|
-
* in case of two concurrent calls to `getOrCreateEncryptionExchangeKeysTo` only one of the calls will receive the updated delegator. This could
|
|
67
|
-
* be a problem if one of the callers would want to update the delegator for other reasons as well, as the request would result in a database
|
|
68
|
-
* conflict. This situation however should be very rare and will be fully resolved in the near future when delegations will be moved out of the
|
|
69
|
-
* data owner objects and into a specific database.
|
|
70
|
-
*/
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
37
|
/**
|
|
75
38
|
* Get all keys currently available for a delegator-delegate pair. At least one of the two data owners must be part of the hierarchy for the current
|
|
76
39
|
* data owner.
|
|
@@ -89,7 +52,7 @@ class ExchangeKeysManager {
|
|
|
89
52
|
const hierarchyIds = yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds();
|
|
90
53
|
if (!hierarchyIds.some((x) => x === delegateId || x === delegatorId))
|
|
91
54
|
throw new Error(`Trying to retrieve exchange key ${key} but current data owner hierarchy is ${hierarchyIds}`);
|
|
92
|
-
return yield this.delegatedExchangeKeysCache.get(key, () => this.forceGetExchangeKeysFor(delegatorId, delegateId));
|
|
55
|
+
return yield this.delegatedExchangeKeysCache.get(key, () => this.forceGetExchangeKeysFor(delegatorId, delegateId).then((x) => ({ item: x })));
|
|
93
56
|
}
|
|
94
57
|
});
|
|
95
58
|
}
|
|
@@ -110,7 +73,7 @@ class ExchangeKeysManager {
|
|
|
110
73
|
}
|
|
111
74
|
getSelfExchangeKeysTo(delegateId) {
|
|
112
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
return yield this.delegatorExchangeKeysCache.get(delegateId, () => this.forceGetSelfExchangeKeysTo(delegateId));
|
|
76
|
+
return yield this.delegatorExchangeKeysCache.get(delegateId, () => this.forceGetSelfExchangeKeysTo(delegateId).then((x) => ({ item: x })));
|
|
114
77
|
});
|
|
115
78
|
}
|
|
116
79
|
forceGetSelfExchangeKeysTo(delegateId) {
|
|
@@ -121,27 +84,6 @@ class ExchangeKeysManager {
|
|
|
121
84
|
return successfulDecryptions;
|
|
122
85
|
});
|
|
123
86
|
}
|
|
124
|
-
forceCreateVerifiedExchangeKeyTo(delegateId) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
const [mainKey, ...otherSelfKeys] = this.keyManager.getSelfVerifiedKeys();
|
|
127
|
-
let otherPublicKeys = Object.fromEntries(otherSelfKeys.map((x) => [x.fingerprint, x.pair.publicKey]));
|
|
128
|
-
if (delegateId !== (yield this.dataOwnerApi.getCurrentDataOwnerId())) {
|
|
129
|
-
const delegate = yield this.dataOwnerApi.getCryptoActorStub(delegateId);
|
|
130
|
-
const delegatePublicKeys = Array.from(this.dataOwnerApi.getHexPublicKeysOf(delegate.stub));
|
|
131
|
-
let verifiedDelegatePublicKeys;
|
|
132
|
-
if (this.useParentKeys && (yield this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()).includes(delegateId)) {
|
|
133
|
-
verifiedDelegatePublicKeys = yield this.keyManager.getVerifiedPublicKeysFor(delegate.stub);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
verifiedDelegatePublicKeys = yield this.cryptoStrategies.verifyDelegatePublicKeys(delegate, delegatePublicKeys, this.primitives);
|
|
137
|
-
}
|
|
138
|
-
if (!verifiedDelegatePublicKeys || verifiedDelegatePublicKeys.length == 0)
|
|
139
|
-
throw new Error(`No verified public keys for delegate ${delegateId}: impossible to create new exchange key.`);
|
|
140
|
-
otherPublicKeys = Object.assign(Object.assign({}, otherPublicKeys), (yield (0, utils_1.loadPublicKeys)(this.primitives.RSA, verifiedDelegatePublicKeys)));
|
|
141
|
-
}
|
|
142
|
-
return yield this.baseExchangeKeysManager.createOrUpdateEncryptedExchangeKeyTo(delegateId, mainKey.pair, otherPublicKeys);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
87
|
}
|
|
146
88
|
exports.ExchangeKeysManager = ExchangeKeysManager;
|
|
147
89
|
//# sourceMappingURL=ExchangeKeysManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExchangeKeysManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,oFAA6E;AAC7E,mCAAwC;AAKxC;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAc9B,IAAI,IAAI;QACN,OAAO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eAAe,mCACV,eAAe,GACf,CAAC,MAAM,IAAA,sBAAc,EAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,0BAA0B,CAAC,CAAC,CAC3E,CAAA;aACF;YACD,OAAO,MAAM,IAAI,CAAC,uBAAuB,CAAC,oCAAoC,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,CAAA;QAC3H,CAAC;KAAA;CACF;AA7ID,kDA6IC","sourcesContent":["import { KeyManager } from './KeyManager'\nimport { BaseExchangeKeysManager } from './BaseExchangeKeysManager'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { loadPublicKeys } from './utils'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\n\n/**\n * @internal This class is meant only for internal use and may be changed without notice.\n * More powerful version of {@link BaseExchangeKeysManager} with a simplified interface. Has the following functionalities:\n * - Caches results\n * - Automatically creates new exchange keys if none is available\n * - Automatically choose the public keys to use during the creation of new exchange keys\n * - Automatically retrieves the private keys to use during decryption.\n */\nexport class ExchangeKeysManager {\n /*\n * Exchange keys cache where the current user is the delegator. The keys where the delegator is the current user should never change without\n * an action from the delegator (unless he does this action from another device), so it should be safe to store them without expiration. However,\n * the delegator may still have a lot of exchange keys (e.g. doctor -> all patients), so it is not safe to have a cache with unlimited size.\n */\n private delegatorExchangeKeysCache: LruTemporisedAsyncCache<string, CryptoKey[]>\n /*\n * Exchange keys cache where the current user is not the delegator. There may be many keys where the current user is the delegate,\n * and they may change over time without any action from the current data owner, since the delegator is someone else. For this reason the cache must\n * be limited in size and it should not use data that is too old, as it may be outdated.\n */\n private delegatedExchangeKeysCache: LruTemporisedAsyncCache<string, CryptoKey[]>\n\n get base(): BaseExchangeKeysManager {\n return this.baseExchangeKeysManager\n }\n\n constructor(\n delegatorKeysCacheSize: number,\n delegatedKeysCacheSize: number,\n delegatedKeysCacheLifetimeMsBase: number,\n delegatedKeysCacheLifetimeMsNoKeys: number,\n private readonly cryptoStrategies: CryptoStrategies,\n private readonly primitives: CryptoPrimitives,\n private readonly keyManager: KeyManager,\n private readonly baseExchangeKeysManager: BaseExchangeKeysManager,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly useParentKeys: boolean\n ) {\n this.delegatedExchangeKeysCache = new LruTemporisedAsyncCache(delegatedKeysCacheSize, (keys) =>\n keys.length > 0 ? delegatedKeysCacheLifetimeMsBase : delegatedKeysCacheLifetimeMsNoKeys\n )\n this.delegatorExchangeKeysCache = new LruTemporisedAsyncCache(delegatorKeysCacheSize, () => -1)\n }\n\n /**\n * Get exchange keys from the current data owner to the provided delegate which are safe for encryption according to the locally verified keys.\n * If currently there is no exchange key towards the provided delegate which is safe for encryption a new one will be automatically created.\n * @param delegateId a delegate\n * @return an object with the following fields:\n * - keys: all available exchange keys which are safe for encryption.\n * - updatedDelegator (optional): if a new key creation job was started when the function was invoked the updated delegator, else undefined.\n */\n async getOrCreateEncryptionExchangeKeysTo(delegateId: string): Promise<{ updatedDelegator?: CryptoActorStubWithType; keys: CryptoKey[] }> {\n const currentKeys = await this.getSelfExchangeKeysTo(delegateId)\n if (currentKeys.length > 0) {\n return { keys: currentKeys }\n } else {\n while (true) {\n let updatedDelegatorJob: Promise<CryptoActorStubWithType> | undefined = undefined\n const keysWithNew = await this.delegatorExchangeKeysCache.get(\n delegateId,\n async (previous) => {\n const fullJob = this.forceCreateVerifiedExchangeKeyTo(delegateId)\n updatedDelegatorJob = fullJob.then(({ updatedDelegator }) => updatedDelegator)\n let existingKeys = previous ? previous : await this.forceGetSelfExchangeKeysTo(delegateId)\n return fullJob.then(({ key }) => [...existingKeys, key])\n },\n (v) => !v.length\n )\n if (keysWithNew.length > 0) {\n const updatedDelegator = updatedDelegatorJob ? await updatedDelegatorJob : undefined\n return updatedDelegator ? { keys: keysWithNew, updatedDelegator } : { keys: keysWithNew }\n }\n }\n /*NOTE:\n * in case of two concurrent calls to `getOrCreateEncryptionExchangeKeysTo` only one of the calls will receive the updated delegator. This could\n * be a problem if one of the callers would want to update the delegator for other reasons as well, as the request would result in a database\n * conflict. This situation however should be very rare and will be fully resolved in the near future when delegations will be moved out of the\n * data owner objects and into a specific database.\n */\n }\n }\n\n /**\n * Get all keys currently available for a delegator-delegate pair. At least one of the two data owners must be part of the hierarchy for the current\n * data owner.\n * @param delegatorId id of a delegator\n * @param delegateId id of a delegate\n * @throws if neither the delegator nor the delegate is part of the hierarchy of the current data owner.\n * @return all available exchange keys from the delegator-delegate pair.\n */\n async getDecryptionExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n if (delegatorId === (await this.dataOwnerApi.getCurrentDataOwnerId())) {\n return await this.getSelfExchangeKeysTo(delegateId)\n } else {\n const key = `${delegatorId}->${delegateId}`\n const hierarchyIds = await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()\n if (!hierarchyIds.some((x) => x === delegateId || x === delegatorId))\n throw new Error(`Trying to retrieve exchange key ${key} but current data owner hierarchy is ${hierarchyIds}`)\n return await this.delegatedExchangeKeysCache.get(key, () => this.forceGetExchangeKeysFor(delegatorId, delegateId))\n }\n }\n\n /**\n * Empties the exchange keys cache.\n * @param includeKeysFromCurrentDataOwner if true also clears the\n */\n clearCache(includeKeysFromCurrentDataOwner: boolean) {\n if (includeKeysFromCurrentDataOwner) this.delegatorExchangeKeysCache.clear()\n this.delegatedExchangeKeysCache.clear()\n }\n\n private async forceGetExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n const encKeys = await this.baseExchangeKeysManager.getEncryptedExchangeKeysFor(delegatorId, delegateId)\n return (await this.baseExchangeKeysManager.tryDecryptExchangeKeys(encKeys, this.keyManager.getDecryptionKeys())).successfulDecryptions\n }\n\n private async getSelfExchangeKeysTo(delegateId: string): Promise<CryptoKey[]> {\n return await this.delegatorExchangeKeysCache.get(delegateId, () => this.forceGetSelfExchangeKeysTo(delegateId))\n }\n\n private async forceGetSelfExchangeKeysTo(delegateId: string): Promise<CryptoKey[]> {\n // Retrieve then try to decrypt with own and parent key pairs\n const encKeys = await this.baseExchangeKeysManager.getEncryptedExchangeKeysFor(await this.dataOwnerApi.getCurrentDataOwnerId(), delegateId)\n const { successfulDecryptions } = await this.baseExchangeKeysManager.tryDecryptExchangeKeys(encKeys, this.keyManager.getDecryptionKeys())\n return successfulDecryptions\n }\n\n private async forceCreateVerifiedExchangeKeyTo(delegateId: string): Promise<{ updatedDelegator: CryptoActorStubWithType; key: CryptoKey }> {\n const [mainKey, ...otherSelfKeys] = this.keyManager.getSelfVerifiedKeys()\n let otherPublicKeys = Object.fromEntries(otherSelfKeys.map((x) => [x.fingerprint, x.pair.publicKey]))\n if (delegateId !== (await this.dataOwnerApi.getCurrentDataOwnerId())) {\n const delegate = await this.dataOwnerApi.getCryptoActorStub(delegateId)\n const delegatePublicKeys = Array.from(this.dataOwnerApi.getHexPublicKeysOf(delegate.stub))\n let verifiedDelegatePublicKeys: string[]\n if (this.useParentKeys && (await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()).includes(delegateId)) {\n verifiedDelegatePublicKeys = await this.keyManager.getVerifiedPublicKeysFor(delegate.stub)\n } else {\n verifiedDelegatePublicKeys = await this.cryptoStrategies.verifyDelegatePublicKeys(delegate, delegatePublicKeys, this.primitives)\n }\n if (!verifiedDelegatePublicKeys || verifiedDelegatePublicKeys.length == 0)\n throw new Error(`No verified public keys for delegate ${delegateId}: impossible to create new exchange key.`)\n otherPublicKeys = {\n ...otherPublicKeys,\n ...(await loadPublicKeys(this.primitives.RSA, verifiedDelegatePublicKeys)),\n }\n }\n return await this.baseExchangeKeysManager.createOrUpdateEncryptedExchangeKeyTo(delegateId, mainKey.pair, otherPublicKeys)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExchangeKeysManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/Exchang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CAAC;KAAA;IAEa,0BAA0B,CAAC,UAAkB;;YACzD,6DAA6D;YAC7D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,2BAA2B,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,EAAE,UAAU,CAAC,CAAA;YAC3I,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC,CAAA;YACzI,OAAO,qBAAqB,CAAA;QAC9B,CAAC;KAAA;CACF;AAjFD,kDAiFC","sourcesContent":["import { UserEncryptionKeysManager } from './UserEncryptionKeysManager'\nimport { BaseExchangeKeysManager } from './BaseExchangeKeysManager'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { LruTemporisedAsyncCache } from '../utils/lru-temporised-async-cache'\nimport { getShaVersionForKey, loadPublicKeys } from './utils'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { IcureStorageFacade } from '../storage/IcureStorageFacade'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\n\n/**\n * @internal This class is meant only for internal use and may be changed without notice.\n * More powerful version of {@link BaseExchangeKeysManager} with a simplified interface. Has the following functionalities:\n * - Caches results\n * - Automatically creates new exchange keys if none is available\n * - Automatically choose the public keys to use during the creation of new exchange keys\n * - Automatically retrieves the private keys to use during decryption.\n */\nexport class ExchangeKeysManager {\n /*\n * Exchange keys cache where the current user is the delegator. The keys where the delegator is the current user should never change without\n * an action from the delegator (unless he does this action from another device), so it should be safe to store them without expiration. However,\n * the delegator may still have a lot of exchange keys (e.g. doctor -> all patients), so it is not safe to have a cache with unlimited size.\n */\n private delegatorExchangeKeysCache: LruTemporisedAsyncCache<string, CryptoKey[]>\n /*\n * Exchange keys cache where the current user is not the delegator. There may be many keys where the current user is the delegate,\n * and they may change over time without any action from the current data owner, since the delegator is someone else. For this reason the cache must\n * be limited in size and it should not use data that is too old, as it may be outdated.\n */\n private delegatedExchangeKeysCache: LruTemporisedAsyncCache<string, CryptoKey[]>\n\n get base(): BaseExchangeKeysManager {\n return this.baseExchangeKeysManager\n }\n\n constructor(\n delegatorKeysCacheSize: number,\n delegatedKeysCacheSize: number,\n delegatedKeysCacheLifetimeMsBase: number,\n delegatedKeysCacheLifetimeMsNoKeys: number,\n private readonly cryptoStrategies: CryptoStrategies,\n private readonly primitives: CryptoPrimitives,\n private readonly keyManager: UserEncryptionKeysManager,\n private readonly baseExchangeKeysManager: BaseExchangeKeysManager,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly useParentKeys: boolean,\n private readonly icureStorage: IcureStorageFacade\n ) {\n this.delegatedExchangeKeysCache = new LruTemporisedAsyncCache(delegatedKeysCacheSize, (keys) =>\n keys.length > 0 ? delegatedKeysCacheLifetimeMsBase : delegatedKeysCacheLifetimeMsNoKeys\n )\n this.delegatorExchangeKeysCache = new LruTemporisedAsyncCache(delegatorKeysCacheSize, () => -1)\n }\n\n /**\n * Get all keys currently available for a delegator-delegate pair. At least one of the two data owners must be part of the hierarchy for the current\n * data owner.\n * @param delegatorId id of a delegator\n * @param delegateId id of a delegate\n * @throws if neither the delegator nor the delegate is part of the hierarchy of the current data owner.\n * @return all available exchange keys from the delegator-delegate pair.\n */\n async getDecryptionExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n if (delegatorId === (await this.dataOwnerApi.getCurrentDataOwnerId())) {\n return await this.getSelfExchangeKeysTo(delegateId)\n } else {\n const key = `${delegatorId}->${delegateId}`\n const hierarchyIds = await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()\n if (!hierarchyIds.some((x) => x === delegateId || x === delegatorId))\n throw new Error(`Trying to retrieve exchange key ${key} but current data owner hierarchy is ${hierarchyIds}`)\n return await this.delegatedExchangeKeysCache.get(key, () => this.forceGetExchangeKeysFor(delegatorId, delegateId).then((x) => ({ item: x })))\n }\n }\n\n /**\n * Empties the exchange keys cache.\n * @param includeKeysFromCurrentDataOwner if true also clears the\n */\n clearCache(includeKeysFromCurrentDataOwner: boolean) {\n if (includeKeysFromCurrentDataOwner) this.delegatorExchangeKeysCache.clear()\n this.delegatedExchangeKeysCache.clear()\n }\n\n private async forceGetExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n const encKeys = await this.baseExchangeKeysManager.getEncryptedExchangeKeysFor(delegatorId, delegateId)\n return (await this.baseExchangeKeysManager.tryDecryptExchangeKeys(encKeys, this.keyManager.getDecryptionKeys())).successfulDecryptions\n }\n\n private async getSelfExchangeKeysTo(delegateId: string): Promise<CryptoKey[]> {\n return await this.delegatorExchangeKeysCache.get(delegateId, () => this.forceGetSelfExchangeKeysTo(delegateId).then((x) => ({ item: x })))\n }\n\n private async forceGetSelfExchangeKeysTo(delegateId: string): Promise<CryptoKey[]> {\n // Retrieve then try to decrypt with own and parent key pairs\n const encKeys = await this.baseExchangeKeysManager.getEncryptedExchangeKeysFor(await this.dataOwnerApi.getCurrentDataOwnerId(), delegateId)\n const { successfulDecryptions } = await this.baseExchangeKeysManager.tryDecryptExchangeKeys(encKeys, this.keyManager.getDecryptionKeys())\n return successfulDecryptions\n }\n}\n"]}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { EncryptedEntity, EncryptedEntityStub } from '../../icc-api/model/models';
|
|
2
|
+
import { EncryptedEntityWithType, EntityWithDelegationTypeName } from '../utils/EntityWithDelegationTypeName';
|
|
3
|
+
import { SecureDelegation } from '../../icc-api/model/SecureDelegation';
|
|
4
|
+
import AccessLevelEnum = SecureDelegation.AccessLevelEnum;
|
|
5
|
+
import { EntityShareOrMetadataUpdateRequest } from '../../icc-api/model/requests/EntityShareOrMetadataUpdateRequest';
|
|
6
|
+
import { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest';
|
|
7
|
+
import { EntityBulkShareResult } from '../../icc-api/model/requests/EntityBulkShareResult';
|
|
8
|
+
import RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum;
|
|
9
|
+
import { ShareMetadataBehaviour } from './ShareMetadataBehaviour';
|
|
10
|
+
import { ShareResult } from '../utils/ShareResult';
|
|
11
|
+
import { MinimalEntityBulkShareResult } from '../../icc-api/model/requests/MinimalEntityBulkShareResult';
|
|
12
|
+
import { EncryptedFieldsManifest } from '../utils';
|
|
13
|
+
/**
|
|
14
|
+
* @internal this interface is meant only for internal use and may be changed without notice.
|
|
15
|
+
* Gives access to several functions to access encrypted entities metadata.
|
|
16
|
+
*/
|
|
17
|
+
export interface ExtendedApisUtils {
|
|
18
|
+
/**
|
|
19
|
+
* Get the encryption keys of an entity that the provided data owner can access, potentially using the keys for his parent.
|
|
20
|
+
* 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.
|
|
21
|
+
* @param entity an encrypted entity.
|
|
22
|
+
* @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.
|
|
23
|
+
* @return the encryption keys that the provided data owner can decrypt, deduplicated.
|
|
24
|
+
*/
|
|
25
|
+
encryptionKeysOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>;
|
|
26
|
+
/**
|
|
27
|
+
* 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
|
|
28
|
+
* owner in the hierarchy which can be decrypted using only that data owner keys (excludes keys accessible through the parent keys). The order of
|
|
29
|
+
* the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.
|
|
30
|
+
* Note that different data owners may have access to the same keys, but the keys extracted for each data owner are deduplicated.
|
|
31
|
+
* 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.
|
|
32
|
+
* @param entity an encrypted entity.
|
|
33
|
+
* @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.
|
|
34
|
+
*/
|
|
35
|
+
encryptionKeysForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{
|
|
36
|
+
ownerId: string;
|
|
37
|
+
extracted: string[];
|
|
38
|
+
}[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the secret ids (SFKs) of an entity that the provided data owner can access, potentially using the keys for his parent.
|
|
41
|
+
* @param entity an encrypted entity.
|
|
42
|
+
* @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.
|
|
43
|
+
* @return the secret ids (SFKs) that the provided data owner can decrypt, deduplicated.
|
|
44
|
+
*/
|
|
45
|
+
secretIdsOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>;
|
|
46
|
+
/**
|
|
47
|
+
* 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
|
|
48
|
+
* owner in the hierarchy which can be decrypted using only that data owner keys (excludes ids accessible through the parent keys). The order of
|
|
49
|
+
* the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.
|
|
50
|
+
* Note that different data owners may have access to the same secret ids, but the secret ids extracted for each data owner are deduplicated.
|
|
51
|
+
* @param entity an encrypted entity.
|
|
52
|
+
* @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.
|
|
53
|
+
*/
|
|
54
|
+
secretIdsForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{
|
|
55
|
+
ownerId: string;
|
|
56
|
+
extracted: string[];
|
|
57
|
+
}[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the decrypted owning entity ids (formerly CFKs) for the provided entity that can be decrypted using the private keys of the current data
|
|
60
|
+
* 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
|
|
61
|
+
* message for documents.
|
|
62
|
+
* 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
|
|
63
|
+
* data.
|
|
64
|
+
* @param entity an encrypted entity.
|
|
65
|
+
* @param dataOwnerId optionally a data owner part of the hierarchy for the current data owner, defaults to the current data owner.
|
|
66
|
+
* @return the owning entity ids (CFKs) that the provided data owner can decrypt, deduplicated.
|
|
67
|
+
*/
|
|
68
|
+
owningEntityIdsOf(entity: EncryptedEntityWithType, dataOwnerId: string | undefined): Promise<string[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the decrypted owning entity ids (formerly CFKs) for the provided entity that can be decrypted using the private keys of the current data
|
|
71
|
+
* 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
|
|
72
|
+
* message for documents.
|
|
73
|
+
* 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
|
|
74
|
+
* accessible through the parent keys). The order of the array is the same as in {@link IccDataOwnerXApi.getCurrentDataOwnerHierarchyIds}.
|
|
75
|
+
* 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
|
|
76
|
+
* deduplicated in case they could be accessed through different delegations.
|
|
77
|
+
* 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
|
|
78
|
+
* data.
|
|
79
|
+
* @param entity an encrypted entity.
|
|
80
|
+
* @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.
|
|
81
|
+
*/
|
|
82
|
+
owningEntityIdsForHcpHierarchyOf(entity: EncryptedEntityWithType): Promise<{
|
|
83
|
+
ownerId: string;
|
|
84
|
+
extracted: string[];
|
|
85
|
+
}[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Get if the current data owner has write access to the content of the entity.
|
|
88
|
+
* @param entity an entity
|
|
89
|
+
* @return if the current data owner (or one of his parents) has write access to the content of the entity.
|
|
90
|
+
*/
|
|
91
|
+
hasWriteAccess(entity: EncryptedEntityWithType): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* @param entity an entity
|
|
94
|
+
* @return if the entity has no encryption metadata and can be safely initialised using .
|
|
95
|
+
*/
|
|
96
|
+
hasEmptyEncryptionMetadata(entity: EncryptedEntity): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Get the data owners which can access the entity. See {@link EncryptedEntityXApi.getDataOwnersWithAccessTo} for more details.
|
|
99
|
+
* @param entity an entity.
|
|
100
|
+
*/
|
|
101
|
+
getDataOwnersWithAccessTo(entity: EncryptedEntityWithType): Promise<{
|
|
102
|
+
permissionsByDataOwnerId: {
|
|
103
|
+
[dataOwnerId: string]: AccessLevelEnum;
|
|
104
|
+
};
|
|
105
|
+
hasUnknownAnonymousDataOwners: boolean;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Initializes encryption metadata for an entity. This includes the encrypted secret id, owning entity id, encryption key for the entity, and
|
|
109
|
+
* the clear text secret foreign key of the parent entity.
|
|
110
|
+
* 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.
|
|
111
|
+
* @param entity entity which requires encryption metadata initialisation.
|
|
112
|
+
* @param entityType type of the entity.
|
|
113
|
+
* @param owningEntity id of the owning entity, if any (e.g. patient id for Contact/HealtchareElement, message id for Document, ...).
|
|
114
|
+
* @param owningEntitySecretId secret id of the parent entity, to use in the secret foreign keys for the provided entity, if any.
|
|
115
|
+
* @param initialiseEncryptionKey if false this method will not initialize an encryption key for the entity. Use only for entities which use
|
|
116
|
+
* delegations for access control but don't actually have any encrypted content.
|
|
117
|
+
* @param initialiseSecretId if false this method will not initialize any secret id, use it for entities which can not be 'owning entities' (e.g.
|
|
118
|
+
* HealthcareElement).
|
|
119
|
+
* @param autoDelegations automatically shares the metadata with the provided data owners, with the provided access level.
|
|
120
|
+
* @throws if the entity already has non-empty values for encryption metadata.
|
|
121
|
+
* @return an updated copy of the entity.
|
|
122
|
+
*/
|
|
123
|
+
entityWithInitialisedEncryptedMetadata<T extends EncryptedEntity>(entity: T, entityType: EntityWithDelegationTypeName, owningEntity: string | undefined, owningEntitySecretId: string | undefined, initialiseEncryptionKey: boolean, initialiseSecretId: boolean, autoDelegations: {
|
|
124
|
+
[dataOwnerId: string]: AccessLevelEnum;
|
|
125
|
+
}): Promise<{
|
|
126
|
+
updatedEntity: T;
|
|
127
|
+
rawEncryptionKey: string | undefined;
|
|
128
|
+
secretId: string | undefined;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* 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
|
|
132
|
+
* delegate.
|
|
133
|
+
* 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
|
|
134
|
+
* owner. Additionally, this method also allows to share new or existing secret ids (shareSecretId), encryption keys (shareEncryptionKeys) and
|
|
135
|
+
* owning entity ids (shareOwningEntityIds) for the entity.
|
|
136
|
+
* You can use methods like {@link secretIdsOf}, {@link secretIdsForHcpHierarchyOf}, {@link encryptionKeysOf}, ... to retrieve the data you want to
|
|
137
|
+
* 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
|
|
138
|
+
* may want to avoid sharing the confidential secret ids of the current user with other hcps.
|
|
139
|
+
* 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
|
|
140
|
+
* be used with entities which already exist in the cloud (the entities must have been saved).
|
|
141
|
+
* @param entitiesType type of entities to update
|
|
142
|
+
* @param entitiesUpdates share/update requests for each entity. An array of objects containing:
|
|
143
|
+
* - The entity to share/update (or at least its encrypted metadata)
|
|
144
|
+
* - 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
|
|
145
|
+
* permissions requested for the delegate (ignored if the request will only update already existing shared metadata).
|
|
146
|
+
* @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).
|
|
147
|
+
* @throws if there are duplicate entities in the requested updates.
|
|
148
|
+
* @return a promise which will be completed with an object containing:
|
|
149
|
+
* - the updated entities, only for entities were at least one update was successful
|
|
150
|
+
* - information on the individual requests failed, containing the id of the entity, id of the delegate that the request was for, the content,
|
|
151
|
+
* an error code mirroring an http status code, and a human-friendly description of the error (but not necessarily end-user friendly).
|
|
152
|
+
*/
|
|
153
|
+
bulkShareOrUpdateEncryptedEntityMetadata<T extends EncryptedEntityStub>(entitiesType: EntityWithDelegationTypeName, entitiesUpdates: {
|
|
154
|
+
entity: EncryptedEntityStub;
|
|
155
|
+
dataForDelegates: {
|
|
156
|
+
[delegateId: string]: {
|
|
157
|
+
shareSecretIds: string[];
|
|
158
|
+
shareEncryptionKeys: string[];
|
|
159
|
+
shareOwningEntityIds: string[];
|
|
160
|
+
requestedPermissions: RequestedPermissionEnum;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
}[], doRequestBulkShareOrUpdate: (request: {
|
|
164
|
+
[entityId: string]: {
|
|
165
|
+
[requestId: string]: EntityShareOrMetadataUpdateRequest;
|
|
166
|
+
};
|
|
167
|
+
}) => Promise<EntityBulkShareResult<T>[]>): Promise<{
|
|
168
|
+
updatedEntities: T[];
|
|
169
|
+
unmodifiedEntitiesIds: string[];
|
|
170
|
+
updateErrors: {
|
|
171
|
+
entityId: string;
|
|
172
|
+
delegateId: string;
|
|
173
|
+
request?: {
|
|
174
|
+
shareSecretIds?: string[];
|
|
175
|
+
shareEncryptionKeys?: string[];
|
|
176
|
+
shareOwningEntityIds?: string[];
|
|
177
|
+
requestedPermissions: RequestedPermissionEnum;
|
|
178
|
+
};
|
|
179
|
+
updatedForMigration: boolean;
|
|
180
|
+
code?: number;
|
|
181
|
+
reason?: string;
|
|
182
|
+
}[];
|
|
183
|
+
}>;
|
|
184
|
+
bulkShareOrUpdateEncryptedEntityMetadataNoEntities(entitiesType: EntityWithDelegationTypeName, entitiesUpdates: {
|
|
185
|
+
entity: EncryptedEntityStub;
|
|
186
|
+
dataForDelegates: {
|
|
187
|
+
[delegateId: string]: {
|
|
188
|
+
shareSecretIds: string[];
|
|
189
|
+
shareEncryptionKeys: string[];
|
|
190
|
+
shareOwningEntityIds: string[];
|
|
191
|
+
requestedPermissions: RequestedPermissionEnum;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
}[], doRequestBulkShareOrUpdate: (request: {
|
|
195
|
+
[entityId: string]: {
|
|
196
|
+
[requestId: string]: EntityShareOrMetadataUpdateRequest;
|
|
197
|
+
};
|
|
198
|
+
}) => Promise<MinimalEntityBulkShareResult[]>): Promise<{
|
|
199
|
+
unmodifiedEntitiesIds: string[];
|
|
200
|
+
successfulUpdates: {
|
|
201
|
+
entityId: string;
|
|
202
|
+
delegateId: string;
|
|
203
|
+
}[];
|
|
204
|
+
updateErrors: {
|
|
205
|
+
entityId: string;
|
|
206
|
+
delegateId: string;
|
|
207
|
+
request?: {
|
|
208
|
+
shareSecretIds?: string[];
|
|
209
|
+
shareEncryptionKeys?: string[];
|
|
210
|
+
shareOwningEntityIds?: string[];
|
|
211
|
+
requestedPermissions: RequestedPermissionEnum;
|
|
212
|
+
};
|
|
213
|
+
updatedForMigration: boolean;
|
|
214
|
+
code?: number;
|
|
215
|
+
reason?: string;
|
|
216
|
+
}[];
|
|
217
|
+
}>;
|
|
218
|
+
/**
|
|
219
|
+
* Simplified version of {@link bulkShareOrUpdateEncryptedEntityMetadata} for a single entity and with automatic retrieval of the encryption keys
|
|
220
|
+
* 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
|
|
221
|
+
* been saved).
|
|
222
|
+
* @param entity an entity.
|
|
223
|
+
* @param unusedSecretIds specifies if the entity should not actually use secret ids but may have some if it was created using older iCure sdk
|
|
224
|
+
* versions. If true the method expects `shareSecretIds` options to always be undefined and will always share any available secret ids. If false
|
|
225
|
+
* it expects `shareSecretIds` options to always be defined and will only share the secret ids specified in the options.
|
|
226
|
+
* @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options:
|
|
227
|
+
* - shareEncryptionKeys specifies if the encryption keys of the entity should be shared. Defaults to
|
|
228
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}.
|
|
229
|
+
* - shareOwningEntityIds specifies if the owning entity ids of the entity should be shared. Defaults to
|
|
230
|
+
* {@link ShareMetadataBehaviour.IF_AVAILABLE}.
|
|
231
|
+
* - shareSecretIds specifies which secret ids of the entity should be shared. Should be defined only if {@link unusedSecretIds} is false.
|
|
232
|
+
* - requestedPermissions requested permissions for the delegate. Defaults to {@link RequestedPermissionEnum.MAX_WRITE}.
|
|
233
|
+
* @param doRequestBulkShareOrUpdate perform the request to share or update an entity encrypted metadata on the cloud API (and save to DB).
|
|
234
|
+
* @return a promise which will be completed with the result of the operation
|
|
235
|
+
* @throws if shareEncryptionKeys or shareOwningEntityIds is {@link ShareMetadataBehaviour.REQUIRED} and the current data owner can't access any
|
|
236
|
+
* value for the required metadata.
|
|
237
|
+
*/
|
|
238
|
+
simpleShareOrUpdateEncryptedEntityMetadata<T extends EncryptedEntityStub>(entity: {
|
|
239
|
+
entity: T;
|
|
240
|
+
type: EntityWithDelegationTypeName;
|
|
241
|
+
}, unusedSecretIds: boolean, delegates: {
|
|
242
|
+
[delegateId: string]: {
|
|
243
|
+
shareSecretIds: string[] | undefined;
|
|
244
|
+
shareEncryptionKeys: ShareMetadataBehaviour | undefined;
|
|
245
|
+
shareOwningEntityIds: ShareMetadataBehaviour | undefined;
|
|
246
|
+
requestedPermissions: RequestedPermissionEnum | undefined;
|
|
247
|
+
};
|
|
248
|
+
}, doRequestBulkShareOrUpdate: (request: {
|
|
249
|
+
[entityId: string]: {
|
|
250
|
+
[requestId: string]: EntityShareOrMetadataUpdateRequest;
|
|
251
|
+
};
|
|
252
|
+
}) => Promise<EntityBulkShareResult<T>[]>): Promise<ShareResult<T>>;
|
|
253
|
+
/**
|
|
254
|
+
* 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
|
|
255
|
+
* access multiple encryption keys of the entity there is no guarantee on which key will be used.
|
|
256
|
+
* Note: you should not use this method to encrypt the `encryptedSelf` of iCure entities, since that will be automatically handled by the extended
|
|
257
|
+
* apis. You should use this method only to encrypt additional data, such as document attachments.
|
|
258
|
+
* @param entity an entity.
|
|
259
|
+
* @param type type of the entity.
|
|
260
|
+
* @param content data of the entity which you want to encrypt.
|
|
261
|
+
* @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.
|
|
262
|
+
* @return the encrypted data and, if a new encryption key was initialised for the entity, the updated entity.
|
|
263
|
+
* @throws if the provided data owner can't access any encryption keys for the entity.
|
|
264
|
+
*/
|
|
265
|
+
encryptDataOf<T extends EncryptedEntityStub>(entity: T, type: EntityWithDelegationTypeName, content: ArrayBuffer | Uint8Array, saveEntity: (entity: T) => Promise<T>): Promise<{
|
|
266
|
+
encryptedData: ArrayBuffer;
|
|
267
|
+
updatedEntity: T | undefined;
|
|
268
|
+
}>;
|
|
269
|
+
/**
|
|
270
|
+
* 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
|
|
271
|
+
* 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
|
|
272
|
+
* provided validator.
|
|
273
|
+
* Note: you should not use this method to decrypt the `encryptedSelf` of iCure entities, since that will be automatically handled by the extended
|
|
274
|
+
* apis. You should use this method only to decrypt additional data, such as document attachments.
|
|
275
|
+
* @param entity an entity.
|
|
276
|
+
* @param content data of the entity which you want to decrypt.
|
|
277
|
+
* @param validator a function which verifies the correctness of decrypted content: helps to identify decryption with the wrong key without relying
|
|
278
|
+
* solely on padding.
|
|
279
|
+
* @return the decrypted data.
|
|
280
|
+
* @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
|
|
281
|
+
* content according to the validator.
|
|
282
|
+
*/
|
|
283
|
+
tryDecryptDataOf(entity: EncryptedEntityWithType, content: ArrayBuffer | Uint8Array, validator: (decryptedData: ArrayBuffer) => Promise<boolean> | undefined): Promise<{
|
|
284
|
+
data: ArrayBuffer;
|
|
285
|
+
wasDecrypted: boolean;
|
|
286
|
+
}>;
|
|
287
|
+
/**
|
|
288
|
+
* TODO work on this
|
|
289
|
+
* Decrypts the content of an encrypted entity.
|
|
290
|
+
*/
|
|
291
|
+
decryptEntity<T extends EncryptedEntity>(entity: T, entityType: EntityWithDelegationTypeName, constructor: (json: any) => T): Promise<{
|
|
292
|
+
entity: T;
|
|
293
|
+
decrypted: boolean;
|
|
294
|
+
}>;
|
|
295
|
+
/**
|
|
296
|
+
* Tries to decrypt data to a json object using the provided keys.
|
|
297
|
+
*/
|
|
298
|
+
tryDecryptJson(potentialKeys: {
|
|
299
|
+
key: CryptoKey;
|
|
300
|
+
raw: string;
|
|
301
|
+
}[], encrypted: Uint8Array, truncateTrailingDecryptedNulls: boolean): Promise<{} | undefined>;
|
|
302
|
+
/**
|
|
303
|
+
* Tries to encrypt the content of an encrypted entity.
|
|
304
|
+
* 1. If valid key for encryption is found the method returns the entity with the encrypted fields specified by cryptedKeys
|
|
305
|
+
* 2. If requireEncryption is true and no key could be found for encryption of the entity the method fails.
|
|
306
|
+
* 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
|
|
307
|
+
* for fields which should be encrypted according to cryptedKeys (e.g. note in a patient using the default configuration). If the entity specifies
|
|
308
|
+
* a value for any field which should be encrypted the method throws an error, otherwise the method returns the original entity.
|
|
309
|
+
*/
|
|
310
|
+
tryEncryptEntity<T extends EncryptedEntity>(entity: T, entityType: EntityWithDelegationTypeName, fieldsToEncrypt: EncryptedFieldsManifest, encodeBinaryData: boolean, requireEncryption: boolean, constructor: (json: any) => T): Promise<T>;
|
|
311
|
+
/**
|
|
312
|
+
* Returns the first encryption key which could be properly decrypted from the entity using the current data owner.
|
|
313
|
+
* @throws if no key could be decrypted.
|
|
314
|
+
*/
|
|
315
|
+
decryptAndImportAnyEncryptionKey(entity: EncryptedEntityWithType): Promise<{
|
|
316
|
+
key: CryptoKey;
|
|
317
|
+
raw: string;
|
|
318
|
+
}>;
|
|
319
|
+
/**
|
|
320
|
+
* Returns all encryption keys which could be properly decrypted from the entity using the current data owner. The keys returned by this method
|
|
321
|
+
* should not be used for encryption of the entity, but only for decryption.
|
|
322
|
+
* This is because this for data from pre-2018 users this method may return also keys from old formats of entities which are not safe anymore for
|
|
323
|
+
* encryption.
|
|
324
|
+
*/
|
|
325
|
+
decryptAndImportAllDecryptionKeys(entity: EncryptedEntityWithType): Promise<{
|
|
326
|
+
key: CryptoKey;
|
|
327
|
+
raw: string;
|
|
328
|
+
}[]>;
|
|
329
|
+
/**
|
|
330
|
+
* 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
|
|
331
|
+
* 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
|
|
332
|
+
* key not safe for encryption anymore, in which case this method will return the entity with a new and safe encryption key.
|
|
333
|
+
* 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.
|
|
334
|
+
*/
|
|
335
|
+
ensureEncryptionKeysInitialised<T extends EncryptedEntity>(entity: T, entityType: EntityWithDelegationTypeName): Promise<T | undefined>;
|
|
336
|
+
}
|