Verify digital signature
Signature verification
- Typescript
- Python
- Java
- PHP
- Golang
import {
AuthenticityClient,
KeyClient,
KeyType,
RecordClient,
Signer,
} from '@bloock/sdk';
const keyClient = new KeyClient();
const authenticityClient = new AuthenticityClient();
const recordClient = new RecordClient();
const key = await keyClient.newLocalKey(KeyType.EcP256k);
const signedRecord = await recordClient
.fromString('Hello world')
.withSigner(new Signer(key))
.build();
const valid = await authenticityClient.verify(signedRecord);
if (valid) {
console.log('Signature was verified successfully');
}
from bloock.client.authenticity import AuthenticityClient
from bloock.client.record import RecordClient
from bloock.client.key import KeyClient
from bloock.entity.key.key_type import KeyType
from bloock.entity.authenticity.signer import Signer
if __name__ == "__main__":
record_client = RecordClient()
authenticity_client = AuthenticityClient()
key_client = KeyClient()
key = key_client.new_local_key(KeyType.EcP256k)
signed_record = (
record_client.from_string("Hello world")
.with_signer(Signer(key))
.build()
)
valid = authenticity_client.verify(signed_record)
if valid:
print("Signature was verified successfully")
import java.util.List;
import com.bloock.sdk.client.AuthenticityClient;
import com.bloock.sdk.client.KeyClient;
import com.bloock.sdk.client.RecordClient;
import com.bloock.sdk.entity.authenticity.Signer;
import com.bloock.sdk.entity.key.KeyType;
import com.bloock.sdk.entity.key.LocalKey;
import com.bloock.sdk.entity.record.Record;
public class Verify {
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 Signer(localKey))
.build();
boolean valid = authenticityClient.verify(signedRecord);
if (valid) {
System.out.println("Signature was verified successfully");
}
}
}
<?php
require "./vendor/autoload.php";
use Bloock\Bloock;
use Bloock\Client\AuthenticityClient;
use Bloock\Client\KeyClient;
use Bloock\Client\RecordClient;
use Bloock\Entity\Authenticity\Signer;
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 Signer($keys, "some name"))
->build();
$valid = $authenticityClient->verify($signedRecord);
if ($valid) {
print "Signature was verified successfully";
}
package main
import (
"fmt"
"log"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity/authenticity"
"github.com/bloock/bloock-sdk-go/v2/entity/key"
)
func main() {
recordClient := client.NewRecordClient()
authenticityClient := client.NewAuthenticityClient()
keyClient := client.NewKeyClient()
key, err := keyClient.NewLocalKey(key.EcP256k)
if err != nil {
log.Println(err)
}
signedRecord, err := recordClient.FromString("Hello world").
WithSigner(authenticity.NewSignerWithLocalKey(key, nil)).
Build()
if err != nil {
log.Println(err)
}
valid, err := authenticityClient.Verify(signedRecord)
if err != nil {
log.Println(err)
}
if valid {
fmt.Println("Signature was verified successfully")
}
}