CType outlines the schema of VC. Think of it as the data model for your claim, consisting of key-value pairs, each of a defined type. The CType schema is formulated using JSON Schema.
To publish a CType, you must first construct a BaseCType
to standardize the format of the CType; then you need to convert the BaseCType
to a CType
(via publishing the CType with your DID)and get the corresponding CTypeHash
BaseCType
contains the following elements:
title
: used to show the title of the CType(e.g. zCloak Membership Credential);description
: the brief description of the CType;type
: the default value is 'object';properties
: marks which fields the VC contains and their data type definitions;required
(optional):marks which fields the VC must contain;An example of a BaseCType would be:
const base: BaseCType = {
title: 'Test',
description: 'Test',
type: 'object',
properties: {
name: {
type: 'string'
},
age: {
type: 'integer'
},
level: {
type: 'integer'
}
},
required: ['name', 'age']
};
CType
contains the following 4 elements:
$id
(CTypehash): the unique identifier of the CType, a hexadecimal string starting with '0x';$schema
: specifies the format of the schema,and the default value is DEFAULT_CType_SCHEMA
, i.e. 'https://json-schema.org/draft-07/schema#';publisher
: the DID URL of the entity that published the CType;signature
: the publisher's signature on $id
(CTypehash);The described structure of CType is shown below:
export interface BaseCType extends CTypeSchema {
title: string;
description: string;
type: 'object';
properties: Record<string, CTypeSchema>;
required?: string[];
}
export interface CType extends BaseCType {
$id: HexString;
$schema: string;
publisher: DidUrl;
signature: string;
}
In this section, we will discuss the methods involved in managing CType and explain their important properties. To simplify the process of implementing these methods, we have created an SDK that you can use, you may explore our SDK Guideline.