Private & Public Data at Hyperledger Fabric

Ta-seen Junaid
Coinmonks
11 min readOct 5, 2019

--

Overview

This article represents both conceptual theories and implementation processes of public and private data at Hyperledger Fabric v1.4 blockchain platform and it is the first article that covers implementation processes of public and private data into a same channel.

We assume that you know all the key concepts of Hyperledger Fabric v1.4 and have sound knowledge on Building Your First Network.

Why we need private data?

Private data is used for data confidentiality and to hide sensitive information from other parties. Like two parties do not want to share their pricing policies among other members of Blockchain network or customers do not want to share all their information among others.

Though Hyperledger Fabric is a private permissioned Blockchain network, creating more channels for private data will cause maintenance nightmare and performance degradation. Encrypting the key-value pairs will create overheads and everyone with the shared key can access the encrypted data. So the best solution is to use private data to keep your necessary information confidential from others.

An Example

Suppose Org A, Org B, Org C and Org D are four business organizations in our blockchain network and those organizations are in Channel x for their business purpose.

Channel x with both public data and private data

Each of them has a same Ledger that holds facts about the current and historical state of a set of business objects whereas Chaincode defines the executable logic that generates new facts to add to each Ledger. So data in the Ledger is public among all organizations of that channel. But Org C and Org D do not want to share their confidential data with other organizations. So they store those private data in a SideDB which is private between Org C & Org D where Org A & Org B will never know the private data but a transaction hash will be added at each Ledger.

Flow of Transactions for a Channel’s Public Data

. Signing transaction proposal and sending that to endorsers

. Gathering signed responses from endorsers

Flow of transactions for a channel’s public data

. Broadcasting request to orders

. Creation of blocks by orders

. Delivering blocks to peers by orders

. Validating by peers

. Updating Ledgers

Flow of Transactions for a Channel’s Private Data

. Signing transaction proposal and sending that to endorsers

. Keeping private data in transient field to hide it from endorsers

Flow of transactions for a channel’s private Data

. Checking of private data collection definition by endorsers

. Sending of private data to some of authorized organizations peers

. Use of gossip protocol among authorized organizations peers to receive private data

. responding with the hash of private data by endorsers

. Broadcasting request to orders

. Creation of blocks by orders

. Delivering blocks to peers by orders

. Validating by peers

. Updating Ledgers with transaction hash (both authorized and unauthorized peers)

. Checking by authorized peers

. Moving of private data into SideDB by authorized peers

. Deletion of private data from transient DB by authorized peers

Hands-on tutorial

Private data collection definition needs to write in a JSON format and needs to introduce it’s path during Chaincode instantiate process(like $GOPATH/src/github.com/chaincode/collections_config.json). We name the JSON file as collections_config.json and you can read official documents about how to write this file.

We name this as “collectionMaterialOrderPrivateDetails” and according to the policy only C and D organizations can have access into the private data.

In our Chaincode, we keep the pricing policy private so only authorized organizations can view it. The Chaincode is written by using GO language.

Chaincode

To install Chanincode:

To instantiate Chaincode:

To invoke Chaincode with both public and private data:

Some invoking commands for both private and public data:

Some query commands for both private and public data:

Summary:

In this article we try to explain public and private data of Hyperledger Fabric v1.4 blockchain platform with a hands-on tutorial about how to implement both private and public data on same channel. We hardly find any tutorial about implementation processes of both private and public data on same channel and so we hope it will help you to develop your blockchain network.

Get Best Software Deals Directly In Your Inbox

--

--