Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logger.debug('sendTokenCommandToPeer - Start');
let targets = peers;
if (!Array.isArray(peers)) {
targets = [peers];
}
let commandResponse = null;
let error = null;
for (const peer of targets) {
try {
// send to one peer, if peer returns response, check error and return
logger.debug('calling sendTokenCommand for peer %s', peer.getUrl());
const signedCommandResponse = await peer.sendTokenCommand(signedCommand, timeout);
commandResponse = fabprotos.token.CommandResponse.decode(signedCommandResponse.response);
logger.debug('received command response: %s', commandResponse);
} catch (err) {
// peer didn't return response, so loop back to next peer
error = err;
logger.error('caught error when sending token command to peer (%s): %s', peer.getUrl(), error);
}
if (commandResponse !== null) {
if (!commandResponse.get('err')) {
return commandResponse;
} else {
logger.error('command response has error: %s', commandResponse.get('err').getMessage());
throw new Error(util.format('command response has error: %s', commandResponse.get('err').getMessage()));
}
}
}
module.exports.buildListCommand = () => {
logger.debug('buildListCommand - Start');
// construct list request and token command
const listRequest = new fabprotos.token.ListRequest();
const tokenCmd = new fabprotos.token.Command();
tokenCmd.set('list_request', listRequest);
return tokenCmd;
};
module.exports.buildListCommand = () => {
logger.debug('buildListCommand - Start');
// construct list request and token command
const listRequest = new fabprotos.token.ListRequest();
const tokenCmd = new fabprotos.token.Command();
tokenCmd.set('list_request', listRequest);
return tokenCmd;
};
module.exports.signCommand = (signingIdentity, command) => {
logger.debug('signCommand - Start');
const command_bytes = command.toBuffer();
const signature = Buffer.from(signingIdentity.sign(command_bytes));
const signedCommand = new fabprotos.token.SignedCommand();
signedCommand.setCommand(command_bytes);
signedCommand.setSignature(signature);
return signedCommand;
};
module.exports.buildTokenCommandHeader = (creator, channelId, nonce, tlsCertHash) => {
logger.debug('buildTokenCommandHeader - start');
const timestamp = client_utils.buildCurrentTimestamp();
const header = new fabprotos.token.Header();
header.setChannelId(channelId);
header.setCreator(creator.serialize());
header.setNonce(nonce);
header.setTimestamp(timestamp);
if (tlsCertHash !== undefined && tlsCertHash !== null) {
header.setTlsCertHash(tlsCertHash);
}
return header;
};