@gerege-systems/eid-mongolia-sdk 0.20.1 → 0.21.0

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.
@@ -133,7 +133,7 @@ var ResponseTooLargeError = class extends EidError {
133
133
  limit;
134
134
  };
135
135
  function maskPath(path) {
136
- return path.split(/[?#]/)[0].replace(/\/(etsi|document)\/[^/?#\s]+/g, "/$1/\u2026");
136
+ return path.split(/[?#]/)[0].replace(/\/(etsi|document|linked)\/[^/?#\s]+/g, "/$1/\u2026");
137
137
  }
138
138
  var SessionFailedError = class extends EidError {
139
139
  constructor(endResult) {
package/dist/convert.js CHANGED
@@ -66,23 +66,25 @@ var InflateError = class extends Error {
66
66
  };
67
67
  var Truncated = class extends InflateError {
68
68
  };
69
- function zlibInflate(src, limit = 64 << 20) {
69
+ var InflateLimitError = class extends InflateError {
70
+ };
71
+ function zlibInflate(src, limit = 64 << 20, initial) {
70
72
  if (src.length < 2) throw new InflateError("zlib: header \u0430\u043B\u0433\u0430");
71
73
  const cmf = src[0];
72
74
  const flg = src[1];
73
75
  if ((cmf & 15) !== 8 || cmf >> 4 > 7 || (cmf << 8 | flg) % 31 !== 0) throw new InflateError("zlib: header \u0431\u0443\u0440\u0443\u0443");
74
76
  if (flg & 32) throw new InflateError("zlib: preset dictionary");
75
- return inflateRaw(src.subarray(2), limit);
77
+ return inflateRaw(src.subarray(2), limit, void 0, initial);
76
78
  }
77
- function inflateRaw(src, limit = 64 << 20, info) {
79
+ function inflateRaw(src, limit = 64 << 20, info, initial) {
78
80
  let pos = 0;
79
81
  let bitBuf = 0;
80
82
  let bitCnt = 0;
81
- let out = new Uint8Array(Math.min(limit, Math.max(1024, src.length * 4)));
83
+ let out = new Uint8Array(Math.min(limit, Math.max(1024, initial ?? src.length * 4)));
82
84
  let len = 0;
83
85
  const need = (n) => {
84
86
  if (len + n <= out.length) return;
85
- if (len + n > limit) throw new InflateError("inflate: \u0445\u044D\u043C\u0436\u044D\u044D\u043D\u0438\u0439 \u0445\u044F\u0437\u0433\u0430\u0430\u0440");
87
+ if (len + n > limit) throw new InflateLimitError("inflate: \u0445\u044D\u043C\u0436\u044D\u044D\u043D\u0438\u0439 \u0445\u044F\u0437\u0433\u0430\u0430\u0440");
86
88
  let cap = out.length * 2;
87
89
  while (cap < len + n) cap *= 2;
88
90
  const nb = new Uint8Array(Math.min(cap, limit));
@@ -944,28 +946,17 @@ var Reader = class {
944
946
  };
945
947
  function findStartXref(b) {
946
948
  const end = b.length;
947
- let searchSize = 200;
948
- let eofEnd = -1;
949
- for (; ; ) {
950
- const from = Math.max(0, end - searchSize);
951
- if (end - searchSize >= 0) {
952
- let hi = end;
953
- while (hi > from && (b[hi - 1] === 10 || b[hi - 1] === 13)) hi--;
954
- while (hi > from && (b[hi - 1] === 10 || b[hi - 1] === 13 || b[hi - 1] === 9 || b[hi - 1] === 32)) hi--;
955
- for (; ; ) {
956
- if (hi - from === 5) break;
957
- if (hi - from >= 5 && fromLatin1(b, hi - 5, hi) === "%%EOF") {
958
- eofEnd = hi;
959
- break;
960
- }
961
- if (hi - from < 5) break;
962
- hi--;
963
- }
964
- if (eofEnd >= 0) break;
949
+ let hi = end;
950
+ while (hi > 0 && (b[hi - 1] === 10 || b[hi - 1] === 13 || b[hi - 1] === 9 || b[hi - 1] === 32)) hi--;
951
+ let idx = -1;
952
+ for (let i2 = hi - 5; i2 >= 0; i2--) {
953
+ if (b[i2] === 37 && b[i2 + 1] === 37 && b[i2 + 2] === 69 && b[i2 + 3] === 79 && b[i2 + 4] === 70) {
954
+ idx = i2;
955
+ break;
965
956
  }
966
- searchSize += 200;
967
- if (searchSize > end) throw new PdfError("not a PDF file: missing %%EOF");
968
957
  }
958
+ if (idx < 0 || 200 * (Math.floor((end - idx) / 200) + 1) > end) throw new PdfError("not a PDF file: missing %%EOF");
959
+ const eofEnd = idx + 5;
969
960
  const winStart = eofEnd - 200;
970
961
  if (winStart < 0) throw new PdfError("malformed PDF file: missing final startxref");
971
962
  const buf = b.subarray(winStart, eofEnd);
package/dist/index.cjs CHANGED
@@ -228,7 +228,7 @@ var ResponseTooLargeError = class extends EidError {
228
228
  limit;
229
229
  };
230
230
  function maskPath(path) {
231
- return path.split(/[?#]/)[0].replace(/\/(etsi|document)\/[^/?#\s]+/g, "/$1/\u2026");
231
+ return path.split(/[?#]/)[0].replace(/\/(etsi|document|linked)\/[^/?#\s]+/g, "/$1/\u2026");
232
232
  }
233
233
  var SessionFailedError = class extends EidError {
234
234
  constructor(endResult) {
@@ -2235,6 +2235,7 @@ async function shareInfo(http) {
2235
2235
  var DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
2236
2236
  var DEFAULT_PDF_TIMEOUT_MS = 8e4;
2237
2237
  var LEGACY_HOSTS = /* @__PURE__ */ new Set(["ca.eidmongolia.mn", "e-id.mn", "www.e-id.mn"]);
2238
+ var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
2238
2239
  function resolveBaseUrl(baseUrl) {
2239
2240
  const raw = (baseUrl ?? DEFAULT_BASE_URL).trim().replace(/\/+$/, "");
2240
2241
  let u;
@@ -2243,6 +2244,9 @@ function resolveBaseUrl(baseUrl) {
2243
2244
  } catch {
2244
2245
  throw new Error(`EidClient: baseUrl \u0431\u0443\u0440\u0443\u0443 URL: ${raw}`);
2245
2246
  }
2247
+ if (u.protocol !== "https:" && !(u.protocol === "http:" && LOOPBACK.has(u.hostname))) {
2248
+ throw new Error(`EidClient: baseUrl https \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439 (http \u0437\u04E9\u0432\u0445\u04E9\u043D localhost): ${u.protocol}//${u.host}`);
2249
+ }
2246
2250
  if (LEGACY_HOSTS.has(u.hostname) && (u.pathname === "" || u.pathname === "/")) {
2247
2251
  throw new Error(
2248
2252
  `EidClient: RP-API ${u.hostname}-\u0430\u0430\u0441 ${DEFAULT_BASE_URL} \u0440\u0443\u0443 \u0448\u0438\u043B\u0436\u0441\u044D\u043D (/v3-\u0433\u04AF\u0439) \u2014 baseUrl-\u0438\u0439\u0433 ${DEFAULT_BASE_URL} \u0431\u043E\u043B\u0433\u043E\u043D\u043E \u0443\u0443 (\u044D\u0441\u0432\u044D\u043B \u0445\u043E\u043E\u0441\u043E\u043D \u043E\u0440\u0445\u0438).`
@@ -2773,6 +2777,59 @@ var HASHES2 = {
2773
2777
  [OID.sha512]: "SHA-512"
2774
2778
  };
2775
2779
 
2780
+ // src/pades/validate/gofmt.ts
2781
+ var NO_RUNE = -1;
2782
+ var PDF_DOC = (() => {
2783
+ const t = new Array(256).fill(NO_RUNE);
2784
+ t[9] = 9;
2785
+ t[10] = 10;
2786
+ t[13] = 13;
2787
+ [728, 711, 710, 729, 733, 731, 730, 732].forEach((r, i) => t[24 + i] = r);
2788
+ for (let i = 32; i < 127; i++) t[i] = i;
2789
+ [
2790
+ 8226,
2791
+ 8224,
2792
+ 8225,
2793
+ 8230,
2794
+ 8212,
2795
+ 8211,
2796
+ 402,
2797
+ 8260,
2798
+ 8249,
2799
+ 8250,
2800
+ 8722,
2801
+ 8240,
2802
+ 8222,
2803
+ 8220,
2804
+ 8221,
2805
+ 8216,
2806
+ 8217,
2807
+ 8218,
2808
+ 8482,
2809
+ 64257,
2810
+ 64258,
2811
+ 321,
2812
+ 338,
2813
+ 352,
2814
+ 376,
2815
+ 381,
2816
+ 305,
2817
+ 322,
2818
+ 339,
2819
+ 353,
2820
+ 382,
2821
+ NO_RUNE
2822
+ ].forEach((r, i) => t[128 + i] = r);
2823
+ t[160] = 8364;
2824
+ for (let i = 161; i <= 255; i++) t[i] = i;
2825
+ t[173] = NO_RUNE;
2826
+ return t;
2827
+ })();
2828
+
2829
+ // src/pades/revocation.ts
2830
+ var REVOCATION_MAX_AGE_MS = 24 * 36e5;
2831
+ var REVOCATION_CLOCK_SKEW_MS = 5 * 6e4;
2832
+
2776
2833
  // src/pades/ltv.ts
2777
2834
  var MAX_TSA_SKEW_MS = 10 * 6e4;
2778
2835
  async function ocspRequest(c, issuer) {
@@ -2839,9 +2896,9 @@ async function parseOCSP(der, serial, issuer) {
2839
2896
  if (!status) throw new Error("OCSP certStatus");
2840
2897
  const revokedAt = status === "revoked" ? parsePreciseTime(expect(children(st)[0], TAG.GeneralizedTime, "revocationTime")) : void 0;
2841
2898
  const thisUpdate = parsePreciseTime(expect(single[2], TAG.GeneralizedTime, "thisUpdate"));
2842
- let nextUpdate;
2899
+ let nextUpdatePrecise;
2843
2900
  for (const x of single.slice(3)) {
2844
- if (x.tag === 160) nextUpdate = parsePreciseTime(children(x)[0]).date;
2901
+ if (x.tag === 160) nextUpdatePrecise = parsePreciseTime(children(x)[0]);
2845
2902
  if (x.tag === 161) {
2846
2903
  for (const ext of children(children(x)[0])) {
2847
2904
  const e = children(ext);
@@ -2849,7 +2906,7 @@ async function parseOCSP(der, serial, issuer) {
2849
2906
  }
2850
2907
  }
2851
2908
  }
2852
- return { status, serial: intValue(expect(cid[3], TAG.INTEGER, "serial").value), thisUpdate, nextUpdate, revokedAt, certificate };
2909
+ return { status, serial: intValue(expect(cid[3], TAG.INTEGER, "serial").value), thisUpdate, nextUpdate: nextUpdatePrecise?.date, nextUpdatePrecise, revokedAt, certificate };
2853
2910
  }
2854
2911
  function sameCertKey(a, b) {
2855
2912
  return equal(a.raw, b.raw) || equal(a.rawSubject, b.rawSubject) && equal(a.spki, b.spki);
package/dist/index.d.cts CHANGED
@@ -1130,7 +1130,7 @@ interface ClientConfig {
1130
1130
  declare const DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
1131
1131
  /** `registerSignature`-ийн анхдагч хугацаа (мс) — Go SDK `DefaultPDFTimeout` (80s)-тэй ижил. */
1132
1132
  declare const DEFAULT_PDF_TIMEOUT_MS = 80000;
1133
- /** baseUrl-ийг шалгаж, төгсгөлийн "/"-ийг хасна. */
1133
+ /** baseUrl-ийг шалгаж (https; http зөвхөн localhost / 127.0.0.1 / [::1]), төгсгөлийн "/"-ийг хасна. */
1134
1134
  declare function resolveBaseUrl(baseUrl: string | undefined): string;
1135
1135
  declare class EidClient {
1136
1136
  readonly auth: AuthApi;
@@ -1309,7 +1309,10 @@ interface EidLoginIdentity {
1309
1309
  surname: string | null;
1310
1310
  name: string | null;
1311
1311
  country: string | null;
1312
- /** Иргэний баримтын дугаар (`PNOMN-…-MOBILE-Q` г.м.) — `client.sign.*ByDocument`-аар ижил төхөөрөмж рүү гарын үсэг. */
1312
+ /**
1313
+ * Нэвтэрсэн төхөөрөмжийн UUID (RP-API `documentNumber`; иргэний бичиг баримтын дугаар ч, `PNOMN-…` ETSI ч биш) —
1314
+ * `client.sign.*ByDocument`-аар ижил төхөөрөмж рүү гарын үсэг. Тунгалаг мөр: хэлбэрийг задлахгүй.
1315
+ */
1313
1316
  documentNumber: string;
1314
1317
  certificateLevel: string;
1315
1318
  /** Иргэний нэвтрэлтийн гэрчилгээ (DER, base64) — validateAuth-аар гинж шалгагдсан. */
package/dist/index.d.ts CHANGED
@@ -1130,7 +1130,7 @@ interface ClientConfig {
1130
1130
  declare const DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
1131
1131
  /** `registerSignature`-ийн анхдагч хугацаа (мс) — Go SDK `DefaultPDFTimeout` (80s)-тэй ижил. */
1132
1132
  declare const DEFAULT_PDF_TIMEOUT_MS = 80000;
1133
- /** baseUrl-ийг шалгаж, төгсгөлийн "/"-ийг хасна. */
1133
+ /** baseUrl-ийг шалгаж (https; http зөвхөн localhost / 127.0.0.1 / [::1]), төгсгөлийн "/"-ийг хасна. */
1134
1134
  declare function resolveBaseUrl(baseUrl: string | undefined): string;
1135
1135
  declare class EidClient {
1136
1136
  readonly auth: AuthApi;
@@ -1309,7 +1309,10 @@ interface EidLoginIdentity {
1309
1309
  surname: string | null;
1310
1310
  name: string | null;
1311
1311
  country: string | null;
1312
- /** Иргэний баримтын дугаар (`PNOMN-…-MOBILE-Q` г.м.) — `client.sign.*ByDocument`-аар ижил төхөөрөмж рүү гарын үсэг. */
1312
+ /**
1313
+ * Нэвтэрсэн төхөөрөмжийн UUID (RP-API `documentNumber`; иргэний бичиг баримтын дугаар ч, `PNOMN-…` ETSI ч биш) —
1314
+ * `client.sign.*ByDocument`-аар ижил төхөөрөмж рүү гарын үсэг. Тунгалаг мөр: хэлбэрийг задлахгүй.
1315
+ */
1313
1316
  documentNumber: string;
1314
1317
  certificateLevel: string;
1315
1318
  /** Иргэний нэвтрэлтийн гэрчилгээ (DER, base64) — validateAuth-аар гинж шалгагдсан. */
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  parseCertificate,
11
11
  parseOCSPFrom,
12
12
  sameCertKey
13
- } from "./chunk-JV4NR4LG.js";
13
+ } from "./chunk-ISTWNY6N.js";
14
14
  import {
15
15
  ApiError,
16
16
  AuthenticationError,
@@ -29,7 +29,7 @@ import {
29
29
  ValidationError,
30
30
  maskPath,
31
31
  parseRetryAfter
32
- } from "./chunk-D5NPS7ET.js";
32
+ } from "./chunk-ZB7LEWA5.js";
33
33
 
34
34
  // src/http.ts
35
35
  var DEFAULT_TIMEOUT_MS = 15e3;
@@ -2006,6 +2006,7 @@ async function shareInfo(http) {
2006
2006
  var DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
2007
2007
  var DEFAULT_PDF_TIMEOUT_MS = 8e4;
2008
2008
  var LEGACY_HOSTS = /* @__PURE__ */ new Set(["ca.eidmongolia.mn", "e-id.mn", "www.e-id.mn"]);
2009
+ var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
2009
2010
  function resolveBaseUrl(baseUrl) {
2010
2011
  const raw = (baseUrl ?? DEFAULT_BASE_URL).trim().replace(/\/+$/, "");
2011
2012
  let u;
@@ -2014,6 +2015,9 @@ function resolveBaseUrl(baseUrl) {
2014
2015
  } catch {
2015
2016
  throw new Error(`EidClient: baseUrl \u0431\u0443\u0440\u0443\u0443 URL: ${raw}`);
2016
2017
  }
2018
+ if (u.protocol !== "https:" && !(u.protocol === "http:" && LOOPBACK.has(u.hostname))) {
2019
+ throw new Error(`EidClient: baseUrl https \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439 (http \u0437\u04E9\u0432\u0445\u04E9\u043D localhost): ${u.protocol}//${u.host}`);
2020
+ }
2017
2021
  if (LEGACY_HOSTS.has(u.hostname) && (u.pathname === "" || u.pathname === "/")) {
2018
2022
  throw new Error(
2019
2023
  `EidClient: RP-API ${u.hostname}-\u0430\u0430\u0441 ${DEFAULT_BASE_URL} \u0440\u0443\u0443 \u0448\u0438\u043B\u0436\u0441\u044D\u043D (/v3-\u0433\u04AF\u0439) \u2014 baseUrl-\u0438\u0439\u0433 ${DEFAULT_BASE_URL} \u0431\u043E\u043B\u0433\u043E\u043D\u043E \u0443\u0443 (\u044D\u0441\u0432\u044D\u043B \u0445\u043E\u043E\u0441\u043E\u043D \u043E\u0440\u0445\u0438).`