In the realm of Verifiable Credentials (VC), each credential must be associated with a schema. This schema outlines the fields and their respective types that the credential contains.

The purpose of this schema is to ensure the authenticity of a VC. It acts as a protective measure, preventing any tampering by adding unauthorized fields.

It’s important to note that all credentials within a single template will share the same schema. This shared schema is referred to as the ‘credential type’.

By adhering to this structure, we can maintain the integrity and verifiability of the credentials, ensuring they serve their purpose effectively.

Example Types

Here are a couple of example types that you can use:

User info

Use the type name userBasicInfo to be able to create credentials with the following schema:

UserBasicInfo {
    name: string;
    email: string;
    age: uint64;
}

This was the payload used to create the type:

{
    "credentialSubjectSchema": [
        {
            "name": "name",
            "type": "string"
        },
        {
            "name": "age",
            "type": "uint64"
        },
        {
            "name": "email",
            "type": "string"
        }
    ]
}

Course Completion

Use the type name courseCompletionExample to be able to create credentials with the following schema:

Course {
    course: string;
    grade: string;
}

This was the payload used to create the type:

{
    "credentialSubjectSchema": [
        {
            "name": "course",
            "type": "string"
        },
        {
            "name": "grade",
            "type": "string"
        }
    ]
}

WalletOwnership

Use the type name walletOwnershipExample to be able to create credentials with the following schema:

WalletOwnership {
    address: string;
    ownerName: address;
    userId: uint256;
}

This was the payload used to create the type:

{
    "credentialSubjectSchema": [
        {
            "name": "address",
            "type": "string"
        },
        {
            "name": "ownerName",
            "type": "address"
        },
        {
            "name": "userId",
            "type": "uint256"
        }
    ]
}

Types Creation Quickstart

This example create a custom type for a credential that represents a course completion. The credential will contain two fields: course and passed.

Copy the createType.js file in the tab above, add your API key generated in previous step to the X-API-KEY header and run via node.

node createType.js

You can also use a tool like Postman or even our API playground for these API calls.

You’ll get back a response that includes an name value. This represents your custom type that will be used when you create your template.

Create a type

To create a credential type you need to call our API specifying a schema for the credential subject. The subject address field is already present in the base VerifiableCredential type.

{
    "credentialSubjectSchema": [
        // Cannot change this field name, "credentialSubjectSchema"
        { "name": "username", "type": "string" },
        { "name": "courses_completed", "type": "uint64" }
    ]
}

You can use:

  • POST https://staging.crossmint.com/api/unstable/credentials/types will create a new type with a random uuid.
  • PUT https://staging.crossmint.com/api/unstable/credentials/types/{yourTypeName} to specify the name of the type that is going to be created.

The response will contain the credential type name.

The possible types for each fiels are:

  • bool
  • uint8
  • uint16
  • uint32
  • uint64
  • uint128
  • uint256
  • address
  • string
  • string[]
  • bytes
  • bytes32
  • CustomObject
  • CustomObject[] (array of CustomObject is supported)

Get a Credential Type

GET https://staging.crossmint.com/api/unstable/credentials/types/{credentialTypeName}

Create complex types

To define a complex object, add the nested object’s schema to the type array.

{
    "credentialSubjectSchema": [
        {
            "name": "username",
            "type": "string"
        },
        {
            "name": "courses_completed",
            "type": "uint64"
        },
        {
            "name": "courses",
            "type": "Course[]"
        }
    ],
    "Course": [
        {
            "name": "name",
            "type": "string"
        },
        {
            "name": "grades",
            "type": "uint64[]"
        },
        {
            "name": "class",
            "type": "Class"
        }
    ],
    "Class": [
        {
            "name": "name",
            "type": "string"
        },
        {
            "name": "teacher",
            "type": "string"
        }
    ]
}

Type Enforcement

All credentials inside a template must match the schema. Trying to issue or verify a credential with different fields name or type will result in an error