1 |
|
2 |
|
3 |
|
4 | const anonize = require('node-anonize2-relic-emscripten')
|
5 |
|
6 | self.onmessage = function (evt) {
|
7 | const request = evt.data
|
8 |
|
9 | const d = function (err, result) {
|
10 | self.postMessage({ msgno: request.msgno, err: err, result: result })
|
11 | }
|
12 |
|
13 | const f = {
|
14 | request:
|
15 | function () {
|
16 | const credential = new anonize.Credential(request.payload.credential)
|
17 | const proof = credential.request()
|
18 |
|
19 | return { credential: JSON.stringify(credential), proof: proof }
|
20 | },
|
21 |
|
22 | finalize:
|
23 | function () {
|
24 | const credential = new anonize.Credential(request.payload.credential)
|
25 |
|
26 | credential.finalize(request.payload.verification)
|
27 | return { credential: JSON.stringify(credential) }
|
28 | },
|
29 |
|
30 | submit:
|
31 | function () {
|
32 | if (request.payload.multiple) {
|
33 | if (!request.payload.ballots) {
|
34 | return { payload: null }
|
35 | }
|
36 |
|
37 | let payload = []
|
38 | request.payload.ballots.forEach(ballot => {
|
39 | const credential = new anonize.Credential(ballot.credential)
|
40 | const surveyor = new anonize.Surveyor(ballot.surveyor)
|
41 |
|
42 | payload.push({
|
43 | surveyorId: surveyor.parameters.surveyorId,
|
44 | proof: credential.submit(surveyor, { publisher: ballot.publisher })
|
45 | })
|
46 | })
|
47 |
|
48 | return { payload }
|
49 | }
|
50 |
|
51 | const credential = new anonize.Credential(request.payload.credential)
|
52 | const surveyor = new anonize.Surveyor(request.payload.surveyor)
|
53 | return { payload: { proof: credential.submit(surveyor, request.payload.data) } }
|
54 | }
|
55 | }[request.operation]
|
56 | if (!f) return d('invalid operation')
|
57 |
|
58 | try {
|
59 | d(null, f())
|
60 | } catch (ex) {
|
61 | d(ex.toString())
|
62 | }
|
63 | }
|