-
Notifications
You must be signed in to change notification settings - Fork 2
/
verifierworker.js
61 lines (50 loc) · 1.37 KB
/
verifierworker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* JavaScript HTML 5 Worker for BOOTH
*/
// import needed resources
importScripts("js/underscore-min.js");
importScripts("js/jscrypto/jsbn.js",
"js/jscrypto/jsbn2.js",
"js/jscrypto/sjcl.js",
"js/jscrypto/class.js",
"js/jscrypto/bigint.js",
"js/jscrypto/random.js",
"js/jscrypto/elgamal.js",
"js/jscrypto/sha1.js",
"js/jscrypto/sha2.js",
"js/jscrypto/helios.js",
"verifier.js");
var console = {
'log' : function(msg) {
self.postMessage({'type':'log','msg':msg});
}
};
var status_update = function(msg) {
self.postMessage({'type' : 'status', 'msg' : msg});
};
var ELECTION = null;
var VOTE = null;
function do_verify(message) {
console.log("verifying!");
// json string
ELECTION = message.election;
// json object
VOTE = message.vote;
var result = verify_ballot(ELECTION, VOTE, status_update);
// send the result back
self.postMessage({
'type': 'result',
'result': result});
}
// receive either
// a) an election and an integer position of the question
// that this worker will be used to encrypt
// {'type': 'setup', 'question_num' : 2, 'election' : election_json}
//
// b) an answer that needs encrypting
// {'type': 'encrypt', 'answer' : answer_json}
//
self.onmessage = function(event) {
// dispatch to method
self['do_' + event.data.type](event.data);
}