@icure/api 8.6.7 → 8.6.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 (43) hide show
  1. package/icc-api/api/IccAccesslogApi.d.ts +14 -0
  2. package/icc-api/api/IccAccesslogApi.js +31 -0
  3. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  4. package/icc-api/model/AbstractFilterAccessLog.d.ts +15 -0
  5. package/icc-api/model/AbstractFilterAccessLog.js +21 -0
  6. package/icc-api/model/AbstractFilterAccessLog.js.map +1 -0
  7. package/icc-api/model/ChapterParagraph.d.ts +16 -0
  8. package/icc-api/model/ChapterParagraph.js +21 -0
  9. package/icc-api/model/ChapterParagraph.js.map +1 -0
  10. package/icc-api/model/Reimbursement.d.ts +2 -0
  11. package/icc-api/model/Reimbursement.js.map +1 -1
  12. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +2 -2
  13. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  14. package/icc-x-api/filters/AccessLogByDataOwnerPatientDateFilter.d.ts +22 -0
  15. package/icc-x-api/filters/AccessLogByDataOwnerPatientDateFilter.js +24 -0
  16. package/icc-x-api/filters/AccessLogByDataOwnerPatientDateFilter.js.map +1 -0
  17. package/icc-x-api/filters/AccessLogByDateFilter.d.ts +20 -0
  18. package/icc-x-api/filters/AccessLogByDateFilter.js +24 -0
  19. package/icc-x-api/filters/AccessLogByDateFilter.js.map +1 -0
  20. package/icc-x-api/filters/AccessLogByUserIdUserTypeDateFilter.d.ts +21 -0
  21. package/icc-x-api/filters/AccessLogByUserIdUserTypeDateFilter.js +24 -0
  22. package/icc-x-api/filters/AccessLogByUserIdUserTypeDateFilter.js.map +1 -0
  23. package/icc-x-api/icc-contact-x-api.js +3 -3
  24. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  25. package/icc-x-api/index.d.ts +3 -2
  26. package/icc-x-api/index.js +4 -0
  27. package/icc-x-api/index.js.map +1 -1
  28. package/icc-x-api/utils/crypto-utils.d.ts +2 -1
  29. package/icc-x-api/utils/crypto-utils.js +57 -6
  30. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  31. package/package.json +1 -1
  32. package/test/icc-x-api/crypto/anonymous-delegations-test.js +1 -1
  33. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +1 -1
  34. package/test/icc-x-api/crypto/cryptoTest.js +99 -1
  35. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -1
  36. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js +3 -3
  37. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js.map +1 -1
  38. package/test/icc-x-api/entity-with-attachments-api-test.js +2 -2
  39. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -1
  40. package/test/icc-x-api/icc-user-x-api-test.js +1 -1
  41. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -1
  42. package/test/support/CSM-243.js +5 -5
  43. package/test/support/CSM-243.js.map +1 -1
@@ -377,18 +377,54 @@ function parseEncryptedFields(encryptedFields, path) {
377
377
  ])),
378
378
  };
379
379
  }
380
+ function encryptedObjectDeepEqual(l, r) {
381
+ if (Array.isArray(l)) {
382
+ if (!Array.isArray(r) || l.length !== r.length) {
383
+ return false;
384
+ }
385
+ for (let i = 0; i < l.length; i++) {
386
+ if (!encryptedObjectDeepEqual(l[i], r[i])) {
387
+ return false;
388
+ }
389
+ }
390
+ }
391
+ else if (typeof l === 'object') {
392
+ if (typeof r !== 'object' || Array.isArray(r)) {
393
+ return false;
394
+ }
395
+ const toEncryptKeys = Object.keys(l);
396
+ const encryptedSelfContentKeys = Object.keys(r);
397
+ if (toEncryptKeys.length !== encryptedSelfContentKeys.length) {
398
+ return false;
399
+ }
400
+ const allKeys = new Set([...toEncryptKeys, ...encryptedSelfContentKeys]);
401
+ if (allKeys.size !== toEncryptKeys.length) {
402
+ return false;
403
+ }
404
+ for (const key of toEncryptKeys) {
405
+ if (!encryptedObjectDeepEqual(l[key], r[key])) {
406
+ return false;
407
+ }
408
+ }
409
+ }
410
+ else {
411
+ return l === r;
412
+ }
413
+ return true;
414
+ }
380
415
  /**
381
416
  * @internal this function is for internal use only and may be changed without notice
382
417
  * Encrypt the object graph recursively. Generally return an updated SHALLOW copy, although some fields may be deep copied if they also needed to be
383
418
  * recursively encrypted.
384
419
  * @param obj the object to encrypt
385
420
  * @param cryptor takes in input an object consisting only of the fields to encrypt of obj, and returns the encrypted object.
421
+ * @param decryptor takes in input an "encrytpedSelf" value and returns the decrypted content. Can return null or throw exception if the decryption fails.
386
422
  * @param keys the keys to encrypt for the
387
423
  * @param path path of the current object, used for error messages.
388
424
  * @return a shallow copy of the object with a new encryptedSelfField and without the encrypted fields.
389
425
  */
390
- function encryptObject(obj_1, cryptor_1, keys_1) {
391
- return __awaiter(this, arguments, void 0, function* (obj, cryptor, keys, path = 'obj') {
426
+ function encryptObject(obj_1, cryptor_1, decryptor_1, keys_1) {
427
+ return __awaiter(this, arguments, void 0, function* (obj, cryptor, decryptor, keys, path = 'obj') {
392
428
  const shallowClone = Object.assign({}, obj);
393
429
  const currEncryptedFields = {};
394
430
  for (const { fieldName } of keys.topLevelFields) {
@@ -399,13 +435,28 @@ function encryptObject(obj_1, cryptor_1, keys_1) {
399
435
  delete shallowClone[fieldName];
400
436
  }
401
437
  }
402
- shallowClone['encryptedSelf'] = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield cryptor(currEncryptedFields)));
438
+ let existingEncryptedSelfMatch = false;
439
+ if (shallowClone.encryptedSelf != undefined) {
440
+ let decrypted = undefined;
441
+ try {
442
+ decrypted = yield decryptor((0, binary_utils_1.string2ua)((0, binary_utils_1.a2b)(shallowClone.encryptedSelf)));
443
+ }
444
+ catch (e) {
445
+ // ignore
446
+ }
447
+ if (decrypted != undefined /* ignore null and undefined */ && encryptedObjectDeepEqual(currEncryptedFields, decrypted)) {
448
+ existingEncryptedSelfMatch = true;
449
+ }
450
+ }
451
+ if (!existingEncryptedSelfMatch) {
452
+ shallowClone['encryptedSelf'] = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield cryptor(currEncryptedFields)));
453
+ }
403
454
  for (const [fieldName, subKeys] of Object.entries(keys.nestedObjectsKeys)) {
404
455
  const fieldValue = shallowClone[fieldName];
405
456
  if (fieldValue !== undefined && fieldValue !== null) {
406
457
  if (!isPojo(fieldValue))
407
458
  throw new Error(`Expected field ${path}.${fieldName} to be a non-array object`);
408
- shallowClone[fieldName] = yield encryptObject(fieldValue, cryptor, subKeys, path + '.' + fieldName);
459
+ shallowClone[fieldName] = yield encryptObject(fieldValue, cryptor, decryptor, subKeys, path + '.' + fieldName);
409
460
  }
410
461
  }
411
462
  for (const [mapFieldName, subKeys] of Object.entries(keys.mapsValuesKeys)) {
@@ -421,7 +472,7 @@ function encryptObject(obj_1, cryptor_1, keys_1) {
421
472
  else {
422
473
  if (!isPojo(value))
423
474
  throw new Error(`Expected field ${path}.${mapFieldName}.${key} to be a non-array object`);
424
- newMap[key] = yield encryptObject(value, cryptor, subKeys, path + '.' + mapFieldName + '.' + key);
475
+ newMap[key] = yield encryptObject(value, cryptor, decryptor, subKeys, path + '.' + mapFieldName + '.' + key);
425
476
  }
426
477
  }
427
478
  shallowClone[mapFieldName] = newMap;
@@ -441,7 +492,7 @@ function encryptObject(obj_1, cryptor_1, keys_1) {
441
492
  else {
442
493
  if (!isPojo(value))
443
494
  throw new Error(`Expected field ${path}.${arrayFieldName}[${i}] to be a non-array object`);
444
- newArray[i] = yield encryptObject(value, cryptor, subKeys, path + '.' + arrayFieldName + '[' + i + ']');
495
+ newArray[i] = yield encryptObject(value, cryptor, decryptor, subKeys, path + '.' + arrayFieldName + '[' + i + ']');
445
496
  }
446
497
  }
447
498
  shallowClone[arrayFieldName] = newArray;
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../../../icc-x-api/utils/crypto-utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAQA,sCAeC;AAED,8BA2BC;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AAM,SAAS,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;oBACvD,IAAI,SAAS,IAAI,IAAI;wBAAE,OAAO,IAAI,CAAA;oBAClC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;gBACvB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YACnB,CAAC;QACH,CAAC;QACD,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;YACtB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAA,wBAAS,EAAC,IAAA,kBAAG,EAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACpE,IAAI,SAAS,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAA;YAClC,uCAAY,IAAI,GAAK,SAAS,EAAE;QAClC,CAAC;;YAAM,OAAO,IAAI,CAAA;IACpB,CAAC;CAAA;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,aAAyB,EAAE,UAAsB;IACxF,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,EAAE,UAAU,CAAC;KAClE,CAAA;AACH,CAAC","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, ShaVersion } 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, shaVersion: ShaVersion): { 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: shaVersion === 'sha-256' ? 'RSA-OAEP-256' : '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 * Configuration for the encryption of an object.\n * @param topLevelFields the fields of the object to encrypt. All the fields will be encrypted in a single encryptedSelf field which is added to the\n * object.\n * @param nestedObjectsKeys the name of fields which are expected to contain a nested object (or undefined). Allows to specify\n */\nexport type EncryptedFieldsManifest = {\n topLevelFields: { fieldName: string; fieldPath: string }[]\n nestedObjectsKeys: {\n [objectFieldName: string]: EncryptedFieldsManifest\n }\n mapsValuesKeys: {\n [mapFieldName: string]: EncryptedFieldsManifest\n }\n arraysValuesKeys: {\n [arrayFieldName: string]: EncryptedFieldsManifest\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n *\n * Parse the encrypted fields configuration for a specific entity type.\n *\n * ## Grammar\n *\n * The grammar for each encrypted field is the following:\n * ```\n * fieldName :=\n * regex([a-zA-Z_][a-zA-Z0-9_]+)\n * encryptedField :=\n * fieldName\n * | fieldName + (\".\" | \".*.\" | \"[].\") + encryptedField\n * ```\n *\n * This grammar allows you to specify the fields to encrypt for the object and recursively for nested objects.\n * - A string containing only a single `fieldName` will encrypt the field with the given name.\n * - A string starting with `fieldName.` allows to specify the encrypted fields of a nested object. The encrypted values of the\n * fields in the nested object will be saved in the nested object.\n * - A string starting with `fieldName.*.` treats `fieldName` as a map/dictionary data structure and allows to specify the encrypted fields of the\n * values of the map. Note that the values of the map must be objects as well. The encrypted content of each map value is stored in that value.\n * - A string starting with `fieldName[].` treats `fieldName` as an array and allows to specify the encrypted fields of the values of the array.\n * Note that the values of the array must be objects as well. The encrypted content of each array element is stored in that element.\n *\n * ## Example\n *\n * Consider the following object and encryption keys:\n * ```javascript\n * const obj = {\n * a: { x: 0, y: 1 },\n * b: \"hello\",\n * c: [ { public: \"a\", secret: \"b\" }, { public: \"c\", secret: \"d\" } ],\n * d: \"ok\",\n * e: {\n * info: \"something\",\n * private: \"secret\",\n * dataMap: {\n * \"en\": {\n * a: 1,\n * b: 2\n * },\n * \"fr\": {\n * a: 3,\n * b: 4\n * }\n * }\n * }\n * }\n * const encryptedFields = [\n * \"a\",\n * \"c[].secret\",\n * \"d\",\n * \"e.private\",\n * \"e.datamap.*.a\"\n * ]\n * ```\n * If you use them with the crypt method you will get the following result:\n * ```json\n * {\n * b: \"hello\",\n * c: [\n * { public: \"a\", encryptedSelf: \"...encrypted data of c[0]\" },\n * { public: \"c\", encryptedSelf: \"...encrypted data of c[1]\" }\n * ],\n * e: {\n * info: \"something\",\n * dataMap: {\n * \"en\": { b: 2, encryptedSelf: \"...encrypted data of e.dataMap['en']\" },\n * \"fr\": { b: 4, encryptedSelf: \"...encrypted data of e.dataMap['fr']\" }\n * },\n * encryptedSelf: \"...encrypted data of e\"\n * },\n * encryptedSelf: \"...encrypted data of obj\"\n * }\n * ```\n *\n * ## Shortened representation\n *\n * You can also group encrypted fields having the same prefix by concatenating to the prefix the JSON representation of an array of all the postfixes.\n * For example the following encrypted fields:\n * ```javascript\n * const encryptedFields = [\"a.b.c.d.e.f1\", \"a.b.c.d.e.f2\", \"a.b.c.d.e.f3\", \"a.b.c.d.e.f4\"]\n * ```\n * can be shortened to\n * ```javascript\n * const encryptedFields = ['a.b.c.d.e.[\"f1\",\"f2\",\"f3\",\"f4\"]'] // Note the use of single quotes to avoid escaping the double quotes\n * ```\n * If you use the shortened representation you may need to escape nested json representations. In that case the use of `JSON.stringify` is\n * recommended.\n *\n * @param encryptedFields\n * @param path\n */\nexport function parseEncryptedFields(encryptedFields: string[], path: string): EncryptedFieldsManifest {\n const groupedData = {\n topLevelFields: new Set<string>(),\n nestedObjectsKeys: {} as { [objectFieldName: string]: string[] },\n mapsValuesKeys: {} as { [mapFieldName: string]: string[] },\n arraysValuesKeys: {} as { [arrayFieldName: string]: string[] },\n }\n const encryptedFieldRegex = /^([_a-zA-Z][_a-zA-Z0-9]*)(?:(\\.\\*\\.|\\[]\\.|\\.)(?:[_a-zA-Z].*|\\[.*]))?$/\n const addSubkeyToGroupedData = (\n currFieldName: string,\n currFieldSeparator: string,\n currEncryptedField: string,\n groupedDataKey: 'nestedObjectsKeys' | 'mapsValuesKeys' | 'arraysValuesKeys'\n ) => {\n const existingOrNew = groupedData[groupedDataKey][currFieldName] ?? (groupedData[groupedDataKey][currFieldName] = [])\n const subKey = currEncryptedField.slice(currFieldName.length + currFieldSeparator.length)\n if (subKey.startsWith('[')) {\n let parsedJson: any[]\n try {\n parsedJson = JSON.parse(subKey)\n } catch {\n throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not a valid JSON subkey)`)\n }\n if (Array.isArray(parsedJson) && parsedJson.every((x) => typeof x == 'string')) {\n parsedJson.forEach((x) => existingOrNew.push(x))\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not an array of strings)`)\n } else {\n existingOrNew.push(subKey)\n }\n }\n for (const currEncryptedField of encryptedFields) {\n const currFieldMatch = currEncryptedField.match(encryptedFieldRegex)\n if (!!currFieldMatch) {\n const currFieldName = currFieldMatch[1]\n const currFieldSeparator = currFieldMatch[2]\n if (!currFieldSeparator) {\n if (groupedData.topLevelFields.has(currFieldName)) throw new Error(`Duplicate encrypted field ${path}${currFieldName}`)\n if (\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n groupedData.topLevelFields.add(currFieldName)\n } else if (currFieldSeparator == '.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'nestedObjectsKeys')\n } else if (currFieldSeparator == '.*.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'mapsValuesKeys')\n } else if (currFieldSeparator == '[].') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'arraysValuesKeys')\n } else throw new Error(`Internal error: unknown separator ${currFieldSeparator} passed regex validation in ${path}${currEncryptedField}`)\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField}`)\n }\n return {\n topLevelFields: Array.from(groupedData.topLevelFields).map((fieldName) => ({ fieldName, fieldPath: path + fieldName })),\n nestedObjectsKeys: Object.fromEntries(\n Object.entries(groupedData.nestedObjectsKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.'),\n ])\n ),\n mapsValuesKeys: Object.fromEntries(\n Object.entries(groupedData.mapsValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.*.'),\n ])\n ),\n arraysValuesKeys: Object.fromEntries(\n Object.entries(groupedData.arraysValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '[].'),\n ])\n ),\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Encrypt the object graph recursively. Generally return an updated SHALLOW copy, although some fields may be deep copied if they also needed to be\n * recursively encrypted.\n * @param obj the object to encrypt\n * @param cryptor takes in input an object consisting only of the fields to encrypt of obj, and returns the encrypted object.\n * @param keys the keys to encrypt for the\n * @param path path of the current object, used for error messages.\n * @return a shallow copy of the object with a new encryptedSelfField and without the encrypted fields.\n */\nexport async function encryptObject(\n obj: { [key: string]: any },\n cryptor: (obj: { [key: string]: any }) => Promise<ArrayBuffer>,\n keys: EncryptedFieldsManifest,\n path: string = 'obj'\n): Promise<{ [key: string]: any }> {\n const shallowClone = { ...obj }\n const currEncryptedFields: { [key: string]: any } = {}\n for (const { fieldName } of keys.topLevelFields) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined) {\n // we keep null values\n currEncryptedFields[fieldName] = fieldValue\n delete shallowClone[fieldName]\n }\n }\n shallowClone['encryptedSelf'] = b2a(ua2string(await cryptor(currEncryptedFields)))\n for (const [fieldName, subKeys] of Object.entries(keys.nestedObjectsKeys)) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${fieldName} to be a non-array object`)\n shallowClone[fieldName] = await encryptObject(fieldValue, cryptor, subKeys, path + '.' + fieldName)\n }\n }\n for (const [mapFieldName, subKeys] of Object.entries(keys.mapsValuesKeys)) {\n const fieldValue = shallowClone[mapFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${mapFieldName} to be a non-array object`)\n const newMap: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(fieldValue as object)) {\n if (value === null || value === undefined) {\n newMap[key] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${mapFieldName}.${key} to be a non-array object`)\n newMap[key] = await encryptObject(value, cryptor, subKeys, path + '.' + mapFieldName + '.' + key)\n }\n }\n shallowClone[mapFieldName] = newMap\n }\n }\n for (const [arrayFieldName, subKeys] of Object.entries(keys.arraysValuesKeys)) {\n const fieldValue = shallowClone[arrayFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!Array.isArray(fieldValue)) throw new Error(`Expected field ${path}.${arrayFieldName} to be an array`)\n const newArray: any[] = Array(fieldValue.length)\n for (let i = 0; i < fieldValue.length; i++) {\n const value = fieldValue[i]\n if (value === null || value === undefined) {\n newArray[i] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${arrayFieldName}[${i}] to be a non-array object`)\n newArray[i] = await encryptObject(value, cryptor, subKeys, path + '.' + arrayFieldName + '[' + i + ']')\n }\n }\n shallowClone[arrayFieldName] = newArray\n }\n }\n return shallowClone\n}\n\n/**\n * Check if value is a non-null object that is not an array.\n */\nfunction isPojo(value: any): boolean {\n // This break if for some reason we have object versions of String/Number/Boolean\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof ArrayBuffer) && !ArrayBuffer.isView(value)\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Decrypt object graph recursively.\n *\n * @param obj the object to decrypt\n * @param decryptor the decryptor function (returns a promise); the decryptor returns the decrypted input or null if\n * the decryption fails\n * @return a deep copy of the object with the decrypted fields and removed encryptedSelf field, or null if the\n * decryption failed\n */\nexport async function decryptObject(\n obj: { [key: string]: any },\n decryptor: (obj: Uint8Array) => Promise<{ [key: string]: any } | null>\n): Promise<{ [key: string]: any } | null> {\n const copy: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(obj)) {\n if (key === 'encryptedSelf') {\n copy[key] = value\n } else if (typeof value === 'object' && value !== null) {\n if (Array.isArray(value)) {\n // Note: nested arrays (and primitives) are returned as is, and they aren't recursively decrypted.\n // This is because we currently don't support encryption of elements from arrays in arrays (we only support\n // arrays in objects in arrays).\n // In future this may change.\n const decryptedElements = []\n for (const element of value) {\n if (isPojo(element)) {\n const decrypted = await decryptObject(element, decryptor)\n if (decrypted == null) return null\n decryptedElements.push(decrypted)\n } else {\n decryptedElements.push(element)\n }\n }\n copy[key] = decryptedElements\n } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {\n copy[key] = value // No direct decryption of array buffer data. Array buffer should be converted to b64 string and encrypted as json data.\n } else {\n const decrypted = await decryptObject(value, decryptor)\n if (decrypted == null) return null\n copy[key] = decrypted\n }\n } else {\n copy[key] = value\n }\n }\n if (obj.encryptedSelf) {\n const decrypted = await decryptor(string2ua(a2b(obj.encryptedSelf)))\n if (decrypted == null) return null\n return { ...copy, ...decrypted }\n } else return copy\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 * @param shaVersion the SHA algorithm version\n * @throws if the key is missing the public modulus or public exponent.\n */\nexport function keyPairFromPrivateKeyJwk(privateKeyJwk: JsonWebKey, shaVersion: ShaVersion): 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)), shaVersion),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CAAC,aAAa,EAAE,CAAC;YACtB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,IAAA,wBAAS,EAAC,IAAA,kBAAG,EAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;YACpE,IAAI,SAAS,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAA;YAClC,uCAAY,IAAI,GAAK,SAAS,EAAE;QAClC,CAAC;;YAAM,OAAO,IAAI,CAAA;IACpB,CAAC;CAAA;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,aAAyB,EAAE,UAAsB;IACxF,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,EAAE,UAAU,CAAC;KAClE,CAAA;AACH,CAAC","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, ShaVersion } 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, shaVersion: ShaVersion): { 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: shaVersion === 'sha-256' ? 'RSA-OAEP-256' : '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 * Configuration for the encryption of an object.\n * @param topLevelFields the fields of the object to encrypt. All the fields will be encrypted in a single encryptedSelf field which is added to the\n * object.\n * @param nestedObjectsKeys the name of fields which are expected to contain a nested object (or undefined). Allows to specify\n */\nexport type EncryptedFieldsManifest = {\n topLevelFields: { fieldName: string; fieldPath: string }[]\n nestedObjectsKeys: {\n [objectFieldName: string]: EncryptedFieldsManifest\n }\n mapsValuesKeys: {\n [mapFieldName: string]: EncryptedFieldsManifest\n }\n arraysValuesKeys: {\n [arrayFieldName: string]: EncryptedFieldsManifest\n }\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n *\n * Parse the encrypted fields configuration for a specific entity type.\n *\n * ## Grammar\n *\n * The grammar for each encrypted field is the following:\n * ```\n * fieldName :=\n * regex([a-zA-Z_][a-zA-Z0-9_]+)\n * encryptedField :=\n * fieldName\n * | fieldName + (\".\" | \".*.\" | \"[].\") + encryptedField\n * ```\n *\n * This grammar allows you to specify the fields to encrypt for the object and recursively for nested objects.\n * - A string containing only a single `fieldName` will encrypt the field with the given name.\n * - A string starting with `fieldName.` allows to specify the encrypted fields of a nested object. The encrypted values of the\n * fields in the nested object will be saved in the nested object.\n * - A string starting with `fieldName.*.` treats `fieldName` as a map/dictionary data structure and allows to specify the encrypted fields of the\n * values of the map. Note that the values of the map must be objects as well. The encrypted content of each map value is stored in that value.\n * - A string starting with `fieldName[].` treats `fieldName` as an array and allows to specify the encrypted fields of the values of the array.\n * Note that the values of the array must be objects as well. The encrypted content of each array element is stored in that element.\n *\n * ## Example\n *\n * Consider the following object and encryption keys:\n * ```javascript\n * const obj = {\n * a: { x: 0, y: 1 },\n * b: \"hello\",\n * c: [ { public: \"a\", secret: \"b\" }, { public: \"c\", secret: \"d\" } ],\n * d: \"ok\",\n * e: {\n * info: \"something\",\n * private: \"secret\",\n * dataMap: {\n * \"en\": {\n * a: 1,\n * b: 2\n * },\n * \"fr\": {\n * a: 3,\n * b: 4\n * }\n * }\n * }\n * }\n * const encryptedFields = [\n * \"a\",\n * \"c[].secret\",\n * \"d\",\n * \"e.private\",\n * \"e.datamap.*.a\"\n * ]\n * ```\n * If you use them with the crypt method you will get the following result:\n * ```json\n * {\n * b: \"hello\",\n * c: [\n * { public: \"a\", encryptedSelf: \"...encrypted data of c[0]\" },\n * { public: \"c\", encryptedSelf: \"...encrypted data of c[1]\" }\n * ],\n * e: {\n * info: \"something\",\n * dataMap: {\n * \"en\": { b: 2, encryptedSelf: \"...encrypted data of e.dataMap['en']\" },\n * \"fr\": { b: 4, encryptedSelf: \"...encrypted data of e.dataMap['fr']\" }\n * },\n * encryptedSelf: \"...encrypted data of e\"\n * },\n * encryptedSelf: \"...encrypted data of obj\"\n * }\n * ```\n *\n * ## Shortened representation\n *\n * You can also group encrypted fields having the same prefix by concatenating to the prefix the JSON representation of an array of all the postfixes.\n * For example the following encrypted fields:\n * ```javascript\n * const encryptedFields = [\"a.b.c.d.e.f1\", \"a.b.c.d.e.f2\", \"a.b.c.d.e.f3\", \"a.b.c.d.e.f4\"]\n * ```\n * can be shortened to\n * ```javascript\n * const encryptedFields = ['a.b.c.d.e.[\"f1\",\"f2\",\"f3\",\"f4\"]'] // Note the use of single quotes to avoid escaping the double quotes\n * ```\n * If you use the shortened representation you may need to escape nested json representations. In that case the use of `JSON.stringify` is\n * recommended.\n *\n * @param encryptedFields\n * @param path\n */\nexport function parseEncryptedFields(encryptedFields: string[], path: string): EncryptedFieldsManifest {\n const groupedData = {\n topLevelFields: new Set<string>(),\n nestedObjectsKeys: {} as { [objectFieldName: string]: string[] },\n mapsValuesKeys: {} as { [mapFieldName: string]: string[] },\n arraysValuesKeys: {} as { [arrayFieldName: string]: string[] },\n }\n const encryptedFieldRegex = /^([_a-zA-Z][_a-zA-Z0-9]*)(?:(\\.\\*\\.|\\[]\\.|\\.)(?:[_a-zA-Z].*|\\[.*]))?$/\n const addSubkeyToGroupedData = (\n currFieldName: string,\n currFieldSeparator: string,\n currEncryptedField: string,\n groupedDataKey: 'nestedObjectsKeys' | 'mapsValuesKeys' | 'arraysValuesKeys'\n ) => {\n const existingOrNew = groupedData[groupedDataKey][currFieldName] ?? (groupedData[groupedDataKey][currFieldName] = [])\n const subKey = currEncryptedField.slice(currFieldName.length + currFieldSeparator.length)\n if (subKey.startsWith('[')) {\n let parsedJson: any[]\n try {\n parsedJson = JSON.parse(subKey)\n } catch {\n throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not a valid JSON subkey)`)\n }\n if (Array.isArray(parsedJson) && parsedJson.every((x) => typeof x == 'string')) {\n parsedJson.forEach((x) => existingOrNew.push(x))\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField} (not an array of strings)`)\n } else {\n existingOrNew.push(subKey)\n }\n }\n for (const currEncryptedField of encryptedFields) {\n const currFieldMatch = currEncryptedField.match(encryptedFieldRegex)\n if (!!currFieldMatch) {\n const currFieldName = currFieldMatch[1]\n const currFieldSeparator = currFieldMatch[2]\n if (!currFieldSeparator) {\n if (groupedData.topLevelFields.has(currFieldName)) throw new Error(`Duplicate encrypted field ${path}${currFieldName}`)\n if (\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n groupedData.topLevelFields.add(currFieldName)\n } else if (currFieldSeparator == '.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.mapsValuesKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'nestedObjectsKeys')\n } else if (currFieldSeparator == '.*.') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.arraysValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'mapsValuesKeys')\n } else if (currFieldSeparator == '[].') {\n if (\n groupedData.topLevelFields.has(currFieldName) ||\n !!groupedData.nestedObjectsKeys[currFieldName] ||\n !!groupedData.mapsValuesKeys[currFieldName]\n )\n throw new Error(`Encrypted field appears multiple times as different nested types and or top-level-field: ${path}${currFieldName}`)\n addSubkeyToGroupedData(currFieldName, currFieldSeparator, currEncryptedField, 'arraysValuesKeys')\n } else throw new Error(`Internal error: unknown separator ${currFieldSeparator} passed regex validation in ${path}${currEncryptedField}`)\n } else throw new Error(`Invalid encrypted field ${path}${currEncryptedField}`)\n }\n return {\n topLevelFields: Array.from(groupedData.topLevelFields).map((fieldName) => ({ fieldName, fieldPath: path + fieldName })),\n nestedObjectsKeys: Object.fromEntries(\n Object.entries(groupedData.nestedObjectsKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.'),\n ])\n ),\n mapsValuesKeys: Object.fromEntries(\n Object.entries(groupedData.mapsValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '.*.'),\n ])\n ),\n arraysValuesKeys: Object.fromEntries(\n Object.entries(groupedData.arraysValuesKeys).map(([fieldName, fieldNames]) => [\n fieldName,\n parseEncryptedFields(fieldNames, path + fieldName + '[].'),\n ])\n ),\n }\n}\n\nfunction encryptedObjectDeepEqual(l: any, r: any): boolean {\n if (Array.isArray(l)) {\n if (!Array.isArray(r) || l.length !== r.length) {\n return false\n }\n for (let i = 0; i < l.length; i++) {\n if (!encryptedObjectDeepEqual(l[i], r[i])) {\n return false\n }\n }\n } else if (typeof l === 'object') {\n if (typeof r !== 'object' || Array.isArray(r)) {\n return false\n }\n const toEncryptKeys = Object.keys(l)\n const encryptedSelfContentKeys = Object.keys(r)\n if (toEncryptKeys.length !== encryptedSelfContentKeys.length) {\n return false\n }\n const allKeys = new Set([...toEncryptKeys, ...encryptedSelfContentKeys])\n if (allKeys.size !== toEncryptKeys.length) {\n return false\n }\n for (const key of toEncryptKeys) {\n if (!encryptedObjectDeepEqual(l[key], r[key])) {\n return false\n }\n }\n } else {\n return l === r\n }\n return true\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Encrypt the object graph recursively. Generally return an updated SHALLOW copy, although some fields may be deep copied if they also needed to be\n * recursively encrypted.\n * @param obj the object to encrypt\n * @param cryptor takes in input an object consisting only of the fields to encrypt of obj, and returns the encrypted object.\n * @param decryptor takes in input an \"encrytpedSelf\" value and returns the decrypted content. Can return null or throw exception if the decryption fails.\n * @param keys the keys to encrypt for the\n * @param path path of the current object, used for error messages.\n * @return a shallow copy of the object with a new encryptedSelfField and without the encrypted fields.\n */\nexport async function encryptObject(\n obj: { [key: string]: any },\n cryptor: (obj: { [key: string]: any }) => Promise<ArrayBuffer>,\n decryptor: (encryptedSelf: Uint8Array<ArrayBufferLike>) => Promise<any>,\n keys: EncryptedFieldsManifest,\n path: string = 'obj'\n): Promise<{ [key: string]: any }> {\n const shallowClone = { ...obj }\n const currEncryptedFields: { [key: string]: any } = {}\n for (const { fieldName } of keys.topLevelFields) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined) {\n // we keep null values\n currEncryptedFields[fieldName] = fieldValue\n delete shallowClone[fieldName]\n }\n }\n let existingEncryptedSelfMatch = false\n if (shallowClone.encryptedSelf != undefined) {\n let decrypted = undefined\n try {\n decrypted = await decryptor(string2ua(a2b(shallowClone.encryptedSelf)))\n } catch (e) {\n // ignore\n }\n if (decrypted != undefined /* ignore null and undefined */ && encryptedObjectDeepEqual(currEncryptedFields, decrypted)) {\n existingEncryptedSelfMatch = true\n }\n }\n if (!existingEncryptedSelfMatch) {\n shallowClone['encryptedSelf'] = b2a(ua2string(await cryptor(currEncryptedFields)))\n }\n for (const [fieldName, subKeys] of Object.entries(keys.nestedObjectsKeys)) {\n const fieldValue = shallowClone[fieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${fieldName} to be a non-array object`)\n shallowClone[fieldName] = await encryptObject(fieldValue, cryptor, decryptor, subKeys, path + '.' + fieldName)\n }\n }\n for (const [mapFieldName, subKeys] of Object.entries(keys.mapsValuesKeys)) {\n const fieldValue = shallowClone[mapFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!isPojo(fieldValue)) throw new Error(`Expected field ${path}.${mapFieldName} to be a non-array object`)\n const newMap: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(fieldValue as object)) {\n if (value === null || value === undefined) {\n newMap[key] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${mapFieldName}.${key} to be a non-array object`)\n newMap[key] = await encryptObject(value, cryptor, decryptor, subKeys, path + '.' + mapFieldName + '.' + key)\n }\n }\n shallowClone[mapFieldName] = newMap\n }\n }\n for (const [arrayFieldName, subKeys] of Object.entries(keys.arraysValuesKeys)) {\n const fieldValue = shallowClone[arrayFieldName]\n if (fieldValue !== undefined && fieldValue !== null) {\n if (!Array.isArray(fieldValue)) throw new Error(`Expected field ${path}.${arrayFieldName} to be an array`)\n const newArray: any[] = Array(fieldValue.length)\n for (let i = 0; i < fieldValue.length; i++) {\n const value = fieldValue[i]\n if (value === null || value === undefined) {\n newArray[i] = value\n } else {\n if (!isPojo(value)) throw new Error(`Expected field ${path}.${arrayFieldName}[${i}] to be a non-array object`)\n newArray[i] = await encryptObject(value, cryptor, decryptor, subKeys, path + '.' + arrayFieldName + '[' + i + ']')\n }\n }\n shallowClone[arrayFieldName] = newArray\n }\n }\n return shallowClone\n}\n\n/**\n * Check if value is a non-null object that is not an array.\n */\nfunction isPojo(value: any): boolean {\n // This break if for some reason we have object versions of String/Number/Boolean\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof ArrayBuffer) && !ArrayBuffer.isView(value)\n}\n\n/**\n * @internal this function is for internal use only and may be changed without notice\n * Decrypt object graph recursively.\n *\n * @param obj the object to decrypt\n * @param decryptor the decryptor function (returns a promise); the decryptor returns the decrypted input or null if\n * the decryption fails\n * @return a deep copy of the object with the decrypted fields and removed encryptedSelf field, or null if the\n * decryption failed\n */\nexport async function decryptObject(\n obj: { [key: string]: any },\n decryptor: (obj: Uint8Array) => Promise<{ [key: string]: any } | null>\n): Promise<{ [key: string]: any } | null> {\n const copy: { [key: string]: any } = {}\n for (const [key, value] of Object.entries(obj)) {\n if (key === 'encryptedSelf') {\n copy[key] = value\n } else if (typeof value === 'object' && value !== null) {\n if (Array.isArray(value)) {\n // Note: nested arrays (and primitives) are returned as is, and they aren't recursively decrypted.\n // This is because we currently don't support encryption of elements from arrays in arrays (we only support\n // arrays in objects in arrays).\n // In future this may change.\n const decryptedElements = []\n for (const element of value) {\n if (isPojo(element)) {\n const decrypted = await decryptObject(element, decryptor)\n if (decrypted == null) return null\n decryptedElements.push(decrypted)\n } else {\n decryptedElements.push(element)\n }\n }\n copy[key] = decryptedElements\n } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {\n copy[key] = value // No direct decryption of array buffer data. Array buffer should be converted to b64 string and encrypted as json data.\n } else {\n const decrypted = await decryptObject(value, decryptor)\n if (decrypted == null) return null\n copy[key] = decrypted\n }\n } else {\n copy[key] = value\n }\n }\n if (obj.encryptedSelf) {\n const decrypted = await decryptor(string2ua(a2b(obj.encryptedSelf)))\n if (decrypted == null) return null\n return { ...copy, ...decrypted }\n } else return copy\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 * @param shaVersion the SHA algorithm version\n * @throws if the key is missing the public modulus or public exponent.\n */\nexport function keyPairFromPrivateKeyJwk(privateKeyJwk: JsonWebKey, shaVersion: ShaVersion): 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)), shaVersion),\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icure/api",
3
- "version": "8.6.7",
3
+ "version": "8.6.9",
4
4
  "description": "Typescript version of iCure standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -298,7 +298,7 @@ describe('Anonymous delegations', () => {
298
298
  it('without de-anonymisation metadata the data owners should be able to identify anonymous delegates only if their parent is part of the delegation with that delegate.', () => __awaiter(void 0, void 0, void 0, function* () {
299
299
  const { parentApi: childApi, parentUser: childUser, grandApi: parentApi, grandUser: parentUser } = yield (0, test_utils_1.createHcpHierarchyApis)(env); // Want to use only hcp with one parent
300
300
  const patientInfo = yield createUserAndApi('anonymous');
301
- let entity = yield parentApi.messageApi.createMessage(yield parentApi.messageApi.newInstanceWithPatient(parentUser, null, { subject: 'A simple subject' }));
301
+ let entity = yield parentApi.messageApi.createMessageWithUser(parentUser, yield parentApi.messageApi.newInstanceWithPatient(parentUser, null, { subject: 'A simple subject' }));
302
302
  entity = yield parentApi.messageApi.shareWith(patientInfo.userInfo.dataOwnerId, entity, [], { requestedPermissions: FULL_WRITE });
303
303
  yield patientInfo.api.cryptoApi.forceReload();
304
304
  const expectedAccess = {