Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "fabric-common in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'fabric-common' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

/**
 * Copyright 2018 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
'use strict';

const {Utils:utils} = require('fabric-common');
const logger = utils.getLogger('DISCOVERY');

const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

const fs = require('fs');
const path = require('path');

const testUtil = require('./util.js');

test('\n\n***** D I S C O V E R Y  *****\n\n', async (t) => {

	// this will use the connection profile to set up the client
	const client_org1 = await testUtil.getClientForOrg(t, 'org1');
	const client_org2 = await testUtil.getClientForOrg(t, 'org2');
	let channel_org1 = null;
/**
 * Copyright 2017 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

// This is an end-to-end test that focuses on exercising all parts of the fabric APIs
// in a happy-path scenario
'use strict';

const {Utils:utils} = require('fabric-common');
const logger = utils.getLogger('E2E install-chaincode');

const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

const e2eUtils = require('../e2e/e2eUtils.js');
const testUtil = require('../../unit/util.js');
const version = 'v0';

test('\n\n***** Node-Chaincode End-to-end flow: chaincode install *****\n\n', (t) => {
	e2eUtils.installChaincode('org1', testUtil.NODE_CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'node', t, true)
		.then(() => {
			t.pass('Successfully installed chaincode in peers of organization "org1"');
			return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
		}, (err) => {
			t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
/**
 * Copyright 2016 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

// This is an end-to-end test that focuses on exercising all parts of the fabric APIs
// in a happy-path scenario
'use strict';

const {Utils: utils} = require('fabric-common');
const logger = utils.getLogger('get-config');

const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

const path = require('path');
const fs = require('fs');
const e2eUtils = require('./e2e/e2eUtils.js');

const Client = require('fabric-client');
const testUtil = require('./util.js');
const Peer = require('fabric-client/lib/Peer.js');
const Orderer = require('fabric-client/lib/Orderer.js');


const client = new Client();
/**
 * Copyright 2018 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
'use strict';

const {Utils:utils} = require('fabric-common');
const logger = utils.getLogger('ONLY-ADMIN');

const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

const fs = require('fs');
const path = require('path');

const testUtil = require('./util.js');

// Testing will demostrate how the connetion profile configuration may hold a
// admin user identity and it will be used for all fabric interactions.
// However since the network is using mutual TLS, the TLS connection will get
// valid certificates from the CertificateAuthority as a testing convenience.
// The CertificateAuthority will not be used to get the required signing certificates
// for the fabric requests.
* Copyright 2017 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

// This is an end to end test that focuses on exercising all parts of the fabric APIs
// in a happy-path scenario

// IMPORTANT ------>>>>> MUST RUN e2e.js FIRST
// AND set environment variables indicated in the comments
// at the end of the invoke-transaction run.

'use strict';

const {Utils:utils} = require('fabric-common');
const logger = utils.getLogger('query');

const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);

const path = require('path');
const util = require('util');
const e2eUtils = require('./e2e/e2eUtils.js');
const fs = require('fs');

const testUtil = require('./util.js');
const Client = require('fabric-client');
const Peer = require('fabric-client/lib/Peer.js');
const Orderer = require('fabric-client/lib/Orderer.js');
const BlockDecoder = require('fabric-client/lib/BlockDecoder.js');
test('\n\n** CryptoKeyStore tests - newCryptoKeyStore tests **\n\n', (t) => {
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
	const keyValStorePath = 'tmp/keyValStore1';
	const config = {path: keyValStorePath};
	let cs = utils.newCryptoKeyStore(config);
	t.equal(cs._storeConfig.opts, config, util.format('Returned instance should have store config opts of %j', config));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	const defaultKVSPath = path.join(os.homedir(), '.hfc-key-store');
	cs = utils.newCryptoKeyStore();
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');

	let kvsImplClass = require(utils.getConfigSetting('key-value-store'));
	cs = utils.newCryptoKeyStore(kvsImplClass);
	t.equal(cs._storeConfig.opts.path, defaultKVSPath, util.format('Returned instance should have store config opts.path of %s', defaultKVSPath));
	t.equal(typeof cs._storeConfig.superClass, 'function', 'Returned instance should have store config superClass');
test('Use FabricCAServices with a File KeyValueStore', (t) => {
	testUtil.resetDefaults();
	Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
	ORGS = Client.getConfigSetting('test-network');
	const fabricCAEndpoint = ORGS[userOrg].ca.url;

	// Set the relevant configuration values
	utils.setConfigSetting('crypto-keysize', 256);
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');

	// var keyValueStore = Client.getConfigSetting('key-value-store');
	const keyValStorePath = path.join(testUtil.getTempDir(), 'customKeyValStorePath');

	const client = new Client();
	let cryptoSuite, member;

	// clean up
	if (testUtil.existsSync(keyValStorePath)) {
		fs.removeSync(keyValStorePath);
	}

	const	tlsOptions = {
		trustedRoots: [],
		verify: false
test('\n\n** TEST ** orderer via member missing orderer', async (t) => {
	testUtil.resetDefaults();
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');// force for npm test
	Client.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
	ORGS = Client.getConfigSetting('test-network');
	const orgName = ORGS[org].name;

	//
	// Create and configure the test channel
	//
	const channel = client.newChannel('testchannel-orderer-member2');
	const cryptoSuite = Client.newCryptoSuite();
	cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({path: testUtil.storePathForOrg(orgName)}));
	client.setCryptoSuite(cryptoSuite);

	const store = await Client.newDefaultKeyValueStore({
		path: testUtil.KVS
	});
test('\n\n** CryptoKeyStore tests - couchdb based store tests - use configSetting **\n\n', (t) => {
	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/CouchDBKeyValueStore.js');

	const couchdb = CouchdbMock.createServer();
	couchdb.listen(5985);

	// override t.end function so it'll always disconnect the event hub
	t.end = ((context, mockdb, f) => {
		return function() {
			if (mockdb) {
				t.comment('Disconnecting the mock couchdb server');
				mockdb.close();
			}

			f.apply(context, arguments);
		};
	})(t, couchdb, t.end);
test('\n\n ** createUser happy path - file store **\n\n', (t) => {
	testUtil.resetDefaults();
	Client.addConfigFile(path.join(__dirname, '../fixtures/profiles/caimport.json'));
	caImport = utils.getConfigSetting('ca-import', 'notfound');

	utils.setConfigSetting('key-value-store', 'fabric-common/lib/impl/FileKeyValueStore.js');
	utils.setConfigSetting('crypto-keysize', 256);
	const userOrg = 'org1';

	const prvKey =  path.join(__dirname, caImport.orgs[userOrg].cryptoContent.privateKey);
	const sgnCert =  path.join(__dirname, caImport.orgs[userOrg].cryptoContent.signedCert);

	const keyStoreOpts = {path: path.join(testUtil.getTempDir(), caImport.orgs[userOrg].storePath)};
	const client = new Client();
	const cryptoSuite = Client.newCryptoSuite();
	cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore(keyStoreOpts));
	client.setCryptoSuite(cryptoSuite);

	logger.debug('try to cleanup kvs Path: ' + keyStoreOpts.path);
	// clean up
	if (testUtil.existsSync(keyStoreOpts.path)) {
		fs.removeSync(keyStoreOpts.path);

Is your System Free of Underlying Vulnerabilities?
Find Out Now