Reader small image

You're reading from  Blockchain Development for Finance Projects

Product typeBook
Published inJan 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781838829094
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Ishan Roy
Ishan Roy
author image
Ishan Roy

Ishan Roy leads the Blockchain initiative at the Centre of Excellence for Emerging Technologies (CEET) at the Tamil Nadu e-Governance Agency (TNeGA). He is currently working on the Tamil Nadu Blockchain Backbone project. His foray into blockchain began in the year 2016, at the blockchain team at ICICI Bank. This team carried out the first blockchain remittance in India. Since then he has worked as the Head of Products at HashCash Consultants where he built blockchain-enabled financial solutions for global clients. He has also mentored students and industry veterans as a blockchain trainer with Edureka. He is extremely passionate about technology and loves to keep himself abreast of new developments in the field through the community
Read more about Ishan Roy

Right arrow

Building a Tamper-Proof Document Storage System

Blockchain's inherent property of immutability makes it an excellent tool for securing information and records. Once stored in a blockchain, data cannot be modified or updated. This is due to the distributed nature of the and its use of hash functions and cryptography. In this chapter, we'll be leveraging this feature of blockchain to build a module that will secure the contents of a document repository. To achieve this, we'll be using Hyperledger Fabric 1.4. Our solution will record hash signatures for the documents within a repository on a private Hyperledger Fabric network. It will then monitor all the recorded files and check at fixed time intervals to see whether the files have been tampered with or modified. Additionally, it'll check whether any new files have been added or modified. If any changes have...

Technical requirements

You can access the code files of this chapter at the following GitHub link:

https://github.com/PacktPublishing/Blockchain-Development-for-Finance-Projects/tree/master/Chapter%207.

For this project, we'll be working with the Hyperledgic Fabric 1.4 binaries and Docker images provided in the Hyperledger Fabric GitHub repository.

You can find the step-by-step installation process at the following link:

https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html.

Hyperledger Fabric assumes that you have the following dependencies installed:

  • The latest version of the cURL tool
  • The latest versions of Docker and Docker Compose
  • Go version 1.12.x
  • Node.js version 10.15.3 or higher
  • Npm version 5.6.0 or higher
  • Python 2.7

After downloading and installing the dependencies, we need to download and install the binaries, samples, and docker images for Hyperledger...

Tamper-proof document storage using blockchain

The consensus algorithm of blockchains makes it virtually impossible to alter any data once it is stored in the blockchain. The consensus algorithm of a blockchain is an elaborate mechanism that ensures that the data captured on all the nodes in the blockchain network (the participating computers or servers that store a copy of the blockchain ledger) is uniform. This means that the data stored on each node, as well as the sequence in which the data is organized, is the same throughout all the nodes in the network.

This also means that once data is written or captured in a blockchain, it is virtually immutable—that is, it cannot be modified as long as the blockchain network remains unchanged. If the recorded data on one of the nodes is altered, the consensus algorithm prevents the altered data from being written to the other...

Setting up the Hyperledger Fabric network

For this project, we'll be working with the Hyperledger Fabric samples provided in the Hyperledger Fabric GitHub repository.

You need to have Docker and Docker Compose installed to carry out the setup. To install all the dependencies, go to https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html and follow the instructions.

After downloading and installing the dependencies, we need to download and install the binaries, samples, and Docker images for Hyperledger Fabric. To do this, we'll be using curl to download the images from the Fabric repository, as follows:

curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.0

This will take up to 15 minutes to complete, depending on your network connectivity. Once this is complete, move on to the next step.

...

Writing and deploying the DocsApp chaincode

Now that our network is online, the next step we need to do is write and deploy our chaincode contract. The chaincode DocsApp consists of the following methods:

  • addDocHash: This method adds a new document hash to the blockchain. Document hashes are indexed by the hash of the file path.
  • addParamHash: This method adds the FTH and the MTH to the blockchain indexed by a timestamp. The timestamp indicates the time at which the FTH and MTH were calculated and stored to the blockchain.
  • queryDocHash: This method retrieves the last updated hash for a document using the hash of the file path.
  • queryParamHash: This method retrieves the FTH and the MTH stored in the blockchain at a particular time using the timestamp indicating the time that it was stored.

We'll also have to install the chaincode for all the nodes that are part of our network...

Building the backend services

We need to build backend services that our frontend can access to write the hashes to the Fabric blockchain and read the hashes from the Fabric blockchain.

We'll be creating the Node.js utility using and building the following services:

  • /api/hashwrite: This endpoint exposes a service that is used for calculating the hash of all the artifacts in a directory root, the hash of the file path of all the artifacts, and the hash of the modified timestamp of all the artifacts then submitting them to the blockchain.
  • /api/hashread: This endpoint exposes a service that is used for re-calculating the hash of all the artifacts in a directory root, the hash of the file path of all the artifacts, and the hash of the modified timestamp of all the artifacts then verifying whether they match the hash values recorded in the blockchain. If there is a mismatch...

Creating a React frontend for the app

Our frontend will be a React app with which the user can register a directory to secure our blockchain. After registering the directory, the app will iterate every 5 seconds and call the /api/hashread service to check whether the directory has been tampered with.

In the case the directory has been tampered with, the app will show the message Tampered! in the header; otherwise, it will say Not Tampered. It will then call the /api/hashreadfile service in the backend server to fetch a list of tampered files, added files, and removed files. These are then listed in the app.

The following are the constituent parts of the app:

  • The main App.js file
  • The following React components:
    • Container.js
    • PathMapper.js
    • FolderBlock.js
    • FolderBlockChkStatus.js
    • GlowBar.js

The following is a brief description of these components:

  • App.js: The main App.js file...

Running the tamper-proof application

Let's run our application.

Make sure that the Hyperledger Fabric network is running:

  1. Bring the backend server online:
node hashcheck
  1. Next, bring the React app online. Navigate to the react directory and enter the following command:
npm start
  1. The app should now open up in your browser, as shown in the following screenshot:
  1. We need to provide a test directory that we'll be monitoring with our app.

I've created a mock test directory, as shown in the following screenshot. Feel free to create your own directory or use a preexisting one:

  1. Next, we will enter the absolute path of the directory in our app to secure it:
  1. Click on Submit to proceed. The app will next hash the files in our directory and capture them to the blockchain. The app will then monitor each of the files in the directory:
  1. The green banner and the...

Summary

That wraps up our tamper-proof Blockchain app. In an enterprise scenario, you can use this app to detect any tampering and then replace the files from a backup, such as a disaster recovery site, if required. This is a simple prototype, and I'm sure that you can figure out multiple applications for this workflow in the different business processes of a financial organization, such as managing digital copies of customers' private documents, confidential files and business information, transaction data, and so on.

We started this chapter with the intention of leveraging the tamper-proof property, or immutability, of blockchains to build an app that will notify us when a record-keeping or document storage system has been tampered with. To that end, we set up a private Hyperledger Fabric network with two nodes, two organizations, and one channel. On the network, we...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Blockchain Development for Finance Projects
Published in: Jan 2020Publisher: PacktISBN-13: 9781838829094
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ishan Roy

Ishan Roy leads the Blockchain initiative at the Centre of Excellence for Emerging Technologies (CEET) at the Tamil Nadu e-Governance Agency (TNeGA). He is currently working on the Tamil Nadu Blockchain Backbone project. His foray into blockchain began in the year 2016, at the blockchain team at ICICI Bank. This team carried out the first blockchain remittance in India. Since then he has worked as the Head of Products at HashCash Consultants where he built blockchain-enabled financial solutions for global clients. He has also mentored students and industry veterans as a blockchain trainer with Edureka. He is extremely passionate about technology and loves to keep himself abreast of new developments in the field through the community
Read more about Ishan Roy