Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (proposalResponse) {
// logger.debug('Received proposal response with status - %s', proposalResponse.response.status);
if (count === total) {
resolve(proposalResponse);
}
} else {
reject(new Error('GRPC client failed to get a proper response from the peer'));
}
}
});
}
});
};
let user;
return Client.newDefaultKeyValueStore({
path: testUtil.KVS
}).then((store) => {
client.setStateStore(store);
return testUtil.getSubmitter(client, t, org);
}).then(
(admin) => {
user = admin;
start2 = Date.now();
promise(user);
},
(err) => {
t.fail('Failed to enroll user \'admin\'. ' + err);
}
).then(
() => {
const end = Date.now();
logger.info('[joinChannel] Calling peers in organization (%s) to join the channel (%s)', orgName, channelName);
var username = testUtil.getOrgEnrollIdSubmitter(cpf, org);
var secret = testUtil.getOrgEnrollSecretSubmitter(cpf, org);
logger.debug('[joinChannel] user=%s, secret=%s', username, secret);
var genesis_block = null;
var eventHubs = [];
var blockCallbacks = [];
// get client key
if (TLS == testUtil.TLSCLIENTAUTH) {
await testUtil.tlsEnroll(client, org, cpf);
logger.debug('[joinChannel] get user private key: org= %s', org);
}
return hfc.newDefaultKeyValueStore({
path: testUtil.storePathForOrg(Nid, orgName)
}).then((store) => {
client.setStateStore(store);
client._userContext = null;
return testUtil.getOrderAdminSubmitter(client, org, cpPath)
}).then(async (admin) => {
logger.info('[joinChannel:%s] Successfully enrolled orderer \'admin\'', org);
the_user = admin;
logger.debug('[joinChannel] orderer admin: ', admin);
// add orderers
chainAddOrderer(channel, client, org);
let tx_id = client.newTransactionID();
var request = {
txId: tx_id
//
const fabric_client = new Fabric_Client();
// setup the fabric network
const channel = fabric_client.newChannel('mychannel');
const peer = fabric_client.newPeer('grpc://localhost:7051');
channel.addPeer(peer);
//
let member_user = null;
const store_path = path.join(__dirname, 'hfc-key-store');
console.log('Store path:' + store_path);
const tx_id = null;
// create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
Fabric_Client.newDefaultKeyValueStore({ path: store_path,
}).then((state_store) => {
// assign the store to the fabric client
fabric_client.setStateStore(state_store);
const crypto_suite = Fabric_Client.newCryptoSuite();
// use the same location for the state store (where the users' certificate are kept)
// and the crypto store (where the users' keys are kept)
const crypto_store = Fabric_Client.newCryptoKeyStore({ path: store_path });
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
// get the enrolled user from persistence, this user will sign all requests
return fabric_client.getUserContext('user1', true);
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded user1 from persistence');
member_user = user_from_store;
var fabric_client = new Fabric_Client();
// setup the fabric network
var channel = fabric_client.newChannel('mychannel');
var peer = fabric_client.newPeer('grpc://localhost:7051');
channel.addPeer(peer);
var order = fabric_client.newOrderer('grpc://localhost:7050')
channel.addOrderer(order);
var member_user = null;
var store_path = path.join(os.homedir(), '.hfc-key-store');
console.log('Store path:'+store_path);
var tx_id = null;
// create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
Fabric_Client.newDefaultKeyValueStore({ path: store_path
}).then((state_store) => {
// assign the store to the fabric client
fabric_client.setStateStore(state_store);
var crypto_suite = Fabric_Client.newCryptoSuite();
// use the same location for the state store (where the users' certificate are kept)
// and the crypto store (where the users' keys are kept)
var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
// get the enrolled user from persistence, this user will sign all requests
return fabric_client.getUserContext('user1', true);
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded user1 from persistence');
member_user = user_from_store;
const Fabric_CA_Client = require('fabric-ca-client');
const os = require('os');
const path = require('path');
const fabric_client = new Fabric_Client();
let fabric_ca_client = null;
let admin_user = null;
let member_user = null;
const homedir = os.homedir();
const hurleyIdentityPath = path.resolve(homedir, 'hyperledger-fabric-network/.hfc-org1');
console.log('Store path:' + hurleyIdentityPath);
// create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
Fabric_Client.newDefaultKeyValueStore({
path: hurleyIdentityPath
}).then((state_store) => {
// assign the store to the fabric client
fabric_client.setStateStore(state_store);
const crypto_suite = Fabric_Client.newCryptoSuite();
// use the same location for the state store (where the users' certificate are kept)
// and the crypto store (where the users' keys are kept)
const crypto_store = Fabric_Client.newCryptoKeyStore({ path: hurleyIdentityPath });
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
// be sure to change the http to https when the CA is running TLS enabled
fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', null, '', crypto_suite);
// first check to see if the admin is already enrolled
return fabric_client.getUserContext('admin', true);
let data = fs.readFileSync(path.join(__dirname, ORGS[org][key]['tls_cacerts']));
let peer = new Peer(
ORGS[org][key].requests,
{
pem: Buffer.from(data).toString(),
'ssl-target-name-override': ORGS[org][key]['server-hostname']
}
);
targets.push(peer);
chain.addPeer(peer);
}
}
}
return hfc.newDefaultKeyValueStore({
path: helper.getKeyStoreForOrg(orgName)
}).then((store) => {
client.setStateStore(store);
return helper.getSubmitter(client, org);
}).then((admin) => {
logger.info('Successfully enrolled user \'admin\'');
adminUser = admin;
nonce = utils.getNonce();
tx_id = chain.buildTransactionID(nonce, adminUser);
// send proposal to endorser
var request = {
targets: targets,
chaincodePath: config.chaincodePath,
chaincodeId: config.chaincodeId,
enrollment.enrollWithAdminCert = function (options, cb) {
var client = new FabricClient();
var channel = client.newChannel(options.channel_id);
var debug = { // this is just for console printing, no PEM here
peer_urls: options.peer_urls,
channel_id: options.channel_id,
uuid: options.uuid,
orderer_url: options.orderer_url,
msp_id: options.msp_id,
};
logger.info('[fcw] Going to enroll with admin cert! ', debug);
// Make eCert kvs (Key Value Store)
FabricClient.newDefaultKeyValueStore({
path: options.kvs_path //get eCert in the kvs directory
}).then(function (store) {
client.setStateStore(store);
return getSubmitterWithAdminCert(client, options); //admin cert is different
}).then(function (submitter) {
channel.addOrderer(new Orderer(options.orderer_url, options.orderer_tls_opts));
channel.addPeer(new Peer(options.peer_urls[0], options.peer_tls_opts)); //add the first peer
logger.debug('added peer', options.peer_urls[0]);
// --- Success --- //
logger.debug('[fcw] Successfully got enrollment ' + options.uuid);
if (cb) cb(null, { client: client, channel: channel, submitter: submitter });
return;
function joinChannel(channel, client, org) {
orgName = ORGS[org].name;
logger.info('[joinChannel] Calling peers in organization (%s) to join the channel (%s)', orgName, channelName);
var username = ORGS[org].username;
var secret = ORGS[org].secret;
logger.info('[joinChannel] user=%s, secret=%s', username, secret);
var genesis_block = null;
// add orderers
chainAddOrderer(channel, client, org);
//printChainInfo(channel);
return hfc.newDefaultKeyValueStore({
path: testUtil.storePathForOrg(Nid, orgName)
}).then((store) => {
client.setStateStore(store);
client._userContext = null;
return testUtil.getOrderAdminSubmitter(client, org, svcFile)
}).then((admin) => {
logger.info('[joinChannel:%s] Successfully enrolled orderer \'admin\'', org);
the_user = admin;
logger.debug('[joinChannel] orderer admin: ', admin);
tx_id = client.newTransactionID();
var request = {
txId : tx_id
};
return channel.getGenesisBlock(request);
}).then((block) =>{
let caroots = Buffer.from(data).toString();
channel.addOrderer(
client.newOrderer(
ORGS.orderer.url,
{
'pem': caroots,
'ssl-target-name-override': ORGS.orderer['server-hostname']
}
)
);
var targets = [];
var transientMap = {'test':'transientValue'};
return Client.newDefaultKeyValueStore({
path: testUtil.storePathForOrg(orgName)
}).then((store) => {
client.setStateStore(store);
return testUtil.getSubmitter(client, true /* use peer org admin*/, userOrg);
}).then((admin) => {
the_user = admin;
let eventPeer = null;
for(let org in ORGS) {
if(org.indexOf('org') === 0) {
for (let key in ORGS[org]) {
if(key.indexOf('peer') === 0) {
let data = fs.readFileSync(path.join(__dirname, rootPath, ORGS[org][key]['tls_cacerts']));
let peer = client.newPeer(
var getRegisteredUsers = function(client, username, org, networkID, mspID) {
var keyPath = util.format('./configs/%s/peerOrganizations/%s/users/%s/msp/keystore/', networkID, org, username);
var keyPEM = Buffer.from(readAllFiles(keyPath)[0]).toString();
var certPath = util.format('./configs/%s/peerOrganizations/%s/users/%s/msp/signcerts/', networkID, org, username);
var certPEM = readAllFiles(certPath)[0].toString();
var cryptoSuite = Client.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: '/tmp/fabric-client-kvs_'+org.split('.')[0]}));
client.setCryptoSuite(cryptoSuite);
return Client.newDefaultKeyValueStore({
path: getKeyStoreForOrg(org)
}).then((store) => {
client.setStateStore(store);
return client.createUser({
username: username.split('@')[0],
mspid: mspID,
cryptoContent: {
privateKeyPEM: keyPEM,
signedCertPEM: certPEM
}
});
});
}