-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enrollUser files to commercial paper (#140)
Signed-off-by: NIKHIL E GUPTA <[email protected]> Co-authored-by: NIKHIL E GUPTA <[email protected]>
- Loading branch information
Showing
9 changed files
with
126 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]/msp/signcerts/* ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected] | ||
cp ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/* ${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk | ||
|
||
cp ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/* ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected] | ||
cp ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/* ${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/priv_sk | ||
|
||
echo Suggest that you monitor the docker containers by running | ||
echo "./organization/magnetocorp/configuration/cli/monitordocker.sh net_test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,4 +100,4 @@ main().then(() => { | |
console.log(e.stack); | ||
process.exit(-1); | ||
|
||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
commercial-paper/organization/digibank/application/enrollUser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
commercial-paper/organization/magnetocorp/application/enrollUser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,4 +98,4 @@ main().then(() => { | |
console.log(e.stack); | ||
process.exit(-1); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters