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.

Basic Construction

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

BaseCTypecontains the following elements:

  1. title: used to show the title of the CType(e.g. zCloak Membership Credential);
  2. description: the brief description of the CType;
  3. type: the default value is 'object';
  4. properties: marks which fields the VC contains and their data type definitions;
  5. 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:

  1. $id(CTypehash): the unique identifier of the CType, a hexadecimal string starting with '0x';
  2. $schema: specifies the format of the schema,and the default value is DEFAULT_CType_SCHEMA, i.e. 'https://json-schema.org/draft-07/schema#';
  3. publisher: the DID URL of the entity that published the CType;
  4. 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;
}

Key Methods

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.