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 ProofID-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": "pid:ctype:0xd8ad043d91d8fdbc382ee0ce33dc96af4ee62ab2d20f7980c49d3e577d80e5f5",
"$schema": "https://proofid.me/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 ProofID 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 ProofID 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 ProofID test blockchain.

Code

Create a new file ctype.js

Copy the following to create a CType from a schema:

const ProofID = require('@proofid/pid-ts-lib')

function createCType() {
return ProofID.CType.fromSchema({
$schema: 'https://proofid.me/draft-01/ctype#',
title: 'Drivers License',
properties: {
name: {
type: 'string',
},
age: {
type: 'integer',
},
},
type: 'object',
})
}

module.exports.createCType = createCType

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:

const ProofID = require('@proofid/pid-ts-lib')

async function ctypeStored(attester, attesterFullDid, ctype, keystore) {
await ProofID.connect()

// Good to check if the ctype is stored on chain
if (await ctype.verifyStored()) {
await ProofID.disconnect()
return ctype
}

// If the ctype isn't stored on the chain, then an account with a full DID will need to store the ctype on-chain.
const tx = await ctype.store()

const authorizedExtrinsic = await attesterFullDid.authorizeExtrinsic(
tx,
keystore,
attester.address
)

await ProofID.BlockchainUtils.signAndSubmitTx(authorizedExtrinsic, attester, {
resolveOn: ProofID.BlockchainUtils.IS_FINALIZED,
reSign: true,
})

await ProofID.disconnect()
return ctype
}
module.exports.ctypeStored = ctypeStored

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!