Skip to content

Template Service

The Template Service allows you to manage and search Credential Templates.

Templates are optional

Templates are designed to be a helpful abstraction over the complexities of producing valid JSON-LD Verifiable Credentials.

You aren't required to use templates; if you produce valid JSON-LD VCs yourself, they can be issued through Trinsic.


Create Template

Creates a new credential template.

In the background, Trinsic will also generate and save a valid JSON-LD Context and schema for your template.

trinsic template create --name 'My Credential' --fields-data '{\"field1\":{}}'
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 trinsic.Template.CreateAsync(templateRequest);
template = await trinsic_service.template.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 := &template.CreateCredentialTemplateRequest{Name: fmt.Sprintf("Example Template - %s", uuid.New()), AllowAdditionalFields: false, Fields: make(map[string]*template.TemplateField)}
templateRequest.Fields["firstName"] = &template.TemplateField{Description: "Given name"}
templateRequest.Fields["lastName"] = &template.TemplateField{}
templateRequest.Fields["age"] = &template.TemplateField{Type: template.FieldType_NUMBER, Optional: true}

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

Request to create a new template
name
string
Name of new template
fields
map(string -> TemplateField)
Fields which compose the template
Show child attributes
allow_additional_fields
bool
Whether credentials may be issued against this template which have fields not specified in fields

Response to CreateCredentialTemplateRequest
data
Created template
Show child attributes


Get Template

Fetches a template definition by id.

trinsic template get --id <TEMPLATE_ID>
var getTemplateResponse = await trinsic.Template.GetAsync(new() { Id = template.Data.Id });
get_template_response = await trinsic_service.template.get(
    request=GetCredentialTemplateRequest(id=template.data.id)
)
getResponse, err := trinsic.Template().Get(context.Background(), &template.GetCredentialTemplateRequest{Id: templateResponse.Data.Id})
var getResponse =
    trinsic.template().get(GetCredentialTemplateRequest.newBuilder().setId(id).build()).get();

Request to fetch a template by ID
id
string
ID of template to fetch

Response to GetCredentialTemplateRequest
template
Template fetched by ID
Show child attributes


Delete Template

Deletes a credential template by id.

trinsic tamplate delete --id <TEMPLATE_ID>
var deleteTemplateResponse = await trinsic.Template.DeleteAsync(new() { Id = template.Data.Id });
delete_template_response = await trinsic_service.template.delete(
    request=DeleteCredentialTemplateRequest(id=template.data.id)
)
deleteResponse, err := trinsic.Template().Delete(context.Background(), &template.DeleteCredentialTemplateRequest{Id: templateResponse.Data.Id})
var deleteResponse =
    trinsic
        .template()
        .delete(DeleteCredentialTemplateRequest.newBuilder().setId(id).build())
        .get();

Request to delete a template by ID
id
string
ID of template to delete

Response to DeleteCredentialTemplateRequest
This message has no fields


Search Templates

Searches all templates defined in the current ecosystem, and a continuation_token to paginate large result sets.

If no query is specified, this call by default returns the first 100 templates.

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

Request to search templates using a SQL query
query
string
SQL query to execute. Example: SELECT * FROM c WHERE c.name = 'Diploma'
continuation_token
optional string
Token provided by previous SearchCredentialTemplatesResponse if more data is available for query

Response to SearchCredentialTemplatesRequest
items_json
string
Raw JSON data returned from query
has_more
bool
Whether more results are available for this query via continuation_token
continuation_token
string
Token to fetch next set of results via SearchCredentialTemplatesRequest

The Search endpoint supports SQL queries through the query parameter.

This allows for arbitrary query predicates, as well as more advanced functionality -- such as modifying the output format.

Schema

Any table name may be used in your query (we use c here) -- it doesn't matter what it is.

Name Type Description
id string Corresponds to the id returned when template was created
type string Always VerifiableCredential
ecosystemId string ID of ecosystem in which template resides
createdBy string ID of account which defined the template
name string Name provided during template creation
schemaUri string HTTPS URL pointing to JSON Schema generated by Trinsic for this template
contextUri string HTTPS URL pointing to JSON-LD Context generated by Trinsic for this template
version int Version of template; increments whenever template is modified.
fields object JSON Object representing the template's fields

Note that fields is an object, not a string; thus, any of its sub-fields may be queried against.

More Info

This endpoint works very similarly to querying Wallet items; please see Wallet Service > Search for more information.