Skip to content

Commit 851933b

Browse files
nikhil550NIKHIL E GUPTA
and
NIKHIL E GUPTA
authored
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>
1 parent 87600bd commit 851933b

File tree

9 files changed

+126
-12
lines changed

9 files changed

+126
-12
lines changed

commercial-paper/network-starter.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ cd "${DIR}/../test-network/"
2020

2121
docker kill cliDigiBank cliMagnetoCorp logspout || true
2222
./network.sh down
23-
./network.sh up createChannel -s couchdb -i 2.0.0
23+
./network.sh up createChannel -ca -s couchdb
2424

25-
# Copy the connection profiles so they are in the correct organizations.
25+
# Copy the connection profiles so they are in the correct organizations.
2626
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "${DIR}/organization/digibank/gateway/"
2727
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "${DIR}/organization/magnetocorp/gateway/"
2828

29+
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
30+
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
31+
32+
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
33+
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
34+
2935
echo Suggest that you monitor the docker containers by running
3036
echo "./organization/magnetocorp/configuration/cli/monitordocker.sh net_test"

commercial-paper/organization/digibank/application/addToWallet.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ async function main() {
2020
const wallet = await Wallets.newFileSystemWallet('../identity/user/balaji/wallet');
2121

2222
// Identity to credentials to be stored in the wallet
23-
const credPath = path.join(fixtures, '/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com');
24-
const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/Admin@org1.example.com-cert.pem')).toString();
23+
const credPath = path.join(fixtures, '/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com');
24+
const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/User1@org1.example.com-cert.pem')).toString();
2525
const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/priv_sk')).toString();
2626

2727
// Load credentials into wallet
2828
const identityLabel = 'balaji';
29-
29+
3030
const identity = {
3131
credentials: {
3232
certificate,
@@ -50,4 +50,4 @@ main().then(() => {
5050
console.log(e);
5151
console.log(e.stack);
5252
process.exit(-1);
53-
});
53+
});

commercial-paper/organization/digibank/application/buy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ main().then(() => {
100100
console.log(e.stack);
101101
process.exit(-1);
102102

103-
});
103+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
'use strict';
6+
7+
const FabricCAServices = require('fabric-ca-client');
8+
const { Wallets } = require('fabric-network');
9+
const fs = require('fs');
10+
const yaml = require('js-yaml');
11+
const path = require('path');
12+
13+
async function main() {
14+
try {
15+
// load the network configuration
16+
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org1.yaml', 'utf8'));
17+
18+
// Create a new CA client for interacting with the CA.
19+
const caInfo = connectionProfile.certificateAuthorities['ca.org1.example.com'];
20+
const caTLSCACerts = caInfo.tlsCACerts.pem;
21+
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
22+
23+
// Create a new file system based wallet for managing identities.
24+
const walletPath = path.join(process.cwd(), '../identity/user/balaji/wallet');
25+
const wallet = await Wallets.newFileSystemWallet(walletPath);
26+
console.log(`Wallet path: ${walletPath}`);
27+
28+
// Check to see if we've already enrolled the admin user.
29+
const userExists = await wallet.get('balaji');
30+
if (userExists) {
31+
console.log('An identity for the client user "balaji" already exists in the wallet');
32+
return;
33+
}
34+
35+
// Enroll the admin user, and import the new identity into the wallet.
36+
const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: 'user1pw' });
37+
const x509Identity = {
38+
credentials: {
39+
certificate: enrollment.certificate,
40+
privateKey: enrollment.key.toBytes(),
41+
},
42+
mspId: 'Org1MSP',
43+
type: 'X.509',
44+
};
45+
await wallet.put('balaji', x509Identity);
46+
console.log('Successfully enrolled client user "balaji" and imported it into the wallet');
47+
48+
} catch (error) {
49+
console.error(`Failed to enroll client user "balaji": ${error}`);
50+
process.exit(1);
51+
}
52+
}
53+
54+
main();

commercial-paper/organization/digibank/application/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "Apache-2.0",
1212
"dependencies": {
1313
"fabric-network": "beta",
14-
"fabric-client": "beta",
14+
"fabric-ca-client": "beta",
1515
"js-yaml": "^3.12.0"
1616
},
1717
"devDependencies": {

commercial-paper/organization/magnetocorp/application/addToWallet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function main() {
3535
type: 'X.509'
3636
}
3737

38-
38+
3939
await wallet.put(identityLabel,identity);
4040

4141
} catch (error) {
@@ -50,4 +50,4 @@ main().then(() => {
5050
console.log(e);
5151
console.log(e.stack);
5252
process.exit(-1);
53-
});
53+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
'use strict';
6+
7+
const FabricCAServices = require('fabric-ca-client');
8+
const { Wallets } = require('fabric-network');
9+
const fs = require('fs');
10+
const yaml = require('js-yaml');
11+
const path = require('path');
12+
13+
async function main() {
14+
try {
15+
// load the network configuration
16+
let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/connection-org2.yaml', 'utf8'));
17+
18+
// Create a new CA client for interacting with the CA.
19+
const caInfo = connectionProfile.certificateAuthorities['ca.org2.example.com'];
20+
const caTLSCACerts = caInfo.tlsCACerts.pem;
21+
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
22+
23+
// Create a new file system based wallet for managing identities.
24+
const walletPath = path.join(process.cwd(), '../identity/user/isabella/wallet');
25+
const wallet = await Wallets.newFileSystemWallet(walletPath);
26+
console.log(`Wallet path: ${walletPath}`);
27+
28+
// Check to see if we've already enrolled the admin user.
29+
const userExists = await wallet.get('isabella');
30+
if (userExists) {
31+
console.log('An identity for the client user "user1" already exists in the wallet');
32+
return;
33+
}
34+
35+
// Enroll the admin user, and import the new identity into the wallet.
36+
const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: 'user1pw' });
37+
const x509Identity = {
38+
credentials: {
39+
certificate: enrollment.certificate,
40+
privateKey: enrollment.key.toBytes(),
41+
},
42+
mspId: 'Org2MSP',
43+
type: 'X.509',
44+
};
45+
await wallet.put('isabella', x509Identity);
46+
console.log('Successfully enrolled client user "isabella" and imported it into the wallet');
47+
48+
} catch (error) {
49+
console.error(`Failed to enroll client user "isabella": ${error}`);
50+
process.exit(1);
51+
}
52+
}
53+
54+
main();

commercial-paper/organization/magnetocorp/application/issue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ main().then(() => {
9898
console.log(e.stack);
9999
process.exit(-1);
100100

101-
});
101+
});

commercial-paper/organization/magnetocorp/application/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "Apache-2.0",
1212
"dependencies": {
1313
"fabric-network": "beta",
14-
"fabric-client": "beta",
14+
"fabric-ca-client": "beta",
1515
"js-yaml": "^3.12.0"
1616
},
1717
"devDependencies": {

0 commit comments

Comments
 (0)