@icure/api 4.2.31 → 5.0.3

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 (103) hide show
  1. package/icc-api/api/IccDeviceApi.d.ts +3 -3
  2. package/icc-api/api/IccDeviceApi.js.map +1 -1
  3. package/icc-api/api/IccHcpartyApi.d.ts +3 -3
  4. package/icc-api/api/IccHcpartyApi.js.map +1 -1
  5. package/icc-api/api/IccPatientApi.d.ts +3 -3
  6. package/icc-api/api/IccPatientApi.js.map +1 -1
  7. package/icc-api/api/IccUserApi.js +1 -1
  8. package/icc-api/api/IccUserApi.js.map +1 -1
  9. package/icc-api/api/XHR.js +2 -1
  10. package/icc-api/api/XHR.js.map +1 -1
  11. package/icc-api/iccApi.js +5 -1
  12. package/icc-api/iccApi.js.map +1 -1
  13. package/icc-api/index.js +5 -1
  14. package/icc-api/index.js.map +1 -1
  15. package/icc-api/model/Body.js +1 -1
  16. package/icc-api/model/Body.js.map +1 -1
  17. package/icc-api/model/Body1.js +1 -1
  18. package/icc-api/model/Body1.js.map +1 -1
  19. package/icc-api/model/Body2.js +1 -1
  20. package/icc-api/model/Body2.js.map +1 -1
  21. package/icc-api/model/Body3.js +1 -1
  22. package/icc-api/model/Body3.js.map +1 -1
  23. package/icc-api/model/ByteArray.js +1 -1
  24. package/icc-api/model/ByteArray.js.map +1 -1
  25. package/icc-api/model/Content.js +1 -1
  26. package/icc-api/model/Content.js.map +1 -1
  27. package/icc-api/model/Device.js +1 -1
  28. package/icc-api/model/Device.js.map +1 -1
  29. package/icc-api/model/Document.js +1 -1
  30. package/icc-api/model/Document.js.map +1 -1
  31. package/icc-api/model/DocumentTemplate.js +1 -1
  32. package/icc-api/model/DocumentTemplate.js.map +1 -1
  33. package/icc-api/model/HealthcareParty.js +1 -1
  34. package/icc-api/model/HealthcareParty.js.map +1 -1
  35. package/icc-api/model/MimeAttachment.js +1 -1
  36. package/icc-api/model/MimeAttachment.js.map +1 -1
  37. package/icc-api/model/Patient.js +1 -1
  38. package/icc-api/model/Patient.js.map +1 -1
  39. package/icc-api/model/models.d.ts +15 -0
  40. package/icc-api/model/models.js +5 -1
  41. package/icc-api/model/models.js.map +1 -1
  42. package/icc-x-api/crypto/AES.d.ts +2 -1
  43. package/icc-x-api/crypto/AES.js +37 -10
  44. package/icc-x-api/crypto/AES.js.map +1 -1
  45. package/icc-x-api/crypto/RSA.d.ts +0 -31
  46. package/icc-x-api/crypto/RSA.js +0 -64
  47. package/icc-x-api/crypto/RSA.js.map +1 -1
  48. package/icc-x-api/crypto/shamir.js.map +1 -1
  49. package/icc-x-api/filters/filters.js +7 -3
  50. package/icc-x-api/filters/filters.js.map +1 -1
  51. package/icc-x-api/icc-accesslog-x-api.js +25 -22
  52. package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
  53. package/icc-x-api/icc-bekmehr-x-api.js +2 -2
  54. package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
  55. package/icc-x-api/icc-calendar-item-x-api.d.ts +2 -2
  56. package/icc-x-api/icc-calendar-item-x-api.js +43 -30
  57. package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
  58. package/icc-x-api/icc-contact-x-api.js +59 -45
  59. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  60. package/icc-x-api/icc-crypto-x-api.d.ts +127 -54
  61. package/icc-x-api/icc-crypto-x-api.js +830 -393
  62. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  63. package/icc-x-api/icc-doctemplate-x-api.js +2 -2
  64. package/icc-x-api/icc-doctemplate-x-api.js.map +1 -1
  65. package/icc-x-api/icc-document-x-api.js +3 -3
  66. package/icc-x-api/icc-document-x-api.js.map +1 -1
  67. package/icc-x-api/icc-form-x-api.js +3 -3
  68. package/icc-x-api/icc-form-x-api.js.map +1 -1
  69. package/icc-x-api/icc-hcparty-x-api.js +4 -4
  70. package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
  71. package/icc-x-api/icc-helement-x-api.d.ts +1 -1
  72. package/icc-x-api/icc-helement-x-api.js +34 -29
  73. package/icc-x-api/icc-helement-x-api.js.map +1 -1
  74. package/icc-x-api/icc-maintenance-task-x-api.js +5 -6
  75. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  76. package/icc-x-api/icc-patient-x-api.d.ts +1 -1
  77. package/icc-x-api/icc-patient-x-api.js +65 -53
  78. package/icc-x-api/icc-patient-x-api.js.map +1 -1
  79. package/icc-x-api/index.d.ts +1 -2
  80. package/icc-x-api/index.js +9 -8
  81. package/icc-x-api/index.js.map +1 -1
  82. package/icc-x-api/utils/binary-utils.js +5 -5
  83. package/icc-x-api/utils/binary-utils.js.map +1 -1
  84. package/icc-x-api/utils/crypto-utils.d.ts +61 -0
  85. package/icc-x-api/utils/crypto-utils.js +245 -0
  86. package/icc-x-api/utils/crypto-utils.js.map +1 -0
  87. package/icc-x-api/utils/formatting-util.js +3 -3
  88. package/icc-x-api/utils/formatting-util.js.map +1 -1
  89. package/icc-x-api/utils/functional-util.d.ts +1 -0
  90. package/icc-x-api/utils/functional-util.js +8 -1
  91. package/icc-x-api/utils/functional-util.js.map +1 -1
  92. package/icc-x-api/utils/index.d.ts +1 -0
  93. package/icc-x-api/utils/index.js +6 -1
  94. package/icc-x-api/utils/index.js.map +1 -1
  95. package/index.js +5 -1
  96. package/index.js.map +1 -1
  97. package/node-compat.d.ts +1 -1
  98. package/node-compat.js +3 -3
  99. package/node-compat.js.map +1 -1
  100. package/package.json +2 -2
  101. package/icc-x-api/crypto/utils.d.ts +0 -68
  102. package/icc-x-api/crypto/utils.js +0 -239
  103. package/icc-x-api/crypto/utils.js.map +0 -1
package/node-compat.js CHANGED
@@ -4,11 +4,11 @@ exports.nodeFetch = exports.crypto = void 0;
4
4
  const tmp = require('os').tmpdir();
5
5
  const util = require('util');
6
6
  exports.crypto = require('crypto').webcrypto;
7
- const node_fetch_1 = require("node-fetch");
7
+ require("isomorphic-fetch");
8
8
  global.localStorage = new (require('node-localstorage').LocalStorage)(tmp, 5 * 1024 * 1024 * 1024);
9
- global.fetch = node_fetch_1.default;
9
+ global.fetch = fetch;
10
10
  global.Storage = '';
11
11
  global.TextDecoder = util.TextDecoder;
12
12
  global.TextEncoder = util.TextEncoder;
13
- exports.nodeFetch = node_fetch_1.default;
13
+ exports.nodeFetch = fetch;
14
14
  //# sourceMappingURL=node-compat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-compat.js","sourceRoot":"","sources":["../node-compat.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAA;AAClC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEf,QAAA,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAA;AAEjD,2CACC;AAAC,MAAc,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAC3G;AAAC,MAAc,CAAC,KAAK,GAAG,oBAAK,CAC7B;AAAC,MAAc,CAAC,OAAO,GAAG,EAAE,CAC5B;AAAC,MAAc,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAC9C;AAAC,MAAc,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;AAElC,QAAA,SAAS,GAAG,oBAAK,CAAA","sourcesContent":["const tmp = require('os').tmpdir()\nconst util = require('util')\n\nexport const crypto = require('crypto').webcrypto\n\nimport fetch from 'node-fetch'\n;(global as any).localStorage = new (require('node-localstorage').LocalStorage)(tmp, 5 * 1024 * 1024 * 1024)\n;(global as any).fetch = fetch\n;(global as any).Storage = ''\n;(global as any).TextDecoder = util.TextDecoder\n;(global as any).TextEncoder = util.TextEncoder\n\nexport const nodeFetch = fetch\n"]}
1
+ {"version":3,"file":"node-compat.js","sourceRoot":"","sources":["../node-compat.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAA;AAClC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEf,QAAA,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAA;AAEjD,4BACC;AAAC,MAAc,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAC3G;AAAC,MAAc,CAAC,KAAK,GAAG,KAAK,CAC7B;AAAC,MAAc,CAAC,OAAO,GAAG,EAAE,CAC5B;AAAC,MAAc,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAC9C;AAAC,MAAc,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAA;AAElC,QAAA,SAAS,GAAG,KAAK,CAAA","sourcesContent":["const tmp = require('os').tmpdir()\nconst util = require('util')\n\nexport const crypto = require('crypto').webcrypto\n\nimport 'isomorphic-fetch'\n;(global as any).localStorage = new (require('node-localstorage').LocalStorage)(tmp, 5 * 1024 * 1024 * 1024)\n;(global as any).fetch = fetch\n;(global as any).Storage = ''\n;(global as any).TextDecoder = util.TextDecoder\n;(global as any).TextEncoder = util.TextEncoder\n\nexport const nodeFetch = fetch\n"]}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@icure/api",
3
- "version": "4.2.31",
3
+ "version": "5.0.3",
4
4
  "description": "Typescript version of iCure standalone API client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "dependencies": {
8
8
  "date-fns": "^2.23.0",
9
9
  "libphonenumber-js": "^1.7.18",
10
- "lodash": "^4.17.20",
10
+ "lodash": "^4.17.21",
11
11
  "moment": "^2.22.1",
12
12
  "text-encoding": "^0.7.0",
13
13
  "uuid": "^8.3.2",
@@ -1,68 +0,0 @@
1
- import { Moment } from 'moment';
2
- export declare class UtilsClass {
3
- constructor();
4
- notConcurrent<T>(concurrencyMap: {
5
- [key: string]: PromiseLike<T>;
6
- }, key: string, proc: () => PromiseLike<T>): PromiseLike<T>;
7
- jwk2pkcs8(jwk: any): string;
8
- jwk2spki(jwk: any): string;
9
- spkiToJwk(buf: Uint8Array): {
10
- kty: string;
11
- alg: string;
12
- n: string;
13
- e: string;
14
- ext: boolean;
15
- };
16
- pkcs8ToJwk(buf: Uint8Array | ArrayBuffer): {
17
- kty: string;
18
- n: string;
19
- e: string;
20
- d: string;
21
- p: string;
22
- q: string;
23
- dp: string;
24
- dq: string;
25
- qi: string;
26
- };
27
- minimalRep(b: Uint8Array): Uint8Array;
28
- /**
29
- * Provide a view over the given Uint8Array where any trailing null bytes at
30
- * the end are truncated.
31
- *
32
- * This can be used to ignore null bytes at the end of a padded UTF-8 string
33
- * without needing to copy that string, assuming code point U+0000 is encoded
34
- * in one null byte according to standards rather than in a multi-byte
35
- * overlong form.
36
- */
37
- truncateTrailingNulls(a: Uint8Array): Uint8Array;
38
- /**
39
- *
40
- * @param buffer1 {Uint8Array}
41
- * @param buffer2{ Uint8Array}
42
- * @returns {ArrayBuffer}
43
- */
44
- appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer;
45
- after(d1: number, d2: number): boolean;
46
- before(d1: number, d2: number): boolean;
47
- moment(epochOrLongCalendar: number): Moment | null;
48
- /**
49
- * Encrypt object graph recursively
50
- *
51
- * @param obj the object to encrypt
52
- * @param cryptor the cryptor function (returns a promise)
53
- * @param keys the keys to be crypted: ex for a Patient ['note', 'addresses.*.["street", "houseNumber", "telecoms.*.telecomNumber"]']
54
- */
55
- crypt(obj: any, cryptor: (obj: {
56
- [key: string]: string;
57
- }) => Promise<ArrayBuffer>, keys: Array<string>): Promise<any>;
58
- /**
59
- * Decrypt object graph recursively
60
- *
61
- * @param obj the object to encrypt
62
- * @param decryptor the decryptor function (returns a promise)
63
- */
64
- decrypt(obj: any, decryptor: (obj: Uint8Array) => Promise<{
65
- [key: string]: string;
66
- }>): Promise<any>;
67
- }
68
- export declare const utils: UtilsClass;
@@ -1,239 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.utils = exports.UtilsClass = void 0;
13
- const moment = require("moment");
14
- const _ = require("lodash");
15
- const binary_utils_1 = require("../utils/binary-utils");
16
- const asn1_packer_1 = require("../utils/asn1-packer");
17
- const asn1_parser_1 = require("../utils/asn1-parser");
18
- class UtilsClass {
19
- constructor() { }
20
- notConcurrent(concurrencyMap, key, proc) {
21
- const inFlight = concurrencyMap[key];
22
- if (!inFlight) {
23
- return (concurrencyMap[key] = (() => __awaiter(this, void 0, void 0, function* () {
24
- try {
25
- return yield proc();
26
- }
27
- finally {
28
- delete concurrencyMap[key];
29
- }
30
- }))());
31
- }
32
- else {
33
- return concurrencyMap[key].then(() => this.notConcurrent(concurrencyMap, key, proc));
34
- }
35
- }
36
- jwk2pkcs8(jwk) {
37
- return asn1_packer_1.pack([
38
- 0x30,
39
- [
40
- [0x02, '00'],
41
- [0x30, [[0x06, '2a864886f70d010101'], [0x05]]],
42
- [
43
- 0x04,
44
- [
45
- [
46
- 0x30,
47
- [
48
- [0x02, '00'],
49
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.n))],
50
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.e))],
51
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.d))],
52
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.p))],
53
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.q))],
54
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.dp))],
55
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.dq))],
56
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.qi))],
57
- ],
58
- ],
59
- ],
60
- ],
61
- ],
62
- ]);
63
- }
64
- jwk2spki(jwk) {
65
- return asn1_packer_1.pack([
66
- 0x30,
67
- [
68
- [0x30, [[0x06, '2a864886f70d010101'], [0x05]]],
69
- [
70
- 0x03,
71
- [
72
- [
73
- 0x30,
74
- [
75
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.n))],
76
- [0x02, binary_utils_1.ua2hex(binary_utils_1.b64Url2ua(jwk.e))],
77
- ],
78
- ],
79
- ],
80
- ],
81
- ],
82
- ]);
83
- }
84
- spkiToJwk(buf) {
85
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
86
- const asn1 = asn1_parser_1.parseAsn1(new Uint8Array(buf));
87
- var modulus = undefined;
88
- var exponent = undefined;
89
- if (asn1.type === 0x30 &&
90
- ((_b = (_a = asn1.children) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === 0x30 &&
91
- ((_f = (_e = (_d = (_c = asn1.children) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.children) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.type) === 0x06 &&
92
- binary_utils_1.ua2hex((_l = (_k = (_j = (_h = (_g = asn1.children) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.children) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : new Uint8Array()) === '2a864886f70d010101') {
93
- modulus = (_s = (_r = (_q = (_p = (_o = (_m = asn1.children) === null || _m === void 0 ? void 0 : _m[1]) === null || _o === void 0 ? void 0 : _o.children) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.children) === null || _r === void 0 ? void 0 : _r[0]) === null || _s === void 0 ? void 0 : _s.value;
94
- exponent = (_y = (_x = (_w = (_v = (_u = (_t = asn1.children) === null || _t === void 0 ? void 0 : _t[1]) === null || _u === void 0 ? void 0 : _u.children) === null || _v === void 0 ? void 0 : _v[0]) === null || _w === void 0 ? void 0 : _w.children) === null || _x === void 0 ? void 0 : _x[1]) === null || _y === void 0 ? void 0 : _y.value;
95
- }
96
- else if (asn1.type === 0x30 && ((_0 = (_z = asn1.children) === null || _z === void 0 ? void 0 : _z[0]) === null || _0 === void 0 ? void 0 : _0.type) === 0x02 && ((_2 = (_1 = asn1.children) === null || _1 === void 0 ? void 0 : _1[1]) === null || _2 === void 0 ? void 0 : _2.type) === 0x02) {
97
- modulus = (_4 = (_3 = asn1.children) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.value;
98
- exponent = (_6 = (_5 = asn1.children) === null || _5 === void 0 ? void 0 : _5[1]) === null || _6 === void 0 ? void 0 : _6.value;
99
- }
100
- if (!modulus || !exponent) {
101
- throw new Error('Invalid spki format');
102
- }
103
- return {
104
- kty: 'RSA',
105
- alg: 'RSA-OAEP',
106
- ext: true,
107
- n: binary_utils_1.ua2b64Url(this.minimalRep(modulus)),
108
- e: binary_utils_1.ua2b64Url(this.minimalRep(exponent)),
109
- };
110
- }
111
- pkcs8ToJwk(buf) {
112
- var _a, _b;
113
- const parsed = asn1_parser_1.parseAsn1(new Uint8Array(buf));
114
- const seq = ((_a = parsed.children) === null || _a === void 0 ? void 0 : _a.length) === 3 && parsed.children[2].type === 0x04 && ((_b = parsed.children[2].children) === null || _b === void 0 ? void 0 : _b.length) === 1
115
- ? parsed.children[2].children[0]
116
- : parsed;
117
- return {
118
- kty: 'RSA',
119
- n: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[1].value)),
120
- e: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[2].value)),
121
- d: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[3].value)),
122
- p: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[4].value)),
123
- q: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[5].value)),
124
- dp: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[6].value)),
125
- dq: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[7].value)),
126
- qi: binary_utils_1.ua2b64Url(this.minimalRep(seq.children[8].value)),
127
- };
128
- }
129
- minimalRep(b) {
130
- let i = 0;
131
- while (b[i] === 0) {
132
- i++;
133
- }
134
- return b.slice(i);
135
- }
136
- /**
137
- * Provide a view over the given Uint8Array where any trailing null bytes at
138
- * the end are truncated.
139
- *
140
- * This can be used to ignore null bytes at the end of a padded UTF-8 string
141
- * without needing to copy that string, assuming code point U+0000 is encoded
142
- * in one null byte according to standards rather than in a multi-byte
143
- * overlong form.
144
- */
145
- truncateTrailingNulls(a) {
146
- let end = a.byteLength - 1;
147
- while (a[end] === 0 && end >= 0) {
148
- end--;
149
- }
150
- // end is now either the last non-null position in a or -1; in the latter
151
- // case the returned array will have length 0.
152
- return a.subarray(0, end + 1);
153
- }
154
- /**
155
- *
156
- * @param buffer1 {Uint8Array}
157
- * @param buffer2{ Uint8Array}
158
- * @returns {ArrayBuffer}
159
- */
160
- appendBuffer(buffer1, buffer2) {
161
- const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
162
- tmp.set(new Uint8Array(buffer1), 0);
163
- tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
164
- return tmp.buffer;
165
- }
166
- //Convenience methods for dates management
167
- after(d1, d2) {
168
- return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1).isAfter(this.moment(d2));
169
- }
170
- before(d1, d2) {
171
- return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1).isBefore(this.moment(d2));
172
- }
173
- moment(epochOrLongCalendar) {
174
- if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {
175
- return null;
176
- }
177
- if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {
178
- return moment('' + epochOrLongCalendar, 'YYYYMMDD');
179
- }
180
- else if (epochOrLongCalendar >= 18000101000000) {
181
- return moment('' + epochOrLongCalendar, 'YYYYMMDDHHmmss');
182
- }
183
- else {
184
- return moment(epochOrLongCalendar);
185
- }
186
- }
187
- /**
188
- * Encrypt object graph recursively
189
- *
190
- * @param obj the object to encrypt
191
- * @param cryptor the cryptor function (returns a promise)
192
- * @param keys the keys to be crypted: ex for a Patient ['note', 'addresses.*.["street", "houseNumber", "telecoms.*.telecomNumber"]']
193
- */
194
- crypt(obj, cryptor, keys) {
195
- return __awaiter(this, void 0, void 0, function* () {
196
- const subObj = _.pick(obj, keys.filter((k) => !k.includes('*')));
197
- obj.encryptedSelf = binary_utils_1.b2a(binary_utils_1.ua2string(yield cryptor(subObj)));
198
- Object.keys(subObj).forEach((k) => delete obj[k]);
199
- yield keys
200
- .filter((k) => k.includes('*'))
201
- .reduce((prev, k) => __awaiter(this, void 0, void 0, function* () {
202
- yield prev;
203
- const k1 = k.split('.*.')[0];
204
- const k2 = k.substr(k1.length + 3);
205
- const mapped = yield Promise.all((_.get(obj, k1) || []).map((so) => this.crypt(so, cryptor, k2.startsWith('[') ? JSON.parse(k2) : [k2])));
206
- _.set(obj, k1, mapped);
207
- }), Promise.resolve());
208
- return obj;
209
- });
210
- }
211
- /**
212
- * Decrypt object graph recursively
213
- *
214
- * @param obj the object to encrypt
215
- * @param decryptor the decryptor function (returns a promise)
216
- */
217
- decrypt(obj, decryptor) {
218
- return __awaiter(this, void 0, void 0, function* () {
219
- yield Object.keys(obj).reduce((prev, k) => __awaiter(this, void 0, void 0, function* () {
220
- yield prev;
221
- if (Array.isArray(obj[k])) {
222
- yield obj[k]
223
- .filter((o) => typeof o === 'object' && o !== null)
224
- .reduce((prev, so) => __awaiter(this, void 0, void 0, function* () {
225
- yield prev;
226
- yield this.decrypt(so, decryptor);
227
- }), Promise.resolve());
228
- }
229
- }), Promise.resolve());
230
- if (obj.encryptedSelf) {
231
- Object.assign(obj, yield decryptor(binary_utils_1.string2ua(binary_utils_1.a2b(obj.encryptedSelf))));
232
- }
233
- return obj;
234
- });
235
- }
236
- }
237
- exports.UtilsClass = UtilsClass;
238
- exports.utils = new UtilsClass();
239
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAgC;AAEhC,4BAA2B;AAC3B,wDAAoG;AACpG,sDAA2C;AAC3C,sDAAgD;AAEhD,MAAa,UAAU;IACrB,gBAAe,CAAC;IAEhB,aAAa,CAAI,cAAiD,EAAE,GAAW,EAAE,IAA0B;QACzG,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;QACpC,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAS,EAAE;gBACxC,IAAI;oBACF,OAAO,MAAM,IAAI,EAAE,CAAA;iBACpB;wBAAS;oBACR,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;iBAC3B;YACH,CAAC,CAAA,CAAC,EAAE,CAAC,CAAA;SACN;aAAM;YACL,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;S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E,CAAC,CAAA;iBACxB;YACH,CAAC,CAAA,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;YACrB,IAAI,GAAG,CAAC,aAAa,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,SAAS,CAAC,wBAAS,CAAC,kBAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;aACvE;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KAAA;CACF;AAvOD,gCAuOC;AAEY,QAAA,KAAK,GAAG,IAAI,UAAU,EAAE,CAAA","sourcesContent":["import * as moment 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 '../utils/asn1-packer'\nimport { parseAsn1 } from '../utils/asn1-parser'\n\nexport class UtilsClass {\n constructor() {}\n\n 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(() => this.notConcurrent(concurrencyMap, key, proc))\n }\n }\n\n jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]],\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\n jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]],\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\n 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()) === '2a864886f70d010101'\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(this.minimalRep(modulus)),\n e: ua2b64Url(this.minimalRep(exponent)),\n }\n }\n\n 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(this.minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(this.minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(this.minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(this.minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(this.minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(this.minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(this.minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(this.minimalRep(seq.children![8].value as Uint8Array)),\n }\n }\n\n 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 */\n 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 */\n 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\n after(d1: number, d2: number): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1)!.isAfter(this.moment(d2)!)\n }\n\n before(d1: number, d2: number): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1)!.isBefore(this.moment(d2)!)\n }\n\n moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return moment(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 */\n async 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) => this.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 */\n async 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 this.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\nexport const utils = new UtilsClass()\n"]}