Unable to issue identity card using Hyperledger Co

2019-08-26 22:20发布

I am trying to create an identity card using the javascript API of Hyperledger Composer. Here is the code:

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();

I already have a participant testUser. Although the code succeeds and I get the userID and userSecret, no card is created.
Does anyone have an idea how to do it instead of using the cli?

1条回答
太酷不给撩
2楼-- · 2019-08-26 23:10

You haven't imported the card.

eg,

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);
    }

See also nodejs test hyperledger composer v0.15 fails with Error: Card not found: PeerAdmin@hlfv1 (answer) it has an example too.

After importing, you should connect with your card to download the cert/key to the wallet eg await businessNetworkConnection.connect(cardName);

查看更多
登录 后发表回答