@gerege-systems/eid-mongolia-sdk 0.30.1 → 0.32.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.
package/dist/validate.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Fetcher,
3
3
  InflateError,
4
+ MAX_IMAGE_SIDE,
4
5
  PRef,
5
6
  Reader,
6
7
  StructureError,
@@ -11,7 +12,7 @@ import {
11
12
  isBrowser,
12
13
  round100,
13
14
  visibleWidget
14
- } from "./chunk-MA4RMWBO.js";
15
+ } from "./chunk-M4NS4UFP.js";
15
16
  import {
16
17
  EID_ISSUERS,
17
18
  INTERMEDIATES,
@@ -65,7 +66,7 @@ import {
65
66
  } from "./chunk-ISTWNY6N.js";
66
67
  import {
67
68
  EidError
68
- } from "./chunk-H7JOACAZ.js";
69
+ } from "./chunk-R73IR6OH.js";
69
70
 
70
71
  // src/pades/validate/evaluate.ts
71
72
  var PROBLEMS = {
@@ -1408,7 +1409,7 @@ function ownVisible(c, d, widget) {
1408
1409
  const m = ms.v;
1409
1410
  if (!ownDate(m) || m.slice(16) !== "+08'00'") throw fail();
1410
1411
  const date = `${m.slice(2, 6)}-${m.slice(6, 8)}-${m.slice(8, 10)} ${m.slice(10, 12)}:${m.slice(12, 14)} (+08)`;
1411
- const ids = apIDs(c, nr);
1412
+ const { ids, sig, stamp } = apIDs(c, nr);
1412
1413
  const form = c.fin.get(ids[0]);
1413
1414
  if (!(form instanceof PStream)) throw fail();
1414
1415
  let head = "";
@@ -1420,7 +1421,7 @@ function ownVisible(c, d, widget) {
1420
1421
  for (const lang of ["mn", "en"]) {
1421
1422
  let bodies;
1422
1423
  try {
1423
- bodies = appearanceObjects({ w, h, rotate: rot, name, role: meta.role, lang, date, url }, ids);
1424
+ bodies = appearanceObjects({ w, h, rotate: rot, name, role: meta.role, lang, date, url, sig, stamp }, ids);
1424
1425
  } catch {
1425
1426
  throw fail();
1426
1427
  }
@@ -1468,6 +1469,21 @@ function apIDs(c, n) {
1468
1469
  if (!(ff instanceof PRef2)) throw fail();
1469
1470
  refs.push(t0, cid, fd, ff, tu);
1470
1471
  }
1472
+ let sig;
1473
+ let stamp;
1474
+ if (isDict(res) && res.has("XObject")) {
1475
+ const xo = dget(res, "XObject");
1476
+ if (!isDict(xo)) throw fail();
1477
+ for (const key of ["Sig", "Stamp"]) {
1478
+ if (!xo.has(key)) continue;
1479
+ const br = dget(xo, key);
1480
+ if (!(br instanceof PRef2)) throw fail();
1481
+ const { im, mr } = apImage(c, br);
1482
+ refs.push(br, mr);
1483
+ if (key === "Sig") sig = im;
1484
+ else stamp = im;
1485
+ }
1486
+ }
1471
1487
  const seen = /* @__PURE__ */ new Set();
1472
1488
  const ids = [];
1473
1489
  for (const r of refs) {
@@ -1475,7 +1491,21 @@ function apIDs(c, n) {
1475
1491
  seen.add(r.num);
1476
1492
  ids.push(r.num);
1477
1493
  }
1478
- return ids;
1494
+ return { ids, sig, stamp };
1495
+ }
1496
+ function apImage(c, br) {
1497
+ const fail = errNotSignatureOnly;
1498
+ const base = c.fin.deref(br);
1499
+ if (!(base instanceof PStream) || base.data.length !== 3) throw fail();
1500
+ const mr = dget(base.dict, "SMask");
1501
+ if (!(mr instanceof PRef2)) throw fail();
1502
+ const mask = c.fin.deref(mr);
1503
+ if (!(mask instanceof PStream)) throw fail();
1504
+ const w = dget(mask.dict, "Width");
1505
+ const h = dget(mask.dict, "Height");
1506
+ const side = BigInt(MAX_IMAGE_SIDE);
1507
+ if (!isInt(w) || !isInt(h) || w < 1n || h < 1n || w > side || h > side) throw fail();
1508
+ return { im: { w: Number(w), h: Number(h), color: [base.data[0], base.data[1], base.data[2]], alpha: mask.data }, mr };
1479
1509
  }
1480
1510
  var isSpaceByte = (x) => x === 9 || x === 10 || x === 11 || x === 12 || x === 13 || x === 32;
1481
1511
  function sameObject(c, num, body) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gerege-systems/eid-mongolia-sdk",
3
- "version": "0.30.1",
3
+ "version": "0.32.0",
4
4
  "description": "e-ID Mongolia Relying Party SDK — иргэнээр утсаар нь нэвтрэлт ба хууль ёсны цахим гарын үсэг (RP-API v3, Smart-ID нийцтэй).",
5
5
  "license": "MIT",
6
6
  "type": "module",