Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Fabric private data

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use Fabric private data, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Hyperledger Fabric private data is a new feature introduced in version 1.2. Fabric private data uses side-branch database (SideDB) to store private data between several channel members, thus providing a more flexible data protection mechanism on top of the channel. This article describes how to use fabric private data in chain code development.

Fabric private data uses SideDB to store private data, which is equivalent to providing a more fine-grained data privacy protection mechanism on top of the channel. This article will introduce the purpose, basic concepts and application scenarios of fabric private data.

What is fabric private data?

Currently, the way to achieve data privacy in Hyperledger Fabric is to use channels. But officials do not create a large number of channels in large networks in order to protect data privacy, because this brings additional overhead, such as management policies, chain code versions, and member service provision (MSP). In a channel, all data is either public or private. So it can be troublesome if you want to transfer assets to members outside the channel. This is why Hyperledger Fabric introduced private transactions. Farbic private data allows you to create private datasets based on policies to define which members of the channel can access the data. You can manage fabric private data simply by adding policies. This makes it possible to expose some data to only some members.

Consider the marbles example for Hyperledger Fabric. All marble data can be made public, except for the owner and the price information, these two data can not be made public to others, the price should not be known by others. Maybe you need to track this data because you need to verify that the person selling the marble is the real holder. A hypothetical marble audit firm can prove this as your partner. If you use the channel, then all your actions will be recorded in the ledger status and can be seen by anyone.

How does fabric private data solve the above problems?

In the figure above, the first collection, Channel Read-Write Sets "is the architecture when fabric private data was not introduced, and each transaction records its status and history.

The second set, private state partition 1, shows a shared private state between two nodes belonging to different institutions. This state is replicated between nodes according to a prior policy.

The third collection, private state partition 2: 3, shows a real example of fabric private data. Datasets can be ignored by some members. This means that you can set up a private dataset for each marble seller and auditor. These datasets allow some additional data to be added, and the main data is still stored in the master state and ledger.

The authorized node will be able to see the data hash in the main ledger, as well as the real data in the private database. Unauthorized nodes will not synchronize private databases and can only see data hashes on the main ledger. Because the hash is irreversible, these unauthorized nodes cannot see the real data.

At a higher level, the problem solved by fabric private data looks like this:

Fabric private data use case

We use the classic fabcar case in Hyperledger Fabric to show how to use a private dataset. The initLedger function will create 10 new cars in our dataset. All of these vehicles can be viewed by anyone on the network. Now let's create a private database, and this data will only be shared with another member garage we hold.

Fabric private data dataset configuration

We first need a dataset configuration file, collections_config.json, which contains the private dataset name and access policy. Access policy is similar to endorsement policy, which allows us to use existing policy logic, such as OR, AND, and so on.

[{"name": "carCollection", "policy": "OR ('Org1MSP.member','Org2MSP.member')", "requiredPeerCount": 0, "maxPeerCount": 3, "blockToLive": 1000000}] modify the chain code to support fabric private data

Here is the original createCar function:

Async createCar (stubHelper: StubHelper, args: string []) {const verifiedArgs = await Helpers.checkArgs (args [0], Yup.object () .shape ({key: Yup.string (). Required (), make: Yup.string (). Required (), model: Yup.string (). Required (), color: Yup.string (). Required () Owner: Yup.string () .required (),}) Let car = {docType: 'car', make: verifiedArgs.make, model: verifiedArgs.model, color: verifiedArgs.color, owner: verifiedArgs.owner}; await stubHelper.putState (verifiedArgs.key, car);}

To add data to the private dataset carCollection, we need to specify the target dataset:

Await stubHelper.putState (verifiedArgs.key, car, {privateCollection: 'carCollection'})

Next, to query the vehicle, we also need to specify the target private dataset:

Async queryPrivateCar (stubHelper: StubHelper, args: string []) {const verifiedArgs = await Helpers.checkArgs (args [0], Yup.object () .shape ({key: Yup.string (). Required (),})); const car = await stubHelper.getStateAsObject (verifiedArgs.key, {privateCollection: 'carCollection'}); if (! car) {throw new NotFoundError (' Car does not exist') } return car;}

Similarly, for both delete and update operations, you need to specify the target private dataset to operate on.

The above is all the contents of this article "how to use Fabric private data". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report