@gerege-systems/eid-mongolia-sdk 0.1.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 +2 -2
- package/dist/index.cjs +22 -2
- package/dist/index.d.cts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +20 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,10 +26,10 @@ 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
|
|
29
|
+
// baseUrl анхдагч https://rp.eidmongolia.mn (RP-API, /v3-гүй) — mTLS-тэй RP ч мөн энэ хост
|
|
30
30
|
credentials: {
|
|
31
31
|
rpUUID: process.env.EID_RP_UUID!,
|
|
32
|
-
rpName: "
|
|
32
|
+
rpName: "Интернэт банк", // дэд системийн нэр, ≤120 тэмдэгт
|
|
33
33
|
apiSecret: process.env.EID_SECRET!, // rp_sk_…
|
|
34
34
|
},
|
|
35
35
|
trust: { trustAnchorsPem: [process.env.EID_NATIONAL_ROOT_CA_PEM!] }, // ← Mongolian National Root CA, production-д ЗААВАЛ
|
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
|
|
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
|
|
4
|
+
/** RP-API-ийн бүтэн суурь URL. Ж: https://rp.eidmongolia.mn */
|
|
5
5
|
baseUrl: string;
|
|
6
6
|
/** API secret (rp_sk_…) — Authorization: Bearer-д орно. */
|
|
7
7
|
apiSecret: string;
|
|
@@ -148,7 +148,10 @@ interface OrgResult {
|
|
|
148
148
|
interface RpCredentials {
|
|
149
149
|
/** relying_parties-д бүртгэлтэй RP UUID. */
|
|
150
150
|
rpUUID: string;
|
|
151
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Дэд системийн нэр (ж: «Интернэт банк») — CA-д session бүрд хадгалагдана, ≤120 тэмдэгт
|
|
153
|
+
* (сервер илүүг таслана). Иргэний утсан дээр харагдах нэр нь RP-ийн бүртгэлийн нэр.
|
|
154
|
+
*/
|
|
152
155
|
rpName: string;
|
|
153
156
|
/** API secret (rp_sk_…). Зөвхөн backend-д хадгална — браузерт ХЭЗЭЭ Ч задлахгүй. */
|
|
154
157
|
apiSecret: string;
|
|
@@ -358,8 +361,11 @@ declare function verifyPayloadSignature(payload: Buffer, sigB64: string, key: Ke
|
|
|
358
361
|
declare function verifyPrehashedSignature(digest: Buffer, sigB64: string, key: KeyObject, alg: string, hash: string): boolean;
|
|
359
362
|
|
|
360
363
|
interface ClientConfig {
|
|
361
|
-
/**
|
|
362
|
-
|
|
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;
|
|
363
369
|
/** RP таних мэдээлэл + API secret. */
|
|
364
370
|
credentials: RpCredentials;
|
|
365
371
|
/** Default certLevel (auth/sign бүрд). Default QUALIFIED. */
|
|
@@ -373,6 +379,10 @@ interface ClientConfig {
|
|
|
373
379
|
/** Trust anchor (Root CA) — validator-д. Production-д ЗААВАЛ. */
|
|
374
380
|
trust?: TrustConfig;
|
|
375
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;
|
|
376
386
|
declare class EidClient {
|
|
377
387
|
readonly auth: AuthApi;
|
|
378
388
|
readonly sign: SignApi;
|
|
@@ -444,4 +454,4 @@ declare class SessionFailedError extends EidError {
|
|
|
444
454
|
declare class ValidationError extends EidError {
|
|
445
455
|
}
|
|
446
456
|
|
|
447
|
-
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
|
|
4
|
+
/** RP-API-ийн бүтэн суурь URL. Ж: https://rp.eidmongolia.mn */
|
|
5
5
|
baseUrl: string;
|
|
6
6
|
/** API secret (rp_sk_…) — Authorization: Bearer-д орно. */
|
|
7
7
|
apiSecret: string;
|
|
@@ -148,7 +148,10 @@ interface OrgResult {
|
|
|
148
148
|
interface RpCredentials {
|
|
149
149
|
/** relying_parties-д бүртгэлтэй RP UUID. */
|
|
150
150
|
rpUUID: string;
|
|
151
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Дэд системийн нэр (ж: «Интернэт банк») — CA-д session бүрд хадгалагдана, ≤120 тэмдэгт
|
|
153
|
+
* (сервер илүүг таслана). Иргэний утсан дээр харагдах нэр нь RP-ийн бүртгэлийн нэр.
|
|
154
|
+
*/
|
|
152
155
|
rpName: string;
|
|
153
156
|
/** API secret (rp_sk_…). Зөвхөн backend-д хадгална — браузерт ХЭЗЭЭ Ч задлахгүй. */
|
|
154
157
|
apiSecret: string;
|
|
@@ -358,8 +361,11 @@ declare function verifyPayloadSignature(payload: Buffer, sigB64: string, key: Ke
|
|
|
358
361
|
declare function verifyPrehashedSignature(digest: Buffer, sigB64: string, key: KeyObject, alg: string, hash: string): boolean;
|
|
359
362
|
|
|
360
363
|
interface ClientConfig {
|
|
361
|
-
/**
|
|
362
|
-
|
|
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;
|
|
363
369
|
/** RP таних мэдээлэл + API secret. */
|
|
364
370
|
credentials: RpCredentials;
|
|
365
371
|
/** Default certLevel (auth/sign бүрд). Default QUALIFIED. */
|
|
@@ -373,6 +379,10 @@ interface ClientConfig {
|
|
|
373
379
|
/** Trust anchor (Root CA) — validator-д. Production-д ЗААВАЛ. */
|
|
374
380
|
trust?: TrustConfig;
|
|
375
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;
|
|
376
386
|
declare class EidClient {
|
|
377
387
|
readonly auth: AuthApi;
|
|
378
388
|
readonly sign: SignApi;
|
|
@@ -444,4 +454,4 @@ declare class SessionFailedError extends EidError {
|
|
|
444
454
|
declare class ValidationError extends EidError {
|
|
445
455
|
}
|
|
446
456
|
|
|
447
|
-
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
|
|
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.
|
|
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",
|