Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.error('File does not exist at path: ', ccpPath);
console.error(
'Please check the CONNECTION_PROFILE environemnt variable in your .env. The path will default to the root of the fabric-driver folder if not supplied',
);
return;
}
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
const config = getConfig();
// Create a new CA client for interacting with the CA.
const org = ccp.client["organization"];
console.log('Org ', org);
const caName = ccp.organizations[org]["certificateAuthorities"][0];
console.log('CA Name ', caName);
const caURL = ccp.certificateAuthorities[config.caUrl ? config.caUrl : caName].url;
console.log('CA URL', caURL);
const ca = new FabricCAServices(caURL);
const ident = ca.newIdentityService();
const wallet = await Wallets.newFileSystemWallet(walletPath);
const adminName = config.admin.name;
const adminSecret = config.admin.secret;
// build a user object for authenticating with the CA // Check to see if we've already enrolled the admin user.
let adminIdentity = await wallet.get(adminName);
if (adminIdentity) {
console.log('An identity for the admin user "admin" already exists in the wallet');
} else {
// Enroll the admin user, and import the new identity into the wallet.
console.log('Enrolling Admin...', adminName, adminSecret);
const enrollment = await ca.enroll({
enrollmentID: adminName,
enrollmentSecret: adminSecret,
async function getSubmitter(
client, enrollmentID, enrollmentSecret, {
url,
mspId
}) {
try {
let user = await client.getUserContext(enrollmentID, true);
if (user && user.isEnrolled()) {
return user;
}
// Need to enroll with CA server
const ca = new CAClient(url, {
verify: false
});
try {
const enrollment = await ca.enroll({
enrollmentID,
enrollmentSecret
});
user = new User(enrollmentID, client);
await user.setEnrollment(enrollment.key, enrollment.certificate, mspId);
await client.setUserContext(user);
return user;
} catch (e) {
throw new Error(
`Failed to enroll and persist User. Error: ${e.message}`);
}
} catch (e) {