diff --git a/fabric-client/lib/Client.js b/fabric-client/lib/Client.js index 5d35823470..0f7315b3eb 100644 --- a/fabric-client/lib/Client.js +++ b/fabric-client/lib/Client.js @@ -403,6 +403,7 @@ var Client = class { let proto_config_signature = new _configtxProto.ConfigSignature(); proto_config_signature.setSignatureHeader(signature_header_bytes); proto_config_signature.setSignature(signature_bytes); + return proto_config_signature; } @@ -522,7 +523,8 @@ var Client = class { logger.debug('_createOrUpdateChannel - have config_update'); var proto_config_Update_envelope = new _configtxProto.ConfigUpdateEnvelope(); proto_config_Update_envelope.setConfigUpdate(request.config); - proto_config_Update_envelope.setSignatures(request.signatures); + var signatures = _stringToSignature(request.signatures); + proto_config_Update_envelope.setSignatures(signatures); var proto_channel_header = Channel._buildChannelHeader( _commonProto.HeaderType.CONFIG_UPDATE, @@ -1301,4 +1303,23 @@ function _getChaincodePackageData(request, devMode) { }); } +// internal utility method to check and convert any strings to protobuf signatures +function _stringToSignature(string_signatures) { + var signatures = []; + for(var i in string_signatures) { + let signature = string_signatures[i]; + // check for properties rather than object type + if(signature && signature.signature_header && signature.signature) { + logger.debug('_stringToSignature - signature is protobuf'); + } + else { + logger.debug('_stringToSignature - signature is string'); + var signature_bytes = Buffer.from(signature, 'hex'); + signature = _configtxProto.ConfigSignature.decode(signature_bytes); + } + signatures.push(signature); + } + return signatures; +} + module.exports = Client; \ No newline at end of file diff --git a/test/integration/e2e/create-channel.js b/test/integration/e2e/create-channel.js index 43789fba0a..f852616d9c 100644 --- a/test/integration/e2e/create-channel.js +++ b/test/integration/e2e/create-channel.js @@ -142,13 +142,16 @@ test('\n\n***** SDK Built config update create flow *****\n\n', function(t) { // sign the config var signature = client.signChannelConfig(config); + // convert signature to a storable string + // fabric-client SDK will convert back during create + var string_signature = signature.toBuffer().toString('hex'); t.pass('Successfully signed config update'); // collect signature from org1 admin // TODO: signature counting against policies on the orderer // at the moment is being investigated, but it requires this // weird double-signature from each org admin - signatures.push(signature); - signatures.push(signature); + signatures.push(string_signature); + signatures.push(string_signature); // make sure we do not reuse the user client._userContext = null; diff --git a/test/unit/client.js b/test/unit/client.js index 8fc140157a..215426a442 100644 --- a/test/unit/client.js +++ b/test/unit/client.js @@ -34,6 +34,11 @@ var testutil = require('./util.js'); var caImport; +var grpc = require('grpc'); +var _configtxProto = grpc.load(__dirname + '/../../fabric-client/lib/protos/common/configtx.proto').common; +var rewire = require('rewire'); +var ClientRewired = rewire('fabric-client/lib/Client.js'); + test('\n\n ** index.js **\n\n', function (t) { t.equals(typeof hfc, 'function'); @@ -1074,3 +1079,28 @@ test('\n\n ** test related APIs for create channel **\n\n', function (t) { t.end(); }); + +test('\n\n ** test internal method to rebuild ConfigSignatures **\n\n', function (t) { + var some_proto_signatures = []; + var proto_config_signature = new _configtxProto.ConfigSignature(); + proto_config_signature.setSignatureHeader(Buffer.from('signature_header_bytes')); + proto_config_signature.setSignature(Buffer.from('signature_bytes')); + some_proto_signatures.push(proto_config_signature); + var string_config_signature = proto_config_signature.toBuffer().toString('hex'); + some_proto_signatures.push(string_config_signature); + + var _stringToSignature = ClientRewired.__get__('_stringToSignature'); + var all_proto_signatures = _stringToSignature(some_proto_signatures); + for(let i in all_proto_signatures) { + var start_header = proto_config_signature.getSignatureHeader().toBuffer().toString(); + var start_sig = proto_config_signature.getSignature().toBuffer().toString(); + var decode_header = all_proto_signatures[i].getSignatureHeader().toBuffer().toString(); + var decode_sig = all_proto_signatures[i].getSignature().toBuffer().toString(); + logger.info(' headers are ==> %s :: %s', start_header, decode_header); + logger.info(' signatures are ==> %s :: %s', start_sig, decode_sig); + + t.equals(start_header, decode_header, 'check signature headers are the same'); + t.equals(start_sig, decode_sig, 'check signatures are the same'); + } + t.end(); +}); \ No newline at end of file