BLOOCK Docs
Search
K

Signing

This is the base step for assuring data/document authenticity. Before starting, make sure to choose from one of the Supported methods that BLOOCK provides.
Javascript
Java
Python
Golang
PHP
const { AuthenticityClient, EcdsaSigner, KeyClient, RecordClient, KeyType } = require("@bloock/sdk");
(async () => {
let keyClient = new KeyClient();
let authenticityClient = new AuthenticityClient();
let recordClient = new RecordClient();
let key = await keyClient.newLocalKey(KeyType.EcP256k);
let signedRecord = await recordClient.fromString("Hello world")
.withSigner(new EcdsaSigner(key))
.build();
console.log("Record was signed successfully");
// we can add another signature with a different key
key = await keyClient.newLocalKey(KeyType.EcP256k);
console.log("Adding another signature");
signedRecord = await recordClient.fromRecord(signedRecord)
.withSigner(new EcdsaSigner(key))
.build();
console.log("Record was signed successfully");
console.log(`Hash: ${await signedRecord.getHash()}`);
let signatures = await authenticityClient.getSignatures(signedRecord);
signatures.forEach((signature, i) => {
console.log(`Signature ${i + 1}: ${JSON.stringify(signature, null, 4)}`);
});
})();
import com.bloock.sdk.client.AuthenticityClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.EcdsaSigner;
import com.bloock.sdk.entity.EcdsaKeyPair;
import com.bloock.sdk.entity.Record;
public class App {
public static void main(String[] args) throws Exception {
RecordClient recordClient = new RecordClient();
AuthenticityClient authenticityClient = new AuthenticityClient();
KeyClient keyClient = new KeyClient();
LocalKey localKey = keyClient.newLocalKey(KeyType.EcP256k);
Record signedRecord = recordClient
.fromString("Hello world")
.withSigner(new SignerArgs(localKey))
.build();
System.out.println("Record was signed successfully");
// we can add another signature with a different key
System.out.println("Adding another signature");
localKey = keyClient.newLocalKey(KeyType.EcP256k);
signedRecord = recordClient.fromRecord(signedRecord)
.withSigner(new EcdsaSigner(new SignerArgs(localKey)))
.build();
System.out.println("Record was signed successfully");
System.out.println("Hash: " + signedRecord.getHash());
authenticityClient
.getSignatures(signedRecord)
.stream()
.forEach(signature -> {
System.out.println("Signature " + signature.getSignature());
});
}
}
from bloock.client.authenticity import AuthenticityClient
from bloock.client.record import RecordClient
from bloock.client.entity.signer import EcdsaSigner
from bloock.client.key import KeyClient
authenticity_client = AuthenticityClient()
record_client = RecordClient()
key_client = KeyClient()
key = key_client.new_local_key(KeyType.EcP256k)
signed_record = (
record_client.from_string("Hello world")
.with_signer(EcdsaSigner(SignerArgs(key)))
.build()
)
print("Record was signed sucessfully")
# we can add another signature with a different key
key = key_client.new_local_key(KeyType.EcP256k)
print("Adding another signature")
signed_record = (
record_client.from_record(signed_record)
.with_signer(EcdsaSigner(SignerArgs(key)))
.build()
)
print("Record was signed sucessfully")
hash = signed_record.get_hash()
print(f"Hash: {hash}")
signatures = authenticity_client.get_signatures(signed_record)
for i, signature in enumerate(signatures):
print(f"Signature {i + 1}: {signature.__dict__}")
import (
"encoding/json"
"fmt"
"log"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity"
)
func main() {
keyClient := client.NewKeyClient()
recordClient := client.NewRecordClient()
authenticityClient := client.NewAuthenticityClient()
key, err := keyClient.NewLocalKey(key.EcP256k)
if err != nil {
log.Println(err)
}
signedRecord, err := recordClient.FromString("Hello world").
WithSigner(entity.NewEcdsaSigner(entity.SignerArgs{
LocalKey: &key,
})).
Build()
if err != nil {
log.Println(err)
}
fmt.Println("Record was signed successfully")
// we can add another signature with a different key
key, err = keyClient.NewLocalKey(key.EcP256k)
if err != nil {
log.Println(err)
}
fmt.Println("Adding another signature")
signedRecord, err = recordClient.FromRecord(signedRecord).
WithSigner(entity.NewEcdsaSigner(entity.SignerArgs{
LocalKey: &key,
})).
Build()
if err != nil {
log.Println(err)
}
fmt.Println("Record was signed successfully")
hash, err := signedRecord.GetHash()
if err != nil {
log.Println(err)
}
fmt.Printf("Hash: %+v" + hash)
signatures, err := authenticityClient.GetSignatures(signedRecord)
if err != nil {
log.Println(err)
}
for i, signature := range signatures {
prettySignature, _ := json.MarshalIndent(signature, "", " ")
fmt.Printf("Signature %d: %s\n", i+1, string(prettySignature))
}
}
<?php
require "./vendor/autoload.php";
use Bloock\Bloock;
use Bloock\Client\AuthenticityClient;
use Bloock\Client\KeyClient;
use Bloock\Client\RecordClient;
use Bloock\Entity\Authenticity\EcdsaSigner;
use Bloock\Entity\Authenticity\SignerArgs;
use Bloock\Entity\Key\KeyType;
Bloock::$apiKey = getenv("API_KEY");
$keyClient = new KeyClient();
$authenticityClient = new AuthenticityClient();
$recordClient = new RecordClient();
$keys = $keyClient->newLocalKey(KeyType::EcP256k);
$signedRecord = $recordClient->fromString("Hello world")
->withSigner(new EcdsaSigner(new SignerArgs($keys)))
->build();
print "Record was signed successfully\n";
$keys = $keyClient->newLocalKey(KeyType::EcP256k);
print "Adding another signature\n";
$signedRecord = $recordClient->fromRecord($signedRecord)
->withSigner(new EcdsaSigner(new SignerArgs($keys)))
->build();
print "Record was signed successfully\n";
$hash = $signedRecord->getHash();
print "Hash: $hash\n";
$signatures = $authenticityClient->getSignatures($signedRecord);