@gerege-systems/eid-mongolia-sdk 0.24.0 → 0.26.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 +14 -4
- package/dist/{chunk-T3QLOY6J.js → chunk-YRL4CWWI.js} +91 -6
- package/dist/convert.js +23 -0
- package/dist/pades.cjs +1024 -16
- package/dist/pades.d.cts +31 -2
- package/dist/pades.d.ts +31 -2
- package/dist/pades.js +940 -12
- package/dist/validate.cjs +37 -14
- package/dist/validate.js +2 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -552,7 +552,7 @@ DSS-д), Adobe / EU DSS-д «LTV enabled», баталгаажуулах (QR) х
|
|
|
552
552
|
|
|
553
553
|
| Функц | Хаана | Тайлбар |
|
|
554
554
|
|---|---|---|
|
|
555
|
-
| `prepare(pdf, { signerCert, claimedRole?, verifyPage?, fileName?, lang?, docId?, appearance?, … })` | браузер / Node | `{ dtbs, digest, docId, state }` — сүлжээгүй |
|
|
555
|
+
| `prepare(pdf, { signerCert, claimedRole?, verifyPage?, fileName?, lang?, docId?, appearance?, … })` | браузер / Node | `{ dtbs, digest, docId, state, placement? }` — сүлжээгүй |
|
|
556
556
|
| `eid.signPdfDigest({ dtbs, fileName, signer, flow?, onBehalfOf? })` | RP backend | DTBS-д гарын үсгийн session (push эсвэл device-link) |
|
|
557
557
|
| `complete(state, signature)` | браузер / Node | TSA + OCSP/CRL → `{ pdf, cms, docId, outSha256, inSha256, hasPage, pageSha256, … }` |
|
|
558
558
|
| `eid.registerSignature(registrationFromCompleted(done, { fileName, sessionID }))` | RP backend | `POST /pdf/signatures` — `/verify/{docID}` бүртгэл |
|
|
@@ -624,13 +624,23 @@ reply({ verifyUrl: reg.verifyUrl });
|
|
|
624
624
|
**Харагдах гарын үсэг (сонголттой).** `appearance: { page?, x, y, width, height, lang? }` өгвөл гарын үсэг хуудсан дээр
|
|
625
625
|
харагдана (QR + нэр, `claimedRole`, «eID Mongolia-аар зурсан», огноо `YYYY-MM-DD HH:MM (+08)`); байхгүй бол үл харагдах
|
|
626
626
|
(өмнөхтэй байт-ижил). Координат pt-ээр, хуудасны CropBox-ийн `/Rotate`-ийн дараах (дэлгэцэнд харагдах) зүүн доод булангаас;
|
|
627
|
-
`page` 1-ээс (
|
|
627
|
+
`page` 1-ээс (байхгүй/0 = оролтын eID verify хуудас БИШ сүүлийн хуудас — энэ prepare-ийн нэмэх ба өмнөх гарын үсгүүдийн
|
|
628
|
+
нэмсэн verify хуудас тооцогдохгүй (0.26.0+); тодорхой дугаар нь verify хуудас байсан ч хэвээр). Өндөр ≥ 45 pt; хуудаснаас гарах, бичвэр
|
|
628
629
|
багтахгүй, docId-гүй (хуудасгүй гарын үсэгтэй баримт) бол `REQUEST_INVALID`. Харагдах бүр ~+90 KB. Дүрэм: Go репогийн
|
|
629
630
|
`pades/APPEARANCE_SPEC.md`.
|
|
630
631
|
|
|
632
|
+
`x, y` нь **хүссэн** байрлал: тэр хэсэгт хуудасны агуулга (бичвэр, хүснэгтийн зураас, зураг, өмнөх гарын үсэг) байвал
|
|
633
|
+
дүрслэл чөлөөт зай руу шилжинэ — эхлээд толин тусгал багана (баруун доод → зүүн доод), дараа нь 12 pt-ээр дээш. Хуудсыг
|
|
634
|
+
рендерлэхгүй, content stream-ийг л уншина (Go-той хайрцаг бүрээр ижил). Үр дүн: `p.placement` —
|
|
635
|
+
`{ page, x, y, width, height, status }` (pt), `status`: `requested` (хүссэн газраа) | `moved` (шилжсэн) | `overlap` (чөлөөт
|
|
636
|
+
зай алга — хүссэн газраа, агуулга дээр) | `unscanned` (хуудсыг хязгаарт багтааж уншиж чадсангүй — хүссэн газраа). Гарын
|
|
637
|
+
үсэг аль ч үед хүчинтэй; `overlap` / `unscanned`-ийг хэрэглэгчид мэдэгдэх нь зүйтэй. Дүрэм: Go репогийн
|
|
638
|
+
`pades/PLACEMENT_SPEC.md`.
|
|
639
|
+
|
|
631
640
|
```ts
|
|
632
641
|
const p = await prepare(pdfBytes, { signerCert, verifyPage: true, fileName: "Гэрээ №12.pdf",
|
|
633
642
|
appearance: { page: 1, x: 340, y: 36, width: 220, height: 64 } });
|
|
643
|
+
if (p.placement?.status === "overlap") notice("Гарын үсэг хуудасны агуулга дээр давхцаж байрлана");
|
|
634
644
|
```
|
|
635
645
|
|
|
636
646
|
### Зөвхөн Node (backend бүгдийг хийнэ)
|
|
@@ -1035,8 +1045,8 @@ npm run test:convert-e2e # /convert жинхэнэ LibreOffice Chromium-д (BR
|
|
|
1035
1045
|
|
|
1036
1046
|
`/pades`-ийн conformance fixture (golden: оролт, тестийн PKI-ийн гэрчилгээ, TSA/OCSP/CRL-ийн тогтмол хариу, хүлээгдэх
|
|
1037
1047
|
sha256) ба фонт/гинжийн asset-ийг Go reference-ээс `node scripts/sync-pades-golden.mjs` хуулна (`GO_SDK_COMMIT` —
|
|
1038
|
-
tag `pades-golden-vN`, одоо
|
|
1039
|
-
`PAGE_SPEC.md`, `PRECHECKS.md`, `WIRE.md`, `APPEARANCE_SPEC.md`.
|
|
1048
|
+
tag `pades-golden-vN`, одоо v5 — `placement/` scanner vectors-той); CI `--check`-ээр бэхэлсэн commit-тэй тулгана. Профайл:
|
|
1049
|
+
Go репогийн `pades/PROFILE.md`, `PAGE_SPEC.md`, `PRECHECKS.md`, `WIRE.md`, `APPEARANCE_SPEC.md`, `PLACEMENT_SPEC.md`.
|
|
1040
1050
|
|
|
1041
1051
|
### Гэрээний шалгалт
|
|
1042
1052
|
|
|
@@ -149,6 +149,58 @@ function zlibInflate(src, limit = 64 << 20, initial) {
|
|
|
149
149
|
return inflateRaw(src.subarray(2), limit, void 0, initial);
|
|
150
150
|
}
|
|
151
151
|
function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
152
|
+
return inflate(src, limit, info, initial, false);
|
|
153
|
+
}
|
|
154
|
+
function zlibInflateStrict(src, limit) {
|
|
155
|
+
if (src.length < 2) throw new InflateError("zlib: header \u0430\u043B\u0433\u0430");
|
|
156
|
+
const cmf = src[0];
|
|
157
|
+
const flg = src[1];
|
|
158
|
+
if ((cmf & 15) !== 8 || cmf >> 4 > 7 || (cmf << 8 | flg) % 31 !== 0) throw new InflateError("zlib: header \u0431\u0443\u0440\u0443\u0443");
|
|
159
|
+
let start = 2;
|
|
160
|
+
if (flg & 32) {
|
|
161
|
+
if (src.length < 6) throw new InflateError("zlib: DICTID \u0434\u0443\u0442\u0443\u0443");
|
|
162
|
+
if (src[2] !== 0 || src[3] !== 0 || src[4] !== 0 || src[5] !== 1) throw new InflateError("zlib: preset dictionary");
|
|
163
|
+
start = 6;
|
|
164
|
+
}
|
|
165
|
+
const info = { end: 0, truncated: false };
|
|
166
|
+
const out = inflate(src.subarray(start), limit, info, void 0, true);
|
|
167
|
+
if (info.truncated) throw new InflateError("inflate: \u04E9\u0433\u04E9\u0433\u0434\u04E9\u043B \u0434\u0443\u0442\u0443\u0443");
|
|
168
|
+
const at = start + info.end;
|
|
169
|
+
if (at + 4 > src.length) throw new InflateError("zlib: adler32 \u0430\u043B\u0433\u0430");
|
|
170
|
+
const want = (src[at] << 24 | src[at + 1] << 16 | src[at + 2] << 8 | src[at + 3]) >>> 0;
|
|
171
|
+
if (adler32(out) !== want) throw new InflateError("zlib: adler32 \u0442\u0430\u0430\u0440\u0430\u0445\u0433\u04AF\u0439");
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
function adler32(b) {
|
|
175
|
+
let a = 1;
|
|
176
|
+
let s = 0;
|
|
177
|
+
for (let i = 0; i < b.length; ) {
|
|
178
|
+
const n = Math.min(5552, b.length - i);
|
|
179
|
+
for (let j = 0; j < n; j++, i++) {
|
|
180
|
+
a += b[i];
|
|
181
|
+
s += a;
|
|
182
|
+
}
|
|
183
|
+
a %= 65521;
|
|
184
|
+
s %= 65521;
|
|
185
|
+
}
|
|
186
|
+
return (s << 16 | a) >>> 0;
|
|
187
|
+
}
|
|
188
|
+
function complete(lengths, n) {
|
|
189
|
+
let max = 0;
|
|
190
|
+
let sum = 0;
|
|
191
|
+
let count = 0;
|
|
192
|
+
for (let i = 0; i < n; i++) if (lengths[i] > max) max = lengths[i];
|
|
193
|
+
if (max === 0) return true;
|
|
194
|
+
for (let i = 0; i < n; i++) {
|
|
195
|
+
const l = lengths[i];
|
|
196
|
+
if (l) {
|
|
197
|
+
sum += 2 ** (max - l);
|
|
198
|
+
count++;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return sum === 2 ** max || sum === 1 && max === 1 && count === 1;
|
|
202
|
+
}
|
|
203
|
+
function inflate(src, limit, info, initial, strict) {
|
|
152
204
|
let pos = 0;
|
|
153
205
|
let bitBuf = 0;
|
|
154
206
|
let bitCnt = 0;
|
|
@@ -223,8 +275,10 @@ function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
|
223
275
|
const hlit = bits(5) + 257;
|
|
224
276
|
const hdist = bits(5) + 1;
|
|
225
277
|
const hclen = bits(4) + 4;
|
|
278
|
+
if (strict && (hlit > 286 || hdist > 30)) throw new InflateError("inflate: HLIT/HDIST");
|
|
226
279
|
const cl = new Uint8Array(19);
|
|
227
280
|
for (let i = 0; i < hclen; i++) cl[CL_ORDER[i]] = bits(3);
|
|
281
|
+
if (strict && !complete(cl, 19)) throw new InflateError("inflate: \u043A\u043E\u0434 \u0431\u04AF\u0440\u044D\u043D \u0431\u0438\u0448");
|
|
228
282
|
const clh = build(cl, 19);
|
|
229
283
|
const lens = new Uint8Array(hlit + hdist);
|
|
230
284
|
for (let i = 0; i < hlit + hdist; ) {
|
|
@@ -245,6 +299,9 @@ function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
|
245
299
|
lens.fill(val, i, i + rep);
|
|
246
300
|
i += rep;
|
|
247
301
|
}
|
|
302
|
+
if (strict && (!complete(lens.subarray(0, hlit), hlit) || !complete(lens.subarray(hlit), hdist))) {
|
|
303
|
+
throw new InflateError("inflate: \u043A\u043E\u0434 \u0431\u04AF\u0440\u044D\u043D \u0431\u0438\u0448");
|
|
304
|
+
}
|
|
248
305
|
lit = build(lens.subarray(0, hlit), hlit);
|
|
249
306
|
dist = build(lens.subarray(hlit), hdist);
|
|
250
307
|
}
|
|
@@ -2228,14 +2285,15 @@ function nthPage(root, n) {
|
|
|
2228
2285
|
};
|
|
2229
2286
|
return walk(root, 0);
|
|
2230
2287
|
}
|
|
2231
|
-
|
|
2288
|
+
var MAX_VERIFY_ANNOTS = 1e4;
|
|
2289
|
+
function defaultStampPage(doc, verifyUri) {
|
|
2232
2290
|
const inc = new Incremental(doc);
|
|
2233
|
-
|
|
2291
|
+
const pages = [];
|
|
2234
2292
|
const walk = (v, depth) => {
|
|
2235
|
-
if (depth > MAX_DEPTH2 ||
|
|
2293
|
+
if (depth > MAX_DEPTH2 || pages.length > 1 << 16) return;
|
|
2236
2294
|
switch (v.key("Type").name()) {
|
|
2237
2295
|
case "Page":
|
|
2238
|
-
|
|
2296
|
+
pages.push(v);
|
|
2239
2297
|
break;
|
|
2240
2298
|
case "Pages": {
|
|
2241
2299
|
const kids = v.key("Kids");
|
|
@@ -2244,7 +2302,31 @@ function pageCount(doc) {
|
|
|
2244
2302
|
}
|
|
2245
2303
|
};
|
|
2246
2304
|
walk(inc.root().key("Pages"), 0);
|
|
2247
|
-
|
|
2305
|
+
const n = pages.length;
|
|
2306
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
2307
|
+
if (!isVerifyPage(pages[i], verifyUri)) return { page: i + 1, n };
|
|
2308
|
+
}
|
|
2309
|
+
return { page: n, n };
|
|
2310
|
+
}
|
|
2311
|
+
function isVerifyPage(page, verifyUri) {
|
|
2312
|
+
try {
|
|
2313
|
+
const annots = page.key("Annots");
|
|
2314
|
+
if (annots.kind() !== "array") return false;
|
|
2315
|
+
const want = latin1(verifyUri);
|
|
2316
|
+
const m = Math.min(annots.len(), MAX_VERIFY_ANNOTS);
|
|
2317
|
+
for (let i = 0; i < m; i++) {
|
|
2318
|
+
const a = annots.index(i);
|
|
2319
|
+
if (a.kind() !== "dict" || a.key("Subtype").name() !== "Link") continue;
|
|
2320
|
+
const act = a.key("A");
|
|
2321
|
+
if (act.kind() !== "dict" || act.key("S").name() !== "URI") continue;
|
|
2322
|
+
const u = act.key("URI");
|
|
2323
|
+
if (u.kind() !== "string") continue;
|
|
2324
|
+
const got = u.rawString();
|
|
2325
|
+
if (got.length === want.length && got.every((b, j) => b === want[j])) return true;
|
|
2326
|
+
}
|
|
2327
|
+
} catch {
|
|
2328
|
+
}
|
|
2329
|
+
return false;
|
|
2248
2330
|
}
|
|
2249
2331
|
|
|
2250
2332
|
export {
|
|
@@ -2253,7 +2335,10 @@ export {
|
|
|
2253
2335
|
isBrowser,
|
|
2254
2336
|
InflateError,
|
|
2255
2337
|
inflateRaw,
|
|
2338
|
+
zlibInflateStrict,
|
|
2339
|
+
adler32,
|
|
2256
2340
|
PdfError,
|
|
2341
|
+
PInt,
|
|
2257
2342
|
PRef,
|
|
2258
2343
|
Reader,
|
|
2259
2344
|
StructureError,
|
|
@@ -2270,5 +2355,5 @@ export {
|
|
|
2270
2355
|
visibleRect,
|
|
2271
2356
|
pageGeometry,
|
|
2272
2357
|
nthPage,
|
|
2273
|
-
|
|
2358
|
+
defaultStampPage
|
|
2274
2359
|
};
|
package/dist/convert.js
CHANGED
|
@@ -77,6 +77,24 @@ function zlibInflate(src, limit = 64 << 20, initial) {
|
|
|
77
77
|
return inflateRaw(src.subarray(2), limit, void 0, initial);
|
|
78
78
|
}
|
|
79
79
|
function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
80
|
+
return inflate(src, limit, info, initial, false);
|
|
81
|
+
}
|
|
82
|
+
function complete(lengths, n) {
|
|
83
|
+
let max = 0;
|
|
84
|
+
let sum = 0;
|
|
85
|
+
let count = 0;
|
|
86
|
+
for (let i = 0; i < n; i++) if (lengths[i] > max) max = lengths[i];
|
|
87
|
+
if (max === 0) return true;
|
|
88
|
+
for (let i = 0; i < n; i++) {
|
|
89
|
+
const l = lengths[i];
|
|
90
|
+
if (l) {
|
|
91
|
+
sum += 2 ** (max - l);
|
|
92
|
+
count++;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return sum === 2 ** max || sum === 1 && max === 1 && count === 1;
|
|
96
|
+
}
|
|
97
|
+
function inflate(src, limit, info, initial, strict) {
|
|
80
98
|
let pos = 0;
|
|
81
99
|
let bitBuf = 0;
|
|
82
100
|
let bitCnt = 0;
|
|
@@ -151,8 +169,10 @@ function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
|
151
169
|
const hlit = bits(5) + 257;
|
|
152
170
|
const hdist = bits(5) + 1;
|
|
153
171
|
const hclen = bits(4) + 4;
|
|
172
|
+
if (strict && (hlit > 286 || hdist > 30)) throw new InflateError("inflate: HLIT/HDIST");
|
|
154
173
|
const cl = new Uint8Array(19);
|
|
155
174
|
for (let i = 0; i < hclen; i++) cl[CL_ORDER[i]] = bits(3);
|
|
175
|
+
if (strict && !complete(cl, 19)) throw new InflateError("inflate: \u043A\u043E\u0434 \u0431\u04AF\u0440\u044D\u043D \u0431\u0438\u0448");
|
|
156
176
|
const clh = build(cl, 19);
|
|
157
177
|
const lens = new Uint8Array(hlit + hdist);
|
|
158
178
|
for (let i = 0; i < hlit + hdist; ) {
|
|
@@ -173,6 +193,9 @@ function inflateRaw(src, limit = 64 << 20, info, initial) {
|
|
|
173
193
|
lens.fill(val, i, i + rep);
|
|
174
194
|
i += rep;
|
|
175
195
|
}
|
|
196
|
+
if (strict && (!complete(lens.subarray(0, hlit), hlit) || !complete(lens.subarray(hlit), hdist))) {
|
|
197
|
+
throw new InflateError("inflate: \u043A\u043E\u0434 \u0431\u04AF\u0440\u044D\u043D \u0431\u0438\u0448");
|
|
198
|
+
}
|
|
176
199
|
lit = build(lens.subarray(0, hlit), hlit);
|
|
177
200
|
dist = build(lens.subarray(hlit), hdist);
|
|
178
201
|
}
|