@gerege-systems/eid-mongolia-sdk 0.9.0 → 0.9.1
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 +13 -2
- package/dist/index.cjs +6 -2
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -182,6 +182,16 @@ const sig = eid.validator.validateSign(result, digest); // digest-ийн эср
|
|
|
182
182
|
console.log(sig.signatureValueB64, sig.subject);
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
+
Device-link / push-оор эхлүүлсэн sign session-д эхлүүлсэн урсгалаа `expectedFlowType`-оор тулга (`validateAuth`-тай
|
|
186
|
+
ижил: зөрвөл `ValidationError`). Гуравдах параметр нь `hashAlgorithm` мөр (хуучин хэлбэр) эсвэл объект:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
eid.validator.validateSign(result, digest, { expectedFlowType: "QR" }); // эсвэл "Web2App" / "App2App" / "Notification"
|
|
190
|
+
eid.validator.validateSign(result, digest384, { hashAlgorithm: "SHA-384", expectedFlowType: "Web2App" });
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
RAW_DIGEST_SIGNATURE-д `flowType` гарын үсэгт ордоггүй (зөвхөн digest зурагдана) — энэ нь RP-API хариуны тулгалт.
|
|
194
|
+
|
|
185
195
|
## 3a. Байгууллагын нэрийн өмнөөс гарын үсэг (onBehalfOf)
|
|
186
196
|
|
|
187
197
|
Иргэн **өөрийн PIN2 гэрчилгээгээр** зурна; тухайн мөчид байгууллагыг төлөөлөх эрхтэйг eID **өөрийн бүртгэлээр**
|
|
@@ -224,7 +234,8 @@ try {
|
|
|
224
234
|
```
|
|
225
235
|
|
|
226
236
|
`prepare`-ийн хариу `digest` (DTBS, base64) — иргэний зурах 32 байт, push ба device-link хоёуланд (хуучин CA push-д
|
|
227
|
-
`undefined`). Иргэний гарын үсгийг өөрөө шалгах бол: `eid.validator.validateSign(r, s.digest
|
|
237
|
+
`undefined`). Иргэний гарын үсгийг өөрөө шалгах бол: `eid.validator.validateSign(r, s.digest!, { expectedFlowType: "QR" })`
|
|
238
|
+
(харуулсан урсгалаа). Гарын үсэгтэй PDF-ийг
|
|
228
239
|
`pdf.document()`-ийн оронд `pdf.documentVerified(sessionId, r.pdf)`-аар тат — `READY` + `outSha256` тулгалтыг хийнэ.
|
|
229
240
|
|
|
230
241
|
Олон талт гэрээ: А байгууллагын гаралтыг өөрчлөлтгүй Б-ийн `prepare`-д (`docID`, өөр `onBehalfOf`) илгээнэ.
|
|
@@ -327,7 +338,7 @@ OK ирж болзошгүй. Иймд `ResponseValidator`:
|
|
|
327
338
|
`initialCallbackUrl`-ийг хариуны `signature.initialCallbackUrl`-аас авна (CA урсгалаар шийднэ: QR/Notification →
|
|
328
339
|
`""`, Web2App/App2App → таны callback) — зөвхөн `""` эсвэл
|
|
329
340
|
таны илгээсэн callback байхад, Web2App/App2App-д заавал таны callback; өөр утга → татгалзана
|
|
330
|
-
- **sign** → RP-ийн өгсөн digest
|
|
341
|
+
- **sign** → RP-ийн өгсөн digest дээр; `expectedFlowType` өгвөл хариуны `flowType` ЯГ таарах (гарын үсэгт ордоггүй — хариуны тулгалт)
|
|
331
342
|
- алгоритм нь гэрчилгээний түлхүүртэй уях: `ecdsa-with-SHA256` зөвхөн EC P-256 түлхүүрт, RSA алгоритмууд зөвхөн
|
|
332
343
|
RSA түлхүүрт (alg confusion хаалт). Hash нь үргэлж хүссэнтэй ЯГ тэнцүү. RP-API session-ий гарын үсэг CA дээр
|
|
333
344
|
SplitKey RSA (одоогийн бүх мобайл гэрчилгээ) эсвэл legacy threshold ECDSA P-256-аас гарна; ECDSA credential
|
package/dist/index.cjs
CHANGED
|
@@ -748,10 +748,14 @@ var ResponseValidator = class {
|
|
|
748
748
|
}
|
|
749
749
|
/**
|
|
750
750
|
* Sign session-ийн хариуг бүрэн шалгаж, баталгаажсан гарын үсгийг буцаана.
|
|
751
|
-
* @param
|
|
751
|
+
* @param opts — `hashAlgorithm` мөр (хуучин хэлбэр; default SHA-256) эсвэл {@link ValidateSignOptions}.
|
|
752
752
|
*/
|
|
753
|
-
validateSign(result, digestB64,
|
|
753
|
+
validateSign(result, digestB64, opts = {}) {
|
|
754
|
+
const { hashAlgorithm = "SHA-256", expectedFlowType } = typeof opts === "string" ? { hashAlgorithm: opts } : opts;
|
|
754
755
|
const leaf = this.precheck(result, "RAW_DIGEST_SIGNATURE");
|
|
756
|
+
if (expectedFlowType && result.flowType !== expectedFlowType) {
|
|
757
|
+
throw new ValidationError(`flowType ${result.flowType} \u2260 \u044D\u0445\u043B\u04AF\u04AF\u043B\u0441\u044D\u043D \u0443\u0440\u0441\u0433\u0430\u043B ${expectedFlowType} (relay \u0431\u0430\u0439\u0436 \u0431\u043E\u043B\u0437\u043E\u0448\u0433\u04AF\u0439)`);
|
|
758
|
+
}
|
|
755
759
|
const digest = Buffer.from(digestB64, "base64");
|
|
756
760
|
const { alg, hash } = this.algorithmOf(result, leaf, null, hashAlgorithm);
|
|
757
761
|
if (digest.length !== hashLen(hash)) throw new ValidationError("digest \u0443\u0440\u0442 hashAlgorithm-\u0442\u0430\u0439 \u0442\u0430\u0430\u0440\u0430\u0445\u0433\u04AF\u0439");
|
package/dist/index.d.cts
CHANGED
|
@@ -271,6 +271,20 @@ interface ValidateAuthOptions {
|
|
|
271
271
|
*/
|
|
272
272
|
userChallengeVerifier?: string;
|
|
273
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* validateSign-ийн нэмэлт шалгалт. Гуравдах параметрт мөр (`hashAlgorithm`) эсвэл энэ объектыг өгнө.
|
|
276
|
+
*/
|
|
277
|
+
interface ValidateSignOptions {
|
|
278
|
+
/** digest-ийг үүсгэсэн hash (хүсэлтэд илгээсэнтэй ижил; default SHA-256). */
|
|
279
|
+
hashAlgorithm?: string;
|
|
280
|
+
/**
|
|
281
|
+
* RP-ийн эхлүүлсэн урсгал (device-link: "QR" / "Web2App" / "App2App"; push → "Notification"). Өгвөл хариуны
|
|
282
|
+
* `flowType` ЯГ ИЖИЛ байх ёстой, эс бөгөөс `ValidationError` — validateAuth-ийн `expectedFlowType`-тэй ижил.
|
|
283
|
+
* ⚠️ RAW_DIGEST_SIGNATURE-д `flowType` гарын үсэгт ОРДОГГҮЙ (зөвхөн digest зурагдана) — энэ нь RP-API хариуны
|
|
284
|
+
* тулгалт, криптограф баталгаа биш.
|
|
285
|
+
*/
|
|
286
|
+
expectedFlowType?: FlowType;
|
|
287
|
+
}
|
|
274
288
|
/**
|
|
275
289
|
* RevocationChecker — иргэний cert revoke хийгдсэн эсэхийг шалгах hook (OCSP/CRL).
|
|
276
290
|
* Сүлжээний I/O шаардсан тул async. RP нь cert доторх AIA (OCSP) / CDP (CRL) URL-аар
|
|
@@ -344,9 +358,9 @@ declare class ResponseValidator {
|
|
|
344
358
|
validateAuth(result: SessionResult, acsp: AcspContext, opts?: ValidateAuthOptions): VerifiedIdentity;
|
|
345
359
|
/**
|
|
346
360
|
* Sign session-ийн хариуг бүрэн шалгаж, баталгаажсан гарын үсгийг буцаана.
|
|
347
|
-
* @param
|
|
361
|
+
* @param opts — `hashAlgorithm` мөр (хуучин хэлбэр; default SHA-256) эсвэл {@link ValidateSignOptions}.
|
|
348
362
|
*/
|
|
349
|
-
validateSign(result: SessionResult, digestB64: string,
|
|
363
|
+
validateSign(result: SessionResult, digestB64: string, opts?: string | ValidateSignOptions): VerifiedSignature;
|
|
350
364
|
/**
|
|
351
365
|
* Хариуны signatureAlgorithm + hashAlgorithm-ийг RP-ийн хүссэнтэй ба иргэний түлхүүрийн төрөлтэй тулгана
|
|
352
366
|
* (downgrade / alg confusion хаалт).
|
|
@@ -649,4 +663,4 @@ declare class EidOidcClient {
|
|
|
649
663
|
/** PKCE S256: `BASE64URL(SHA-256(ASCII(code_verifier)))` (RFC 7636 §4.2). */
|
|
650
664
|
declare function pkceChallenge(codeVerifier: string): Promise<string>;
|
|
651
665
|
|
|
652
|
-
export { AcspContext, type AcspV2Params, AuthApi, type AuthDefaults, type AuthOptions, type BuildDeviceLinkInput, type CertSubject, CertificateLevel, type ClientConfig, type CreateAuthorizationOptions, DEFAULT_BASE_URL, DeviceLinkSession, type DeviceLinkSessionType, type DeviceLinkType, EID_ACR_ADVANCED, EID_ACR_QUALIFIED, EID_OIDC_ISSUER, type EidAuthorization, type EidCallbackChecks, type EidCallbackResult, EidClient, EidError, type EidIdTokenClaims, EidOidcClient, type EidOidcClientConfig, type EidOidcDiscovery, EidOidcError, type EidOidcErrorCode, FlowType, HashAlgorithm, Http, type HttpConfig, Interaction, NotificationSession, OrganizationApi, PdfApi, type PdfDefaults, type PdfPrepareInput, type PdfPrepareSession, PdfSessionBlock, type PdfSignerRef, type QrDeviceLinkTickerOptions, RepresentationsResponse, ResponseValidator, type RevocationChecker, type RevocationStatus, RpCredentials, SessionApi, SessionResult, SignApi, type SignDefaults, type SignOptions, SignatureAlgorithm, type TrustConfig, type ValidateAuthOptions, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, buildDeviceLink, interactionsToBase64, parseSessionResult, parseSubject, pkceChallenge, qrDeviceLinkTicker, randomChallenge, resolveBaseUrl, sha256Base64, userChallengeOf, verifyPayloadSignature, verifyPrehashedSignature };
|
|
666
|
+
export { AcspContext, type AcspV2Params, AuthApi, type AuthDefaults, type AuthOptions, type BuildDeviceLinkInput, type CertSubject, CertificateLevel, type ClientConfig, type CreateAuthorizationOptions, DEFAULT_BASE_URL, DeviceLinkSession, type DeviceLinkSessionType, type DeviceLinkType, EID_ACR_ADVANCED, EID_ACR_QUALIFIED, EID_OIDC_ISSUER, type EidAuthorization, type EidCallbackChecks, type EidCallbackResult, EidClient, EidError, type EidIdTokenClaims, EidOidcClient, type EidOidcClientConfig, type EidOidcDiscovery, EidOidcError, type EidOidcErrorCode, FlowType, HashAlgorithm, Http, type HttpConfig, Interaction, NotificationSession, OrganizationApi, PdfApi, type PdfDefaults, type PdfPrepareInput, type PdfPrepareSession, PdfSessionBlock, type PdfSignerRef, type QrDeviceLinkTickerOptions, RepresentationsResponse, ResponseValidator, type RevocationChecker, type RevocationStatus, RpCredentials, SessionApi, SessionResult, SignApi, type SignDefaults, type SignOptions, SignatureAlgorithm, type TrustConfig, type ValidateAuthOptions, type ValidateSignOptions, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, buildDeviceLink, interactionsToBase64, parseSessionResult, parseSubject, pkceChallenge, qrDeviceLinkTicker, randomChallenge, resolveBaseUrl, sha256Base64, userChallengeOf, verifyPayloadSignature, verifyPrehashedSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -271,6 +271,20 @@ interface ValidateAuthOptions {
|
|
|
271
271
|
*/
|
|
272
272
|
userChallengeVerifier?: string;
|
|
273
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* validateSign-ийн нэмэлт шалгалт. Гуравдах параметрт мөр (`hashAlgorithm`) эсвэл энэ объектыг өгнө.
|
|
276
|
+
*/
|
|
277
|
+
interface ValidateSignOptions {
|
|
278
|
+
/** digest-ийг үүсгэсэн hash (хүсэлтэд илгээсэнтэй ижил; default SHA-256). */
|
|
279
|
+
hashAlgorithm?: string;
|
|
280
|
+
/**
|
|
281
|
+
* RP-ийн эхлүүлсэн урсгал (device-link: "QR" / "Web2App" / "App2App"; push → "Notification"). Өгвөл хариуны
|
|
282
|
+
* `flowType` ЯГ ИЖИЛ байх ёстой, эс бөгөөс `ValidationError` — validateAuth-ийн `expectedFlowType`-тэй ижил.
|
|
283
|
+
* ⚠️ RAW_DIGEST_SIGNATURE-д `flowType` гарын үсэгт ОРДОГГҮЙ (зөвхөн digest зурагдана) — энэ нь RP-API хариуны
|
|
284
|
+
* тулгалт, криптограф баталгаа биш.
|
|
285
|
+
*/
|
|
286
|
+
expectedFlowType?: FlowType;
|
|
287
|
+
}
|
|
274
288
|
/**
|
|
275
289
|
* RevocationChecker — иргэний cert revoke хийгдсэн эсэхийг шалгах hook (OCSP/CRL).
|
|
276
290
|
* Сүлжээний I/O шаардсан тул async. RP нь cert доторх AIA (OCSP) / CDP (CRL) URL-аар
|
|
@@ -344,9 +358,9 @@ declare class ResponseValidator {
|
|
|
344
358
|
validateAuth(result: SessionResult, acsp: AcspContext, opts?: ValidateAuthOptions): VerifiedIdentity;
|
|
345
359
|
/**
|
|
346
360
|
* Sign session-ийн хариуг бүрэн шалгаж, баталгаажсан гарын үсгийг буцаана.
|
|
347
|
-
* @param
|
|
361
|
+
* @param opts — `hashAlgorithm` мөр (хуучин хэлбэр; default SHA-256) эсвэл {@link ValidateSignOptions}.
|
|
348
362
|
*/
|
|
349
|
-
validateSign(result: SessionResult, digestB64: string,
|
|
363
|
+
validateSign(result: SessionResult, digestB64: string, opts?: string | ValidateSignOptions): VerifiedSignature;
|
|
350
364
|
/**
|
|
351
365
|
* Хариуны signatureAlgorithm + hashAlgorithm-ийг RP-ийн хүссэнтэй ба иргэний түлхүүрийн төрөлтэй тулгана
|
|
352
366
|
* (downgrade / alg confusion хаалт).
|
|
@@ -649,4 +663,4 @@ declare class EidOidcClient {
|
|
|
649
663
|
/** PKCE S256: `BASE64URL(SHA-256(ASCII(code_verifier)))` (RFC 7636 §4.2). */
|
|
650
664
|
declare function pkceChallenge(codeVerifier: string): Promise<string>;
|
|
651
665
|
|
|
652
|
-
export { AcspContext, type AcspV2Params, AuthApi, type AuthDefaults, type AuthOptions, type BuildDeviceLinkInput, type CertSubject, CertificateLevel, type ClientConfig, type CreateAuthorizationOptions, DEFAULT_BASE_URL, DeviceLinkSession, type DeviceLinkSessionType, type DeviceLinkType, EID_ACR_ADVANCED, EID_ACR_QUALIFIED, EID_OIDC_ISSUER, type EidAuthorization, type EidCallbackChecks, type EidCallbackResult, EidClient, EidError, type EidIdTokenClaims, EidOidcClient, type EidOidcClientConfig, type EidOidcDiscovery, EidOidcError, type EidOidcErrorCode, FlowType, HashAlgorithm, Http, type HttpConfig, Interaction, NotificationSession, OrganizationApi, PdfApi, type PdfDefaults, type PdfPrepareInput, type PdfPrepareSession, PdfSessionBlock, type PdfSignerRef, type QrDeviceLinkTickerOptions, RepresentationsResponse, ResponseValidator, type RevocationChecker, type RevocationStatus, RpCredentials, SessionApi, SessionResult, SignApi, type SignDefaults, type SignOptions, SignatureAlgorithm, type TrustConfig, type ValidateAuthOptions, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, buildDeviceLink, interactionsToBase64, parseSessionResult, parseSubject, pkceChallenge, qrDeviceLinkTicker, randomChallenge, resolveBaseUrl, sha256Base64, userChallengeOf, verifyPayloadSignature, verifyPrehashedSignature };
|
|
666
|
+
export { AcspContext, type AcspV2Params, AuthApi, type AuthDefaults, type AuthOptions, type BuildDeviceLinkInput, type CertSubject, CertificateLevel, type ClientConfig, type CreateAuthorizationOptions, DEFAULT_BASE_URL, DeviceLinkSession, type DeviceLinkSessionType, type DeviceLinkType, EID_ACR_ADVANCED, EID_ACR_QUALIFIED, EID_OIDC_ISSUER, type EidAuthorization, type EidCallbackChecks, type EidCallbackResult, EidClient, EidError, type EidIdTokenClaims, EidOidcClient, type EidOidcClientConfig, type EidOidcDiscovery, EidOidcError, type EidOidcErrorCode, FlowType, HashAlgorithm, Http, type HttpConfig, Interaction, NotificationSession, OrganizationApi, PdfApi, type PdfDefaults, type PdfPrepareInput, type PdfPrepareSession, PdfSessionBlock, type PdfSignerRef, type QrDeviceLinkTickerOptions, RepresentationsResponse, ResponseValidator, type RevocationChecker, type RevocationStatus, RpCredentials, SessionApi, SessionResult, SignApi, type SignDefaults, type SignOptions, SignatureAlgorithm, type TrustConfig, type ValidateAuthOptions, type ValidateSignOptions, type VerifiedIdentity, type VerifiedSignature, acspV2Digest, buildAcspV2Payload, buildDeviceLink, interactionsToBase64, parseSessionResult, parseSubject, pkceChallenge, qrDeviceLinkTicker, randomChallenge, resolveBaseUrl, sha256Base64, userChallengeOf, verifyPayloadSignature, verifyPrehashedSignature };
|
package/dist/index.js
CHANGED
|
@@ -648,10 +648,14 @@ var ResponseValidator = class {
|
|
|
648
648
|
}
|
|
649
649
|
/**
|
|
650
650
|
* Sign session-ийн хариуг бүрэн шалгаж, баталгаажсан гарын үсгийг буцаана.
|
|
651
|
-
* @param
|
|
651
|
+
* @param opts — `hashAlgorithm` мөр (хуучин хэлбэр; default SHA-256) эсвэл {@link ValidateSignOptions}.
|
|
652
652
|
*/
|
|
653
|
-
validateSign(result, digestB64,
|
|
653
|
+
validateSign(result, digestB64, opts = {}) {
|
|
654
|
+
const { hashAlgorithm = "SHA-256", expectedFlowType } = typeof opts === "string" ? { hashAlgorithm: opts } : opts;
|
|
654
655
|
const leaf = this.precheck(result, "RAW_DIGEST_SIGNATURE");
|
|
656
|
+
if (expectedFlowType && result.flowType !== expectedFlowType) {
|
|
657
|
+
throw new ValidationError(`flowType ${result.flowType} \u2260 \u044D\u0445\u043B\u04AF\u04AF\u043B\u0441\u044D\u043D \u0443\u0440\u0441\u0433\u0430\u043B ${expectedFlowType} (relay \u0431\u0430\u0439\u0436 \u0431\u043E\u043B\u0437\u043E\u0448\u0433\u04AF\u0439)`);
|
|
658
|
+
}
|
|
655
659
|
const digest = Buffer.from(digestB64, "base64");
|
|
656
660
|
const { alg, hash } = this.algorithmOf(result, leaf, null, hashAlgorithm);
|
|
657
661
|
if (digest.length !== hashLen(hash)) throw new ValidationError("digest \u0443\u0440\u0442 hashAlgorithm-\u0442\u0430\u0439 \u0442\u0430\u0430\u0440\u0430\u0445\u0433\u04AF\u0439");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gerege-systems/eid-mongolia-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "e-ID Mongolia Relying Party SDK — иргэнээр утсаар нь нэвтрэлт ба хууль ёсны цахим гарын үсэг (RP-API v3, Smart-ID нийцтэй).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|