docker-compose-files/hyperledger_fabric/v2.2.1/sdk-node/createWallet.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-08-19 05:14:16 +08:00
"use strict";
const fs = require('fs');
const path = require('path');
const {common: commonProto} = require('fabric-protos');
const {Wallets} = require('fabric-network');
const mspId = 'Org1MSP';
2021-09-02 04:40:50 +08:00
const baseMSPPath = '../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp'
const signCertPath = path.resolve(baseMSPPath + '/signcerts/Admin@org1.example.com-cert.pem');
const signKeyPath = path.resolve(baseMSPPath + '/keystore/priv_sk');
2021-08-19 05:14:16 +08:00
const signCert = fs.readFileSync(signCertPath).toString();
const signKey = fs.readFileSync(signKeyPath).toString();
/**
* Main entrance method
* @returns {Promise<*>}
*/
const main = async () => {
2021-09-02 04:40:50 +08:00
const wallet = await Wallets.newFileSystemWallet('/opt/test/wallet');
2021-08-19 05:14:16 +08:00
2021-09-02 04:40:50 +08:00
const x509Identity = {
credentials: {
certificate: signCert,
privateKey: signKey,
},
mspId: mspId,
type: 'X.509',
};
await wallet.put(mspId + '-admin', x509Identity);
return "wallet is created"
2021-08-19 05:14:16 +08:00
};
main()
2021-09-02 04:40:50 +08:00
.then(console.log)
.catch(console.error);