向参与者发放新的身份

使用API,命令行或在Hyperledger Composer Playground中使用ID卡,可以向参与者发放新的身份。一旦发放了新的身份,参与者就可以使用该身份在参与者上下文中与业务网络进行交互。

使用Hyperledger Fabric时,Hyperledger Composer使用Hyperledger Fabric证书颁发机构(CA)来注册新的登记证书,从而发放新的身份。Hyperledger Fabric证书颁发机构生成一个可以提供给参与者的登记密码,然后可以使用登记密码从Hyperledger Fabric证书颁发机构请求登记证书和私钥。

在你开始之前

在执行这些步骤之前,你必须已将参与者添加到参与者库中。新身份的发放人(无论使用命令行或使用下面的JavaScript API)本身必须具有“发放人”的权威和适当的ACL,ALC要允许他们Hyperledger Composer中发放(与参与者相关联的)身份。

下面的过程显示了一个使用以下数字财产范例业务网络定义的参与者模型的示例:digitalproperty-network

  1. namespace net.biz.digitalPropertyNetwork
  2. participant Person identified by personId {
  3. o String personId
  4. o String firstName
  5. o String lastName
  6. }

该示例假定该net.biz.digitalPropertyNetwork#mae@biznet.org参与者的实例已经被创建并被放入参与者库中。

过程

1.连接到业务网络并向参与者颁发新的身份

JavaScript API:

  1. const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
  2. let businessNetworkConnection = new BusinessNetworkConnection();
  3. return businessNetworkConnection.connect('admin@digitalPropertyNetwork')
  4. .then(() => {
  5. return businessNetworkConnection.issueIdentity('net.biz.digitalPropertyNetwork.Person#mae@biznet.org', 'maeid1')
  6. })
  7. .then((result) => {
  8. console.log(`userID = ${result.userID}`);
  9. console.log(`userSecret = ${result.userSecret}`);
  10. return businessNetworkConnection.disconnect();
  11. })
  12. .catch((error) => {
  13. console.error(error);
  14. process.exit(1);
  15. });

命令行:

  1. composer identity issue -c admin@network -f maeid1.card -u maeid1 -a "resource:net.biz.digitalPropertyNetwork.Person#mae@biznet.org"

1.作为参与者,测试与业务网络的连接

JavaScript API:

  1. const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
  2. let businessNetworkConnection = new BusinessNetworkConnection();
  3. return businessNetworkConnection.connect('admin@digitalPropertyNetwork')
  4. .then(() => {
  5. return businessNetworkConnection.ping();
  6. })
  7. .then((result) => {
  8. console.log(`participant = ${result.participant ? result.participant : '<no participant found>'}`);
  9. return businessNetworkConnection.disconnect();
  10. })
  11. .catch((error) => {
  12. console.error(error);
  13. process.exit(1);
  14. });

命令行:

  1. composer network ping -c maeid1@network