fabric-samples/commercial-paper/organization/digibank/application/addToWallet.js
Anthony O'Dowd e67fcf14a3 FAB-12322 Update commercial-paper sample
Change-Id: I235cb62df492b7713bb1c355b7457f679903bd34
Signed-off-by: Anthony O'Dowd <a_o-dowd@uk.ibm.com>
2018-11-14 17:53:12 +00:00

45 lines
No EOL
1.4 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 { FileSystemWallet, X509WalletMixin } = require('fabric-network');
const path = require('path');
const fixtures = path.resolve(__dirname, '../../../../basic-network');
// A wallet stores a collection of identities
const wallet = new FileSystemWallet('../identity/user/balaji/wallet');
async function main() {
// Main try/catch block
try {
// 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 cert = fs.readFileSync(path.join(credPath, '/msp/signcerts/Admin@org1.example.com-cert.pem')).toString();
const key = fs.readFileSync(path.join(credPath, '/msp/keystore/cd96d5260ad4757551ed4a5a991e62130f8008a0bf996e4e4b84cd097a747fec_sk')).toString();
// Load credentials into wallet
const identityLabel = 'Admin@org1.example.com';
const identity = X509WalletMixin.createIdentity('Org1MSP', cert, key);
await wallet.import(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);
});