How to use the fabric-common.User function in fabric-common

To help you get started, we’ve selected a few fabric-common 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 / fabric-ca-services-tests.js View on Github external
}).then((secret) => {
			t.comment('secret: ' + JSON.stringify(secret));
			enrollmentSecret = secret; // to be used in the next test case

			t.pass('testUser \'' + enrollmentID + '\'');

			member = new User('adminX');
			return member.setEnrollment(eResult.key, eResult.certificate, 'Org1MSP');
		}, (err) => {
			t.fail(util.format('Failed to register "%s". %s', enrollmentID, err.stack ? err.stack : err));
github hyperledger / fabric-sdk-node / test / integration / fabric-ca-certificate-service-tests.js View on Github external
const req = {
		enrollmentID: 'user_' + Math.floor(Math.random() * 1000),
		enrollmentSecret: 'userpw',
		affiliation,
		// set this identity can manage identities of the role user
		attrs: [{name: HFCAIdentityAttributes.HFREGISTRARROLES, value: HFCAIdentityType.USER}]
	};

	await identityService.create(req, admin);

	const enrollment = await ca.enroll({
		enrollmentID: req.enrollmentID,
		enrollmentSecret: req.enrollmentSecret
	});
	const user = new User(req.enrollmentID);
	await user.setEnrollment(enrollment.key, enrollment.certificate, mspId);
	return user;
}
github hyperledger / fabric-sdk-node / test / integration / fabric-ca-identity-service-tests.js View on Github external
};
	let hfcaIdentityService1;
	let hfcaIdentityService2;

	try {
		const enrollment1 = await caService1.enroll(bootstrapUser);
		t.pass('Successfully enrolled admin at ca_Org1');

		const enrollment2 = await caService2.enroll(bootstrapUser);
		t.pass('Successfully enrolled admin at ca_Org2');

		admin1 = new User('admin');
		await admin1.setEnrollment(enrollment1.key, enrollment1.certificate, 'Org1MSP');
		t.pass('Successfully set enrollment for user admin1');

		admin2 = new User('admin2');
		await admin2.setEnrollment(enrollment2.key, enrollment2.certificate, 'Org2MSP');
		t.pass('Successfully set enrollment for user admin2');

		hfcaIdentityService1 = caService1.newIdentityService();
		hfcaIdentityService2 = caService2.newIdentityService();

		// create a new Identity with admin1
		let resp = await hfcaIdentityService1.create(testIdentity, admin1);
		t.equal(resp, testIdentity.enrollmentSecret, 'Response matched enrollment secret');
		t.pass('Successfully created new Identity %s by admin1', testIdentity.enrollmentID);

		let enrollment;
		// enroll the new created user at ca_Org1
		enrollment = await caService1.enroll({
			enrollmentID: testIdentity.enrollmentID,
			enrollmentSecret: testIdentity.enrollmentSecret
github hyperledger / fabric-sdk-node / test / integration / fabric-ca-identity-service-tests.js View on Github external
hfcaIdentityService1 = caService1.newIdentityService();
		hfcaIdentityService2 = caService2.newIdentityService();

		// create a new Identity with admin1
		let resp = await hfcaIdentityService1.create(testIdentity, admin1);
		t.equal(resp, testIdentity.enrollmentSecret, 'Response matched enrollment secret');
		t.pass('Successfully created new Identity %s by admin1', testIdentity.enrollmentID);

		let enrollment;
		// enroll the new created user at ca_Org1
		enrollment = await caService1.enroll({
			enrollmentID: testIdentity.enrollmentID,
			enrollmentSecret: testIdentity.enrollmentSecret
		});
		t.pass(`Successfully enrolled ${testIdentity.enrollmentID} at ca_Org1`);
		const identity = new User(testIdentity.enrollmentID);
		await identity.setEnrollment(enrollment.key, enrollment.certificate, 'Org1MSP');

		// should throw error if we enroll this new identity at ca_Org2
		try {
			enrollment = await caService2.enroll({
				enrollmentID: testIdentity.enrollmentID,
				enrollmentSecret: testIdentity.enrollmentSecret
			});
			t.fail('should throw error if we enroll this new identity at ca_Org2');
			t.end();
		} catch (e) {
			t.ok(e.message.indexOf('failure') >= 0, 'throws expected error if we enroll this new identity at ca_Org2');
		}

		// get this Identity from ca_Org1 by identity
		resp = await hfcaIdentityService1.getOne(testIdentity.enrollmentID, identity);
github hyperledger / fabric-sdk-node / fabric-client / lib / Client.js View on Github external
async loadUserFromStateStore(name) {
		const memberStr = await this._stateStore.getValue(name);
		if (!memberStr) {
			logger.debug(`Failed to find "${name}" in local key value store`);
			return null;
		}

		// The member was found in the key value store, so restore the state.
		const newUser = new User(name);
		if (!this.getCryptoSuite()) {
			logger.debug('loadUserFromStateStore, cryptoSuite is not set, will load using defaults');
		}
		newUser.setCryptoSuite(this.getCryptoSuite());
		const data = await newUser.fromString(memberStr, true);
		if (!data) {
			logger.debug(`Failed to load user "${name}" from local key value store`);
			return null;
		}
		logger.debug(`Successfully load user "${name}" from local key value store`);
		return data;
	}
github hyperledger / fabric-sdk-node / fabric-client / lib / Client.js View on Github external
logger.debug('cryptoSuite does not have a cryptoKeyStore');
			}
		}

		// need to load private key and pre-enrolled certificate from files based on the MSP
		// root MSP config directory structure:
		// 
		//    \_ keystore
		//       \_ admin.pem  <<== this is the private key saved in PEM file
		//    \_ signcerts
		//       \_ admin.pem  <<== this is the signed certificate saved in PEM file

		// first load the private key and save in the BCCSP's key store

		let importedKey;
		const user = new User(opts.username);
		let privateKeyPEM = opts.cryptoContent.privateKeyPEM;
		if (opts.cryptoContent.privateKey) {
			privateKeyPEM = await readFile(opts.cryptoContent.privateKey);
		}
		if (privateKeyPEM) {
			logger.debug('then privateKeyPEM data');
			if (opts.skipPersistence) {
				importedKey = await this.getCryptoSuite().createKeyFromRaw(privateKeyPEM.toString());
			} else {
				importedKey = await this.getCryptoSuite().importKey(privateKeyPEM.toString());
			}
		} else {
			importedKey = opts.cryptoContent.privateKeyObj;
		}
		let signedCertPEM = opts.cryptoContent.signedCertPEM;
		if (opts.cryptoContent.signedCert) {
github hyperledger / fabric-sdk-node / test / integration / cloudant-fabricca-tests.js View on Github external
() => {
						return client.setUserContext(new User('userx'));
					})
				.then(
github hyperledger / fabric-sdk-node / test / integration / fabric-ca-certificate-service-tests.js View on Github external
async function enrollAdmin(caService1, caService2, t) {
	const bootstrapUser = {
		enrollmentID: 'admin',
		enrollmentSecret: 'adminpw'
	};
	const enrollment1 = await caService1.enroll(bootstrapUser);
	t.pass('Successfully enrolled admin at ca_Org1');

	const enrollment2 = await caService2.enroll(bootstrapUser);
	t.pass('Successfully enrolled admin at ca_Org2');

	const admin1 = new User('admin1');
	await admin1.setEnrollment(enrollment1.key, enrollment1.certificate, 'Org1MSP');
	t.pass('Successfully set enrollment for user admin1');

	const admin2 = new User('admin2');
	await admin2.setEnrollment(enrollment2.key, enrollment2.certificate, 'Org2MSP');
	t.pass('Successfully set enrollment for user admin2');
	return {admin1, admin2};
}
github hyperledger / fabric-sdk-node / test / integration / couchdb-fabricca-tests.js View on Github external
() => {
						return client.setUserContext(new User('userx'));
					})
				.then(