Hyperledger Composer BusinessNetwork连接 - 0.14.3无法连接

时间:2017-11-03 17:41:07

标签: node.js hyperledger hyperledger-composer

我正在尝试将BusinessNetworkConnection用于NodeJS,但是如何从操场上的已部署BNA获取凭据并将其保存在我的服务器目录中?

我正在

2017-11-03T13:07:32.83-0400 [APP/PROC/WEB/0] ERR (node:62) 
UnhandledPromiseRejectionWarning: Unhandled promise rejection 
(rejection id: 1): Error: Error trying login and get user Context. 
Error: Error trying to enroll user or load channel configuration. 
Error: Enrollment failed with errors 
[[{"code":400,"message":"Authorization failure"}]]

当我尝试使用代码时

const BusinessNetworkConnection = require("composer-client").BusinessNetworkConnection;
this.businessNetworkConnection = new BusinessNetworkConnection();
this.CONNECTION_PROFILE_NAME = "ibm-bc-org1";
this.businessNetworkIdentifier = "giveback";
this.businessNetworkConnection
  .connect(
    this.CONNECTION_PROFILE_NAME,
    this.businessNetworkIdentifier,
    "admin",
    "adminpw"
  )
  .then(result => {
    this.businessNetworkDefinition = result;
    console.log("BusinessNetworkConnection: ", result);
  })

我有一个目录/home/vcap/app/.composer-connection-profiles/ibm-bc-org1,其connection.json文件引用/home/vcap/app/.composer-credentials/ibm-bc-org1作为我的凭据。该代码适用于composer@0.13.2,但现在我转移到composer@0.14.3。我删除了以前的凭据并创建了一个新的游乐场等,一切都很新鲜干净。

1 个答案:

答案 0 :(得分:0)

当发生类似这样的事情时,有一种解决方法。因为我尝试使用Composer使用admin || adminpw创建的凭据进行连接。您只需在模型文件中定义新参与者,然后授予该参与者系统查询和侦听Historian发出的事件的权限。

例如,在model.cto

participant ServerAdmin identified by serverhash {
  // ServerAdmin is a type of participant 
  o String serverhash
}

permissions.acl添加:

rule ServerAdminUser {
  description: "Grant business network administrators full access to 
  user resources"
  participant: "org.acme.sample.ServerAdmin"
  operation: ALL
  resource: "**"
  action: ALLOW
}

rule ServerAdminSystem {
  description: "Grant business network administrators full access to system resources"
  participant: "org.acme.sample.ServerAdmin"
  operation: ALL
  resource: "org.hyperledger.composer.system.**"
  action: ALLOW
}

然后,当Composer在操场上部署网络后,您可以通过REST API添加此参与者,并向其发出新身份。这将为您提供User IDUser Secret,您可以在BusinessNetworkConnection.connect()

中使用