voting_schemes-dummy 0.22.1 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03fb1f1a56bf94aa7cdd8d05fceccb589f653cee741791a63abb84eae4bc0646
4
- data.tar.gz: 8ce31759adf83aec085d49b40bf2a105faad2a04550e2c071b1df1397befcad5
3
+ metadata.gz: e2a6b9c60ee60ff66b24a548bc01d30ce4022b44eeca4fe5c390a08b3d6ca5ea
4
+ data.tar.gz: fbbf7d9f3dc387a8566106f0b58cc6dbc361c05fc59e73fc04f00710376c1f0c
5
5
  SHA512:
6
- metadata.gz: 2192b25217f12daede912168b50420b170c8b9744768fb8f28b676d641f56c8214248cd0ce87a9a7ee27b696b59573a3e8d7ea542958553321f1a966ebb8294a
7
- data.tar.gz: d9adafa82c864e0ffa214e3d64bb4c6c7ecda792d3ae4d06922a0fd38ade8162958f35058837d78c3339a7757e08143339cc3222e41b566ebe3c0fe19d15596e
6
+ metadata.gz: 646c326fddd0aa8bb0b51e93bbcbb29f0d3c7abb35fff3f8251dd11b6b44662042ded65de6a410435747b6592eebdb4f34e1f882383d3a2ca8e692c362460057
7
+ data.tar.gz: 0f386de4f0d0e505aaae6e63ca327a8eef963aa4e49173fd503ab73fe3694044872ee5e2ff1124df97a751e62af37f24990007448965645ad0a8087e2444012b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- voting_schemes-dummy (0.22.1)
4
+ voting_schemes-dummy (0.22.2)
5
5
  rails (>= 5.0.0)
6
6
 
7
7
  GEM
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{TrusteeWrapperAdapter:()=>r,VoterWrapperAdapter:()=>n});class s{constructor({trusteeId:e}){this.trusteeId=e,this.status=0,this.electionPublicKey=0,this.jointElectionKey=0,this.tallyCastMessage=null}processMessage(e,t){switch(this.status){case 0:if("start_key_ceremony"===e)return this.status=1,this.electionPublicKey=2*Math.floor(50+200*Math.random())+1,{messageType:"key_ceremony.step_1",content:JSON.stringify({election_public_key:this.electionPublicKey,owner_id:this.trusteeId})};break;case 1:if("end_key_ceremony"===e){const e=JSON.parse(t.content);this.jointElectionKey=e.joint_election_key,this.status=2}break;case 2:"start_tally"===e&&(this.status=3);break;case 3:if("tally.cast"===e){this.tallyCastMessage=t.content;const e=JSON.parse(this.tallyCastMessage);for(const[t,s]of Object.entries(e))for(const[r,i]of Object.entries(s))e[t][r]=i%this.electionPublicKey*this.electionPublicKey;return{messageType:"tally.share",content:JSON.stringify({owner_id:this.trusteeId,contests:e})}}if("tally.missing_trustee"===e){const e=JSON.parse(this.tallyCastMessage);for(const[t,s]of Object.entries(e))for(const[r,i]of Object.entries(s))e[t][r]=i%this.electionPublicKey*1*this.jointElectionKey/this.electionPublicKey/this.electionPublicKey;return{messageType:"tally.compensation",content:JSON.stringify({owner_id:this.trusteeId,trustee_id:t.trustee_id,contests:e})}}"end_tally"===e&&(this.status=4)}}isFresh(){return 0===this.status}backup(){return JSON.stringify(this)}restore(e){if(!this.isFresh())return console.warn("Restore not needed"),!1;const t=JSON.parse(e);if(t.trusteeId!==this.trusteeId)return console.warn("Invalid trustee id"),!1;if(0===t.status)return console.warn("Invalid restored status"),!1;try{Object.assign(this,t)}catch(e){return console.error(e),!1}return!0}isKeyCeremonyDone(){return this.status>=2}isTallyDone(){return this.status>=4}}class r{constructor({trusteeId:e}){this.trusteeId=e,this.wrapper=new s({trusteeId:e})}setup(){}processMessage(e,t){return this.wrapper.processMessage(e,t)}isFresh(){return this.wrapper.isFresh()}backup(){return this.wrapper.backup()}restore(e){return this.wrapper.restore(e)}isKeyCeremonyDone(){return this.wrapper.isKeyCeremonyDone()}isTallyDone(){return this.wrapper.isTallyDone()}}class i{constructor({voterId:e,waitTime:t}){this.voterId=e,this.jointElectionKey=null,this.contests={},this.waitTime=t??500}processMessage(e,t){switch(e){case"create_election":this.contests=t.description.contests;break;case"end_key_ceremony":{const e=JSON.parse(t.content);this.jointElectionKey=e.joint_election_key;break}}}async encrypt(e,t){return new Promise((e=>setTimeout(e,500))).then((()=>{if(!this.jointElectionKey)return void console.warn("Invalid election status.");const t=this.createAuditableBallot(e);return{auditableData:t,encryptedData:JSON.stringify(this.createEncryptedData(JSON.parse(JSON.stringify(t))))}}))}createAuditableBallot(e){return{ballot_style:"ballot-style",contests:this.contests.map((({object_id:t,ballot_selections:s})=>({object_id:t,ballot_selections:s.map((s=>{const r=Math.random(),i=e[t]&&e[t].includes(s.object_id)?1:0;return{object_id:s.object_id,ciphertext:i+Math.floor(500*r)*this.jointElectionKey,random:r,plaintext:i}}))})))}}createEncryptedData(e){return this.removeAuditInformation(e)}removeAuditInformation(e){return e.contests.map((e=>e.ballot_selections.map((e=>(delete e.random,delete e.plaintext,e))))),e}}class n{constructor({voterId:e,waitTime:t}){this.voterId=e,this.wrapper=new i({voterId:e,waitTime:t})}setup(){}processMessage(e,t){return this.wrapper.processMessage(e,t)}encrypt(e,t){return this.wrapper.encrypt(e,t)}}window.dummyVotingScheme=t})();
1
+ (()=>{"use strict";var e={d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{TrusteeWrapperAdapter:()=>n,VoterWrapperAdapter:()=>a});const s="key_ceremony.step_1",r="tally.share";class i{constructor({trusteeId:e}){this.trusteeId=e,this.status=0,this.electionPublicKey=0,this.jointElectionKey=0,this.tallyCastMessage=null,this.quorum=0,this.trusteesKeys={},this.trusteesShares={}}processMessage(e,t){switch(this.status){case 0:"create_election"===e&&(this.quorum=t.scheme.quorum,this.status=1);case 1:if("start_key_ceremony"===e)return this.status=2,this.electionPublicKey=2*Math.floor(50+200*Math.random())+1,{messageType:s,content:JSON.stringify({election_public_key:this.electionPublicKey,owner_id:this.trusteeId})};break;case 2:if(e===s){const e=JSON.parse(t.content);this.trusteesKeys[e.owner_id]=e.election_public_key}else if("end_key_ceremony"===e){const e=JSON.parse(t.content);this.jointElectionKey=e.joint_election_key,this.status=3}break;case 3:"start_tally"===e&&(this.status=4);break;case 4:if("tally.cast"===e){this.tallyCastMessage=t.content;const e=JSON.parse(this.tallyCastMessage);for(const[t,s]of Object.entries(e))for(const[r,i]of Object.entries(s))e[t][r]=i%this.electionPublicKey*this.electionPublicKey;return{messageType:r,content:JSON.stringify({owner_id:this.trusteeId,contests:e})}}if(e===r){const e=JSON.parse(t.content);return this.trusteesShares[e.owner_id]=!0,this._compensate()}if("tally.missing_trustee"===e){if(!(t.truestee_id in this.trusteesShares))return this.trusteesShares[t.truestee_id]=!1,this._compensate()}else"end_tally"===e&&(this.status=5)}}isFresh(){return 0===this.status}backup(){return JSON.stringify(this)}restore(e){if(!this.isFresh())return console.warn("Restore not needed"),!1;const t=JSON.parse(e);if(t.trusteeId!==this.trusteeId)return console.warn("Invalid trustee id"),!1;if(1===t.status)return console.warn("Invalid restored status"),!1;try{Object.assign(this,t)}catch(e){return console.error(e),!1}return!0}isKeyCeremonyDone(){return this.status>=3}isTallyDone(){return this.status>=5}_compensate(){const e=Object.keys(this.trusteesKeys).length,t=Object.values(this.trusteesShares).filter((e=>!e)).length;if(t>0&&Object.keys(this.trusteesShares).length===e){const s=JSON.parse(this.tallyCastMessage);for(const[r,i]of Object.entries(s))for(const[n,o]of Object.entries(i))s[r][n]=Math.pow(o%this.electionPublicKey,t)/Math.pow(this.electionPublicKey,e-t);return{messageType:"tally.compensation",content:JSON.stringify({owner_id:this.trusteeId,contests:s})}}}}class n{constructor({trusteeId:e}){this.trusteeId=e,this.wrapper=new i({trusteeId:e})}setup(){}processMessage(e,t){return this.wrapper.processMessage(e,t)}isFresh(){return this.wrapper.isFresh()}backup(){return this.wrapper.backup()}restore(e){return this.wrapper.restore(e)}isKeyCeremonyDone(){return this.wrapper.isKeyCeremonyDone()}isTallyDone(){return this.wrapper.isTallyDone()}}class o{constructor({voterId:e,waitTime:t}){this.voterId=e,this.jointElectionKey=null,this.contests={},this.waitTime=t??500}processMessage(e,t){switch(e){case"create_election":this.contests=t.description.contests;break;case"end_key_ceremony":{const e=JSON.parse(t.content);this.jointElectionKey=e.joint_election_key;break}}}async encrypt(e,t){return new Promise((e=>setTimeout(e,500))).then((()=>{if(!this.jointElectionKey)return void console.warn("Invalid election status.");const t=this.createAuditableBallot(e);return{auditableData:t,encryptedData:JSON.stringify(this.createEncryptedData(JSON.parse(JSON.stringify(t))))}}))}createAuditableBallot(e){return{ballot_style:"ballot-style",contests:this.contests.map((({object_id:t,ballot_selections:s})=>({object_id:t,ballot_selections:s.map((s=>{const r=Math.random(),i=e[t]&&e[t].includes(s.object_id)?1:0;return{object_id:s.object_id,ciphertext:i+Math.floor(500*r)*this.jointElectionKey,random:r,plaintext:i}}))})))}}createEncryptedData(e){return this.removeAuditInformation(e)}removeAuditInformation(e){return e.contests.map((e=>e.ballot_selections.map((e=>(delete e.random,delete e.plaintext,e))))),e}}class a{constructor({voterId:e,waitTime:t}){this.voterId=e,this.wrapper=new o({voterId:e,waitTime:t})}setup(){}processMessage(e,t){return this.wrapper.processMessage(e,t)}encrypt(e,t){return this.wrapper.encrypt(e,t)}}window.dummyVotingScheme=t})();
@@ -2,6 +2,6 @@
2
2
 
3
3
  module VotingSchemes
4
4
  module Dummy
5
- VERSION = "0.22.1"
5
+ VERSION = "0.22.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voting_schemes-dummy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.22.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Morcillo
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-09-06 00:00:00.000000000 Z
14
+ date: 2021-09-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails