Skip to content

Instantly share code, notes, and snippets.

@rdemorais
Created April 9, 2018 14:59
Show Gist options
  • Save rdemorais/d23124955371ad971ee176929c046659 to your computer and use it in GitHub Desktop.
Save rdemorais/d23124955371ad971ee176929c046659 to your computer and use it in GitHub Desktop.
Hyperlegder Fabric - Composer - Create participant
async function teste() {
var namespace = 'br.com.synapsetec';
var producerType = 'Producer';
var producerNS = namespace + '.' + producerType;
const AdminConnection = require('composer-admin').AdminConnection;
const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
const cardStore = require('composer-common').NetworkCardStoreManager.getCardStore();
const { IdCard } = require('composer-common');
businessNetworkConnection = new BusinessNetworkConnection({ cardStore: cardStore });
await businessNetworkConnection.connect('admin@my-network');
factory = businessNetworkConnection.getBusinessNetwork().getFactory();
const producerRegistry = await businessNetworkConnection.getParticipantRegistry(producerNS);
const alice = factory.newResource(namespace, producerType, '[email protected]');
await producerRegistry.add(alice);
let identity = await businessNetworkConnection.issueIdentity(producerNS + '#[email protected]', 'alice3');
const connectionProfile = {
"name": "my-network",
"x-type": "hlfv1"
};
adminConnection = new AdminConnection({ cardStore: cardStore });
const metadata = {
userName: identity.userID,
version: 1,
enrollmentSecret: identity.userSecret,
businessNetwork: 'my-network'
};
const card = new IdCard(metadata, connectionProfile);
await adminConnection.importCard('alice@my-network', card);
console.log('ok');
}
teste();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment