@gerege-systems/eid-mongolia-sdk 0.41.0 → 0.43.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/pades.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { E as EidError } from './errors-CgJcEjrZ.js';
1
+ import { E as EidError } from './errors-BN0Fp3qd.js';
2
2
  import { F as FetchFn } from './fetch-BjfH46q9.js';
3
3
 
4
4
  /** Олгогчийн гарын үсэгтэй «revoked» хариу (OCSP эсвэл CRL) — complete-д дахин оролдохгүй хатуу алдаа (Go ErrCertificateRevoked). */
@@ -245,5 +245,44 @@ declare function suggestPlacement(pdf: Uint8Array, appearance: PadesAppearance):
245
245
  * @throws `signal.reason` (анхдагч `DOMException` `AbortError`) — `signal` цуцлагдвал.
246
246
  */
247
247
  declare function complete(state: Uint8Array | ArrayBuffer, signature: Uint8Array | string, opts?: PadesCompleteOptions): Promise<PadesCompleted>;
248
+ /** Байгууллагын тамганы RP-API — `EidClient.seal` (`SealApi`) хангана; тестэд орлуулж болно. */
249
+ interface PadesSealer {
250
+ getCertificate(orgEtsi: string): Promise<{
251
+ certificate: Uint8Array;
252
+ }>;
253
+ seal(orgEtsi: string, digest: Uint8Array, hashAlgorithm: "SHA-256"): Promise<{
254
+ signature: Uint8Array;
255
+ certificate: Uint8Array;
256
+ }>;
257
+ }
258
+ /**
259
+ * {@link sealPdf}-ийн тохиргоо. Тамга үл харагдах, баталгаажуулалтын (QR) хуудасгүй: verify хуудас нь CA-ийн бүртгэл
260
+ * (`/verify/{docId}`) рүү заадаг ч тамга иргэний гарын үсгийн бүртгэлд (`POST /pdf/signatures`) ордоггүй.
261
+ */
262
+ interface PadesSealOptions {
263
+ /** `/Reason` (≤ 127 UTF-16 нэгж). */
264
+ reason?: string;
265
+ /** `/Name`; хоосон бол гэрчилгээний CN (байгууллагын нэр). */
266
+ signerName?: string;
267
+ /** `/M`. Анхдагч — одоо. */
268
+ signingTime?: Date;
269
+ /** Олгогч гинж DER (05, 03, 02). Анхдагч — шигтгэсэн eID гинжээс. */
270
+ chain?: Uint8Array[];
271
+ /** TSA/OCSP/CRL ({@link complete}-тэй ижил). RFC 3161 timestamp ЗААВАЛ — TSA унавал `TSA_UNAVAILABLE`. */
272
+ complete?: PadesCompleteOptions;
273
+ }
274
+ /**
275
+ * PDF-ийг байгууллагын цахим тамгаар (e-Seal) тамгална: тамганы гэрчилгээ (`GET /seal/certificate/{orgEtsi}`) →
276
+ * {@link prepare} → 32 байт DTBS-ийг `POST /seal/{orgEtsi}`-ээр (SHA-256) тамгалуулна → {@link complete} (TSA + OCSP/CRL +
277
+ * DSS) → PAdES-BASELINE-LT. PDF eID руу очихгүй. Шалгагчид (CA `/v3/validate/pdf`, `validatePdf`) энэ гарын үсгийг
278
+ * `usage: "seal"` (байгууллагын тамга) гэж ангилна. Go `pades.SealPDF`-тэй ижил.
279
+ *
280
+ * `sealer` нь RP backend-ийн `EidClient.seal` (RP secret) — хөтөчөөс шууд дуудахгүй.
281
+ *
282
+ * @throws {PadesError} SIGNER_INVALID (гэрчилгээ e-Seal биш, эсвэл тамгалах хооронд гэрчилгээ солигдсон — дахин оролд),
283
+ * prepare/complete-ийн бусад код (SIGNATURE_INVALID, TSA_UNAVAILABLE, LTV_UNAVAILABLE …). RP-API-ийн алдаа
284
+ * (ForbiddenError — SEAL эрхгүй; ApiError 429 — `retryable`) хэвээр шидэгдэнэ.
285
+ */
286
+ declare function sealPdf(sealer: PadesSealer, orgEtsi: string, pdf: Uint8Array | ArrayBuffer, opts?: PadesSealOptions): Promise<PadesCompleted>;
248
287
 
249
- export { CertificateRevokedError, PADES_ERROR_CODES, PROFILE_VERSION, type PadesAppearance, type PadesCompleteOptions, type PadesCompleted, PadesError, type PadesErrorCode, type PadesPlacement, type PadesPlacementStatus, type PadesPrepareOptions, type PadesPrepared, type PlacementSuggestion, complete, prepare, profileVersion, suggestPlacement };
288
+ export { CertificateRevokedError, PADES_ERROR_CODES, PROFILE_VERSION, type PadesAppearance, type PadesCompleteOptions, type PadesCompleted, PadesError, type PadesErrorCode, type PadesPlacement, type PadesPlacementStatus, type PadesPrepareOptions, type PadesPrepared, type PadesSealOptions, type PadesSealer, type PlacementSuggestion, complete, prepare, profileVersion, sealPdf, suggestPlacement };
package/dist/pades.js CHANGED
@@ -59,7 +59,7 @@ import {
59
59
  } from "./chunk-ISTWNY6N.js";
60
60
  import {
61
61
  EidError
62
- } from "./chunk-PWFTN52X.js";
62
+ } from "./chunk-GBG7CMO7.js";
63
63
 
64
64
  // src/pades/limits.ts
65
65
  var MAX_INPUT_BYTES = (10 << 20) - (256 << 10);
@@ -1971,6 +1971,34 @@ async function complete(state, signature, opts = {}) {
1971
1971
  claimedRole: st.claimedRole
1972
1972
  };
1973
1973
  }
1974
+ function isSealCert(c) {
1975
+ return !c.isCA && (c.keyUsage & 2) !== 0 && (c.keyUsage & 1) === 0 && c.extKeyUsage.length === 0;
1976
+ }
1977
+ async function sealPdf(sealer, orgEtsi, pdf, opts = {}) {
1978
+ if (!sealer || typeof sealer.getCertificate !== "function" || typeof sealer.seal !== "function") {
1979
+ throw new PadesError("REQUEST_INVALID", "sealer (EidClient.seal) \u0437\u0430\u0430\u0432\u0430\u043B");
1980
+ }
1981
+ const sc = await sealer.getCertificate(orgEtsi);
1982
+ let cert;
1983
+ try {
1984
+ cert = parseCertificate(u8(sc.certificate, "certificate"));
1985
+ } catch (e) {
1986
+ throw new PadesError("SIGNER_INVALID", "\u0442\u0430\u043C\u0433\u0430\u043D\u044B \u0433\u044D\u0440\u0447\u0438\u043B\u0433\u044D\u044D \u0437\u0430\u0434\u0430\u0440\u0441\u0430\u043D\u0433\u04AF\u0439", { cause: e });
1987
+ }
1988
+ if (!isSealCert(cert)) throw new PadesError("SIGNER_INVALID", "\u0433\u044D\u0440\u0447\u0438\u043B\u0433\u044D\u044D e-Seal \u0431\u0438\u0448 (KeyUsage = \u0437\u04E9\u0432\u0445\u04E9\u043D nonRepudiation \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439)");
1989
+ const p = await prepare(pdf, {
1990
+ signerCert: cert.raw,
1991
+ chain: opts.chain,
1992
+ signerName: opts.signerName,
1993
+ reason: opts.reason,
1994
+ signingTime: opts.signingTime
1995
+ });
1996
+ const r = await sealer.seal(orgEtsi, p.dtbs, "SHA-256");
1997
+ if (!eq2(u8(r.certificate, "certificate"), cert.raw)) {
1998
+ throw new PadesError("SIGNER_INVALID", "\u0442\u0430\u043C\u0433\u0430\u043B\u0430\u0445 \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u0433\u0443\u0443\u043B\u043B\u0430\u0433\u044B\u043D \u0442\u0430\u043C\u0433\u0430\u043D\u044B \u0433\u044D\u0440\u0447\u0438\u043B\u0433\u044D\u044D \u0441\u043E\u043B\u0438\u0433\u0434\u0441\u043E\u043D \u2014 \u0434\u0430\u0445\u0438\u043D \u043E\u0440\u043E\u043B\u0434\u043E\u043D\u043E \u0443\u0443");
1999
+ }
2000
+ return complete(p.state, r.signature, opts.complete);
2001
+ }
1974
2002
  export {
1975
2003
  CertificateRevokedError,
1976
2004
  PADES_ERROR_CODES,
@@ -1979,5 +2007,6 @@ export {
1979
2007
  complete,
1980
2008
  prepare,
1981
2009
  profileVersion,
2010
+ sealPdf,
1982
2011
  suggestPlacement
1983
2012
  };
@@ -1,4 +1,4 @@
1
- import { E as EidError } from './errors-CgJcEjrZ.cjs';
1
+ import { E as EidError } from './errors-BN0Fp3qd.cjs';
2
2
  import { F as FetchFn } from './fetch-BjfH46q9.cjs';
3
3
 
4
4
  type Indication = "valid" | "invalid" | "indeterminate";
@@ -1,4 +1,4 @@
1
- import { E as EidError } from './errors-CgJcEjrZ.js';
1
+ import { E as EidError } from './errors-BN0Fp3qd.js';
2
2
  import { F as FetchFn } from './fetch-BjfH46q9.js';
3
3
 
4
4
  type Indication = "valid" | "invalid" | "indeterminate";
package/dist/validate.js CHANGED
@@ -65,7 +65,7 @@ import {
65
65
  } from "./chunk-ISTWNY6N.js";
66
66
  import {
67
67
  EidError
68
- } from "./chunk-PWFTN52X.js";
68
+ } from "./chunk-GBG7CMO7.js";
69
69
 
70
70
  // src/pades/validate/evaluate.ts
71
71
  var PROBLEMS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gerege-systems/eid-mongolia-sdk",
3
- "version": "0.41.0",
3
+ "version": "0.43.0",
4
4
  "description": "e-ID Mongolia Relying Party SDK — иргэнээр утсаар нь нэвтрэлт ба хууль ёсны цахим гарын үсэг (RP-API v3, Smart-ID нийцтэй).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsup src/index.ts src/browser.ts src/pades.ts src/validate.ts --format esm,cjs --dts --clean && tsup src/button.ts --format esm,cjs --dts --tsconfig tsconfig.button.json && tsup src/convert.ts --format esm --dts --tsconfig tsconfig.button.json",
52
- "test": "npm run build && node --test --experimental-strip-types test/sdk.test.ts test/portal-gaps.test.ts test/chain.test.ts test/qr.test.ts test/myqr.test.ts test/login.test.ts test/button.test.ts test/sign-gaps.test.ts test/session-start.test.ts test/pades-session.test.ts test/pades-golden.test.ts test/pades-placement.test.ts test/pades-unit.test.ts test/convert.test.ts test/share.test.ts test/validate-golden.test.ts test/validate-revisions.test.ts test/validate-env.test.ts test/pades-revocation.test.ts test/pades-encrypt.test.ts test/pades-objstm.test.ts test/pades-objstm-encrypt.test.ts test/validate-fuzz.test.ts test/pades-lexer-loop.test.ts",
52
+ "test": "npm run build && node --test --experimental-strip-types test/sdk.test.ts test/portal-gaps.test.ts test/chain.test.ts test/qr.test.ts test/myqr.test.ts test/login.test.ts test/button.test.ts test/sign-gaps.test.ts test/session-start.test.ts test/pades-session.test.ts test/pades-golden.test.ts test/pades-placement.test.ts test/pades-unit.test.ts test/convert.test.ts test/share.test.ts test/validate-golden.test.ts test/validate-revisions.test.ts test/validate-env.test.ts test/pades-revocation.test.ts test/pades-encrypt.test.ts test/pades-objstm.test.ts test/pades-objstm-encrypt.test.ts test/validate-fuzz.test.ts test/pades-lexer-loop.test.ts test/seal.test.ts",
53
53
  "test:contract": "npm run build && node --experimental-strip-types test/contract.test.ts",
54
54
  "lint": "tsc --noEmit && tsc --noEmit -p tsconfig.button.json",
55
55
  "golden:check": "node scripts/sync-pades-golden.mjs --check",