Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions packages/sd-jwt-vc/src/sd-jwt-vc-type-metadata-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,33 @@ export type ClaimPath = z.infer<typeof ClaimPathSchema>;
/**
* Display metadata for a specific claim.
*/
export const ClaimDisplaySchema = z.looseObject({
/** REQUIRED. Language tag according to RFC 5646. */
lang: z.string(),
/** REQUIRED. Human-readable label for the claim. */
label: z.string(),
/** OPTIONAL. Description of the claim for end users. */
description: z.string().optional(),
});
export const ClaimDisplaySchema = z
.looseObject({
/**
* Language tag according to RFC 5646.
* @deprecated - use `locale` instead
*/
lang: z.string().optional(),

/**
* REQUIRED (preferred). Language tag according to RFC 5646.
* Alias for `lang` - either `lang` or `locale` must be provided.
*/
locale: z.string().optional(),

/** REQUIRED. Human-readable label for the claim. */
label: z.string(),
/** OPTIONAL. Description of the claim for end users. */
description: z.string().optional(),
})
.transform(({ lang, locale, ...rest }) => ({
...rest,
locale: locale ?? lang,
}))
.refine(({ locale }) => locale !== undefined, {
message:
'Either locale (preferred) or lang (spec name, deprecated) MUST be defined on claim display entry.',
});

export type ClaimDisplay = z.infer<typeof ClaimDisplaySchema>;

Expand Down Expand Up @@ -141,6 +160,11 @@ export const ClaimSchema = z.looseObject({
display: z.array(ClaimDisplaySchema).optional(),
/** OPTIONAL. Controls whether the claim must, may, or must not be selectively disclosed. */
sd: ClaimSelectiveDisclosureSchema.optional(),
/**
* OPTIONAL. A boolean indicating whether the claim must be present in the Unsecured Payload
* of the SD-JWT VC. Default is false if not specified.
*/
mandatory: z.boolean().optional(),
/**
* OPTIONAL. Unique string identifier for referencing the claim in an SVG template.
* Must consist of alphanumeric characters or underscores and must not start with a digit.
Expand All @@ -152,7 +176,7 @@ export type Claim = z.infer<typeof ClaimSchema>;

/**
* Type metadata for a specific Verifiable Credential (VC) type.
* Reference: https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-09.html#name-type-metadata-format
* Reference: https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-13.html#name-type-metadata-format
*/
export const TypeMetadataFormatSchema = z.looseObject({
/** REQUIRED. A URI uniquely identifying the credential type. */
Expand Down
18 changes: 9 additions & 9 deletions packages/sd-jwt-vc/src/test/vct.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const baseVctm: TypeMetadataFormat = {
claims: [
{
path: ['firstName'],
display: [{ lang: 'en', label: 'First Name' }],
display: [{ locale: 'en', label: 'First Name' }],
},
],
display: [
Expand All @@ -42,7 +42,7 @@ const extendingVctm: TypeMetadataFormat = {
claims: [
{
path: ['lastName'],
display: [{ lang: 'en', label: 'Last Name' }],
display: [{ locale: 'en', label: 'Last Name' }],
},
],
display: [
Expand All @@ -67,7 +67,7 @@ const middleVctm: TypeMetadataFormat = {
claims: [
{
path: ['age'],
display: [{ lang: 'en', label: 'Age' }],
display: [{ locale: 'en', label: 'Age' }],
},
],
};
Expand All @@ -80,12 +80,12 @@ const overridingVctm: TypeMetadataFormat = {
claims: [
{
path: ['firstName'],
display: [{ lang: 'en', label: 'Given Name' }], // Override with different label
display: [{ locale: 'en', label: 'Given Name' }], // Override with different label
sd: 'always' as const,
},
{
path: ['middleName'],
display: [{ lang: 'en', label: 'Middle Name' }],
display: [{ locale: 'en', label: 'Middle Name' }],
},
],
};
Expand All @@ -109,7 +109,7 @@ const baseWithSdAlways: TypeMetadataFormat = {
{
path: ['sensitiveData'],
sd: 'always' as const,
display: [{ lang: 'en', label: 'Sensitive Data' }],
display: [{ locale: 'en', label: 'Sensitive Data' }],
},
],
};
Expand All @@ -122,7 +122,7 @@ const invalidExtendingSdChange: TypeMetadataFormat = {
{
path: ['sensitiveData'],
sd: 'never' as const, // Invalid: trying to change from 'always' to 'never'
display: [{ lang: 'en', label: 'Sensitive Data' }],
display: [{ locale: 'en', label: 'Sensitive Data' }],
},
],
};
Expand All @@ -135,7 +135,7 @@ const validExtendingSdChange: TypeMetadataFormat = {
{
path: ['firstName'],
sd: 'always' as const, // Valid: base doesn't have sd or has 'allowed'
display: [{ lang: 'en', label: 'First Name' }],
display: [{ locale: 'en', label: 'First Name' }],
},
],
};
Expand All @@ -147,7 +147,7 @@ const vctWithCustomProperties: TypeMetadataFormat = {
{
path: ['firstName'],
sd: 'always' as const, // Valid: base doesn't have sd or has 'allowed'
display: [{ lang: 'en', label: 'First Name' }],
display: [{ locale: 'en', label: 'First Name' }],
anotherCustom: 'property',
},
],
Expand Down