mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-18 16:05:10 +00:00
Add enrollUser files to commercial paper (#140)
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com> Co-authored-by: NIKHIL E GUPTA <negupta@us.ibm.com>
This commit is contained in:
parent
87600bd29b
commit
851933b33e
9 changed files with 126 additions and 12 deletions
|
|
@ -20,11 +20,17 @@ cd "${DIR}/../test-network/"
|
|||
|
||||
docker kill cliDigiBank cliMagnetoCorp logspout || true
|
||||
./network.sh down
|
||||
./network.sh up createChannel -s couchdb -i 2.0.0
|
||||
./network.sh up createChannel -ca -s couchdb
|
||||
|
||||
# Copy the connection profiles so they are in the correct organizations.
|
||||
# Copy the connection profiles so they are in the correct organizations.
|
||||
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "${DIR}/organization/digibank/gateway/"
|
||||
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "${DIR}/organization/magnetocorp/gateway/"
|
||||
|
||||
cp ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/* ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem
|
||||
cp ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/* ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk
|
||||
|
||||
cp ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/* ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/User1@org2.example.com-cert.pem
|
||||
cp ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/* ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/priv_sk
|
||||
|
||||
echo Suggest that you monitor the docker containers by running
|
||||
echo "./organization/magnetocorp/configuration/cli/monitordocker.sh net_test"
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ async function main() {
|
|||
const wallet = await Wallets.newFileSystemWallet('../identity/user/balaji/wallet');
|
||||
|
||||
// Identity to credentials to be stored in the wallet
|
||||
const credPath = path.join(fixtures, '/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com');
|
||||
const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/Admin@org1.example.com-cert.pem')).toString();
|
||||
const credPath = path.join(fixtures, '/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com');
|
||||
const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/User1@org1.example.com-cert.pem')).toString();
|
||||
const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/priv_sk')).toString();
|
||||
|
||||
// Load credentials into wallet
|
||||
const identityLabel = 'balaji';
|
||||
|
||||
|
||||
const identity = {
|
||||
credentials: {
|
||||
certificate,
|
||||
|
|
@ -50,4 +50,4 @@ main().then(() => {
|
|||
console.log(e);
|
||||
console.log(e.stack);
|
||||
process.exit(-1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -100,4 +100,4 @@ main().then(() => {
|
|||
console.log(e.stack);
|
||||
process.exit(-1);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const FabricCAServices = require('fabric-ca-client');
|
||||
const { Wallets } = require('fabric-network');
|
||||
const fs = require('fs');
|
||||
const yaml = require('js-yaml');
|
||||
const path = require('path');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// load the network configuration
|
||||
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org1.yaml', 'utf8'));
|
||||
|
||||
// Create a new CA client for interacting with the CA.
|
||||
const caInfo = connectionProfile.certificateAuthorities['ca.org1.example.com'];
|
||||
const caTLSCACerts = caInfo.tlsCACerts.pem;
|
||||
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
|
||||
|
||||
// Create a new file system based wallet for managing identities.
|
||||
const walletPath = path.join(process.cwd(), '../identity/user/balaji/wallet');
|
||||
const wallet = await Wallets.newFileSystemWallet(walletPath);
|
||||
console.log(`Wallet path: ${walletPath}`);
|
||||
|
||||
// Check to see if we've already enrolled the admin user.
|
||||
const userExists = await wallet.get('balaji');
|
||||
if (userExists) {
|
||||
console.log('An identity for the client user "balaji" already exists in the wallet');
|
||||
return;
|
||||
}
|
||||
|
||||
// Enroll the admin user, and import the new identity into the wallet.
|
||||
const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: 'user1pw' });
|
||||
const x509Identity = {
|
||||
credentials: {
|
||||
certificate: enrollment.certificate,
|
||||
privateKey: enrollment.key.toBytes(),
|
||||
},
|
||||
mspId: 'Org1MSP',
|
||||
type: 'X.509',
|
||||
};
|
||||
await wallet.put('balaji', x509Identity);
|
||||
console.log('Successfully enrolled client user "balaji" and imported it into the wallet');
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Failed to enroll client user "balaji": ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"fabric-network": "beta",
|
||||
"fabric-client": "beta",
|
||||
"fabric-ca-client": "beta",
|
||||
"js-yaml": "^3.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async function main() {
|
|||
type: 'X.509'
|
||||
}
|
||||
|
||||
|
||||
|
||||
await wallet.put(identityLabel,identity);
|
||||
|
||||
} catch (error) {
|
||||
|
|
@ -50,4 +50,4 @@ main().then(() => {
|
|||
console.log(e);
|
||||
console.log(e.stack);
|
||||
process.exit(-1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const FabricCAServices = require('fabric-ca-client');
|
||||
const { Wallets } = require('fabric-network');
|
||||
const fs = require('fs');
|
||||
const yaml = require('js-yaml');
|
||||
const path = require('path');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// load the network configuration
|
||||
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org2.yaml', 'utf8'));
|
||||
|
||||
// Create a new CA client for interacting with the CA.
|
||||
const caInfo = connectionProfile.certificateAuthorities['ca.org2.example.com'];
|
||||
const caTLSCACerts = caInfo.tlsCACerts.pem;
|
||||
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
|
||||
|
||||
// Create a new file system based wallet for managing identities.
|
||||
const walletPath = path.join(process.cwd(), '../identity/user/isabella/wallet');
|
||||
const wallet = await Wallets.newFileSystemWallet(walletPath);
|
||||
console.log(`Wallet path: ${walletPath}`);
|
||||
|
||||
// Check to see if we've already enrolled the admin user.
|
||||
const userExists = await wallet.get('isabella');
|
||||
if (userExists) {
|
||||
console.log('An identity for the client user "user1" already exists in the wallet');
|
||||
return;
|
||||
}
|
||||
|
||||
// Enroll the admin user, and import the new identity into the wallet.
|
||||
const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: 'user1pw' });
|
||||
const x509Identity = {
|
||||
credentials: {
|
||||
certificate: enrollment.certificate,
|
||||
privateKey: enrollment.key.toBytes(),
|
||||
},
|
||||
mspId: 'Org2MSP',
|
||||
type: 'X.509',
|
||||
};
|
||||
await wallet.put('isabella', x509Identity);
|
||||
console.log('Successfully enrolled client user "isabella" and imported it into the wallet');
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Failed to enroll client user "isabella": ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
@ -98,4 +98,4 @@ main().then(() => {
|
|||
console.log(e.stack);
|
||||
process.exit(-1);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"fabric-network": "beta",
|
||||
"fabric-client": "beta",
|
||||
"fabric-ca-client": "beta",
|
||||
"js-yaml": "^3.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue