@icure/api 8.1.9 → 8.2.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-x-api/crypto/BaseExchangeDataManager.d.ts +19 -9
- package/icc-x-api/crypto/BaseExchangeDataManager.js +25 -5
- package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
- package/icc-x-api/crypto/CryptoStrategies.d.ts +2 -1
- package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
- package/icc-x-api/crypto/DelegationsDeAnonymization.js +1 -1
- package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -1
- package/icc-x-api/crypto/ExchangeDataManager.d.ts +25 -2
- package/icc-x-api/crypto/ExchangeDataManager.js +98 -5
- package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
- package/icc-x-api/crypto/ExtendedApisUtils.d.ts +3 -1
- package/icc-x-api/crypto/ExtendedApisUtils.js.map +1 -1
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.d.ts +1 -1
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +3 -3
- package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
- package/icc-x-api/crypto/SecureDelegationsManager.d.ts +3 -1
- package/icc-x-api/crypto/SecureDelegationsManager.js +10 -6
- package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
- package/icc-x-api/crypto/ShamirKeysManager.js +1 -1
- package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
- package/icc-x-api/crypto/UserEncryptionKeysManager.d.ts +2 -1
- package/icc-x-api/crypto/UserEncryptionKeysManager.js +18 -1
- package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -1
- package/icc-x-api/crypto/utils.js +1 -1
- package/icc-x-api/crypto/utils.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 +6 -2
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +4 -0
- package/icc-x-api/icc-calendar-item-x-api.js +3 -1
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +3 -0
- package/icc-x-api/icc-classification-x-api.js +3 -1
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +3 -0
- package/icc-x-api/icc-contact-x-api.js +3 -1
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +29 -0
- package/icc-x-api/icc-crypto-x-api.js +36 -0
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +3 -0
- package/icc-x-api/icc-document-x-api.js +3 -1
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +3 -0
- package/icc-x-api/icc-form-x-api.js +3 -1
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +3 -0
- package/icc-x-api/icc-helement-x-api.js +3 -1
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +3 -0
- package/icc-x-api/icc-invoice-x-api.js +3 -1
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +3 -0
- package/icc-x-api/icc-maintenance-task-x-api.js +3 -1
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +3 -0
- package/icc-x-api/icc-message-x-api.js +3 -1
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +3 -0
- package/icc-x-api/icc-patient-x-api.js +6 -2
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +3 -0
- package/icc-x-api/icc-receipt-x-api.js +3 -1
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-recovery-x-api.js +8 -1
- package/icc-x-api/icc-recovery-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +3 -0
- package/icc-x-api/icc-time-table-x-api.js +3 -1
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-topic-x-api.d.ts +3 -0
- package/icc-x-api/icc-topic-x-api.js +3 -1
- package/icc-x-api/icc-topic-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +16 -0
- package/icc-x-api/index.js +8 -2
- package/icc-x-api/index.js.map +1 -1
- package/package.json +1 -1
- package/test/icc-x-api/autofix-anonymity-test.js +18 -4
- package/test/icc-x-api/autofix-anonymity-test.js.map +1 -1
- package/test/icc-x-api/crypto/exchange-data-manager-test.js +30 -30
- package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +1 -1
- package/test/icc-x-api/crypto/secure-delegations-manager-test.js +2 -2
- package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +1 -1
- package/test/icc-x-api/icc-hcparty-x-api-test.js +2 -14
- package/test/icc-x-api/icc-hcparty-x-api-test.js.map +1 -1
- package/test/icc-x-api/keyless-api.d.ts +1 -0
- package/test/icc-x-api/keyless-api.js +125 -0
- package/test/icc-x-api/keyless-api.js.map +1 -0
- package/test/utils/FakeEncryptionKeysManager.js +1 -1
- package/test/utils/FakeEncryptionKeysManager.js.map +1 -1
- package/test/utils/FakeExchangeDataManager.d.ts +8 -0
- package/test/utils/FakeExchangeDataManager.js +3 -0
- package/test/utils/FakeExchangeDataManager.js.map +1 -1
- package/test/utils/KeylessCryptoStrategies.d.ts +23 -0
- package/test/utils/KeylessCryptoStrategies.js +26 -0
- package/test/utils/KeylessCryptoStrategies.js.map +1 -0
- package/test/utils/test_utils.d.ts +7 -0
- package/test/utils/test_utils.js +30 -1
- package/test/utils/test_utils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-delegations-manager-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/secure-delegations-manager-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAgC;AAChC,iFAAgF;AAChF,mCAAkC;AAClC,qFAAiF;AACjF,uGAAmG;AACnG,kDAA6F;AAC7F,iGAA6F;AAC7F,iGAA6F;AAC7F,uFAAqI;AACrI,+FAA2F;AAC3F,yEAAqE;AACrE,mEAA+D;AAC/D,2EAAuE;AAEvE,2FAAuF;AACvF,+BAA6B;AAE7B,8EAA0E;AAC1E,8EAA0E;AAE1E,yHAAqH;AACrH,2DAAkF;AAClF,gFAA4E;AAC5E,uFAAmF;AACnF,mGAAqH;AAErH,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,2BAA2B,CAAA;AAC/E,IAAO,mBAAmB,GAAG,qEAAiC,CAAC,mBAAmB,CAAA;AAElF,IAAA,gBAAQ,EAAC,4BAA4B,EAAE;;QACrC,MAAM,UAAU,GAAG,IAAI,sCAAmB,CAAC,kBAAgB,CAAC,CAAA;QAC5D,IAAI,MAAc,CAAA;QAClB,IAAI,SAAiB,CAAA;QACrB,IAAI,WAA+B,CAAA;QACnC,IAAI,UAAkB,CAAA;QACtB,IAAI,aAAqB,CAAA;QACzB,IAAI,eAAmC,CAAA;QACvC,IAAI,YAA8B,CAAA;QAClC,IAAI,sBAAkD,CAAA;QACtD,IAAI,2BAAwD,CAAA;QAC5D,IAAI,OAAiC,CAAA;QACrC,IAAI,YAAiC,CAAA;QACrC,IAAI,wBAAkD,CAAA;QACtD,IAAI,SAAoC,CAAA;QAExC,SAAe,oBAAoB,CAAC,YAAqB,EAAE,gBAAyB;;gBAClF,MAAM,GAAG,UAAU,CAAC,UAAU,EAAE,CAAA;gBAChC,WAAW,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,eAAe,CAAC,sBAAU,CAAC,MAAM,CAAC,CAAA;gBACrE,SAAS,GAAG,IAAA,kBAAM,EAAC,MAAM,UAAU,CAAC,GAAG,C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AAU,EACV,CAAC,GAAG,iBAAiB,CAAC,EACtB,CAAC,GAAG,sBAAsB,CAAC,EAC3B,CAAC,GAAG,uBAAuB,CAAC,EAC5B,uBAAuB,CAAC,SAAS,CAClC,CAAA;gBACD,IAAA,aAAM,EAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAA;YAC7C,CAAC;SAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import { describe } from 'mocha'\nimport { WebCryptoPrimitives } from '../../../icc-x-api/crypto/CryptoPrimitives'\nimport { webcrypto } from 'crypto'\nimport { FakeEncryptionKeysManager } from '../../utils/FakeEncryptionKeysManager'\nimport { SecureDelegationsEncryption } from '../../../icc-x-api/crypto/SecureDelegationsEncryption'\nimport { EntityWithDelegationTypeName, hex2ua, ShaVersion, ua2hex } from '../../../icc-x-api'\nimport { SecureDelegationsManager } from '../../../icc-x-api/crypto/SecureDelegationsManager'\nimport { AccessControlSecretUtils } from '../../../icc-x-api/crypto/AccessControlSecretUtils'\nimport { ExchangeDataManager, initialiseExchangeDataManagerForCurrentDataOwner } from '../../../icc-x-api/crypto/ExchangeDataManager'\nimport { BaseExchangeDataManager } from '../../../icc-x-api/crypto/BaseExchangeDataManager'\nimport { FakeExchangeDataApi } from '../../utils/FakeExchangeDataApi'\nimport { FakeDataOwnerApi } from '../../utils/FakeDataOwnerApi'\nimport { TestCryptoStrategies } from '../../utils/TestCryptoStrategies'\nimport { KeyPair } from '../../../icc-x-api/crypto/RSA'\nimport { EntityShareRequest } from '../../../icc-api/model/requests/EntityShareRequest'\nimport { expect } from 'chai'\nimport { EncryptedEntityStub } from '../../../icc-api/model/models'\nimport { SecurityMetadata } from '../../../icc-api/model/SecurityMetadata'\nimport { SecureDelegation } from '../../../icc-api/model/SecureDelegation'\nimport { asyncGeneratorToArray } from '../../../icc-x-api/utils/collection-utils'\nimport { EntitySharedMetadataUpdateRequest } from '../../../icc-api/model/requests/EntitySharedMetadataUpdateRequest'\nimport { fingerprintV1toV2, fingerprintV2 } from '../../../icc-x-api/crypto/utils'\nimport { DataOwnerTypeEnum } from '../../../icc-api/model/DataOwnerTypeEnum'\nimport { FakeExchangeDataMapManager } from '../../utils/FakeExchangeDataMapManager'\nimport { SecurityMetadataDecryptor, SecurityMetadataType } from '../../../icc-x-api/crypto/SecurityMetadataDecryptor'\nimport { BaseExchangeKeysManager } from '../../../icc-x-api/crypto/BaseExchangeKeysManager'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionInternal\nimport EntryUpdateTypeEnum = EntitySharedMetadataUpdateRequest.EntryUpdateTypeEnum\n\ndescribe('Secure delegations manager', async function () {\n const primitives = new WebCryptoPrimitives(webcrypto as any)\n let selfId: string\n let selfKeyFp: string\n let selfKeypair: KeyPair<CryptoKey>\n let delegateId: string\n let delegateKeyFp: string\n let delegateKeypair: KeyPair<CryptoKey>\n let dataOwnerApi: FakeDataOwnerApi\n let exchangeDataMapManager: FakeExchangeDataMapManager\n let secureDelegationsEncryption: SecureDelegationsEncryption\n let manager: SecureDelegationsManager\n let exchangeData: ExchangeDataManager\n let accessControlSecretUtils: AccessControlSecretUtils\n let decryptor: SecurityMetadataDecryptor\n\n async function initialiseComponents(explicitSelf: boolean, explicitDelegate: boolean) {\n selfId = primitives.randomUuid()\n selfKeypair = await primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n selfKeyFp = ua2hex(await primitives.RSA.exportKey(selfKeypair.publicKey, 'spki')).slice(-32)\n delegateId = primitives.randomUuid()\n delegateKeypair = await primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n delegateKeyFp = fingerprintV2(ua2hex(await primitives.RSA.exportKey(delegateKeypair.publicKey, 'spki')))\n dataOwnerApi = new FakeDataOwnerApi(\n {\n id: selfId,\n type: explicitSelf ? DataOwnerTypeEnum.Hcp : DataOwnerTypeEnum.Patient,\n publicKey: ua2hex(await primitives.RSA.exportKey(selfKeypair.publicKey, 'spki')),\n },\n [\n {\n id: delegateId,\n type: explicitDelegate ? DataOwnerTypeEnum.Hcp : DataOwnerTypeEnum.Patient,\n publicKey: ua2hex(await primitives.RSA.exportKey(delegateKeypair.publicKey, 'spki')),\n },\n ]\n )\n const cryptoStrategies = new TestCryptoStrategies()\n const exchangeDataApi = new FakeExchangeDataApi()\n accessControlSecretUtils = new AccessControlSecretUtils(primitives)\n const encryptionKeysManager = await FakeEncryptionKeysManager.create(primitives, [selfKeypair])\n const baseExchangeData = new BaseExchangeDataManager(exchangeDataApi, dataOwnerApi, primitives, !explicitSelf, false)\n exchangeData = await initialiseExchangeDataManagerForCurrentDataOwner(\n baseExchangeData,\n encryptionKeysManager,\n accessControlSecretUtils,\n cryptoStrategies,\n dataOwnerApi,\n primitives,\n true\n )\n exchangeDataMapManager = new FakeExchangeDataMapManager()\n secureDelegationsEncryption = new SecureDelegationsEncryption(encryptionKeysManager, primitives)\n decryptor = new SecurityMetadataDecryptor(\n {\n cache: {},\n get base(): BaseExchangeKeysManager {\n throw 'unused'\n },\n async getDecryptionExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n return Promise.resolve([])\n },\n async reloadCache(): Promise<void> {\n throw 'unused'\n },\n } as any,\n primitives,\n exchangeData,\n exchangeDataMapManager,\n secureDelegationsEncryption,\n dataOwnerApi\n )\n manager = new SecureDelegationsManager(\n exchangeData,\n exchangeDataMapManager,\n secureDelegationsEncryption,\n accessControlSecretUtils,\n encryptionKeysManager,\n primitives,\n dataOwnerApi,\n cryptoStrategies,\n !explicitSelf\n )\n }\n\n it('should make a share request which will create a decryptable secure delegation.', async function () {\n async function doTest(explicitSelf: boolean, explicitDelegate: boolean) {\n await initialiseComponents(explicitSelf, explicitDelegate)\n const secretIds = [ua2hex(primitives.randomBytes(16)), ua2hex(primitives.randomBytes(16))]\n const encryptionKeys = [ua2hex(primitives.randomBytes(16))]\n const owningEntityIds = [ua2hex(primitives.randomBytes(16)), ua2hex(primitives.randomBytes(16)), ua2hex(primitives.randomBytes(16))]\n const entityType = EntityWithDelegationTypeName.Patient\n const shareOrUpdateParams = await manager.makeShareOrUpdateRequestParams(\n { entity: { secretForeignKeys: [] }, type: entityType },\n delegateId,\n secretIds,\n encryptionKeys,\n owningEntityIds,\n EntityShareRequest.RequestedPermissionEnum.MAX_WRITE\n )\n expect(shareOrUpdateParams).to.not.be.undefined\n expect(shareOrUpdateParams!.update).to.be.undefined\n expect(shareOrUpdateParams!.share).to.not.be.undefined\n const shareParams = shareOrUpdateParams!.share!\n expect(shareParams.accessControlKeys).to.have.length(1)\n if (explicitSelf && explicitDelegate) {\n expect(shareParams.exchangeDataId).to.not.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(0)\n } else if (explicitSelf && !explicitDelegate) {\n expect(shareParams.exchangeDataId).to.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(1)\n expect(shareParams.encryptedExchangeDataId![fingerprintV1toV2(selfKeyFp)]).to.not.be.undefined\n } else if (!explicitSelf && explicitDelegate) {\n expect(shareParams.exchangeDataId).to.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(1)\n expect(shareParams.encryptedExchangeDataId![delegateKeyFp]).to.not.be.undefined\n } else {\n expect(shareParams.exchangeDataId).to.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(0)\n }\n const secDelKey = ua2hex(await primitives.sha256(hex2ua(shareParams.accessControlKeys[0])))\n const fakeEntity: { entity: EncryptedEntityStub; type: EntityWithDelegationTypeName } = {\n entity: {\n secretForeignKeys: [],\n securityMetadata: new SecurityMetadata({\n secureDelegations: {\n [secDelKey]: new SecureDelegation({\n delegator: shareParams.explicitDelegator,\n delegate: shareParams.explicitDelegate,\n secretIds: shareParams.secretIds,\n encryptionKeys: shareParams.encryptionKeys,\n owningEntityIds: shareParams.owningEntityIds,\n exchangeDataId: shareParams.exchangeDataId,\n encryptedExchangeDataId: shareParams.encryptedExchangeDataId,\n permissions: SecureDelegation.AccessLevelEnum.WRITE,\n }),\n },\n }),\n },\n type: EntityWithDelegationTypeName.Patient,\n }\n await exchangeDataMapManager.createExchangeDataMaps({ [secDelKey]: shareParams.encryptedExchangeDataId! })\n await exchangeData.clearOrRepopulateCache()\n const decryptedSecretIds = (await decryptor.decryptAll(fakeEntity.entity, [selfId], SecurityMetadataType.SecretId))[0].extracted\n const decryptedEncryptionKeys = (await decryptor.decryptAll(fakeEntity.entity, [selfId], SecurityMetadataType.EncryptionKey))[0].extracted\n const decryptedOwningEntityIds = (await decryptor.decryptAll(fakeEntity.entity, [selfId], SecurityMetadataType.OwningEntityId))[0].extracted\n expect(decryptedSecretIds).to.have.length(secretIds.length)\n for (const secretId of secretIds) {\n expect(decryptedSecretIds).to.include(secretId)\n }\n expect(decryptedEncryptionKeys).to.have.length(encryptionKeys.length)\n for (const encryptionKey of encryptionKeys) {\n expect(decryptedEncryptionKeys).to.include(encryptionKey)\n }\n expect(decryptedOwningEntityIds).to.have.length(owningEntityIds.length)\n for (const owningEntityId of owningEntityIds) {\n expect(decryptedOwningEntityIds).to.include(owningEntityId)\n }\n }\n console.log('Patient->Patient')\n await doTest(false, false)\n console.log('Hcp->Patient')\n await doTest(true, false)\n console.log('Patient->Hcp')\n await doTest(false, true)\n console.log('Hcp->Hcp')\n await doTest(true, true)\n })\n\n it('should make an update request which the missing entries for existing secure delegations.', async function () {\n async function doTest(makeAccessibleFromAlias: boolean) {\n await initialiseComponents(false, false)\n const canonicalSfk = primitives.randomUuid()\n const aliasSfk = primitives.randomUuid()\n const exchangeDataInfo = await exchangeData.getOrCreateEncryptionDataTo(delegateId, false)\n const canonicalKey = await accessControlSecretUtils.secureDelegationKeyFor(\n exchangeDataInfo.accessControlSecret,\n EntityWithDelegationTypeName.Patient\n )\n const aliasKey = await accessControlSecretUtils.secureDelegationKeyFor(\n exchangeDataInfo.accessControlSecret,\n EntityWithDelegationTypeName.Patient\n )\n const existingSecretIds = [ua2hex(primitives.randomBytes(16))]\n const newSecretIds = [ua2hex(primitives.randomBytes(16))]\n const existingEncryptionKeys: string[] = []\n const newEncryptionKeys = [ua2hex(primitives.randomBytes(16))]\n const existingOwningEntityIds = [ua2hex(primitives.randomBytes(16))]\n const newOwningEntityIds: string[] = []\n const fakeEntity: { entity: EncryptedEntityStub; type: EntityWithDelegationTypeName } = {\n entity: {\n secretForeignKeys: makeAccessibleFromAlias ? [aliasSfk] : [canonicalSfk],\n securityMetadata: new SecurityMetadata({\n secureDelegations: {\n [canonicalKey]: new SecureDelegation({\n delegator: selfId,\n delegate: selfId,\n secretIds: await secureDelegationsEncryption.encryptSecretIds(existingSecretIds, exchangeDataInfo.exchangeKey),\n encryptionKeys: await secureDelegationsEncryption.encryptEncryptionKeys(existingEncryptionKeys, exchangeDataInfo.exchangeKey),\n owningEntityIds: await secureDelegationsEncryption.encryptOwningEntityIds(existingOwningEntityIds, exchangeDataInfo.exchangeKey),\n permissions: SecureDelegation.AccessLevelEnum.WRITE,\n }),\n },\n keysEquivalences: { [aliasKey]: canonicalKey },\n }),\n },\n type: EntityWithDelegationTypeName.Patient,\n }\n const shareOrUpdateParams = await manager.makeShareOrUpdateRequestParams(\n fakeEntity,\n delegateId,\n [...existingSecretIds, ...newSecretIds],\n [...existingEncryptionKeys, ...newEncryptionKeys],\n [...existingOwningEntityIds, ...newOwningEntityIds],\n RequestedPermissionEnum.MAX_WRITE\n )\n expect(shareOrUpdateParams).to.not.be.undefined\n expect(shareOrUpdateParams!.share).to.be.undefined\n expect(shareOrUpdateParams!.update).to.not.be.undefined\n const updateParams = shareOrUpdateParams!.update!\n expect(updateParams.metadataAccessControlHash).to.equal(canonicalKey)\n expect(Object.keys(updateParams.secretIds ?? {})).to.have.length(newSecretIds.length)\n for (const [secretId, updateType] of Object.entries(updateParams.secretIds ?? {})) {\n expect(updateType).to.equal(EntryUpdateTypeEnum.CREATE)\n expect(newSecretIds).to.contain(await secureDelegationsEncryption.decryptSecretId(secretId, exchangeDataInfo.exchangeKey))\n }\n expect(Object.keys(updateParams.encryptionKeys ?? {})).to.have.length(newEncryptionKeys.length)\n for (const [encryptionKey, updateType] of Object.entries(updateParams.encryptionKeys ?? {})) {\n expect(updateType).to.equal(EntryUpdateTypeEnum.CREATE)\n expect(newEncryptionKeys).to.contain(await secureDelegationsEncryption.decryptEncryptionKey(encryptionKey, exchangeDataInfo.exchangeKey))\n }\n expect(Object.keys(updateParams.owningEntityIds ?? {})).to.have.length(newOwningEntityIds.length)\n for (const [owningEntityId, updateType] of Object.entries(updateParams.owningEntityIds ?? {})) {\n expect(updateType).to.equal(EntryUpdateTypeEnum.CREATE)\n expect(newOwningEntityIds).to.contain(await secureDelegationsEncryption.decryptOwningEntityId(owningEntityId, exchangeDataInfo.exchangeKey))\n }\n }\n await doTest(true)\n await doTest(false)\n })\n\n it('should return undefined for existing secure delegations if it contains all entries.', async function () {\n await initialiseComponents(false, false)\n const canonicalSfk = primitives.randomUuid()\n const exchangeDataInfo = await exchangeData.getOrCreateEncryptionDataTo(delegateId, false)\n const canonicalKey = await accessControlSecretUtils.secureDelegationKeyFor(\n exchangeDataInfo.accessControlSecret,\n EntityWithDelegationTypeName.Patient\n )\n const existingSecretIds = [ua2hex(primitives.randomBytes(16))]\n const existingEncryptionKeys: string[] = []\n const existingOwningEntityIds = [ua2hex(primitives.randomBytes(16))]\n const fakeEntity: { entity: EncryptedEntityStub; type: EntityWithDelegationTypeName } = {\n entity: {\n secretForeignKeys: [canonicalSfk],\n securityMetadata: new SecurityMetadata({\n secureDelegations: {\n [canonicalKey]: new SecureDelegation({\n delegator: selfId,\n delegate: selfId,\n secretIds: await secureDelegationsEncryption.encryptSecretIds(existingSecretIds, exchangeDataInfo.exchangeKey),\n encryptionKeys: await secureDelegationsEncryption.encryptEncryptionKeys(existingEncryptionKeys, exchangeDataInfo.exchangeKey),\n owningEntityIds: await secureDelegationsEncryption.encryptOwningEntityIds(existingOwningEntityIds, exchangeDataInfo.exchangeKey),\n permissions: SecureDelegation.AccessLevelEnum.WRITE,\n }),\n },\n }),\n },\n type: EntityWithDelegationTypeName.Patient,\n }\n const shareOrUpdateParams = await manager.makeShareOrUpdateRequestParams(\n fakeEntity,\n delegateId,\n [...existingSecretIds],\n [...existingEncryptionKeys],\n [...existingOwningEntityIds],\n RequestedPermissionEnum.MAX_WRITE\n )\n expect(shareOrUpdateParams).to.be.undefined\n })\n})\n"]}
|
|
1
|
+
{"version":3,"file":"secure-delegations-manager-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/secure-delegations-manager-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAgC;AAChC,iFAAgF;AAChF,mCAAkC;AAClC,qFAAiF;AACjF,uGAAmG;AACnG,kDAA6F;AAC7F,iGAA6F;AAC7F,iGAA6F;AAC7F,uFAAqI;AACrI,+FAA2F;AAC3F,yEAAqE;AACrE,mEAA+D;AAC/D,2EAAuE;AAEvE,2FAAuF;AACvF,+BAA6B;AAE7B,8EAA0E;AAC1E,8EAA0E;AAE1E,yHAAqH;AACrH,2DAAkF;AAClF,gFAA4E;AAC5E,uFAAmF;AACnF,mGAAqH;AAErH,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,2BAA2B,CAAA;AAC/E,IAAO,mBAAmB,GAAG,qEAAiC,CAAC,mBAAmB,CAAA;AAElF,IAAA,gBAAQ,EAAC,4BAA4B,EAAE;;QACrC,MAAM,UAAU,GAAG,IAAI,sCAAmB,CAAC,kBAAgB,CAAC,CAAA;QAC5D,IAAI,MAAc,CAAA;QAClB,IAAI,SAAiB,CAAA;QACrB,IAAI,WAA+B,CAAA;QACnC,IAAI,UAAkB,CAAA;QACtB,IAAI,aAAqB,CAAA;QACzB,IAAI,eAAmC,CAAA;QACvC,IAAI,YAA8B,CAAA;QAClC,IAAI,sBAAkD,CAAA;QACtD,IAAI,2BAAwD,CAAA;QAC5D,IAAI,OAAiC,CAAA;QACrC,IAAI,YAAiC,CAAA;QACrC,IAAI,wBAAkD,CAAA;QACtD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uB,EAAE,gBAAgB,CAAC,WAAW,CAAC;oCAChI,WAAW,EAAE,mCAAgB,CAAC,eAAe,CAAC,KAAK;iCACpD,CAAC;6BACH;yBACF,CAAC;qBACH;oBACD,IAAI,EAAE,wCAA4B,CAAC,OAAO;iBAC3C,CAAA;gBACD,MAAM,mBAAmB,GAAG,MAAM,OAAO,CAAC,8BAA8B,CACtE,UAAU,EACV,UAAU,EACV,CAAC,GAAG,iBAAiB,CAAC,EACtB,CAAC,GAAG,sBAAsB,CAAC,EAC3B,CAAC,GAAG,uBAAuB,CAAC,EAC5B,uBAAuB,CAAC,SAAS,CAClC,CAAA;gBACD,IAAA,aAAM,EAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAA;YAC7C,CAAC;SAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import { describe } from 'mocha'\nimport { WebCryptoPrimitives } from '../../../icc-x-api/crypto/CryptoPrimitives'\nimport { webcrypto } from 'crypto'\nimport { FakeEncryptionKeysManager } from '../../utils/FakeEncryptionKeysManager'\nimport { SecureDelegationsEncryption } from '../../../icc-x-api/crypto/SecureDelegationsEncryption'\nimport { EntityWithDelegationTypeName, hex2ua, ShaVersion, ua2hex } from '../../../icc-x-api'\nimport { SecureDelegationsManager } from '../../../icc-x-api/crypto/SecureDelegationsManager'\nimport { AccessControlSecretUtils } from '../../../icc-x-api/crypto/AccessControlSecretUtils'\nimport { ExchangeDataManager, initialiseExchangeDataManagerForCurrentDataOwner } from '../../../icc-x-api/crypto/ExchangeDataManager'\nimport { BaseExchangeDataManager } from '../../../icc-x-api/crypto/BaseExchangeDataManager'\nimport { FakeExchangeDataApi } from '../../utils/FakeExchangeDataApi'\nimport { FakeDataOwnerApi } from '../../utils/FakeDataOwnerApi'\nimport { TestCryptoStrategies } from '../../utils/TestCryptoStrategies'\nimport { KeyPair } from '../../../icc-x-api/crypto/RSA'\nimport { EntityShareRequest } from '../../../icc-api/model/requests/EntityShareRequest'\nimport { expect } from 'chai'\nimport { EncryptedEntityStub } from '../../../icc-api/model/models'\nimport { SecurityMetadata } from '../../../icc-api/model/SecurityMetadata'\nimport { SecureDelegation } from '../../../icc-api/model/SecureDelegation'\nimport { asyncGeneratorToArray } from '../../../icc-x-api/utils/collection-utils'\nimport { EntitySharedMetadataUpdateRequest } from '../../../icc-api/model/requests/EntitySharedMetadataUpdateRequest'\nimport { fingerprintV1toV2, fingerprintV2 } from '../../../icc-x-api/crypto/utils'\nimport { DataOwnerTypeEnum } from '../../../icc-api/model/DataOwnerTypeEnum'\nimport { FakeExchangeDataMapManager } from '../../utils/FakeExchangeDataMapManager'\nimport { SecurityMetadataDecryptor, SecurityMetadataType } from '../../../icc-x-api/crypto/SecurityMetadataDecryptor'\nimport { BaseExchangeKeysManager } from '../../../icc-x-api/crypto/BaseExchangeKeysManager'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionInternal\nimport EntryUpdateTypeEnum = EntitySharedMetadataUpdateRequest.EntryUpdateTypeEnum\n\ndescribe('Secure delegations manager', async function () {\n const primitives = new WebCryptoPrimitives(webcrypto as any)\n let selfId: string\n let selfKeyFp: string\n let selfKeypair: KeyPair<CryptoKey>\n let delegateId: string\n let delegateKeyFp: string\n let delegateKeypair: KeyPair<CryptoKey>\n let dataOwnerApi: FakeDataOwnerApi\n let exchangeDataMapManager: FakeExchangeDataMapManager\n let secureDelegationsEncryption: SecureDelegationsEncryption\n let manager: SecureDelegationsManager\n let exchangeData: ExchangeDataManager\n let accessControlSecretUtils: AccessControlSecretUtils\n let decryptor: SecurityMetadataDecryptor\n\n async function initialiseComponents(explicitSelf: boolean, explicitDelegate: boolean) {\n selfId = primitives.randomUuid()\n selfKeypair = await primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n selfKeyFp = ua2hex(await primitives.RSA.exportKey(selfKeypair.publicKey, 'spki')).slice(-32)\n delegateId = primitives.randomUuid()\n delegateKeypair = await primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n delegateKeyFp = fingerprintV2(ua2hex(await primitives.RSA.exportKey(delegateKeypair.publicKey, 'spki')))\n dataOwnerApi = new FakeDataOwnerApi(\n {\n id: selfId,\n type: explicitSelf ? DataOwnerTypeEnum.Hcp : DataOwnerTypeEnum.Patient,\n publicKey: ua2hex(await primitives.RSA.exportKey(selfKeypair.publicKey, 'spki')),\n },\n [\n {\n id: delegateId,\n type: explicitDelegate ? DataOwnerTypeEnum.Hcp : DataOwnerTypeEnum.Patient,\n publicKey: ua2hex(await primitives.RSA.exportKey(delegateKeypair.publicKey, 'spki')),\n },\n ]\n )\n const cryptoStrategies = new TestCryptoStrategies()\n const exchangeDataApi = new FakeExchangeDataApi()\n accessControlSecretUtils = new AccessControlSecretUtils(primitives)\n const encryptionKeysManager = await FakeEncryptionKeysManager.create(primitives, [selfKeypair])\n const baseExchangeData = new BaseExchangeDataManager(exchangeDataApi, dataOwnerApi, primitives, !explicitSelf, false)\n exchangeData = await initialiseExchangeDataManagerForCurrentDataOwner(\n baseExchangeData,\n encryptionKeysManager,\n accessControlSecretUtils,\n cryptoStrategies,\n dataOwnerApi,\n primitives,\n true\n )\n exchangeDataMapManager = new FakeExchangeDataMapManager()\n secureDelegationsEncryption = new SecureDelegationsEncryption(encryptionKeysManager, primitives)\n decryptor = new SecurityMetadataDecryptor(\n {\n cache: {},\n get base(): BaseExchangeKeysManager {\n throw 'unused'\n },\n async getDecryptionExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n return Promise.resolve([])\n },\n async reloadCache(): Promise<void> {\n throw 'unused'\n },\n } as any,\n primitives,\n exchangeData,\n exchangeDataMapManager,\n secureDelegationsEncryption,\n dataOwnerApi\n )\n manager = new SecureDelegationsManager(\n exchangeData,\n exchangeDataMapManager,\n secureDelegationsEncryption,\n accessControlSecretUtils,\n encryptionKeysManager,\n primitives,\n dataOwnerApi,\n cryptoStrategies,\n !explicitSelf\n )\n }\n\n it('should make a share request which will create a decryptable secure delegation.', async function () {\n async function doTest(explicitSelf: boolean, explicitDelegate: boolean) {\n await initialiseComponents(explicitSelf, explicitDelegate)\n const secretIds = [ua2hex(primitives.randomBytes(16)), ua2hex(primitives.randomBytes(16))]\n const encryptionKeys = [ua2hex(primitives.randomBytes(16))]\n const owningEntityIds = [ua2hex(primitives.randomBytes(16)), ua2hex(primitives.randomBytes(16)), ua2hex(primitives.randomBytes(16))]\n const entityType = EntityWithDelegationTypeName.Patient\n const shareOrUpdateParams = await manager.makeShareOrUpdateRequestParams(\n { entity: { secretForeignKeys: [] }, type: entityType },\n delegateId,\n secretIds,\n encryptionKeys,\n owningEntityIds,\n EntityShareRequest.RequestedPermissionEnum.MAX_WRITE\n )\n expect(shareOrUpdateParams).to.not.be.undefined\n expect(shareOrUpdateParams!.update).to.be.undefined\n expect(shareOrUpdateParams!.share).to.not.be.undefined\n const shareParams = shareOrUpdateParams!.share!\n expect(shareParams.accessControlKeys).to.have.length(1)\n if (explicitSelf && explicitDelegate) {\n expect(shareParams.exchangeDataId).to.not.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(0)\n } else if (explicitSelf && !explicitDelegate) {\n expect(shareParams.exchangeDataId).to.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(1)\n expect(shareParams.encryptedExchangeDataId![fingerprintV1toV2(selfKeyFp)]).to.not.be.undefined\n } else if (!explicitSelf && explicitDelegate) {\n expect(shareParams.exchangeDataId).to.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(1)\n expect(shareParams.encryptedExchangeDataId![delegateKeyFp]).to.not.be.undefined\n } else {\n expect(shareParams.exchangeDataId).to.be.undefined\n expect(Object.entries(shareParams.encryptedExchangeDataId ?? {})).to.have.length(0)\n }\n const secDelKey = ua2hex(await primitives.sha256(hex2ua(shareParams.accessControlKeys[0])))\n const fakeEntity: { entity: EncryptedEntityStub; type: EntityWithDelegationTypeName } = {\n entity: {\n secretForeignKeys: [],\n securityMetadata: new SecurityMetadata({\n secureDelegations: {\n [secDelKey]: new SecureDelegation({\n delegator: shareParams.explicitDelegator,\n delegate: shareParams.explicitDelegate,\n secretIds: shareParams.secretIds,\n encryptionKeys: shareParams.encryptionKeys,\n owningEntityIds: shareParams.owningEntityIds,\n exchangeDataId: shareParams.exchangeDataId,\n encryptedExchangeDataId: shareParams.encryptedExchangeDataId,\n permissions: SecureDelegation.AccessLevelEnum.WRITE,\n }),\n },\n }),\n },\n type: EntityWithDelegationTypeName.Patient,\n }\n await exchangeDataMapManager.createExchangeDataMaps({ [secDelKey]: shareParams.encryptedExchangeDataId! })\n await exchangeData.clearOrRepopulateCache()\n const decryptedSecretIds = (await decryptor.decryptAll(fakeEntity.entity, [selfId], SecurityMetadataType.SecretId))[0].extracted\n const decryptedEncryptionKeys = (await decryptor.decryptAll(fakeEntity.entity, [selfId], SecurityMetadataType.EncryptionKey))[0].extracted\n const decryptedOwningEntityIds = (await decryptor.decryptAll(fakeEntity.entity, [selfId], SecurityMetadataType.OwningEntityId))[0].extracted\n expect(decryptedSecretIds).to.have.length(secretIds.length)\n for (const secretId of secretIds) {\n expect(decryptedSecretIds).to.include(secretId)\n }\n expect(decryptedEncryptionKeys).to.have.length(encryptionKeys.length)\n for (const encryptionKey of encryptionKeys) {\n expect(decryptedEncryptionKeys).to.include(encryptionKey)\n }\n expect(decryptedOwningEntityIds).to.have.length(owningEntityIds.length)\n for (const owningEntityId of owningEntityIds) {\n expect(decryptedOwningEntityIds).to.include(owningEntityId)\n }\n }\n console.log('Patient->Patient')\n await doTest(false, false)\n console.log('Hcp->Patient')\n await doTest(true, false)\n console.log('Patient->Hcp')\n await doTest(false, true)\n console.log('Hcp->Hcp')\n await doTest(true, true)\n })\n\n it('should make an update request which the missing entries for existing secure delegations.', async function () {\n async function doTest(makeAccessibleFromAlias: boolean) {\n await initialiseComponents(false, false)\n const canonicalSfk = primitives.randomUuid()\n const aliasSfk = primitives.randomUuid()\n const exchangeDataInfo = await exchangeData.getOrCreateEncryptionDataTo(delegateId)\n const canonicalKey = await accessControlSecretUtils.secureDelegationKeyFor(\n exchangeDataInfo.accessControlSecret,\n EntityWithDelegationTypeName.Patient\n )\n const aliasKey = await accessControlSecretUtils.secureDelegationKeyFor(\n exchangeDataInfo.accessControlSecret,\n EntityWithDelegationTypeName.Patient\n )\n const existingSecretIds = [ua2hex(primitives.randomBytes(16))]\n const newSecretIds = [ua2hex(primitives.randomBytes(16))]\n const existingEncryptionKeys: string[] = []\n const newEncryptionKeys = [ua2hex(primitives.randomBytes(16))]\n const existingOwningEntityIds = [ua2hex(primitives.randomBytes(16))]\n const newOwningEntityIds: string[] = []\n const fakeEntity: { entity: EncryptedEntityStub; type: EntityWithDelegationTypeName } = {\n entity: {\n secretForeignKeys: makeAccessibleFromAlias ? [aliasSfk] : [canonicalSfk],\n securityMetadata: new SecurityMetadata({\n secureDelegations: {\n [canonicalKey]: new SecureDelegation({\n delegator: selfId,\n delegate: selfId,\n secretIds: await secureDelegationsEncryption.encryptSecretIds(existingSecretIds, exchangeDataInfo.exchangeKey),\n encryptionKeys: await secureDelegationsEncryption.encryptEncryptionKeys(existingEncryptionKeys, exchangeDataInfo.exchangeKey),\n owningEntityIds: await secureDelegationsEncryption.encryptOwningEntityIds(existingOwningEntityIds, exchangeDataInfo.exchangeKey),\n permissions: SecureDelegation.AccessLevelEnum.WRITE,\n }),\n },\n keysEquivalences: { [aliasKey]: canonicalKey },\n }),\n },\n type: EntityWithDelegationTypeName.Patient,\n }\n const shareOrUpdateParams = await manager.makeShareOrUpdateRequestParams(\n fakeEntity,\n delegateId,\n [...existingSecretIds, ...newSecretIds],\n [...existingEncryptionKeys, ...newEncryptionKeys],\n [...existingOwningEntityIds, ...newOwningEntityIds],\n RequestedPermissionEnum.MAX_WRITE\n )\n expect(shareOrUpdateParams).to.not.be.undefined\n expect(shareOrUpdateParams!.share).to.be.undefined\n expect(shareOrUpdateParams!.update).to.not.be.undefined\n const updateParams = shareOrUpdateParams!.update!\n expect(updateParams.metadataAccessControlHash).to.equal(canonicalKey)\n expect(Object.keys(updateParams.secretIds ?? {})).to.have.length(newSecretIds.length)\n for (const [secretId, updateType] of Object.entries(updateParams.secretIds ?? {})) {\n expect(updateType).to.equal(EntryUpdateTypeEnum.CREATE)\n expect(newSecretIds).to.contain(await secureDelegationsEncryption.decryptSecretId(secretId, exchangeDataInfo.exchangeKey))\n }\n expect(Object.keys(updateParams.encryptionKeys ?? {})).to.have.length(newEncryptionKeys.length)\n for (const [encryptionKey, updateType] of Object.entries(updateParams.encryptionKeys ?? {})) {\n expect(updateType).to.equal(EntryUpdateTypeEnum.CREATE)\n expect(newEncryptionKeys).to.contain(await secureDelegationsEncryption.decryptEncryptionKey(encryptionKey, exchangeDataInfo.exchangeKey))\n }\n expect(Object.keys(updateParams.owningEntityIds ?? {})).to.have.length(newOwningEntityIds.length)\n for (const [owningEntityId, updateType] of Object.entries(updateParams.owningEntityIds ?? {})) {\n expect(updateType).to.equal(EntryUpdateTypeEnum.CREATE)\n expect(newOwningEntityIds).to.contain(await secureDelegationsEncryption.decryptOwningEntityId(owningEntityId, exchangeDataInfo.exchangeKey))\n }\n }\n await doTest(true)\n await doTest(false)\n })\n\n it('should return undefined for existing secure delegations if it contains all entries.', async function () {\n await initialiseComponents(false, false)\n const canonicalSfk = primitives.randomUuid()\n const exchangeDataInfo = await exchangeData.getOrCreateEncryptionDataTo(delegateId)\n const canonicalKey = await accessControlSecretUtils.secureDelegationKeyFor(\n exchangeDataInfo.accessControlSecret,\n EntityWithDelegationTypeName.Patient\n )\n const existingSecretIds = [ua2hex(primitives.randomBytes(16))]\n const existingEncryptionKeys: string[] = []\n const existingOwningEntityIds = [ua2hex(primitives.randomBytes(16))]\n const fakeEntity: { entity: EncryptedEntityStub; type: EntityWithDelegationTypeName } = {\n entity: {\n secretForeignKeys: [canonicalSfk],\n securityMetadata: new SecurityMetadata({\n secureDelegations: {\n [canonicalKey]: new SecureDelegation({\n delegator: selfId,\n delegate: selfId,\n secretIds: await secureDelegationsEncryption.encryptSecretIds(existingSecretIds, exchangeDataInfo.exchangeKey),\n encryptionKeys: await secureDelegationsEncryption.encryptEncryptionKeys(existingEncryptionKeys, exchangeDataInfo.exchangeKey),\n owningEntityIds: await secureDelegationsEncryption.encryptOwningEntityIds(existingOwningEntityIds, exchangeDataInfo.exchangeKey),\n permissions: SecureDelegation.AccessLevelEnum.WRITE,\n }),\n },\n }),\n },\n type: EntityWithDelegationTypeName.Patient,\n }\n const shareOrUpdateParams = await manager.makeShareOrUpdateRequestParams(\n fakeEntity,\n delegateId,\n [...existingSecretIds],\n [...existingEncryptionKeys],\n [...existingOwningEntityIds],\n RequestedPermissionEnum.MAX_WRITE\n )\n expect(shareOrUpdateParams).to.be.undefined\n })\n})\n"]}
|
|
@@ -29,20 +29,8 @@ describe('icc-hcparty-x-api Tests', () => {
|
|
|
29
29
|
// Given
|
|
30
30
|
const { userApi: userApi, healthcarePartyApi: hcpApi } = yield initApi(env, test_utils_1.hcp1Username);
|
|
31
31
|
const user = yield userApi.getCurrentUser();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
yield hcpApi.getHealthcareParties({ ids: [user.id, user.healthcarePartyId] });
|
|
35
|
-
promiseResolves = true;
|
|
36
|
-
}
|
|
37
|
-
catch (_a) {
|
|
38
|
-
promiseResolves = false;
|
|
39
|
-
}
|
|
40
|
-
yield hcpApi.getHealthcareParties({ ids: [user.id, user.healthcarePartyId] }).then((_) => {
|
|
41
|
-
throw new Error('This promise should not resolve');
|
|
42
|
-
}, (e) => {
|
|
43
|
-
(0, chai_1.expect)(JSON.parse(e.message)['message']).to.be.equal(`Object with ID ${user.id} is not of expected type org.taktik.icure.entities.HealthcareParty but of type org.taktik.icure.entities.User`);
|
|
44
|
-
});
|
|
45
|
-
(0, chai_1.expect)(promiseResolves).to.be.false;
|
|
32
|
+
const retrievedBoth = yield hcpApi.getHealthcareParties({ ids: [user.id, user.healthcarePartyId] });
|
|
33
|
+
(0, chai_1.expect)(retrievedBoth.map((x) => x.id)).to.have.members([user.healthcarePartyId]);
|
|
46
34
|
const hcp = yield hcpApi.getHealthcareParty(user.healthcarePartyId);
|
|
47
35
|
(0, chai_1.expect)(hcp.id).to.be.equal(user.healthcarePartyId);
|
|
48
36
|
yield hcpApi.getHealthcareParty(user.id).then((_) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-hcparty-x-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-hcparty-x-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AAEzB,iCAA8B;AAC9B,oDAAyG;AACzG,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,+BAA6B;AAC7B,mDAAmE;
|
|
1
|
+
{"version":3,"file":"icc-hcparty-x-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-hcparty-x-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AAEzB,iCAA8B;AAC9B,oDAAyG;AACzG,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,+BAA6B;AAC7B,mDAAmE;AAGnE,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AAEjB,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,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,2CAA2C,EAAE,GAAS,EAAE;QACzD,QAAQ;QACR,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,yBAAY,CAAC,CAAA;QAEzF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAA;QAE3C,MAAM,aAAa,GAAsB,MAAM,MAAM,CAAC,oBAAoB,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,EAAG,EAAE,IAAI,CAAC,iBAAkB,CAAC,EAAE,CAAC,CAAA;QACxH,IAAA,aAAM,EAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAEhF,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,iBAAkB,CAAC,CAAA;QACpE,IAAA,aAAM,EAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAkB,CAAC,CAAA;QAEnD,MAAM,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAG,CAAC,CAAC,IAAI,CAC5C,CAAC,CAAC,EAAE,EAAE;YACJ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,IAAA,aAAM,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAClD,kBAAkB,IAAI,CAAC,EAAG,+GAA+G,CAC1I,CAAA;QACH,CAAC,CACF,CAAA;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\n\nimport { before } from 'mocha'\nimport { getEnvironmentInitializer, hcp1Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport initApi = TestUtils.initApi\nimport { expect } from 'chai'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { HealthcareParty } from '../../icc-api/model/HealthcareParty'\n\nsetLocalStorage(fetch)\nlet env: TestVars\n\ndescribe('icc-hcparty-x-api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('Does not cache entities that are not HCPs', async () => {\n // Given\n const { userApi: userApi, healthcarePartyApi: hcpApi } = await initApi(env, hcp1Username)\n\n const user = await userApi.getCurrentUser()\n\n const retrievedBoth: HealthcareParty[] = await hcpApi.getHealthcareParties({ ids: [user.id!, user.healthcarePartyId!] })\n expect(retrievedBoth.map((x) => x.id)).to.have.members([user.healthcarePartyId])\n\n const hcp = await hcpApi.getHealthcareParty(user.healthcarePartyId!)\n expect(hcp.id).to.be.equal(user.healthcarePartyId!)\n\n await hcpApi.getHealthcareParty(user.id!).then(\n (_) => {\n throw new Error('This promise should not resolve')\n },\n (e) => {\n expect(JSON.parse(e.message)['message']).to.be.equal(\n `Object with ID ${user.id!} is not of expected type org.taktik.icure.entities.HealthcareParty but of type org.taktik.icure.entities.User`\n )\n }\n )\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
require("isomorphic-fetch");
|
|
13
|
+
const mocha_1 = require("mocha");
|
|
14
|
+
const test_utils_1 = require("../utils/test_utils");
|
|
15
|
+
const icc_x_api_1 = require("../../icc-x-api");
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
17
|
+
const chai_1 = require("chai");
|
|
18
|
+
const types_1 = require("@icure/test-setup/types");
|
|
19
|
+
const TestStorage_1 = require("../utils/TestStorage");
|
|
20
|
+
const TestCryptoStrategies_1 = require("../utils/TestCryptoStrategies");
|
|
21
|
+
const KeylessCryptoStrategies_1 = require("../utils/KeylessCryptoStrategies");
|
|
22
|
+
(0, test_utils_1.setLocalStorage)(fetch);
|
|
23
|
+
let env;
|
|
24
|
+
describe('Keyless api Tests', () => {
|
|
25
|
+
(0, mocha_1.before)(function () {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
this.timeout(600000);
|
|
28
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
29
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
const calendarItemTitle = 'Encrypted title';
|
|
33
|
+
function initializeTestData() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const { api: patientApi, credentials: patientCredentials } = yield (0, test_utils_1.createNewKeylessApi)(env);
|
|
36
|
+
const patientUser = yield patientApi.userApi.getCurrentUser();
|
|
37
|
+
const patient = (yield patientApi.dataOwnerApi.getCurrentDataOwner()).dataOwner;
|
|
38
|
+
const { api: hcpApi, credentials: hcpDetails, user: hcpUser } = yield (0, test_utils_1.createNewHcpApi)(env);
|
|
39
|
+
const exchangeData = yield patientApi.cryptoApi.keylessCreateExchangeDataTo(hcpDetails.dataOwnerId);
|
|
40
|
+
const createdCalendarItem = yield patientApi.calendarItemApi.createCalendarItemWithHcParty(patientUser, yield patientApi.calendarItemApi.newInstancePatient(patientUser, patient, { title: calendarItemTitle }, {
|
|
41
|
+
sfkOption: icc_x_api_1.SecretIdUseOption.UseNone,
|
|
42
|
+
alternateRootDelegation: hcpDetails.dataOwnerId,
|
|
43
|
+
}));
|
|
44
|
+
(0, chai_1.expect)(createdCalendarItem.title).to.equal(calendarItemTitle);
|
|
45
|
+
return {
|
|
46
|
+
patientApi,
|
|
47
|
+
patientCredentials,
|
|
48
|
+
patientUser,
|
|
49
|
+
patient,
|
|
50
|
+
hcpApi,
|
|
51
|
+
hcpDetails,
|
|
52
|
+
hcpUser,
|
|
53
|
+
exchangeData,
|
|
54
|
+
createdCalendarItem,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
it('Keyless api should allow creation of data and retrieval by delegator and delegate', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const { patientApi, patientUser, patient, hcpApi, hcpUser, createdCalendarItem } = yield initializeTestData();
|
|
60
|
+
const retrievedByPatient = yield patientApi.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id);
|
|
61
|
+
(0, chai_1.expect)(retrievedByPatient.title).to.equal(calendarItemTitle);
|
|
62
|
+
(0, chai_1.expect)(yield patientApi.calendarItemApi.decryptPatientIdOf(retrievedByPatient)).to.have.members([patient.id]);
|
|
63
|
+
const retrievedByHcp = yield hcpApi.calendarItemApi.getCalendarItemWithUser(hcpUser, createdCalendarItem.id);
|
|
64
|
+
(0, chai_1.expect)(retrievedByHcp.title).to.equal(calendarItemTitle);
|
|
65
|
+
(0, chai_1.expect)(yield hcpApi.calendarItemApi.decryptPatientIdOf(retrievedByHcp)).to.have.members([patient.id]);
|
|
66
|
+
}));
|
|
67
|
+
it('Keyless api should allow retrieval in new instance after exchange data injection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const { patientCredentials, patientUser, patient, exchangeData, createdCalendarItem } = yield initializeTestData();
|
|
69
|
+
const newPatientApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, patientCredentials, new KeylessCryptoStrategies_1.KeylessCryptoStrategies(), crypto_1.webcrypto, fetch, {});
|
|
70
|
+
yield newPatientApi.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id).then(() => {
|
|
71
|
+
throw new Error('Get before injection for anonymous user should not work');
|
|
72
|
+
}, () => {
|
|
73
|
+
/* ok, expected */
|
|
74
|
+
});
|
|
75
|
+
yield newPatientApi.cryptoApi.injectExchangeData([Object.assign(Object.assign({}, exchangeData), { verified: false })], false);
|
|
76
|
+
const retrievedByNewApi = yield newPatientApi.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id);
|
|
77
|
+
(0, chai_1.expect)(retrievedByNewApi.title).to.equal(calendarItemTitle);
|
|
78
|
+
(0, chai_1.expect)(yield newPatientApi.calendarItemApi.decryptPatientIdOf(retrievedByNewApi)).to.have.members([patient.id]);
|
|
79
|
+
}));
|
|
80
|
+
it('Should allow re-encryption of exchange data as unverified on injection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const { patientApi, patientCredentials, patientUser, patient, hcpDetails, exchangeData, createdCalendarItem } = yield initializeTestData();
|
|
82
|
+
const keyStorage = new TestStorage_1.TestKeyStorage();
|
|
83
|
+
const newKey = yield patientApi.cryptoApi.primitives.RSA.generateKeyPair(icc_x_api_1.ShaVersion.Sha256);
|
|
84
|
+
const newPatientApiWithKeyAndInjected = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, patientCredentials, new TestCryptoStrategies_1.TestCryptoStrategies(newKey), crypto_1.webcrypto, fetch, {
|
|
85
|
+
keyStorage,
|
|
86
|
+
injectExchangeData: {
|
|
87
|
+
details: [Object.assign(Object.assign({}, exchangeData), { verified: false })],
|
|
88
|
+
reEncryptWithOwnKeys: true,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
(0, chai_1.expect)((yield newPatientApiWithKeyAndInjected.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==
|
|
92
|
+
exchangeData.exchangeDataId).to.be.false;
|
|
93
|
+
const newPatientApiWithKey = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, patientCredentials, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
94
|
+
keyStorage,
|
|
95
|
+
});
|
|
96
|
+
const retrievedByNewApi = yield newPatientApiWithKey.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id);
|
|
97
|
+
(0, chai_1.expect)(retrievedByNewApi.title).to.equal(calendarItemTitle);
|
|
98
|
+
(0, chai_1.expect)(yield newPatientApiWithKey.calendarItemApi.decryptPatientIdOf(retrievedByNewApi)).to.have.members([patient.id]);
|
|
99
|
+
(0, chai_1.expect)((yield newPatientApiWithKey.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==
|
|
100
|
+
exchangeData.exchangeDataId).to.be.false;
|
|
101
|
+
}));
|
|
102
|
+
it('Should allow re-encryption of exchange data as verified on injection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
const { patientApi, patientCredentials, patientUser, patient, hcpDetails, exchangeData, createdCalendarItem } = yield initializeTestData();
|
|
104
|
+
const keyStorage = new TestStorage_1.TestKeyStorage();
|
|
105
|
+
const newKey = yield patientApi.cryptoApi.primitives.RSA.generateKeyPair(icc_x_api_1.ShaVersion.Sha256);
|
|
106
|
+
const newPatientApiWithKeyAndInjected = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, patientCredentials, new TestCryptoStrategies_1.TestCryptoStrategies(newKey), crypto_1.webcrypto, fetch, {
|
|
107
|
+
keyStorage,
|
|
108
|
+
injectExchangeData: {
|
|
109
|
+
details: [Object.assign(Object.assign({}, exchangeData), { verified: true })],
|
|
110
|
+
reEncryptWithOwnKeys: true,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
(0, chai_1.expect)((yield newPatientApiWithKeyAndInjected.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==
|
|
114
|
+
exchangeData.exchangeDataId).to.be.true;
|
|
115
|
+
const newPatientApiWithKey = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, patientCredentials, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
116
|
+
keyStorage,
|
|
117
|
+
});
|
|
118
|
+
(0, chai_1.expect)((yield newPatientApiWithKey.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==
|
|
119
|
+
exchangeData.exchangeDataId).to.be.true;
|
|
120
|
+
const retrievedByNewApi = yield newPatientApiWithKey.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id);
|
|
121
|
+
(0, chai_1.expect)(retrievedByNewApi.title).to.equal(calendarItemTitle);
|
|
122
|
+
(0, chai_1.expect)(yield newPatientApiWithKey.calendarItemApi.decryptPatientIdOf(retrievedByNewApi)).to.have.members([patient.id]);
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=keyless-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyless-api.js","sourceRoot":"","sources":["../../../test/icc-x-api/keyless-api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AAEzB,iCAA8B;AAC9B,oDAAiI;AACjI,+CAAyE;AACzE,mCAAkC;AAClC,+BAA6B;AAC7B,mDAAmE;AAGnE,sDAAqD;AACrD,wEAAoE;AACpE,8EAA0E;AAE1E,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AAEjB,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAA,cAAM,EAAC;;YACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,G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AAC,SAAS,CAAC,YAAY,CAAC,2BAA2B,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE;YACrH,YAAY,CAAC,cAAc,CAC9B,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;QACZ,MAAM,iBAAiB,GAAiB,MAAM,oBAAoB,CAAC,eAAe,CAAC,uBAAuB,CAAC,WAAW,EAAE,mBAAmB,CAAC,EAAE,CAAC,CAAA;QAC/I,IAAA,aAAM,EAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;QAC3D,IAAA,aAAM,EAAC,MAAM,oBAAoB,CAAC,eAAe,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IACxH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\n\nimport { before } from 'mocha'\nimport { createNewHcpApi, createNewKeylessApi, getEnvironmentInitializer, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { IcureApi, SecretIdUseOption, ShaVersion } from '../../icc-x-api'\nimport { webcrypto } from 'crypto'\nimport { expect } from 'chai'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { Patient } from '../../icc-api/model/Patient'\nimport { CalendarItem } from '../../icc-api/model/CalendarItem'\nimport { TestKeyStorage } from '../utils/TestStorage'\nimport { TestCryptoStrategies } from '../utils/TestCryptoStrategies'\nimport { KeylessCryptoStrategies } from '../utils/KeylessCryptoStrategies'\n\nsetLocalStorage(fetch)\nlet env: TestVars\n\ndescribe('Keyless api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n const calendarItemTitle = 'Encrypted title'\n\n async function initializeTestData() {\n const { api: patientApi, credentials: patientCredentials } = await createNewKeylessApi(env)\n const patientUser = await patientApi.userApi.getCurrentUser()\n const patient = (await patientApi.dataOwnerApi.getCurrentDataOwner()).dataOwner as Patient\n const { api: hcpApi, credentials: hcpDetails, user: hcpUser } = await createNewHcpApi(env)\n const exchangeData = await patientApi.cryptoApi.keylessCreateExchangeDataTo(hcpDetails.dataOwnerId)\n const createdCalendarItem = await patientApi.calendarItemApi.createCalendarItemWithHcParty(\n patientUser,\n await patientApi.calendarItemApi.newInstancePatient(\n patientUser,\n patient,\n { title: calendarItemTitle },\n {\n sfkOption: SecretIdUseOption.UseNone,\n alternateRootDelegation: hcpDetails.dataOwnerId,\n }\n )\n )\n expect(createdCalendarItem.title).to.equal(calendarItemTitle)\n return {\n patientApi,\n patientCredentials,\n patientUser,\n patient,\n hcpApi,\n hcpDetails,\n hcpUser,\n exchangeData,\n createdCalendarItem,\n }\n }\n\n it('Keyless api should allow creation of data and retrieval by delegator and delegate', async () => {\n const { patientApi, patientUser, patient, hcpApi, hcpUser, createdCalendarItem } = await initializeTestData()\n\n const retrievedByPatient: CalendarItem = await patientApi.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id)\n expect(retrievedByPatient.title).to.equal(calendarItemTitle)\n expect(await patientApi.calendarItemApi.decryptPatientIdOf(retrievedByPatient)).to.have.members([patient.id])\n const retrievedByHcp: CalendarItem = await hcpApi.calendarItemApi.getCalendarItemWithUser(hcpUser, createdCalendarItem.id)\n expect(retrievedByHcp.title).to.equal(calendarItemTitle)\n expect(await hcpApi.calendarItemApi.decryptPatientIdOf(retrievedByHcp)).to.have.members([patient.id])\n })\n\n it('Keyless api should allow retrieval in new instance after exchange data injection', async () => {\n const { patientCredentials, patientUser, patient, exchangeData, createdCalendarItem } = await initializeTestData()\n\n const newPatientApi = await IcureApi.initialise(env.iCureUrl, patientCredentials, new KeylessCryptoStrategies(), webcrypto as any, fetch, {})\n await newPatientApi.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id).then(\n () => {\n throw new Error('Get before injection for anonymous user should not work')\n },\n () => {\n /* ok, expected */\n }\n )\n await newPatientApi.cryptoApi.injectExchangeData([{ ...exchangeData, verified: false }], false)\n const retrievedByNewApi: CalendarItem = await newPatientApi.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id)\n expect(retrievedByNewApi.title).to.equal(calendarItemTitle)\n expect(await newPatientApi.calendarItemApi.decryptPatientIdOf(retrievedByNewApi)).to.have.members([patient.id])\n })\n\n it('Should allow re-encryption of exchange data as unverified on injection', async () => {\n const { patientApi, patientCredentials, patientUser, patient, hcpDetails, exchangeData, createdCalendarItem } = await initializeTestData()\n\n const keyStorage = new TestKeyStorage()\n const newKey = await patientApi.cryptoApi.primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const newPatientApiWithKeyAndInjected = await IcureApi.initialise(\n env.iCureUrl,\n patientCredentials,\n new TestCryptoStrategies(newKey),\n webcrypto as any,\n fetch,\n {\n keyStorage,\n injectExchangeData: {\n details: [{ ...exchangeData, verified: false }],\n reEncryptWithOwnKeys: true,\n },\n }\n )\n expect(\n (await newPatientApiWithKeyAndInjected.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==\n exchangeData.exchangeDataId\n ).to.be.false\n const newPatientApiWithKey = await IcureApi.initialise(env.iCureUrl, patientCredentials, new TestCryptoStrategies(), webcrypto as any, fetch, {\n keyStorage,\n })\n const retrievedByNewApi: CalendarItem = await newPatientApiWithKey.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id)\n expect(retrievedByNewApi.title).to.equal(calendarItemTitle)\n expect(await newPatientApiWithKey.calendarItemApi.decryptPatientIdOf(retrievedByNewApi)).to.have.members([patient.id])\n expect(\n (await newPatientApiWithKey.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==\n exchangeData.exchangeDataId\n ).to.be.false\n })\n\n it('Should allow re-encryption of exchange data as verified on injection', async () => {\n const { patientApi, patientCredentials, patientUser, patient, hcpDetails, exchangeData, createdCalendarItem } = await initializeTestData()\n\n const keyStorage = new TestKeyStorage()\n const newKey = await patientApi.cryptoApi.primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const newPatientApiWithKeyAndInjected = await IcureApi.initialise(\n env.iCureUrl,\n patientCredentials,\n new TestCryptoStrategies(newKey),\n webcrypto as any,\n fetch,\n {\n keyStorage,\n injectExchangeData: {\n details: [{ ...exchangeData, verified: true }],\n reEncryptWithOwnKeys: true,\n },\n }\n )\n expect(\n (await newPatientApiWithKeyAndInjected.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==\n exchangeData.exchangeDataId\n ).to.be.true\n const newPatientApiWithKey = await IcureApi.initialise(env.iCureUrl, patientCredentials, new TestCryptoStrategies(), webcrypto as any, fetch, {\n keyStorage,\n })\n expect(\n (await newPatientApiWithKey.cryptoApi.exchangeData.getOrCreateEncryptionDataTo(hcpDetails.dataOwnerId)).exchangeData.id ==\n exchangeData.exchangeDataId\n ).to.be.true\n const retrievedByNewApi: CalendarItem = await newPatientApiWithKey.calendarItemApi.getCalendarItemWithUser(patientUser, createdCalendarItem.id)\n expect(retrievedByNewApi.title).to.equal(calendarItemTitle)\n expect(await newPatientApiWithKey.calendarItemApi.decryptPatientIdOf(retrievedByNewApi)).to.have.members([patient.id])\n })\n})\n"]}
|
|
@@ -17,7 +17,7 @@ const _ = require("lodash");
|
|
|
17
17
|
const utils_1 = require("../../icc-x-api/crypto/utils");
|
|
18
18
|
class FakeEncryptionKeysManager extends UserEncryptionKeysManager_1.UserEncryptionKeysManager {
|
|
19
19
|
constructor(keys) {
|
|
20
|
-
super(null, null, null, null, null, null, null);
|
|
20
|
+
super(null, null, null, null, null, null, null, null);
|
|
21
21
|
this.keys = keys;
|
|
22
22
|
}
|
|
23
23
|
static create(primitives, verifiedKeys, unverifiedKeys = []) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeEncryptionKeysManager.js","sourceRoot":"","sources":["../../../test/utils/FakeEncryptionKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gGAA4F;AAE5F,oDAAgE;AAEhE,+CAAwC;AACxC,4BAA2B;AAC3B,wDAA4D;AAE5D,MAAa,yBAA0B,SAAQ,qDAAyB;IACtE,YAA6B,IAAgF;QAC3G,KAAK,CAAC,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"FakeEncryptionKeysManager.js","sourceRoot":"","sources":["../../../test/utils/FakeEncryptionKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gGAA4F;AAE5F,oDAAgE;AAEhE,+CAAwC;AACxC,4BAA2B;AAC3B,wDAA4D;AAE5D,MAAa,yBAA0B,SAAQ,qDAAyB;IACtE,YAA6B,IAAgF;QAC3G,KAAK,CAAC,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,EAAE,IAAW,CAAC,CAAA;QADlF,SAAI,GAAJ,IAAI,CAA4E;IAE7G,CAAC;IAED,MAAM,CAAO,MAAM,CACjB,UAA4B,EAC5B,YAAkC,EAClC,iBAAuC,EAAE;;YAEzC,MAAM,iBAAiB,GAAG,EAAgF,CAAA;YAC1G,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE;gBAC9B,MAAM,WAAW,GAAG,IAAA,qBAAa,EAAC,IAAA,kBAAM,EAAC,MAAM,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;gBAChG,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;aAC/D;YACD,KAAK,MAAM,GAAG,IA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AI,EAAE,CAAA;QACxD,CAAC;KAAA;CACF;AA3ED,8DA2EC","sourcesContent":["import { UserEncryptionKeysManager } from '../../icc-x-api/crypto/UserEncryptionKeysManager'\nimport { DataOwner } from '../../icc-x-api/icc-data-owner-x-api'\nimport { KeyPair, ShaVersion } from '../../icc-x-api/crypto/RSA'\nimport { CryptoPrimitives } from '../../icc-x-api/crypto/CryptoPrimitives'\nimport { ua2hex } from '../../icc-x-api'\nimport * as _ from 'lodash'\nimport { fingerprintV1 } from '../../icc-x-api/crypto/utils'\n\nexport class FakeEncryptionKeysManager extends UserEncryptionKeysManager {\n constructor(private readonly keys: { [fingerprint: string]: { pair: KeyPair<CryptoKey>; verified: boolean } }) {\n super(null as any, null as any, null as any, null as any, null as any, null as any, null as any, null as any)\n }\n\n static async create(\n primitives: CryptoPrimitives,\n verifiedKeys: KeyPair<CryptoKey>[],\n unverifiedKeys: KeyPair<CryptoKey>[] = []\n ): Promise<FakeEncryptionKeysManager> {\n const keysByFingerprint = {} as { [fingerprint: string]: { pair: KeyPair<CryptoKey>; verified: boolean } }\n for (const key of verifiedKeys) {\n const fingerprint = fingerprintV1(ua2hex(await primitives.RSA.exportKey(key.publicKey, 'spki')))\n keysByFingerprint[fingerprint] = { pair: key, verified: true }\n }\n for (const key of unverifiedKeys) {\n const fingerprint = fingerprintV1(ua2hex(await primitives.RSA.exportKey(key.publicKey, 'spki')))\n keysByFingerprint[fingerprint] = { pair: key, verified: false }\n }\n return new FakeEncryptionKeysManager(keysByFingerprint)\n }\n\n async getCurrentUserAvailablePublicKeysHex(verifiedOnly: boolean): Promise<string[]> {\n throw new Error('Not implemented')\n }\n\n async getCurrentUserHierarchyAvailablePublicKeysHex(): Promise<string[]> {\n throw new Error('Not implemented')\n }\n\n getKeyPairForFingerprint(fingerprint: string): { pair: KeyPair<CryptoKey>; verified: boolean } | undefined {\n const key = this.keys[fingerprint]\n if (key) return _.cloneDeep(key)\n return undefined\n }\n\n async initialiseKeys(): Promise<{ newKeyPair: KeyPair<CryptoKey>; newKeyFingerprint: string } | undefined> {\n return Promise.resolve(undefined)\n }\n\n async reloadKeys(): Promise<void> {}\n\n getSelfVerifiedKeys(): { fingerprint: string; pair: KeyPair<CryptoKey> }[] {\n const res = []\n for (const [fingerprint, { pair, verified }] of Object.entries(this.keys)) {\n if (verified) res.push({ fingerprint, pair })\n }\n return res\n }\n\n async getVerifiedPublicKeysFor(dataOwner: DataOwner): Promise<string[]> {\n throw new Error('Not implemented')\n }\n\n getDecryptionKeys(): { [p: string]: KeyPair<CryptoKey> } {\n return Object.fromEntries(Object.entries(this.keys).map(([fp, { pair }]) => [fp, pair]))\n }\n\n deleteKey(fp: string) {\n delete this.keys[fp]\n }\n\n async addOrUpdateKey(primitives: CryptoPrimitives, pair: KeyPair<CryptoKey>, verified: boolean) {\n const fp = fingerprintV1(ua2hex(await primitives.RSA.exportKey(pair.publicKey, 'spki')))\n this.keys[fp] = { pair, verified }\n }\n\n async unverifyExistingKeysAndCreateNewVerified(primitives: CryptoPrimitives) {\n Object.values(this.keys).map((x) => {\n x.verified = false\n })\n const newKey = await primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const newKeyFp = fingerprintV1(ua2hex(await primitives.RSA.exportKey(newKey.publicKey, 'spki')))\n this.keys[newKeyFp] = { pair: newKey, verified: true }\n }\n}\n"]}
|
|
@@ -28,6 +28,7 @@ export declare class FakeDecryptionExchangeDataManager implements ExchangeDataMa
|
|
|
28
28
|
exchangeData: ExchangeData;
|
|
29
29
|
accessControlSecret: string;
|
|
30
30
|
exchangeKey: CryptoKey;
|
|
31
|
+
sharedSignatureKey: CryptoKey;
|
|
31
32
|
}>;
|
|
32
33
|
cacheFakeData(exchangeData: ExchangeData, keyAndHashesFromSecret: {
|
|
33
34
|
exchangeKey: CryptoKey;
|
|
@@ -37,4 +38,11 @@ export declare class FakeDecryptionExchangeDataManager implements ExchangeDataMa
|
|
|
37
38
|
giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string): Promise<void>;
|
|
38
39
|
getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined>;
|
|
39
40
|
get base(): BaseExchangeDataManager;
|
|
41
|
+
injectDecryptedExchangeData(exchangeDataDetails: {
|
|
42
|
+
exchangeDataId: string;
|
|
43
|
+
accessControlSecret: ArrayBuffer;
|
|
44
|
+
exchangeKey: ArrayBuffer;
|
|
45
|
+
sharedSignatureKey: ArrayBuffer;
|
|
46
|
+
verified: boolean;
|
|
47
|
+
}[], reEncryptWithOwnKeys: boolean): Promise<void>;
|
|
40
48
|
}
|
|
@@ -74,6 +74,9 @@ class FakeDecryptionExchangeDataManager {
|
|
|
74
74
|
get base() {
|
|
75
75
|
throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported');
|
|
76
76
|
}
|
|
77
|
+
injectDecryptedExchangeData(exchangeDataDetails, reEncryptWithOwnKeys) {
|
|
78
|
+
throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported');
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
exports.FakeDecryptionExchangeDataManager = FakeDecryptionExchangeDataManager;
|
|
79
82
|
//# sourceMappingURL=FakeExchangeDataManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeExchangeDataManager.js","sourceRoot":"","sources":["../../../test/utils/FakeExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"FakeExchangeDataManager.js","sourceRoot":"","sources":["../../../test/utils/FakeExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA,MAAa,iCAAiC;IAC5C,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAE9C,eAAU,GAA4G,EAAE,CAAA;QACxH,aAAQ,GAErB,EAAE,CAAA;IAL4D,CAAC;IAOnE,sBAAsB;QACpB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAA;IACvG,CAAC;IAED,yB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a,aAAb,aAAa,cAAb,aAAa,GAAI,KAAK;YACrC,mBAAmB,EAAE,QAAQ;SAC9B,CAAA;QACD,IAAI,sBAAsB,EAAE;YAC1B,KAAK,MAAM,IAAI,IAAI,sBAAsB,CAAC,MAAM,EAAE;gBAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,EAAE,QAAS,EAAE,CAAA;aAC1H;SACF;IACH,CAAC;IAED,gBAAgB,CAAC,cAAsB,EAAE,qBAA6B;QACpE,MAAM,IAAI,KAAK,CAAC,kHAAkH,CAAC,CAAA;IACrI,CAAC;IAED,oBAAoB,CAAC,UAAwC;QAC3D,MAAM,IAAI,KAAK,CAAC,kHAAkH,CAAC,CAAA;IACrI,CAAC;IAED,IAAI,IAAI;QACN,MAAM,IAAI,KAAK,CAAC,kHAAkH,CAAC,CAAA;IACrI,CAAC;IAED,2BAA2B,CACzB,mBAMG,EACH,oBAA6B;QAE7B,MAAM,IAAI,KAAK,CAAC,kHAAkH,CAAC,CAAA;IACrI,CAAC;CACF;AAlGD,8EAkGC","sourcesContent":["import { ExchangeDataManager } from '../../icc-x-api/crypto/ExchangeDataManager'\nimport { EntityWithDelegationTypeName } from '../../icc-x-api/utils/EntityWithDelegationTypeName'\nimport { ExchangeData } from '../../icc-api/model/internal/ExchangeData'\nimport { expect } from 'chai'\nimport { BaseExchangeDataManager } from '../../icc-x-api/crypto/BaseExchangeDataManager'\nimport { CryptoPrimitives } from '../../icc-x-api'\nimport { id } from 'date-fns/locale'\n\nexport class FakeDecryptionExchangeDataManager implements ExchangeDataManager {\n constructor(private readonly cryptoPrimitives: CryptoPrimitives) {}\n\n private readonly dataByHash: { [hash: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } } = {}\n private readonly dataById: {\n [id: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; fakeNonCached: boolean }\n } = {}\n\n clearOrRepopulateCache(): Promise<void> {\n throw new Error('This method is not supported by fake exchange data manager and should not be used.')\n }\n\n getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined> {\n throw new Error('This method is not supported by fake exchange data manager and should not be used.')\n }\n\n async getCachedDecryptionDataKeyByAccessControlHash(\n hashes: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n const res: { [p: string]: { exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey } } = {}\n for (const hash of hashes) {\n const retrieved = this.dataByHash[hash]\n if (retrieved) res[hash] = retrieved\n }\n return res\n }\n\n async getDecryptionDataKeyByIds(\n ids: string[],\n retrieveIfNotCached: boolean\n ): Promise<{ [id: string]: { exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; exchangeData: ExchangeData } }> {\n const res: { [id: string]: { exchangeKey: CryptoKey | undefined; accessControlSecret: string | undefined; exchangeData: ExchangeData } } = {}\n for (const id of ids) {\n const retrieved = this.dataById[id]\n if (retrieved) {\n if (retrieveIfNotCached || !retrieved.fakeNonCached) {\n res[id] = retrieved\n }\n }\n }\n return res\n }\n\n getOrCreateEncryptionDataTo(\n delegateId: string\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: CryptoKey; sharedSignatureKey: CryptoKey }> {\n throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported')\n }\n\n cacheFakeData(\n exchangeData: ExchangeData,\n keyAndHashesFromSecret:\n | {\n exchangeKey: CryptoKey\n accessControlSecret?: string\n hashes: string[]\n }\n | undefined,\n fakeNonCached?: boolean\n ) {\n const acSecret = !!keyAndHashesFromSecret ? keyAndHashesFromSecret.accessControlSecret ?? this.cryptoPrimitives.randomUuid() : undefined\n this.dataById[exchangeData.id!] = {\n exchangeData,\n exchangeKey: keyAndHashesFromSecret?.exchangeKey,\n fakeNonCached: fakeNonCached ?? false,\n accessControlSecret: acSecret,\n }\n if (keyAndHashesFromSecret) {\n for (const hash of keyAndHashesFromSecret.hashes) {\n this.dataByHash[hash] = { exchangeData, exchangeKey: keyAndHashesFromSecret.exchangeKey, accessControlSecret: acSecret! }\n }\n }\n }\n\n giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string): Promise<void> {\n throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported')\n }\n\n getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined> {\n throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported')\n }\n\n get base(): BaseExchangeDataManager {\n throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported')\n }\n\n injectDecryptedExchangeData(\n exchangeDataDetails: {\n exchangeDataId: string\n accessControlSecret: ArrayBuffer\n exchangeKey: ArrayBuffer\n sharedSignatureKey: ArrayBuffer\n verified: boolean\n }[],\n reEncryptWithOwnKeys: boolean\n ): Promise<void> {\n throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported')\n }\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CryptoPrimitives, CryptoStrategies, KeyPair } from '../../icc-x-api';
|
|
2
|
+
import { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub';
|
|
3
|
+
import { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType';
|
|
4
|
+
export declare class KeylessCryptoStrategies implements CryptoStrategies {
|
|
5
|
+
requestedKey: boolean;
|
|
6
|
+
dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean;
|
|
7
|
+
generateNewKeyForDataOwner(): Promise<KeyPair<CryptoKey> | boolean | 'keyless'>;
|
|
8
|
+
recoverAndVerifySelfHierarchyKeys(keysData: {
|
|
9
|
+
dataOwner: DataOwnerWithType;
|
|
10
|
+
unknownKeys: string[];
|
|
11
|
+
unavailableKeys: string[];
|
|
12
|
+
}[]): Promise<{
|
|
13
|
+
[p: string]: {
|
|
14
|
+
recoveredKeys: {
|
|
15
|
+
[p: string]: KeyPair<CryptoKey>;
|
|
16
|
+
};
|
|
17
|
+
keyAuthenticity: {
|
|
18
|
+
[p: string]: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeylessCryptoStrategies = void 0;
|
|
4
|
+
const DataOwnerTypeEnum_1 = require("../../icc-api/model/DataOwnerTypeEnum");
|
|
5
|
+
class KeylessCryptoStrategies {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.requestedKey = false;
|
|
8
|
+
}
|
|
9
|
+
dataOwnerRequiresAnonymousDelegation(dataOwner) {
|
|
10
|
+
return dataOwner.type != DataOwnerTypeEnum_1.DataOwnerTypeEnum.Hcp;
|
|
11
|
+
}
|
|
12
|
+
generateNewKeyForDataOwner() {
|
|
13
|
+
this.requestedKey = true;
|
|
14
|
+
return Promise.resolve('keyless');
|
|
15
|
+
}
|
|
16
|
+
recoverAndVerifySelfHierarchyKeys(keysData) {
|
|
17
|
+
const res = {};
|
|
18
|
+
keysData.forEach((x) => (res[x.dataOwner.dataOwner.id] = { recoveredKeys: {}, keyAuthenticity: {} }));
|
|
19
|
+
return Promise.resolve(res);
|
|
20
|
+
}
|
|
21
|
+
verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
|
|
22
|
+
return Promise.resolve(publicKeys);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.KeylessCryptoStrategies = KeylessCryptoStrategies;
|
|
26
|
+
//# sourceMappingURL=KeylessCryptoStrategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeylessCryptoStrategies.js","sourceRoot":"","sources":["../../../test/utils/KeylessCryptoStrategies.ts"],"names":[],"mappings":";;;AAEA,6EAAyE;AAGzE,MAAa,uBAAuB;IAApC;QACE,iBAAY,GAAY,KAAK,CAAA;IA8B/B,CAAC;IA5BC,oCAAoC,CAAC,SAAkC;QACrE,OAAO,SAAS,CAAC,IAAI,IAAI,qCAAiB,CAAC,GAAG,CAAA;IAChD,CAAC;IAED,0BAA0B;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;QACxB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC;IAED,iCAAiC,CAC/B,QAIG;QAIH,MAAM,GAAG,GAEL,EAAE,CAAA;QACN,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,EAAG,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;QACtG,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC7B,CAAC;IAED,wBAAwB,CAAC,QAAiC,EAAE,UAAoB,EAAE,gBAAkC;QAClH,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACpC,CAAC;CACF;AA/BD,0DA+BC","sourcesContent":["import { CryptoPrimitives, CryptoStrategies, KeyPair } from '../../icc-x-api'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { DataOwnerTypeEnum } from '../../icc-api/model/DataOwnerTypeEnum'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\n\nexport class KeylessCryptoStrategies implements CryptoStrategies {\n requestedKey: boolean = false\n\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type != DataOwnerTypeEnum.Hcp\n }\n\n generateNewKeyForDataOwner(): Promise<KeyPair<CryptoKey> | boolean | 'keyless'> {\n this.requestedKey = true\n return Promise.resolve('keyless')\n }\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 const res: {\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n } = {}\n keysData.forEach((x) => (res[x.dataOwner.dataOwner.id!] = { recoveredKeys: {}, keyAuthenticity: {} }))\n return Promise.resolve(res)\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n return Promise.resolve(publicKeys)\n }\n}\n"]}
|
|
@@ -29,6 +29,13 @@ export declare function createNewPatientApi(env: TestVars): Promise<{
|
|
|
29
29
|
credentials: UserDetails;
|
|
30
30
|
user: User;
|
|
31
31
|
}>;
|
|
32
|
+
export declare function createNewKeylessApi(env: TestVars): Promise<{
|
|
33
|
+
api: IcureApi;
|
|
34
|
+
credentials: {
|
|
35
|
+
username: string;
|
|
36
|
+
password: string;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
32
39
|
/**
|
|
33
40
|
* Creates a hierarchy of HCPs with the following structure:
|
|
34
41
|
* grand HCP -+-> parent HCP ---> child HCP
|
package/test/utils/test_utils.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
var _a, _b, _c, _d;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.itNoLite = exports.describeNoLite = exports.isLiteTest = exports.createUserInMultipleGroups = exports.testSetupMasterApi = exports.createNewHcpWithoutKeyAndParentWithKey = exports.createHcpHierarchyApis = exports.createNewPatientApi = exports.createNewHcpApi = exports.getApiAndAddPrivateKeysForUser = exports.TestUtils = exports.getEnvironmentInitializer = exports.deviceUsername = exports.patUsername = exports.hcp3Username = exports.hcp2Username = exports.hcp1Username = exports.setLocalStorage = exports.getTempEmail = void 0;
|
|
13
|
+
exports.itNoLite = exports.describeNoLite = exports.isLiteTest = exports.createUserInMultipleGroups = exports.testSetupMasterApi = exports.createNewHcpWithoutKeyAndParentWithKey = exports.createHcpHierarchyApis = exports.createNewKeylessApi = exports.createNewPatientApi = exports.createNewHcpApi = exports.getApiAndAddPrivateKeysForUser = exports.TestUtils = exports.getEnvironmentInitializer = exports.deviceUsername = exports.patUsername = exports.hcp3Username = exports.hcp2Username = exports.hcp1Username = exports.setLocalStorage = exports.getTempEmail = void 0;
|
|
14
14
|
const icc_x_api_1 = require("../../icc-x-api");
|
|
15
15
|
const os_1 = require("os");
|
|
16
16
|
const util_1 = require("util");
|
|
@@ -27,6 +27,8 @@ require("isomorphic-fetch");
|
|
|
27
27
|
const creation_1 = require("@icure/test-setup/creation");
|
|
28
28
|
const icc_api_1 = require("../../icc-api");
|
|
29
29
|
const mocha_1 = require("mocha");
|
|
30
|
+
const Patient_1 = require("../../icc-api/model/Patient");
|
|
31
|
+
const KeylessCryptoStrategies_1 = require("./KeylessCryptoStrategies");
|
|
30
32
|
function getTempEmail() {
|
|
31
33
|
return `${(0, uuid_1.v4)().substring(0, 8)}@icure.com`;
|
|
32
34
|
}
|
|
@@ -178,6 +180,33 @@ function createNewPatientApi(env) {
|
|
|
178
180
|
});
|
|
179
181
|
}
|
|
180
182
|
exports.createNewPatientApi = createNewPatientApi;
|
|
183
|
+
function createNewKeylessApi(env) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const initialisationApi = yield icc_x_api_1.IcureBasicApi.initialise(env.iCureUrl, { username: env.masterHcp.user, password: env.masterHcp.password }, fetch);
|
|
186
|
+
const login = `${(0, crypto_1.randomUUID)()}@test.icure.com`;
|
|
187
|
+
const password = (0, crypto_1.randomUUID)();
|
|
188
|
+
const patient = new Patient_1.Patient({
|
|
189
|
+
id: (0, crypto_1.randomUUID)(),
|
|
190
|
+
firstName: 'Gino',
|
|
191
|
+
lastName: 'Pino',
|
|
192
|
+
});
|
|
193
|
+
const user = new User_1.User({
|
|
194
|
+
id: (0, crypto_1.randomUUID)(),
|
|
195
|
+
login,
|
|
196
|
+
passwordHash: password,
|
|
197
|
+
patientId: patient.id,
|
|
198
|
+
});
|
|
199
|
+
yield initialisationApi.userApi.createUser(user);
|
|
200
|
+
yield initialisationApi.patientApi.createPatient(patient);
|
|
201
|
+
const credentials = { username: login, password };
|
|
202
|
+
const cryptoStrategies = new KeylessCryptoStrategies_1.KeylessCryptoStrategies();
|
|
203
|
+
const api = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, credentials, cryptoStrategies, crypto_1.webcrypto, fetch, {});
|
|
204
|
+
if (!cryptoStrategies.requestedKey)
|
|
205
|
+
throw new Error('Illegal state: did not request key');
|
|
206
|
+
return { api, credentials };
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
exports.createNewKeylessApi = createNewKeylessApi;
|
|
181
210
|
/**
|
|
182
211
|
* Creates a hierarchy of HCPs with the following structure:
|
|
183
212
|
* grand HCP -+-> parent HCP ---> child HCP
|