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:
Examples
- Typescript
- Python
- Java
- PHP
- Golang
import { RecordClient } from '@bloock/sdk';
import fs from 'fs';
try {
const recordClient = new RecordClient();
const record = await recordClient.fromString('Hello world').build();
// we can get the hash of the record
const hash = await record.getHash();
console.log(hash);
// build a record from an existing record
const _record2 = await recordClient.fromRecord(record).build();
// we can read a file as an array of bytes
const file = fs.readFileSync('sample.pdf');
const _record3 = await recordClient.fromFile(file).build();
} catch (e) {
console.log(e);
}
from bloock.client.record import RecordClient
if __name__ == "__main__":
record_client = RecordClient()
record = record_client.from_string("Hello world").build()
# we can get the hash of the record
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()
import com.bloock.sdk.client.KeyClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.key.ManagedKey;
import com.bloock.sdk.entity.record.Record;
import java.nio.file.Files;
import java.nio.file.Paths;
public class PrepareRecord {
public static void main(String[] args) throws Exception {
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);
}
}
}
<?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();
package main
import (
"log"
"os"
"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
_, 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
_, err = recordClient.FromFile(file).Build()
if err != nil {
log.Println(err)
}
}