Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement VC 2.0 data model #5

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# vc-data-model Changelog

## 2.0.0 - 2024-xx-xx
### Added
- Implement VC Data Model v2.0

## 1.1.0 - 2022-12-12
### Added
- Initial commit. Meant to model VC Data Model v1.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@digitalcredentials/vc-data-model",
"description": "Typescript types for the W3C Verifiable Credentials Data Model.",
"version": "1.1.0",
"version": "2.0.0",
"scripts": {
"build": "npm run clear && tsc -d && tsc -p tsconfig.json",
"clear": "rimraf dist/*",
Expand Down
125 changes: 84 additions & 41 deletions src/VerifiableCredential.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
/*!
* Copyright (c) 2022 Digital Credentials Consortium. All rights reserved.
*/
export type Type = string | string[]
export type Type = string | string[];

export interface ImageObject {
id: string
type?: Type
[x: string]: any
id: string;
type?: Type;
[x: string]: any;
}

export interface LinkedDataObject {
// id and type are very common to all Linked Data objects
id?: string
type?: Type
id?: string;
type?: Type;

name?: string
image?: string | ImageObject
name?: string;
description?: string;
image?: string | ImageObject;
}

export interface IssuerObject extends LinkedDataObject {
id: string
url?: string
id: string;
url?: string;

[x: string]: any
[x: string]: any;
}

export type VerifiableCredential = VCDIVerifiableCredential | CompactJWT
export type VerifiableCredential = VCDIVerifiableCredential | CompactJWT;

// Represents a Json Web Token in compact form: "header.payload.signature"
export type CompactJWT = string
export type CompactJWT = string;

// Represents a Verifiable Credential protected by
// the Verifiable Credential Data Integrity 1.0 spec
Expand All @@ -38,82 +39,124 @@ export interface VCDIVerifiableCredential extends LinkedDataObject {
// Subsequent elements are either URLs for other contexts OR
// inline context objects.
// https://w3c.github.io/vc-data-model/#contexts
'@context': string[] | any
'@context': string[] | any;

// https://w3c.github.io/vc-data-model/#identifiers
id?: string
id?: string;

// https://w3c.github.io/vc-data-model/#types
type: Type
type: Type;

// https://w3c.github.io/vc-data-model/#issuer
issuer: string | IssuerObject
issuer: string | IssuerObject;

// https://w3c.github.io/vc-data-model/#issuance-date
issuanceDate: string
// https://w3c.github.io/vc-data-model/#validity-period
validFrom?: string;

// https://w3c.github.io/vc-data-model/#expiration
expirationDate?: string
// https://w3c.github.io/vc-data-model/#validity-period
validUntil?: string;

// https://w3c.github.io/vc-data-model/#credential-subject
credentialSubject: CredentialSubject
credentialSubject: CredentialSubject | CredentialSubject[];

// https://w3c.github.io/vc-data-model/#status
credentialStatus?: CredentialStatus
credentialStatus?: CredentialStatus;

// https://w3c.github.io/vc-data-model/#data-schemas
credentialSchema?: CredentialSchema
credentialSchema?: CredentialSchema | CredentialSchema[];

// https://w3c.github.io/vc-data-model/#integrity-of-related-resources
relatedResource?: RelatedResource[];
dmitrizagidulin marked this conversation as resolved.
Show resolved Hide resolved

// https://w3c.github.io/vc-data-model/#evidence
evidence?: Evidence | Evidence[]
evidence?: Evidence | Evidence[];

// https://w3c.github.io/vc-data-model/#refreshing
refreshService?: RefreshService
refreshService?: RefreshService | RefreshService[];

// https://w3c.github.io/vc-data-model/#terms-of-use
termsOfUse?: any
termsOfUse?: TermsOfUse | TermsOfUse[];

// https://w3c-ccg.github.io/confidence-method-spec
confidenceMethod?: ConfidenceMethod | ConfidenceMethod[];

// https://w3c-ccg.github.io/vc-render-method
renderMethod?: RenderMethod | RenderMethod[];

// For W3C Linked Data Integrity-protected VCs, a 'proof' is required
// However, for JWT-protected VCs, 'proof' is optional (is external)
// @see https://w3c-ccg.github.io/ld-cryptosuite-registry/
// for examples of cryptographic suites used for VC proofs
proof?: any
proof?: any;

// Implementers are free to add any other properties to a VC
[x: string]: any
[x: string]: any;
}

// https://w3c.github.io/vc-data-model/#credential-subject
export interface CredentialSubject extends LinkedDataObject {
// although a VC is required to have a `credentialSubject` property,
// the spec does not require any properties inside it.
[x: string]: any;
}

// https://w3c.github.io/vc-data-model/#status
export interface CredentialStatus extends LinkedDataObject {
// id and type are required for `credentialStatus` by the VC spec
id: string
type: Type
[x: string]: any
id?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

type: Type;
[x: string]: any;

// Each status type has its own required fields. For example:
// https://w3c-ccg.github.io/vc-status-list-2021
statusPurpose?: string
statusListIndex?: string | number
statusListCredential?: string
// https://w3c.github.io/vc-bitstring-status-list
statusPurpose?: string;
statusListIndex?: string | number;
statusListCredential?: string;
}

// https://w3c.github.io/vc-data-model/#data-schemas
export interface CredentialSchema {
id: string
type: string
id: string;
type: string;
[x: string]: any;
}

// https://w3c.github.io/vc-data-model/#terms-of-use
export interface TermsOfUse {
id?: string;
type: string;
[x: string]: any;
}

// https://w3c.github.io/vc-data-model/#refreshing
export interface RefreshService {
id: string
type: string
type: string;
[x: string]: any;
}

// https://w3c.github.io/vc-data-model/#integrity-of-related-resources
export interface RelatedResource {
id: string;
digestSRI: string;
mediaType?: string;
}

// https://w3c.github.io/vc-data-model/#evidence
export interface Evidence extends LinkedDataObject {}
export interface Evidence {
id?: string;
type: string;
[x: string]: any;
}

// https://w3c-ccg.github.io/confidence-method-spec
export interface ConfidenceMethod {
id?: string;
type: string;
[x: string]: any;
}

// https://w3c-ccg.github.io/vc-render-method
export interface RenderMethod {
type: string;
[x: string]: any;
}
16 changes: 10 additions & 6 deletions src/VerifiablePresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@
*/
import {
LinkedDataObject,
RefreshService,
Type,
VerifiableCredential
} from './VerifiableCredential'

export interface VerifiablePresentation extends LinkedDataObject {
'@context': any
'@context': any;

// A 'type' property is required for VPs
// see https://www.w3.org/TR/vc-data-model/#presentations-0
type: Type
type: Type;

// Optional, expected to be a URI for the entity presenting the VP
holder?: string
holder?: string;

// Including VCs in a VP is optional; "empty" VPs are used for DID Auth
verifiableCredential?: VerifiableCredential | VerifiableCredential[]
verifiableCredential?: VerifiableCredential | VerifiableCredential[];

// https://w3c.github.io/vc-data-model/#refreshing
refreshService?: RefreshService;

// Adding a proof (signing) to a VP is optional, and is typically used
// to authenticate the presenter (who may be different from the subject of
// any of the VCs).
proof?: any
proof?: any;

// Implementers are free to add any other properties to a VP
[x: string]: any
[x: string]: any;
}
Loading