fabric-samples/commercial-paper/organization/digibank/application/addToWallet.js
Matthew B White 4c2a0a4a49 [FAB-16147] Update Commercial Paper to work with v2 (#98)
Update the applications and scripts to use the new v2
SDKs and the new lifecycle

Add in a basic script based on the readme.md that does
a basic run of the scenario

Signed-off-by: Matthew B White <whitemat@uk.ibm.com>
2020-01-14 16:44:31 +00:00

53 lines
No EOL
1.6 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, '../../../../basic-network');
async function main() {
// Main try/catch block
try {
// A wallet stores a collection of identities
const wallet = await Wallets.newFileSystemWallet('../identity/user/balaji/wallet');
// Identity to credentials to be stored in the wallet
const credPath = path.join(fixtures, '/crypto-config/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 privateKey = fs.readFileSync(path.join(credPath, '/msp/keystore/5ba12183ab07014ba831f9a79cf51fe7e6f62cdebe6193f070445243aedddee9_sk')).toString();
// Load credentials into wallet
const identityLabel = 'Admin@org1.example.com';
const identity = {
credentials: {
certificate,
privateKey
},
mspId: 'Org1MSP',
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);
});