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-12-11 13:53:25 +11:00
function generateEncryptedVote ( election , answers , should _do _fingerprint ) {
2017-11-23 23:10:57 +11:00
encrypted _answers = [ ] ;
2017-12-07 18:32:01 +11:00
for ( var q _num = 0 ; q _num < answers . length ; q _num ++ ) {
answer _json = answers [ q _num ] ;
2017-11-23 23:10:57 +11:00
answer = eosjs . eos . core . objects . _ _all _ _ . EosObject . deserialise _and _unwrap ( answer _json , null ) ;
2017-12-11 20:54:13 +11:00
encrypted _answer = eosjs . eos . psr . election . _ _all _ _ . BlockEncryptedAnswer . encrypt ( election . public _key , answer , election . questions . _ _getitem _ _ ( q _num ) . max _bits ( ) + 32 ) ; // +32 bits for the length
2017-11-23 23:10:57 +11:00
encrypted _answers . push ( eosjs . eos . core . objects . _ _all _ _ . EosObject . serialise _and _wrap ( encrypted _answer , null ) ) ;
}
2017-11-23 21:07:16 +11:00
2017-12-11 13:53:25 +11:00
postMessage ( {
encrypted _answers : encrypted _answers
} ) ;
2017-11-23 21:07:16 +11:00
}
onmessage = function ( msg ) {
2017-12-11 21:17:32 +11:00
try {
if ( ! isLibrariesLoaded ) {
importScripts (
msg . data . static _base _url + "js/eosjs.js"
) ;
isLibrariesLoaded = true ;
}
2017-11-23 21:07:16 +11:00
2017-12-11 21:17:32 +11:00
if ( msg . data . action === "generateEncryptedVote" ) {
msg . data . election = eosjs . eos . core . objects . _ _all _ _ . EosObject . deserialise _and _unwrap ( msg . data . election , null ) ;
generateEncryptedVote ( msg . data . election , msg . data . answers ) ;
} else {
throw "Unknown action: " + msg . data . action ;
}
} catch ( ex ) {
if ( ex . _ _repr _ _ ) {
throw ex . _ _repr _ _ ( ) ;
}
throw ex ;
2017-11-23 21:07:16 +11:00
}
}