@gerege-systems/eid-mongolia-sdk 0.33.0 → 0.35.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/README.md +7 -28
- package/dist/{types-Cf3GT4wh.d.cts → browser-CCP--VGv.d.ts} +17 -50
- package/dist/{types-Cf3GT4wh.d.ts → browser-w1Ca6FdZ.d.cts} +17 -50
- package/dist/browser.d.cts +2 -18
- package/dist/browser.d.ts +2 -18
- package/dist/browser.js +1 -1
- package/dist/{chunk-M4NS4UFP.js → chunk-MA4RMWBO.js} +13 -102
- package/dist/{chunk-TNXO4QLU.js → chunk-PWFTN52X.js} +0 -1
- package/dist/{errors-mcDbKiz_.d.cts → errors-CgJcEjrZ.d.cts} +2 -2
- package/dist/{errors-mcDbKiz_.d.ts → errors-CgJcEjrZ.d.ts} +2 -2
- package/dist/index.cjs +18 -26
- package/dist/index.d.cts +26 -30
- package/dist/index.d.ts +26 -30
- package/dist/index.js +19 -26
- package/dist/pades.cjs +20 -169
- package/dist/pades.d.cts +2 -44
- package/dist/pades.d.ts +2 -44
- package/dist/pades.js +9 -71
- package/dist/validate.cjs +15 -150
- package/dist/validate.d.cts +1 -1
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +5 -35
- package/package.json +1 -1
package/dist/pades.js
CHANGED
|
@@ -7,10 +7,8 @@ import {
|
|
|
7
7
|
PRef,
|
|
8
8
|
PdfError,
|
|
9
9
|
Reader,
|
|
10
|
-
appearanceObjectCount,
|
|
11
10
|
appearanceObjects,
|
|
12
11
|
appendVerifyPage,
|
|
13
|
-
checkPdfImage,
|
|
14
12
|
checkStructure,
|
|
15
13
|
defaultStampPage,
|
|
16
14
|
escapeName,
|
|
@@ -25,7 +23,7 @@ import {
|
|
|
25
23
|
visibleRect,
|
|
26
24
|
visibleWidget,
|
|
27
25
|
zlibInflateStrict
|
|
28
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-MA4RMWBO.js";
|
|
29
27
|
import {
|
|
30
28
|
CLAIMED_ROLE_MAX_RUNES,
|
|
31
29
|
CertificateRevokedError,
|
|
@@ -61,7 +59,7 @@ import {
|
|
|
61
59
|
} from "./chunk-ISTWNY6N.js";
|
|
62
60
|
import {
|
|
63
61
|
EidError
|
|
64
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-PWFTN52X.js";
|
|
65
63
|
|
|
66
64
|
// src/pades/limits.ts
|
|
67
65
|
var MAX_INPUT_BYTES = (10 << 20) - (256 << 10);
|
|
@@ -1110,7 +1108,7 @@ async function prepareSignature(base, signingTime, signerName, reason, vis) {
|
|
|
1110
1108
|
const sigID = inc.reserve();
|
|
1111
1109
|
const fieldID = inc.reserve();
|
|
1112
1110
|
const catID = inc.reserve();
|
|
1113
|
-
const apIDs = vis ? Array.from({ length:
|
|
1111
|
+
const apIDs = vis ? Array.from({ length: 11 }, () => inc.reserve()) : [];
|
|
1114
1112
|
let sig = `<<
|
|
1115
1113
|
/Type /Sig
|
|
1116
1114
|
/Filter /Adobe.PPKLite
|
|
@@ -1152,10 +1150,7 @@ async function prepareSignature(base, signingTime, signerName, reason, vis) {
|
|
|
1152
1150
|
placement = placeOnPage(page, box, rot, vis.x, vis.y, vis.w, vis.h, vis.exact === true);
|
|
1153
1151
|
if (placement.x !== vis.x || placement.y !== vis.y) rect = visibleRect(box, rot, placement.x, placement.y, vis.w, vis.h);
|
|
1154
1152
|
}
|
|
1155
|
-
const bodies = appearanceObjects(
|
|
1156
|
-
{ w: vis.w, h: vis.h, rotate: rot, name: vis.name, role: vis.role, lang: vis.lang, date: vis.date, url: vis.url, sig: vis.sig, stamp: vis.stamp },
|
|
1157
|
-
apIDs
|
|
1158
|
-
);
|
|
1153
|
+
const bodies = appearanceObjects({ w: vis.w, h: vis.h, rotate: rot, name: vis.name, role: vis.role, lang: vis.lang, date: vis.date, url: vis.url }, apIDs);
|
|
1159
1154
|
inc.writeObject(fieldID, visibleWidget(fieldName, rect, page.ptr.id, page.ptr.gen, sigID, apIDs[0]));
|
|
1160
1155
|
bodies.forEach((b2, i) => inc.writeObject(apIDs[i], b2));
|
|
1161
1156
|
}
|
|
@@ -1500,7 +1495,6 @@ function encodeState(s) {
|
|
|
1500
1495
|
};
|
|
1501
1496
|
if (s.pageSha256) head.pageSha256 = s.pageSha256;
|
|
1502
1497
|
if (s.claimedRole) head.claimedRole = s.claimedRole;
|
|
1503
|
-
if (s.images?.length) head.images = s.images.map((x) => ({ kind: x.kind, sha256: x.sha256 }));
|
|
1504
1498
|
head.preparedSha256 = s.preparedSha256;
|
|
1505
1499
|
const h = enc.encode(JSON.stringify(head));
|
|
1506
1500
|
const len = new Uint8Array(4);
|
|
@@ -1526,7 +1520,6 @@ async function decodeState(b) {
|
|
|
1526
1520
|
hasPage: j.hasPage === true,
|
|
1527
1521
|
pageSha256: str("pageSha256"),
|
|
1528
1522
|
claimedRole: str("claimedRole"),
|
|
1529
|
-
images: stateImages(j.images),
|
|
1530
1523
|
preparedSha256: str("preparedSha256"),
|
|
1531
1524
|
pdf
|
|
1532
1525
|
};
|
|
@@ -1536,16 +1529,6 @@ async function decodeState(b) {
|
|
|
1536
1529
|
}
|
|
1537
1530
|
return s;
|
|
1538
1531
|
}
|
|
1539
|
-
function stateImages(v) {
|
|
1540
|
-
if (v === void 0 || v === null) return void 0;
|
|
1541
|
-
if (!Array.isArray(v)) throw new Error("state images \u0431\u0443\u0440\u0443\u0443");
|
|
1542
|
-
const out = v.map((x) => {
|
|
1543
|
-
const o = x;
|
|
1544
|
-
if (!o || o.kind !== "signature" && o.kind !== "stamp" || typeof o.sha256 !== "string") throw new Error("state images \u0431\u0443\u0440\u0443\u0443");
|
|
1545
|
-
return { kind: o.kind, sha256: o.sha256 };
|
|
1546
|
-
});
|
|
1547
|
-
return out.length ? out : void 0;
|
|
1548
|
-
}
|
|
1549
1532
|
|
|
1550
1533
|
// src/pades.ts
|
|
1551
1534
|
var PROFILE_VERSION = "pades-client/1";
|
|
@@ -1580,21 +1563,6 @@ var PadesError = class extends EidError {
|
|
|
1580
1563
|
return this.code === "TSA_UNAVAILABLE" || this.code === "LTV_UNAVAILABLE";
|
|
1581
1564
|
}
|
|
1582
1565
|
};
|
|
1583
|
-
var DEFAULT_STAMP_SIZE = { width: 220, height: 64 };
|
|
1584
|
-
var DEFAULT_SIGNATURE_STAMP_SIZE = { width: 220, height: 110 };
|
|
1585
|
-
var DEFAULT_ORG_STAMP_SIZE = { width: 240, height: 147.5 };
|
|
1586
|
-
function appearanceSize(a) {
|
|
1587
|
-
if (a.width !== 0 || a.height !== 0) return { width: a.width, height: a.height };
|
|
1588
|
-
if (a.stampImage) return DEFAULT_ORG_STAMP_SIZE;
|
|
1589
|
-
if (a.signatureImage) return DEFAULT_SIGNATURE_STAMP_SIZE;
|
|
1590
|
-
return DEFAULT_STAMP_SIZE;
|
|
1591
|
-
}
|
|
1592
|
-
var SHA256_HEX_RE = /^[0-9a-f]{64}$/;
|
|
1593
|
-
var BASE64_STD_RE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
1594
|
-
function imageData(im) {
|
|
1595
|
-
if (im === void 0) return void 0;
|
|
1596
|
-
return { w: im.width, h: im.height, color: im.color, alpha: fromB64(im.alpha) };
|
|
1597
|
-
}
|
|
1598
1566
|
var MAX_OUTPUT_BYTES = 10 << 20;
|
|
1599
1567
|
var MAX_FILE_NAME = 120;
|
|
1600
1568
|
var PAGE_BRAND = "eID Mongolia";
|
|
@@ -1694,9 +1662,6 @@ async function prepare(pdf, opts) {
|
|
|
1694
1662
|
}
|
|
1695
1663
|
const first = pos === "first";
|
|
1696
1664
|
checkAppearance(opts);
|
|
1697
|
-
if (opts.appearance?.stampImage && !opts.claimedRole) {
|
|
1698
|
-
throw new PadesError("REQUEST_INVALID", "appearance: stampImage \u0437\u04E9\u0432\u0445\u04E9\u043D claimedRole (onBehalfOf)-\u0442\u043E\u0439");
|
|
1699
|
-
}
|
|
1700
1665
|
const now = opts.signingTime ?? /* @__PURE__ */ new Date();
|
|
1701
1666
|
if (Number.isNaN(now.getTime())) throw new PadesError("REQUEST_INVALID", "signingTime \u0431\u0443\u0440\u0443\u0443 Date");
|
|
1702
1667
|
const inHex = toHex(await sha256(doc));
|
|
@@ -1770,7 +1735,6 @@ async function prepare(pdf, opts) {
|
|
|
1770
1735
|
hasPage,
|
|
1771
1736
|
pageSha256: pageHex,
|
|
1772
1737
|
claimedRole: role,
|
|
1773
|
-
images: prepImages(opts.appearance),
|
|
1774
1738
|
preparedSha256: toHex(await sha256(prep.pdf)),
|
|
1775
1739
|
pdf: prep.pdf
|
|
1776
1740
|
});
|
|
@@ -1794,24 +1758,6 @@ function checkAppearance(o) {
|
|
|
1794
1758
|
if (a.exact !== void 0 && typeof a.exact !== "boolean") throw bad("exact: boolean");
|
|
1795
1759
|
const role = o.claimedRole ?? "";
|
|
1796
1760
|
if (role !== "" && /[\p{Cc}\p{Cf}\p{Cs}]/u.test(role)) throw bad("claimedRole-\u0434 \u0443\u0434\u0438\u0440\u0434\u0430\u0445 \u0442\u044D\u043C\u0434\u044D\u0433\u0442");
|
|
1797
|
-
for (const [name, im] of [["signatureImage", a.signatureImage], ["stampImage", a.stampImage]]) {
|
|
1798
|
-
if (im === void 0) continue;
|
|
1799
|
-
if (im === null || typeof im !== "object") throw bad(`${name}: \u043E\u0431\u044A\u0435\u043A\u0442`);
|
|
1800
|
-
if (typeof im.sha256 !== "string" || !SHA256_HEX_RE.test(im.sha256)) throw bad(`${name}.sha256: \u0436\u0438\u0436\u0438\u0433 hex SHA-256`);
|
|
1801
|
-
if (typeof im.alpha !== "string" || !BASE64_STD_RE.test(im.alpha)) throw bad(`${name}.alpha: \u0441\u0442\u0430\u043D\u0434\u0430\u0440\u0442 base64`);
|
|
1802
|
-
try {
|
|
1803
|
-
checkPdfImage(imageData(im));
|
|
1804
|
-
} catch (e) {
|
|
1805
|
-
if (e instanceof AppearanceError) throw bad(`${name}: ${e.message.replace(/^зураг: /, "")}`);
|
|
1806
|
-
throw e;
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
function prepImages(a) {
|
|
1811
|
-
const out = [];
|
|
1812
|
-
if (a?.signatureImage) out.push({ kind: "signature", sha256: a.signatureImage.sha256 });
|
|
1813
|
-
if (a?.stampImage) out.push({ kind: "stamp", sha256: a.stampImage.sha256 });
|
|
1814
|
-
return out.length ? out : void 0;
|
|
1815
1761
|
}
|
|
1816
1762
|
function visibleSpec(doc, o, name, now, docId, revIndex) {
|
|
1817
1763
|
const a = o.appearance;
|
|
@@ -1826,15 +1772,12 @@ function visibleSpec(doc, o, name, now, docId, revIndex) {
|
|
|
1826
1772
|
if (page > n) throw new PadesError("REQUEST_INVALID", `appearance: page ${page} > \u0445\u0443\u0443\u0434\u0430\u0441\u043D\u044B \u0442\u043E\u043E ${n}`);
|
|
1827
1773
|
const z = new Date(now.getTime() + 8 * 36e5);
|
|
1828
1774
|
const p2 = (v) => String(v).padStart(2, "0");
|
|
1829
|
-
const size = appearanceSize(a);
|
|
1830
1775
|
return {
|
|
1831
1776
|
page,
|
|
1832
1777
|
x: round100(a.x),
|
|
1833
1778
|
y: round100(a.y),
|
|
1834
|
-
w: round100(
|
|
1835
|
-
h: round100(
|
|
1836
|
-
sig: imageData(a.signatureImage),
|
|
1837
|
-
stamp: imageData(a.stampImage),
|
|
1779
|
+
w: round100(a.width),
|
|
1780
|
+
h: round100(a.height),
|
|
1838
1781
|
name: goTrim(name),
|
|
1839
1782
|
role: o.claimedRole ?? "",
|
|
1840
1783
|
lang: a.lang || o.lang || "mn",
|
|
@@ -1867,9 +1810,8 @@ async function suggestPlacement(pdf, appearance) {
|
|
|
1867
1810
|
const id = docIdFromPage(doc);
|
|
1868
1811
|
if (id !== "") verifyUri = VERIFY_URL_PREFIX + id;
|
|
1869
1812
|
}
|
|
1870
|
-
const
|
|
1871
|
-
const
|
|
1872
|
-
const h = round100(size.height);
|
|
1813
|
+
const w = round100(appearance.width);
|
|
1814
|
+
const h = round100(appearance.height);
|
|
1873
1815
|
let s;
|
|
1874
1816
|
try {
|
|
1875
1817
|
s = suggestVisible(doc, verifyUri, appearance.page ?? 0, round100(appearance.x), round100(appearance.y), w, h, appearance.exact === true);
|
|
@@ -2030,15 +1972,11 @@ async function complete(state, signature, opts = {}) {
|
|
|
2030
1972
|
priorCmsSha256: prior,
|
|
2031
1973
|
priorRevisionSha256: priorRev,
|
|
2032
1974
|
signerCert: cert.raw,
|
|
2033
|
-
claimedRole: st.claimedRole
|
|
2034
|
-
...st.images?.length ? { images: st.images.map((x) => ({ ...x })) } : {}
|
|
1975
|
+
claimedRole: st.claimedRole
|
|
2035
1976
|
};
|
|
2036
1977
|
}
|
|
2037
1978
|
export {
|
|
2038
1979
|
CertificateRevokedError,
|
|
2039
|
-
DEFAULT_ORG_STAMP_SIZE,
|
|
2040
|
-
DEFAULT_SIGNATURE_STAMP_SIZE,
|
|
2041
|
-
DEFAULT_STAMP_SIZE,
|
|
2042
1980
|
PADES_ERROR_CODES,
|
|
2043
1981
|
PROFILE_VERSION,
|
|
2044
1982
|
PadesError,
|
package/dist/validate.cjs
CHANGED
|
@@ -1749,27 +1749,6 @@ function zlibInflate(src, limit = 64 << 20, initial) {
|
|
|
1749
1749
|
function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
1750
1750
|
return inflate(src, limit, info, initial, false);
|
|
1751
1751
|
}
|
|
1752
|
-
function zlibInflateStrict(src, limit, exact = false) {
|
|
1753
|
-
if (src.length < 2) throw new InflateError("zlib: header \u0430\u043B\u0433\u0430");
|
|
1754
|
-
const cmf = src[0];
|
|
1755
|
-
const flg = src[1];
|
|
1756
|
-
if ((cmf & 15) !== 8 || cmf >> 4 > 7 || (cmf << 8 | flg) % 31 !== 0) throw new InflateError("zlib: header \u0431\u0443\u0440\u0443\u0443");
|
|
1757
|
-
let start = 2;
|
|
1758
|
-
if (flg & 32) {
|
|
1759
|
-
if (src.length < 6) throw new InflateError("zlib: DICTID \u0434\u0443\u0442\u0443\u0443");
|
|
1760
|
-
if (src[2] !== 0 || src[3] !== 0 || src[4] !== 0 || src[5] !== 1) throw new InflateError("zlib: preset dictionary");
|
|
1761
|
-
start = 6;
|
|
1762
|
-
}
|
|
1763
|
-
const info = { end: 0, truncated: false };
|
|
1764
|
-
const out = inflate(src.subarray(start), limit, info, void 0, true);
|
|
1765
|
-
if (info.truncated) throw new InflateError("inflate: \u04E9\u0433\u04E9\u0433\u0434\u04E9\u043B \u0434\u0443\u0442\u0443\u0443");
|
|
1766
|
-
const at = start + info.end;
|
|
1767
|
-
if (at + 4 > src.length) throw new InflateError("zlib: adler32 \u0430\u043B\u0433\u0430");
|
|
1768
|
-
const want = (src[at] << 24 | src[at + 1] << 16 | src[at + 2] << 8 | src[at + 3]) >>> 0;
|
|
1769
|
-
if (adler32(out) !== want) throw new InflateError("zlib: adler32 \u0442\u0430\u0430\u0440\u0430\u0445\u0433\u04AF\u0439");
|
|
1770
|
-
if (exact && at + 4 !== src.length) throw new InflateError("zlib: stream-\u0438\u0439\u043D \u0430\u0440\u0434 \u0438\u043B\u04AF\u04AF \u0431\u0430\u0439\u0442");
|
|
1771
|
-
return out;
|
|
1772
|
-
}
|
|
1773
1752
|
function adler32(b) {
|
|
1774
1753
|
let a = 1;
|
|
1775
1754
|
let s = 0;
|
|
@@ -3308,61 +3287,6 @@ function toUnicode(f) {
|
|
|
3308
3287
|
// src/pades/page/appearance.ts
|
|
3309
3288
|
var AppearanceError = class extends PdfError {
|
|
3310
3289
|
};
|
|
3311
|
-
var MAX_IMAGE_SIDE = 1600;
|
|
3312
|
-
var MAX_IMAGE_ALPHA_BYTES = 300 << 10;
|
|
3313
|
-
var isIntIn = (v, lo, hi) => Number.isInteger(v) && v >= lo && v <= hi;
|
|
3314
|
-
function checkPdfImage(im) {
|
|
3315
|
-
const bad = (msg) => new AppearanceError(`\u0437\u0443\u0440\u0430\u0433: ${msg}`);
|
|
3316
|
-
if (!isIntIn(im.w, 1, MAX_IMAGE_SIDE) || !isIntIn(im.h, 1, MAX_IMAGE_SIDE)) throw bad("\u0445\u044D\u043C\u0436\u044D\u044D 1\u20261600 px");
|
|
3317
|
-
if (!Array.isArray(im.color) || im.color.length !== 3) throw bad("\u04E9\u043D\u0433\u04E9 0\u2026255");
|
|
3318
|
-
for (const c of im.color) if (!isIntIn(c, 0, 255)) throw bad("\u04E9\u043D\u0433\u04E9 0\u2026255");
|
|
3319
|
-
if (!(im.alpha instanceof Uint8Array) || im.alpha.length === 0 || im.alpha.length > MAX_IMAGE_ALPHA_BYTES) throw bad("alpha 1 B\u2026300 KiB");
|
|
3320
|
-
if (im.alpha.length >= 2 && im.alpha[1] & 32) throw bad("alpha preset dictionary (FDICT)");
|
|
3321
|
-
let n;
|
|
3322
|
-
try {
|
|
3323
|
-
n = zlibInflateStrict(im.alpha, im.w * im.h, true).length;
|
|
3324
|
-
} catch (e) {
|
|
3325
|
-
if (!(e instanceof InflateError)) throw e;
|
|
3326
|
-
n = -1;
|
|
3327
|
-
}
|
|
3328
|
-
if (n !== im.w * im.h) throw bad("alpha \u043D\u044C \u044F\u0433 \u04E9\u0440\u0433\u04E9\u043D\xD7\u04E9\u043D\u0434\u04E9\u0440 \u0431\u0430\u0439\u0442 \u0431\u0438\u0448 (\u044D\u0441\u0432\u044D\u043B \u044D\u0432\u0434\u044D\u0440\u0441\u044D\u043D)");
|
|
3329
|
-
}
|
|
3330
|
-
var idiv = (a, b) => Math.trunc(a / b);
|
|
3331
|
-
function apFit(iw, ih, bw, bh) {
|
|
3332
|
-
if (iw * bh >= ih * bw) return [bw, Math.max(1, idiv(bw * ih, iw))];
|
|
3333
|
-
return [Math.max(1, idiv(bh * iw, ih)), bh];
|
|
3334
|
-
}
|
|
3335
|
-
function apLayoutImages(p) {
|
|
3336
|
-
const l = { boxH: p.h, rowH: p.h, sig: [0, 0, 0, 0], stamp: [0, 0, 0, 0] };
|
|
3337
|
-
if (!p.sig && !p.stamp) return l;
|
|
3338
|
-
const small = () => new AppearanceError("\u0445\u044D\u0442 \u0436\u0438\u0436\u0438\u0433 (\u0437\u0443\u0440\u0430\u0433\u0442\u0430\u0439 \u0434\u04AF\u0440\u0441\u043B\u044D\u043B)");
|
|
3339
|
-
if (p.stamp) l.boxH = idiv(p.h * 4, 5);
|
|
3340
|
-
const band = idiv(l.boxH * 9, 22);
|
|
3341
|
-
l.rowH = l.boxH - band;
|
|
3342
|
-
const sh = idiv(band * 14, 15);
|
|
3343
|
-
const sy = l.rowH - idiv(band * 2, 15);
|
|
3344
|
-
let sw = idiv(p.w * 15, 22);
|
|
3345
|
-
let sx = idiv(p.w - sw, 2);
|
|
3346
|
-
if (p.stamp) {
|
|
3347
|
-
const d = idiv(l.boxH * 2, 3);
|
|
3348
|
-
const qx = Math.min(idiv(p.w * 41, 60) - idiv(d, 2), p.w - d);
|
|
3349
|
-
if (qx < 0 || d <= 0) throw small();
|
|
3350
|
-
const [dw, dh] = apFit(p.stamp.w, p.stamp.h, d, d);
|
|
3351
|
-
l.stamp = [qx + idiv(d - dw, 2), p.h - d + idiv(d - dh, 2), dw, dh];
|
|
3352
|
-
sx = idiv(p.w, 30);
|
|
3353
|
-
sw = qx + idiv(d, 2) - sx;
|
|
3354
|
-
}
|
|
3355
|
-
if (p.sig) {
|
|
3356
|
-
if (sw <= 0 || sh <= 0) throw small();
|
|
3357
|
-
const [dw, dh] = apFit(p.sig.w, p.sig.h, sw, sh);
|
|
3358
|
-
const dx = p.stamp ? sx : sx + idiv(sw - dw, 2);
|
|
3359
|
-
l.sig = [dx, sy + idiv(sh - dh, 2), dw, dh];
|
|
3360
|
-
}
|
|
3361
|
-
return l;
|
|
3362
|
-
}
|
|
3363
|
-
function apDrawImage(w, name, r) {
|
|
3364
|
-
w.op(`q ${num100(r[2])} 0 0 ${num100(r[3])} ${num100(r[0])} ${num100(r[1])} cm /${name} Do Q`);
|
|
3365
|
-
}
|
|
3366
3290
|
var AP_PAD = 400;
|
|
3367
3291
|
var AP_GAP = 400;
|
|
3368
3292
|
var AP_MIN_MODULE = 100;
|
|
@@ -3407,10 +3331,6 @@ function appearanceContent(p) {
|
|
|
3407
3331
|
if (label === void 0) throw new AppearanceError(`\u0445\u044D\u043B ${p.lang}`);
|
|
3408
3332
|
if (!asciiURL(p.url)) throw new AppearanceError("URL ASCII \u0431\u0438\u0448");
|
|
3409
3333
|
if (p.w <= 0 || p.h <= 0 || p.w > MAX_APPEARANCE_SIDE || p.h > MAX_APPEARANCE_SIDE) throw new AppearanceError("\u0445\u044D\u043C\u0436\u044D\u044D");
|
|
3410
|
-
if (p.stamp && p.role === "") throw new AppearanceError("\u0442\u0430\u043C\u0433\u044B\u043D \u0437\u0443\u0440\u0430\u0433 \u0437\u04E9\u0432\u0445\u04E9\u043D \u0431\u0430\u0439\u0433\u0443\u0443\u043B\u043B\u0430\u0433\u044B\u043D \u043D\u044D\u0440\u0438\u0439\u043D \u04E9\u043C\u043D\u04E9\u04E9\u0441 (claimedRole)");
|
|
3411
|
-
for (const im of [p.sig, p.stamp]) if (im) checkPdfImage(im);
|
|
3412
|
-
const il = apLayoutImages(p);
|
|
3413
|
-
const rowH = il.rowH;
|
|
3414
3334
|
let m;
|
|
3415
3335
|
try {
|
|
3416
3336
|
m = qrEncode(latin1(p.url));
|
|
@@ -3418,14 +3338,14 @@ function appearanceContent(p) {
|
|
|
3418
3338
|
throw new AppearanceError(String(e));
|
|
3419
3339
|
}
|
|
3420
3340
|
const n = m.length;
|
|
3421
|
-
const mod = Math.trunc((
|
|
3341
|
+
const mod = Math.trunc((p.h - 2 * AP_PAD) / n);
|
|
3422
3342
|
if (mod < AP_MIN_MODULE) throw new AppearanceError(`\u0445\u044D\u0442 \u0436\u0438\u0436\u0438\u0433 (\u04E9\u043D\u0434\u04E9\u0440 \u2265 ${num100(2 * AP_PAD + n * AP_MIN_MODULE)} pt)`);
|
|
3423
3343
|
const tx = AP_PAD + mod * n + AP_GAP;
|
|
3424
3344
|
const tw = p.w - tx - AP_PAD;
|
|
3425
3345
|
const [reg, bld] = loadFonts();
|
|
3426
3346
|
const w = new PageWriter(reg, bld);
|
|
3427
3347
|
let lines;
|
|
3428
|
-
for (let f = AP_MAX_SIZE; f >= AP_MIN_SIZE && lines === void 0 && tw > 0; f--) lines = apLayout(w, p, label, f, tw
|
|
3348
|
+
for (let f = AP_MAX_SIZE; f >= AP_MIN_SIZE && lines === void 0 && tw > 0; f--) lines = apLayout(w, p, label, f, tw);
|
|
3429
3349
|
if (lines === void 0) throw new AppearanceError("\u0445\u044D\u0442 \u0436\u0438\u0436\u0438\u0433 (\u0431\u0438\u0447\u0432\u044D\u0440 \u0431\u0430\u0433\u0442\u0430\u0445\u0433\u04AF\u0439)");
|
|
3430
3350
|
let total = 0;
|
|
3431
3351
|
for (const l of lines) total += l.size * AP_LEADING;
|
|
@@ -3437,13 +3357,8 @@ function appearanceContent(p) {
|
|
|
3437
3357
|
}
|
|
3438
3358
|
w.op(`${C_OK} RG`);
|
|
3439
3359
|
w.op("1 w");
|
|
3440
|
-
w.op(`0.5 0.5 ${num100(p.w - 100)} ${num100(
|
|
3441
|
-
|
|
3442
|
-
w.op("0.5 w");
|
|
3443
|
-
w.op(`0 ${num100(rowH)} m ${num100(p.w)} ${num100(rowH)} l S`);
|
|
3444
|
-
}
|
|
3445
|
-
if (p.sig) apDrawImage(w, "Sig", il.sig);
|
|
3446
|
-
w.op(`q ${num100(mod)} 0 0 ${num100(mod)} ${num100(AP_PAD)} ${num100(Math.trunc((rowH - mod * n) / 2))} cm`);
|
|
3360
|
+
w.op(`0.5 0.5 ${num100(p.w - 100)} ${num100(p.h - 100)} re S`);
|
|
3361
|
+
w.op(`q ${num100(mod)} 0 0 ${num100(mod)} ${num100(AP_PAD)} ${num100(Math.trunc((p.h - mod * n) / 2))} cm`);
|
|
3447
3362
|
w.op("0 0 0 rg");
|
|
3448
3363
|
for (let r = 0; r < n; r++) {
|
|
3449
3364
|
for (let c = 0; c < n; ) {
|
|
@@ -3458,18 +3373,17 @@ function appearanceContent(p) {
|
|
|
3458
3373
|
}
|
|
3459
3374
|
w.op("f");
|
|
3460
3375
|
w.op("Q");
|
|
3461
|
-
let cursor =
|
|
3376
|
+
let cursor = p.h - AP_PAD - Math.trunc((p.h - 2 * AP_PAD - total) / 2);
|
|
3462
3377
|
for (const l of lines) {
|
|
3463
3378
|
cursor -= l.size * AP_LEADING;
|
|
3464
3379
|
w.op(`${l.color} rg`);
|
|
3465
3380
|
w.op(`BT /F${l.font} ${l.size} Tf ${num100(tx)} ${num100(cursor + l.size * AP_DESCENT)} Td ${w.glyphHex(l.font, l.text)} Tj ET`);
|
|
3466
3381
|
}
|
|
3467
|
-
if (p.stamp) apDrawImage(w, "Stamp", il.stamp);
|
|
3468
3382
|
if (cm !== "") w.op("Q");
|
|
3469
3383
|
w.op("EMC");
|
|
3470
3384
|
return w.ops;
|
|
3471
3385
|
}
|
|
3472
|
-
function apLayout(w, p, label, f, tw
|
|
3386
|
+
function apLayout(w, p, label, f, tw) {
|
|
3473
3387
|
const b = f - AP_BODY_DELTA;
|
|
3474
3388
|
const limit = tw * 10;
|
|
3475
3389
|
const lines = [];
|
|
@@ -3483,40 +3397,20 @@ function apLayout(w, p, label, f, tw, rowH) {
|
|
|
3483
3397
|
if (l.text === "" || w.width1000(l.font, l.size, l.text) > limit) return void 0;
|
|
3484
3398
|
total += l.size * AP_LEADING;
|
|
3485
3399
|
}
|
|
3486
|
-
if (total >
|
|
3400
|
+
if (total > p.h - 2 * AP_PAD) return void 0;
|
|
3487
3401
|
return lines;
|
|
3488
3402
|
}
|
|
3489
|
-
function appearanceObjectCount(p) {
|
|
3490
|
-
return 11 + (p.sig ? 2 : 0) + (p.stamp ? 2 : 0);
|
|
3491
|
-
}
|
|
3492
3403
|
function appearanceObjects(p, ids) {
|
|
3493
|
-
if (ids.length !== appearanceObjectCount(p)) throw new AppearanceError("\u043E\u0431\u044A\u0435\u043A\u0442\u044B\u043D \u0442\u043E\u043E");
|
|
3494
3404
|
const [reg, bld] = loadFonts();
|
|
3495
3405
|
const { bw, bh } = apRotation(p.rotate, p.w, p.h);
|
|
3496
3406
|
const content = appearanceContent(p);
|
|
3497
|
-
let res = `/Font << /F1 ${ids[1]} 0 R /F2 ${ids[6]} 0 R >>`;
|
|
3498
|
-
const imgs = [];
|
|
3499
|
-
let next = 11;
|
|
3500
|
-
if (p.sig || p.stamp) {
|
|
3501
|
-
res += " /XObject <<";
|
|
3502
|
-
for (const [name, im] of [["Sig", p.sig], ["Stamp", p.stamp]]) {
|
|
3503
|
-
if (!im) continue;
|
|
3504
|
-
const base = ids[next];
|
|
3505
|
-
const mask = ids[next + 1];
|
|
3506
|
-
next += 2;
|
|
3507
|
-
res += ` /${name} ${base} 0 R`;
|
|
3508
|
-
imgs.push(
|
|
3509
|
-
streamObj(` /Type /XObject /Subtype /Image /Width 1 /Height 1 /ColorSpace /DeviceRGB /BitsPerComponent 8 /SMask ${mask} 0 R`, Uint8Array.from(im.color)),
|
|
3510
|
-
streamObj(` /Type /XObject /Subtype /Image /Width ${im.w} /Height ${im.h} /ColorSpace /DeviceGray /BitsPerComponent 8 /Filter /FlateDecode`, im.alpha)
|
|
3511
|
-
);
|
|
3512
|
-
}
|
|
3513
|
-
res += " >>";
|
|
3514
|
-
}
|
|
3515
3407
|
return [
|
|
3516
|
-
streamObj(
|
|
3408
|
+
streamObj(
|
|
3409
|
+
` /Type /XObject /Subtype /Form /BBox [0 0 ${num100(bw)} ${num100(bh)}] /Resources << /Font << /F1 ${ids[1]} 0 R /F2 ${ids[6]} 0 R >> >>`,
|
|
3410
|
+
latin1(content)
|
|
3411
|
+
),
|
|
3517
3412
|
...fontBodies(ids.slice(1, 6), reg),
|
|
3518
|
-
...fontBodies(ids.slice(6, 11), bld)
|
|
3519
|
-
...imgs
|
|
3413
|
+
...fontBodies(ids.slice(6, 11), bld)
|
|
3520
3414
|
];
|
|
3521
3415
|
}
|
|
3522
3416
|
function visibleWidget(fieldName, rect, pageID, pageGen, sigID, formID) {
|
|
@@ -4339,7 +4233,7 @@ function ownVisible(c, d, widget) {
|
|
|
4339
4233
|
const m = ms.v;
|
|
4340
4234
|
if (!ownDate(m) || m.slice(16) !== "+08'00'") throw fail();
|
|
4341
4235
|
const date = `${m.slice(2, 6)}-${m.slice(6, 8)}-${m.slice(8, 10)} ${m.slice(10, 12)}:${m.slice(12, 14)} (+08)`;
|
|
4342
|
-
const
|
|
4236
|
+
const ids = apIDs(c, nr);
|
|
4343
4237
|
const form = c.fin.get(ids[0]);
|
|
4344
4238
|
if (!(form instanceof PStream2)) throw fail();
|
|
4345
4239
|
let head = "";
|
|
@@ -4351,7 +4245,7 @@ function ownVisible(c, d, widget) {
|
|
|
4351
4245
|
for (const lang of ["mn", "en"]) {
|
|
4352
4246
|
let bodies;
|
|
4353
4247
|
try {
|
|
4354
|
-
bodies = appearanceObjects({ w, h, rotate: rot, name, role: meta.role, lang, date, url
|
|
4248
|
+
bodies = appearanceObjects({ w, h, rotate: rot, name, role: meta.role, lang, date, url }, ids);
|
|
4355
4249
|
} catch {
|
|
4356
4250
|
throw fail();
|
|
4357
4251
|
}
|
|
@@ -4399,21 +4293,6 @@ function apIDs(c, n) {
|
|
|
4399
4293
|
if (!(ff instanceof PRef2)) throw fail();
|
|
4400
4294
|
refs.push(t0, cid, fd, ff, tu);
|
|
4401
4295
|
}
|
|
4402
|
-
let sig;
|
|
4403
|
-
let stamp;
|
|
4404
|
-
if (isDict(res) && res.has("XObject")) {
|
|
4405
|
-
const xo = dget(res, "XObject");
|
|
4406
|
-
if (!isDict(xo)) throw fail();
|
|
4407
|
-
for (const key of ["Sig", "Stamp"]) {
|
|
4408
|
-
if (!xo.has(key)) continue;
|
|
4409
|
-
const br = dget(xo, key);
|
|
4410
|
-
if (!(br instanceof PRef2)) throw fail();
|
|
4411
|
-
const { im, mr } = apImage(c, br);
|
|
4412
|
-
refs.push(br, mr);
|
|
4413
|
-
if (key === "Sig") sig = im;
|
|
4414
|
-
else stamp = im;
|
|
4415
|
-
}
|
|
4416
|
-
}
|
|
4417
4296
|
const seen = /* @__PURE__ */ new Set();
|
|
4418
4297
|
const ids = [];
|
|
4419
4298
|
for (const r of refs) {
|
|
@@ -4421,21 +4300,7 @@ function apIDs(c, n) {
|
|
|
4421
4300
|
seen.add(r.num);
|
|
4422
4301
|
ids.push(r.num);
|
|
4423
4302
|
}
|
|
4424
|
-
return
|
|
4425
|
-
}
|
|
4426
|
-
function apImage(c, br) {
|
|
4427
|
-
const fail = errNotSignatureOnly;
|
|
4428
|
-
const base = c.fin.deref(br);
|
|
4429
|
-
if (!(base instanceof PStream2) || base.data.length !== 3) throw fail();
|
|
4430
|
-
const mr = dget(base.dict, "SMask");
|
|
4431
|
-
if (!(mr instanceof PRef2)) throw fail();
|
|
4432
|
-
const mask = c.fin.deref(mr);
|
|
4433
|
-
if (!(mask instanceof PStream2)) throw fail();
|
|
4434
|
-
const w = dget(mask.dict, "Width");
|
|
4435
|
-
const h = dget(mask.dict, "Height");
|
|
4436
|
-
const side = BigInt(MAX_IMAGE_SIDE);
|
|
4437
|
-
if (!isInt2(w) || !isInt2(h) || w < 1n || h < 1n || w > side || h > side) throw fail();
|
|
4438
|
-
return { im: { w: Number(w), h: Number(h), color: [base.data[0], base.data[1], base.data[2]], alpha: mask.data }, mr };
|
|
4303
|
+
return ids;
|
|
4439
4304
|
}
|
|
4440
4305
|
var isSpaceByte = (x) => x === 9 || x === 10 || x === 11 || x === 12 || x === 13 || x === 32;
|
|
4441
4306
|
function sameObject(c, num, body) {
|
package/dist/validate.d.cts
CHANGED
package/dist/validate.d.ts
CHANGED
package/dist/validate.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Fetcher,
|
|
3
3
|
InflateError,
|
|
4
|
-
MAX_IMAGE_SIDE,
|
|
5
4
|
PRef,
|
|
6
5
|
Reader,
|
|
7
6
|
StructureError,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
isBrowser,
|
|
13
12
|
round100,
|
|
14
13
|
visibleWidget
|
|
15
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MA4RMWBO.js";
|
|
16
15
|
import {
|
|
17
16
|
EID_ISSUERS,
|
|
18
17
|
INTERMEDIATES,
|
|
@@ -66,7 +65,7 @@ import {
|
|
|
66
65
|
} from "./chunk-ISTWNY6N.js";
|
|
67
66
|
import {
|
|
68
67
|
EidError
|
|
69
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-PWFTN52X.js";
|
|
70
69
|
|
|
71
70
|
// src/pades/validate/evaluate.ts
|
|
72
71
|
var PROBLEMS = {
|
|
@@ -1409,7 +1408,7 @@ function ownVisible(c, d, widget) {
|
|
|
1409
1408
|
const m = ms.v;
|
|
1410
1409
|
if (!ownDate(m) || m.slice(16) !== "+08'00'") throw fail();
|
|
1411
1410
|
const date = `${m.slice(2, 6)}-${m.slice(6, 8)}-${m.slice(8, 10)} ${m.slice(10, 12)}:${m.slice(12, 14)} (+08)`;
|
|
1412
|
-
const
|
|
1411
|
+
const ids = apIDs(c, nr);
|
|
1413
1412
|
const form = c.fin.get(ids[0]);
|
|
1414
1413
|
if (!(form instanceof PStream)) throw fail();
|
|
1415
1414
|
let head = "";
|
|
@@ -1421,7 +1420,7 @@ function ownVisible(c, d, widget) {
|
|
|
1421
1420
|
for (const lang of ["mn", "en"]) {
|
|
1422
1421
|
let bodies;
|
|
1423
1422
|
try {
|
|
1424
|
-
bodies = appearanceObjects({ w, h, rotate: rot, name, role: meta.role, lang, date, url
|
|
1423
|
+
bodies = appearanceObjects({ w, h, rotate: rot, name, role: meta.role, lang, date, url }, ids);
|
|
1425
1424
|
} catch {
|
|
1426
1425
|
throw fail();
|
|
1427
1426
|
}
|
|
@@ -1469,21 +1468,6 @@ function apIDs(c, n) {
|
|
|
1469
1468
|
if (!(ff instanceof PRef2)) throw fail();
|
|
1470
1469
|
refs.push(t0, cid, fd, ff, tu);
|
|
1471
1470
|
}
|
|
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
|
-
}
|
|
1487
1471
|
const seen = /* @__PURE__ */ new Set();
|
|
1488
1472
|
const ids = [];
|
|
1489
1473
|
for (const r of refs) {
|
|
@@ -1491,21 +1475,7 @@ function apIDs(c, n) {
|
|
|
1491
1475
|
seen.add(r.num);
|
|
1492
1476
|
ids.push(r.num);
|
|
1493
1477
|
}
|
|
1494
|
-
return
|
|
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 };
|
|
1478
|
+
return ids;
|
|
1509
1479
|
}
|
|
1510
1480
|
var isSpaceByte = (x) => x === 9 || x === 10 || x === 11 || x === 12 || x === 13 || x === 32;
|
|
1511
1481
|
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.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "e-ID Mongolia Relying Party SDK — иргэнээр утсаар нь нэвтрэлт ба хууль ёсны цахим гарын үсэг (RP-API v3, Smart-ID нийцтэй).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|