@gerege-systems/eid-mongolia-sdk 0.18.3 → 0.20.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.cjs CHANGED
@@ -538,6 +538,8 @@ function schemeFor(alg) {
538
538
  return { kind: "rsa", hash: "SHA-384" };
539
539
  case OID.sha512WithRSA:
540
540
  return { kind: "rsa", hash: "SHA-512" };
541
+ case "1.2.840.10045.4.1":
542
+ return { kind: "ecdsa", hash: "SHA-1" };
541
543
  case OID.ecdsaSHA256:
542
544
  return { kind: "ecdsa", hash: "SHA-256" };
543
545
  case OID.ecdsaSHA384:
@@ -944,6 +946,9 @@ function lenOf(n) {
944
946
  }
945
947
  var OID_OCSP_BASIC = "1.3.6.1.5.5.7.48.1.1";
946
948
  async function parseOCSPForCert(der2, c, issuer) {
949
+ return parseOCSP(der2, intValue(c.serial), issuer);
950
+ }
951
+ async function parseOCSP(der2, serial, issuer) {
947
952
  const top = children(expect(parseOne(der2), TAG.SEQUENCE, "OCSPResponse"));
948
953
  if (expect(top[0], TAG.ENUMERATED, "status").value[0] !== 0) throw new Error("OCSP response status");
949
954
  const rb = children(expect(children(expect(top[1], 160, "responseBytes"))[0], TAG.SEQUENCE, "ResponseBytes"));
@@ -959,18 +964,22 @@ async function parseOCSPForCert(der2, c, issuer) {
959
964
  if (rid.tag !== 161 && rid.tag !== 162) throw new Error("invalid responder id tag");
960
965
  i++;
961
966
  const responses = children(expect(tf[i], TAG.SEQUENCE, "responses"));
962
- if (responses.length === 0) throw new Error("OCSP response contains bad number of responses");
963
- const serial = intValue(c.serial);
964
967
  let single;
965
- for (const r of responses) {
966
- const f = children(r);
967
- const cid2 = children(f[0]);
968
- if (intValue(expect(cid2[3], TAG.INTEGER, "serial").value) === serial) {
969
- single = f;
970
- break;
968
+ if (serial !== void 0) {
969
+ if (responses.length === 0) throw new Error("OCSP response contains bad number of responses");
970
+ for (const r of responses) {
971
+ const f = children(r);
972
+ const cid2 = children(f[0]);
973
+ if (intValue(expect(cid2[3], TAG.INTEGER, "serial").value) === serial) {
974
+ single = f;
975
+ break;
976
+ }
971
977
  }
978
+ if (!single) throw new Error("no response matching the supplied certificate");
979
+ } else {
980
+ if (responses.length !== 1) throw new Error("OCSP response contains bad number of responses");
981
+ single = children(responses[0]);
972
982
  }
973
- if (!single) throw new Error("no response matching the supplied certificate");
974
983
  let certificate;
975
984
  if (basic[3]?.tag === 160) {
976
985
  const certs = children(expect(children(basic[3])[0], TAG.SEQUENCE, "certs"));
@@ -978,8 +987,8 @@ async function parseOCSPForCert(der2, c, issuer) {
978
987
  }
979
988
  if (certificate) {
980
989
  if (!await verifySignature(certificate, sigAlg, tbs.raw, sigBits)) throw new Error("bad signature on embedded certificate");
981
- if (!await checkSignature(issuer, certificate.sigAlg, certificate.tbs, certificate.signature)) throw new Error("bad OCSP signature");
982
- } else if (!await verifySignature(issuer, sigAlg, tbs.raw, sigBits)) {
990
+ if (issuer && !await checkSignature(issuer, certificate.sigAlg, certificate.tbs, certificate.signature)) throw new Error("bad OCSP signature");
991
+ } else if (issuer && !await verifySignature(issuer, sigAlg, tbs.raw, sigBits)) {
983
992
  throw new Error("bad OCSP signature");
984
993
  }
985
994
  const cid = children(single[0]);
@@ -988,6 +997,7 @@ async function parseOCSPForCert(der2, c, issuer) {
988
997
  const st = single[1];
989
998
  const status = st.tag === 128 ? "good" : st.tag === 161 ? "revoked" : st.tag === 130 ? "unknown" : void 0;
990
999
  if (!status) throw new Error("OCSP certStatus");
1000
+ const revokedAt = status === "revoked" ? parsePreciseTime(expect(children(st)[0], TAG.GeneralizedTime, "revocationTime")) : void 0;
991
1001
  const thisUpdate = parsePreciseTime(expect(single[2], TAG.GeneralizedTime, "thisUpdate"));
992
1002
  let nextUpdate;
993
1003
  for (const x of single.slice(3)) {
@@ -999,7 +1009,7 @@ async function parseOCSPForCert(der2, c, issuer) {
999
1009
  }
1000
1010
  }
1001
1011
  }
1002
- return { status, thisUpdate, nextUpdate, certificate };
1012
+ return { status, serial: intValue(expect(cid[3], TAG.INTEGER, "serial").value), thisUpdate, nextUpdate, revokedAt, certificate };
1003
1013
  }
1004
1014
  function responderOK(resp, issuer) {
1005
1015
  if (!resp.certificate || equal(resp.certificate.raw, issuer.raw)) return true;
@@ -1211,7 +1221,7 @@ function zlibInflate(src, limit = 64 << 20) {
1211
1221
  if (flg & 32) throw new InflateError("zlib: preset dictionary");
1212
1222
  return inflateRaw(src.subarray(2), limit);
1213
1223
  }
1214
- function inflateRaw(src, limit = 64 << 20) {
1224
+ function inflateRaw(src, limit = 64 << 20, info) {
1215
1225
  let pos = 0;
1216
1226
  let bitBuf = 0;
1217
1227
  let bitCnt = 0;
@@ -1256,7 +1266,9 @@ function inflateRaw(src, limit = 64 << 20) {
1256
1266
  inflateBlocks();
1257
1267
  } catch (e) {
1258
1268
  if (!(e instanceof Truncated)) throw e;
1269
+ if (info) info.truncated = true;
1259
1270
  }
1271
+ if (info) info.end = pos;
1260
1272
  return out.slice(0, len);
1261
1273
  function inflateBlocks() {
1262
1274
  for (; ; ) {
package/dist/pades.d.cts CHANGED
@@ -1,15 +1,5 @@
1
1
  import { E as EidError } from './errors-xTmsGXyo.cjs';
2
-
3
- type FetchFn = (url: string, init: {
4
- method: string;
5
- headers?: Record<string, string>;
6
- body?: Uint8Array;
7
- redirect: "manual";
8
- signal?: AbortSignal;
9
- }) => Promise<{
10
- status: number;
11
- arrayBuffer(): Promise<ArrayBuffer>;
12
- }>;
2
+ import { F as FetchFn } from './fetch-BjfH46q9.cjs';
13
3
 
14
4
  /** PDF/CMS профайлын хувилбар (Go reference `ProfileVersion`). */
15
5
  declare const PROFILE_VERSION = "pades-client/1";
package/dist/pades.d.ts CHANGED
@@ -1,15 +1,5 @@
1
1
  import { E as EidError } from './errors-xTmsGXyo.js';
2
-
3
- type FetchFn = (url: string, init: {
4
- method: string;
5
- headers?: Record<string, string>;
6
- body?: Uint8Array;
7
- redirect: "manual";
8
- signal?: AbortSignal;
9
- }) => Promise<{
10
- status: number;
11
- arrayBuffer(): Promise<ArrayBuffer>;
12
- }>;
2
+ import { F as FetchFn } from './fetch-BjfH46q9.js';
13
3
 
14
4
  /** PDF/CMS профайлын хувилбар (Go reference `ProfileVersion`). */
15
5
  declare const PROFILE_VERSION = "pades-client/1";