@sd-jwt/sd-jwt-vc 0.17.2-next.4 → 0.17.2-next.7

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.mts CHANGED
@@ -1,137 +1,276 @@
1
1
  import { SDJWTConfig, Verifier, kbPayload, kbHeader, DisclosureFrame } from '@sd-jwt/types';
2
+ import { z } from 'zod';
2
3
  import { SdJwtPayload, SDJwtInstance, VerifierOptions } from '@sd-jwt/core';
3
4
 
4
5
  /**
5
6
  * Logo metadata used in rendering a credential.
6
7
  */
7
- type Logo = {
8
- /** REQUIRED. A URI pointing to the logo image. */
9
- uri: string;
10
- /** OPTIONAL. An "integrity metadata" string as described in Section 7. */
11
- 'uri#integrity'?: string;
12
- /** OPTIONAL. A string containing alternative text for the logo image. */
13
- alt_text?: string;
14
- };
8
+ declare const LogoSchema: z.ZodObject<{
9
+ uri: z.ZodString;
10
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
11
+ alt_text: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>;
13
+ type Logo = z.infer<typeof LogoSchema>;
15
14
  /**
16
15
  * The simple rendering method is intended for applications that do not support SVG.
17
16
  */
18
- type SimpleRendering = {
19
- /** OPTIONAL. Logo metadata to display for the credential. */
20
- logo?: Logo;
21
- /** OPTIONAL. RGB color value for the credential background (e.g., "#FFFFFF"). */
22
- background_color?: string;
23
- /** OPTIONAL. RGB color value for the credential text (e.g., "#000000"). */
24
- text_color?: string;
25
- };
17
+ declare const SimpleRenderingSchema: z.ZodObject<{
18
+ logo: z.ZodOptional<z.ZodObject<{
19
+ uri: z.ZodString;
20
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
21
+ alt_text: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>>;
23
+ background_color: z.ZodOptional<z.ZodString>;
24
+ text_color: z.ZodOptional<z.ZodString>;
25
+ }, z.core.$strip>;
26
+ type SimpleRendering = z.infer<typeof SimpleRenderingSchema>;
26
27
  /** Enum of valid values for rendering orientation. */
27
- type Orientation = 'portrait' | 'landscape';
28
+ declare const OrientationSchema: z.ZodEnum<{
29
+ portrait: "portrait";
30
+ landscape: "landscape";
31
+ }>;
28
32
  /** Enum of valid values for rendering color schemes. */
29
- type ColorScheme = 'light' | 'dark';
33
+ declare const ColorSchemeSchema: z.ZodEnum<{
34
+ light: "light";
35
+ dark: "dark";
36
+ }>;
30
37
  /** Enum of valid values for rendering contrast. */
31
- type Contrast = 'normal' | 'high';
38
+ declare const ContrastSchema: z.ZodEnum<{
39
+ normal: "normal";
40
+ high: "high";
41
+ }>;
32
42
  /**
33
43
  * Properties that describe the display preferences for an SVG template rendering.
34
44
  */
35
- type SvgTemplateProperties = {
36
- /** OPTIONAL. Orientation optimized for the template. */
37
- orientation?: Orientation;
38
- /** OPTIONAL. Color scheme optimized for the template. */
39
- color_scheme?: ColorScheme;
40
- /** OPTIONAL. Contrast level optimized for the template. */
41
- contrast?: Contrast;
42
- };
45
+ declare const SvgTemplatePropertiesSchema: z.ZodObject<{
46
+ orientation: z.ZodOptional<z.ZodEnum<{
47
+ portrait: "portrait";
48
+ landscape: "landscape";
49
+ }>>;
50
+ color_scheme: z.ZodOptional<z.ZodEnum<{
51
+ light: "light";
52
+ dark: "dark";
53
+ }>>;
54
+ contrast: z.ZodOptional<z.ZodEnum<{
55
+ normal: "normal";
56
+ high: "high";
57
+ }>>;
58
+ }, z.core.$strip>;
59
+ type SvgTemplateProperties = z.infer<typeof SvgTemplatePropertiesSchema>;
43
60
  /**
44
61
  * SVG rendering metadata containing URI and optional integrity and properties.
45
62
  */
46
- type SvgTemplateRendering = {
47
- /** REQUIRED. A URI pointing to the SVG template. */
48
- uri: string;
49
- /** OPTIONAL. An "integrity metadata" string as described in Section 7. */
50
- 'uri#integrity'?: string;
51
- /** REQUIRED if more than one SVG template is present. */
52
- properties?: SvgTemplateProperties;
53
- };
63
+ declare const SvgTemplateRenderingSchema: z.ZodObject<{
64
+ uri: z.ZodString;
65
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
66
+ properties: z.ZodOptional<z.ZodObject<{
67
+ orientation: z.ZodOptional<z.ZodEnum<{
68
+ portrait: "portrait";
69
+ landscape: "landscape";
70
+ }>>;
71
+ color_scheme: z.ZodOptional<z.ZodEnum<{
72
+ light: "light";
73
+ dark: "dark";
74
+ }>>;
75
+ contrast: z.ZodOptional<z.ZodEnum<{
76
+ normal: "normal";
77
+ high: "high";
78
+ }>>;
79
+ }, z.core.$strip>>;
80
+ }, z.core.$strip>;
81
+ type SvgTemplateRendering = z.infer<typeof SvgTemplateRenderingSchema>;
54
82
  /**
55
83
  * Rendering metadata, either simple or SVG-based, for a credential.
56
84
  */
57
- type Rendering = {
58
- /** OPTIONAL. Simple rendering metadata. */
59
- simple?: SimpleRendering;
60
- /** OPTIONAL. Array of SVG template rendering objects. */
61
- svg_template?: SvgTemplateRendering[];
62
- };
85
+ declare const RenderingSchema: z.ZodObject<{
86
+ simple: z.ZodOptional<z.ZodObject<{
87
+ logo: z.ZodOptional<z.ZodObject<{
88
+ uri: z.ZodString;
89
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
90
+ alt_text: z.ZodOptional<z.ZodString>;
91
+ }, z.core.$strip>>;
92
+ background_color: z.ZodOptional<z.ZodString>;
93
+ text_color: z.ZodOptional<z.ZodString>;
94
+ }, z.core.$strip>>;
95
+ svg_template: z.ZodOptional<z.ZodArray<z.ZodObject<{
96
+ uri: z.ZodString;
97
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
98
+ properties: z.ZodOptional<z.ZodObject<{
99
+ orientation: z.ZodOptional<z.ZodEnum<{
100
+ portrait: "portrait";
101
+ landscape: "landscape";
102
+ }>>;
103
+ color_scheme: z.ZodOptional<z.ZodEnum<{
104
+ light: "light";
105
+ dark: "dark";
106
+ }>>;
107
+ contrast: z.ZodOptional<z.ZodEnum<{
108
+ normal: "normal";
109
+ high: "high";
110
+ }>>;
111
+ }, z.core.$strip>>;
112
+ }, z.core.$strip>>>;
113
+ }, z.core.$strip>;
114
+ type Rendering = z.infer<typeof RenderingSchema>;
63
115
  /**
64
116
  * Display metadata associated with a credential type.
65
117
  */
66
- type Display = {
67
- /** REQUIRED. Language tag according to RFC 5646 (e.g., "en", "de"). */
68
- lang: string;
69
- /** REQUIRED. Human-readable name for the credential type. */
70
- name: string;
71
- /** OPTIONAL. Description of the credential type for end users. */
72
- description?: string;
73
- /** OPTIONAL. Rendering information (simple or SVG) for the credential. */
74
- rendering?: Rendering;
75
- };
118
+ declare const DisplaySchema: z.ZodObject<{
119
+ lang: z.ZodString;
120
+ name: z.ZodString;
121
+ description: z.ZodOptional<z.ZodString>;
122
+ rendering: z.ZodOptional<z.ZodObject<{
123
+ simple: z.ZodOptional<z.ZodObject<{
124
+ logo: z.ZodOptional<z.ZodObject<{
125
+ uri: z.ZodString;
126
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
127
+ alt_text: z.ZodOptional<z.ZodString>;
128
+ }, z.core.$strip>>;
129
+ background_color: z.ZodOptional<z.ZodString>;
130
+ text_color: z.ZodOptional<z.ZodString>;
131
+ }, z.core.$strip>>;
132
+ svg_template: z.ZodOptional<z.ZodArray<z.ZodObject<{
133
+ uri: z.ZodString;
134
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
135
+ properties: z.ZodOptional<z.ZodObject<{
136
+ orientation: z.ZodOptional<z.ZodEnum<{
137
+ portrait: "portrait";
138
+ landscape: "landscape";
139
+ }>>;
140
+ color_scheme: z.ZodOptional<z.ZodEnum<{
141
+ light: "light";
142
+ dark: "dark";
143
+ }>>;
144
+ contrast: z.ZodOptional<z.ZodEnum<{
145
+ normal: "normal";
146
+ high: "high";
147
+ }>>;
148
+ }, z.core.$strip>>;
149
+ }, z.core.$strip>>>;
150
+ }, z.core.$strip>>;
151
+ }, z.core.$strip>;
152
+ type Display = z.infer<typeof DisplaySchema>;
76
153
  /**
77
154
  * Claim path within the credential's JSON structure.
78
155
  * Example: ["address", "street_address"]
79
156
  */
80
- type ClaimPath = Array<string | null>;
157
+ declare const ClaimPathSchema: z.ZodArray<z.ZodNullable<z.ZodString>>;
158
+ type ClaimPath = z.infer<typeof ClaimPathSchema>;
81
159
  /**
82
160
  * Display metadata for a specific claim.
83
161
  */
84
- type ClaimDisplay = {
85
- /** REQUIRED. Language tag according to RFC 5646. */
86
- lang: string;
87
- /** REQUIRED. Human-readable label for the claim. */
88
- label: string;
89
- /** OPTIONAL. Description of the claim for end users. */
90
- description?: string;
91
- };
162
+ declare const ClaimDisplaySchema: z.ZodObject<{
163
+ lang: z.ZodString;
164
+ label: z.ZodString;
165
+ description: z.ZodOptional<z.ZodString>;
166
+ }, z.core.$strip>;
167
+ type ClaimDisplay = z.infer<typeof ClaimDisplaySchema>;
92
168
  /**
93
169
  * Indicates whether a claim is selectively disclosable.
94
170
  */
95
- type ClaimSelectiveDisclosure = 'always' | 'allowed' | 'never';
171
+ declare const ClaimSelectiveDisclosureSchema: z.ZodEnum<{
172
+ never: "never";
173
+ always: "always";
174
+ allowed: "allowed";
175
+ }>;
176
+ type ClaimSelectiveDisclosure = z.infer<typeof ClaimSelectiveDisclosureSchema>;
96
177
  /**
97
178
  * Metadata for individual claims in the credential type.
98
179
  */
99
- type Claim = {
100
- /**
101
- * REQUIRED. Array of one or more paths to the claim in the credential subject.
102
- * Each path is an array of strings (or null for array elements).
103
- */
104
- path: ClaimPath;
105
- /** OPTIONAL. Display metadata in multiple languages. */
106
- display?: ClaimDisplay[];
107
- /** OPTIONAL. Controls whether the claim must, may, or must not be selectively disclosed. */
108
- sd?: ClaimSelectiveDisclosure;
109
- /**
110
- * OPTIONAL. Unique string identifier for referencing the claim in an SVG template.
111
- * Must consist of alphanumeric characters or underscores and must not start with a digit.
112
- */
113
- svg_id?: string;
114
- };
180
+ declare const ClaimSchema: z.ZodObject<{
181
+ path: z.ZodArray<z.ZodNullable<z.ZodString>>;
182
+ display: z.ZodOptional<z.ZodArray<z.ZodObject<{
183
+ lang: z.ZodString;
184
+ label: z.ZodString;
185
+ description: z.ZodOptional<z.ZodString>;
186
+ }, z.core.$strip>>>;
187
+ sd: z.ZodOptional<z.ZodEnum<{
188
+ never: "never";
189
+ always: "always";
190
+ allowed: "allowed";
191
+ }>>;
192
+ svg_id: z.ZodOptional<z.ZodString>;
193
+ }, z.core.$strip>;
194
+ type Claim = z.infer<typeof ClaimSchema>;
115
195
  /**
116
196
  * Type metadata for a specific Verifiable Credential (VC) type.
117
197
  * Reference: https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-09.html#name-type-metadata-format
118
198
  */
119
- type TypeMetadataFormat = {
120
- /** REQUIRED. A URI uniquely identifying the credential type. */
121
- vct: string;
122
- /** OPTIONAL. Human-readable name for developers. */
123
- name?: string;
124
- /** OPTIONAL. Human-readable description for developers. */
125
- description?: string;
126
- /** OPTIONAL. URI of another type that this one extends. */
127
- extends?: string;
128
- /** OPTIONAL. Integrity metadata for the 'extends' field. */
129
- 'extends#integrity'?: string;
130
- /** OPTIONAL. Array of localized display metadata for the type. */
131
- display?: Display[];
132
- /** OPTIONAL. Array of claim metadata. */
133
- claims?: Claim[];
199
+ declare const TypeMetadataFormatSchema: z.ZodObject<{
200
+ vct: z.ZodString;
201
+ name: z.ZodOptional<z.ZodString>;
202
+ description: z.ZodOptional<z.ZodString>;
203
+ extends: z.ZodOptional<z.ZodString>;
204
+ 'extends#integrity': z.ZodOptional<z.ZodString>;
205
+ display: z.ZodOptional<z.ZodArray<z.ZodObject<{
206
+ lang: z.ZodString;
207
+ name: z.ZodString;
208
+ description: z.ZodOptional<z.ZodString>;
209
+ rendering: z.ZodOptional<z.ZodObject<{
210
+ simple: z.ZodOptional<z.ZodObject<{
211
+ logo: z.ZodOptional<z.ZodObject<{
212
+ uri: z.ZodString;
213
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
214
+ alt_text: z.ZodOptional<z.ZodString>;
215
+ }, z.core.$strip>>;
216
+ background_color: z.ZodOptional<z.ZodString>;
217
+ text_color: z.ZodOptional<z.ZodString>;
218
+ }, z.core.$strip>>;
219
+ svg_template: z.ZodOptional<z.ZodArray<z.ZodObject<{
220
+ uri: z.ZodString;
221
+ 'uri#integrity': z.ZodOptional<z.ZodString>;
222
+ properties: z.ZodOptional<z.ZodObject<{
223
+ orientation: z.ZodOptional<z.ZodEnum<{
224
+ portrait: "portrait";
225
+ landscape: "landscape";
226
+ }>>;
227
+ color_scheme: z.ZodOptional<z.ZodEnum<{
228
+ light: "light";
229
+ dark: "dark";
230
+ }>>;
231
+ contrast: z.ZodOptional<z.ZodEnum<{
232
+ normal: "normal";
233
+ high: "high";
234
+ }>>;
235
+ }, z.core.$strip>>;
236
+ }, z.core.$strip>>>;
237
+ }, z.core.$strip>>;
238
+ }, z.core.$strip>>>;
239
+ claims: z.ZodOptional<z.ZodArray<z.ZodObject<{
240
+ path: z.ZodArray<z.ZodNullable<z.ZodString>>;
241
+ display: z.ZodOptional<z.ZodArray<z.ZodObject<{
242
+ lang: z.ZodString;
243
+ label: z.ZodString;
244
+ description: z.ZodOptional<z.ZodString>;
245
+ }, z.core.$strip>>>;
246
+ sd: z.ZodOptional<z.ZodEnum<{
247
+ never: "never";
248
+ always: "always";
249
+ allowed: "allowed";
250
+ }>>;
251
+ svg_id: z.ZodOptional<z.ZodString>;
252
+ }, z.core.$strip>>>;
253
+ }, z.core.$strip>;
254
+ /**
255
+ * The resolved type metadata. If you just want to use the type metadata, you should use `typeMetadata`.
256
+ * In case additional processing is needed (e.g. for extensions in type metadata), you can use the `typeMetadataChain`
257
+ */
258
+ type ResolvedTypeMetadata = {
259
+ /**
260
+ * The merged type metadata based on the resolved `vct` document and all `extends` values.
261
+ */
262
+ mergedTypeMetadata: TypeMetadataFormat;
263
+ /**
264
+ * The original type metadata documents, ordered from the extending type to the last extended type.
265
+ */
266
+ typeMetadataChain: [TypeMetadataFormat, ...TypeMetadataFormat[]];
267
+ /**
268
+ * The vct values present in the type metadata chain. This can be used for matching against e.g.
269
+ * DCQL queries which can query an underlying type.
270
+ */
271
+ vctValues: [string, ...string[]];
134
272
  };
273
+ type TypeMetadataFormat = z.infer<typeof TypeMetadataFormatSchema>;
135
274
 
136
275
  type VcTFetcher = (uri: string, integrity?: string) => Promise<TypeMetadataFormat | undefined>;
137
276
 
@@ -147,6 +286,7 @@ type SDJWTVCConfig = SDJWTConfig & {
147
286
  statusVerifier?: Verifier;
148
287
  loadTypeMetadataFormat?: boolean;
149
288
  timeout?: number;
289
+ maxVctExtendsDepth?: number;
150
290
  };
151
291
 
152
292
  interface SDJWTVCStatusReference {
@@ -175,7 +315,7 @@ type VerificationResult = {
175
315
  payload: kbPayload;
176
316
  header: kbHeader;
177
317
  } | undefined;
178
- typeMetadataFormat?: TypeMetadataFormat;
318
+ typeMetadata?: ResolvedTypeMetadata;
179
319
  };
180
320
 
181
321
  declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
@@ -215,7 +355,7 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
215
355
  * @param encodedSDJwt
216
356
  * @returns
217
357
  */
218
- getVct(encodedSDJwt: string): Promise<TypeMetadataFormat | undefined>;
358
+ getVct(encodedSDJwt: string): Promise<ResolvedTypeMetadata | undefined>;
219
359
  /**
220
360
  * Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
221
361
  * @param integrity
@@ -227,25 +367,63 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
227
367
  * @param url
228
368
  * @returns
229
369
  */
230
- private fetch;
370
+ private fetchWithIntegrity;
231
371
  /**
232
372
  * Verifies the VCT of the SD-JWT-VC. Returns the type metadata format.
373
+ * Resolves the full extends chain according to spec sections 6.4, 8.2, and 9.5.
233
374
  * @param result
234
375
  * @returns
235
376
  */
236
- private verifyVct;
377
+ private fetchVct;
237
378
  /**
238
- * Fetches VCT Metadata of the SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC does not contain a vct claim, an error is thrown.
239
- * @param result
240
- * @returns
379
+ * Checks if two claim paths are equal by comparing each element.
380
+ * @param path1 First claim path
381
+ * @param path2 Second claim path
382
+ * @returns True if paths are equal, false otherwise
241
383
  */
242
- private fetchVct;
384
+ private claimPathsEqual;
385
+ /**
386
+ * Validates that extending claim metadata respects the constraints from spec section 9.5.1.
387
+ * @param baseClaim The base claim metadata
388
+ * @param extendingClaim The extending claim metadata
389
+ * @throws SDJWTException if validation fails
390
+ */
391
+ private validateClaimExtension;
392
+ /**
393
+ * Merges two type metadata formats, with the extending metadata overriding the base metadata.
394
+ * According to spec section 9.5:
395
+ * - All claim metadata from the extended type are inherited
396
+ * - The child type can add new claims or properties
397
+ * - If the child type defines claim metadata with the same path as the extended type,
398
+ * the child type's object will override the corresponding object from the extended type
399
+ * According to spec section 9.5.1:
400
+ * - sd property can only be changed from 'allowed' (or omitted) to 'always' or 'never'
401
+ * - sd property cannot be changed from 'always' or 'never' to a different value
402
+ * According to spec section 8.2:
403
+ * - If the extending type defines its own display property, the original display metadata is ignored
404
+ * Note: The spec also mentions 'mandatory' property constraints, but this is not currently
405
+ * defined in the Claim type and will be validated when that property is added to the type.
406
+ * @param base The base type metadata format
407
+ * @param extending The extending type metadata format
408
+ * @returns The merged type metadata format
409
+ */
410
+ private mergeTypeMetadata;
411
+ /**
412
+ * Resolves the full VCT chain by recursively fetching extended type metadata.
413
+ * Implements security considerations from spec section 10.3 for circular dependencies.
414
+ * @param vct The VCT URI to resolve
415
+ * @param integrity Optional integrity metadata for the VCT
416
+ * @param depth Current depth in the chain
417
+ * @param visitedVcts Set of already visited VCT URIs to detect circular dependencies
418
+ * @returns The fully resolved and merged type metadata format
419
+ */
420
+ private resolveVctExtendsChain;
243
421
  /**
244
- * Fetches VCT Metadata from the header of the SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC does not contain a vct claim, an error is thrown.
422
+ * Fetches and verifies the VCT Metadata for a VCT value.
245
423
  * @param result
246
- * @param
424
+ * @returns
247
425
  */
248
- private fetchVctFromHeader;
426
+ private fetchSingleVct;
249
427
  /**
250
428
  * Verifies the status of the SD-JWT-VC.
251
429
  * @param result
@@ -254,4 +432,4 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
254
432
  private verifyStatus;
255
433
  }
256
434
 
257
- export { type Claim, type ClaimDisplay, type ClaimPath, type ClaimSelectiveDisclosure, type Display, type Logo, type Rendering, type SDJWTVCConfig, type SDJWTVCStatusReference, SDJwtVcInstance, type SdJwtVcPayload, type SimpleRendering, type StatusListFetcher, type StatusValidator, type SvgTemplateProperties, type SvgTemplateRendering, type TypeMetadataFormat, type VcTFetcher, type VerificationResult };
435
+ export { type Claim, type ClaimDisplay, ClaimDisplaySchema, type ClaimPath, ClaimPathSchema, ClaimSchema, type ClaimSelectiveDisclosure, ClaimSelectiveDisclosureSchema, ColorSchemeSchema, ContrastSchema, type Display, DisplaySchema, type Logo, LogoSchema, OrientationSchema, type Rendering, RenderingSchema, type ResolvedTypeMetadata, type SDJWTVCConfig, type SDJWTVCStatusReference, SDJwtVcInstance, type SdJwtVcPayload, type SimpleRendering, SimpleRenderingSchema, type StatusListFetcher, type StatusValidator, type SvgTemplateProperties, SvgTemplatePropertiesSchema, type SvgTemplateRendering, SvgTemplateRenderingSchema, type TypeMetadataFormat, TypeMetadataFormatSchema, type VcTFetcher, type VerificationResult };