@gerege-systems/eid-mongolia-sdk 0.24.0 → 0.25.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 +12 -3
- package/dist/{chunk-T3QLOY6J.js → chunk-CRXEUCMP.js} +60 -0
- package/dist/convert.js +23 -0
- package/dist/pades.cjs +991 -8
- package/dist/pades.d.cts +26 -1
- package/dist/pades.d.ts +26 -1
- package/dist/pades.js +936 -8
- 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}` бүртгэл |
|
|
@@ -628,9 +628,18 @@ reply({ verifyUrl: reg.verifyUrl });
|
|
|
628
628
|
багтахгүй, docId-гүй (хуудасгүй гарын үсэгтэй баримт) бол `REQUEST_INVALID`. Харагдах бүр ~+90 KB. Дүрэм: Go репогийн
|
|
629
629
|
`pades/APPEARANCE_SPEC.md`.
|
|
630
630
|
|
|
631
|
+
`x, y` нь **хүссэн** байрлал: тэр хэсэгт хуудасны агуулга (бичвэр, хүснэгтийн зураас, зураг, өмнөх гарын үсэг) байвал
|
|
632
|
+
дүрслэл чөлөөт зай руу шилжинэ — эхлээд толин тусгал багана (баруун доод → зүүн доод), дараа нь 12 pt-ээр дээш. Хуудсыг
|
|
633
|
+
рендерлэхгүй, content stream-ийг л уншина (Go-той хайрцаг бүрээр ижил). Үр дүн: `p.placement` —
|
|
634
|
+
`{ page, x, y, width, height, status }` (pt), `status`: `requested` (хүссэн газраа) | `moved` (шилжсэн) | `overlap` (чөлөөт
|
|
635
|
+
зай алга — хүссэн газраа, агуулга дээр) | `unscanned` (хуудсыг хязгаарт багтааж уншиж чадсангүй — хүссэн газраа). Гарын
|
|
636
|
+
үсэг аль ч үед хүчинтэй; `overlap` / `unscanned`-ийг хэрэглэгчид мэдэгдэх нь зүйтэй. Дүрэм: Go репогийн
|
|
637
|
+
`pades/PLACEMENT_SPEC.md`.
|
|
638
|
+
|
|
631
639
|
```ts
|
|
632
640
|
const p = await prepare(pdfBytes, { signerCert, verifyPage: true, fileName: "Гэрээ №12.pdf",
|
|
633
641
|
appearance: { page: 1, x: 340, y: 36, width: 220, height: 64 } });
|
|
642
|
+
if (p.placement?.status === "overlap") notice("Гарын үсэг хуудасны агуулга дээр давхцаж байрлана");
|
|
634
643
|
```
|
|
635
644
|
|
|
636
645
|
### Зөвхөн Node (backend бүгдийг хийнэ)
|
|
@@ -1035,8 +1044,8 @@ npm run test:convert-e2e # /convert жинхэнэ LibreOffice Chromium-д (BR
|
|
|
1035
1044
|
|
|
1036
1045
|
`/pades`-ийн conformance fixture (golden: оролт, тестийн PKI-ийн гэрчилгээ, TSA/OCSP/CRL-ийн тогтмол хариу, хүлээгдэх
|
|
1037
1046
|
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`.
|
|
1047
|
+
tag `pades-golden-vN`, одоо v5 — `placement/` scanner vectors-той); CI `--check`-ээр бэхэлсэн commit-тэй тулгана. Профайл:
|
|
1048
|
+
Go репогийн `pades/PROFILE.md`, `PAGE_SPEC.md`, `PRECHECKS.md`, `WIRE.md`, `APPEARANCE_SPEC.md`, `PLACEMENT_SPEC.md`.
|
|
1040
1049
|
|
|
1041
1050
|
### Гэрээний шалгалт
|
|
1042
1051
|
|
|
@@ -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
|
}
|
|
@@ -2253,7 +2310,10 @@ export {
|
|
|
2253
2310
|
isBrowser,
|
|
2254
2311
|
InflateError,
|
|
2255
2312
|
inflateRaw,
|
|
2313
|
+
zlibInflateStrict,
|
|
2314
|
+
adler32,
|
|
2256
2315
|
PdfError,
|
|
2316
|
+
PInt,
|
|
2257
2317
|
PRef,
|
|
2258
2318
|
Reader,
|
|
2259
2319
|
StructureError,
|
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
|
}
|