使用交换矩阵网关API的HL客户端

问题描述 投票:0回答:1

我正在尝试将我的应用程序从Fabric SDK迁移到Fabric网关,并为其编写示例POC。因为我已经在使用Fabric Java SDK连接到区块链,所以我已经设置了证书,密钥和必要的安全性。在网关中,我们创建了保存用户身份的钱包,并将其传递给网关对象以访问网络。我试图弄清楚如何使用现有的现有密钥和证书来实例化Wallet对象,例如,如果我必须使用以下FileSystemStore钱包,以后将在连接网关连接时使用它。

WalletStore walletStore = new FileSystemWalletStore(walletDirectory);   
WalletImpl wallet = new WalletImpl(walletStore);

任何指针都会有所帮助。我正在使用Java编写客户端应用程序。

hyperledger-fabric gateway
1个回答
0
投票

使用mspId,X509证书和用户的私钥,您可以创建X509Identity,将其放入钱包实例中并提供给网关构建器:

Identity identity = Identities.newX509Identity(<msp_id>, <x509_certificate>, <private_key>);

Wallet wallet = Wallets.newFileSystemWallet(<path_to_wallet>);
wallet.put(<enrollment_id>, identity);

Gateway.Builder gatewayBuilder = Gateway.createBuilder();
Gateway gateway = gatewayBuilder
                        .identity(wallet, <enrollment_id>)
                        .networkConfig(<path_to_connection_profile>)
                        .discovery(<service_discovery_option>)
                        .connect();
© www.soinside.com 2019 - 2024. All rights reserved.