@icure/api 8.0.7 → 8.0.9

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 (259) hide show
  1. package/icc-api/model/models.d.ts +1 -0
  2. package/icc-api/model/models.js +1 -0
  3. package/icc-api/model/models.js.map +1 -1
  4. package/icc-x-api/crypto/ExchangeDataManager.js +3 -2
  5. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  6. package/icc-x-api/crypto/KeyRecovery.js +5 -4
  7. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  8. package/icc-x-api/crypto/RSA.d.ts +4 -1
  9. package/icc-x-api/crypto/RSA.js +6 -1
  10. package/icc-x-api/crypto/RSA.js.map +1 -1
  11. package/icc-x-api/crypto/SecureDelegationsManager.js +2 -1
  12. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  13. package/icc-x-api/crypto/TransferKeysManager.js +4 -3
  14. package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
  15. package/icc-x-api/crypto/UserEncryptionKeysManager.js +2 -1
  16. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -1
  17. package/icc-x-api/crypto/utils.d.ts +1 -4
  18. package/icc-x-api/crypto/utils.js +6 -8
  19. package/icc-x-api/crypto/utils.js.map +1 -1
  20. package/icc-x-api/icc-accesslog-x-api.js +16 -14
  21. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  22. package/icc-x-api/icc-calendar-item-x-api.d.ts +2 -2
  23. package/icc-x-api/icc-calendar-item-x-api.js +17 -17
  24. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  25. package/icc-x-api/icc-classification-x-api.js +12 -11
  26. package/icc-x-api/icc-classification-x-api.js.map +1 -1
  27. package/icc-x-api/icc-contact-x-api.d.ts +2 -2
  28. package/icc-x-api/icc-contact-x-api.js +23 -20
  29. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  30. package/icc-x-api/icc-document-x-api.js +17 -16
  31. package/icc-x-api/icc-document-x-api.js.map +1 -1
  32. package/icc-x-api/icc-form-x-api.js +13 -12
  33. package/icc-x-api/icc-form-x-api.js.map +1 -1
  34. package/icc-x-api/icc-helement-x-api.js +18 -16
  35. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  36. package/icc-x-api/icc-invoice-x-api.js +12 -11
  37. package/icc-x-api/icc-invoice-x-api.js.map +1 -1
  38. package/icc-x-api/icc-maintenance-task-x-api.js +11 -11
  39. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  40. package/icc-x-api/icc-message-x-api.js +14 -14
  41. package/icc-x-api/icc-message-x-api.js.map +1 -1
  42. package/icc-x-api/icc-patient-x-api.js +28 -27
  43. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  44. package/icc-x-api/icc-receipt-x-api.js +11 -10
  45. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  46. package/icc-x-api/icc-recovery-x-api.js +3 -2
  47. package/icc-x-api/icc-recovery-x-api.js.map +1 -1
  48. package/icc-x-api/icc-time-table-x-api.js +9 -8
  49. package/icc-x-api/icc-time-table-x-api.js.map +1 -1
  50. package/icc-x-api/icc-topic-x-api.js +13 -13
  51. package/icc-x-api/icc-topic-x-api.js.map +1 -1
  52. package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +17 -1
  53. package/icc-x-api/utils/EntityWithDelegationTypeName.js +33 -15
  54. package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -1
  55. package/icc-x-api/utils/index.d.ts +1 -0
  56. package/icc-x-api/utils/index.js +1 -0
  57. package/icc-x-api/utils/index.js.map +1 -1
  58. package/package.json +1 -1
  59. package/test/icc-api/api/IccAnonymousAccessApi.d.ts +1 -0
  60. package/test/icc-api/api/IccAnonymousAccessApi.js +58 -0
  61. package/test/icc-api/api/IccAnonymousAccessApi.js.map +1 -0
  62. package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
  63. package/test/icc-api/api/IccDocumentApi.js +208 -0
  64. package/test/icc-api/api/IccDocumentApi.js.map +1 -0
  65. package/test/icc-api/api/IccGroupApi.d.ts +1 -0
  66. package/test/icc-api/api/IccGroupApi.js +50 -0
  67. package/test/icc-api/api/IccGroupApi.js.map +1 -0
  68. package/test/icc-api/api/IccRecoveryDataApi.d.ts +1 -0
  69. package/test/icc-api/api/IccRecoveryDataApi.js +95 -0
  70. package/test/icc-api/api/IccRecoveryDataApi.js.map +1 -0
  71. package/test/icc-api/api/IccRoleApi.d.ts +1 -0
  72. package/test/icc-api/api/IccRoleApi.js +34 -0
  73. package/test/icc-api/api/IccRoleApi.js.map +1 -0
  74. package/test/icc-api/api/IccUserApi.d.ts +1 -0
  75. package/test/icc-api/api/IccUserApi.js +96 -0
  76. package/test/icc-api/api/IccUserApi.js.map +1 -0
  77. package/test/icc-api/e2e/IccCalendarItemApi.d.ts +1 -0
  78. package/test/icc-api/e2e/IccCalendarItemApi.js +46 -0
  79. package/test/icc-api/e2e/IccCalendarItemApi.js.map +1 -0
  80. package/test/icc-api/model/modelHelpersTest.d.ts +1 -0
  81. package/test/icc-api/model/modelHelpersTest.js +45 -0
  82. package/test/icc-api/model/modelHelpersTest.js.map +1 -0
  83. package/test/icc-x-api/auth/group-switch-test.d.ts +1 -0
  84. package/test/icc-x-api/auth/group-switch-test.js +81 -0
  85. package/test/icc-x-api/auth/group-switch-test.js.map +1 -0
  86. package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +2 -0
  87. package/test/icc-x-api/auth/jwt-concurrency-test.js +113 -0
  88. package/test/icc-x-api/auth/jwt-concurrency-test.js.map +1 -0
  89. package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +1 -0
  90. package/test/icc-x-api/auth/smart-auth-provider-test.js +224 -0
  91. package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
  92. package/test/icc-x-api/autofix-anonymity-test.d.ts +1 -0
  93. package/test/icc-x-api/autofix-anonymity-test.js +108 -0
  94. package/test/icc-x-api/autofix-anonymity-test.js.map +1 -0
  95. package/test/icc-x-api/confidential-entities-test.d.ts +1 -0
  96. package/test/icc-x-api/confidential-entities-test.js +110 -0
  97. package/test/icc-x-api/confidential-entities-test.js.map +1 -0
  98. package/test/icc-x-api/crud/comprehensive-crud-test.d.ts +1 -0
  99. package/test/icc-x-api/crud/comprehensive-crud-test.js +276 -0
  100. package/test/icc-x-api/crud/comprehensive-crud-test.js.map +1 -0
  101. package/test/icc-x-api/crud/entities-crud-test-interface.d.ts +16 -0
  102. package/test/icc-x-api/crud/entities-crud-test-interface.js +422 -0
  103. package/test/icc-x-api/crud/entities-crud-test-interface.js.map +1 -0
  104. package/test/icc-x-api/crypto/anonymous-delegations-test.d.ts +1 -0
  105. package/test/icc-x-api/crypto/anonymous-delegations-test.js +588 -0
  106. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +1 -0
  107. package/test/icc-x-api/crypto/concurrency.d.ts +1 -0
  108. package/test/icc-x-api/crypto/concurrency.js +35 -0
  109. package/test/icc-x-api/crypto/concurrency.js.map +1 -0
  110. package/test/icc-x-api/crypto/crypto-utils.d.ts +1 -0
  111. package/test/icc-x-api/crypto/crypto-utils.js +80 -0
  112. package/test/icc-x-api/crypto/crypto-utils.js.map +1 -0
  113. package/test/icc-x-api/crypto/cryptoTest.d.ts +2 -0
  114. package/test/icc-x-api/crypto/cryptoTest.js +302 -0
  115. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -0
  116. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +1 -0
  117. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +166 -0
  118. package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +1 -0
  119. package/test/icc-x-api/crypto/exchange-data-manager-test.d.ts +1 -0
  120. package/test/icc-x-api/crypto/exchange-data-manager-test.js +690 -0
  121. package/test/icc-x-api/crypto/exchange-data-manager-test.js.map +1 -0
  122. package/test/icc-x-api/crypto/full-crypto-test.d.ts +1 -0
  123. package/test/icc-x-api/crypto/full-crypto-test.js +457 -0
  124. package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
  125. package/test/icc-x-api/crypto/secure-delegations-manager-test.d.ts +1 -0
  126. package/test/icc-x-api/crypto/secure-delegations-manager-test.js +266 -0
  127. package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +1 -0
  128. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.d.ts +1 -0
  129. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js +393 -0
  130. package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js.map +1 -0
  131. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.d.ts +1 -0
  132. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js +213 -0
  133. package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js.map +1 -0
  134. package/test/icc-x-api/crypto/shamir.d.ts +2 -0
  135. package/test/icc-x-api/crypto/shamir.js +166 -0
  136. package/test/icc-x-api/crypto/shamir.js.map +1 -0
  137. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +1 -0
  138. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +71 -0
  139. package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
  140. package/test/icc-x-api/crypto/signature-keys-manager-test.d.ts +1 -0
  141. package/test/icc-x-api/crypto/signature-keys-manager-test.js +44 -0
  142. package/test/icc-x-api/crypto/signature-keys-manager-test.js.map +1 -0
  143. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.d.ts +1 -0
  144. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js +246 -0
  145. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js.map +1 -0
  146. package/test/icc-x-api/entity-with-attachments-api-test.d.ts +1 -0
  147. package/test/icc-x-api/entity-with-attachments-api-test.js +142 -0
  148. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -0
  149. package/test/icc-x-api/filters/filters.d.ts +1 -0
  150. package/test/icc-x-api/filters/filters.js +49 -0
  151. package/test/icc-x-api/filters/filters.js.map +1 -0
  152. package/test/icc-x-api/icc-accesslog-x-api.d.ts +1 -0
  153. package/test/icc-x-api/icc-accesslog-x-api.js +106 -0
  154. package/test/icc-x-api/icc-accesslog-x-api.js.map +1 -0
  155. package/test/icc-x-api/icc-auth-api.d.ts +1 -0
  156. package/test/icc-x-api/icc-auth-api.js +47 -0
  157. package/test/icc-x-api/icc-auth-api.js.map +1 -0
  158. package/test/icc-x-api/icc-calendar-item-x-api.d.ts +1 -0
  159. package/test/icc-x-api/icc-calendar-item-x-api.js +150 -0
  160. package/test/icc-x-api/icc-calendar-item-x-api.js.map +1 -0
  161. package/test/icc-x-api/icc-contact-x-api.d.ts +1 -0
  162. package/test/icc-x-api/icc-contact-x-api.js +279 -0
  163. package/test/icc-x-api/icc-contact-x-api.js.map +1 -0
  164. package/test/icc-x-api/icc-form-x-api.d.ts +1 -0
  165. package/test/icc-x-api/icc-form-x-api.js +98 -0
  166. package/test/icc-x-api/icc-form-x-api.js.map +1 -0
  167. package/test/icc-x-api/icc-helement-x-api-test.d.ts +1 -0
  168. package/test/icc-x-api/icc-helement-x-api-test.js +153 -0
  169. package/test/icc-x-api/icc-helement-x-api-test.js.map +1 -0
  170. package/test/icc-x-api/icc-invoice-x-api.d.ts +1 -0
  171. package/test/icc-x-api/icc-invoice-x-api.js +99 -0
  172. package/test/icc-x-api/icc-invoice-x-api.js.map +1 -0
  173. package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +1 -0
  174. package/test/icc-x-api/icc-maintenance-task-x-api-test.js +221 -0
  175. package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
  176. package/test/icc-x-api/icc-message-x-api.d.ts +1 -0
  177. package/test/icc-x-api/icc-message-x-api.js +328 -0
  178. package/test/icc-x-api/icc-message-x-api.js.map +1 -0
  179. package/test/icc-x-api/icc-patient-x-api-test.d.ts +1 -0
  180. package/test/icc-x-api/icc-patient-x-api-test.js +158 -0
  181. package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
  182. package/test/icc-x-api/icc-recovery-x-api.d.ts +1 -0
  183. package/test/icc-x-api/icc-recovery-x-api.js +170 -0
  184. package/test/icc-x-api/icc-recovery-x-api.js.map +1 -0
  185. package/test/icc-x-api/icc-time-table-x-api.d.ts +1 -0
  186. package/test/icc-x-api/icc-time-table-x-api.js +100 -0
  187. package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
  188. package/test/icc-x-api/icc-topic-x-api.d.ts +1 -0
  189. package/test/icc-x-api/icc-topic-x-api.js +269 -0
  190. package/test/icc-x-api/icc-topic-x-api.js.map +1 -0
  191. package/test/icc-x-api/icc-user-x-api-test.d.ts +1 -0
  192. package/test/icc-x-api/icc-user-x-api-test.js +99 -0
  193. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
  194. package/test/icc-x-api/patient-user.d.ts +2 -0
  195. package/test/icc-x-api/patient-user.js +104 -0
  196. package/test/icc-x-api/patient-user.js.map +1 -0
  197. package/test/icc-x-api/storage/storage.d.ts +1 -0
  198. package/test/icc-x-api/storage/storage.js +48 -0
  199. package/test/icc-x-api/storage/storage.js.map +1 -0
  200. package/test/icc-x-api/test-api-no-parent.d.ts +1 -0
  201. package/test/icc-x-api/test-api-no-parent.js +79 -0
  202. package/test/icc-x-api/test-api-no-parent.js.map +1 -0
  203. package/test/icc-x-api/test-legacy-data-support.d.ts +1 -0
  204. package/test/icc-x-api/test-legacy-data-support.js +376 -0
  205. package/test/icc-x-api/test-legacy-data-support.js.map +1 -0
  206. package/test/icc-x-api/utils/graph-test.d.ts +1 -0
  207. package/test/icc-x-api/utils/graph-test.js +54 -0
  208. package/test/icc-x-api/utils/graph-test.js.map +1 -0
  209. package/test/icc-x-api/utils/lru-temporised-async-cache-test.d.ts +1 -0
  210. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js +364 -0
  211. package/test/icc-x-api/utils/lru-temporised-async-cache-test.js.map +1 -0
  212. package/test/support/CSM-185.d.ts +1 -0
  213. package/test/support/CSM-185.js +124 -0
  214. package/test/support/CSM-185.js.map +1 -0
  215. package/test/support/CSM-243.d.ts +1 -0
  216. package/test/support/CSM-243.js +120 -0
  217. package/test/support/CSM-243.js.map +1 -0
  218. package/test/support/CSM-87.d.ts +0 -0
  219. package/test/support/CSM-87.js +21 -0
  220. package/test/support/CSM-87.js.map +1 -0
  221. package/test/support/CSM-93.d.ts +1 -0
  222. package/test/support/CSM-93.js +112 -0
  223. package/test/support/CSM-93.js.map +1 -0
  224. package/test/utils/FakeDataOwnerApi.d.ts +32 -0
  225. package/test/utils/FakeDataOwnerApi.js +136 -0
  226. package/test/utils/FakeDataOwnerApi.js.map +1 -0
  227. package/test/utils/FakeEncryptionKeysManager.d.ts +35 -0
  228. package/test/utils/FakeEncryptionKeysManager.js +87 -0
  229. package/test/utils/FakeEncryptionKeysManager.js.map +1 -0
  230. package/test/utils/FakeExchangeDataApi.d.ts +30 -0
  231. package/test/utils/FakeExchangeDataApi.js +74 -0
  232. package/test/utils/FakeExchangeDataApi.js.map +1 -0
  233. package/test/utils/FakeExchangeDataManager.d.ts +40 -0
  234. package/test/utils/FakeExchangeDataManager.js +89 -0
  235. package/test/utils/FakeExchangeDataManager.js.map +1 -0
  236. package/test/utils/FakeExchangeDataMapManager.d.ts +12 -0
  237. package/test/utils/FakeExchangeDataMapManager.js +38 -0
  238. package/test/utils/FakeExchangeDataMapManager.js.map +1 -0
  239. package/test/utils/FakeGenericApi.d.ts +16 -0
  240. package/test/utils/FakeGenericApi.js +65 -0
  241. package/test/utils/FakeGenericApi.js.map +1 -0
  242. package/test/utils/FakeSignatureKeysManager.d.ts +16 -0
  243. package/test/utils/FakeSignatureKeysManager.js +54 -0
  244. package/test/utils/FakeSignatureKeysManager.js.map +1 -0
  245. package/test/utils/TestApi.d.ts +3 -0
  246. package/test/utils/TestApi.js +30 -0
  247. package/test/utils/TestApi.js.map +1 -0
  248. package/test/utils/TestCollectionUtils.d.ts +1 -0
  249. package/test/utils/TestCollectionUtils.js +109 -0
  250. package/test/utils/TestCollectionUtils.js.map +1 -0
  251. package/test/utils/TestCryptoStrategies.d.ts +42 -0
  252. package/test/utils/TestCryptoStrategies.js +80 -0
  253. package/test/utils/TestCryptoStrategies.js.map +1 -0
  254. package/test/utils/TestStorage.d.ts +23 -0
  255. package/test/utils/TestStorage.js +61 -0
  256. package/test/utils/TestStorage.js.map +1 -0
  257. package/test/utils/test_utils.d.ts +76 -0
  258. package/test/utils/test_utils.js +419 -0
  259. package/test/utils/test_utils.js.map +1 -0
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FakeEncryptionKeysManager = void 0;
13
+ const UserEncryptionKeysManager_1 = require("../../icc-x-api/crypto/UserEncryptionKeysManager");
14
+ const icc_x_api_1 = require("../../icc-x-api");
15
+ const _ = require("lodash");
16
+ const utils_1 = require("../../icc-x-api/crypto/utils");
17
+ class FakeEncryptionKeysManager extends UserEncryptionKeysManager_1.UserEncryptionKeysManager {
18
+ constructor(keys) {
19
+ super(null, null, null, null, null, null, null);
20
+ this.keys = keys;
21
+ }
22
+ static create(primitives, verifiedKeys, unverifiedKeys = []) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const keysByFingerprint = {};
25
+ for (const key of verifiedKeys) {
26
+ const fingerprint = (0, utils_1.fingerprintV1)((0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(key.publicKey, 'spki')));
27
+ keysByFingerprint[fingerprint] = { pair: key, verified: true };
28
+ }
29
+ for (const key of unverifiedKeys) {
30
+ const fingerprint = (0, utils_1.fingerprintV1)((0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(key.publicKey, 'spki')));
31
+ keysByFingerprint[fingerprint] = { pair: key, verified: false };
32
+ }
33
+ return new FakeEncryptionKeysManager(keysByFingerprint);
34
+ });
35
+ }
36
+ getCurrentUserAvailablePublicKeysHex(verifiedOnly) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ throw new Error('Not implemented');
39
+ });
40
+ }
41
+ getCurrentUserHierarchyAvailablePublicKeysHex() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ throw new Error('Not implemented');
44
+ });
45
+ }
46
+ getKeyPairForFingerprint(fingerprint) {
47
+ const key = this.keys[fingerprint];
48
+ if (key)
49
+ return _.cloneDeep(key);
50
+ return undefined;
51
+ }
52
+ initialiseKeys() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return Promise.resolve(undefined);
55
+ });
56
+ }
57
+ reloadKeys() {
58
+ return __awaiter(this, void 0, void 0, function* () { });
59
+ }
60
+ getSelfVerifiedKeys() {
61
+ const res = [];
62
+ for (const [fingerprint, { pair, verified }] of Object.entries(this.keys)) {
63
+ if (verified)
64
+ res.push({ fingerprint, pair });
65
+ }
66
+ return res;
67
+ }
68
+ getVerifiedPublicKeysFor(dataOwner) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ throw new Error('Not implemented');
71
+ });
72
+ }
73
+ getDecryptionKeys() {
74
+ return Object.fromEntries(Object.entries(this.keys).map(([fp, { pair }]) => [fp, pair]));
75
+ }
76
+ deleteKey(fp) {
77
+ delete this.keys[fp];
78
+ }
79
+ addOrUpdateKey(primitives, pair, verified) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const fp = (0, utils_1.fingerprintV1)((0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(pair.publicKey, 'spki')));
82
+ this.keys[fp] = { pair, verified };
83
+ });
84
+ }
85
+ }
86
+ exports.FakeEncryptionKeysManager = FakeEncryptionKeysManager;
87
+ //# sourceMappingURL=FakeEncryptionKeysManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeEncryptionKeysManager.js","sourceRoot":"","sources":["../../../test/utils/FakeEncryptionKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gGAA4F;AAI5F,+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;QADrE,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,IAAI,cAAc,EAAE;gBAChC,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,C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AE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IAC1F,CAAC;IAED,SAAS,CAAC,EAAU;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACtB,CAAC;IAEK,cAAc,CAAC,UAA4B,EAAE,IAAwB,EAAE,QAAiB;;YAC5F,MAAM,EAAE,GAAG,IAAA,qBAAa,EAAC,IAAA,kBAAM,EAAC,MAAM,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;YACxF,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;QACpC,CAAC;KAAA;CACF;AAlED,8DAkEC","sourcesContent":["import { UserEncryptionKeysManager } from '../../icc-x-api/crypto/UserEncryptionKeysManager'\nimport { DataOwner } from '../../icc-x-api/icc-data-owner-x-api'\nimport { KeyPair } 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)\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"]}
@@ -0,0 +1,30 @@
1
+ import { IccExchangeDataApi } from '../../icc-api/api/internal/IccExchangeDataApi';
2
+ import { ExchangeData } from '../../icc-api/model/internal/ExchangeData';
3
+ import { PaginatedListExchangeData } from '../../icc-api/model/PaginatedListExchangeData';
4
+ export type CallCount = {
5
+ getExchangeDataById: number;
6
+ createExchangeData: number;
7
+ modifyExchangeData: number;
8
+ getExchangeDataByParticipant: number;
9
+ getExchangeDataByDelegatorDelegate: number;
10
+ };
11
+ export type ExpectedCallCount = {
12
+ getExchangeDataById?: number;
13
+ createExchangeData?: number;
14
+ modifyExchangeData?: number;
15
+ getExchangeDataByParticipant?: number;
16
+ getExchangeDataByDelegatorDelegate?: number;
17
+ };
18
+ export declare class FakeExchangeDataApi extends IccExchangeDataApi {
19
+ private readonly data;
20
+ private _callCount;
21
+ get callCount(): CallCount;
22
+ compareCallCountFromBaseline(baseline: CallCount, expected: ExpectedCallCount): void;
23
+ constructor();
24
+ createExchangeData(body: ExchangeData): Promise<ExchangeData>;
25
+ modifyExchangeData(body: ExchangeData): Promise<ExchangeData>;
26
+ getExchangeDataById(exchangeDataId: string): Promise<ExchangeData>;
27
+ getExchangeDataByDelegatorDelegate(delegatorId: string, delegateId: string): Promise<ExchangeData[]>;
28
+ getExchangeDataByParticipant(dataOwnerId: string, startDocumentId?: string, limit?: number): Promise<PaginatedListExchangeData>;
29
+ getAll(): ExchangeData[];
30
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FakeExchangeDataApi = void 0;
4
+ const IccExchangeDataApi_1 = require("../../icc-api/api/internal/IccExchangeDataApi");
5
+ const ExchangeData_1 = require("../../icc-api/model/internal/ExchangeData");
6
+ const PaginatedListExchangeData_1 = require("../../icc-api/model/PaginatedListExchangeData");
7
+ const FakeGenericApi_1 = require("./FakeGenericApi");
8
+ const PaginatedDocumentKeyIdPairObject_1 = require("../../icc-api/model/PaginatedDocumentKeyIdPairObject");
9
+ const _ = require("lodash");
10
+ const chai_1 = require("chai");
11
+ class FakeExchangeDataApi extends IccExchangeDataApi_1.IccExchangeDataApi {
12
+ get callCount() {
13
+ return _.cloneDeep(this._callCount);
14
+ }
15
+ compareCallCountFromBaseline(baseline, expected) {
16
+ for (const [key, v] of Object.entries(expected)) {
17
+ const curr = this._callCount[key];
18
+ const currBaseline = baseline[key];
19
+ (0, chai_1.expect)(curr).to.equal(currBaseline + v, `Actual call count for ${key} does not match expected
20
+ Current: ${JSON.stringify(this._callCount)}
21
+ Baseline: ${JSON.stringify(baseline)}
22
+ ExpectedDifference: ${JSON.stringify(expected)}
23
+ `);
24
+ }
25
+ }
26
+ constructor() {
27
+ super('fake', {}, null, null);
28
+ this.data = new FakeGenericApi_1.FakeGenericApi();
29
+ this._callCount = {
30
+ createExchangeData: 0,
31
+ modifyExchangeData: 0,
32
+ getExchangeDataById: 0,
33
+ getExchangeDataByDelegatorDelegate: 0,
34
+ getExchangeDataByParticipant: 0,
35
+ };
36
+ }
37
+ createExchangeData(body) {
38
+ this._callCount.createExchangeData += 1;
39
+ return Promise.resolve(new ExchangeData_1.ExchangeData(this.data.createObject(body)));
40
+ }
41
+ modifyExchangeData(body) {
42
+ this._callCount.modifyExchangeData += 1;
43
+ return Promise.resolve(new ExchangeData_1.ExchangeData(this.data.modifyObject(body)));
44
+ }
45
+ getExchangeDataById(exchangeDataId) {
46
+ this._callCount.getExchangeDataById += 1;
47
+ const retrieved = this.data.getById(exchangeDataId);
48
+ if (!retrieved)
49
+ throw new Error(`Exchange data with id ${exchangeDataId} does not exist`);
50
+ return Promise.resolve(new ExchangeData_1.ExchangeData(retrieved));
51
+ }
52
+ getExchangeDataByDelegatorDelegate(delegatorId, delegateId) {
53
+ this._callCount.getExchangeDataByDelegatorDelegate += 1;
54
+ return Promise.resolve(this.data
55
+ .getAll()
56
+ .filter((x) => x.delegate === delegateId && x.delegator === delegatorId)
57
+ .map((x) => new ExchangeData_1.ExchangeData(x)));
58
+ }
59
+ getExchangeDataByParticipant(dataOwnerId, startDocumentId, limit) {
60
+ this._callCount.getExchangeDataByParticipant += 1;
61
+ const retrieved = this.data.getPaged(startDocumentId, limit !== null && limit !== void 0 ? limit : 1000);
62
+ return Promise.resolve(new PaginatedListExchangeData_1.PaginatedListExchangeData({
63
+ pageSize: retrieved.rows.length,
64
+ totalSize: retrieved.rows.length,
65
+ rows: retrieved.rows.filter((x) => x.delegator === dataOwnerId || x.delegate === dataOwnerId).map((x) => new ExchangeData_1.ExchangeData(x)),
66
+ nextKeyPair: new PaginatedDocumentKeyIdPairObject_1.PaginatedDocumentKeyIdPairObject({ startKeyDocId: retrieved.nextId }),
67
+ }));
68
+ }
69
+ getAll() {
70
+ return this.data.getAll().map((x) => new ExchangeData_1.ExchangeData(x));
71
+ }
72
+ }
73
+ exports.FakeExchangeDataApi = FakeExchangeDataApi;
74
+ //# sourceMappingURL=FakeExchangeDataApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeExchangeDataApi.js","sourceRoot":"","sources":["../../../test/utils/FakeExchangeDataApi.ts"],"names":[],"mappings":";;;AAAA,sFAAkF;AAClF,4EAAwE;AACxE,6FAAyF;AACzF,qDAAiD;AACjD,2GAAuG;AACvG,4BAA2B;AAC3B,+BAA6B;AAmB7B,MAAa,mBAAoB,SAAQ,uCAAkB;IAUzD,IAAW,SAAS;QAClB,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IAED,4BAA4B,CAAC,QAAmB,EAAE,QAA2B;QAC3E,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC/C,MAAM,IAAI,GAAI,IAAI,CAAC,UAAkB,CAAC,GAAG,CAAW,CAAA;YACpD,MAAM,YAAY,GAAI,QAAgB,CAAC,GAAG,CAAW,CAAA;YACrD,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CACnB,YAAY,GAAG,CAAC,EAChB,yBAAyB,GAAG;mBACjB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;oBAC9B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;8BACd,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;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DataApi } from '../../icc-api/api/internal/IccExchangeDataApi'\nimport { ExchangeData } from '../../icc-api/model/internal/ExchangeData'\nimport { PaginatedListExchangeData } from '../../icc-api/model/PaginatedListExchangeData'\nimport { FakeGenericApi } from './FakeGenericApi'\nimport { PaginatedDocumentKeyIdPairObject } from '../../icc-api/model/PaginatedDocumentKeyIdPairObject'\nimport * as _ from 'lodash'\nimport { expect } from 'chai'\nimport base = Mocha.reporters.base\n\nexport type CallCount = {\n getExchangeDataById: number\n createExchangeData: number\n modifyExchangeData: number\n getExchangeDataByParticipant: number\n getExchangeDataByDelegatorDelegate: number\n}\n\nexport type ExpectedCallCount = {\n getExchangeDataById?: number\n createExchangeData?: number\n modifyExchangeData?: number\n getExchangeDataByParticipant?: number\n getExchangeDataByDelegatorDelegate?: number\n}\n\nexport class FakeExchangeDataApi extends IccExchangeDataApi {\n private readonly data = new FakeGenericApi<ExchangeData>()\n private _callCount: CallCount = {\n createExchangeData: 0,\n modifyExchangeData: 0,\n getExchangeDataById: 0,\n getExchangeDataByDelegatorDelegate: 0,\n getExchangeDataByParticipant: 0,\n }\n\n public get callCount(): CallCount {\n return _.cloneDeep(this._callCount)\n }\n\n compareCallCountFromBaseline(baseline: CallCount, expected: ExpectedCallCount) {\n for (const [key, v] of Object.entries(expected)) {\n const curr = (this._callCount as any)[key] as number\n const currBaseline = (baseline as any)[key] as number\n expect(curr).to.equal(\n currBaseline + v,\n `Actual call count for ${key} does not match expected\n Current: ${JSON.stringify(this._callCount)}\n Baseline: ${JSON.stringify(baseline)}\n ExpectedDifference: ${JSON.stringify(expected)}\n `\n )\n }\n }\n\n constructor() {\n super('fake', {}, null as any, null as any)\n }\n\n createExchangeData(body: ExchangeData): Promise<ExchangeData> {\n this._callCount.createExchangeData += 1\n return Promise.resolve(new ExchangeData(this.data.createObject(body)))\n }\n\n modifyExchangeData(body: ExchangeData): Promise<ExchangeData> {\n this._callCount.modifyExchangeData += 1\n return Promise.resolve(new ExchangeData(this.data.modifyObject(body)))\n }\n\n getExchangeDataById(exchangeDataId: string): Promise<ExchangeData> {\n this._callCount.getExchangeDataById += 1\n const retrieved = this.data.getById(exchangeDataId)\n if (!retrieved) throw new Error(`Exchange data with id ${exchangeDataId} does not exist`)\n return Promise.resolve(new ExchangeData(retrieved))\n }\n\n getExchangeDataByDelegatorDelegate(delegatorId: string, delegateId: string): Promise<ExchangeData[]> {\n this._callCount.getExchangeDataByDelegatorDelegate += 1\n return Promise.resolve(\n this.data\n .getAll()\n .filter((x) => x.delegate === delegateId && x.delegator === delegatorId)\n .map((x) => new ExchangeData(x))\n )\n }\n\n getExchangeDataByParticipant(dataOwnerId: string, startDocumentId?: string, limit?: number): Promise<PaginatedListExchangeData> {\n this._callCount.getExchangeDataByParticipant += 1\n const retrieved = this.data.getPaged(startDocumentId, limit ?? 1000)\n return Promise.resolve(\n new PaginatedListExchangeData({\n pageSize: retrieved.rows.length,\n totalSize: retrieved.rows.length,\n rows: retrieved.rows.filter((x) => x.delegator === dataOwnerId || x.delegate === dataOwnerId).map((x) => new ExchangeData(x)),\n nextKeyPair: new PaginatedDocumentKeyIdPairObject({ startKeyDocId: retrieved.nextId }),\n })\n )\n }\n\n getAll(): ExchangeData[] {\n return this.data.getAll().map((x) => new ExchangeData(x))\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import { ExchangeDataManager } from '../../icc-x-api/crypto/ExchangeDataManager';
2
+ import { EntityWithDelegationTypeName } from '../../icc-x-api/utils/EntityWithDelegationTypeName';
3
+ import { ExchangeData } from '../../icc-api/model/internal/ExchangeData';
4
+ import { BaseExchangeDataManager } from '../../icc-x-api/crypto/BaseExchangeDataManager';
5
+ import { CryptoPrimitives } from '../../icc-x-api';
6
+ export declare class FakeDecryptionExchangeDataManager implements ExchangeDataManager {
7
+ private readonly expectedEntityType;
8
+ private readonly expectedSecretForeignKeys;
9
+ private readonly cryptoPrimitives;
10
+ constructor(expectedEntityType: EntityWithDelegationTypeName, expectedSecretForeignKeys: string[], cryptoPrimitives: CryptoPrimitives);
11
+ private readonly dataByHash;
12
+ private readonly dataById;
13
+ clearOrRepopulateCache(): Promise<void>;
14
+ getAccessControlKeysValue(entityType: EntityWithDelegationTypeName): Promise<string | undefined>;
15
+ getCachedDecryptionDataKeyByAccessControlHash(hashes: string[], entityType: EntityWithDelegationTypeName, entitySecretForeignKeys: string[]): Promise<{
16
+ [p: string]: {
17
+ exchangeData: ExchangeData;
18
+ exchangeKey: CryptoKey;
19
+ accessControlSecret: string;
20
+ };
21
+ }>;
22
+ getDecryptionDataKeyById(id: string, entityType: EntityWithDelegationTypeName | undefined, entitySecretForeignKeys: string[] | undefined, retrieveIfNotCached: boolean): Promise<{
23
+ exchangeKey: CryptoKey | undefined;
24
+ exchangeData: ExchangeData;
25
+ accessControlSecret: string | undefined;
26
+ } | undefined>;
27
+ getOrCreateEncryptionDataTo(delegateId: string, entityType: EntityWithDelegationTypeName | undefined, entitySecretForeignKeys: string[] | undefined): Promise<{
28
+ exchangeData: ExchangeData;
29
+ accessControlSecret: string;
30
+ exchangeKey: CryptoKey;
31
+ }>;
32
+ cacheFakeData(exchangeData: ExchangeData, keyAndHashesFromSecret: {
33
+ exchangeKey: CryptoKey;
34
+ accessControlSecret?: string;
35
+ hashes: string[];
36
+ } | undefined, fakeNonCached?: boolean): void;
37
+ giveAccessBackTo(otherDataOwner: string, newDataOwnerPublicKey: string): Promise<void>;
38
+ getAllDelegationKeys(entityType: EntityWithDelegationTypeName): Promise<string[] | undefined>;
39
+ get base(): BaseExchangeDataManager;
40
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FakeDecryptionExchangeDataManager = void 0;
13
+ const chai_1 = require("chai");
14
+ class FakeDecryptionExchangeDataManager {
15
+ constructor(expectedEntityType, expectedSecretForeignKeys, cryptoPrimitives) {
16
+ this.expectedEntityType = expectedEntityType;
17
+ this.expectedSecretForeignKeys = expectedSecretForeignKeys;
18
+ this.cryptoPrimitives = cryptoPrimitives;
19
+ this.dataByHash = {};
20
+ this.dataById = {};
21
+ }
22
+ clearOrRepopulateCache() {
23
+ throw new Error('This method is not supported by fake exchange data manager and should not be used.');
24
+ }
25
+ getAccessControlKeysValue(entityType) {
26
+ throw new Error('This method is not supported by fake exchange data manager and should not be used.');
27
+ }
28
+ getCachedDecryptionDataKeyByAccessControlHash(hashes, entityType, entitySecretForeignKeys) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ (0, chai_1.expect)(entityType).to.equal(this.expectedEntityType);
31
+ (0, chai_1.expect)(entitySecretForeignKeys).to.equal(this.expectedSecretForeignKeys);
32
+ const res = {};
33
+ for (const hash of hashes) {
34
+ const retrieved = this.dataByHash[hash];
35
+ if (retrieved)
36
+ res[hash] = retrieved;
37
+ }
38
+ return res;
39
+ });
40
+ }
41
+ getDecryptionDataKeyById(id, entityType, entitySecretForeignKeys, retrieveIfNotCached) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ (0, chai_1.expect)(entityType).to.equal(this.expectedEntityType);
44
+ (0, chai_1.expect)(entitySecretForeignKeys).to.equal(this.expectedSecretForeignKeys);
45
+ const retrieved = this.dataById[id];
46
+ if (retrieved) {
47
+ if (retrieveIfNotCached || !retrieved.fakeNonCached) {
48
+ return retrieved;
49
+ }
50
+ else
51
+ return undefined;
52
+ }
53
+ else if (!retrieveIfNotCached) {
54
+ return undefined;
55
+ }
56
+ else
57
+ throw new Error('Exchange data does not exist.');
58
+ });
59
+ }
60
+ getOrCreateEncryptionDataTo(delegateId, entityType, entitySecretForeignKeys) {
61
+ throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported');
62
+ }
63
+ cacheFakeData(exchangeData, keyAndHashesFromSecret, fakeNonCached) {
64
+ var _a;
65
+ const acSecret = !!keyAndHashesFromSecret ? (_a = keyAndHashesFromSecret.accessControlSecret) !== null && _a !== void 0 ? _a : this.cryptoPrimitives.randomUuid() : undefined;
66
+ this.dataById[exchangeData.id] = {
67
+ exchangeData,
68
+ exchangeKey: keyAndHashesFromSecret === null || keyAndHashesFromSecret === void 0 ? void 0 : keyAndHashesFromSecret.exchangeKey,
69
+ fakeNonCached: fakeNonCached !== null && fakeNonCached !== void 0 ? fakeNonCached : false,
70
+ accessControlSecret: acSecret,
71
+ };
72
+ if (keyAndHashesFromSecret) {
73
+ for (const hash of keyAndHashesFromSecret.hashes) {
74
+ this.dataByHash[hash] = { exchangeData, exchangeKey: keyAndHashesFromSecret.exchangeKey, accessControlSecret: acSecret };
75
+ }
76
+ }
77
+ }
78
+ giveAccessBackTo(otherDataOwner, newDataOwnerPublicKey) {
79
+ throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported');
80
+ }
81
+ getAllDelegationKeys(entityType) {
82
+ throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported');
83
+ }
84
+ get base() {
85
+ throw new Error('This method should not be used with this fake exchange data manager: only retrieval decryption data is supported');
86
+ }
87
+ }
88
+ exports.FakeDecryptionExchangeDataManager = FakeDecryptionExchangeDataManager;
89
+ //# sourceMappingURL=FakeExchangeDataManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeExchangeDataManager.js","sourceRoot":"","sources":["../../../test/utils/FakeExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,+BAA6B;AAI7B,MAAa,iCAAiC;IAC5C,YACmB,kBAAgD,EAChD,yBAAmC,EACnC,gBAAk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AAM,IAAI,KAAK,CAAC,kHAAkH,CAAC,CAAA;IACrI,CAAC;IAED,IAAI,IAAI;QACN,MAAM,IAAI,KAAK,CAAC,kHAAkH,CAAC,CAAA;IACrI,CAAC;CACF;AAjGD,8EAiGC","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'\n\nexport class FakeDecryptionExchangeDataManager implements ExchangeDataManager {\n constructor(\n private readonly expectedEntityType: EntityWithDelegationTypeName,\n private readonly expectedSecretForeignKeys: string[],\n private readonly cryptoPrimitives: CryptoPrimitives\n ) {}\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 entityType: EntityWithDelegationTypeName,\n entitySecretForeignKeys: string[]\n ): Promise<{ [p: string]: { exchangeData: ExchangeData; exchangeKey: CryptoKey; accessControlSecret: string } }> {\n expect(entityType).to.equal(this.expectedEntityType)\n expect(entitySecretForeignKeys).to.equal(this.expectedSecretForeignKeys)\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 getDecryptionDataKeyById(\n id: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined,\n retrieveIfNotCached: boolean\n ): Promise<{ exchangeKey: CryptoKey | undefined; exchangeData: ExchangeData; accessControlSecret: string | undefined } | undefined> {\n expect(entityType).to.equal(this.expectedEntityType)\n expect(entitySecretForeignKeys).to.equal(this.expectedSecretForeignKeys)\n const retrieved = this.dataById[id]\n if (retrieved) {\n if (retrieveIfNotCached || !retrieved.fakeNonCached) {\n return retrieved\n } else return undefined\n } else if (!retrieveIfNotCached) {\n return undefined\n } else throw new Error('Exchange data does not exist.')\n }\n\n getOrCreateEncryptionDataTo(\n delegateId: string,\n entityType: EntityWithDelegationTypeName | undefined,\n entitySecretForeignKeys: string[] | undefined\n ): Promise<{ exchangeData: ExchangeData; accessControlSecret: string; exchangeKey: 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"]}
@@ -0,0 +1,12 @@
1
+ import { ExchangeDataMapManager } from '../../icc-x-api/crypto/ExchangeDataMapManager';
2
+ import { ExchangeDataMap } from '../../icc-api/model/internal/ExchangeDataMap';
3
+ export declare class FakeExchangeDataMapManager extends ExchangeDataMapManager {
4
+ private fakeApi;
5
+ constructor();
6
+ createExchangeDataMaps(batch: {
7
+ [accessControlKeyHash: string]: {
8
+ [fp: string]: string;
9
+ };
10
+ }): Promise<void>;
11
+ getExchangeDataMapBatch(accessControlKeyHashes: string[]): Promise<ExchangeDataMap[]>;
12
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FakeExchangeDataMapManager = void 0;
13
+ const ExchangeDataMapManager_1 = require("../../icc-x-api/crypto/ExchangeDataMapManager");
14
+ const IccExchangeDataMapApi_1 = require("../../icc-api/api/internal/IccExchangeDataMapApi");
15
+ const ExchangeDataMap_1 = require("../../icc-api/model/internal/ExchangeDataMap");
16
+ const FakeGenericApi_1 = require("./FakeGenericApi");
17
+ class FakeExchangeDataMapManager extends ExchangeDataMapManager_1.ExchangeDataMapManager {
18
+ constructor() {
19
+ super(new IccExchangeDataMapApi_1.IccExchangeDataMapApi('', {}));
20
+ this.fakeApi = new FakeGenericApi_1.FakeGenericApi();
21
+ }
22
+ createExchangeDataMaps(batch) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ Object.entries(batch).forEach(([hash, encryptedIds]) => {
25
+ this.fakeApi.createObject(new ExchangeDataMap_1.ExchangeDataMap({ id: hash, encryptedExchangeDataIds: encryptedIds }));
26
+ });
27
+ });
28
+ }
29
+ getExchangeDataMapBatch(accessControlKeyHashes) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return accessControlKeyHashes.reduce((prev, curr) => {
32
+ return [...prev, this.fakeApi.getById(curr)];
33
+ }, []);
34
+ });
35
+ }
36
+ }
37
+ exports.FakeExchangeDataMapManager = FakeExchangeDataMapManager;
38
+ //# sourceMappingURL=FakeExchangeDataMapManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeExchangeDataMapManager.js","sourceRoot":"","sources":["../../../test/utils/FakeExchangeDataMapManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0FAAsF;AACtF,4FAAwF;AACxF,kFAA8E;AAC9E,qDAAiD;AAEjD,MAAa,0BAA2B,SAAQ,+CAAsB;IAGpE;QACE,KAAK,CAAC,IAAI,6CAAqB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;QAHlC,YAAO,GAAG,IAAI,+BAAc,EAAmB,CAAA;IAIvD,CAAC;IAEK,sBAAsB,CAAC,KAAmE;;YAC9F,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,EAAE;gBACrD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,iCAAe,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,YAAY,EAAE,CAAC,CAAC,CAAA;YACtG,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAEK,uBAAuB,CAAC,sBAAgC;;YAC5D,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;gBAClD,OAAO,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAE,CAAC,CAAA;YAC/C,CAAC,EAAE,EAAuB,CAAC,CAAA;QAC7B,CAAC;KAAA;CACF;AAlBD,gEAkBC","sourcesContent":["import { ExchangeDataMapManager } from '../../icc-x-api/crypto/ExchangeDataMapManager'\nimport { IccExchangeDataMapApi } from '../../icc-api/api/internal/IccExchangeDataMapApi'\nimport { ExchangeDataMap } from '../../icc-api/model/internal/ExchangeDataMap'\nimport { FakeGenericApi } from './FakeGenericApi'\n\nexport class FakeExchangeDataMapManager extends ExchangeDataMapManager {\n private fakeApi = new FakeGenericApi<ExchangeDataMap>()\n\n constructor() {\n super(new IccExchangeDataMapApi('', {}))\n }\n\n async createExchangeDataMaps(batch: { [accessControlKeyHash: string]: { [fp: string]: string } }): Promise<void> {\n Object.entries(batch).forEach(([hash, encryptedIds]) => {\n this.fakeApi.createObject(new ExchangeDataMap({ id: hash, encryptedExchangeDataIds: encryptedIds }))\n })\n }\n\n async getExchangeDataMapBatch(accessControlKeyHashes: string[]): Promise<ExchangeDataMap[]> {\n return accessControlKeyHashes.reduce((prev, curr) => {\n return [...prev, this.fakeApi.getById(curr)!]\n }, [] as ExchangeDataMap[])\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ export declare class FakeGenericApi<T extends {
2
+ id?: string;
3
+ rev?: string;
4
+ }> {
5
+ private readonly data;
6
+ private readonly primitives;
7
+ createObject(obj: T): T;
8
+ modifyObject(obj: T): T;
9
+ getAll(): T[];
10
+ getPaged(startId: string | undefined, limit: number): {
11
+ rows: T[];
12
+ nextId: string | undefined;
13
+ };
14
+ getById(id: string): T | undefined;
15
+ private nextRev;
16
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FakeGenericApi = void 0;
4
+ const _ = require("lodash");
5
+ const CryptoPrimitives_1 = require("../../icc-x-api/crypto/CryptoPrimitives");
6
+ const crypto_1 = require("crypto");
7
+ class FakeGenericApi {
8
+ constructor() {
9
+ this.data = new Map();
10
+ this.primitives = new CryptoPrimitives_1.CryptoPrimitives(crypto_1.webcrypto);
11
+ }
12
+ createObject(obj) {
13
+ if (!obj.id)
14
+ throw new Error(`New object should have id`);
15
+ if (obj.rev)
16
+ throw new Error(`New object should not have rev`);
17
+ if (this.data.get(obj.id))
18
+ throw new Error(`Object with id ${obj.id} already exists.`);
19
+ const withRev = _.cloneDeep(obj);
20
+ withRev.rev = this.nextRev(withRev.rev);
21
+ this.data.set(obj.id, withRev);
22
+ return _.cloneDeep(withRev);
23
+ }
24
+ modifyObject(obj) {
25
+ if (!obj.id)
26
+ throw new Error(`Modified object should have id`);
27
+ const existing = this.data.get(obj.id);
28
+ if (!existing)
29
+ throw new Error(`No object with id ${obj.id}`);
30
+ if (existing.rev !== obj.rev)
31
+ throw new Error(`Object with id ${obj.id} has wrong rev: ${obj.rev} but expected ${existing.rev}.`);
32
+ const withNewRev = _.cloneDeep(obj);
33
+ withNewRev.rev = this.nextRev(withNewRev.rev);
34
+ this.data.set(obj.id, withNewRev);
35
+ return _.cloneDeep(withNewRev);
36
+ }
37
+ getAll() {
38
+ return [...this.data.values()].map((x) => _.cloneDeep(x));
39
+ }
40
+ getPaged(startId, limit) {
41
+ let rows = [...this.data.values()];
42
+ let nextId = undefined;
43
+ if (startId) {
44
+ const startIndex = rows.findIndex((x) => x.id === startId);
45
+ rows = rows.slice(startIndex);
46
+ }
47
+ if (rows.length > limit) {
48
+ nextId = rows[limit].id;
49
+ rows = rows.slice(0, limit);
50
+ }
51
+ return { rows: rows.map((x) => _.cloneDeep(x)), nextId };
52
+ }
53
+ getById(id) {
54
+ const retrieved = this.data.get(id);
55
+ return retrieved ? _.cloneDeep(retrieved) : undefined;
56
+ }
57
+ nextRev(rev) {
58
+ if (!rev)
59
+ return `1-${this.primitives.randomUuid()}`;
60
+ const prevRevNumber = parseInt(rev.split('-')[0]);
61
+ return `${prevRevNumber + 1}-${this.primitives.randomUuid()}`;
62
+ }
63
+ }
64
+ exports.FakeGenericApi = FakeGenericApi;
65
+ //# sourceMappingURL=FakeGenericApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeGenericApi.js","sourceRoot":"","sources":["../../../test/utils/FakeGenericApi.ts"],"names":[],"mappings":";;;AAAA,4BAA2B;AAC3B,8EAA0E;AAC1E,mCAAkC;AAElC,MAAa,cAAc;IAA3B;QACmB,SAAI,GAAmB,IAAI,GAAG,EAAE,CAAA;QAChC,eAAU,GAAqB,IAAI,mCAAgB,CAAC,kBAAgB,CAAC,CAAA;IAyDxF,CAAC;IAvDC,YAAY,CAAC,GAAM;QACjB,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QACzD,IAAI,GAAG,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;QAC9D,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAAA;QACvF,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAChC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QAC9B,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;IAED,YAAY,CAAC,GAAM;QACjB,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,gC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U,CAAC,CAAA;SAC9B;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE;YACvB,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;YACvB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;SAC5B;QACD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1D,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACnC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACvD,CAAC;IAEO,OAAO,CAAC,GAAuB;QACrC,IAAI,CAAC,GAAG;YAAE,OAAO,KAAK,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,CAAA;QACpD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACjD,OAAO,GAAG,aAAa,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,CAAA;IAC/D,CAAC;CACF;AA3DD,wCA2DC","sourcesContent":["import * as _ from 'lodash'\nimport { CryptoPrimitives } from '../../icc-x-api/crypto/CryptoPrimitives'\nimport { webcrypto } from 'crypto'\n\nexport class FakeGenericApi<T extends { id?: string; rev?: string }> {\n private readonly data: Map<string, T> = new Map()\n private readonly primitives: CryptoPrimitives = new CryptoPrimitives(webcrypto as any)\n\n createObject(obj: T): T {\n if (!obj.id) throw new Error(`New object should have id`)\n if (obj.rev) throw new Error(`New object should not have rev`)\n if (this.data.get(obj.id!)) throw new Error(`Object with id ${obj.id} already exists.`)\n const withRev = _.cloneDeep(obj)\n withRev.rev = this.nextRev(withRev.rev)\n this.data.set(obj.id, withRev)\n return _.cloneDeep(withRev)\n }\n\n modifyObject(obj: T): T {\n if (!obj.id) throw new Error(`Modified object should have id`)\n const existing = this.data.get(obj.id!)\n if (!existing) throw new Error(`No object with id ${obj.id}`)\n if (existing.rev !== obj.rev) throw new Error(`Object with id ${obj.id} has wrong rev: ${obj.rev} but expected ${existing.rev}.`)\n const withNewRev = _.cloneDeep(obj)\n withNewRev.rev = this.nextRev(withNewRev.rev)\n this.data.set(obj.id, withNewRev)\n return _.cloneDeep(withNewRev)\n }\n\n getAll(): T[] {\n return [...this.data.values()].map((x) => _.cloneDeep(x))\n }\n\n getPaged(\n startId: string | undefined,\n limit: number\n ): {\n rows: T[]\n nextId: string | undefined\n } {\n let rows = [...this.data.values()]\n let nextId = undefined\n if (startId) {\n const startIndex = rows.findIndex((x) => x.id === startId)\n rows = rows.slice(startIndex)\n }\n if (rows.length > limit) {\n nextId = rows[limit].id\n rows = rows.slice(0, limit)\n }\n return { rows: rows.map((x) => _.cloneDeep(x)), nextId }\n }\n\n getById(id: string): T | undefined {\n const retrieved = this.data.get(id)\n return retrieved ? _.cloneDeep(retrieved) : undefined\n }\n\n private nextRev(rev: string | undefined): string {\n if (!rev) return `1-${this.primitives.randomUuid()}`\n const prevRevNumber = parseInt(rev.split('-')[0])\n return `${prevRevNumber + 1}-${this.primitives.randomUuid()}`\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { KeyPair } from '../../icc-x-api/crypto/RSA';
2
+ import { UserSignatureKeysManager } from '../../icc-x-api/crypto/UserSignatureKeysManager';
3
+ import { CryptoPrimitives } from '../../icc-x-api/crypto/CryptoPrimitives';
4
+ export declare class FakeSignatureKeysManager extends UserSignatureKeysManager {
5
+ private readonly _primitives;
6
+ constructor(_primitives: CryptoPrimitives);
7
+ private signatureKeypair;
8
+ private extraKeys;
9
+ getSignatureVerificationKey(fingerprint: string): Promise<CryptoKey | undefined>;
10
+ getOrCreateSignatureKeyPair(): Promise<{
11
+ fingerprint: string;
12
+ keyPair: KeyPair<CryptoKey>;
13
+ }>;
14
+ addVerificationKey(key: CryptoKey): Promise<string>;
15
+ clearKeys(): void;
16
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FakeSignatureKeysManager = void 0;
13
+ const UserSignatureKeysManager_1 = require("../../icc-x-api/crypto/UserSignatureKeysManager");
14
+ const icc_x_api_1 = require("../../icc-x-api");
15
+ class FakeSignatureKeysManager extends UserSignatureKeysManager_1.UserSignatureKeysManager {
16
+ constructor(_primitives) {
17
+ super(null, null, _primitives);
18
+ this._primitives = _primitives;
19
+ this.extraKeys = new Map();
20
+ }
21
+ getSignatureVerificationKey(fingerprint) {
22
+ var _a;
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if (((_a = this.signatureKeypair) === null || _a === void 0 ? void 0 : _a.fingerprint) === fingerprint) {
25
+ return this.signatureKeypair.keyPair.publicKey;
26
+ }
27
+ else
28
+ return this.extraKeys.get(fingerprint);
29
+ });
30
+ }
31
+ getOrCreateSignatureKeyPair() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ if (!this.signatureKeypair) {
34
+ const keyPair = yield this._primitives.RSA.generateSignatureKeyPair();
35
+ const fingerprint = (0, icc_x_api_1.ua2hex)(yield this._primitives.RSA.exportKey(keyPair.publicKey, 'spki')).slice(-32);
36
+ this.signatureKeypair = { keyPair, fingerprint };
37
+ }
38
+ return this.signatureKeypair;
39
+ });
40
+ }
41
+ addVerificationKey(key) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const fingerprint = (0, icc_x_api_1.ua2hex)(yield this._primitives.RSA.exportKey(key, 'spki')).slice(-32);
44
+ this.extraKeys.set(fingerprint, key);
45
+ return fingerprint;
46
+ });
47
+ }
48
+ clearKeys() {
49
+ this.extraKeys.clear();
50
+ this.signatureKeypair = undefined;
51
+ }
52
+ }
53
+ exports.FakeSignatureKeysManager = FakeSignatureKeysManager;
54
+ //# sourceMappingURL=FakeSignatureKeysManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeSignatureKeysManager.js","sourceRoot":"","sources":["../../../test/utils/FakeSignatureKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8FAA0F;AAE1F,+CAAwC;AAExC,MAAa,wBAAyB,SAAQ,mDAAwB;IACpE,YAA6B,WAA6B;QACxD,KAAK,CAAC,IAAW,EAAE,IAAW,EAAE,WAAW,CAAC,CAAA;QADjB,gBAAW,GAAX,WAAW,CAAkB;QAKlD,cAAS,GAA2B,IAAI,GAAG,EAAE,CAAA;IAHrD,CAAC;IAKK,2BAA2B,CAAC,WAAmB;;;YACnD,IAAI,CAAA,MAAA,IAAI,CAAC,gBAAgB,0CAAE,WAAW,MAAK,WAAW,EAAE;gBACtD,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAA;aAC/C;;gBAAM,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;;KAC9C;IAEK,2BAA2B;;YAC/B,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,wBAAwB,EAAE,CAAA;gBACrE,MAAM,WAAW,GAAG,IAAA,kBAAM,EAAC,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;gBACtG,IAAI,CAAC,gBAAgB,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,CAAA;aACjD;YACD,OAAO,IAAI,CAAC,gBAAiB,CAAA;QAC/B,CAAC;KAAA;IAEK,kBAAkB,CAAC,GAAc;;YACrC,MAAM,WAAW,GAAG,IAAA,kBAAM,EAAC,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;YACxF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;YACpC,OAAO,WAAW,CAAA;QACpB,CAAC;KAAA;IAED,SAAS;QACP,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;QACtB,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAA;IACnC,CAAC;CACF;AAjCD,4DAiCC","sourcesContent":["import { KeyPair } from '../../icc-x-api/crypto/RSA'\nimport { UserSignatureKeysManager } from '../../icc-x-api/crypto/UserSignatureKeysManager'\nimport { CryptoPrimitives } from '../../icc-x-api/crypto/CryptoPrimitives'\nimport { ua2hex } from '../../icc-x-api'\n\nexport class FakeSignatureKeysManager extends UserSignatureKeysManager {\n constructor(private readonly _primitives: CryptoPrimitives) {\n super(null as any, null as any, _primitives)\n }\n\n private signatureKeypair: { fingerprint: string; keyPair: KeyPair<CryptoKey> } | undefined\n private extraKeys: Map<string, CryptoKey> = new Map()\n\n async getSignatureVerificationKey(fingerprint: string): Promise<CryptoKey | undefined> {\n if (this.signatureKeypair?.fingerprint === fingerprint) {\n return this.signatureKeypair.keyPair.publicKey\n } else return this.extraKeys.get(fingerprint)\n }\n\n async getOrCreateSignatureKeyPair(): Promise<{ fingerprint: string; keyPair: KeyPair<CryptoKey> }> {\n if (!this.signatureKeypair) {\n const keyPair = await this._primitives.RSA.generateSignatureKeyPair()\n const fingerprint = ua2hex(await this._primitives.RSA.exportKey(keyPair.publicKey, 'spki')).slice(-32)\n this.signatureKeypair = { keyPair, fingerprint }\n }\n return this.signatureKeypair!\n }\n\n async addVerificationKey(key: CryptoKey): Promise<string> {\n const fingerprint = ua2hex(await this._primitives.RSA.exportKey(key, 'spki')).slice(-32)\n this.extraKeys.set(fingerprint, key)\n return fingerprint\n }\n\n clearKeys() {\n this.extraKeys.clear()\n this.signatureKeypair = undefined\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { IcureApi, IcureApiOptions, KeyPair } from '../../icc-x-api';
2
+ import 'isomorphic-fetch';
3
+ export declare const TestApi: (host: string, username: string, password: string, crypto?: Crypto, keyPair?: KeyPair<CryptoKey>, options?: IcureApiOptions) => Promise<IcureApi>;