@icure/api 8.0.48 → 8.0.50
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/IccContactApi.js +1 -1
- package/icc-api/api/IccContactApi.js.map +1 -1
- package/icc-x-api/crypto/ConfidentialEntities.js +1 -1
- package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -1
- package/icc-x-api/crypto/DelegationsDeAnonymization.js +5 -2
- package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -1
- package/icc-x-api/crypto/ExtendedApisUtils.d.ts +5 -8
- package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -1
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +5 -5
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +4 -14
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
- package/icc-x-api/crypto/utils.js +5 -2
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/filters/HealthElementByHcPartyTagCodeFilter.d.ts +1 -1
- package/icc-x-api/filters/HealthElementByHcPartyTagCodeFilter.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +6 -0
- package/icc-x-api/icc-accesslog-x-api.js +9 -3
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +6 -0
- package/icc-x-api/icc-calendar-item-x-api.js +9 -3
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +6 -0
- package/icc-x-api/icc-classification-x-api.js +9 -3
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +6 -0
- package/icc-x-api/icc-contact-x-api.js +9 -3
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +6 -0
- package/icc-x-api/icc-document-x-api.js +9 -3
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +6 -0
- package/icc-x-api/icc-form-x-api.js +9 -3
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +6 -0
- package/icc-x-api/icc-helement-x-api.js +9 -3
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +6 -0
- package/icc-x-api/icc-invoice-x-api.js +9 -3
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +6 -0
- package/icc-x-api/icc-maintenance-task-x-api.js +9 -3
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.js +5 -2
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.js +5 -2
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +6 -0
- package/icc-x-api/icc-receipt-x-api.js +9 -3
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +6 -0
- package/icc-x-api/icc-time-table-x-api.js +9 -3
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-topic-x-api.d.ts +6 -0
- package/icc-x-api/icc-topic-x-api.js +9 -3
- package/icc-x-api/icc-topic-x-api.js.map +1 -1
- package/package.json +1 -1
- package/test/icc-x-api/help-meddi.d.ts +1 -0
- package/test/icc-x-api/help-meddi.js +53 -0
- package/test/icc-x-api/help-meddi.js.map +1 -0
- package/test/icc-x-api/icc-recovery-x-api.js +5 -0
- package/test/icc-x-api/icc-recovery-x-api.js.map +1 -1
|
@@ -22,6 +22,8 @@ const DataOwnerTypeEnum_1 = require("../../icc-api/model/DataOwnerTypeEnum");
|
|
|
22
22
|
const SecureDelegation_1 = require("../../icc-api/model/SecureDelegation");
|
|
23
23
|
var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
|
|
24
24
|
const icc_recovery_x_api_1 = require("../../icc-x-api/icc-recovery-x-api");
|
|
25
|
+
const FilterChainHealthElement_1 = require("../../icc-api/model/FilterChainHealthElement");
|
|
26
|
+
const HealthElementByHcPartyFilter_1 = require("../../icc-x-api/filters/HealthElementByHcPartyFilter");
|
|
25
27
|
(0, chai_1.use)(chaiAsPromised);
|
|
26
28
|
(0, test_utils_1.setLocalStorage)(fetch);
|
|
27
29
|
let env;
|
|
@@ -79,6 +81,9 @@ describe('Recovery api use scenarios', () => {
|
|
|
79
81
|
(0, chai_1.expect)(yield patientApi.recoveryApi.recoverExchangeData(recoveryKey + 'aa')).to.equal(icc_recovery_x_api_1.RecoveryDataUseFailureReason.Missing); // User put in the wrong key
|
|
80
82
|
(0, chai_1.expect)(yield patientApi.recoveryApi.recoverExchangeData(recoveryKey)).to.be.null;
|
|
81
83
|
(0, chai_1.expect)(yield patientApi.recoveryApi.recoverExchangeData(recoveryKey)).to.equal(icc_recovery_x_api_1.RecoveryDataUseFailureReason.Missing); // After use it is automatically deleted
|
|
84
|
+
(0, chai_1.expect)((yield patientApi.healthcareElementApi.filterByWithUser(patientUser, undefined, 10000, new FilterChainHealthElement_1.FilterChainHealthElement({
|
|
85
|
+
filter: new HealthElementByHcPartyFilter_1.HealthElementByHcPartyFilter({ hcpId: patientUser.patientId }),
|
|
86
|
+
}))).rows[0]).to.be.deep.equal(sharedHealthData);
|
|
82
87
|
(0, chai_1.expect)(yield patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, sharedHealthData.id)).to.be.deep.equal(sharedHealthData);
|
|
83
88
|
yield hcp.api.cryptoApi.forceReload();
|
|
84
89
|
const healthData2 = yield hcp.api.healthcareElementApi.createHealthElementWithUser(hcp.user, yield hcp.api.healthcareElementApi.newInstance(hcp.user, patient, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-recovery-x-api.js","sourceRoot":"","sources":["../../../test/icc-x-api/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M,UAAU,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;YAChF,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,iDAA4B,CAAC,OAAO,EAAE,CAAC,CAAA;QACrF,CAAC;KAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { createNewHcpApi, getEnvironmentInitializer, getTempEmail, isLiteTest, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { CryptoPrimitives, IcureApi, KeyPair, sleep } from '../../icc-x-api'\nimport { randomUUID, webcrypto } from 'crypto'\nimport { User } from '../../icc-api/model/User'\nimport { assert, expect, use as chaiUse } from 'chai'\nimport * as chaiAsPromised from 'chai-as-promised'\nimport { TestKeyStorage, TestStorage } from '../utils/TestStorage'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { DataOwnerTypeEnum } from '../../icc-api/model/DataOwnerTypeEnum'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { RecoveryDataUseFailureReason } from '../../icc-x-api/icc-recovery-x-api'\nimport { KeyPairRecoverer } from '../../icc-x-api/crypto/KeyPairRecoverer'\nimport { delay } from 'lodash'\n\nchaiUse(chaiAsPromised)\nsetLocalStorage(fetch)\nlet env: TestVars\n\ndescribe('Recovery api use scenarios', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('An hcp should be able to share data with an uninitialized patient data owner and the patient should be able to recover the exchange data with the provided recovery key.', async function () {\n const hcp = await createNewHcpApi(env)\n const patientId = randomUUID()\n const patientMail = getTempEmail()\n const patientPassword = randomUUID()\n const patient = await hcp.api.patientApi.createPatientWithUser(\n hcp.user,\n await hcp.api.patientApi.newInstance(hcp.user, {\n id: patientId,\n firstName: 'John',\n lastName: 'Doe',\n })\n )\n const patientUser = await hcp.api.userApi.createUser(\n new User({\n id: randomUUID(),\n login: patientMail,\n passwordHash: patientPassword,\n patientId: patientId,\n })\n )\n const healthData = await hcp.api.healthcareElementApi.createHealthElementWithUser(\n hcp.user,\n await hcp.api.healthcareElementApi.newInstance(hcp.user, patient, {\n descr: 'Health data',\n })\n )\n await expect(hcp.api.healthcareElementApi.shareWith(patientId, healthData)).to.be.rejected\n expect(await hcp.api.patientApi.forceInitialiseExchangeDataToNewlyInvitedPatient(patientId)).to.be.true\n const recoveryKey = await hcp.api.recoveryApi.createExchangeDataRecoveryInfo(patientId)\n const sharedHealthData = await hcp.api.healthcareElementApi.shareWith(patientId, healthData)\n const patientApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: patientMail, password: patientPassword },\n {\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type == DataOwnerTypeEnum.Patient\n },\n generateNewKeyForDataOwner(): Promise<boolean> {\n return Promise.resolve(true)\n },\n recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[]\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n return Promise.resolve(Object.fromEntries(keysData.map((x) => [x.dataOwner.dataOwner.id, { recoveredKeys: {}, keyAuthenticity: {} }])))\n },\n verifyDelegatePublicKeys(_: any, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n },\n },\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n if (!isLiteTest()) await expect(patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, sharedHealthData.id!)).to.be.rejected\n expect(await patientApi.recoveryApi.recoverExchangeData(recoveryKey + 'aa')).to.equal(RecoveryDataUseFailureReason.Missing) // User put in the wrong key\n expect(await patientApi.recoveryApi.recoverExchangeData(recoveryKey)).to.be.null\n expect(await patientApi.recoveryApi.recoverExchangeData(recoveryKey)).to.equal(RecoveryDataUseFailureReason.Missing) // After use it is automatically deleted\n expect(await patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, sharedHealthData.id!)).to.be.deep.equal(sharedHealthData)\n await hcp.api.cryptoApi.forceReload()\n const healthData2 = await hcp.api.healthcareElementApi.createHealthElementWithUser(\n hcp.user,\n await hcp.api.healthcareElementApi.newInstance(\n hcp.user,\n patient,\n {\n descr: 'Health data 2',\n },\n {\n additionalDelegates: { [patientId]: AccessLevelEnum.WRITE },\n }\n )\n )\n expect(await patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, healthData2.id!)).to.be.deep.equal(healthData2)\n expect(await hcp.api.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.credentials.dataOwnerId, patientId)).to.have.length(1)\n })\n\n it('A user should be able to create keypair recovery data and use the recovery key to get back the keys.', async function () {\n const hcp = await createNewHcpApi(env)\n const patient = await hcp.api.patientApi.createPatientWithUser(\n hcp.user,\n await hcp.api.patientApi.newInstance(hcp.user, {\n firstName: 'John',\n lastName: 'Doe',\n note: 'Encrypted content',\n })\n )\n expect(patient.note).to.equal('Encrypted content')\n const recoveryKey = await hcp.api.recoveryApi.createRecoveryInfoForAvailableKeyPairs()\n let recoverAndVerifiedCalled = false\n const recoveredApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcp.credentials.user, password: hcp.credentials.password },\n {\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type == DataOwnerTypeEnum.Patient\n },\n generateNewKeyForDataOwner(): Promise<boolean> {\n return Promise.resolve(false)\n },\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n _: any,\n keyRecoverer: KeyPairRecoverer\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n recoverAndVerifiedCalled = true\n const recovered = await keyRecoverer.recoverWithRecoveryKey(recoveryKey, true)\n if ('success' in recovered) {\n expect(Object.entries(recovered.success)).to.have.length(1)\n const recoveredForSelf = recovered.success[hcp.credentials.dataOwnerId]\n expect(Object.entries(recoveredForSelf)).to.have.length(1)\n expect(await keyRecoverer.recoverWithRecoveryKey(recoveryKey, true)).to.deep.equal({ failure: RecoveryDataUseFailureReason.Missing })\n const res: {\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n } = {}\n for (const keyData of keysData) {\n if (keyData.dataOwner.dataOwner.id == hcp.credentials.dataOwnerId) {\n res[keyData.dataOwner.dataOwner.id] = {\n recoveredKeys: recoveredForSelf,\n keyAuthenticity: {},\n }\n } else {\n res[keyData.dataOwner.dataOwner.id!] = {\n recoveredKeys: {},\n keyAuthenticity: {},\n }\n }\n }\n return res\n } else {\n assert.fail('Could not recover keys with recovery key')\n }\n },\n verifyDelegatePublicKeys(_: any, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n },\n },\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n expect(recoverAndVerifiedCalled).to.be.true\n expect(recoveredApi.dataOwnerApi.getHexPublicKeysOf(await recoveredApi.healthcarePartyApi.getCurrentHealthcareParty())).to.have.length(1)\n expect(await recoveredApi.patientApi.getPatientWithUser(hcp.user, patient.id!)).to.be.deep.equal(patient)\n })\n\n it('Recovery data should expire after the lifetime has elapsed', async function () {\n const hcp = await createNewHcpApi(env)\n const recoveryKey = await hcp.api.recoveryApi.createRecoveryInfoForAvailableKeyPairs({ lifetimeSeconds: 5 })\n await sleep(1000)\n const recovered1 = await hcp.api.recoveryApi.recoverKeyPairs(recoveryKey, false)\n expect(recovered1).to.have.keys('success')\n await sleep(1000)\n const recovered2 = await hcp.api.recoveryApi.recoverKeyPairs(recoveryKey, false)\n expect(recovered2).to.have.keys('success')\n await sleep(3000)\n const recovered3 = await hcp.api.recoveryApi.recoverKeyPairs(recoveryKey, false)\n expect(recovered3).to.deep.equal({ failure: RecoveryDataUseFailureReason.Missing })\n })\n})\n"]}
|
|
1
|
+
{"version":3,"file":"icc-recovery-x-api.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-recovery-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAsI;AACtI,iCAA8B;AAC9B,mDAAmE;AACnE,+CAA4E;AAC5E,mCAA8C;AAC9C,mDAA+C;AAC/C,+BAAqD;AACrD,mDAAkD;AAClD,sDAAkE;AAElE,6EAAyE;AAEzE,2EAAuE;AACvE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,2EAAiF;AAGjF,2FAAuF;AACvF,uGAAmG;AAEnG,IAAA,UAAO,EAAC,cAAc,CAAC,CAAA;AACvB,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AAEjB,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,IAAA,cAAM,EAAC;;YACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;YACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;QACpD,CAAC;KAAA,CAAC,CAAA;IAEF,EAAE,CAAC,0KAA0K,EAAE;;YAC7K,MAAM,GAAG,GAAG,MAAM,IAAA,4BAAe,EAAC,GAAG,CAAC,CAAA;YACtC,MAAM,SAAS,GAAG,IAAA,mBAAU,GAAE,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AE;;YAC/D,MAAM,GAAG,GAAG,MAAM,IAAA,4BAAe,EAAC,GAAG,CAAC,CAAA;YACtC,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,sCAAsC,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC,CAAA;YAC5G,MAAM,IAAA,iBAAK,EAAC,IAAI,CAAC,CAAA;YACjB,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;YAChF,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC1C,MAAM,IAAA,iBAAK,EAAC,IAAI,CAAC,CAAA;YACjB,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;YAChF,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC1C,MAAM,IAAA,iBAAK,EAAC,IAAI,CAAC,CAAA;YACjB,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;YAChF,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,iDAA4B,CAAC,OAAO,EAAE,CAAC,CAAA;QACrF,CAAC;KAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { createNewHcpApi, getEnvironmentInitializer, getTempEmail, isLiteTest, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { CryptoPrimitives, IcureApi, KeyPair, sleep } from '../../icc-x-api'\nimport { randomUUID, webcrypto } from 'crypto'\nimport { User } from '../../icc-api/model/User'\nimport { assert, expect, use as chaiUse } from 'chai'\nimport * as chaiAsPromised from 'chai-as-promised'\nimport { TestKeyStorage, TestStorage } from '../utils/TestStorage'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { DataOwnerTypeEnum } from '../../icc-api/model/DataOwnerTypeEnum'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport { RecoveryDataUseFailureReason } from '../../icc-x-api/icc-recovery-x-api'\nimport { KeyPairRecoverer } from '../../icc-x-api/crypto/KeyPairRecoverer'\nimport { delay } from 'lodash'\nimport { FilterChainHealthElement } from '../../icc-api/model/FilterChainHealthElement'\nimport { HealthElementByHcPartyFilter } from '../../icc-x-api/filters/HealthElementByHcPartyFilter'\n\nchaiUse(chaiAsPromised)\nsetLocalStorage(fetch)\nlet env: TestVars\n\ndescribe('Recovery api use scenarios', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('An hcp should be able to share data with an uninitialized patient data owner and the patient should be able to recover the exchange data with the provided recovery key.', async function () {\n const hcp = await createNewHcpApi(env)\n const patientId = randomUUID()\n const patientMail = getTempEmail()\n const patientPassword = randomUUID()\n const patient = await hcp.api.patientApi.createPatientWithUser(\n hcp.user,\n await hcp.api.patientApi.newInstance(hcp.user, {\n id: patientId,\n firstName: 'John',\n lastName: 'Doe',\n })\n )\n const patientUser = await hcp.api.userApi.createUser(\n new User({\n id: randomUUID(),\n login: patientMail,\n passwordHash: patientPassword,\n patientId: patientId,\n })\n )\n const healthData = await hcp.api.healthcareElementApi.createHealthElementWithUser(\n hcp.user,\n await hcp.api.healthcareElementApi.newInstance(hcp.user, patient, {\n descr: 'Health data',\n })\n )\n await expect(hcp.api.healthcareElementApi.shareWith(patientId, healthData)).to.be.rejected\n expect(await hcp.api.patientApi.forceInitialiseExchangeDataToNewlyInvitedPatient(patientId)).to.be.true\n const recoveryKey = await hcp.api.recoveryApi.createExchangeDataRecoveryInfo(patientId)\n const sharedHealthData = await hcp.api.healthcareElementApi.shareWith(patientId, healthData)\n const patientApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: patientMail, password: patientPassword },\n {\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type == DataOwnerTypeEnum.Patient\n },\n generateNewKeyForDataOwner(): Promise<boolean> {\n return Promise.resolve(true)\n },\n recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[]\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n return Promise.resolve(Object.fromEntries(keysData.map((x) => [x.dataOwner.dataOwner.id, { recoveredKeys: {}, keyAuthenticity: {} }])))\n },\n verifyDelegatePublicKeys(_: any, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n },\n },\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n if (!isLiteTest()) await expect(patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, sharedHealthData.id!)).to.be.rejected\n expect(await patientApi.recoveryApi.recoverExchangeData(recoveryKey + 'aa')).to.equal(RecoveryDataUseFailureReason.Missing) // User put in the wrong key\n expect(await patientApi.recoveryApi.recoverExchangeData(recoveryKey)).to.be.null\n expect(await patientApi.recoveryApi.recoverExchangeData(recoveryKey)).to.equal(RecoveryDataUseFailureReason.Missing) // After use it is automatically deleted\n expect(\n (\n await patientApi.healthcareElementApi.filterByWithUser(\n patientUser,\n undefined,\n 10000,\n new FilterChainHealthElement({\n filter: new HealthElementByHcPartyFilter({ hcpId: patientUser.patientId }),\n })\n )\n ).rows![0]\n ).to.be.deep.equal(sharedHealthData)\n expect(await patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, sharedHealthData.id!)).to.be.deep.equal(sharedHealthData)\n await hcp.api.cryptoApi.forceReload()\n const healthData2 = await hcp.api.healthcareElementApi.createHealthElementWithUser(\n hcp.user,\n await hcp.api.healthcareElementApi.newInstance(\n hcp.user,\n patient,\n {\n descr: 'Health data 2',\n },\n {\n additionalDelegates: { [patientId]: AccessLevelEnum.WRITE },\n }\n )\n )\n expect(await patientApi.healthcareElementApi.getHealthElementWithUser(patientUser, healthData2.id!)).to.be.deep.equal(healthData2)\n expect(await hcp.api.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.credentials.dataOwnerId, patientId)).to.have.length(1)\n })\n\n it('A user should be able to create keypair recovery data and use the recovery key to get back the keys.', async function () {\n const hcp = await createNewHcpApi(env)\n const patient = await hcp.api.patientApi.createPatientWithUser(\n hcp.user,\n await hcp.api.patientApi.newInstance(hcp.user, {\n firstName: 'John',\n lastName: 'Doe',\n note: 'Encrypted content',\n })\n )\n expect(patient.note).to.equal('Encrypted content')\n const recoveryKey = await hcp.api.recoveryApi.createRecoveryInfoForAvailableKeyPairs()\n let recoverAndVerifiedCalled = false\n const recoveredApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcp.credentials.user, password: hcp.credentials.password },\n {\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type == DataOwnerTypeEnum.Patient\n },\n generateNewKeyForDataOwner(): Promise<boolean> {\n return Promise.resolve(false)\n },\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n _: any,\n keyRecoverer: KeyPairRecoverer\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n recoverAndVerifiedCalled = true\n const recovered = await keyRecoverer.recoverWithRecoveryKey(recoveryKey, true)\n if ('success' in recovered) {\n expect(Object.entries(recovered.success)).to.have.length(1)\n const recoveredForSelf = recovered.success[hcp.credentials.dataOwnerId]\n expect(Object.entries(recoveredForSelf)).to.have.length(1)\n expect(await keyRecoverer.recoverWithRecoveryKey(recoveryKey, true)).to.deep.equal({ failure: RecoveryDataUseFailureReason.Missing })\n const res: {\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n } = {}\n for (const keyData of keysData) {\n if (keyData.dataOwner.dataOwner.id == hcp.credentials.dataOwnerId) {\n res[keyData.dataOwner.dataOwner.id] = {\n recoveredKeys: recoveredForSelf,\n keyAuthenticity: {},\n }\n } else {\n res[keyData.dataOwner.dataOwner.id!] = {\n recoveredKeys: {},\n keyAuthenticity: {},\n }\n }\n }\n return res\n } else {\n assert.fail('Could not recover keys with recovery key')\n }\n },\n verifyDelegatePublicKeys(_: any, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n },\n },\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n expect(recoverAndVerifiedCalled).to.be.true\n expect(recoveredApi.dataOwnerApi.getHexPublicKeysOf(await recoveredApi.healthcarePartyApi.getCurrentHealthcareParty())).to.have.length(1)\n expect(await recoveredApi.patientApi.getPatientWithUser(hcp.user, patient.id!)).to.be.deep.equal(patient)\n })\n\n it('Recovery data should expire after the lifetime has elapsed', async function () {\n const hcp = await createNewHcpApi(env)\n const recoveryKey = await hcp.api.recoveryApi.createRecoveryInfoForAvailableKeyPairs({ lifetimeSeconds: 5 })\n await sleep(1000)\n const recovered1 = await hcp.api.recoveryApi.recoverKeyPairs(recoveryKey, false)\n expect(recovered1).to.have.keys('success')\n await sleep(1000)\n const recovered2 = await hcp.api.recoveryApi.recoverKeyPairs(recoveryKey, false)\n expect(recovered2).to.have.keys('success')\n await sleep(3000)\n const recovered3 = await hcp.api.recoveryApi.recoverKeyPairs(recoveryKey, false)\n expect(recovered3).to.deep.equal({ failure: RecoveryDataUseFailureReason.Missing })\n })\n})\n"]}
|