Prepare data
The first step of the certification process is to prepare the data that you want to certify through BLOOCK.
This basically translates to load this data to the SDK, standardize it and compute a hash using the algorithm that BLOOCK uses internally (Keccak256). Luckily, all this process is done by the SDK internally so all you need to do is
The principal element of the BLOOCK SDKs is the Record as it's used on most of the functionalities. It's responsible for different interactions such as:
- Encapsulate your data
- Hashing
- Add self-contained metadata
In order to generate a Record, our SDKs provide different builders to do so. Those builders enable to set as input different data types, formats or encodings based on your needs.
Currently, the following builders are available:
Name | Description |
---|---|
fromString | It takes a UTF-8 string as input |
fromBytes | It takes an array of bytes as input |
fromHex | It takes a hash string (hex encoded 64-chars long string) as input |
fromJson | It takes a JSON as input |
fromRecord | It takes a record as input |
fromFile | It takes a file (as a byte array) as input |
fromLoader |
Javascript
Java
Python
PHP
Golang
const { RecordClient, Bloock } = require("@bloock/sdk");
const fs = require("fs");
try {
let recordClient = new RecordClient();
let record = await recordClient.fromString("Hello world").build();
// we can get the hash of the record
let hash = await record.getHash()
console.log(hash)
// build a record from an existing record
let record2 = await recordClient.fromRecord(record).build();
// we can read a file as an array of bytes
const file = fs.readFileSync('sample.pdf');
let record3 = await recordClient.fromFile(file).build();
} catch (e) {
console.log(e);
}
import java.nio.file.Files;
import java.nio.file.Paths;
import com.bloock.sdk.Bloock;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.Record;
class Test {
public static void main(String[] args) {
try {
RecordClient recordClient = new RecordClient();
Record record = recordClient.fromString("Hello world").build();
// we can get the hash of the record
String hash = record.getHash();
System.out.println(hash);
// build a record from an existing record
Record record2 = recordClient.fromRecord(record).build();
// we can read a file as an array of bytes
byte[] file = Files.readAllBytes(Paths.get("sample.pdf"));
Record record3 = recordClient.fromFile(file).build();
} catch (Exception e) {
System.out.println(e);
}
}
}
import os
import bloock
from bloock.client.record import RecordClient
record_client = RecordClient()
record = record_client.from_string("Hello world").build()
# we can get the hash of the record
hash = record.get_hash()
# build a record from an existing record
record2 = record_client.from_record(record).build()
# we can read a file as an array of bytes
with open("sample.pdf", "rb") as file:
data = bytes(file.read())
# and build a record from it
record3 = record_client.from_file(data).build()
<?php
require "./vendor/autoload.php";
use Bloock\Client\RecordClient;
$recordClient = new RecordClient();
$record = $recordClient->fromString("Hello world")->build();
$hash = $record->getHash();
$record2 = $recordClient->fromRecord($record)->build();
$file = file_get_contents('./fills.pdf');
$record3 = $recordClient->fromFile(unpack('C*', $file))->build();
import (
"log"
"os"
"github.com/bloock/bloock-sdk-go/v2"
"github.com/bloock/bloock-sdk-go/v2/client"
)
func main() {
recordClient := client.NewRecordClient()
record, err := recordClient.FromString("Hello world").Build()
if err != nil {
log.Println(err)
}
// we can get the hash of the record
hash, err := record.GetHash()
if err != nil {
log.Println(err)
}
log.Println(hash)
// build a record from an existing record
record2, err := recordClient.FromRecord(record).Build()
if err != nil {
log.Println(err)
}
// we can read a file as an array of bytes
file, err := os.ReadFile("sample.pdf")
if err != nil {
log.Println(err)
}
// and build a record from it
record3, err := recordClient.FromFile(file).Build()
if err != nil {
log.Println(err)
}
}
Last modified 2mo ago