Create Credential Types
Specify the schema that the Verifiable Credential adheres to
In the realm of Verifiable Credentials, each credential must be associated with a schema. The credential’s schema is referred to as “type”.
Credential types outline the attributes and their respective data types that the credential contains. The purpose of types is to ensure the credential’s authenticity. Types allow you to specify the attributes you are interested in certifying and act as a protective measure, preventing the addition of unauthorized attributes and, as a result, the tampering of the Verifiable Credential.
It’s important to note that all credentials within a single template will share the same type. Trying to issue or verify a credential with different field names or types will result in an error.
By adhering to this structure, we maintain the integrity and verifiability of the credentials, ensuring they serve their purpose effectively.
Example Types
Credentials play a crucial role in verifying and validating various aspects of identity, achievement, and authorization. Below are some examples of credential types you can create and manage through Crossmint:
Proof of Employment
- Purpose: Issued to individuals that want to prove their employment.
- Name:
ProofOfEmployment
The payload used to create this type is the following:
To reference this example type in your credential template definition, use crossmint:bfb292e7-2700-4924-9213-478f3d71f2d8:ProofOfEmployment
.
Course Completion Certificates
- Purpose: Issued to students upon the successful completion of a course. The certificate may indicate that the student has mastered a specific skill or knowledge.
- Type:
CourseCompletionCertificate
If you want to use this example type in your credential template definition, you can reference it as crossmint:bfb292e7-2700-4924-9213-478f3d71f2d8:CourseCompletionCertificate
.
Membership Credentials
- Purpose: Provided to individuals who are members of a specific organization or club. The certificate may grant access to exclusive resources and events.
- Name:
Membership
If you want to use this example type in your credential template definition, you can reference it as crossmint:bfb292e7-2700-4924-9213-478f3d71f2d8:Membership
.
Event Participation Certificates
- Purpose: Issued to individuals who attend or participate in specific events.
- Name:
EventParticipation
If you want to use this example type in your credential template definition, you can reference it as crossmint:bfb292e7-2700-4924-9213-478f3d71f2d8:EventParticipation
.
Types Creation Quickstart
This example creates a custom type, CourseCompletionCertificate
, 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 to the X-API-KEY
header (or create one if you haven’t already) and run via node.
The response, shown below, includes the credential type name.
The type id defined will be used when you create your credential template.
You can also utilize the POST /credentials/types/
endpoint to generate a random uuid for the new credential type.
For internal use within Crossmint, reference the type using id
. The $id
will be included as the credentials
schema by Crossmint but should not be used to reference the type in Crossmint APIs.
Example of a credentials using the type "crossmint:bfb292e7-2700-4924-9213-478f3d71f2d8:CourseCompletionCertificate"
just created.
Types Creation Deep Dive
In the realm of Verifiable Credentials, types are defined using the JSON schema. For more details, refer to the W3C VC JSON Schema. When calling the create type API an invalid JSON schema will result in an error.
Type schema structure
Below is an example of a JSON schema structure for defining a credential type:
Explanation of Each Part:
- $schema: This should always be set to “https://json-schema.org/draft/2020-12/schema”.
- $id: This field should NOT be defined, will be generated by Crossmint and returned in the response.
- title: Represents the name of the type.
- description: A brief description of the schema.
- type: Must be set to “object”.
- properties: Must include
credentialSubject
as an object.
Important Notes:
- The credential subject is the section that needs to be defined. Any field or nested field can be added, as long as it is valid JSON schema.
- The
credentialSubject.properties.id
will be automatically added with the type “string”, this is used to specify the wallet and therefore the identity of the subject. additionalProperties
should always be set tofalse
to prevent unauthorized fields from being added.- All specified fields should be marked as
required
unless they are optional. This ensures that missing fields will trigger an error during schema validation. additionalProperties
andrequired
apply only at the level they are specified. For nested objects, these need to be repeated.
Type import
If you already have a JSON schema type, you can easily import it by calling the same endpoint with the following structure:
Important Notes for Import:
- All notes for type creation apply here as well.
credentialSubject.properties.id
will not be added for imported schemas. If the original schema does not include this specification, the resulting credentials will not include the user wallet in thesubject.id
. To know the subject of a credential, checking the NFT owner will be necessary.
To follow along and test the API calls use a tool like Postman or our API playground.