npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kbc-verifier

v1.3.9

Published

Kingsland Blockchain Certificate Verifier

Downloads

19

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": "[email protected]",
        "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
}