mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
* WIP Commercial Paper -> Test network Signed-off-by: Matthew B White <whitemat@uk.ibm.com> * Update Commercial Paper to v2.0 lifecycle - move to using the test-network - updating README.md to include commands to use v2.0 lifecylce - update Contracts and Applications to use 2.0 libraries Signed-off-by: Matthew B White <whitemat@uk.ibm.com>
53 lines
No EOL
1.5 KiB
JavaScript
53 lines
No EOL
1.5 KiB
JavaScript
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
// Bring key classes into scope, most importantly Fabric SDK network class
|
|
const fs = require('fs');
|
|
const { Wallets } = require('fabric-network');
|
|
const path = require('path');
|
|
|
|
const fixtures = path.resolve(__dirname, '../../../../test-network');
|
|
|
|
async function main() {
|
|
|
|
// Main try/catch block
|
|
try {
|
|
// A wallet stores a collection of identities
|
|
const wallet = await Wallets.newFileSystemWallet('../identity/user/isabella/wallet');
|
|
|
|
// Identity to credentials to be stored in the wallet
|
|
const credPath = path.join(fixtures, '/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com');
|
|
const certificate = fs.readFileSync(path.join(credPath, '/msp/signcerts/User1@org2.example.com-cert.pem')).toString();
|
|
const privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/priv_sk')).toString();
|
|
|
|
// Load credentials into wallet
|
|
const identityLabel = 'isabella';
|
|
|
|
const identity = {
|
|
credentials: {
|
|
certificate,
|
|
privateKey
|
|
},
|
|
mspId: 'Org2MSP',
|
|
type: 'X.509'
|
|
}
|
|
|
|
|
|
await wallet.put(identityLabel,identity);
|
|
|
|
} catch (error) {
|
|
console.log(`Error adding to wallet. ${error}`);
|
|
console.log(error.stack);
|
|
}
|
|
}
|
|
|
|
main().then(() => {
|
|
console.log('done');
|
|
}).catch((e) => {
|
|
console.log(e);
|
|
console.log(e.stack);
|
|
process.exit(-1);
|
|
}); |