如何解决使用JavaScript从Web客户端访问Hyperledger Fabric 2.0中的私钥?
我想从Web客户端注册用户,并且想转换下面的代码。当前设置使用存储在通过nodejs访问的服务器上的钱包。但是,如果我完全从Web客户端访问它,该怎么办?是否可以直接在Web客户端中使用针对Hyperledger Fabric 2.0的API调用并访问客户端设备上的私钥?
这是nodejs示例-
const { Wallets } = require('fabric-network');
const FabricCAServices = require('fabric-ca-client');
const fs = require('fs');
const path = require('path');
async function main() {
try {
// load the network configuration
const ccpPath = path.resolve(__dirname,'..','test-network','organizations','peerOrganizations','org1.example.com','connecti
on-org1.json');
// const ccp = JSON.parse(fs.readFileSync(ccpPath,'utf8'));
const ccpPath1 = "./fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.json";
const ccp = JSON.parse(fs.readFileSync(ccpPath1,'utf8'));
// Create a new CA client for interacting with the CA.
const caURL = ccp.certificateAuthorities['ca.org1.example.com'].url;
const ca = new FabricCAServices(caURL);
// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(),'wallet');
const wallet = await Wallets.newFileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
解决方法
为了从客户端连接到结构节点(在本例中为您的Node JS代码),您需要具有要连接的节点的身份(证书和私钥以证明证书属于您)认识。因此,基本上没有私钥和证书,就无法连接到结构节点。
如果您有权访问组织管理员的私钥和证书,则可以使用这些私钥和证书将身份加载到电子钱包。根据您的要求,电子钱包可以是内存中,文件系统或Couch DB钱包。
const identity: X509Identity = {
credentials: {
certificate: 'PEM format certificate string',privateKey: 'PEM format private key string',},mspId: 'org1',type: 'X.509',};
await wallet.put('admin.org1',identity);
您现在可以使用此管理员身份连接到组织CA,并根据需要请求注册和注册更多用户。
您还可以在钱包中使用HSM提供程序。
了解更多here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。