无法使用Hyperledger Composer Javascript API发布身份证

时间:2018-05-10 22:43:09

标签: hyperledger-composer

我正在尝试使用Hyperledger Composer的JavaScript API创建身份证。这是代码:

const BusinessNetworkConnection = require('composer- 
client').BusinessNetworkConnection;

async function identityIssue() {
  let businessNetworkConnection = new BusinessNetworkConnection();
  try {
    await businessNetworkConnection.connect('admin@demoNetwork');
    let result = await businessNetworkConnection.issueIdentity('org.acme.demoNetwork.Participant#testUser', 'test');
    console.log(`userID = ${result.userID}`);
    console.log(`userSecret = ${result.userSecret}`);
    await businessNetworkConnection.disconnect();
  } catch(error) {
    console.log(error);
    process.exit(1);
  }
}

identityIssue();

我已有参与者testUser。 虽然代码成功,但我获得了userID和userSecret,但没有创建卡 有没有人知道怎么做而不是使用cli?

1 个答案:

答案 0 :(得分:0)

您尚未导入该卡。

例如

async function importCardForIdentity(cardName, identity) {
        const metadata = {
            userName: identity.userID,
            version: 1,
            enrollmentSecret: identity.userSecret,
            businessNetwork: businessNetworkName
        };
        const card = new IdCard(metadata, connectionProfile);
        await adminConnection.importCard(cardName, card);
    }

另见nodejs test hyperledger composer v0.15 fails with Error: Card not found: PeerAdmin@hlfv1(答案)它也有一个例子。

导入后,您应该使用卡连接以将证书/密钥下载到钱包,例如await businessNetworkConnection.connect(cardName);