UNPKG

@fabric-es/operator

Version:
34 lines 1.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFabricCaService = void 0; const path_1 = __importDefault(require("path")); const util_1 = __importDefault(require("util")); const fabric_ca_client_1 = __importDefault(require("fabric-ca-client")); const js_yaml_1 = __importDefault(require("js-yaml")); const getLogger_1 = require("./getLogger"); const promiseToReadFile_1 = require("./promiseToReadFile"); const getFabricCaService = async (connectionProfile, caName) => { let caService; const logger = getLogger_1.getLogger({ name: '[operator] getFabricCaService.js' }); const ccpPath = path_1.default.resolve(connectionProfile); logger.debug(`ccpPath: ${ccpPath}`); try { const connection = await promiseToReadFile_1.promiseToReadFile(ccpPath); const ccp = js_yaml_1.default.safeLoad(connection); const caInfo = ccp.certificateAuthorities[caName]; logger.debug(util_1.default.format('cainfo: %j', caInfo)); const caTLSCACerts = await promiseToReadFile_1.promiseToReadFile(caInfo.tlsCACerts.path); logger.debug(`caTLSCACerts: ${caTLSCACerts}`); caService = new fabric_ca_client_1.default(caInfo.url, { trustedRoots: Buffer.from(caTLSCACerts), verify: false }, caInfo.caName); } catch (e) { logger.error(util_1.default.format('fail to getFabricCaService: %j', e)); throw new Error(e); } return caService; }; exports.getFabricCaService = getFabricCaService; //# sourceMappingURL=getFabricCaService.js.map