I'm trying to send a JSON with several information, one of the fields depends on a external function. When I get the JSON result, this field is empty because the send function is executed before the variable value replenishment function. This is my code:
router.post('/sign', function(req, res) {
var id_server = serverKeys.id_server;
var id_client = req.body[0].A;
var moneda = req.body[2].coin;
var cantidad = req.body[3].cantidad;
var signed = blindSignature.sign(moneda, cantidad);
console.log('Mensaje firmado en la api: ' + signed);
var data = ([{"A": id_server}, {"B": id_client}, {"coin_signed": signed}, {'cantidad': cantidad}]);
var Po = nonRepudiation.gethash(data);
var response = ([{"A": id_server}, {"B": id_client}, {"signed": signed}, {'cantidad': cantidad}, {'Po': Po}, {'status': "Mensaje firmado"}]);
res.status(200).send(response);
});
var signed
value relies on blindSignature.sign()
function. So, the coin_signed
field on data JSON sends empty.
exports.sign = function(mensaje, cantidad) {
console.log('Firma ciega');
Key.find({"valor": cantidad}, function (err, clave) {
if (err) return next(err);
d = clave[0].d;
n = clave[0].n;
var signed = bigInt(mensaje).modPow(d, n);
console.log("Mensaje firmado en módulo: " + signed.toString());
return signed;
});};
Thanks in advance.