@icure/api 7.1.34 → 7.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/icc-api/api/IccAuthApi.d.ts +1 -0
  2. package/icc-api/api/IccAuthApi.js +1 -0
  3. package/icc-api/api/IccAuthApi.js.map +1 -1
  4. package/icc-x-api/index.d.ts +22 -29
  5. package/icc-x-api/index.js +60 -38
  6. package/icc-x-api/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
  9. package/test/icc-api/api/IccDocumentApi.js +200 -0
  10. package/test/icc-api/api/IccDocumentApi.js.map +1 -0
  11. package/test/icc-api/api/IccGroupApi.d.ts +1 -0
  12. package/test/icc-api/api/IccGroupApi.js +50 -0
  13. package/test/icc-api/api/IccGroupApi.js.map +1 -0
  14. package/test/icc-api/api/IccRoleApi.d.ts +1 -0
  15. package/test/icc-api/api/IccRoleApi.js +34 -0
  16. package/test/icc-api/api/IccRoleApi.js.map +1 -0
  17. package/test/icc-api/api/IccUserApi.d.ts +1 -0
  18. package/test/icc-api/api/IccUserApi.js +80 -0
  19. package/test/icc-api/api/IccUserApi.js.map +1 -0
  20. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +1 -0
  21. package/test/icc-api/e2e/IccCalendarItemApi.js +45 -0
  22. package/test/icc-api/e2e/IccCalendarItemApi.js.map +1 -0
  23. package/test/icc-api/model/modelHelpersTest.d.ts +1 -0
  24. package/test/icc-api/model/modelHelpersTest.js +45 -0
  25. package/test/icc-api/model/modelHelpersTest.js.map +1 -0
  26. package/test/icc-x-api/auth/group-switch-test.d.ts +1 -0
  27. package/test/icc-x-api/auth/group-switch-test.js +81 -0
  28. package/test/icc-x-api/auth/group-switch-test.js.map +1 -0
  29. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +2 -0
  30. package/test/icc-x-api/auth/jwt-concurrency-test.js +113 -0
  31. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +1 -0
  32. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +1 -0
  33. package/test/icc-x-api/auth/smart-auth-provider-test.js +222 -0
  34. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
  35. package/test/icc-x-api/crypto/KeyManager-test.d.ts +1 -0
  36. package/test/icc-x-api/crypto/KeyManager-test.js +225 -0
  37. package/test/icc-x-api/crypto/KeyManager-test.js.map +1 -0
  38. package/test/icc-x-api/crypto/concurrency.d.ts +1 -0
  39. package/test/icc-x-api/crypto/concurrency.js +35 -0
  40. package/test/icc-x-api/crypto/concurrency.js.map +1 -0
  41. package/test/icc-x-api/crypto/crypto-utils.d.ts +1 -0
  42. package/test/icc-x-api/crypto/crypto-utils.js +80 -0
  43. package/test/icc-x-api/crypto/crypto-utils.js.map +1 -0
  44. package/test/icc-x-api/crypto/cryptoTest.d.ts +2 -0
  45. package/test/icc-x-api/crypto/cryptoTest.js +275 -0
  46. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -0
  47. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +1 -0
  48. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +132 -0
  49. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +1 -0
  50. package/test/icc-x-api/crypto/full-crypto-test.d.ts +1 -0
  51. package/test/icc-x-api/crypto/full-crypto-test.js +458 -0
  52. package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
  53. package/test/icc-x-api/crypto/shamir.d.ts +2 -0
  54. package/test/icc-x-api/crypto/shamir.js +156 -0
  55. package/test/icc-x-api/crypto/shamir.js.map +1 -0
  56. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +1 -0
  57. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +75 -0
  58. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
  59. package/test/icc-x-api/data-compatibility-test-7to6.d.ts +1 -0
  60. package/test/icc-x-api/data-compatibility-test-7to6.js +343 -0
  61. package/test/icc-x-api/data-compatibility-test-7to6.js.map +1 -0
  62. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +1 -0
  63. package/test/icc-x-api/entity-with-attachments-api-test.js +142 -0
  64. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -0
  65. package/test/icc-x-api/filters/filters.d.ts +1 -0
  66. package/test/icc-x-api/filters/filters.js +49 -0
  67. package/test/icc-x-api/filters/filters.js.map +1 -0
  68. package/test/icc-x-api/icc-accesslog-x-api.d.ts +1 -0
  69. package/test/icc-x-api/icc-accesslog-x-api.js +121 -0
  70. package/test/icc-x-api/icc-accesslog-x-api.js.map +1 -0
  71. package/test/icc-x-api/icc-auth-api.d.ts +1 -0
  72. package/test/icc-x-api/icc-auth-api.js +46 -0
  73. package/test/icc-x-api/icc-auth-api.js.map +1 -0
  74. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +1 -0
  75. package/test/icc-x-api/icc-calendar-item-x-api.js +146 -0
  76. package/test/icc-x-api/icc-calendar-item-x-api.js.map +1 -0
  77. package/test/icc-x-api/icc-contact-x-api.d.ts +1 -0
  78. package/test/icc-x-api/icc-contact-x-api.js +311 -0
  79. package/test/icc-x-api/icc-contact-x-api.js.map +1 -0
  80. package/test/icc-x-api/icc-form-x-api.d.ts +1 -0
  81. package/test/icc-x-api/icc-form-x-api.js +331 -0
  82. package/test/icc-x-api/icc-form-x-api.js.map +1 -0
  83. package/test/icc-x-api/icc-helement-x-api-test.d.ts +1 -0
  84. package/test/icc-x-api/icc-helement-x-api-test.js +158 -0
  85. package/test/icc-x-api/icc-helement-x-api-test.js.map +1 -0
  86. package/test/icc-x-api/icc-invoice-x-api.d.ts +1 -0
  87. package/test/icc-x-api/icc-invoice-x-api.js +115 -0
  88. package/test/icc-x-api/icc-invoice-x-api.js.map +1 -0
  89. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +1 -0
  90. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +230 -0
  91. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
  92. package/test/icc-x-api/icc-patient-x-api-test.d.ts +1 -0
  93. package/test/icc-x-api/icc-patient-x-api-test.js +169 -0
  94. package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
  95. package/test/icc-x-api/icc-time-table-x-api.d.ts +1 -0
  96. package/test/icc-x-api/icc-time-table-x-api.js +110 -0
  97. package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
  98. package/test/icc-x-api/icc-user-x-api-test.d.ts +1 -0
  99. package/test/icc-x-api/icc-user-x-api-test.js +108 -0
  100. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
  101. package/test/icc-x-api/icureapi-group-test.d.ts +1 -0
  102. package/test/icc-x-api/icureapi-group-test.js +130 -0
  103. package/test/icc-x-api/icureapi-group-test.js.map +1 -0
  104. package/test/icc-x-api/patient-user.d.ts +2 -0
  105. package/test/icc-x-api/patient-user.js +117 -0
  106. package/test/icc-x-api/patient-user.js.map +1 -0
  107. package/test/icc-x-api/storage/storage.d.ts +1 -0
  108. package/test/icc-x-api/storage/storage.js +50 -0
  109. package/test/icc-x-api/storage/storage.js.map +1 -0
  110. package/test/icc-x-api/subscription-apis.d.ts +2 -0
  111. package/test/icc-x-api/subscription-apis.js +498 -0
  112. package/test/icc-x-api/subscription-apis.js.map +1 -0
  113. package/test/icc-x-api/test-api-no-parent.d.ts +1 -0
  114. package/test/icc-x-api/test-api-no-parent.js +79 -0
  115. package/test/icc-x-api/test-api-no-parent.js.map +1 -0
  116. package/test/icc-x-api/test-legacy-data-support.d.ts +1 -0
  117. package/test/icc-x-api/test-legacy-data-support.js +231 -0
  118. package/test/icc-x-api/test-legacy-data-support.js.map +1 -0
  119. package/test/icc-x-api/utils/crypto-utils-test.d.ts +1 -0
  120. package/test/icc-x-api/utils/crypto-utils-test.js +586 -0
  121. package/test/icc-x-api/utils/crypto-utils-test.js.map +1 -0
  122. package/test/icc-x-api/utils/graph-test.d.ts +1 -0
  123. package/test/icc-x-api/utils/graph-test.js +54 -0
  124. package/test/icc-x-api/utils/graph-test.js.map +1 -0
  125. package/test/support/CSM-185.d.ts +1 -0
  126. package/test/support/CSM-185.js +120 -0
  127. package/test/support/CSM-185.js.map +1 -0
  128. package/test/support/CSM-87.d.ts +0 -0
  129. package/test/support/CSM-87.js +21 -0
  130. package/test/support/CSM-87.js.map +1 -0
  131. package/test/support/CSM-93.d.ts +1 -0
  132. package/test/support/CSM-93.js +111 -0
  133. package/test/support/CSM-93.js.map +1 -0
  134. package/test/utils/TestApi.d.ts +3 -0
  135. package/test/utils/TestApi.js +27 -0
  136. package/test/utils/TestApi.js.map +1 -0
  137. package/test/utils/TestCollectionUtils.d.ts +1 -0
  138. package/test/utils/TestCollectionUtils.js +109 -0
  139. package/test/utils/TestCollectionUtils.js.map +1 -0
  140. package/test/utils/TestCryptoStrategies.d.ts +37 -0
  141. package/test/utils/TestCryptoStrategies.js +72 -0
  142. package/test/utils/TestCryptoStrategies.js.map +1 -0
  143. package/test/utils/TestStorage.d.ts +31 -0
  144. package/test/utils/TestStorage.js +88 -0
  145. package/test/utils/TestStorage.js.map +1 -0
  146. package/test/utils/test_utils.d.ts +60 -0
  147. package/test/utils/test_utils.js +313 -0
  148. package/test/utils/test_utils.js.map +1 -0
@@ -0,0 +1,225 @@
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
+ const mocha_1 = require("mocha");
13
+ const crypto_1 = require("crypto");
14
+ require("isomorphic-fetch");
15
+ const chai_1 = require("chai");
16
+ const test_utils_1 = require("../../utils/test_utils");
17
+ const TestStorage_1 = require("../../utils/TestStorage");
18
+ const TestCryptoStrategies_1 = require("../../utils/TestCryptoStrategies");
19
+ const types_1 = require("@icure/test-setup/types");
20
+ const icc_x_api_1 = require("../../../icc-x-api");
21
+ const apiV6_1 = require("@icure/apiV6");
22
+ (0, test_utils_1.setLocalStorage)(fetch);
23
+ let env;
24
+ (0, mocha_1.describe)('Key manager', function () {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ this.timeout(600000);
27
+ (0, mocha_1.before)(function () {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
30
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
31
+ });
32
+ });
33
+ (0, mocha_1.it)(`Should not ask crypto strategies to recover available keys`, () => __awaiter(this, void 0, void 0, function* () {
34
+ const apis = yield (0, test_utils_1.createHcpHierarchyApis)(env);
35
+ const storageWithoutParentKey = yield (0, TestStorage_1.testStorageWithKeys)([
36
+ {
37
+ dataOwnerId: apis.grandCredentials.dataOwnerId,
38
+ pairs: [{ privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }],
39
+ },
40
+ {
41
+ dataOwnerId: apis.childCredentials.dataOwnerId,
42
+ pairs: [{ privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }],
43
+ },
44
+ ]);
45
+ const cryptoStrats = new TestCryptoStrategies_1.TestCryptoStrategies(undefined, {}, {
46
+ [apis.parentCredentials.dataOwnerId]: { privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey },
47
+ });
48
+ yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: apis.childCredentials.user, password: apis.childCredentials.password }, cryptoStrats, crypto_1.webcrypto, fetch, {
49
+ storage: storageWithoutParentKey.storage,
50
+ keyStorage: storageWithoutParentKey.keyStorage,
51
+ entryKeysFactory: storageWithoutParentKey.keyFactory,
52
+ });
53
+ (0, chai_1.expect)(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(1);
54
+ const params = cryptoStrats.recoverAndVerifyCallsParams[0];
55
+ (0, chai_1.expect)(params).to.have.length(3);
56
+ (0, chai_1.expect)(params[0].dataOwner.dataOwner.id).to.equal(apis.grandCredentials.dataOwnerId);
57
+ (0, chai_1.expect)(params[0].unavailableKeys).to.be.empty;
58
+ (0, chai_1.expect)(params[0].unknownKeys).to.be.empty;
59
+ (0, chai_1.expect)(params[1].dataOwner.dataOwner.id).to.equal(apis.parentCredentials.dataOwnerId);
60
+ (0, chai_1.expect)(params[1].unavailableKeys).to.have.members([apis.parentCredentials.publicKey]);
61
+ (0, chai_1.expect)(params[1].unknownKeys).to.have.members([apis.parentCredentials.publicKey]);
62
+ (0, chai_1.expect)(params[2].dataOwner.dataOwner.id).to.equal(apis.childCredentials.dataOwnerId);
63
+ (0, chai_1.expect)(params[2].unavailableKeys).to.be.empty;
64
+ (0, chai_1.expect)(params[2].unknownKeys).to.be.empty;
65
+ }));
66
+ (0, mocha_1.it)('Should not ask crypto strategies to recover keys if all keys are available', () => __awaiter(this, void 0, void 0, function* () {
67
+ const apis = yield (0, test_utils_1.createHcpHierarchyApis)(env);
68
+ const storageWithoutParentKey = yield (0, TestStorage_1.testStorageWithKeys)([
69
+ {
70
+ dataOwnerId: apis.grandCredentials.dataOwnerId,
71
+ pairs: [{ privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }],
72
+ },
73
+ {
74
+ dataOwnerId: apis.parentCredentials.dataOwnerId,
75
+ pairs: [{ privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey }],
76
+ },
77
+ {
78
+ dataOwnerId: apis.childCredentials.dataOwnerId,
79
+ pairs: [{ privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }],
80
+ },
81
+ ]);
82
+ const cryptoStrats = new TestCryptoStrategies_1.TestCryptoStrategies();
83
+ yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: apis.childCredentials.user, password: apis.childCredentials.password }, cryptoStrats, crypto_1.webcrypto, fetch, {
84
+ storage: storageWithoutParentKey.storage,
85
+ keyStorage: storageWithoutParentKey.keyStorage,
86
+ entryKeysFactory: storageWithoutParentKey.keyFactory,
87
+ });
88
+ (0, chai_1.expect)(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(0);
89
+ }));
90
+ (0, mocha_1.it)('Should allow to retrieve all keys for a data owner and his parents', () => __awaiter(this, void 0, void 0, function* () {
91
+ const apis = yield (0, test_utils_1.createHcpHierarchyApis)(env);
92
+ const keysData = yield apis.childApi.cryptoApi.getEncryptionDecryptionKeypairsForDataOwnerHierarchy();
93
+ function checkKey(userDetails, key) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const exportedPrivateKey = (0, apiV6_1.ua2hex)(yield apis.childApi.cryptoApi.primitives.RSA.exportKey(key.privateKey, 'pkcs8'));
96
+ const exportedPublicKey = (0, apiV6_1.ua2hex)(yield apis.childApi.cryptoApi.primitives.RSA.exportKey(key.publicKey, 'spki'));
97
+ (0, chai_1.expect)(exportedPublicKey).to.equal(userDetails.publicKey);
98
+ (0, chai_1.expect)(exportedPrivateKey).to.equal(userDetails.privateKey);
99
+ });
100
+ }
101
+ (0, chai_1.expect)(keysData.self.dataOwnerId).to.equal(apis.childCredentials.dataOwnerId);
102
+ (0, chai_1.expect)(keysData.self.keys).to.have.length(1);
103
+ (0, chai_1.expect)(keysData.self.keys[0].verified).to.be.true;
104
+ yield checkKey(apis.childCredentials, keysData.self.keys[0].pair);
105
+ (0, chai_1.expect)(keysData.parents).to.have.length(2);
106
+ (0, chai_1.expect)(keysData.parents[0].dataOwnerId).to.equal(apis.grandCredentials.dataOwnerId);
107
+ (0, chai_1.expect)(keysData.parents[0].keys).to.have.length(1);
108
+ yield checkKey(apis.grandCredentials, keysData.parents[0].keys[0].pair);
109
+ (0, chai_1.expect)(keysData.parents[1].dataOwnerId).to.equal(apis.parentCredentials.dataOwnerId);
110
+ (0, chai_1.expect)(keysData.parents[1].keys).to.have.length(1);
111
+ yield checkKey(apis.parentCredentials, keysData.parents[1].keys[0].pair);
112
+ }));
113
+ (0, mocha_1.it)('If a HCP has no key yet, but the parent does the crypto strategies should first ask to recover the keys for the parent then ask for the generation of a new key to the data owner', () => __awaiter(this, void 0, void 0, function* () {
114
+ const hcpsInfo = yield (0, test_utils_1.createNewHcpWithoutKeyAndParentWithKey)(env);
115
+ const cryptoStrats = new (class {
116
+ constructor() {
117
+ this.generateNewKeyCalled = false;
118
+ this.recoverCalled = false;
119
+ this.generatedKeyPair = undefined;
120
+ }
121
+ generateNewKeyForDataOwner(self, cryptoPrimitives) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ if (this.generateNewKeyCalled)
124
+ throw new Error('generateNewKeyForDataOwner called twice');
125
+ if (!this.recoverCalled)
126
+ throw new Error('generateNewKeyForDataOwner called before recoverAndVerifySelfHierarchyKeys');
127
+ this.generateNewKeyCalled = true;
128
+ (0, chai_1.expect)(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId);
129
+ return (this.generatedKeyPair = yield cryptoPrimitives.RSA.generateKeyPair());
130
+ });
131
+ }
132
+ recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ if (this.recoverCalled)
135
+ throw new Error('recoverAndVerifySelfHierarchyKeys called twice');
136
+ this.recoverCalled = true;
137
+ (0, chai_1.expect)(keysData).to.have.length(2);
138
+ (0, chai_1.expect)(keysData[0].dataOwner.dataOwner.id).to.equal(hcpsInfo.parentCredentials.dataOwnerId);
139
+ (0, chai_1.expect)(keysData[0].unknownKeys).to.have.members([hcpsInfo.parentCredentials.publicKey]);
140
+ (0, chai_1.expect)(keysData[0].unavailableKeys).to.have.members([hcpsInfo.parentCredentials.publicKey]);
141
+ (0, chai_1.expect)(keysData[1].dataOwner.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId);
142
+ (0, chai_1.expect)(keysData[1].unknownKeys).to.be.empty;
143
+ (0, chai_1.expect)(keysData[1].unavailableKeys).to.be.empty;
144
+ return {
145
+ [hcpsInfo.parentCredentials.dataOwnerId]: {
146
+ recoveredKeys: {
147
+ [hcpsInfo.parentCredentials.publicKey.slice(-32)]: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.hex2ua)(hcpsInfo.parentCredentials.privateKey), 'spki', (0, icc_x_api_1.hex2ua)(hcpsInfo.parentCredentials.publicKey)),
148
+ },
149
+ keyAuthenticity: {},
150
+ },
151
+ [hcpsInfo.childDataOwnerId]: {
152
+ recoveredKeys: {},
153
+ keyAuthenticity: {},
154
+ },
155
+ };
156
+ });
157
+ }
158
+ verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
159
+ throw new Error('This method should not be called by this test');
160
+ }
161
+ })();
162
+ const childApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcpsInfo.childUser, password: hcpsInfo.childPassword }, cryptoStrats, crypto_1.webcrypto, fetch, {
163
+ storage: new TestStorage_1.TestStorage(),
164
+ keyStorage: new TestStorage_1.TestKeyStorage(),
165
+ });
166
+ (0, chai_1.expect)(cryptoStrats.generateNewKeyCalled).to.be.true;
167
+ (0, chai_1.expect)(cryptoStrats.recoverCalled).to.be.true;
168
+ const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf((yield childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner));
169
+ (0, chai_1.expect)(keys).to.have.length(1);
170
+ (0, chai_1.expect)(Array.from(keys)[0]).to.equal((0, apiV6_1.ua2hex)(yield childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair.publicKey, 'spki')));
171
+ }));
172
+ (0, mocha_1.it)('If a HCP has no key yet, but the parent does and the key is available the crypto strategies should ask for the generation of a new key to the data owner', () => __awaiter(this, void 0, void 0, function* () {
173
+ function doTest(initialiseEmptyKeyForChild) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ const hcpsInfo = yield (0, test_utils_1.createNewHcpWithoutKeyAndParentWithKey)(env, { initialiseEmptyKeyForChild });
176
+ const cryptoStrats = new (class {
177
+ constructor() {
178
+ this.generateNewKeyCalled = false;
179
+ this.generatedKeyPair = undefined;
180
+ }
181
+ generateNewKeyForDataOwner(self, cryptoPrimitives) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ if (this.generateNewKeyCalled)
184
+ throw new Error('generateNewKeyForDataOwner called twice');
185
+ this.generateNewKeyCalled = true;
186
+ (0, chai_1.expect)(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId);
187
+ return (this.generatedKeyPair = yield cryptoPrimitives.RSA.generateKeyPair());
188
+ });
189
+ }
190
+ recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ throw new Error('This method should not be called by this test');
193
+ });
194
+ }
195
+ verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
196
+ throw new Error('This method should not be called by this test');
197
+ }
198
+ })();
199
+ const storages = yield (0, TestStorage_1.testStorageWithKeys)([
200
+ {
201
+ dataOwnerId: hcpsInfo.parentCredentials.dataOwnerId,
202
+ pairs: [{ privateKey: hcpsInfo.parentCredentials.privateKey, publicKey: hcpsInfo.parentCredentials.publicKey }],
203
+ },
204
+ ]);
205
+ const childApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcpsInfo.childUser, password: hcpsInfo.childPassword }, cryptoStrats, crypto_1.webcrypto, fetch, {
206
+ storage: storages.storage,
207
+ keyStorage: storages.keyStorage,
208
+ entryKeysFactory: storages.keyFactory,
209
+ });
210
+ (0, chai_1.expect)(cryptoStrats.generateNewKeyCalled).to.be.true;
211
+ const initialisedHcp = (yield childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner;
212
+ const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf(initialisedHcp));
213
+ (0, chai_1.expect)(keys).to.have.length(1);
214
+ (0, chai_1.expect)(keys[0]).to.equal((0, apiV6_1.ua2hex)(yield childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair.publicKey, 'spki')));
215
+ // V7 ONLY: the new key should be saved in `publicKey`
216
+ (0, chai_1.expect)(initialisedHcp.publicKey).to.equal(keys[0]);
217
+ });
218
+ }
219
+ yield doTest(false);
220
+ // V7 ONLY
221
+ yield doTest(true);
222
+ }));
223
+ });
224
+ });
225
+ //# sourceMappingURL=KeyManager-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyManager-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/KeyManager-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,iCAA4C;AAE5C,mCAAkC;AAClC,4BAAyB;AAGzB,+BAA6B;AAG7B,uDAAmJ;AACnJ,yDAA0F;AAC1F,2EAAuE;AACvE,mDAAgF;AAChF,kDAAkG;AAIlG,wCAAqC;AAIrC,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AAEtB,IAAI,GAAa,CAAA;AAEjB,IAAA,gBAAQ,EAAC,aAAa,EAAE;;QACtB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAEpB,IAAA,cAAM,EAAC;;gBACL,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;gBACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;YACpD,CAAC;SAAA,CAAC,CAAA;QAEF,IAAA,UAAE,EAAC,4DAA4D,EAAE,GAAS,EAAE;YAC1E,MAAM,IAAI,GAAG,MAAM,IAAA,mCAAsB,EAAC,GAAG,CAAC,CAAA;YAC9C,MAAM,uBAAuB,GAAG,MAAM,IAAA,iCAAmB,EAAC;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,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBACpD,CAAC;aAAA;YACD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAA;YACnB,UAAU;YACV,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;QACpB,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import { v4 as uuid } from 'uuid'\nimport { User } from '../../../icc-api/model/User'\nimport { before, describe, it } from 'mocha'\n\nimport { webcrypto } from 'crypto'\nimport 'isomorphic-fetch'\n\nimport { IccPatientApi } from '../../../icc-api'\nimport { expect } from 'chai'\n\nimport { BasicAuthenticationProvider } from '../../../icc-x-api/auth/AuthenticationProvider'\nimport { createHcpHierarchyApis, createNewHcpWithoutKeyAndParentWithKey, getEnvironmentInitializer, setLocalStorage } from '../../utils/test_utils'\nimport { TestKeyStorage, TestStorage, testStorageWithKeys } from '../../utils/TestStorage'\nimport { TestCryptoStrategies } from '../../utils/TestCryptoStrategies'\nimport { getEnvVariables, TestVars, UserDetails } from '@icure/test-setup/types'\nimport { CryptoPrimitives, CryptoStrategies, hex2ua, IcureApi, KeyPair } from '../../../icc-x-api'\nimport exp = require('constants')\nimport { KeyManager } from '../../../icc-x-api/crypto/KeyManager'\nimport { TestApi } from '../../utils/TestApi'\nimport { ua2hex } from '@icure/apiV6'\nimport { DataOwnerWithType } from '../../../icc-api/model/DataOwnerWithType'\nimport { CryptoActorStubWithType } from '../../../icc-api/model/CryptoActorStub'\n\nsetLocalStorage(fetch)\n\nlet env: TestVars\n\ndescribe('Key manager', async function () {\n this.timeout(600000)\n\n before(async function () {\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it(`Should not ask crypto strategies to recover available keys`, async () => {\n const apis = await createHcpHierarchyApis(env)\n const storageWithoutParentKey = await testStorageWithKeys([\n {\n dataOwnerId: apis.grandCredentials.dataOwnerId,\n pairs: [{ privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }],\n },\n {\n dataOwnerId: apis.childCredentials.dataOwnerId,\n pairs: [{ privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }],\n },\n ])\n const cryptoStrats = new TestCryptoStrategies(\n undefined,\n {},\n {\n [apis.parentCredentials.dataOwnerId]: { privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey },\n }\n )\n await IcureApi.initialise(\n env.iCureUrl,\n { username: apis.childCredentials.user, password: apis.childCredentials.password },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: storageWithoutParentKey.storage,\n keyStorage: storageWithoutParentKey.keyStorage,\n entryKeysFactory: storageWithoutParentKey.keyFactory,\n }\n )\n expect(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(1)\n const params = cryptoStrats.recoverAndVerifyCallsParams[0]\n expect(params).to.have.length(3)\n expect(params[0].dataOwner.dataOwner.id).to.equal(apis.grandCredentials.dataOwnerId)\n expect(params[0].unavailableKeys).to.be.empty\n expect(params[0].unknownKeys).to.be.empty\n expect(params[1].dataOwner.dataOwner.id).to.equal(apis.parentCredentials.dataOwnerId)\n expect(params[1].unavailableKeys).to.have.members([apis.parentCredentials.publicKey])\n expect(params[1].unknownKeys).to.have.members([apis.parentCredentials.publicKey])\n expect(params[2].dataOwner.dataOwner.id).to.equal(apis.childCredentials.dataOwnerId)\n expect(params[2].unavailableKeys).to.be.empty\n expect(params[2].unknownKeys).to.be.empty\n })\n\n it('Should not ask crypto strategies to recover keys if all keys are available', async () => {\n const apis = await createHcpHierarchyApis(env)\n const storageWithoutParentKey = await testStorageWithKeys([\n {\n dataOwnerId: apis.grandCredentials.dataOwnerId,\n pairs: [{ privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }],\n },\n {\n dataOwnerId: apis.parentCredentials.dataOwnerId,\n pairs: [{ privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey }],\n },\n {\n dataOwnerId: apis.childCredentials.dataOwnerId,\n pairs: [{ privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }],\n },\n ])\n const cryptoStrats = new TestCryptoStrategies()\n await IcureApi.initialise(\n env.iCureUrl,\n { username: apis.childCredentials.user, password: apis.childCredentials.password },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: storageWithoutParentKey.storage,\n keyStorage: storageWithoutParentKey.keyStorage,\n entryKeysFactory: storageWithoutParentKey.keyFactory,\n }\n )\n expect(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(0)\n })\n\n it('Should allow to retrieve all keys for a data owner and his parents', async () => {\n const apis = await createHcpHierarchyApis(env)\n const keysData = await apis.childApi.cryptoApi.getEncryptionDecryptionKeypairsForDataOwnerHierarchy()\n async function checkKey(userDetails: UserDetails, key: KeyPair<CryptoKey>) {\n const exportedPrivateKey = ua2hex(await apis.childApi.cryptoApi.primitives.RSA.exportKey(key.privateKey, 'pkcs8'))\n const exportedPublicKey = ua2hex(await apis.childApi.cryptoApi.primitives.RSA.exportKey(key.publicKey, 'spki'))\n expect(exportedPublicKey).to.equal(userDetails.publicKey)\n expect(exportedPrivateKey).to.equal(userDetails.privateKey)\n }\n expect(keysData.self.dataOwnerId).to.equal(apis.childCredentials.dataOwnerId)\n expect(keysData.self.keys).to.have.length(1)\n expect(keysData.self.keys[0].verified).to.be.true\n await checkKey(apis.childCredentials, keysData.self.keys[0].pair)\n expect(keysData.parents).to.have.length(2)\n expect(keysData.parents[0].dataOwnerId).to.equal(apis.grandCredentials.dataOwnerId)\n expect(keysData.parents[0].keys).to.have.length(1)\n await checkKey(apis.grandCredentials, keysData.parents[0].keys[0].pair)\n expect(keysData.parents[1].dataOwnerId).to.equal(apis.parentCredentials.dataOwnerId)\n expect(keysData.parents[1].keys).to.have.length(1)\n await checkKey(apis.parentCredentials, keysData.parents[1].keys[0].pair)\n })\n\n it('If a HCP has no key yet, but the parent does the crypto strategies should first ask to recover the keys for the parent then ask for the generation of a new key to the data owner', async () => {\n const hcpsInfo = await createNewHcpWithoutKeyAndParentWithKey(env)\n const cryptoStrats = new (class implements CryptoStrategies {\n generateNewKeyCalled: boolean = false\n recoverCalled: boolean = false\n generatedKeyPair: KeyPair<CryptoKey> | undefined = undefined\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType, cryptoPrimitives: CryptoPrimitives): Promise<KeyPair<CryptoKey> | boolean> {\n if (this.generateNewKeyCalled) throw new Error('generateNewKeyForDataOwner called twice')\n if (!this.recoverCalled) throw new Error('generateNewKeyForDataOwner called before recoverAndVerifySelfHierarchyKeys')\n this.generateNewKeyCalled = true\n expect(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId)\n return (this.generatedKeyPair = await cryptoPrimitives.RSA.generateKeyPair())\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n if (this.recoverCalled) throw new Error('recoverAndVerifySelfHierarchyKeys called twice')\n this.recoverCalled = true\n expect(keysData).to.have.length(2)\n expect(keysData[0].dataOwner.dataOwner.id).to.equal(hcpsInfo.parentCredentials.dataOwnerId)\n expect(keysData[0].unknownKeys).to.have.members([hcpsInfo.parentCredentials.publicKey])\n expect(keysData[0].unavailableKeys).to.have.members([hcpsInfo.parentCredentials.publicKey])\n expect(keysData[1].dataOwner.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId)\n expect(keysData[1].unknownKeys).to.be.empty\n expect(keysData[1].unavailableKeys).to.be.empty\n return {\n [hcpsInfo.parentCredentials.dataOwnerId]: {\n recoveredKeys: {\n [hcpsInfo.parentCredentials.publicKey.slice(-32)]: await cryptoPrimitives.RSA.importKeyPair(\n 'pkcs8',\n hex2ua(hcpsInfo.parentCredentials.privateKey),\n 'spki',\n hex2ua(hcpsInfo.parentCredentials.publicKey)\n ),\n },\n keyAuthenticity: {},\n },\n [hcpsInfo.childDataOwnerId]: {\n recoveredKeys: {},\n keyAuthenticity: {},\n },\n }\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n throw new Error('This method should not be called by this test')\n }\n })()\n const childApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcpsInfo.childUser, password: hcpsInfo.childPassword },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n expect(cryptoStrats.generateNewKeyCalled).to.be.true\n expect(cryptoStrats.recoverCalled).to.be.true\n const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf((await childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner))\n expect(keys).to.have.length(1)\n expect(Array.from(keys)[0]).to.equal(ua2hex(await childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair!.publicKey, 'spki')))\n })\n\n it('If a HCP has no key yet, but the parent does and the key is available the crypto strategies should ask for the generation of a new key to the data owner', async () => {\n async function doTest(initialiseEmptyKeyForChild: boolean) {\n const hcpsInfo = await createNewHcpWithoutKeyAndParentWithKey(env, { initialiseEmptyKeyForChild })\n const cryptoStrats = new (class implements CryptoStrategies {\n generateNewKeyCalled: boolean = false\n generatedKeyPair: KeyPair<CryptoKey> | undefined = undefined\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType, cryptoPrimitives: CryptoPrimitives): Promise<KeyPair<CryptoKey> | boolean> {\n if (this.generateNewKeyCalled) throw new Error('generateNewKeyForDataOwner called twice')\n this.generateNewKeyCalled = true\n expect(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId)\n return (this.generatedKeyPair = await cryptoPrimitives.RSA.generateKeyPair())\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n throw new Error('This method should not be called by this test')\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n throw new Error('This method should not be called by this test')\n }\n })()\n const storages = await testStorageWithKeys([\n {\n dataOwnerId: hcpsInfo.parentCredentials.dataOwnerId,\n pairs: [{ privateKey: hcpsInfo.parentCredentials.privateKey, publicKey: hcpsInfo.parentCredentials.publicKey }],\n },\n ])\n const childApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcpsInfo.childUser, password: hcpsInfo.childPassword },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: storages.storage,\n keyStorage: storages.keyStorage,\n entryKeysFactory: storages.keyFactory,\n }\n )\n expect(cryptoStrats.generateNewKeyCalled).to.be.true\n const initialisedHcp = (await childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner\n const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf(initialisedHcp))\n expect(keys).to.have.length(1)\n expect(keys[0]).to.equal(ua2hex(await childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair!.publicKey, 'spki')))\n // V7 ONLY: the new key should be saved in `publicKey`\n expect(initialisedHcp.publicKey).to.equal(keys[0])\n }\n await doTest(false)\n // V7 ONLY\n await doTest(true)\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import 'mocha';
@@ -0,0 +1,35 @@
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
+ const icc_x_api_1 = require("../../../icc-x-api");
13
+ const chai_1 = require("chai");
14
+ require("mocha");
15
+ const delay = (ms) => new Promise((res) => setTimeout(res, ms));
16
+ describe('Concurrency test', () => {
17
+ it('should return ordered sequence', () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const cm = {};
19
+ const seq1 = [];
20
+ const seq2 = [];
21
+ const ctrl = yield Promise.all([500, 400, 300, 200, 100].map((x, idx) => __awaiter(void 0, void 0, void 0, function* () {
22
+ yield delay(x);
23
+ seq1.push(idx);
24
+ return idx;
25
+ })));
26
+ const res = yield Promise.all([500, 400, 300, 200, 100].map((x, idx) => (0, icc_x_api_1.notConcurrent)(cm, '123', () => __awaiter(void 0, void 0, void 0, function* () {
27
+ yield delay(x);
28
+ seq2.push(idx);
29
+ return idx;
30
+ }))));
31
+ (0, chai_1.expect)(seq1).to.not.eql(ctrl);
32
+ (0, chai_1.expect)(seq2).to.eql(res);
33
+ }));
34
+ });
35
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/concurrency.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kDAAkD;AAClD,+BAA6B;AAC7B,iBAAc;AAEd,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;AAEvE,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,gCAAgC,EAAE,GAAS,EAAE;QAC9C,MAAM,EAAE,GAAG,EAAE,CAAA;QACb,MAAM,IAAI,GAAa,EAAE,CAAA;QACzB,MAAM,IAAI,GAAa,EAAE,CAAA;QAEzB,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAC5B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAO,CAAC,EAAE,GAAG,EAAE,EAAE;YAC7C,MAAM,KAAK,CAAC,CAAC,CAAC,CAAA;YACd,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACd,OAAO,GAAG,CAAA;QACZ,CAAC,CAAA,CAAC,CACH,CAAA;QACD,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAC3B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CACvC,IAAA,yBAAa,EAAC,EAAE,EAAE,KAAK,EAAE,GAAS,EAAE;YAClC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAA;YACd,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACd,OAAO,GAAG,CAAA;QACZ,CAAC,CAAA,CAAC,CACH,CACF,CAAA;QAED,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC7B,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { notConcurrent } from '../../../icc-x-api'\nimport { expect } from 'chai'\nimport 'mocha'\n\nconst delay = (ms: number) => new Promise((res) => setTimeout(res, ms))\n\ndescribe('Concurrency test', () => {\n it('should return ordered sequence', async () => {\n const cm = {}\n const seq1: number[] = []\n const seq2: number[] = []\n\n const ctrl = await Promise.all(\n [500, 400, 300, 200, 100].map(async (x, idx) => {\n await delay(x)\n seq1.push(idx)\n return idx\n })\n )\n const res = await Promise.all(\n [500, 400, 300, 200, 100].map((x, idx) =>\n notConcurrent(cm, '123', async () => {\n await delay(x)\n seq2.push(idx)\n return idx\n })\n )\n )\n\n expect(seq1).to.not.eql(ctrl)\n expect(seq2).to.eql(res)\n })\n})\n"]}
@@ -0,0 +1 @@
1
+ import 'mocha';
@@ -0,0 +1,80 @@
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
+ const icc_x_api_1 = require("../../../icc-x-api");
13
+ const chai_1 = require("chai");
14
+ require("mocha");
15
+ const index_1 = require("../../../index");
16
+ const node_compat_1 = require("../../../node-compat");
17
+ const RSA_1 = require("../../../icc-x-api/crypto/RSA");
18
+ const asn1_parser_1 = require("../../../icc-x-api/utils/asn1-parser");
19
+ const test_utils_1 = require("../../utils/test_utils");
20
+ const TestApi_1 = require("../../utils/TestApi");
21
+ const types_1 = require("@icure/test-setup/types");
22
+ let env;
23
+ describe('ArrayBuffer methods', () => {
24
+ let rsa;
25
+ 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
+ rsa = new RSA_1.RSAUtils(node_compat_1.crypto);
31
+ });
32
+ });
33
+ describe('truncateTrailingNulls', () => {
34
+ it('should truncate trailing nulls out of an Uint8Array without copying', () => {
35
+ const bytes = [72, 101, 108, 108, 111, 33];
36
+ const originalArray = Uint8Array.from([...bytes, 0, 0]);
37
+ const truncatedArray = (0, index_1.truncateTrailingNulls)(originalArray);
38
+ (0, chai_1.expect)(truncatedArray.buffer).to.equal(originalArray.buffer);
39
+ (0, chai_1.expect)(Array.from(truncatedArray)).to.eql(bytes);
40
+ });
41
+ it('should preserve the offset into the buffer', () => {
42
+ const bytes = [72, 101, 108, 108, 111, 33];
43
+ const originalBuffer = new Uint8Array([0, 0, ...bytes, 0, 0]).buffer;
44
+ const originalArray = new Uint8Array(originalBuffer, 2, bytes.length);
45
+ const truncatedArray = (0, index_1.truncateTrailingNulls)(originalArray);
46
+ (0, chai_1.expect)(truncatedArray.buffer).to.equal(originalArray.buffer);
47
+ (0, chai_1.expect)(truncatedArray.byteOffset).to.equal(originalArray.byteOffset);
48
+ (0, chai_1.expect)(Array.from(truncatedArray)).to.eql(bytes);
49
+ });
50
+ });
51
+ describe('convertKeysFormat', () => {
52
+ it('should manage jwk conversions for private keys gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const { healthcarePartyApi } = yield (0, TestApi_1.TestApi)(env.iCureUrl, env.dataOwnerDetails[test_utils_1.hcp1Username].user, env.dataOwnerDetails[test_utils_1.hcp1Username].password, node_compat_1.crypto);
54
+ const privKey = env.dataOwnerDetails[test_utils_1.hcp1Username].privateKey;
55
+ const parsed = (0, asn1_parser_1.parseAsn1)(new Uint8Array((0, index_1.hex2ua)(privKey)));
56
+ const jwk1 = (0, index_1.pkcs8ToJwk)((0, index_1.hex2ua)(privKey));
57
+ const pkcs8 = (0, index_1.jwk2pkcs8)(jwk1);
58
+ const jwk2 = (0, index_1.pkcs8ToJwk)((0, index_1.hex2ua)(pkcs8));
59
+ (0, chai_1.expect)(jwk1.n).to.equal(jwk2.n);
60
+ const pubKey = yield healthcarePartyApi.getCurrentHealthcareParty().then((hcp) => hcp.publicKey);
61
+ const jwk3 = (0, index_1.spkiToJwk)((0, index_1.hex2ua)(pubKey));
62
+ const spki = (0, index_1.jwk2spki)(jwk3);
63
+ const jwk4 = (0, index_1.spkiToJwk)((0, index_1.hex2ua)(spki));
64
+ (0, chai_1.expect)(jwk3.n).to.equal(jwk4.n);
65
+ }));
66
+ it('should convert spki to jwk in a coherent way', () => __awaiter(void 0, void 0, void 0, function* () {
67
+ const { healthcarePartyApi } = yield (0, TestApi_1.TestApi)(env.iCureUrl, env.dataOwnerDetails[test_utils_1.hcp1Username].user, env.dataOwnerDetails[test_utils_1.hcp1Username].password, node_compat_1.crypto);
68
+ const pubKey = yield healthcarePartyApi.getCurrentHealthcareParty().then((hcp) => hcp.publicKey);
69
+ const jwk1 = (0, index_1.spkiToJwk)((0, index_1.hex2ua)(pubKey));
70
+ const rsaKey1 = yield rsa.importKey('jwk', jwk1, ['encrypt']);
71
+ const rsaKey2 = yield rsa.importKey('spki', (0, index_1.hex2ua)(pubKey), ['encrypt']);
72
+ const jwk2 = yield rsa.exportKey(rsaKey2, 'jwk');
73
+ const rsaKey3 = yield rsa.importKey('jwk', jwk2, ['encrypt']);
74
+ const n1 = (0, index_1.ua2hex)((0, icc_x_api_1.b64Url2ua)(jwk1.n));
75
+ const n2 = (0, index_1.ua2hex)((0, icc_x_api_1.b64Url2ua)(jwk2.n));
76
+ (0, chai_1.expect)(jwk1.n).to.equal(jwk2.n);
77
+ }));
78
+ });
79
+ });
80
+ //# sourceMappingURL=crypto-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/crypto-utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kDAA8C;AAC9C,+BAA6B;AAE7B,iBAAc;AACd,0CAAkH;AAClH,sDAA6C;AAC7C,uDAAwD;AACxD,sEAAgE;AAChE,uDAAgF;AAChF,iDAA6C;AAC7C,mDA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CAAA;YAEtC,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;YAC7D,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,IAAA,cAAM,EAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;YACxE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;YAChD,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;YAE7D,MAAM,EAAE,GAAG,IAAA,cAAM,EAAC,IAAA,qBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;YACpC,MAAM,EAAE,GAAG,IAAA,cAAM,EAAC,IAAA,qBAAS,EAAC,IAAI,CAAC,CAAE,CAAC,CAAC,CAAA;YAErC,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjC,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { b64Url2ua } from '../../../icc-x-api'\nimport { expect } from 'chai'\n\nimport 'mocha'\nimport { hex2ua, jwk2pkcs8, jwk2spki, pkcs8ToJwk, spkiToJwk, truncateTrailingNulls, ua2hex } from '../../../index'\nimport { crypto } from '../../../node-compat'\nimport { RSAUtils } from '../../../icc-x-api/crypto/RSA'\nimport { parseAsn1 } from '../../../icc-x-api/utils/asn1-parser'\nimport { getEnvironmentInitializer, hcp1Username } from '../../utils/test_utils'\nimport { TestApi } from '../../utils/TestApi'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nlet env: TestVars | undefined\n\ndescribe('ArrayBuffer methods', () => {\n let rsa: RSAUtils\n\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n rsa = new RSAUtils(crypto)\n })\n\n describe('truncateTrailingNulls', () => {\n it('should truncate trailing nulls out of an Uint8Array without copying', () => {\n const bytes = [72, 101, 108, 108, 111, 33]\n const originalArray = Uint8Array.from([...bytes, 0, 0])\n const truncatedArray = truncateTrailingNulls(originalArray)\n expect(truncatedArray.buffer).to.equal(originalArray.buffer)\n expect(Array.from(truncatedArray)).to.eql(bytes)\n })\n\n it('should preserve the offset into the buffer', () => {\n const bytes = [72, 101, 108, 108, 111, 33]\n const originalBuffer = new Uint8Array([0, 0, ...bytes, 0, 0]).buffer\n const originalArray = new Uint8Array(originalBuffer, 2, bytes.length)\n const truncatedArray = truncateTrailingNulls(originalArray)\n expect(truncatedArray.buffer).to.equal(originalArray.buffer)\n expect(truncatedArray.byteOffset).to.equal(originalArray.byteOffset)\n expect(Array.from(truncatedArray)).to.eql(bytes)\n })\n })\n\n describe('convertKeysFormat', () => {\n it('should manage jwk conversions for private keys gracefully', async () => {\n const { healthcarePartyApi } = await TestApi(\n env!.iCureUrl,\n env!.dataOwnerDetails[hcp1Username].user,\n env!.dataOwnerDetails[hcp1Username].password,\n crypto\n )\n const privKey = env!.dataOwnerDetails[hcp1Username].privateKey\n const parsed = parseAsn1(new Uint8Array(hex2ua(privKey)))\n\n const jwk1 = pkcs8ToJwk(hex2ua(privKey))\n const pkcs8 = jwk2pkcs8(jwk1)\n const jwk2 = pkcs8ToJwk(hex2ua(pkcs8))\n\n expect(jwk1.n).to.equal(jwk2.n)\n\n const pubKey = await healthcarePartyApi.getCurrentHealthcareParty().then((hcp) => hcp.publicKey!)\n const jwk3 = spkiToJwk(hex2ua(pubKey))\n const spki = jwk2spki(jwk3)\n const jwk4 = spkiToJwk(hex2ua(spki))\n\n expect(jwk3.n).to.equal(jwk4.n)\n })\n\n it('should convert spki to jwk in a coherent way', async () => {\n const { healthcarePartyApi } = await TestApi(\n env!.iCureUrl,\n env!.dataOwnerDetails[hcp1Username].user,\n env!.dataOwnerDetails[hcp1Username].password,\n crypto\n )\n const pubKey = await healthcarePartyApi.getCurrentHealthcareParty().then((hcp) => hcp.publicKey!)\n const jwk1 = spkiToJwk(hex2ua(pubKey))\n\n const rsaKey1 = await rsa.importKey('jwk', jwk1, ['encrypt'])\n const rsaKey2 = await rsa.importKey('spki', hex2ua(pubKey), ['encrypt'])\n const jwk2 = await rsa.exportKey(rsaKey2, 'jwk')\n const rsaKey3 = await rsa.importKey('jwk', jwk2, ['encrypt'])\n\n const n1 = ua2hex(b64Url2ua(jwk1.n))\n const n2 = ua2hex(b64Url2ua(jwk2.n!))\n\n expect(jwk1.n).to.equal(jwk2.n)\n })\n })\n})\n"]}
@@ -0,0 +1,2 @@
1
+ import 'isomorphic-fetch';
2
+ import 'mocha';