@sd-jwt/sd-jwt-vc 0.17.2-next.0 → 0.17.2-next.10

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.
@@ -1,144 +1,196 @@
1
+ import { z } from 'zod';
2
+
1
3
  /**
2
4
  * Logo metadata used in rendering a credential.
3
5
  */
4
- export type Logo = {
6
+ export const LogoSchema = z.object({
5
7
  /** REQUIRED. A URI pointing to the logo image. */
6
- uri: string;
8
+ uri: z.string(),
7
9
  /** OPTIONAL. An "integrity metadata" string as described in Section 7. */
8
- 'uri#integrity'?: string;
10
+ 'uri#integrity': z.string().optional(),
9
11
  /** OPTIONAL. A string containing alternative text for the logo image. */
10
- alt_text?: string;
11
- };
12
+ alt_text: z.string().optional(),
13
+ });
14
+
15
+ export type Logo = z.infer<typeof LogoSchema>;
12
16
 
13
17
  /**
14
18
  * The simple rendering method is intended for applications that do not support SVG.
15
19
  */
16
- export type SimpleRendering = {
20
+ export const SimpleRenderingSchema = z.object({
17
21
  /** OPTIONAL. Logo metadata to display for the credential. */
18
- logo?: Logo;
22
+ logo: LogoSchema.optional(),
19
23
  /** OPTIONAL. RGB color value for the credential background (e.g., "#FFFFFF"). */
20
- background_color?: string;
24
+ background_color: z.string().optional(),
21
25
  /** OPTIONAL. RGB color value for the credential text (e.g., "#000000"). */
22
- text_color?: string;
23
- };
26
+ text_color: z.string().optional(),
27
+ });
28
+
29
+ export type SimpleRendering = z.infer<typeof SimpleRenderingSchema>;
24
30
 
25
31
  /** Enum of valid values for rendering orientation. */
26
- type Orientation = 'portrait' | 'landscape';
32
+ export const OrientationSchema = z.enum(['portrait', 'landscape']);
27
33
 
28
34
  /** Enum of valid values for rendering color schemes. */
29
- type ColorScheme = 'light' | 'dark';
35
+ export const ColorSchemeSchema = z.enum(['light', 'dark']);
30
36
 
31
37
  /** Enum of valid values for rendering contrast. */
32
- type Contrast = 'normal' | 'high';
38
+ export const ContrastSchema = z.enum(['normal', 'high']);
33
39
 
34
40
  /**
35
41
  * Properties that describe the display preferences for an SVG template rendering.
36
42
  */
37
- export type SvgTemplateProperties = {
43
+ export const SvgTemplatePropertiesSchema = z.object({
38
44
  /** OPTIONAL. Orientation optimized for the template. */
39
- orientation?: Orientation;
45
+ orientation: OrientationSchema.optional(),
40
46
  /** OPTIONAL. Color scheme optimized for the template. */
41
- color_scheme?: ColorScheme;
47
+ color_scheme: ColorSchemeSchema.optional(),
42
48
  /** OPTIONAL. Contrast level optimized for the template. */
43
- contrast?: Contrast;
44
- };
49
+ contrast: ContrastSchema.optional(),
50
+ });
51
+
52
+ export type SvgTemplateProperties = z.infer<typeof SvgTemplatePropertiesSchema>;
45
53
 
46
54
  /**
47
55
  * SVG rendering metadata containing URI and optional integrity and properties.
48
56
  */
49
- export type SvgTemplateRendering = {
57
+ export const SvgTemplateRenderingSchema = z.object({
50
58
  /** REQUIRED. A URI pointing to the SVG template. */
51
- uri: string;
59
+ uri: z.string(),
52
60
  /** OPTIONAL. An "integrity metadata" string as described in Section 7. */
53
- 'uri#integrity'?: string;
61
+ 'uri#integrity': z.string().optional(),
54
62
  /** REQUIRED if more than one SVG template is present. */
55
- properties?: SvgTemplateProperties;
56
- };
63
+ properties: SvgTemplatePropertiesSchema.optional(),
64
+ });
65
+
66
+ export type SvgTemplateRendering = z.infer<typeof SvgTemplateRenderingSchema>;
57
67
 
58
68
  /**
59
69
  * Rendering metadata, either simple or SVG-based, for a credential.
60
70
  */
61
- export type Rendering = {
71
+ export const RenderingSchema = z.object({
62
72
  /** OPTIONAL. Simple rendering metadata. */
63
- simple?: SimpleRendering;
73
+ simple: SimpleRenderingSchema.optional(),
64
74
  /** OPTIONAL. Array of SVG template rendering objects. */
65
- svg_template?: SvgTemplateRendering[];
66
- };
75
+ svg_template: z.array(SvgTemplateRenderingSchema).optional(),
76
+ });
77
+
78
+ export type Rendering = z.infer<typeof RenderingSchema>;
67
79
 
68
80
  /**
69
81
  * Display metadata associated with a credential type.
70
82
  */
71
- export type Display = {
83
+ export const DisplaySchema = z.object({
72
84
  /** REQUIRED. Language tag according to RFC 5646 (e.g., "en", "de"). */
73
- lang: string;
85
+ lang: z.string(),
74
86
  /** REQUIRED. Human-readable name for the credential type. */
75
- name: string;
87
+ name: z.string(),
76
88
  /** OPTIONAL. Description of the credential type for end users. */
77
- description?: string;
89
+ description: z.string().optional(),
78
90
  /** OPTIONAL. Rendering information (simple or SVG) for the credential. */
79
- rendering?: Rendering;
80
- };
91
+ rendering: RenderingSchema.optional(),
92
+ });
93
+
94
+ export type Display = z.infer<typeof DisplaySchema>;
81
95
 
82
96
  /**
83
97
  * Claim path within the credential's JSON structure.
84
98
  * Example: ["address", "street_address"]
85
99
  */
86
- export type ClaimPath = Array<string | null>;
100
+ export const ClaimPathSchema = z.array(z.string().nullable());
101
+
102
+ export type ClaimPath = z.infer<typeof ClaimPathSchema>;
87
103
 
88
104
  /**
89
105
  * Display metadata for a specific claim.
90
106
  */
91
- export type ClaimDisplay = {
107
+ export const ClaimDisplaySchema = z.object({
92
108
  /** REQUIRED. Language tag according to RFC 5646. */
93
- lang: string;
109
+ lang: z.string(),
94
110
  /** REQUIRED. Human-readable label for the claim. */
95
- label: string;
111
+ label: z.string(),
96
112
  /** OPTIONAL. Description of the claim for end users. */
97
- description?: string;
98
- };
113
+ description: z.string().optional(),
114
+ });
115
+
116
+ export type ClaimDisplay = z.infer<typeof ClaimDisplaySchema>;
99
117
 
100
118
  /**
101
119
  * Indicates whether a claim is selectively disclosable.
102
120
  */
103
- export type ClaimSelectiveDisclosure = 'always' | 'allowed' | 'never';
121
+ export const ClaimSelectiveDisclosureSchema = z.enum([
122
+ 'always',
123
+ 'allowed',
124
+ 'never',
125
+ ]);
126
+
127
+ export type ClaimSelectiveDisclosure = z.infer<
128
+ typeof ClaimSelectiveDisclosureSchema
129
+ >;
104
130
 
105
131
  /**
106
132
  * Metadata for individual claims in the credential type.
107
133
  */
108
- export type Claim = {
134
+ export const ClaimSchema = z.object({
109
135
  /**
110
136
  * REQUIRED. Array of one or more paths to the claim in the credential subject.
111
137
  * Each path is an array of strings (or null for array elements).
112
138
  */
113
- path: ClaimPath;
139
+ path: ClaimPathSchema,
114
140
  /** OPTIONAL. Display metadata in multiple languages. */
115
- display?: ClaimDisplay[];
141
+ display: z.array(ClaimDisplaySchema).optional(),
116
142
  /** OPTIONAL. Controls whether the claim must, may, or must not be selectively disclosed. */
117
- sd?: ClaimSelectiveDisclosure;
143
+ sd: ClaimSelectiveDisclosureSchema.optional(),
118
144
  /**
119
145
  * OPTIONAL. Unique string identifier for referencing the claim in an SVG template.
120
146
  * Must consist of alphanumeric characters or underscores and must not start with a digit.
121
147
  */
122
- svg_id?: string;
123
- };
148
+ svg_id: z.string().optional(),
149
+ });
150
+
151
+ export type Claim = z.infer<typeof ClaimSchema>;
124
152
 
125
153
  /**
126
154
  * Type metadata for a specific Verifiable Credential (VC) type.
127
155
  * Reference: https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-09.html#name-type-metadata-format
128
156
  */
129
- export type TypeMetadataFormat = {
157
+ export const TypeMetadataFormatSchema = z.object({
130
158
  /** REQUIRED. A URI uniquely identifying the credential type. */
131
- vct: string;
159
+ vct: z.string(),
132
160
  /** OPTIONAL. Human-readable name for developers. */
133
- name?: string;
161
+ name: z.string().optional(),
134
162
  /** OPTIONAL. Human-readable description for developers. */
135
- description?: string;
163
+ description: z.string().optional(),
136
164
  /** OPTIONAL. URI of another type that this one extends. */
137
- extends?: string;
165
+ extends: z.string().optional(),
138
166
  /** OPTIONAL. Integrity metadata for the 'extends' field. */
139
- 'extends#Integrity'?: string;
167
+ 'extends#integrity': z.string().optional(),
140
168
  /** OPTIONAL. Array of localized display metadata for the type. */
141
- display?: Display[];
169
+ display: z.array(DisplaySchema).optional(),
142
170
  /** OPTIONAL. Array of claim metadata. */
143
- claims?: Claim[];
171
+ claims: z.array(ClaimSchema).optional(),
172
+ });
173
+
174
+ /**
175
+ * The resolved type metadata. If you just want to use the type metadata, you should use `typeMetadata`.
176
+ * In case additional processing is needed (e.g. for extensions in type metadata), you can use the `typeMetadataChain`
177
+ */
178
+ export type ResolvedTypeMetadata = {
179
+ /**
180
+ * The merged type metadata based on the resolved `vct` document and all `extends` values.
181
+ */
182
+ mergedTypeMetadata: TypeMetadataFormat;
183
+
184
+ /**
185
+ * The original type metadata documents, ordered from the extending type to the last extended type.
186
+ */
187
+ typeMetadataChain: [TypeMetadataFormat, ...TypeMetadataFormat[]];
188
+
189
+ /**
190
+ * The vct values present in the type metadata chain. This can be used for matching against e.g.
191
+ * DCQL queries which can query an underlying type.
192
+ */
193
+ vctValues: [string, ...string[]];
144
194
  };
195
+
196
+ export type TypeMetadataFormat = z.infer<typeof TypeMetadataFormatSchema>;
@@ -3,4 +3,4 @@ import type { TypeMetadataFormat } from './sd-jwt-vc-type-metadata-format';
3
3
  export type VcTFetcher = (
4
4
  uri: string,
5
5
  integrity?: string,
6
- ) => Promise<TypeMetadataFormat>;
6
+ ) => Promise<TypeMetadataFormat | undefined>;
@@ -87,7 +87,7 @@ describe('App', () => {
87
87
  expectedPayload,
88
88
  disclosureFrame as unknown as DisclosureFrame<SdJwtVcPayload>,
89
89
  );
90
- expect(encodedSdjwt).rejects.toThrowError();
90
+ await expect(encodedSdjwt).rejects.toThrowError();
91
91
  });
92
92
  });
93
93
 
@@ -149,7 +149,7 @@ describe('Revocation', () => {
149
149
  const expectedPayload: SdJwtVcPayload = { iat, iss, vct, ...claims };
150
150
  const encodedSdjwt = await sdjwt.issue(expectedPayload);
151
151
  const result = sdjwt.verify(encodedSdjwt);
152
- expect(result).rejects.toThrowError('Status is not valid');
152
+ await expect(result).rejects.toThrowError('Status is not valid');
153
153
  });
154
154
 
155
155
  test('test to fetch the statuslist', async () => {