Skip to main content

๐Ÿ’  CTYPE

Before the claimer can make a claim about themselves, first a claim type (CType for short) needs to be found or created. It requires an account and a full DID with tokens in order to pay the Angel's fee and deposit of a CType.

A claim type (CTYPE for short) is a KILT-specific term, but the concept is simple:
A CTYPE defines the structure of a claim. You can think of it as the data model for your claim.

For example, a very basic CTYPE for a driver's license could look like this:

{
"schema": {
"$id": "kilt:ctype:0xd8ad043d91d8fdbc382ee0ce33dc96af4ee62ab2d20f7980c49d3e577d80e5f5",
"$schema": "http://kilt-protocol.org/draft-01/ctype#",
"title": "Drivers License",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"type": "object"
},
"owner": "5DD7fAZKSpgctg1ZQigAYuk3ypBtr2Q9RPKJBx5UpUwQw4vB",
"hash": "0xd8ad043d91d8fdbc382ee0ce33dc96af4ee62ab2d20f7980c49d3e577d80e5f5"
}
CType

CTYPEs are based on JSON Schema, a standard used to annotate and validate JSON documents. A schema defines which properties exist and what their type should be, i.e. is it a string, a number, an object, etc.

When you create a CType from a schema, it is checked whether your CType aligns with the underlying schema. Think of checking whether a cook (user) followed a certain recipe (schema) when preparing a meal (creating a CType).

We don't need to dive into it in this tutorial, for now we can think of CTYPE as JSON objects.

Let's have a look at these attributes.

KeyValue
schema > $idThe KILT id of this CTYPE.
schema > $schemaThe JSON schema on which the CTYPE is based.
schema > titleThe title of the CTYPE.
schema > propertiesThe properties that a claim of type in $schema should have.
ownerThe public address of the user who created this CTYPE.
hashMost important attribute, the hash is the CTYPE's digital footprint.

A CTYPE is stored on the KILT blockchain.

In a real-life setup, a user would simply retrieve an existing CTYPE from the chain or a repository of CTYPEs for example via a REST API.

In this tutorial, we'll create and try to store a CTYPE on the KILT test blockchain.

Code

Create a new file ctype.js

Copy the following to create a CType from a schema:

{
"schema": {
"$id": "kilt:ctype:0xd8ad043d91d8fdbc382ee0ce33dc96af4ee62ab2d20f7980c49d3e577d80e5f5",
"$schema": "http://kilt-protocol.org/draft-01/ctype#",
"title": "Drivers License",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"type": "object"
},
"owner": "5DD7fAZKSpgctg1ZQigAYuk3ypBtr2Q9RPKJBx5UpUwQw4vB",
"hash": "0xd8ad043d91d8fdbc382ee0ce33dc96af4ee62ab2d20f7980c49d3e577d80e5f5"
}

Once you have constructed the schema, pass the attester, attestersFullDid, keystore and ctype.

Creating a new file storedCtype.js

Copy the following to store the CType on-chain, an account must have the require amount to pay the Angel's fee and deposit:

import * as Kilt from '@kiltprotocol/sdk-js'

export function main(): Kilt.CType {
return Kilt.CType.fromSchema({
$schema: 'http://kilt-protocol.org/draft-01/ctype#',
title: 'Drivers License',
properties: {
name: {
type: 'string',
},
age: {
type: 'integer',
},
},
type: 'object',
})
}

Create a new file ctype.json and store the ctype.

OK, now you've got all you need to create a claim: a light DID and a CTYPE.

Let's move on!