In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the CouchDB wallet in Fabric Node SDK. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. The type of Hyperledger Fabric wallet
There are three types of wallets: file system wallets, memory wallets, and CouchDB wallets.
File system wallet:
The file system wallet is a simple folder, which is a good default choice in most cases. In the fabric-samples/balance-transfer example, the file system wallet is used. When you run the sample code, it creates a fabric-client-kv-orgName folder and stores all the required Fabric identities in it. For this configuration definition, please refer to orgname.yaml.
Memory wallet:
As the name implies, a memory wallet is a wallet that is temporarily stored in the application memory. This wallet can be used when running in a restricted environment or when there is no need to access the file system, such as in a browser. It should be reminded that the identity information in this wallet will be gone after the termination of the application. The details of the memory wallet can be found here.
CouchDB Wallet:
That is, CouchDB is used to save identity data, which is the most common choice in a production environment.
2. Hyperledger Fabric CouchDB wallet
The wallet uses two libraries to hold the certificate and private key:
Status Library:
The state library is used to hold the certificate of a registered identity, which stores basic information about an identity:
{"name": "test", "mspid": "org1", "roles": null, "affiliation": "", "enrollmentSecret": "", "enrollment": {"signingIdentity": "", "identity": {"certificate": ""}
Note: signingIdentity points to the storage address of the private key and the public key in the cryptographic database.
Cryptography database:
The cryptographic database is used to hold the private and public keys of the identity.
3. Enable CouchDB wallet in Hyperledger Fabric application
First, introduce the CouchDBKeyValueStore library provided by Fabric Node SDK:
Const CDBKVS = require ("fabric-client/lib/impl/CouchDBKeyValueStore.js")
Then set up the status library:
Let stateStore = await new CDBKVS ({url: "https://:@", name:"}); const Client = require (" fabric-client "); const client = Client.loadFromConfig (" path of network.yaml "); client.setStateStore (stateStore)
Where:
< USERNAME>User name of couchdb
< PASSWORD>Password of couchdb
< URL>: URL of couchdb
< DB_NAME>Optional, state library name The default name is userdb, which is automatically created by Fabric Node SDK when the specified state library does not exist
Finally, set up the cryptography database:
Const cryptoSuite = Client.newCryptoSuite (); let cryptoKS = Client.newCryptoKeyStore (CDBKVS, {url: "https://:@", name:"}); cryptoSuite.setCryptoKeyStore (cryptoKS); client.setCryptoSuite (cryptoSuite); 4. Use the CouchDB wallet in the Balance Transfer example
Balance Transfer is a sample code provided officially by Hyperledger Fabric.
First follow the example to start the balance transfer network, which contains:
2 CA
1 SOLO sort node
There are 4 peer nodes in 2 organizations
Start the docker image of couchdb:
~ $docker run-- name couch-userdb-e COUCHDB_USER=admin\-e COUCHDB_PASSWORD=password-p 5984 COUCHDB_USER=admin 5984-d couchdb
The above command automatically pulls the couchdb image on docker hub.
Details of CouchDB are as follows:
Container name: couch-userdb
CouchDB user name: admin
CouchDB password: password
URL:localhost:5984
The URL of the CouchDB connection is as follows:
Https://:@ https://admin:password@localhost:5984
Then update the client configuration in the balance-transfer example: open the file / helper.js and update the getClientForOrg function:
'use strict';var log4js = require (' log4js'); var logger = log4js.getLogger ('Helper'); logger.setLevel (' DEBUG'); var path = require ('path'); var util = require (' util'); var hfc = require ('fabric-client'); hfc.setLogger (logger); / / couchDB config const CDBKVS = require ("fabric-client/lib/impl/CouchDBKeyValueStore.js") Async function getClientForOrg (userorg, username) {logger.debug ('getClientForOrg-* START% s% slots, userorg, username) / / get a fabric client loaded with a connection profile for this org let config ='-connection-profile-path'; / / build a client context and load it with a connection profile / / lets only load the network settings and save the client for later let client = hfc.loadFromConfig (hfc.getConfigSetting ('network' + config)) / / This will load a connection profile over the top of the current one one / / since the first one did not have a client section and the following one does / / nothing will actually be replaced. / / This will also set an admin identity because the organization defined in the / / client section has one defined client.loadFromConfig (hfc.getConfigSetting (userorg + config)) / / * * CouchDB configuration * * / / set the state store let stateStore = await new CDBKVS ({url: "https://:@", name:"}); client.setStateStore (stateStore) / / set the cryto store const cryptoSuite = hfc.newCryptoSuite (); let cryptoKS = hfc.newCryptoKeyStore (CDBKVS, {url: "https://:@", name:"}); cryptoSuite.setCryptoKeyStore (cryptoKS); client.setCryptoSuite (cryptoSuite) / / * CouchDB configuration END * * if (username) {let user = await client.getUserContext (username, true) If (! user) {throw new Error (util.format ('User was not found:', username));} else {logger.debug ('User% s was found to be registered and enrolled', username);}} logger.debug (' getClientForOrg-* END% s\ n\ n\ n) return client;}
Our modifications are as follows:
Line 13: Import the CouchDBKeyValueStore....
Line 31-52: set up the state library and cryptography database
There is one small change in the above code:
/ / Client variable is used as hfcvar hfc = require ("fabric-client"); / / Instead of Clientconst Client = require ("fabric-client")
Then register a new user in balance transfer, and once the registration is successful, you can use couchdb's api to view the state library and cryptography database.
For example, you can register a user with the following parameters. For org1, we use the same library org1db for both the state library and the cryptographic database:
Name: alice
Org: org1
DBNAME: org1db
CouchDB URL: http://admin:password@localhost:5369
Open a browser to access http://localhost:5369/org1db/_all_docs and you can see all the documents saved in org1db.
Where certificates, certificates, and certificates are for admin.
Certificate is the certificate saved by alice in the state store
Keys and keys are the public and private keys kept by alice in the cryptographic database
When you visit http://localhost:5369/org1db/alice, you can see all the details of alice in the state repository:
View signingIdentity:
"signingIdentity": "d37a97a8c2377c21537801ec1a929d81905ae57963a2f6c8ba0308931a7fc791"
Now if you look at the figures above, you can see that they are the same.
As you may recall, the signingIdentity field points to the private and public keys stored in the cryptographic database.
This is the end of the article on "how to use CouchDB Wallet in Fabric Node SDK". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.