@gerege-systems/eid-mongolia-sdk 0.40.3 → 0.42.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.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-A6FYBPRV.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
  };
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-A6FYBPRV.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.40.3",
3
+ "version": "0.42.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",