@icure/api 6.4.0 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/icc-api/api/IccDeviceApi.d.ts +1 -1
- package/icc-api/api/IccDeviceApi.js.map +1 -1
- package/icc-api/api/IccDoctemplateApi.js.map +1 -1
- package/icc-api/api/IccDocumentTemplateApi.js.map +1 -1
- package/icc-api/api/IccHcpartyApi.d.ts +1 -1
- package/icc-api/api/IccHcpartyApi.js.map +1 -1
- package/icc-api/api/IccPatientApi.d.ts +1 -1
- package/icc-api/api/IccPatientApi.js.map +1 -1
- package/icc-api/model/MaintenanceTask.d.ts +6 -5
- package/icc-api/model/MaintenanceTask.js +5 -0
- package/icc-api/model/MaintenanceTask.js.map +1 -1
- package/icc-api/model/User.d.ts +23 -1
- package/icc-api/model/User.js +21 -0
- package/icc-api/model/User.js.map +1 -1
- package/icc-api/model/models.d.ts +14 -0
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/crypto/AES.d.ts +2 -0
- package/icc-x-api/crypto/AES.js +12 -0
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/crypto/BaseExchangeKeysManager.d.ts +122 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.js +356 -0
- package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -0
- package/icc-x-api/crypto/ConfidentialEntities.d.ts +58 -0
- package/icc-x-api/crypto/ConfidentialEntities.js +99 -0
- package/icc-x-api/crypto/ConfidentialEntities.js.map +1 -0
- package/icc-x-api/crypto/CryptoPrimitives.d.ts +31 -0
- package/icc-x-api/crypto/CryptoPrimitives.js +55 -0
- package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -0
- package/icc-x-api/crypto/CryptoStrategies.d.ts +82 -0
- package/icc-x-api/crypto/CryptoStrategies.js +3 -0
- package/icc-x-api/crypto/CryptoStrategies.js.map +1 -0
- package/icc-x-api/crypto/EntitiesEncryption.d.ts +254 -0
- package/icc-x-api/crypto/EntitiesEncryption.js +700 -0
- package/icc-x-api/crypto/EntitiesEncryption.js.map +1 -0
- package/icc-x-api/crypto/ExchangeKeysManager.d.ts +56 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js +147 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -0
- package/icc-x-api/crypto/KeyManager.d.ts +103 -0
- package/icc-x-api/crypto/KeyManager.js +288 -0
- package/icc-x-api/crypto/KeyManager.js.map +1 -0
- package/icc-x-api/crypto/KeyRecovery.d.ts +34 -0
- package/icc-x-api/crypto/KeyRecovery.js +253 -0
- package/icc-x-api/crypto/KeyRecovery.js.map +1 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.d.ts +28 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.js +22 -0
- package/icc-x-api/crypto/LegacyCryptoStrategies.js.map +1 -0
- package/icc-x-api/crypto/RSA.d.ts +19 -20
- package/icc-x-api/crypto/RSA.js +30 -1
- package/icc-x-api/crypto/RSA.js.map +1 -1
- package/icc-x-api/crypto/ShamirKeysManager.d.ts +43 -0
- package/icc-x-api/crypto/ShamirKeysManager.js +150 -0
- package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.d.ts +19 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.js +24 -0
- package/icc-x-api/crypto/ShareMetadataBehaviour.js.map +1 -0
- package/icc-x-api/crypto/TransferKeysManager.d.ts +29 -0
- package/icc-x-api/crypto/TransferKeysManager.js +121 -0
- package/icc-x-api/crypto/TransferKeysManager.js.map +1 -0
- package/icc-x-api/crypto/utils.d.ts +46 -0
- package/icc-x-api/crypto/utils.js +128 -0
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.d.ts +11 -0
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js +11 -0
- package/icc-x-api/filters/ContactByHcPartyTagCodeDateFilter.js.map +1 -1
- package/icc-x-api/filters/DeviceByHcPartyFilter.d.ts +11 -0
- package/icc-x-api/filters/DeviceByHcPartyFilter.js +11 -0
- package/icc-x-api/filters/DeviceByHcPartyFilter.js.map +1 -1
- package/icc-x-api/filters/DeviceByIdsFilter.d.ts +11 -0
- package/icc-x-api/filters/DeviceByIdsFilter.js +11 -0
- package/icc-x-api/filters/DeviceByIdsFilter.js.map +1 -1
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.d.ts +11 -0
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js +11 -0
- package/icc-x-api/filters/HealthElementByHcPartySecretForeignKeysFilter.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +49 -4
- package/icc-x-api/icc-accesslog-x-api.js +112 -102
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +53 -5
- package/icc-x-api/icc-calendar-item-x-api.js +112 -100
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +45 -2
- package/icc-x-api/icc-classification-x-api.js +89 -41
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +57 -19
- package/icc-x-api/icc-contact-x-api.js +149 -154
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +266 -366
- package/icc-x-api/icc-crypto-x-api.js +416 -1327
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.d.ts +110 -11
- package/icc-x-api/icc-data-owner-x-api.js +188 -14
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
- package/icc-x-api/icc-doctemplate-x-api.js +3 -3
- package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +76 -5
- package/icc-x-api/icc-document-x-api.js +137 -59
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +47 -7
- package/icc-x-api/icc-form-x-api.js +85 -86
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.d.ts +1 -1
- package/icc-x-api/icc-hcparty-x-api.js +1 -1
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +50 -3
- package/icc-x-api/icc-helement-x-api.js +101 -118
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-icure-maintenance-x-api.d.ts +31 -0
- package/icc-x-api/icc-icure-maintenance-x-api.js +124 -0
- package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -0
- package/icc-x-api/icc-invoice-x-api.d.ts +45 -5
- package/icc-x-api/icc-invoice-x-api.js +89 -64
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +38 -6
- package/icc-x-api/icc-maintenance-task-x-api.js +73 -102
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +55 -2
- package/icc-x-api/icc-message-x-api.js +92 -33
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +67 -7
- package/icc-x-api/icc-patient-x-api.js +409 -473
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +49 -5
- package/icc-x-api/icc-receipt-x-api.js +85 -47
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +34 -10
- package/icc-x-api/icc-time-table-x-api.js +61 -18
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +30 -1
- package/icc-x-api/index.js +112 -49
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/maintenance/KeyPairUpdateRequest.d.ts +35 -0
- package/icc-x-api/maintenance/KeyPairUpdateRequest.js +54 -0
- package/icc-x-api/maintenance/KeyPairUpdateRequest.js.map +1 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.d.ts +9 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js +23 -0
- package/icc-x-api/storage/DefaultStorageEntryKeysFactory.js.map +1 -0
- package/icc-x-api/storage/IcureStorageFacade.d.ts +55 -0
- package/icc-x-api/storage/IcureStorageFacade.js +95 -0
- package/icc-x-api/storage/IcureStorageFacade.js.map +1 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.d.ts +31 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.js +3 -0
- package/icc-x-api/storage/StorageEntryKeysFactory.js.map +1 -0
- package/icc-x-api/utils/collection-utils.d.ts +8 -0
- package/icc-x-api/utils/collection-utils.js +26 -0
- package/icc-x-api/utils/collection-utils.js.map +1 -0
- package/icc-x-api/utils/crypto-utils.d.ts +8 -1
- package/icc-x-api/utils/crypto-utils.js +19 -3
- package/icc-x-api/utils/crypto-utils.js.map +1 -1
- package/icc-x-api/utils/graph-utils.d.ts +45 -0
- package/icc-x-api/utils/graph-utils.js +203 -0
- package/icc-x-api/utils/graph-utils.js.map +1 -0
- package/icc-x-api/utils/lru-temporised-async-cache.d.ts +27 -0
- package/icc-x-api/utils/lru-temporised-async-cache.js +120 -0
- package/icc-x-api/utils/lru-temporised-async-cache.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specifies the entry keys to use for storage of data needed by iCure.
|
|
3
|
+
*/
|
|
4
|
+
export interface StorageEntryKeysFactory {
|
|
5
|
+
/**
|
|
6
|
+
* Get the entry key for the storage of a key pair of a data owner which was created on this device. All keys created on this device will be
|
|
7
|
+
* considered as verified and safe.
|
|
8
|
+
* This entry key will be used in a {@link KeyStorageFacade}.
|
|
9
|
+
* @param dataOwnerId Id of a data owner.
|
|
10
|
+
* @param publicKeyFingerprint Fingerprint of the public key in a keypair of the data owner.
|
|
11
|
+
* @return entry key for the keypair.
|
|
12
|
+
*/
|
|
13
|
+
deviceKeypairOfDataOwner(dataOwnerId: string, publicKeyFingerprint: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the entry key for the storage of a key pair of a data owner which was recovered from transfer keys or shamir.
|
|
16
|
+
* These keys are going to be considered as UNSAFE for encryption unless their public key has been verified by the human user and has been stored in
|
|
17
|
+
* {@link selfPublicKeysVerificationCacheForDataOwner}.
|
|
18
|
+
* This entry key will be used in a {@link KeyStorageFacade}.
|
|
19
|
+
* @param dataOwnerId Id of a data owner.
|
|
20
|
+
* @param publicKeyFingerprint Fingerprint of the public key in a keypair of the data owner.
|
|
21
|
+
* @return entry key for the keypair.
|
|
22
|
+
*/
|
|
23
|
+
cachedRecoveredKeypairOfDataOwner(dataOwnerId: string, publicKeyFingerprint: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get the entry key for the storage of answers to own public key verification (from {@link CryptoStrategies.verifyOwnPublicKeys}).
|
|
26
|
+
* This entry key will be used in a {@link StorageFacade}.
|
|
27
|
+
* @param dataOwnerId Id of a data owner.
|
|
28
|
+
* @return entry key for verified public keys of the data owner.
|
|
29
|
+
*/
|
|
30
|
+
selfPublicKeysVerificationCacheForDataOwner(dataOwnerId: string): string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageEntryKeysFactory.js","sourceRoot":"","sources":["../../../icc-x-api/storage/StorageEntryKeysFactory.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Specifies the entry keys to use for storage of data needed by iCure.\n */\nexport interface StorageEntryKeysFactory {\n /**\n * Get the entry key for the storage of a key pair of a data owner which was created on this device. All keys created on this device will be\n * considered as verified and safe.\n * This entry key will be used in a {@link KeyStorageFacade}.\n * @param dataOwnerId Id of a data owner.\n * @param publicKeyFingerprint Fingerprint of the public key in a keypair of the data owner.\n * @return entry key for the keypair.\n */\n deviceKeypairOfDataOwner(dataOwnerId: string, publicKeyFingerprint: string): string\n\n /**\n * Get the entry key for the storage of a key pair of a data owner which was recovered from transfer keys or shamir.\n * These keys are going to be considered as UNSAFE for encryption unless their public key has been verified by the human user and has been stored in\n * {@link selfPublicKeysVerificationCacheForDataOwner}.\n * This entry key will be used in a {@link KeyStorageFacade}.\n * @param dataOwnerId Id of a data owner.\n * @param publicKeyFingerprint Fingerprint of the public key in a keypair of the data owner.\n * @return entry key for the keypair.\n */\n cachedRecoveredKeypairOfDataOwner(dataOwnerId: string, publicKeyFingerprint: string): string\n\n /**\n * Get the entry key for the storage of answers to own public key verification (from {@link CryptoStrategies.verifyOwnPublicKeys}).\n * This entry key will be used in a {@link StorageFacade}.\n * @param dataOwnerId Id of a data owner.\n * @return entry key for verified public keys of the data owner.\n */\n selfPublicKeysVerificationCacheForDataOwner(dataOwnerId: string): string\n\n /*\n * There is no need to store verified public keys for other data owners: we verify only when we want to create a new exchange key, and we need to\n * create an exchange key to each user only once unless we lose our key. But we can lose our key only if we delete our data, which means we would\n * also used the verified keys for other data owners...\n */\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if two sets are equals (they contain the same elements). Will not work if the content can't be compared by `==`.
|
|
3
|
+
*/
|
|
4
|
+
export declare function setEquals<T>(setA: Set<T>, setB: Set<T>): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Check if two arrays are equals (they contain the same elements). Will not work if the content can't be compared by `==`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function arrayEquals<T>(arrayA: T[], arrayB: T[]): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arrayEquals = exports.setEquals = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if two sets are equals (they contain the same elements). Will not work if the content can't be compared by `==`.
|
|
6
|
+
*/
|
|
7
|
+
function setEquals(setA, setB) {
|
|
8
|
+
if (setA.size != setB.size)
|
|
9
|
+
return false;
|
|
10
|
+
return Array.from(setA).every((x) => setB.has(x));
|
|
11
|
+
}
|
|
12
|
+
exports.setEquals = setEquals;
|
|
13
|
+
/**
|
|
14
|
+
* Check if two arrays are equals (they contain the same elements). Will not work if the content can't be compared by `==`.
|
|
15
|
+
*/
|
|
16
|
+
function arrayEquals(arrayA, arrayB) {
|
|
17
|
+
if (arrayA.length != arrayB.length)
|
|
18
|
+
return false;
|
|
19
|
+
for (let i = 0; i < arrayA.length; ++i) {
|
|
20
|
+
if (arrayA[i] !== arrayB[i])
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
exports.arrayEquals = arrayEquals;
|
|
26
|
+
//# sourceMappingURL=collection-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-utils.js","sourceRoot":"","sources":["../../../icc-x-api/utils/collection-utils.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,SAAS,CAAI,IAAY,EAAE,IAAY;IACrD,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAHD,8BAGC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAI,MAAW,EAAE,MAAW;IACrD,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACtC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;KAC1C;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAND,kCAMC","sourcesContent":["/**\n * Check if two sets are equals (they contain the same elements). Will not work if the content can't be compared by `==`.\n */\nexport function setEquals<T>(setA: Set<T>, setB: Set<T>): boolean {\n if (setA.size != setB.size) return false\n return Array.from(setA).every((x) => setB.has(x))\n}\n\n/**\n * Check if two arrays are equals (they contain the same elements). Will not work if the content can't be compared by `==`.\n */\nexport function arrayEquals<T>(arrayA: T[], arrayB: T[]): boolean {\n if (arrayA.length != arrayB.length) return false\n for (let i = 0; i < arrayA.length; ++i) {\n if (arrayA[i] !== arrayB[i]) return false\n }\n return true\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { KeyPair } from '../crypto/RSA';
|
|
1
2
|
export declare function notConcurrent<T>(concurrencyMap: {
|
|
2
|
-
[key: string]: PromiseLike<
|
|
3
|
+
[key: string]: PromiseLike<any>;
|
|
3
4
|
}, key: string, proc: () => PromiseLike<T>): PromiseLike<T>;
|
|
4
5
|
export declare function jwk2pkcs8(jwk: any): string;
|
|
5
6
|
export declare function jwk2spki(jwk: any): string;
|
|
@@ -59,3 +60,9 @@ export declare function crypt(obj: any, cryptor: (obj: {
|
|
|
59
60
|
export declare function decrypt(obj: any, decryptor: (obj: Uint8Array) => Promise<{
|
|
60
61
|
[key: string]: string;
|
|
61
62
|
}>): Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Extracts the full jwk key pair from the jwk representation of the private key.
|
|
65
|
+
* @param privateKeyJwk private key in jwk representation
|
|
66
|
+
* @throws if the key is missing the public modulus or public exponent.
|
|
67
|
+
*/
|
|
68
|
+
export declare function keyPairFromPrivateKeyJwk(privateKeyJwk: JsonWebKey): KeyPair<JsonWebKey>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.decrypt = exports.crypt = exports.before = exports.after = exports.appendBuffer = exports.truncateTrailingNulls = exports.pkcs8ToJwk = exports.spkiToJwk = exports.jwk2spki = exports.jwk2pkcs8 = exports.notConcurrent = void 0;
|
|
12
|
+
exports.keyPairFromPrivateKeyJwk = exports.decrypt = exports.crypt = exports.before = exports.after = exports.appendBuffer = exports.truncateTrailingNulls = exports.pkcs8ToJwk = exports.spkiToJwk = exports.jwk2spki = exports.jwk2pkcs8 = exports.notConcurrent = void 0;
|
|
13
13
|
const mm = require("moment");
|
|
14
14
|
const _ = require("lodash");
|
|
15
15
|
const binary_utils_1 = require("../utils/binary-utils");
|
|
@@ -18,14 +18,16 @@ const asn1_parser_1 = require("./asn1-parser");
|
|
|
18
18
|
function notConcurrent(concurrencyMap, key, proc) {
|
|
19
19
|
const inFlight = concurrencyMap[key];
|
|
20
20
|
if (!inFlight) {
|
|
21
|
-
|
|
21
|
+
const newJob = (() => __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
try {
|
|
23
23
|
return yield proc();
|
|
24
24
|
}
|
|
25
25
|
finally {
|
|
26
26
|
delete concurrencyMap[key];
|
|
27
27
|
}
|
|
28
|
-
}))()
|
|
28
|
+
}))();
|
|
29
|
+
concurrencyMap[key] = newJob;
|
|
30
|
+
return newJob;
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
33
|
return concurrencyMap[key].then(() => notConcurrent(concurrencyMap, key, proc));
|
|
@@ -243,4 +245,18 @@ function decrypt(obj, decryptor) {
|
|
|
243
245
|
});
|
|
244
246
|
}
|
|
245
247
|
exports.decrypt = decrypt;
|
|
248
|
+
/**
|
|
249
|
+
* Extracts the full jwk key pair from the jwk representation of the private key.
|
|
250
|
+
* @param privateKeyJwk private key in jwk representation
|
|
251
|
+
* @throws if the key is missing the public modulus or public exponent.
|
|
252
|
+
*/
|
|
253
|
+
function keyPairFromPrivateKeyJwk(privateKeyJwk) {
|
|
254
|
+
if (!privateKeyJwk.n || !privateKeyJwk.e)
|
|
255
|
+
throw new Error('Incomplete private JsonWebKey: missing public modulus and/or exponent');
|
|
256
|
+
return {
|
|
257
|
+
privateKey: privateKeyJwk,
|
|
258
|
+
publicKey: spkiToJwk((0, binary_utils_1.hex2ua)(jwk2spki(privateKeyJwk))),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
exports.keyPairFromPrivateKeyJwk = keyPairFromPrivateKeyJwk;
|
|
246
262
|
//# sourceMappingURL=crypto-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../../../icc-x-api/utils/crypto-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAA4B;AAE5B,4BAA2B;AAC3B,wDAAoG;AACpG,+CAAoC;AACpC,+CAAyC;AAEzC,SAAgB,aAAa,CAAI,cAAiD,EAAE,GAAW,EAAE,IAA0B;IACzH,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAS,EAAE;YACxC,IAAI;gBACF,OAAO,MAAM,IAAI,EAAE,CAAA;aACpB;oBAAS;gBACR,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;aAC3B;QACH,CAAC,CAAA,CAAC,EAAE,CAAC,CAAA;KACN;SAAM;QACL,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;KAChF;AACH,CAAC;AAbD,sCAaC;AAED,SAAgB,SAAS,CAAC,GAAQ;IAChC,OAAO,IAAA,kBAAI,EAAC;QACV,IAAI;QACJ;YACE,CAAC,IAAI,EAAE,IAAI,CAAC;YACZ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,oBAAoB,CAAC,EAAE,CAAC,IAAI,C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AA;gBAC9B,CAAC,CAAA,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;aACxB;QACH,CAAC,CAAA,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;QACrB,IAAI,GAAG,CAAC,aAAa,EAAE;YACrB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,SAAS,CAAC,IAAA,wBAAS,EAAC,IAAA,kBAAG,EAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;SACvE;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CAAA;AAhBD,0BAgBC","sourcesContent":["import * as mm from 'moment'\nimport { Moment } from 'moment'\nimport * as _ from 'lodash'\nimport { a2b, b2a, b64Url2ua, string2ua, ua2b64Url, ua2hex, ua2string } from '../utils/binary-utils'\nimport { pack } from './asn1-packer'\nimport { parseAsn1 } from './asn1-parser'\n\nexport function notConcurrent<T>(concurrencyMap: { [key: string]: PromiseLike<T> }, key: string, proc: () => PromiseLike<T>): PromiseLike<T> {\n const inFlight = concurrencyMap[key]\n if (!inFlight) {\n return (concurrencyMap[key] = (async () => {\n try {\n return await proc()\n } finally {\n delete concurrencyMap[key]\n }\n })())\n } else {\n return concurrencyMap[key].then(() => notConcurrent(concurrencyMap, key, proc))\n }\n}\n\nexport function jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x04,\n [\n [\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x03,\n [\n [\n 0x30,\n [\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function spkiToJwk(buf: Uint8Array): { kty: string; alg: string; n: string; e: string; ext: boolean } {\n const asn1 = parseAsn1(new Uint8Array(buf))\n\n var modulus: Uint8Array | undefined = undefined\n var exponent: Uint8Array | undefined = undefined\n if (\n asn1.type === 0x30 &&\n asn1.children?.[0]?.type === 0x30 &&\n asn1.children?.[0]?.children?.[0]?.type === 0x06 &&\n ua2hex(asn1.children?.[0]?.children?.[0]?.value ?? new Uint8Array(0)) === '2a864886f70d010101' // pragma: allowlist secret\n ) {\n modulus = asn1.children?.[1]?.children?.[0]?.children?.[0]?.value\n exponent = asn1.children?.[1]?.children?.[0]?.children?.[1]?.value\n } else if (asn1.type === 0x30 && asn1.children?.[0]?.type === 0x02 && asn1.children?.[1]?.type === 0x02) {\n modulus = asn1.children?.[0]?.value\n exponent = asn1.children?.[1]?.value\n }\n\n if (!modulus || !exponent) {\n throw new Error('Invalid spki format')\n }\n return {\n kty: 'RSA',\n alg: 'RSA-OAEP',\n ext: true,\n n: ua2b64Url(minimalRep(modulus)),\n e: ua2b64Url(minimalRep(exponent)),\n }\n}\n\nexport function pkcs8ToJwk(buf: Uint8Array | ArrayBuffer) {\n const parsed = parseAsn1(new Uint8Array(buf))\n const seq =\n parsed.children?.length === 3 && parsed.children[2].type === 0x04 && parsed.children[2].children?.length === 1\n ? parsed.children[2].children[0]\n : parsed\n return {\n kty: 'RSA',\n n: ua2b64Url(minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(minimalRep(seq.children![8].value as Uint8Array)),\n }\n}\n\nfunction minimalRep(b: Uint8Array) {\n let i = 0\n while (b[i] === 0) {\n i++\n }\n return b.slice(i)\n}\n\n/**\n * Provide a view over the given Uint8Array where any trailing null bytes at\n * the end are truncated.\n *\n * This can be used to ignore null bytes at the end of a padded UTF-8 string\n * without needing to copy that string, assuming code point U+0000 is encoded\n * in one null byte according to standards rather than in a multi-byte\n * overlong form.\n */\nexport function truncateTrailingNulls(a: Uint8Array) {\n let end = a.byteLength - 1\n while (a[end] === 0 && end >= 0) {\n end--\n }\n // end is now either the last non-null position in a or -1; in the latter\n // case the returned array will have length 0.\n return a.subarray(0, end + 1)\n}\n\n/**\n *\n * @param buffer1 {Uint8Array}\n * @param buffer2{ Uint8Array}\n * @returns {ArrayBuffer}\n */\nexport function appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)\n tmp.set(new Uint8Array(buffer1), 0)\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength)\n return tmp.buffer as ArrayBuffer\n}\n\n//Convenience methods for dates management\nexport function after(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isAfter(moment(d2)!)\n}\n\nexport function before(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isBefore(moment(d2)!)\n}\n\nfunction moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return mm(epochOrLongCalendar)\n }\n}\n\n/**\n * Encrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param cryptor the cryptor function (returns a promise)\n * @param keys the keys to be crypted: ex for a Patient ['note', 'addresses.*.[\"street\", \"houseNumber\", \"telecoms.*.telecomNumber\"]']\n */\nexport async function crypt(obj: any, cryptor: (obj: { [key: string]: string }) => Promise<ArrayBuffer>, keys: Array<string>) {\n const subObj = _.pick(\n obj,\n keys.filter((k) => !k.includes('*'))\n )\n obj.encryptedSelf = b2a(ua2string(await cryptor(subObj)))\n Object.keys(subObj).forEach((k) => delete obj[k])\n\n await keys\n .filter((k) => k.includes('*'))\n .reduce(async (prev: Promise<void>, k: any) => {\n await prev\n const k1 = k.split('.*.')[0]\n const k2 = k.substr(k1.length + 3)\n\n const mapped = await Promise.all((_.get(obj, k1) || []).map((so: any) => crypt(so, cryptor, k2.startsWith('[') ? JSON.parse(k2) : [k2])))\n _.set(obj, k1, mapped)\n }, Promise.resolve())\n\n return obj\n}\n\n/**\n * Decrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param decryptor the decryptor function (returns a promise)\n */\nexport async function decrypt(obj: any, decryptor: (obj: Uint8Array) => Promise<{ [key: string]: string }>) {\n await Object.keys(obj).reduce(async (prev: Promise<void>, k: any) => {\n await prev\n if (Array.isArray(obj[k])) {\n await (obj[k] as Array<any>)\n .filter((o) => typeof o === 'object' && o !== null)\n .reduce(async (prev: Promise<void>, so: any) => {\n await prev\n await decrypt(so, decryptor)\n }, Promise.resolve())\n }\n }, Promise.resolve())\n if (obj.encryptedSelf) {\n Object.assign(obj, await decryptor(string2ua(a2b(obj.encryptedSelf))))\n }\n return obj\n}\n"]}
|
|
1
|
+
{"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../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AO,GAAG,CAAA;IACZ,CAAC;CAAA;AAhBD,0BAgBC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,aAAyB;IAChE,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;IAClI,OAAO;QACL,UAAU,EAAE,aAAa;QACzB,SAAS,EAAE,SAAS,CAAC,IAAA,qBAAM,EAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;KACtD,CAAA;AACH,CAAC;AAND,4DAMC","sourcesContent":["import * as mm from 'moment'\nimport { Moment } from 'moment'\nimport * as _ from 'lodash'\nimport { a2b, b2a, b64Url2ua, hex2ua, string2ua, ua2b64Url, ua2hex, ua2string } from '../utils/binary-utils'\nimport { pack } from './asn1-packer'\nimport { parseAsn1 } from './asn1-parser'\nimport { KeyPair } from '../crypto/RSA'\n\nexport function notConcurrent<T>(concurrencyMap: { [key: string]: PromiseLike<any> }, key: string, proc: () => PromiseLike<T>): PromiseLike<T> {\n const inFlight = concurrencyMap[key]\n if (!inFlight) {\n const newJob = (async () => {\n try {\n return await proc()\n } finally {\n delete concurrencyMap[key]\n }\n })()\n concurrencyMap[key] = newJob\n return newJob\n } else {\n return concurrencyMap[key].then(() => notConcurrent(concurrencyMap, key, proc))\n }\n}\n\nexport function jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x04,\n [\n [\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret\n [\n 0x03,\n [\n [\n 0x30,\n [\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n ],\n ],\n ],\n ],\n ],\n ])\n}\n\nexport function spkiToJwk(buf: Uint8Array): { kty: string; alg: string; n: string; e: string; ext: boolean } {\n const asn1 = parseAsn1(new Uint8Array(buf))\n\n var modulus: Uint8Array | undefined = undefined\n var exponent: Uint8Array | undefined = undefined\n if (\n asn1.type === 0x30 &&\n asn1.children?.[0]?.type === 0x30 &&\n asn1.children?.[0]?.children?.[0]?.type === 0x06 &&\n ua2hex(asn1.children?.[0]?.children?.[0]?.value ?? new Uint8Array(0)) === '2a864886f70d010101' // pragma: allowlist secret\n ) {\n modulus = asn1.children?.[1]?.children?.[0]?.children?.[0]?.value\n exponent = asn1.children?.[1]?.children?.[0]?.children?.[1]?.value\n } else if (asn1.type === 0x30 && asn1.children?.[0]?.type === 0x02 && asn1.children?.[1]?.type === 0x02) {\n modulus = asn1.children?.[0]?.value\n exponent = asn1.children?.[1]?.value\n }\n\n if (!modulus || !exponent) {\n throw new Error('Invalid spki format')\n }\n return {\n kty: 'RSA',\n alg: 'RSA-OAEP',\n ext: true,\n n: ua2b64Url(minimalRep(modulus)),\n e: ua2b64Url(minimalRep(exponent)),\n }\n}\n\nexport function pkcs8ToJwk(buf: Uint8Array | ArrayBuffer) {\n const parsed = parseAsn1(new Uint8Array(buf))\n const seq =\n parsed.children?.length === 3 && parsed.children[2].type === 0x04 && parsed.children[2].children?.length === 1\n ? parsed.children[2].children[0]\n : parsed\n return {\n kty: 'RSA',\n n: ua2b64Url(minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(minimalRep(seq.children![8].value as Uint8Array)),\n }\n}\n\nfunction minimalRep(b: Uint8Array) {\n let i = 0\n while (b[i] === 0) {\n i++\n }\n return b.slice(i)\n}\n\n/**\n * Provide a view over the given Uint8Array where any trailing null bytes at\n * the end are truncated.\n *\n * This can be used to ignore null bytes at the end of a padded UTF-8 string\n * without needing to copy that string, assuming code point U+0000 is encoded\n * in one null byte according to standards rather than in a multi-byte\n * overlong form.\n */\nexport function truncateTrailingNulls(a: Uint8Array) {\n let end = a.byteLength - 1\n while (a[end] === 0 && end >= 0) {\n end--\n }\n // end is now either the last non-null position in a or -1; in the latter\n // case the returned array will have length 0.\n return a.subarray(0, end + 1)\n}\n\n/**\n *\n * @param buffer1 {Uint8Array}\n * @param buffer2{ Uint8Array}\n * @returns {ArrayBuffer}\n */\nexport function appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)\n tmp.set(new Uint8Array(buffer1), 0)\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength)\n return tmp.buffer as ArrayBuffer\n}\n\n//Convenience methods for dates management\nexport function after(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isAfter(moment(d2)!)\n}\n\nexport function before(d1: number | null | undefined, d2: number | null | undefined): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || moment(d1)!.isBefore(moment(d2)!)\n}\n\nfunction moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return mm('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return mm(epochOrLongCalendar)\n }\n}\n\n/**\n * Encrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param cryptor the cryptor function (returns a promise)\n * @param keys the keys to be crypted: ex for a Patient ['note', 'addresses.*.[\"street\", \"houseNumber\", \"telecoms.*.telecomNumber\"]']\n */\nexport async function crypt(obj: any, cryptor: (obj: { [key: string]: string }) => Promise<ArrayBuffer>, keys: Array<string>) {\n const subObj = _.pick(\n obj,\n keys.filter((k) => !k.includes('*'))\n )\n obj.encryptedSelf = b2a(ua2string(await cryptor(subObj)))\n Object.keys(subObj).forEach((k) => delete obj[k])\n\n await keys\n .filter((k) => k.includes('*'))\n .reduce(async (prev: Promise<void>, k: any) => {\n await prev\n const k1 = k.split('.*.')[0]\n const k2 = k.substr(k1.length + 3)\n\n const mapped = await Promise.all((_.get(obj, k1) || []).map((so: any) => crypt(so, cryptor, k2.startsWith('[') ? JSON.parse(k2) : [k2])))\n _.set(obj, k1, mapped)\n }, Promise.resolve())\n\n return obj\n}\n\n/**\n * Decrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param decryptor the decryptor function (returns a promise)\n */\nexport async function decrypt(obj: any, decryptor: (obj: Uint8Array) => Promise<{ [key: string]: string }>) {\n await Object.keys(obj).reduce(async (prev: Promise<void>, k: any) => {\n await prev\n if (Array.isArray(obj[k])) {\n await (obj[k] as Array<any>)\n .filter((o) => typeof o === 'object' && o !== null)\n .reduce(async (prev: Promise<void>, so: any) => {\n await prev\n await decrypt(so, decryptor)\n }, Promise.resolve())\n }\n }, Promise.resolve())\n if (obj.encryptedSelf) {\n Object.assign(obj, await decryptor(string2ua(a2b(obj.encryptedSelf))))\n }\n return obj\n}\n\n/**\n * Extracts the full jwk key pair from the jwk representation of the private key.\n * @param privateKeyJwk private key in jwk representation\n * @throws if the key is missing the public modulus or public exponent.\n */\nexport function keyPairFromPrivateKeyJwk(privateKeyJwk: JsonWebKey): KeyPair<JsonWebKey> {\n if (!privateKeyJwk.n || !privateKeyJwk.e) throw new Error('Incomplete private JsonWebKey: missing public modulus and/or exponent')\n return {\n privateKey: privateKeyJwk,\n publicKey: spkiToJwk(hex2ua(jwk2spki(privateKeyJwk))),\n }\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Represents a graph. Each node is associated to a set of nodes that can be directly reached from it in a single step.
|
|
4
|
+
*/
|
|
5
|
+
export type Graph = {
|
|
6
|
+
[node: string]: Set<string>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
* Represents from which all cycles have been removed using strongly connected components. Also holds information on all groups.
|
|
11
|
+
*/
|
|
12
|
+
export type StronglyConnectedGraph = {
|
|
13
|
+
acyclicGraph: Graph;
|
|
14
|
+
originalLabelToAcyclicLabel: {
|
|
15
|
+
[originalLabel: string]: string;
|
|
16
|
+
};
|
|
17
|
+
acyclicLabelToGroup: {
|
|
18
|
+
[newLabel: string]: string[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
* Creates a graph from a series of edges and optionally additional nodes.
|
|
24
|
+
* @param edges edges between nodes, [from, to].
|
|
25
|
+
* @param additionalNodes nodes which do not appear in any edge.
|
|
26
|
+
* @return a graph built using the provided parameters.
|
|
27
|
+
*/
|
|
28
|
+
export declare function graphFromEdges(edges: [string, string][], additionalNodes?: string[]): Graph;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
* Get the nodes reachable from each node in an acyclic graph. Exclude the node itself.
|
|
32
|
+
* @param graph an acyclic graph.
|
|
33
|
+
* @return all nodes reachable from each node in the graph with 1 or more steps.
|
|
34
|
+
*/
|
|
35
|
+
export declare function reachSetsAcyclic(graph: Graph): {
|
|
36
|
+
[node: string]: Set<string>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
* Get a new graph where each cycle has been replaced by a single node, with label chosen from the labels of nodes in the cycle (the specific way
|
|
41
|
+
* the label is chosen is implementation-dependant).
|
|
42
|
+
* @param graph a graph.
|
|
43
|
+
* @return the new graph and dictionaries to allow mapping between original labels and labels in the new graph
|
|
44
|
+
*/
|
|
45
|
+
export declare function acyclic(graph: Graph): StronglyConnectedGraph;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.acyclic = exports.reachSetsAcyclic = exports.graphFromEdges = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Creates a graph from a series of edges and optionally additional nodes.
|
|
7
|
+
* @param edges edges between nodes, [from, to].
|
|
8
|
+
* @param additionalNodes nodes which do not appear in any edge.
|
|
9
|
+
* @return a graph built using the provided parameters.
|
|
10
|
+
*/
|
|
11
|
+
function graphFromEdges(edges, additionalNodes) {
|
|
12
|
+
const nodes = edges.reduce((acc, [edgeFrom, edgeTo]) => {
|
|
13
|
+
acc.add(edgeFrom);
|
|
14
|
+
acc.add(edgeTo);
|
|
15
|
+
return acc;
|
|
16
|
+
}, new Set(additionalNodes !== null && additionalNodes !== void 0 ? additionalNodes : []));
|
|
17
|
+
const res = Array.from(nodes).reduce((res, node) => {
|
|
18
|
+
res[node] = new Set();
|
|
19
|
+
return res;
|
|
20
|
+
}, {});
|
|
21
|
+
edges.forEach(([edgeFrom, edgeTo]) => {
|
|
22
|
+
if (edgeFrom != edgeTo) {
|
|
23
|
+
res[edgeFrom].add(edgeTo);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
exports.graphFromEdges = graphFromEdges;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
* Get the nodes reachable from each node in an acyclic graph. Exclude the node itself.
|
|
32
|
+
* @param graph an acyclic graph.
|
|
33
|
+
* @return all nodes reachable from each node in the graph with 1 or more steps.
|
|
34
|
+
*/
|
|
35
|
+
function reachSetsAcyclic(graph) {
|
|
36
|
+
const res = {};
|
|
37
|
+
function calculateAndCacheReachSetRecursive(node) {
|
|
38
|
+
if (res[node])
|
|
39
|
+
return res[node];
|
|
40
|
+
const set = new Set(Array.from(graph[node]));
|
|
41
|
+
graph[node].forEach((child) => {
|
|
42
|
+
calculateAndCacheReachSetRecursive(child).forEach((x) => set.add(x));
|
|
43
|
+
});
|
|
44
|
+
res[node] = set;
|
|
45
|
+
return set;
|
|
46
|
+
}
|
|
47
|
+
Object.keys(graph).forEach((n) => calculateAndCacheReachSetRecursive(n));
|
|
48
|
+
return res;
|
|
49
|
+
}
|
|
50
|
+
exports.reachSetsAcyclic = reachSetsAcyclic;
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
* Get a new graph where each cycle has been replaced by a single node, with label chosen from the labels of nodes in the cycle (the specific way
|
|
54
|
+
* the label is chosen is implementation-dependant).
|
|
55
|
+
* @param graph a graph.
|
|
56
|
+
* @return the new graph and dictionaries to allow mapping between original labels and labels in the new graph
|
|
57
|
+
*/
|
|
58
|
+
function acyclic(graph) {
|
|
59
|
+
const idToName = Object.keys(graph);
|
|
60
|
+
const nameToId = {};
|
|
61
|
+
idToName.forEach((name, id) => {
|
|
62
|
+
nameToId[name] = id;
|
|
63
|
+
});
|
|
64
|
+
const ogAdjacency = idToName.map((name) => {
|
|
65
|
+
return Array.from(graph[name]).map((adjacencyName) => nameToId[adjacencyName]);
|
|
66
|
+
});
|
|
67
|
+
const { components, adjacencyList } = stronglyConnectedComponents(ogAdjacency);
|
|
68
|
+
const namedGroups = components.map((group) => group.map((id) => idToName[id]));
|
|
69
|
+
const originalLabelToAcyclicLabel = {};
|
|
70
|
+
namedGroups.forEach((group) => {
|
|
71
|
+
group.forEach((element) => {
|
|
72
|
+
originalLabelToAcyclicLabel[element] = group[0];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
const acyclicLabelToGroup = {};
|
|
76
|
+
namedGroups.forEach((group) => {
|
|
77
|
+
acyclicLabelToGroup[group[0]] = group;
|
|
78
|
+
});
|
|
79
|
+
const remappedIdToName = components.map((group) => idToName[group[0]]);
|
|
80
|
+
const res = {};
|
|
81
|
+
adjacencyList.forEach((adjacencyList, index) => {
|
|
82
|
+
res[remappedIdToName[index]] = new Set(adjacencyList.filter((x) => x !== index).map((x) => remappedIdToName[x]));
|
|
83
|
+
});
|
|
84
|
+
return { acyclicGraph: res, originalLabelToAcyclicLabel, acyclicLabelToGroup };
|
|
85
|
+
}
|
|
86
|
+
exports.acyclic = acyclic;
|
|
87
|
+
// Implementation from https://github.com/mikolalysenko/strongly-connected-components
|
|
88
|
+
function stronglyConnectedComponents(adjList) {
|
|
89
|
+
const numVertices = adjList.length;
|
|
90
|
+
const index = new Array(numVertices);
|
|
91
|
+
const lowValue = new Array(numVertices);
|
|
92
|
+
const active = new Array(numVertices);
|
|
93
|
+
const child = new Array(numVertices);
|
|
94
|
+
const scc = new Array(numVertices);
|
|
95
|
+
const sccLinks = new Array(numVertices);
|
|
96
|
+
//Initialize tables
|
|
97
|
+
for (let i = 0; i < numVertices; ++i) {
|
|
98
|
+
index[i] = -1;
|
|
99
|
+
lowValue[i] = 0;
|
|
100
|
+
active[i] = false;
|
|
101
|
+
child[i] = 0;
|
|
102
|
+
scc[i] = -1;
|
|
103
|
+
sccLinks[i] = [];
|
|
104
|
+
}
|
|
105
|
+
// The strongConnect function
|
|
106
|
+
let count = 0;
|
|
107
|
+
const components = [];
|
|
108
|
+
const sccAdjList = [];
|
|
109
|
+
function strongConnect(v) {
|
|
110
|
+
// To avoid running out of stack space, this emulates the recursive behaviour of the normal algorithm, effectively using T as the call stack.
|
|
111
|
+
const S = [v], T = [v];
|
|
112
|
+
index[v] = lowValue[v] = count;
|
|
113
|
+
active[v] = true;
|
|
114
|
+
count += 1;
|
|
115
|
+
while (T.length > 0) {
|
|
116
|
+
v = T[T.length - 1];
|
|
117
|
+
const e = adjList[v];
|
|
118
|
+
if (child[v] < e.length) {
|
|
119
|
+
// If we're not done iterating over the children, first try finishing that.
|
|
120
|
+
let i;
|
|
121
|
+
for (i = child[v]; i < e.length; ++i) {
|
|
122
|
+
// Start where we left off.
|
|
123
|
+
const u = e[i];
|
|
124
|
+
if (index[u] < 0) {
|
|
125
|
+
index[u] = lowValue[u] = count;
|
|
126
|
+
active[u] = true;
|
|
127
|
+
count += 1;
|
|
128
|
+
S.push(u);
|
|
129
|
+
T.push(u);
|
|
130
|
+
break; // First recurse, then continue here (with the same child!).
|
|
131
|
+
// There is a slight change to Tarjan's algorithm here.
|
|
132
|
+
// Normally, after having recursed, we set lowValue like we do for an active child (although some variants of the algorithm do it slightly differently).
|
|
133
|
+
// Here, we only do so if the child we recursed on is still active.
|
|
134
|
+
// The reasoning is that if it is no longer active, it must have had a lowValue equal to its own index, which means that it is necessarily higher than our lowValue.
|
|
135
|
+
}
|
|
136
|
+
else if (active[u]) {
|
|
137
|
+
lowValue[v] = Math.min(lowValue[v], lowValue[u]) | 0;
|
|
138
|
+
}
|
|
139
|
+
if (scc[u] >= 0) {
|
|
140
|
+
// Node v is not yet assigned an scc, but once it is that scc can apparently reach scc[u].
|
|
141
|
+
sccLinks[v].push(scc[u]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
child[v] = i; // Remember where we left off.
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// If we're done iterating over the children, check whether we have an scc.
|
|
148
|
+
if (lowValue[v] === index[v]) {
|
|
149
|
+
// NOTTODO: It /might/ be true that T is always a prefix of S (at this point!!!), and if so, this could be used here.
|
|
150
|
+
const component = [];
|
|
151
|
+
const links = [];
|
|
152
|
+
let linkCount = 0;
|
|
153
|
+
for (let i = S.length - 1; i >= 0; --i) {
|
|
154
|
+
const w = S[i];
|
|
155
|
+
active[w] = false;
|
|
156
|
+
component.push(w);
|
|
157
|
+
links.push(sccLinks[w]);
|
|
158
|
+
linkCount += sccLinks[w].length;
|
|
159
|
+
scc[w] = components.length;
|
|
160
|
+
if (w === v) {
|
|
161
|
+
S.length = i;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
components.push(component);
|
|
166
|
+
const allLinks = new Array(linkCount);
|
|
167
|
+
for (let i = 0; i < links.length; i++) {
|
|
168
|
+
for (let j = 0; j < links[i].length; j++) {
|
|
169
|
+
allLinks[--linkCount] = links[i][j];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
sccAdjList.push(allLinks);
|
|
173
|
+
}
|
|
174
|
+
T.pop(); // Now we're finished exploring this particular node (normally corresponds to the return statement)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//Run strong connect starting from each vertex
|
|
179
|
+
for (let i = 0; i < numVertices; ++i) {
|
|
180
|
+
if (index[i] < 0) {
|
|
181
|
+
strongConnect(i);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Compact sccAdjList
|
|
185
|
+
let newE;
|
|
186
|
+
for (let i = 0; i < sccAdjList.length; i++) {
|
|
187
|
+
const e = sccAdjList[i];
|
|
188
|
+
if (e.length === 0)
|
|
189
|
+
continue;
|
|
190
|
+
e.sort(function (a, b) {
|
|
191
|
+
return a - b;
|
|
192
|
+
});
|
|
193
|
+
newE = [e[0]];
|
|
194
|
+
for (let j = 1; j < e.length; j++) {
|
|
195
|
+
if (e[j] !== e[j - 1]) {
|
|
196
|
+
newE.push(e[j]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
sccAdjList[i] = newE;
|
|
200
|
+
}
|
|
201
|
+
return { components: components, adjacencyList: sccAdjList };
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=graph-utils.js.map
|
|
@@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Represents a graph. Each node is associated to a set of nodes that can be directly reached from it in a single step.\n */\nexport type Graph = { [node: string]: Set<string> }\n\n/**\n * @internal\n * Represents from which all cycles have been removed using strongly connected components. Also holds information on all groups.\n */\nexport type StronglyConnectedGraph = {\n acyclicGraph: Graph\n originalLabelToAcyclicLabel: { [originalLabel: string]: string }\n acyclicLabelToGroup: { [newLabel: string]: string[] } // includes new label.\n}\n\n/**\n * @internal\n * Creates a graph from a series of edges and optionally additional nodes.\n * @param edges edges between nodes, [from, to].\n * @param additionalNodes nodes which do not appear in any edge.\n * @return a graph built using the provided parameters.\n */\nexport function graphFromEdges(edges: [string, string][], additionalNodes?: string[]): Graph {\n const nodes = edges.reduce<Set<string>>((acc, [edgeFrom, edgeTo]) => {\n acc.add(edgeFrom)\n acc.add(edgeTo)\n return acc\n }, new Set(additionalNodes ?? []))\n const res = Array.from(nodes).reduce<Graph>((res, node) => {\n res[node] = new Set<string>()\n return res\n }, {})\n edges.forEach(([edgeFrom, edgeTo]) => {\n if (edgeFrom != edgeTo) {\n res[edgeFrom].add(edgeTo)\n }\n })\n return res\n}\n\n/**\n * @internal\n * Get the nodes reachable from each node in an acyclic graph. Exclude the node itself.\n * @param graph an acyclic graph.\n * @return all nodes reachable from each node in the graph with 1 or more steps.\n */\nexport function reachSetsAcyclic(graph: Graph): { [node: string]: Set<string> } {\n const res: { [node: string]: Set<string> } = {}\n function calculateAndCacheReachSetRecursive(node: string): Set<string> {\n if (res[node]) return res[node]\n const set = new Set(Array.from(graph[node]))\n graph[node].forEach((child) => {\n calculateAndCacheReachSetRecursive(child).forEach((x) => set.add(x))\n })\n res[node] = set\n return set\n }\n Object.keys(graph).forEach((n) => calculateAndCacheReachSetRecursive(n))\n return res\n}\n\n/**\n * @internal\n * Get a new graph where each cycle has been replaced by a single node, with label chosen from the labels of nodes in the cycle (the specific way\n * the label is chosen is implementation-dependant).\n * @param graph a graph.\n * @return the new graph and dictionaries to allow mapping between original labels and labels in the new graph\n */\nexport function acyclic(graph: Graph): StronglyConnectedGraph {\n const idToName = Object.keys(graph)\n const nameToId: { [name: string]: number } = {}\n idToName.forEach((name, id) => {\n nameToId[name] = id\n })\n const ogAdjacency: number[][] = idToName.map((name) => {\n return Array.from(graph[name]).map((adjacencyName) => nameToId[adjacencyName])\n })\n const { components, adjacencyList } = stronglyConnectedComponents(ogAdjacency)\n const namedGroups = components.map((group) => group.map((id) => idToName[id]))\n const originalLabelToAcyclicLabel: { [originalLabel: string]: string } = {}\n namedGroups.forEach((group) => {\n group.forEach((element) => {\n originalLabelToAcyclicLabel[element] = group[0]\n })\n })\n const acyclicLabelToGroup: { [newLabel: string]: string[] } = {}\n namedGroups.forEach((group) => {\n acyclicLabelToGroup[group[0]] = group\n })\n const remappedIdToName = components.map((group) => idToName[group[0]])\n const res: Graph = {}\n adjacencyList.forEach((adjacencyList, index) => {\n res[remappedIdToName[index]] = new Set(adjacencyList.filter((x) => x !== index).map((x) => remappedIdToName[x]))\n })\n return { acyclicGraph: res, originalLabelToAcyclicLabel, acyclicLabelToGroup }\n}\n\n// Implementation from https://github.com/mikolalysenko/strongly-connected-components\nfunction stronglyConnectedComponents(adjList: number[][]): { components: number[][]; adjacencyList: number[][] } {\n const numVertices = adjList.length\n const index = new Array(numVertices)\n const lowValue = new Array(numVertices)\n const active = new Array(numVertices)\n const child = new Array(numVertices)\n const scc = new Array(numVertices)\n const sccLinks = new Array(numVertices)\n\n //Initialize tables\n for (let i = 0; i < numVertices; ++i) {\n index[i] = -1\n lowValue[i] = 0\n active[i] = false\n child[i] = 0\n scc[i] = -1\n sccLinks[i] = []\n }\n\n // The strongConnect function\n let count = 0\n const components: number[][] = []\n const sccAdjList: number[][] = []\n\n function strongConnect(v: number) {\n // To avoid running out of stack space, this emulates the recursive behaviour of the normal algorithm, effectively using T as the call stack.\n const S = [v],\n T = [v]\n index[v] = lowValue[v] = count\n active[v] = true\n count += 1\n while (T.length > 0) {\n v = T[T.length - 1]\n const e = adjList[v]\n if (child[v] < e.length) {\n // If we're not done iterating over the children, first try finishing that.\n let i\n for (i = child[v]; i < e.length; ++i) {\n // Start where we left off.\n const u = e[i]\n if (index[u] < 0) {\n index[u] = lowValue[u] = count\n active[u] = true\n count += 1\n S.push(u)\n T.push(u)\n break // First recurse, then continue here (with the same child!).\n // There is a slight change to Tarjan's algorithm here.\n // Normally, after having recursed, we set lowValue like we do for an active child (although some variants of the algorithm do it slightly differently).\n // Here, we only do so if the child we recursed on is still active.\n // The reasoning is that if it is no longer active, it must have had a lowValue equal to its own index, which means that it is necessarily higher than our lowValue.\n } else if (active[u]) {\n lowValue[v] = Math.min(lowValue[v], lowValue[u]) | 0\n }\n if (scc[u] >= 0) {\n // Node v is not yet assigned an scc, but once it is that scc can apparently reach scc[u].\n sccLinks[v].push(scc[u])\n }\n }\n child[v] = i // Remember where we left off.\n } else {\n // If we're done iterating over the children, check whether we have an scc.\n if (lowValue[v] === index[v]) {\n // NOTTODO: It /might/ be true that T is always a prefix of S (at this point!!!), and if so, this could be used here.\n const component = []\n const links = []\n let linkCount = 0\n for (let i = S.length - 1; i >= 0; --i) {\n const w = S[i]\n active[w] = false\n component.push(w)\n links.push(sccLinks[w])\n linkCount += sccLinks[w].length\n scc[w] = components.length\n if (w === v) {\n S.length = i\n break\n }\n }\n components.push(component)\n const allLinks = new Array(linkCount)\n for (let i = 0; i < links.length; i++) {\n for (let j = 0; j < links[i].length; j++) {\n allLinks[--linkCount] = links[i][j]\n }\n }\n sccAdjList.push(allLinks)\n }\n T.pop() // Now we're finished exploring this particular node (normally corresponds to the return statement)\n }\n }\n }\n\n //Run strong connect starting from each vertex\n for (let i = 0; i < numVertices; ++i) {\n if (index[i] < 0) {\n strongConnect(i)\n }\n }\n\n // Compact sccAdjList\n let newE\n for (let i = 0; i < sccAdjList.length; i++) {\n const e = sccAdjList[i]\n if (e.length === 0) continue\n e.sort(function (a, b) {\n return a - b\n })\n newE = [e[0]]\n for (let j = 1; j < e.length; j++) {\n if (e[j] !== e[j - 1]) {\n newE.push(e[j])\n }\n }\n sccAdjList[i] = newE\n }\n\n return { components: components, adjacencyList: sccAdjList }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class LruTemporisedAsyncCache<K, V> {
|
|
2
|
+
private readonly maxCacheSize;
|
|
3
|
+
private readonly lifetimeForValue;
|
|
4
|
+
private readonly nodesMap;
|
|
5
|
+
private firstNode;
|
|
6
|
+
private lastNode;
|
|
7
|
+
/**
|
|
8
|
+
* @param maxCacheSize Maximum size of the cache. Any value <= 0 is considered as no limit.
|
|
9
|
+
* @param lifetimeForValue Get the maximum lifetime for an entry given its value.
|
|
10
|
+
*/
|
|
11
|
+
constructor(maxCacheSize: number, lifetimeForValue: (value: V) => number);
|
|
12
|
+
/**
|
|
13
|
+
* Gets a cached value or retrieves it and caches it if the value is not available or if it is available but expired. A value will never be expired
|
|
14
|
+
* if it was not yet retrieved, even if the retrieved value would be expired according to the {@link additionalExpirationCondition}
|
|
15
|
+
* @param key key of the entry
|
|
16
|
+
* @param retrieve given the previous value (if available, expired but not yet removed) of the entry retrieves an updated value.
|
|
17
|
+
* @param additionalExpirationCondition an expiration condition for already cached values to consider in addition to time-based expiration. Returns
|
|
18
|
+
* always false by default, meaning the value is not expired if its lifetime didn't already surpass the maximum lifetime.
|
|
19
|
+
* @return the cached value if present and not expired, else the retrieved value.
|
|
20
|
+
*/
|
|
21
|
+
get(key: K, retrieve: (previousValue: V | undefined) => Promise<V>, additionalExpirationCondition?: (value: V) => boolean): Promise<V>;
|
|
22
|
+
clear(): void;
|
|
23
|
+
private addToTail;
|
|
24
|
+
private evict;
|
|
25
|
+
private markUsed;
|
|
26
|
+
private registerJob;
|
|
27
|
+
}
|