Welcome! This documentation will provide you with an example showcasing the process of generating a Verifiable Credential (VC). For more comprehensive details on the SDK capabilities, we recommend referring to our SDK Guideline.

CType Creation

As a prerequisite for requesting a VC, you need to select a CType that has already been generated and published. If you already possess such a CType, you may skip this section and proceed directly to the following section - 'VC Generation'.

Customizing CType

First, create a custom BaseCType based on your requirements. Here, we present an example of a CType with two properties: {name: String; age: Integer}.

export interface BaseCType extends CTypeSchema {
  title: string;
  description: string;
  type: 'object';
  properties: Record<string, CTypeSchema>;
  required?: string[];
}

Getting CTypeHash

Invoke the getCTypeHash(...) function to acquire the unique identifier of the custom CType -- CTypeHash.

export function getCTypeHash(
  base: BaseCType,
  publisher: DidUrl,
  schema = DEFAULT_CType_SCHEMA
): HexString

Publishing CType

Invoke the getPublish(...) function to generate a custom CType from the BaseCType. The CType includes a signature generated by signing the CTypeHash with the publisher's DID.

export async function getPublish(base: BaseCType, publisher: Did): Promise<CType>

VC generation

Filling Basic Content

Firstly, populate the information of your data -- name and age (in accordance with the CType example utilized in the 'Customizing CType' section).

const CONTENTS = {
  name: 'Alice',
  age: 20,
};

Secondly, to generate a VC, claimers need to provide the owner (the DID URL of the claimer), CType (CTypeHash), and the hashType used in VC Construction. Afterwards, call the calcRootHash(...) method to calculate the root hash, which automatically performs hashing-with-salt operations through the introduction of a random value (UUID).

 const raw = new Raw({
    contents: CONTENTS,
    owner: holder.id,
    CType,
    hashType: 'keccak256'
  });
 raw.calcRootHash();

Attester Signature

By invoking the build(..) method in VerifiableCredentialBuilder, the issuer can employ their own DID to generate the VC.