Create Schema
Next, we must think about what type of credentials we want to issue. For example, we want to issue a card that identifies BLOOCK employees. In order to create the schema I have to follow these steps.
- I must first think about the name of the schema type, in this case for example it would be BloockEmployee.
- I must define what attributes my credential will have, for example, I will put an employee number, name and date of birth.
Once this is defined, I will be able to create my schema. Notice that all we are doing is defining the attributes that our credentials will have.
The schemas are uploaded to IPFS, in order to identify the schemas we use their IPFS identifier.
Example: QmadTvnNKvj2fBDgen35uAp1TfP9pSPVCNeDWw4fitqqne
Examples
- Typescript
- Python
- Java
- PHP
- Golang
import { Bloock, IdentityClient } from '@bloock/sdk';
try {
// we set the API key and create a client
Bloock.setApiKey(process.env['API_KEY'] || "");
// we set de identity managed API host you have deployed
Bloock.setIdentityApiHost(process.env['IDENTITY_MANAGED_API_HOST'] || "");
// initialize the IdentityClient
const identityClient = new IdentityClient();
// we create the Schema, passing Schema information
const schemaName = "Bloock Employee"; // name Schema. REQUIRED.
const schemaType = "BloockEmployee"; // we defined the Schema type, basically you could use the name but in CamelCase. REQUIRED.
const schemaVersion = "1.0"; // Schema version. REQUIRED. By default you can set "1.0".
const schemaDescription = "BLOOCK Employee would be the new credential for BLOOCK employees"; // Schema description. REQUIRED.
const schema = await identityClient
.buildSchema(schemaName, schemaType, schemaVersion, schemaDescription)
.addIntegerAttribute("Number", "number", "indicates the employee number associated", true)
.addDecimalAttribute("Salary", "salary", "indicates the employee salary", true)
.addStringAttribute("NIF", "nif", "indicates the employee nif", true)
.addBooleanAttribute("Previous Formation", "previous_formation", "indicates if the employee has or not previous formation", true)
.addDateAttribute("Birth Date", "birth_date", "the employee birth date", true)
.addDateTimeAttribute("Time Registered", "time_registered", "indicates the date and time the employee was registered", true)
.addStringEnumAttribute("Country", "country", "to know if the employee is from one of the following", true, ["spain", "portugal", "france"])
.addIntegerEnumAttribute("Brother", "brother", "the employee number of brothers", true, [1, 2, 3])
.addDecimalEnumAttribute("Heigt", "height", "the employee aprox height", true, [1.50, 1.70, 1.90])
.build();
// returns a Schema entity
console.log(schema.cid) // Schema identifier generated from IPFS. Ex: QmadTvnNKvj2fBDgen35uAp1TfP9pSPVCNeDWw4fitqqne.
console.log(schema.cidJsonLd) // Schema in JSON-LD representation. Gives you extra information about the context.
console.log(schema.json) // represents the Schema JSON.
console.log(schema.schemaType) // the Schema type defined above.
} catch (e) {
console.log(e);
}
import os
import bloock
from bloock.client.identity import IdentityClient
# we set the API key and create a client
bloock.api_key = os.environ["API_KEY"]
# we set de identity managed API host you have deployed
bloock.identity_api_host = os.environ["IDENTITY_MANAGED_API_HOST"]
# initialize the IdentityClient
identity_client = IdentityClient()
# we create the Schema, passing Schema information
# name Schema. REQUIRED
schema_name = "Bloock Employee"
# we defined the Schema type, basically you could use the name but in CamelCase. REQUIRED.
schema_type = "BloockEmployee"
# Schema version. REQUIRED. By default you can set "1.0".
schema_version = "1.0"
# Schema description. REQUIRED.
schema_desc = "BLOOCK Employee would be the new credential for BLOOCK employees"
schema = identity_client.build_schema(schema_name, schema_type, schema_version, schema_desc) \
.add_integer_attribute("Number", "number",
"indicates the employee number associated", True) \
.add_decimal_attribute("Salary", "salary",
"indicates the employee salary", True) \
.add_string_attribute("NIF", "nif",
"indicates the employee nif", True) \
.add_boolean_attribute("Previous Formation", "previous_formation",
"indicates if the employee has or not previous formation", True) \
.add_date_attribute("Birth Date", "birth_date",
"the employee birth date", True) \
.add_datetime_attribute("Time Registered", "time_registered",
"indicates the date and time the employee was registered", True) \
.add_string_enum_attribute("Country", "country",
"to know if the employee is from one of the following", True,
["spain", "portugal", "france"]) \
.add_integer_enum_attribute("Brother", "brother",
"the employee number of brothers", True, [1, 2, 3]) \
.add_decimal_enum_attribute("Heigt", "height",
"the employee aprox height", True, [1.50, 1.70, 1.90]) \
.build()
# returns a Schema entity
# Schema identifier generated from IPFS. Ex: QmadTvnNKvj2fBDgen35uAp1TfP9pSPVCNeDWw4fitqqne.
print(schema.cid)
# Schema in JSON-LD representation. Gives you extra information about the context.
print(schema.cid_json_ld)
# represents the Schema JSON.
print(schema.json)
# the Schema type defined above.
print(schema.schema_type)
import java.io.IOException;
import com.bloock.sdk.Bloock;
import com.bloock.sdk.client.IdentityClient;
import com.bloock.sdk.entity.identity.Schema;
import java.util.*;
public class CreateSchema {
public static void main(String[] args) throws Exception {
try {
// we set the API key and create a client
Bloock.apiKey = System.getenv("API_KEY");
// we set de identity managed API host you have deployed
Bloock.identityApiHost = System.getenv("IDENTITY_MANAGED_API_HOST");
// initialize the IdentityClient
IdentityClient identityClient = new IdentityClient();
// we create the Schema, passing Schema information
// name Schema. REQUIRED.
String schemaName = "Bloock Employee";
// we defined the Schema type, basically you could use the name but in
// CamelCase. REQUIRED.
String schemaType = "BloockEmployee";
// Schema version. REQUIRED. By default you can set "1.0".
String schemaVersion = "1.0";
// Schema description. REQUIRED.
String schemaDescription = "BLOOCK Employee would be the new credential for BLOOCK employees";
List<String> stringList = new ArrayList<>();
stringList.add("spain");
stringList.add("portugal");
stringList.add("france");
List<Long> integerList = new ArrayList<>();
integerList.add(1L);
integerList.add(2L);
integerList.add(30L);
List<Double> doubleList = new ArrayList<>();
doubleList.add(1.50);
doubleList.add(1.70);
doubleList.add(1.90);
Schema schema = identityClient
.buildSchema(
schemaName, schemaType, schemaVersion, schemaDescription)
.addIntegerAttribute("Number", "number", "indicates the employee number associated", true)
.addDecimalAttribute("Salary", "salary", "indicates the employee salary", true)
.addStringAttribute("NIF", "nif", "indicates the employee nif", true)
.addBooleanAttribute("Previous Formation", "previous_formation",
"indicates if the employee has or not previous formation", true)
.addDateAttribute("Birth Date", "birth_date", "the employee birth date", true)
.addDatetimeAttribute("Time Registered", "time_registered",
"indicates the date and time the employee was registered", true)
.addStringEnumAttribute("Country", "country",
"to know if the employee is from one of the following", true, stringList)
.addIntegerEnumAttribute("Brother", "brother", "the employee number of brothers", true, integerList)
.addDecimalEnumAttribute("Heigt", "height", "the employee aprox height", true, doubleList)
.build();
// returns a Schema entity
// Schema identifier generated from IPFS. Ex:
// QmadTvnNKvj2fBDgen35uAp1TfP9pSPVCNeDWw4fitqqne.
System.out.println(schema.getCid());
// Schema in JSON-LD representation. Gives you extra information about the
// context.
System.out.println(schema.getCidJsonLD());
// represents the Schema JSON.
System.out.println(schema.getJson());
// the Schema type defined above.
System.out.println(schema.getSchemaType());
} catch (Exception e) {
System.out.println(e);
}
}
}
<?php
use Bloock\Bloock;
use Bloock\Client\IdentityClient;
require "./vendor/autoload.php";
// we set the API key and create a client
Bloock::$apiKey = getenv("API_KEY") ?: "";
// we set de identity managed API host you have deployed
Bloock::$identityApiHost = getenv("IDENTITY_MANAGED_API_HOST") ?: "";
// initialize the IdentityClient
$identityClient = new IdentityClient();
// we create the Schema, passing Schema information
$schemaName = "Bloock Employee"; // name Schema. REQUIRED.
$schemaType = "BloockEmployee"; // we defined the Schema type, basically you could use the name but in CamelCase. REQUIRED.
$schemaVersion = "1.0"; // Schema version. REQUIRED. By default you can set "1.0".
$schemaDescription = "BLOOCK Employee would be the new credential for BLOOCK employees"; // Schema description. REQUIRED.
$schema = $identityClient->buildSchema($schemaName, $schemaType, $schemaVersion, $schemaDescription)
->addIntegerAttribute("Number", "number", "indicates the employee number associated", true)
->addDecimalAttribute("Salary", "salary", "indicates the employee salary", true)
->addStringAttribute("NIF", "nif", "indicates the employee nif", true)
->addBooleanAttribute("Previous Formation", "previous_formation", "indicates if the employee has or not previous formation", true)
->addDateAttribute("Birth Date", "birth_date", "the employee birth date", true)
->addDateTimeAttribute("Time Registered", "time_registered", "indicates the date and time the employee was registered", true)
->addStringEnumAttribute("Country", "country", "to know if the employee is from one of the following", true, ["spain", "portugal", "france"])
->addIntegerEnumAttribute("Brother", "brother", "the employee number of brothers", true, [1, 2, 3])
->addDecimalEnumAttribute("Heigt", "height", "the employee aprox height", true, [1.50, 1.70, 1.90])
->build();
// returns a Schema entity
$createdSchemaCID = $schema->getCid(); // Schema identifier generated from IPFS. Ex: QmadTvnNKvj2fBDgen35uAp1TfP9pSPVCNeDWw4fitqqne.
$createdSchemaCIDJsonLD = $schema->getCidJsonLd(); // Schema in JSON-LD representation. Gives you extra information about the context.
$createdSchema = $schema->getJson(); // represents the Schema JSON.
$createdSchema = $schema->getSchemaType(); // the Schema type defined above.
package main
import (
"log"
"os"
"github.com/bloock/bloock-sdk-go/v2"
"github.com/bloock/bloock-sdk-go/v2/client"
)
func main() {
// we set the API key and create a client
bloock.ApiKey = os.Getenv("API_KEY")
// we set de identity managed API host you have deployed
bloock.IdentityApiHost = os.Getenv("IDENTITY_MANAGED_API_HOST")
// initialize the IdentityClient
identityClient := client.NewIdentityClient()
// we create the Schema, passing Schema information
schemaName := "Bloock Employee" // name Schema. REQUIRED,
schemaType := "BloockEmployee" // we defined the Schema type, basically you could use the name but in CamelCase. REQUIRED.
schemaVersion := "1.0" // Schema version. REQUIRED. By default you can set "1.0".
schemaDescription := "BLOOCK Employee would be the new credential for BLOOCK employees" // Schema description. REQUIRED.
schema, err := identityClient.BuildSchema(schemaName, schemaType, schemaVersion, schemaDescription).
AddIntegerAttribute("Number", "number", "indicates the employee number associated", true).
AddDecimalAttribute("Salary", "salary", "indicates the employee salary", true).
AddStringAttribute("NIF", "nif", "indicates the employee nif", true).
AddBooleanAttribute("Previous Formation", "previous_formation", "indicates if the employee has or not previous formation", true).
AddDateAttribute("Birth Date", "birth_date", "the employee birth date", true).
AddDatetimeAttribute("Time Registered", "time_registered", "indicates the date and time the employee was registered", true).
AddStringEnumAttribute("Country", "country", "to know if the employee is from one of the following", true, []string{"spain", "portugal", "france"}).
AddIntegerEnumAttribute("Brother", "brother", "the employee number of brothers", true, []int64{1, 2, 3}).
AddDecimalEnumAttribute("Heigt", "height", "the employee aprox height", true, []float64{1.50, 1.70, 1.90}).
Build()
if err != nil {
log.Fatalln(err)
}
// returns a Schema entity
log.Println(schema.Cid) // Schema identifier generated from IPFS. Ex: QmadTvnNKvj2fBDgen35uAp1TfP9pSPVCNeDWw4fitqqne.
log.Println(schema.CidJsonLd) // Schema in JSON-LD representation. Gives you extra information about the context.
log.Panicln(schema.Json) // represents the Schema JSON.
log.Println(schema.SchemaType) // the Schema type defined above.
}