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.
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'.
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[];
}
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
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>
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();
By invoking the build(..) method in VerifiableCredentialBuilder, the issuer can employ their own DID to generate the VC.