Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
'use strict';
// TODO(murgatroid99): use multiple grpc implementations
var grpc = require('grpc');
var proto = grpc.load(__dirname + '/../packages/grpc-native-core/ext/grpc/src/proto/grpc/testing/metrics.proto');
var metrics = proto.grpc.testing;
function main() {
var parseArgs = require('minimist');
var argv = parseArgs(process.argv, {
string: 'metrics_server_address',
boolean: 'total_only'
});
var client = new metrics.MetricsService(argv.metrics_server_address,
grpc.credentials.createInsecure());
if (argv.total_only) {
client.getGauge({name: 'qps'}, function(err, data) {
console.log(data.name + ':', data.long_value);
});
} else {
var call = client.getAllGauges({});
var grpc = require('grpc');
var util = require('util');
var jsrsa = require('jsrsasign');
var elliptic = require('elliptic');
var sha3 = require('js-sha3');
var BN = require('bn.js');
var crypto = require("./crypto");
var stats = require("./stats");
var sdk_util = require("./sdk_util");
var events = require('events');
var debug = debugModule('hfc'); // 'hfc' stands for 'Hyperledger Fabric Client'
var asn1 = jsrsa.asn1;
var asn1Builder = require('asn1');
var _caProto = grpc.load(__dirname + "/protos/ca.proto").protos;
var _fabricProto = grpc.load(__dirname + "/protos/fabric.proto").protos;
var _chaincodeProto = grpc.load(__dirname + "/protos/chaincode.proto").protos;
var net = require('net');
var DEFAULT_SECURITY_LEVEL = 256;
var DEFAULT_HASH_ALGORITHM = "SHA3";
var CONFIDENTIALITY_1_2_STATE_KD_C6 = 6;
var _chains = {};
// A request to get a batch of TCerts
var GetTCertBatchRequest = (function () {
function GetTCertBatchRequest(name, enrollment, num, attrs) {
this.name = name;
this.enrollment = enrollment;
this.num = num;
this.attrs = attrs;
}
;
return GetTCertBatchRequest;
}());
var grpc = require('grpc');
var booksProto = grpc.load('books.proto');
// In-memory array of book objects
var books = [{
id: 123,
title: 'A Tale of Two Cities',
author: 'Charles Dickens'
}];
var server = new grpc.Server();
server.addProtoService(booksProto.books.BookService.service, {
list: function(call, callback) {
callback(null, books);
},
insert: function(call, callback) {
books.push(call.request);
callback(null, {});
var zlib = require("zlib");
var debugModule = require('debug');
let debug = debugModule('hfc'); // 'hfc' stands for 'HyperLedger Fabric Client'
//
// Load required crypto stuff.
//
var sha3_256 = require('js-sha3').sha3_256;
//
// Load required protobufs.
//
var _timeStampProto = grpc.load(__dirname + "/protos/google/protobuf/timestamp.proto").google.protobuf.Timestamp;
//
// GenerateUUID returns an RFC4122 compliant UUID.
// http://www.ietf.org/rfc/rfc4122.txt
//
export function GenerateUUID() {
return uuid.v4();
};
//
// GenerateTimestamp returns the current time in the google/protobuf/timestamp.proto
// structure.
//
export function GenerateTimestamp() {
"use strict";
const grpc = require("grpc");
const SERVER_PORT = 9000;
const XOR_CONSTR = `model-server:${SERVER_PORT}`;
const EMOTION_CONSTR = `emotion-server:${SERVER_PORT}`;
const GENDER_CONSTR = `gender-server:${SERVER_PORT}`;
const PROTO_PATH = __dirname + "/protos/prediction_service.proto";
const TensorflowServing = grpc.load(PROTO_PATH).tensorflow.serving;
/*
this should actually be split in a
generic client/predict class
*/
const xorClient = new TensorflowServing.PredictionService(
XOR_CONSTR, grpc.credentials.createInsecure()
);
const emotionClient = new TensorflowServing.PredictionService(
EMOTION_CONSTR, grpc.credentials.createInsecure()
);
const genderClient = new TensorflowServing.PredictionService(
GENDER_CONSTR, grpc.credentials.createInsecure()
var Policy = require('./Policy.js');
var logger = utils.getLogger('ChannelConfig.js');
var _ccProto = grpc.load(__dirname + '/protos/peer/chaincode.proto').protos;
var _transProto = grpc.load(__dirname + '/protos/peer/transaction.proto').protos;
var _proposalProto = grpc.load(__dirname + '/protos/peer/proposal.proto').protos;
var _responseProto = grpc.load(__dirname + '/protos/peer/proposal_response.proto').protos;
var _queryProto = grpc.load(__dirname + '/protos/peer/query.proto').protos;
var _peerConfigurationProto = grpc.load(__dirname + '/protos/peer/configuration.proto').protos;
var _mspPrProto = grpc.load(__dirname + '/protos/msp/msp_principal.proto').common;
var _commonProto = grpc.load(__dirname + '/protos/common/common.proto').common;
var _configtxProto = grpc.load(__dirname + '/protos/common/configtx.proto').common;
var _policiesProto = grpc.load(__dirname + '/protos/common/policies.proto').common;
var _ledgerProto = grpc.load(__dirname + '/protos/common/ledger.proto').common;
var _commonConfigurationProto = grpc.load(__dirname + '/protos/common/configuration.proto').common;
var _ordererConfigurationProto = grpc.load(__dirname + '/protos/orderer/configuration.proto').orderer;
var _abProto = grpc.load(__dirname + '/protos/orderer/ab.proto').orderer;
var _mspConfigProto = grpc.load(__dirname + '/protos/msp/msp_config.proto').msp;
var _timestampProto = grpc.load(__dirname + '/protos/google/protobuf/timestamp.proto').google.protobuf;
var _identityProto = grpc.load(path.join(__dirname, '/protos/msp/identities.proto')).msp;
const ImplicitMetaPolicy_Rule = {ANY:0, ALL:1, MAJORITY:2};
/**
* Builds a Protobuf Channel Config which may be used to create hyperledger/fabric channel
* @class
*/
var ChannelConfig = class {
/**
* Construct an utility object that builds a fabric channel configuration.
* This will allow the building of a protobuf ConfigUpdate object
var _ccProto = grpc.load(__dirname + '/protos/peer/chaincode.proto').protos;
var _transProto = grpc.load(__dirname + '/protos/peer/transaction.proto').protos;
var _proposalProto = grpc.load(__dirname + '/protos/peer/proposal.proto').protos;
var _responseProto = grpc.load(__dirname + '/protos/peer/proposal_response.proto').protos;
var _queryProto = grpc.load(__dirname + '/protos/peer/query.proto').protos;
var _peerConfigurationProto = grpc.load(__dirname + '/protos/peer/configuration.proto').protos;
var _mspPrProto = grpc.load(__dirname + '/protos/msp/msp_principal.proto').common;
var _commonProto = grpc.load(__dirname + '/protos/common/common.proto').common;
var _configtxProto = grpc.load(__dirname + '/protos/common/configtx.proto').common;
var _policiesProto = grpc.load(__dirname + '/protos/common/policies.proto').common;
var _ledgerProto = grpc.load(__dirname + '/protos/common/ledger.proto').common;
var _commonConfigurationProto = grpc.load(__dirname + '/protos/common/configuration.proto').common;
var _ordererConfigurationProto = grpc.load(__dirname + '/protos/orderer/configuration.proto').orderer;
var _abProto = grpc.load(__dirname + '/protos/orderer/ab.proto').orderer;
var _mspConfigProto = grpc.load(__dirname + '/protos/msp/msp_config.proto').msp;
var _timestampProto = grpc.load(__dirname + '/protos/google/protobuf/timestamp.proto').google.protobuf;
var _identityProto = grpc.load(path.join(__dirname, '/protos/msp/identities.proto')).msp;
const ImplicitMetaPolicy_Rule = {ANY:0, ALL:1, MAJORITY:2};
/**
* Builds a Protobuf Channel Config which may be used to create hyperledger/fabric channel
* @class
*/
var ChannelConfig = class {
/**
* Construct an utility object that builds a fabric channel configuration.
* This will allow the building of a protobuf ConfigUpdate object
* that will be based on the MSPs loaded here using the simplified JSON
* definition of a channel.
* @param {Object[]} msps Map of Member Service Provider objects
async function main() {
if (typeof(argv.cfg)!=='undefined') {
cfgData = toml.parse(fs.readFileSync(argv.cfg,'utf8'));
var servers = [];
Object.keys(cfgData["server"]).forEach((name) => {
servers.push(cfgData["server"][name]);
});
for (let item of servers) {
if (item.service) {
let root = await protobuf.load(item.proto);
const apiData = api(root,item.service, wsProto);
var generatedApi = apiData["output"];
var methodNames = apiData["methods"];
var proto = grpc.load(item.proto);
var stub=null;
eval("stub = proto." + item.pkg);
var service = { cfg:item, api:generatedApi,methods:methodNames,remote:stub, grpc:item.grpc};
services[item.service] = service;
apiText+=generatedApi;
}
}
}
app.use(require('helmet')());
if (typeof(argv.webroot)=='undefined')
app.use('/', express.static("."));
else
app.use('/', express.static(argv.webroot));
var urlParser = require('url');
var grpc = require('grpc');
var events = require('events');
var util = require('util');
//crypto stuff
var jsrsa = require('jsrsasign');
var KEYUTIL = jsrsa.KEYUTIL;
var asn1 = jsrsa.asn1;
var elliptic = require('elliptic');
var sha3_256 = require('js-sha3').sha3_256;
var sha3_384 = require('js-sha3').sha3_384;
var kdf = require(__dirname+'/kdf');
var _caProto = grpc.load(__dirname + "/protos/ca.proto").protos;
var _fabricProto = grpc.load(__dirname + "/protos/fabric.proto").protos;
var _timeStampProto = grpc.load(__dirname + "/protos/google/protobuf/timestamp.proto").google.protobuf.Timestamp;
var _chains = {};
var DEFAULT_TCERT_BATCH_SIZE = 200;
/**
* Create a new chain. If it already exists, throws an Error.
* @param name {string} Name of the chain. It can be any name and has value only for the client.
* @returns
*/
function newChain(name) {
var chain = _chains[name];
if (chain) throw Error(util.format("chain %s already exists",name));
chain = new Chain(name);
_chains[name] = chain;
return chain;