2017-11-23 21:07:16 +11:00
|
|
|
/*
|
|
|
|
Eos - Verifiable elections
|
|
|
|
Copyright © 2017 RunasSudo (Yingtong Li)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
window = self; // Workaround for libraries
|
|
|
|
isLibrariesLoaded = false;
|
|
|
|
|
2017-11-23 23:10:57 +11:00
|
|
|
function generateEncryptedVote(election, answers) {
|
|
|
|
encrypted_answers = [];
|
|
|
|
for (var answer_json of answers) {
|
|
|
|
answer = eosjs.eos.core.objects.__all__.EosObject.deserialise_and_unwrap(answer_json, null);
|
|
|
|
encrypted_answer = eosjs.eos.psr.election.__all__.BlockEncryptedAnswer.encrypt(election.public_key, answer);
|
|
|
|
encrypted_answers.push(eosjs.eos.core.objects.__all__.EosObject.serialise_and_wrap(encrypted_answer, null));
|
|
|
|
}
|
2017-11-23 21:07:16 +11:00
|
|
|
|
2017-11-23 23:10:57 +11:00
|
|
|
postMessage(encrypted_answers);
|
2017-11-23 21:07:16 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
onmessage = function(msg) {
|
|
|
|
if (!isLibrariesLoaded) {
|
|
|
|
importScripts(
|
|
|
|
msg.data.static_base_url + "js/eosjs.js"
|
|
|
|
);
|
|
|
|
isLibrariesLoaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.data.action === "generateEncryptedVote") {
|
2017-11-23 23:10:57 +11:00
|
|
|
msg.data.election = eosjs.eos.core.objects.__all__.EosObject.deserialise_and_unwrap(msg.data.election, null);
|
2017-11-23 21:07:16 +11:00
|
|
|
|
2017-11-23 23:10:57 +11:00
|
|
|
generateEncryptedVote(msg.data.election, msg.data.answers);
|
2017-11-23 21:07:16 +11:00
|
|
|
} else {
|
|
|
|
throw "Unknown action: " + msg.data.action;
|
|
|
|
}
|
|
|
|
}
|