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
String
- The token to the rest API (Obtained through the network admin)String
- The baseURL to the Rest API (Obtained through the network admin)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
String
- The id of the besluit (Uri typically)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';
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
boolean
- The choice which is made (true = authenticate, false = burn)String
- The transactionId return from the function "publishBesluit" within this packageString
- 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';
const myBesluit = besluit.toJSON();
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
txId
- The transactionId return from the function "publishBesluit" within this packageString
- 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';
const myBesluit = besluit.toJSON();
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