Skip to content

Template Service

Credential Templates are JSON templates that help issuers save context when issuing credentials.

When issuing a credential through Trinsic, it's as simple as adding the attributes to the credential template and then issuing it.

These credential templates can be shared between issuers in an ecosystem.

Create Template

Creates a new credential template. Once created, the template is saved in JSON-LD format that can be used to issue and verify credentials.

trinsic template create --name 'My Credential' --fields-data '{\"field1\":{}}'

When using one of the SDKs, you must supply a Create Credential Template Request object. This object follows the model below:

Request to create a new template

Field Type Description
name string Name of new template
fields CreateCredentialTemplateRequest.FieldsEntry[] Fields which compose the template
allow_additional_fields bool Whether credentials may be issued against this template which have fields not specified in fields

Then you can supply it to SDK:

const credentialTemplateName = `My First Credential Template-${uuid()}`;
const nameField = TemplateField.fromPartial({
  description: "The name of the person",
  type: FieldType.STRING,
  optional: false,
});

const numberOfBags = TemplateField.fromPartial({
  type: FieldType.NUMBER,
  description: "The number of bags the person is taking on the trip",
  optional: false,
});

const dateOfBirth = TemplateField.fromPartial({
  type: FieldType.DATETIME,
  description: "The date of birth of the person",
  optional: false,
});

const isVaccinated = TemplateField.fromPartial({
  type: FieldType.BOOL,
  description: "Whether or not the person has been vaccinated",
  optional: false,
});
CreateCredentialTemplateRequest templateRequest = new() {
    Name = "An Example Credential",
    AllowAdditionalFields = false
};
templateRequest.Fields.Add("firstName", new() {Description = "Given name"});
templateRequest.Fields.Add("lastName", new());
templateRequest.Fields.Add("age", new() {Optional = true}); // TODO - use FieldType.NUMBER once schema validation is fixed.

var template = await templateService.CreateAsync(templateRequest);
template = await template_service.create(
    request=CreateCredentialTemplateRequest(
        name=f"An Example Credential: {uuid.uuid4()}",
        allow_additional_fields=False,
        fields={
            "firstName": TemplateField(description="Given name"),
            "lastName": TemplateField(),
            "age": TemplateField(optional=True, type=FieldType.NUMBER),
        },
    )
)
templateRequest := &sdk.CreateCredentialTemplateRequest{Name: fmt.Sprintf("Example Template - %s", uuid.New()), AllowAdditionalFields: false, Fields: make(map[string]*sdk.TemplateField)}
templateRequest.Fields["firstName"] = &sdk.TemplateField{Description: "Given name"}
templateRequest.Fields["lastName"] = &sdk.TemplateField{}
templateRequest.Fields["age"] = &sdk.TemplateField{Type: sdk.FieldType_NUMBER, Optional: true}

template, err := templateService.Create(context.Background(), templateRequest)
var fields = new HashMap<String, Templates.TemplateField>();
fields.put("firstName", Templates.TemplateField.newBuilder().setDescription("Given name").build());
fields.put("lastName", Templates.TemplateField.newBuilder().build());
fields.put("age", Templates.TemplateField.newBuilder().setType(Templates.FieldType.NUMBER).setOptional(true).build());
var templateRequest = Templates.CreateCredentialTemplateRequest.newBuilder().setName("My Example Credential-" + UUID.randomUUID()).setAllowAdditionalFields(false).putAllFields(fields).build();
var template = templateService.create(templateRequest).get();

The response model is of type Create Credential Template Response:

Response to CreateCredentialTemplateRequest

Field Type Description
data TemplateData Created template

Get

Get the specified credential template through the supplied template/definition ID.

trinsic template get --id <TEMPLATE_ID>

When using one of the SDKs, you must supply a Get Credential Template Request object. This object follows the model below:

Request to fetch a template by ID

Field Type Description
id string ID of template to fetch

Then you can supply it to SDK:

var getTemplateResponse = await templateService.GetAsync(new() {Id = template.Data.Id});
get_template_response = await template_service.get(
    request=GetCredentialTemplateRequest(id=template.data.id)
)
getResponse, err := templateService.Get(context.Background(), &sdk.GetCredentialTemplateRequest{Id: template.Data.Id})
var getResponse = templateService.get(Templates.GetCredentialTemplateRequest.newBuilder().setId(id).build()).get();

The response model is of type Get Credential Template Response:

Response to GetCredentialTemplateRequest

Field Type Description
template TemplateData Template fetched by ID

Search / Query

Querying template data in our SDK is enabled through the use of familiar SQL syntax. All data is stored in JSON-LD format, so it can be easily searched. This approach allows us to give developers full control over how data is retrieved. In addition to customizable sorting, paging and filtering, developers have the ability to construct projections, combine result sets, and even run user-defined functions over their queries.

This endpoint will support querying using Verifiable Presentation Request Spec . This feature is still in development.

Template searching works very similarly to Wallet searching. Please refer to Wallet Service > Search / Query for more information.

The default query used in the commands below returns the first 100 items in the template result set. The query is SELECT * FROM c OFFSET 0 LIMIT 100.

trinsic template search

To pass custom query to the search function, use the query parameter or the available overload.

trinsic wallet search \
    --query "SELECT * FROM c"
var searchTemplateResponse = await templateService.SearchAsync(new() {Query = "SELECT * FROM c"});
search_template_response = await template_service.search(
    request=SearchCredentialTemplatesRequest(query="SELECT * FROM c")
)
searchResponse, err := templateService.Search(context.Background(), &sdk.SearchCredentialTemplatesRequest{Query: "SELECT * FROM c"})
var searchResponse = templateService.search(Templates.SearchCredentialTemplatesRequest.newBuilder().setQuery("SELECT * FROM c WHERE c.id = '" + id + "'").build()).get();

Delete

Deletes a credential template.

trinsic tamplate delete --id <TEMPLATE_ID>

When using one of the SDKs, you must supply a Delete Credential Template Request object. This object follows the model below:

Request to delete a template by ID

Field Type Description
id string ID of template to delete

Then you can supply it to SDK:

var deleteTemplateResponse = await templateService.DeleteAsync(new() {Id = template.Data.Id});
delete_template_response = await template_service.delete(
    request=DeleteCredentialTemplateRequest(id=template.data.id)
)
deleteResponse, err := templateService.Delete(context.Background(), &sdk.DeleteCredentialTemplateRequest{Id: template.Data.Id})
var deleteResponse = templateService.delete(Templates.DeleteCredentialTemplateRequest.newBuilder().setId(id).build()).get();