Create a draft
The VcDecorator
represents the entry point for the UDT model and the lifecycle of the credential (Create → Update → Issue → Present). This page covers the first step of the credential lifecycle - creating a draft resource.
Example: Create a draft with basic claims
The example below takes the previously defined basic credential schema, creates the VcDecorator
instance and adds claims to the Draft
resource:
- TypeScript
- Java
const vcDecoratorInstance = await client.createVcDecorator(ClaimsModelExample); // VcDecorator
const createdDraft = await vcDecoratorInstance.create({ // Draft<ClaimsModelExample>
claims: {
name: "Alice",
age: 30
}
});
VcDecorator<ClaimsModelExample> vcDecoratorInstance = client.vcDecorator(ClaimsModelExample.class);
ClaimsModelExample claimsModelData = new ClaimsModelExample();
claimsModelData.setName("Alice");
claimsModelData.setAge(30);
var createdDraft = vcDecoratorInstance.create(claimsModelData);
The createVcDecorator
method creates a new draft using the API and returns its representation (the Draft
instance). This returns a draft instance with the assigned claims model passed to the VcDecorator
. In the example above, it is the ClaimsModelExample
.
Once created, you can update the draft as needed or issue a verifiable credential (VC).
Example: Create a draft with date and date-time claims
The example below shows how to add date-based claims values the previously defined credential schema with dates:
- TypeScript
- Java
const vcDecoratorInstance = await client.createVcDecorator(ClaimsModelExample); // VcDecorator
const createdDraft = await vcDecoratorInstance.create({
claims: {
field1: new Rfc3339Date(1992, 10, 15),
field2: new Rfc3339DateTime(), // Current date and time
}
});
ClaimsModelExample claimsModelData = new ClaimsModelExample();
claimsModelData.setField1(LocalDate.of(1992, 10, 15));
claimsModelData.setField2(OffsetDateTime.now());
var createdDraft = vcDecoratorInstance.create(claimsModelData));
Remember these key points about working with Rfc3339DateTime
when passing it as a string:
- Always use UTC times (indicated by the
Z
at the end of the string representation). - Use the following format:
YYYY-MM-DDTHH:mm:ss.sssZ
.