lblod-blockchain

2.0.1 • Public • Published

LBLOD

Proof of concept rond Lokale Besluiten als Gelinkte Open Data – centrale vindplaats en mandatendatabank.

Repo structure

  • dist: this contains the transpiled version of the repo
  • src: this contains the actual code
    • utils
      • api
        • apiService: exposing all services
        • identityService: all interactions with identities
        • queryService: all interactions with queries
        • transaction: all transaction implementations
      • connection: class to instantiate a connection
      • ErrorMessages: export for all error messages
      • lblod: main package exposing all functionalities
      • wallets: all possible wallets
    • index: exporting of the package

Features

  • Creating a connection to the Rest API
  • Publishing a certain asset (Besluit) to the HLF network
  • Signing (voting) for a certain asset (Besluit) and register this action on the network
  • Validating/Compare an existing asset on the network with a given asset
  • Getting a certain asset by asset Id

Requirements

LBLOD Blockchain PoC API References

Getting started

First you need to get lblod into your project. This can be done using the following methods:

  • npm: npm install lblod-blockchain
  • bower: bower install lblod-blockchain
  • meteor: meteor add vo-blockchain:lblod-blockchain
  • vanilla: link the dist/index.js

LBLOD constructor

Parameters
  1. String - The token to the rest API (Obtained through the network admin)
  2. String - The baseURL to the Rest API (Obtained through the network admin)
  3. Boolean - Indicator whether development mode is enabled or not
Returns

LBLOD-Blockchain instance on which you can call any function specified below.

Example
import LBLOD from 'lblod-blockchain';
 
const lblod = new LBLOD('my-api-token', 'api-base-url', false);

publishBesluit

Parameters
  1. String - The id of the besluit (Uri typically)
  2. String - The besluit which should be hashed (Object must be able to be stringified)
Returns

Promise - Returns the transactionId of the publication on the blockchain

Example
import LBLOD from 'lblod-blockchain';
 
// besluit MUST be processable by a stringifier and should be a JSON file
const myBesluit = besluit.toJSON();
 
const lblod = new LBLOD('my-api-token', 'api-base-url', false);
const txId = await lblod.publishBesluit('my-besluit-id', myBesluit);

signBesluit

Parameters
  1. boolean - The choice which is made (true = authenticate, false = burn)
  2. String - The transactionId return from the function "publishBesluit" within this package
  3. String - The assign signer to perform the action on. Signers are obtained through the wallets export
Returns

Promise - Returns the transactionId of the sign action on the blockchain

Example
import LBLOD, { wallets } from 'lblod-blockchain';
 
// besluit MUST be processable by a stringifier and should be a JSON file
const myBesluit = besluit.toJSON();
 
// I choose to AUTHENTICATE the asset. True = Authenticate, False = Burn
const myChoice = true;
 
const lblod = new LBLOD('my-api-token', 'api-base-url', false);
const txId = await lblod.publishBesluit('my-besluit-id', myBesluit);
 
const result = await lblod.signBesluit(choice, txId, wallets.signer);

validateBesluit

Parameters
  1. txId - The transactionId return from the function "publishBesluit" within this package
  2. String - The besluit which should be hashed and compared to the original besluit (Object must be able to be stringified)
Returns

Promise - Returns a promise with True or False depending on the comparing results

Example
import LBLOD from 'lblod-blockchain';
 
// besluit MUST be processable by a stringifier and should be a JSON file
const myBesluit = besluit.toJSON();
 
// fakeBesluit MUST also be processable by a stringifier and should be a JSON file.
// This process should be the EXACT same operations as the process which
// the original published besluit went through to be able to replicate the same hash and result
const myFakeBesluit = fakeBesluit.toJSON();
 
const lblod = new LBLOD('my-api-token', 'api-base-url', false);
const txId = await lblod.publishBesluit('my-besluit-id', myBesluit);
 
const result = await lblod.validateBesluit(txId, myFakeBesluit);
console.log('Is myFakeBesluit tampered? ', result);

Full implementation example

This is an example of a service layer in your frontend application which implements all functionalities of this NPM package.

import LBLOD, { wallets }  from 'lblod-blockchain';
 
export default class hlfService {
 
  constructor(token){
    this.lblod = new LBLOD(token);
  }
 
  publishBesluit = (besluitId, besluit) => {
    return this.lblod.publishBesluit(besluitId, besluit, wallets.publisher);
  };
 
  sign = (choice, txId, signer) => {
    return this.lblod.signBesluit(choice, txId, signer);
  };
 
  validate = (txId, besluit) => {
    return this.lblod.validateBesluit(txId, besluit);
  };
 
  getAssetById = (txId) => {
    return this.lblod.getBesluitById(txId);
  };
}
 

Important note
- This is project is not intended to be used in any production environment as this is a Proof Of Concept and is not ready for production.
- As identity management is out of the scope of this project, all identities are handled in this package. This is NOT applicable for production and MUST be refactored
- Error handling is not included in the code examples, but don't forget to implement these with the proper try-catches or when using .then chaining, with .catch

Readme

Keywords

Package Sidebar

Install

npm i lblod-blockchain

Weekly Downloads

0

Version

2.0.1

License

AGPL-3.0

Unpacked Size

62.9 kB

Total Files

32

Last publish

Collaborators

  • dalderupmaurice