How to use the fabric-client.newCryptoSuite function in fabric-client

To help you get started, we’ve selected a few fabric-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / test / integration / e2e / updateAnchorPeers.js View on Github external
const ORGS = Client.getConfigSetting('test-network');

	const client = new Client();

	const caRootsPath = ORGS.orderer.tls_cacerts;
	const data = fs.readFileSync(path.join(__dirname, caRootsPath));
	const caroots = Buffer.from(data).toString();

	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');

	const tlsInfo = await e2eUtils.tlsEnroll(org);
	client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);

	const store = await Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(ORGS[org].name)});
	client.setStateStore(store);
	const cryptoSuite = Client.newCryptoSuite();
	cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(ORGS[org].name)}));
	client.setCryptoSuite(cryptoSuite);


	await testUtil.getSubmitter(client, t, true /* get the org admin*/, org);
	t.pass(`Successfully enrolled user 'admin' for ${org}`);

	const orderer = client.newOrderer(
		ORGS.orderer.url,
		{
			name: 'new orderer',
			'pem': caroots,
			'ssl-target-name-override': ORGS.orderer['server-hostname']
		}
	);
github hyperledger / fabric-sdk-node / test / integration / perf / peer.js View on Github external
async function perfTest3(t) {
	testUtil.resetDefaults();
	Client.setConfigSetting('key-value-store', 'fabric-ca-client/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
	Client.addConfigFile(path.join(__dirname, '../e2e', 'config.json'));
	ORGS = Client.getConfigSetting('test-network');
	const orgName = ORGS[org].name;

	const cryptoSuite = Client.newCryptoSuite();
	cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
	client.setCryptoSuite(cryptoSuite);

	const caRootsPath = ORGS[org].peer1.tls_cacerts;
	const data = fs.readFileSync(path.join(__dirname, '../e2e', caRootsPath));
	const caroots = Buffer.from(data).toString();

	const tlsInfo = await e2eUtils.tlsEnroll(org);
	client.setTlsClientCertAndKey(tlsInfo.certificate, tlsInfo.key);

	const peer = client.newPeer(
		ORGS[org].peer1.requests,
		{
			'pem': caroots,
			'ssl-target-name-override': ORGS[org].peer1['server-hostname'],
			'request-timeout': 120000
github IBM / monitoring_ui / react-backend / routes / index.js View on Github external
//   config = hfc.loadFromConfig(json)
    // });
    client = hfc.loadFromConfig('./connection_profile.json')
  } else {
    client = hfc.loadFromConfig(requestConnectionProfile(req))
  }

  org = Object.keys(client._network_config._network_config.organizations)[0]
  certificateAuthorities = client._network_config._network_config.certificateAuthorities
  certificateAuthorityName = Object.keys(certificateAuthorities)[0]
  certificateAuthObj = certificateAuthorities[certificateAuthorityName]
  mspId = client._network_config._network_config.organizations[org]['mspid']
  storePath = './'
  client_crypto_suite = hfc.newCryptoSuite()
  crypto_store = hfc.newCryptoKeyStore({path: storePath})
  crypto_suite = hfc.newCryptoSuite()
  crypto_suite.setCryptoKeyStore(crypto_store)
  username = "monitoring_admin"
  // var crypto_store = hfc.newCryptoKeyStore({path: storePath})
  // crypto_suite.setCryptoKeyStore(crypto_store)
  client.setCryptoSuite(crypto_suite)
  // config.setCryptoSuite(client_crypto_suite);

  hfc.newDefaultKeyValueStore({path: storePath}).then( (store) => {
    client.setStateStore(store)
  }).then( (result) => {
    client.getUserContext(username, true).then ( (user) => {
    // res.send("Client Initialized")
    // console.log("Client Initialized")
    if (user && user.isEnrolled()) {
      console.log("Client Loaded From Persistence")
      res.send("Client Loaded From Persistence")
github hyperledger / fabric-sdk-node / examples / balance-transfer / app / helper.js View on Github external
var hfc = require('fabric-client');
hfc.addConfigFile(path.join(__dirname, 'network-config.json'));
hfc.setLogger(logger);
var ORGS = hfc.getConfigSetting('network-config');

var clients = {};
var channels = {};
var caClients = {};

// set up the client and channel objects for each org
for (let key in ORGS) {
	if (key.indexOf('org') === 0) {
		let client = new hfc();

		let cryptoSuite = hfc.newCryptoSuite();
		cryptoSuite.setCryptoKeyStore(hfc.newCryptoKeyStore({path: getKeyStoreForOrg(ORGS[key].name)}));
		client.setCryptoSuite(cryptoSuite);

		let channel = client.newChannel(config.channelName);
		channel.addOrderer(newOrderer(client));

		clients[key] = client;
		channels[key] = channel;

		setupPeers(channel, key, client);

		let caUrl = ORGS[key].ca;
		caClients[key] = new copService(caUrl, null /*defautl TLS opts*/, '' /* default CA */, cryptoSuite);
	}
}
github IBM / car-auction-network-fabric-node-sdk / registerUser.js View on Github external
}).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);
    // be sure to change the http to https when the CA is running TLS enabled
    fabric_ca_client = new Fabric_CA_Client('https://:@', null ,'', crypto_suite);
    // first check to see if the admin is already enrolled
    return fabric_client.getUserContext('admin', true);
}).then((user_from_store) => {
    if (user_from_store && user_from_store.isEnrolled()) {
github hyperledger / fabric-sdk-node / test / unit / client.js View on Github external
test('\n\n ** Client.js Tests: CryptoSuite() methods **\n\n', (t) => {
	const client = new Client();
	t.equals(client.getCryptoSuite(), null, 'Should return null when CryptoSuite has not been set');

	let crypto = Client.newCryptoSuite();
	client.setCryptoSuite(crypto);
	if (crypto) {
		t.pass('Successfully called newCryptoSuite()');
	}
	else {
		t.fail('newCryptoSuite() did not return an object');
	}

	crypto = client.getCryptoSuite();
	if (crypto) {
		t.pass('Successfully called getCryptoSuite()');
	}
	else {
		t.fail('getCryptoSuite() did not return an object');
	}
github hyperledger / fabric-sdk-node / fabric-network / lib / impl / wallet / filesystemwallet.js View on Github external
async getCryptoSuite(label) {
		const partitionedPath = this._getPartitionedPath(label);
		const cryptoSuite = Client.newCryptoSuite();
		cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: partitionedPath}));
		return cryptoSuite;
	}
github xuehuiit / fabric-explorer / app / helper.js View on Github external
var getOrgAdmin = function(userOrg) {
	var admin = ORGS[userOrg].admin;
	var keyPath = path.join(__dirname,"../",admin.key);
	var keyPEM = Buffer.from(readAllFiles(keyPath)[0]).toString();
	var certPath = path.join(__dirname,"../",admin.cert);
	var certPEM = readAllFiles(certPath)[0].toString();

	var client = getClientForOrg(userOrg);
	var cryptoSuite = hfc.newCryptoSuite();
	if (userOrg) {
		cryptoSuite.setCryptoKeyStore(hfc.newCryptoKeyStore({path: getKeyStoreForOrg(getOrgName(userOrg))}));
		client.setCryptoSuite(cryptoSuite);
	}

	return hfc.newDefaultKeyValueStore({
		path: getKeyStoreForOrg(getOrgName(userOrg))
	}).then((store) => {
		client.setStateStore(store);

		return client.createUser({
			username: 'peer'+userOrg+'Admin',
			mspid: getMspID(userOrg),
			cryptoContent: {
				privateKeyPEM: keyPEM,
				signedCertPEM: certPEM
github nexledger / accelerator / innovation-sandbox / caliper / src / adapters / accelerator / util.js View on Github external
let basePath = path.join(cryptodir, 'peerOrganizations', domain, 'users', util.format('Admin@%s', domain));

            let keyPath = path.join(basePath, 'keystore');
            if(!fs.existsSync(keyPath)) {
                keyPath = path.join(basePath, 'msp', 'keystore');
            }
            keyPEM = readAllFiles(keyPath)[0];

            let certPath = path.join(basePath, 'signcerts');
            if(!fs.existsSync(certPath)) {
                certPath = path.join(basePath, 'msp', 'signcerts');
            }
            certPEM = readAllFiles(certPath)[0];
        }

        const cryptoSuite = Client.newCryptoSuite();
        cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: module.exports.storePathForOrg(ORGS[userOrg].name)}));
        client.setCryptoSuite(cryptoSuite);

        return await client.createUser({
            username: 'peer'+userOrg+'Admin',
            mspid: org.mspid,
            cryptoContent: {
                privateKeyPEM: keyPEM.toString(),
                signedCertPEM: certPEM.toString()
            }
        });
    }
    catch(err) {
        commLogger.error(`Couldn't retrieve admin of ${userOrg}: ${err.stack ? err.stack : err}`);
        throw err;
    }
github dongmingh / v1performance / pte-main.js View on Github external
function chaincodeInstall(channel, client, org) {
    orgName = ORGS[org].name;
    logger.info('[chaincodeInstall] org: %s, org Name: %s, channel name: %s', org, orgName, channel.getName());

    var cryptoSuite = hfc.newCryptoSuite();
    cryptoSuite.setCryptoKeyStore(hfc.newCryptoKeyStore({path: testUtil.storePathForOrg(Nid, orgName)}));
    client.setCryptoSuite(cryptoSuite);

    chainAddOrderer(channel, client, org);

    channelAddPeer(channel, client, org);
    //printChainInfo(channel);

    //sendInstallProposal
    var request_install = {
        targets: targets,
        chaincodePath: uiContent.deploy.chaincodePath,
        chaincodeId: chaincode_id,
        chaincodeVersion: chaincode_ver
    };