@gerege-systems/eid-mongolia-sdk 0.2.0 → 0.3.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 CHANGED
@@ -26,7 +26,7 @@ Node.js ≥ 22 (global `fetch`, `node:crypto`).
26
26
  import { EidClient } from "@gerege-systems/eid-mongolia-sdk";
27
27
 
28
28
  const eid = new EidClient({
29
- baseUrl: "https://ca.eidmongolia.mn",
29
+ // baseUrl анхдагч https://rp.eidmongolia.mn (RP-API, /v3-гүй) — mTLS-тэй RP ч мөн энэ хост
30
30
  credentials: {
31
31
  rpUUID: process.env.EID_RP_UUID!,
32
32
  rpName: "Интернэт банк", // дэд системийн нэр, ≤120 тэмдэгт
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  ApiError: () => ApiError,
24
24
  AuthApi: () => AuthApi,
25
25
  AuthenticationError: () => AuthenticationError,
26
+ DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
26
27
  EidClient: () => EidClient,
27
28
  EidError: () => EidError,
28
29
  ForbiddenError: () => ForbiddenError,
@@ -38,6 +39,7 @@ __export(index_exports, {
38
39
  interactionsToBase64: () => interactionsToBase64,
39
40
  parseSessionResult: () => parseSessionResult,
40
41
  randomChallenge: () => randomChallenge,
42
+ resolveBaseUrl: () => resolveBaseUrl,
41
43
  sha256Base64: () => sha256Base64,
42
44
  verifyPayloadSignature: () => verifyPayloadSignature,
43
45
  verifyPrehashedSignature: () => verifyPrehashedSignature
@@ -691,15 +693,31 @@ function isCa(cert) {
691
693
  }
692
694
 
693
695
  // src/client.ts
696
+ var DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
697
+ var LEGACY_HOSTS = /* @__PURE__ */ new Set(["ca.eidmongolia.mn", "e-id.mn", "www.e-id.mn"]);
698
+ function resolveBaseUrl(baseUrl) {
699
+ const raw = (baseUrl ?? DEFAULT_BASE_URL).trim().replace(/\/+$/, "");
700
+ let u;
701
+ try {
702
+ u = new URL(raw);
703
+ } catch {
704
+ throw new Error(`EidClient: baseUrl \u0431\u0443\u0440\u0443\u0443 URL: ${raw}`);
705
+ }
706
+ if (LEGACY_HOSTS.has(u.hostname) && (u.pathname === "" || u.pathname === "/")) {
707
+ throw new Error(
708
+ `EidClient: RP-API ${u.hostname}-\u0430\u0430\u0441 ${DEFAULT_BASE_URL} \u0440\u0443\u0443 \u0448\u0438\u043B\u0436\u0441\u044D\u043D (/v3-\u0433\u04AF\u0439) \u2014 baseUrl-\u0438\u0439\u0433 ${DEFAULT_BASE_URL} \u0431\u043E\u043B\u0433\u043E\u043D\u043E \u0443\u0443 (\u044D\u0441\u0432\u044D\u043B \u0445\u043E\u043E\u0441\u043E\u043D \u043E\u0440\u0445\u0438).`
709
+ );
710
+ }
711
+ return raw;
712
+ }
694
713
  var EidClient = class {
695
714
  auth;
696
715
  sign;
697
716
  session;
698
717
  validator;
699
718
  constructor(cfg) {
700
- if (!cfg.baseUrl) throw new Error("EidClient: baseUrl \u0448\u0430\u0430\u0440\u0434\u043B\u0430\u0433\u0430\u0442\u0430\u0439");
701
719
  if (!cfg.credentials?.apiSecret) throw new Error("EidClient: credentials.apiSecret \u0448\u0430\u0430\u0440\u0434\u043B\u0430\u0433\u0430\u0442\u0430\u0439");
702
- const base = cfg.baseUrl.replace(/\/+$/, "") + "/v3";
720
+ const base = resolveBaseUrl(cfg.baseUrl);
703
721
  const http = new Http({
704
722
  baseUrl: base,
705
723
  apiSecret: cfg.credentials.apiSecret,
@@ -719,6 +737,7 @@ var EidClient = class {
719
737
  ApiError,
720
738
  AuthApi,
721
739
  AuthenticationError,
740
+ DEFAULT_BASE_URL,
722
741
  EidClient,
723
742
  EidError,
724
743
  ForbiddenError,
@@ -734,6 +753,7 @@ var EidClient = class {
734
753
  interactionsToBase64,
735
754
  parseSessionResult,
736
755
  randomChallenge,
756
+ resolveBaseUrl,
737
757
  sha256Base64,
738
758
  verifyPayloadSignature,
739
759
  verifyPrehashedSignature
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { X509Certificate, KeyObject } from 'node:crypto';
2
2
 
3
3
  interface HttpConfig {
4
- /** RP-API суурь URL, /v3 хүртэл. Ж: https://ca.eidmongolia.mn/v3 */
4
+ /** RP-API-ийн бүтэн суурь URL. Ж: https://rp.eidmongolia.mn */
5
5
  baseUrl: string;
6
6
  /** API secret (rp_sk_…) — Authorization: Bearer-д орно. */
7
7
  apiSecret: string;
@@ -361,8 +361,11 @@ declare function verifyPayloadSignature(payload: Buffer, sigB64: string, key: Ke
361
361
  declare function verifyPrehashedSignature(digest: Buffer, sigB64: string, key: KeyObject, alg: string, hash: string): boolean;
362
362
 
363
363
  interface ClientConfig {
364
- /** RP-API суурь URL (/v3-гүйгээр — SDK нэмнэ). Ж: https://ca.eidmongolia.mn */
365
- baseUrl: string;
364
+ /**
365
+ * RP-API-ийн БҮТЭН суурь URL — SDK зам залгахаас өөр юу ч нэмэхгүй (0.3.0-аас /v3 залгахгүй).
366
+ * Анхдагч: {@link DEFAULT_BASE_URL} (`https://rp.eidmongolia.mn`). mTLS-тэй RP ч мөн энэ хост.
367
+ */
368
+ baseUrl?: string;
366
369
  /** RP таних мэдээлэл + API secret. */
367
370
  credentials: RpCredentials;
368
371
  /** Default certLevel (auth/sign бүрд). Default QUALIFIED. */
@@ -376,6 +379,10 @@ interface ClientConfig {
376
379
  /** Trust anchor (Root CA) — validator-д. Production-д ЗААВАЛ. */
377
380
  trust?: TrustConfig;
378
381
  }
382
+ /** RP-API-ийн албан ёсны хост (2026-09-28-наас бүх RP, /v3-гүй). */
383
+ declare const DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
384
+ /** baseUrl-ийг шалгаж, төгсгөлийн "/"-ийг хасна. */
385
+ declare function resolveBaseUrl(baseUrl: string | undefined): string;
379
386
  declare class EidClient {
380
387
  readonly auth: AuthApi;
381
388
  readonly sign: SignApi;
@@ -447,4 +454,4 @@ declare class SessionFailedError extends EidError {
447
454
  declare class ValidationError extends EidError {
448
455
  }
449
456
 
450
- export { type AcspContext, type AcspV2Params, ApiError, AuthApi, type AuthDefaults, type AuthOptions, AuthenticationError, type CertificateLevel, type ClientConfig, type DeviceLinkSession, EidClient, EidError, type EndResult, type FlowType, ForbiddenError, type HashAlgorithm, Http, type HttpConfig, type Interaction, NetworkError, type NotificationSession, ResponseValidator, type RevocationChecker, type RevocationStatus, type RpCredentials, SessionApi, SessionFailedError, type SessionResult, type SessionState, SignApi, type SignDefaults, type SignOptions, type SignatureAlgorithm, type SignatureAlgorithmParameters, type SignatureProtocol, type TrustConfig, ValidationError, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, interactionsToBase64, parseSessionResult, randomChallenge, sha256Base64, verifyPayloadSignature, verifyPrehashedSignature };
457
+ export { type AcspContext, type AcspV2Params, ApiError, AuthApi, type AuthDefaults, type AuthOptions, AuthenticationError, type CertificateLevel, type ClientConfig, DEFAULT_BASE_URL, type DeviceLinkSession, EidClient, EidError, type EndResult, type FlowType, ForbiddenError, type HashAlgorithm, Http, type HttpConfig, type Interaction, NetworkError, type NotificationSession, ResponseValidator, type RevocationChecker, type RevocationStatus, type RpCredentials, SessionApi, SessionFailedError, type SessionResult, type SessionState, SignApi, type SignDefaults, type SignOptions, type SignatureAlgorithm, type SignatureAlgorithmParameters, type SignatureProtocol, type TrustConfig, ValidationError, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, interactionsToBase64, parseSessionResult, randomChallenge, resolveBaseUrl, sha256Base64, verifyPayloadSignature, verifyPrehashedSignature };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { X509Certificate, KeyObject } from 'node:crypto';
2
2
 
3
3
  interface HttpConfig {
4
- /** RP-API суурь URL, /v3 хүртэл. Ж: https://ca.eidmongolia.mn/v3 */
4
+ /** RP-API-ийн бүтэн суурь URL. Ж: https://rp.eidmongolia.mn */
5
5
  baseUrl: string;
6
6
  /** API secret (rp_sk_…) — Authorization: Bearer-д орно. */
7
7
  apiSecret: string;
@@ -361,8 +361,11 @@ declare function verifyPayloadSignature(payload: Buffer, sigB64: string, key: Ke
361
361
  declare function verifyPrehashedSignature(digest: Buffer, sigB64: string, key: KeyObject, alg: string, hash: string): boolean;
362
362
 
363
363
  interface ClientConfig {
364
- /** RP-API суурь URL (/v3-гүйгээр — SDK нэмнэ). Ж: https://ca.eidmongolia.mn */
365
- baseUrl: string;
364
+ /**
365
+ * RP-API-ийн БҮТЭН суурь URL — SDK зам залгахаас өөр юу ч нэмэхгүй (0.3.0-аас /v3 залгахгүй).
366
+ * Анхдагч: {@link DEFAULT_BASE_URL} (`https://rp.eidmongolia.mn`). mTLS-тэй RP ч мөн энэ хост.
367
+ */
368
+ baseUrl?: string;
366
369
  /** RP таних мэдээлэл + API secret. */
367
370
  credentials: RpCredentials;
368
371
  /** Default certLevel (auth/sign бүрд). Default QUALIFIED. */
@@ -376,6 +379,10 @@ interface ClientConfig {
376
379
  /** Trust anchor (Root CA) — validator-д. Production-д ЗААВАЛ. */
377
380
  trust?: TrustConfig;
378
381
  }
382
+ /** RP-API-ийн албан ёсны хост (2026-09-28-наас бүх RP, /v3-гүй). */
383
+ declare const DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
384
+ /** baseUrl-ийг шалгаж, төгсгөлийн "/"-ийг хасна. */
385
+ declare function resolveBaseUrl(baseUrl: string | undefined): string;
379
386
  declare class EidClient {
380
387
  readonly auth: AuthApi;
381
388
  readonly sign: SignApi;
@@ -447,4 +454,4 @@ declare class SessionFailedError extends EidError {
447
454
  declare class ValidationError extends EidError {
448
455
  }
449
456
 
450
- export { type AcspContext, type AcspV2Params, ApiError, AuthApi, type AuthDefaults, type AuthOptions, AuthenticationError, type CertificateLevel, type ClientConfig, type DeviceLinkSession, EidClient, EidError, type EndResult, type FlowType, ForbiddenError, type HashAlgorithm, Http, type HttpConfig, type Interaction, NetworkError, type NotificationSession, ResponseValidator, type RevocationChecker, type RevocationStatus, type RpCredentials, SessionApi, SessionFailedError, type SessionResult, type SessionState, SignApi, type SignDefaults, type SignOptions, type SignatureAlgorithm, type SignatureAlgorithmParameters, type SignatureProtocol, type TrustConfig, ValidationError, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, interactionsToBase64, parseSessionResult, randomChallenge, sha256Base64, verifyPayloadSignature, verifyPrehashedSignature };
457
+ export { type AcspContext, type AcspV2Params, ApiError, AuthApi, type AuthDefaults, type AuthOptions, AuthenticationError, type CertificateLevel, type ClientConfig, DEFAULT_BASE_URL, type DeviceLinkSession, EidClient, EidError, type EndResult, type FlowType, ForbiddenError, type HashAlgorithm, Http, type HttpConfig, type Interaction, NetworkError, type NotificationSession, ResponseValidator, type RevocationChecker, type RevocationStatus, type RpCredentials, SessionApi, SessionFailedError, type SessionResult, type SessionState, SignApi, type SignDefaults, type SignOptions, type SignatureAlgorithm, type SignatureAlgorithmParameters, type SignatureProtocol, type TrustConfig, ValidationError, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, interactionsToBase64, parseSessionResult, randomChallenge, resolveBaseUrl, sha256Base64, verifyPayloadSignature, verifyPrehashedSignature };
package/dist/index.js CHANGED
@@ -645,15 +645,31 @@ function isCa(cert) {
645
645
  }
646
646
 
647
647
  // src/client.ts
648
+ var DEFAULT_BASE_URL = "https://rp.eidmongolia.mn";
649
+ var LEGACY_HOSTS = /* @__PURE__ */ new Set(["ca.eidmongolia.mn", "e-id.mn", "www.e-id.mn"]);
650
+ function resolveBaseUrl(baseUrl) {
651
+ const raw = (baseUrl ?? DEFAULT_BASE_URL).trim().replace(/\/+$/, "");
652
+ let u;
653
+ try {
654
+ u = new URL(raw);
655
+ } catch {
656
+ throw new Error(`EidClient: baseUrl \u0431\u0443\u0440\u0443\u0443 URL: ${raw}`);
657
+ }
658
+ if (LEGACY_HOSTS.has(u.hostname) && (u.pathname === "" || u.pathname === "/")) {
659
+ throw new Error(
660
+ `EidClient: RP-API ${u.hostname}-\u0430\u0430\u0441 ${DEFAULT_BASE_URL} \u0440\u0443\u0443 \u0448\u0438\u043B\u0436\u0441\u044D\u043D (/v3-\u0433\u04AF\u0439) \u2014 baseUrl-\u0438\u0439\u0433 ${DEFAULT_BASE_URL} \u0431\u043E\u043B\u0433\u043E\u043D\u043E \u0443\u0443 (\u044D\u0441\u0432\u044D\u043B \u0445\u043E\u043E\u0441\u043E\u043D \u043E\u0440\u0445\u0438).`
661
+ );
662
+ }
663
+ return raw;
664
+ }
648
665
  var EidClient = class {
649
666
  auth;
650
667
  sign;
651
668
  session;
652
669
  validator;
653
670
  constructor(cfg) {
654
- if (!cfg.baseUrl) throw new Error("EidClient: baseUrl \u0448\u0430\u0430\u0440\u0434\u043B\u0430\u0433\u0430\u0442\u0430\u0439");
655
671
  if (!cfg.credentials?.apiSecret) throw new Error("EidClient: credentials.apiSecret \u0448\u0430\u0430\u0440\u0434\u043B\u0430\u0433\u0430\u0442\u0430\u0439");
656
- const base = cfg.baseUrl.replace(/\/+$/, "") + "/v3";
672
+ const base = resolveBaseUrl(cfg.baseUrl);
657
673
  const http = new Http({
658
674
  baseUrl: base,
659
675
  apiSecret: cfg.credentials.apiSecret,
@@ -672,6 +688,7 @@ export {
672
688
  ApiError,
673
689
  AuthApi,
674
690
  AuthenticationError,
691
+ DEFAULT_BASE_URL,
675
692
  EidClient,
676
693
  EidError,
677
694
  ForbiddenError,
@@ -687,6 +704,7 @@ export {
687
704
  interactionsToBase64,
688
705
  parseSessionResult,
689
706
  randomChallenge,
707
+ resolveBaseUrl,
690
708
  sha256Base64,
691
709
  verifyPayloadSignature,
692
710
  verifyPrehashedSignature
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gerege-systems/eid-mongolia-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "e-ID Mongolia Relying Party SDK — иргэнээр утсаар нь нэвтрэлт ба хууль ёсны цахим гарын үсэг (RP-API v3, Smart-ID нийцтэй).",
5
5
  "license": "MIT",
6
6
  "type": "module",