Certificates

Certificate related functions.

In the VeChainThor blockchain, a certificate is a data structure used for client-side self-signed certificates. It plays a crucial role in providing a mechanism for secure identification and validation of data.

Purpose of Certificates

Certificates are primarily used for purposes like attestation, validation, and verification of data authenticity. They are used as proofs of authenticity and origin for data exchanged within the VeChain ecosystem.

Structure of a Certificate

A Certificate in the VeChainThor blockchain typically consists of the following components:

  1. Purpose: The purpose field indicates the intended use or context of the certificate. For example, it could be used for identification, verification, or attestation.

  2. Payload: The payload field holds the actual content of the certificate. This content can be of various types, such as text, images, or other data.

  3. Domain: The domain field represents the specific context or domain for which the certificate is valid. It helps ensure that the certificate is only applicable within the intended context.

  4. Timestamp: The timestamp field records the time at which the certificate was created or issued. This provides a temporal reference for the certificate's validity.

  5. Signer: The signer field indicates the address of the entity that signs the certificate. It is the public key address of the entity that issues the certificate.

  6. Signature: The signature field contains the cryptographic signature generated by the issuer's private key. This signature ensures the integrity and authenticity of the certificate's content.

Usage of Certificates

Certificates are used in various scenarios within the VeChainThor blockchain, including:

  • Proof of Authenticity: Certificates can be used to prove the authenticity and origin of data, ensuring that the data has not been tampered with or altered.

  • Identification: Certificates can be employed to establish the identity of a specific entity or participant within the blockchain ecosystem.

  • Verification: Certificates can be used to verify the validity of data or transactions, providing a mechanism for trust and validation.

Self-Signed Certificates

It's important to note that certificates in the VeChainThor blockchain are self-signed, which means that they are issued and signed by the same entity or user. The signature from the issuer's private key serves as proof of the certificate's authenticity.

import { Certificate, secp256k1, blake2b256, address } from 'thor-devkit'

// Generate a private key and address for the signer
const privateKey = secp256k1.generatePrivateKey()
const publicKey = secp256k1.derivePublicKey(privateKey)
const signerAddress = address.fromPublicKey(publicKey)

// Create a certificate
const cert = {
    purpose: 'identification',
    payload: {
        type: 'text',
        content: 'fyi'
    },
    domain: 'localhost',
    timestamp: 1545035330,
    signer: signerAddress
}

// Sign certificate
const jsonStr = Certificate.encode(cert)
const signature = secp256k1.sign(blake2b256(jsonStr), privateKey)

// Add 0x to signature
cert.signature = '0x' + signature.toString('hex')

// Verify certificate
Certificate.verify(cert)

// Get certificate id
const id = '0x' + blake2b256(Certificate.encode(cert)).toString('hex')
console.log(id)
// 0x0...

Last updated