diff --git a/lib/commands/pin-rpc.js b/lib/commands/pin-rpc.js index d77732ce9..27a8ae28d 100644 --- a/lib/commands/pin-rpc.js +++ b/lib/commands/pin-rpc.js @@ -142,23 +142,9 @@ var getFreeSpace = Pinning.getFreeSpace = function (Env, safeKey, cb) { }); }; -var hashChannelList = function (A) { - var uniques = []; - - A.forEach(function (a) { - if (uniques.indexOf(a) === -1) { uniques.push(a); } - }); - uniques.sort(); - - var hash = Nacl.util.encodeBase64(Nacl.hash(Nacl - .util.decodeUTF8(JSON.stringify(uniques)))); - - return hash; -}; - var getHash = Pinning.getHash = function (Env, safeKey, cb) { getChannelList(Env, safeKey, function (channels) { - cb(void 0, hashChannelList(channels)); + Env.hashChannelList(channels, cb); }); }; diff --git a/lib/hk-util.js b/lib/hk-util.js index 57e0afe36..799ec547f 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -951,7 +951,7 @@ HK.initializeValidationWorkers = function (Env) { worker.on('message', function (res) { if (!res || !res.txid) { return; } //console.log(+new Date(), "Received verification response"); - response.handle(res.txid, [res.error]); + response.handle(res.txid, [res.error, res.value]); }); // Spawn a new process in one ends worker.on('exit', function () { @@ -1001,6 +1001,13 @@ HK.initializeValidationWorkers = function (Env) { key: publicKey, }, cb); }; + + Env.hashChannelList = function (channels, cb) { + send({ + command: 'HASH_CHANNEL_LIST', + channels: channels, + }, cb); + }; }; /* onChannelMessage diff --git a/lib/workers/check-signature.js b/lib/workers/check-signature.js index 846f41d3b..5ed58ac7c 100644 --- a/lib/workers/check-signature.js +++ b/lib/workers/check-signature.js @@ -73,17 +73,34 @@ COMMANDS.DETACHED = function (data, cb) { cb(); }; +COMMANDS.HASH_CHANNEL_LIST = function (data, cb) { + var channels = data.channels; + if (!Array.isArray(channels)) { return void cb('INVALID_CHANNEL_LIST'); } + var uniques = []; + + channels.forEach(function (a) { + if (uniques.indexOf(a) === -1) { uniques.push(a); } + }); + uniques.sort(); + + var hash = Nacl.util.encodeBase64(Nacl.hash(Nacl + .util.decodeUTF8(JSON.stringify(uniques)))); + + cb(void 0, hash); +}; + process.on('message', function (data) { - if (!data || !data.key || !data.msg || !data.txid) { + if (!data || !data.txid) { return void process.send({ error:'E_INVAL' }); } - const cb = function (err) { + const cb = function (err, value) { process.send({ txid: data.txid, error: err, + value: value, }); };