@openeudi/openid4vp 0.2.1 → 0.4.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/index.d.ts CHANGED
@@ -1,3 +1,36 @@
1
+ import { DcqlQuery, TrustedAuthoritiesQuery, DcqlMatchResult, DcqlSubmission } from '@openeudi/dcql';
2
+ export { DcqlMatchError, DcqlMatchResult, DcqlQuery, DcqlSubmission, DcqlValidationError, DcqlValidationErrorCode } from '@openeudi/dcql';
3
+
4
+ interface AuthorizationRequestInput {
5
+ clientId: string;
6
+ responseUri: string;
7
+ nonce: string;
8
+ state?: string;
9
+ responseMode?: 'direct_post' | 'direct_post.jwt';
10
+ }
11
+ interface AuthorizationRequest {
12
+ uri: string;
13
+ dcqlQuery: DcqlQuery;
14
+ nonce: string;
15
+ state: string;
16
+ }
17
+
18
+ declare function createAuthorizationRequest(input: AuthorizationRequestInput, query: DcqlQuery): AuthorizationRequest;
19
+
20
+ interface HaipQueryInput {
21
+ credentialId: string;
22
+ format: 'dc+sd-jwt' | 'mso_mdoc';
23
+ vctValues?: string[];
24
+ doctypeValue?: string;
25
+ claims: string[];
26
+ trustedAuthorities?: TrustedAuthoritiesQuery[];
27
+ }
28
+
29
+ declare const HAIP_DOCTYPE_NAMESPACES: Record<string, string>;
30
+ declare function buildHaipQuery(input: HaipQueryInput): DcqlQuery;
31
+ declare function validateHaipQuery(query: DcqlQuery): void;
32
+ declare function isHaipQuery(query: DcqlQuery): boolean;
33
+
1
34
  interface IssuerInfo {
2
35
  certificate: Uint8Array;
3
36
  country: string;
@@ -20,21 +53,15 @@ interface PresentationResult {
20
53
  claims: CredentialClaims;
21
54
  issuer: IssuerInfo;
22
55
  error?: string;
23
- }
24
-
25
- interface AuthorizationRequestInput {
26
- requestedAttributes: string[];
27
- acceptedFormats: CredentialFormat[];
28
- responseUri: string;
29
- nonce: string;
30
- clientId: string;
31
- state?: string;
32
- }
33
- interface AuthorizationRequest {
34
- uri: string;
35
- presentationDefinition: object;
36
- nonce: string;
37
- state: string;
56
+ /** SD-JWT type (Verifiable Credential Type URI). Populated for `sd-jwt-vc` format. */
57
+ vct?: string;
58
+ /** mDOC docType (ISO 18013-5). Populated for `mdoc` format. */
59
+ docType?: string;
60
+ /**
61
+ * mDOC claims grouped by namespace. Populated for `mdoc` format.
62
+ * DCQL claim paths address this shape: `['org.iso.18013.5.1', 'age_over_18']`.
63
+ */
64
+ namespacedClaims?: Record<string, Record<string, unknown>>;
38
65
  }
39
66
 
40
67
  interface ParseOptions {
@@ -51,6 +78,13 @@ interface ParseOptions {
51
78
  * where no trusted issuer set is available.
52
79
  */
53
80
  skipTrustCheck?: boolean;
81
+ /**
82
+ * When set, the parsed credential's `docType` (mDOC) or `vct` (SD-JWT)
83
+ * must equal this value — otherwise parsing throws `MalformedCredentialError`.
84
+ * Defends against doc-type confusion attacks when the verifier expects a
85
+ * specific credential class (e.g. `'eu.europa.ec.eudi.pid.1'`).
86
+ */
87
+ expectedDocType?: string;
54
88
  }
55
89
  interface ICredentialParser {
56
90
  readonly format: CredentialFormat;
@@ -58,6 +92,29 @@ interface ICredentialParser {
58
92
  parse(vpToken: unknown, options: ParseOptions): Promise<PresentationResult>;
59
93
  }
60
94
 
95
+ declare function parsePresentation(vpToken: unknown, options: ParseOptions): Promise<PresentationResult>;
96
+
97
+ type VerifyOptions = ParseOptions;
98
+ interface VerifyResult {
99
+ parsed: PresentationResult;
100
+ match: DcqlMatchResult;
101
+ submission: DcqlSubmission | null;
102
+ valid: boolean;
103
+ }
104
+
105
+ /**
106
+ * Parses a VP token, then matches it against a DCQL query.
107
+ *
108
+ * Cryptographic / structural parser failures still throw (via `parsePresentation`).
109
+ * Query-level mismatches are surfaced as `match.unmatched` entries so callers can
110
+ * show per-claim diagnostics.
111
+ *
112
+ * @param vpToken raw VP token (SD-JWT string or mDOC Uint8Array)
113
+ * @param query DCQL query describing the required credential(s)
114
+ * @param options parse + verify options (nonce, trusted issuers, etc.)
115
+ */
116
+ declare function verifyPresentation(vpToken: unknown, query: DcqlQuery, options: VerifyOptions): Promise<VerifyResult>;
117
+
61
118
  /**
62
119
  * SD-JWT VC credential parser.
63
120
  *
@@ -78,18 +135,19 @@ declare class SdJwtParser implements ICredentialParser {
78
135
  * mDOC / mDL credential parser.
79
136
  *
80
137
  * Decodes and validates mDOC (Mobile Document) credentials as specified in
81
- * ISO 18013-5 and the EUDI Wallet ecosystem. Processes CBOR-encoded
82
- * DeviceResponse structures containing:
83
- * - Document type validation (eu.europa.ec.eudi.pid.1)
84
- * - Issuer certificate trust chain verification via COSE_Sign1 issuerAuth
85
- * - Validity period checking
86
- * - Claim extraction from IssuerSignedItem nameSpace elements
138
+ * ISO 18013-5 and the EUDI Wallet ecosystem. Composes the crypto modules
139
+ * to perform full verification:
140
+ * - COSE_Sign1 decode + signature verification
141
+ * - MSO decode + validity + docType validation
142
+ * - Digest verification for all IssuerSignedItems
143
+ * - Issuer certificate trust chain check
87
144
  */
88
145
  declare class MdocParser implements ICredentialParser {
89
146
  readonly format: CredentialFormat;
90
147
  /**
91
148
  * Returns true when the token is binary data (Uint8Array or Buffer),
92
149
  * indicating a CBOR-encoded mDOC DeviceResponse.
150
+ * Buffer extends Uint8Array, so `instanceof Uint8Array` catches both.
93
151
  */
94
152
  canParse(vpToken: unknown): boolean;
95
153
  /**
@@ -116,11 +174,13 @@ declare class MalformedCredentialError extends Error {
116
174
  declare class NonceValidationError extends Error {
117
175
  constructor(message?: string);
118
176
  }
177
+ type HaipValidationCode = 'EMPTY_QUERY' | 'UNSUPPORTED_FORMAT' | 'MISSING_SDJWT_META' | 'MISSING_MDOC_META' | 'NO_CLAIMS' | 'CLAIM_SETS_DISALLOWED' | 'CREDENTIAL_SETS_DISALLOWED';
178
+ declare class HaipValidationError extends Error {
179
+ readonly code: HaipValidationCode;
180
+ readonly credentialId?: string;
181
+ constructor(code: HaipValidationCode, message: string, credentialId?: string);
182
+ }
119
183
 
120
- declare function createAuthorizationRequest(input: AuthorizationRequestInput): AuthorizationRequest;
121
-
122
- declare function parsePresentation(vpToken: unknown, options: ParseOptions): Promise<PresentationResult>;
123
-
124
- declare const VERSION = "0.2.1";
184
+ declare const VERSION = "0.4.0";
125
185
 
126
- export { type AuthorizationRequest, type AuthorizationRequestInput, type CredentialClaims, type CredentialFormat, ExpiredCredentialError, type ICredentialParser, InvalidSignatureError, type IssuerInfo, MalformedCredentialError, MdocParser, NonceValidationError, type ParseOptions, type PresentationResult, SdJwtParser, UnsupportedFormatError, VERSION, createAuthorizationRequest, parsePresentation };
186
+ export { type AuthorizationRequest, type AuthorizationRequestInput, type CredentialClaims, type CredentialFormat, ExpiredCredentialError, HAIP_DOCTYPE_NAMESPACES, type HaipQueryInput, type HaipValidationCode, HaipValidationError, type ICredentialParser, InvalidSignatureError, type IssuerInfo, MalformedCredentialError, MdocParser, NonceValidationError, type ParseOptions, type PresentationResult, SdJwtParser, UnsupportedFormatError, VERSION, type VerifyOptions, type VerifyResult, buildHaipQuery, createAuthorizationRequest, isHaipQuery, parsePresentation, validateHaipQuery, verifyPresentation };