This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
worker.js
63 lines (50 loc) · 1.8 KB
/
worker.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
62
63
/* jshint asi: true, node: true, laxbreak: true, laxcomma: true, undef: true, unused: true */
/* global self */
const anonize = require('node-anonize2-relic-emscripten')
self.onmessage = function (evt) {
const request = evt.data
const d = function (err, result) {
self.postMessage({ msgno: request.msgno, err: err, result: result })
}
const f = {
request:
function () {
const credential = new anonize.Credential(request.payload.credential)
const proof = credential.request()
return { credential: JSON.stringify(credential), proof: proof }
},
finalize:
function () {
const credential = new anonize.Credential(request.payload.credential)
credential.finalize(request.payload.verification)
return { credential: JSON.stringify(credential) }
},
submit:
function () {
if (request.payload.multiple) {
if (!request.payload.ballots) {
return { payload: null }
}
let payload = []
request.payload.ballots.forEach(ballot => {
const credential = new anonize.Credential(ballot.credential)
const surveyor = new anonize.Surveyor(ballot.surveyor)
payload.push({
surveyorId: surveyor.parameters.surveyorId,
proof: credential.submit(surveyor, { publisher: ballot.publisher })
})
})
return { payload }
}
const credential = new anonize.Credential(request.payload.credential)
const surveyor = new anonize.Surveyor(request.payload.surveyor)
return { payload: { proof: credential.submit(surveyor, request.payload.data) } }
}
}[request.operation]
if (!f) return d('invalid operation')
try {
d(null, f())
} catch (ex) {
d(ex.toString())
}
}