kbc-verifier

Kingsland Blockchain Certificate Verifier

Usage no npm install needed!

<script type="module">
  import kbcVerifier from 'https://cdn.skypack.dev/kbc-verifier';
</script>

README

Kingsland Blockchain Certificate Verifier

Library that verifies Kingsland Blockchain Certificate JSON.

Installation

run:
npm install kbc-verifier --save

Getting started

add to js files:
cjs: const { Verifier } = require('kbc-verifier');
esm: import { Verifier } from 'kbc-verifier';

manual add from project:
cjs: const { Verifier } = require('./kbc-verifier/lib/cjs/index.js');
esm: import { Verifier } from './kbc-verifier/lib/esm/index.js';

Usage

const { Verifier } = require('kbc-verifier');

const verifier = new Verifier({
  etherScanApiKey: '[YOUR API KEY HERE]'
});

(async () => {

  // this is a sample unofficial certificate
  const certificate = {
    "signature": {
      "merkle": null,
      "payloadHash": "b3892c90df99c7e50c14406376cf648eb90dc598"
    },
    "payload": {
      "@data": {
        "email": "jamesbond@example.com",
        "fname": "James",
        "lname": "Bond",
        "issueDate": "2021-05-28T05:33:20.387Z"
      },
      "@institutionAddress": "0xb3b7681369e0e1f0a53b75feafe1292e57926da5",
      "@issuers": [
        "02930a80957a410aab3e3be3db5b782f6d15ac9c",
        "79e1e98e63e28f4b58c224123eaa0309264b937f"
      ],
      "@certificateVersion": 1,
      "@signatories": [
        {
          "fullname": "Example Name",
          "designation": "Director"
        }
      ],
      "@course": {
        "name": "Zero to Blockchain Q1",
        "modules": [
          {
            "name": "Programming Basics",
            "displayName": "Programming Basics",
            "topics": [
              {
                "hours": 3,
                "name": "Intro to programming"
              },
              {
                "hours": 3,
                "name": "Expressions and Statements"
              }
            ]
          }
        ]
      },
      "@template": {
        "name": "Certified Full Stack Developer",
        "type": "Remote Modular"
      }
    }
  };

  try {
    // A. Certificate integrity validation
    const integrityValidation = await verifier.validateIntegrity(certificate);
    console.log(integrityValidation);
    // { valid: true, error: null }


    // B. Institution Contract Validation
    const institutionValidation = await verifier.validateInstitution(certificate);
    console.log(institutionValidation);
    // { valid: true, error: null }


    // C. Issuers Validation
    const issuersValidation = await verifier.validateIssuers(certificate);
    console.log(issuersValidation);
    // { valid: true, error: null }


    // D. Merkle Hash State Validation
    const merkleValidation = await verifier.validateMerkle(certificate);
    console.log(merkleValidation);
    // { valid: true, error: null }


    // E. Certificate Hash State Validation
    const stateValidation = await verifier.validateState(certificate);
    console.log(stateValidation);
    // { valid: false, error: 'Certificate is not officially issued.' }
  }
  catch (e) {
    // something went wrong with validation
    // check internet connection
    // check api key
    // either super admin address or an institution address is not a smart contract
    console.error(e);
  }
})();

Verifier Class

Constructor Parameter
  • param.network {string} - code name of network to use. default: homestead
  • param.etherScanApiKey {string} - API key for ether scan
Methods
  • getAdminContract() {Contract} - gets the ethers.Contract instance of super admin.

  • getInstitutionContract(certificate) {Contract} - gets the ethers.Contract instance of the certificate's institution.

    • certificate {Certificate} - certificate json/object.
  • getAddressTransactions(address) - gets all the transactions of the given address.

    • address {string} - address of account
  • getInstitutionState(certificate) {Promise<InstitutionState | null>} - gets the state of institution address from super admin contract.

    • certificate {Certificate} - certificate json/object.
  • getInstitutionData(certificate) {Promise<InstitutionData | null>} - gets institution data from it's address (contract).

    • certificate {Certificate} - certificate json/object.
  • getIssuerData(certificate, issuerAddress) {Promise<IssuerData | null>} - gets issuer data from institution contract.

    • certificate {Certificate} - certificate json/object.
    • issuerAddress {string} - specific address of issuer from the certificate's payload.
  • getCertificateState(certificate) {Promise<{[key: string]: any}>} - gets the state of certificate.

    • certificate {Certificate} - certificate json/object.
  • validateIntegrity(certificate) {Promise} - validates the integrity if the payload.

    • certificate {Certificate} - certificate json/object.
  • validateInstitution(certificate) {Promise} - validates the institution.

    • certificate {Certificate} - certificate json/object.
  • validateIssuers(certificate) {Promise} - validates the certificate's issuers.

    • certificate {Certificate} - certificate json/object.
  • validateMerkle(certificate) {Promise} - validates the merkle root if merkle exists.

    • certificate {Certificate} - certificate json/object.
  • validateState(certificate) {Promise} - validates the state of certificate.

    • certificate {Certificate} - certificate json/object.
  • validate(certificate) {Promise} - straight forward one call validation

    • certificate {Certificate} - certificate json/object.

Interfaces / Types

interface InstitutionData {
  institutionName: string
  physicalAddress: string
  website: string
  contact: string
}
interface InstitutionState {
  isApproved: boolean
  revokedOn: number
}
interface IssuerData {
  address: string
  fullIssuerName: string
  isActive: boolean
  revokedOn: number
}
interface VerifierValidationResult {
  valid: boolean
  error: string | null
}
interface Transaction {
  blockNumber: string
  timeStamp: string
  hash: string
  nonce: string
  blockHash: string
  transactionIndex: string
  from: string
  to: string
  value: string
  gas: string
  gasPrice: string
  isError: string
  txreceipt_status: string
  input: string
  contractAddress: string
  cumulativeGasUsed: string
  gasUsed: string
  confirmations: string
}