fabric-shim
Advanced tools
Comparing version 1.0.0-snapshot.7 to 1.0.0-snapshot.8
@@ -16,12 +16,6 @@ /* | ||
const Stub = require('./stub.js'); | ||
const fs = require('fs'); | ||
const argsDef = [{ | ||
name: 'peer.address', type: String | ||
},{ | ||
name: 'key', type: String | ||
},{ | ||
name: 'cert', type: String | ||
},]; | ||
}]; | ||
let opts = CLIArgs(argsDef); | ||
@@ -55,8 +49,5 @@ | ||
let url = parsePeerUrl(opts['peer.address']); | ||
if (isTLS()){ | ||
opts.pem = fs.readFileSync(process.env.CORE_PEER_TLS_ROOTCERT_FILE).toString(); | ||
} | ||
logger.debug(opts); | ||
let client = new Handler(chaincode, url, opts); | ||
let client = new Handler(chaincode, url); | ||
let chaincodeName = process.env.CORE_CHAINCODE_ID_NAME; | ||
@@ -104,3 +95,4 @@ let chaincodeID = new _chaincodeProto.ChaincodeID(); | ||
if (url.indexOf('grpc://') !== 0 && url.indexOf('grpcs://') !== 0) { | ||
if (isTLS()) | ||
let tls = process.env.CORE_PEER_TLS_ENABLED; | ||
if (typeof tls === 'string' && tls.toLowerCase() === 'true') | ||
url = 'grpcs://' + url; | ||
@@ -116,9 +108,4 @@ else | ||
function isTLS(){ | ||
let tls = process.env.CORE_PEER_TLS_ENABLED; | ||
return typeof tls === 'string' && tls.toLowerCase() === 'true'; | ||
} | ||
module.exports.start = start; | ||
module.exports.success = success; | ||
module.exports.error = error; |
@@ -9,4 +9,2 @@ /* | ||
process.env.GRPC_SSL_CIPHER_SUITES = 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384'; | ||
const grpc = require('grpc'); | ||
@@ -88,9 +86,25 @@ const urlParser = require('url'); | ||
let pem = null; | ||
let ssl_target_name_override = ''; | ||
let default_authority = ''; | ||
if (opts && opts.pem) { | ||
pem = opts.pem; | ||
} | ||
if (opts && opts['ssl-target-name-override']) { | ||
ssl_target_name_override = opts['ssl-target-name-override']; | ||
default_authority = opts['ssl-target-name-override']; | ||
} | ||
// connection options | ||
this._options = {}; | ||
if (opts && opts['ssl-target-name-override'] && opts['ssl-target-name-override'] !== '') { | ||
this._options['grpc.ssl_target_name_override'] = opts['ssl-target-name-override']; | ||
this._options['grpc.default_authority'] = opts['ssl-target-name-override']; | ||
if (ssl_target_name_override !== '') { | ||
this._options['grpc.ssl_target_name_override'] = ssl_target_name_override; | ||
} | ||
if (default_authority !== '') { | ||
this._options['grpc.default_authority'] = default_authority; | ||
} | ||
for (let key in opts ? opts : {}) { | ||
@@ -104,3 +118,3 @@ if (key !== 'pem' && key !== 'ssl-target-name-override') { | ||
this._url = url; | ||
this._endpoint = new Endpoint(url, opts); | ||
this._endpoint = new Endpoint(url, pem); | ||
@@ -112,2 +126,3 @@ // node.js based timeout | ||
} | ||
this._client = new _serviceProto.ChaincodeSupport(this._endpoint.addr, this._endpoint.creds, this._options); | ||
@@ -511,4 +526,4 @@ this._peerListeners = {}; | ||
let Endpoint = class { | ||
constructor(url /*string*/, opts ) { | ||
var fs = require('fs'), | ||
constructor(url /*string*/ , pem /*string*/ ) { | ||
let fs = require('fs'), | ||
path = require('path'); | ||
@@ -525,13 +540,7 @@ | ||
} else if (protocol === 'grpcs') { | ||
if(!opts || !opts.pem || !(typeof opts.pem === 'string')) { | ||
if(!(typeof pem === 'string')) { | ||
throw new Error('PEM encoded certificate is required.'); | ||
} | ||
if(!opts.key || !(typeof opts.key === 'string')) { | ||
throw new Error('encoded Private key is required.'); | ||
} | ||
if(!opts.cert || !(typeof opts.cert === 'string')) { | ||
throw new Error('encoded client certificate is required.'); | ||
} | ||
this.addr = purl.host; | ||
this.creds = grpc.credentials.createSsl(Buffer.from(opts.pem), Buffer.from(opts.key,'base64'), Buffer.from(opts.cert,'base64')); | ||
this.creds = grpc.credentials.createSsl(new Buffer(pem)); | ||
} else { | ||
@@ -538,0 +547,0 @@ let error = new Error(); |
@@ -62,4 +62,6 @@ 'use strict'; | ||
queryResult.done = !(this.currentLoc < this.response.results.length || this.response.has_more); | ||
this.emit('data', this, queryResult); | ||
if (queryResult.done) { | ||
if (this.listenerCount('data') > 0) { | ||
this.emit('data', this, queryResult); | ||
} | ||
if (queryResult.done && this.listenerCount('end') > 0) { | ||
this.emit('end', this); | ||
@@ -71,3 +73,4 @@ } | ||
/** | ||
* Get the next value | ||
* Get the next value and return it through a promise and also emit | ||
* it if event listeners have been registered. | ||
* @return {promise} a promise that is fulfilled with the next value or | ||
@@ -84,9 +87,25 @@ * is rejected otherwise | ||
if (this.response.has_more) { | ||
let response = await this.handler.handleQueryStateNext(this.response.id, this.txID); | ||
this.currentLoc = 0; | ||
this.response = response; | ||
return this._createAndEmitResult(); | ||
try { | ||
let response = await this.handler.handleQueryStateNext(this.response.id, this.txID); | ||
this.currentLoc = 0; | ||
this.response = response; | ||
return this._createAndEmitResult(); | ||
} | ||
catch(err) { | ||
// if someone is utilising the event driven way to work with | ||
// iterators (by explicitly checking for data here, not error) | ||
// then emit an error event. This means it will emit an event | ||
// even if no-one is listening for the error event. Error events | ||
// are handled specially by Node. | ||
if (this.listenerCount('data') > 0) { | ||
this.emit('error', this, err); | ||
return; | ||
} | ||
throw err; | ||
} | ||
} | ||
// no more, just return EMCA spec defined response | ||
this.emit('end', this); | ||
if (this.listenerCount('end') > 0) { | ||
this.emit('end', this); | ||
} | ||
return {done: true}; | ||
@@ -93,0 +112,0 @@ } |
@@ -50,3 +50,3 @@ /* | ||
const MIN_UNICODE_RUNE_VALUE = '\u0000'; | ||
const MAX_UNICODE_RUNE_VALUE = '\u0010\uffff'; | ||
const MAX_UNICODE_RUNE_VALUE = '\uffff'; // Can't use '\u0010\uffff' | ||
const COMPOSITEKEY_NS = '\x00'; | ||
@@ -66,11 +66,3 @@ const EMPTY_KEY_SUBSTITUTE = '\x01'; | ||
this.args = chaincodeInput.args.map((entry) => { | ||
let ret; | ||
// attempt to parse the input as JSON first | ||
try { | ||
ret = JSON.parse(entry.toBuffer()); | ||
} catch(err) { | ||
ret = entry.toBuffer().toString(); | ||
} | ||
return ret; | ||
return entry.toBuffer().toString(); | ||
}); | ||
@@ -212,2 +204,5 @@ this.handler = client; | ||
async getStateByRange(startKey, endKey) { | ||
if (!startKey || startKey.length === 0) { | ||
startKey = EMPTY_KEY_SUBSTITUTE; | ||
} | ||
return await this.handler.handleGetStateByRange(startKey, endKey, this.txId); | ||
@@ -214,0 +209,0 @@ } |
{ | ||
"name": "fabric-shim", | ||
"version": "1.0.0-snapshot.7", | ||
"version": "1.0.0-snapshot.8", | ||
"description": "A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
72883
944
4