|
1 |
| -![Microsoft Defending Democracy Program: ElectionGuard Python][banner image] |
| 1 | +# 🗳 ElectionGuard Typescript |
2 | 2 |
|
3 |
| -# 🗳 ETS: ElectionGuard Typescript |
| 3 | +A typescript library that implements a subset of the [ElectionGuard](https://www.electionguard.vote/) spec to allow encryption of ballots in browsers. |
4 | 4 |
|
| 5 | +## Features |
5 | 6 |
|
6 |
| -[banner image]: https://raw.githubusercontent.com/microsoft/electionguard-python/main/images/electionguard-banner.svg |
| 7 | +- Ballot encryption |
7 | 8 |
|
| 9 | + **Note**: write-ins, overvotes, and undervotes are not supported in our implementation of ElectionGuard 1.0. |
8 | 10 |
|
9 |
| -## ❓ What Is Vote-by-mail? |
10 |
| - Vote by mail, or vote at home, is a method of voting that voters get their ballot delivered to them weeks before Election Day, fill it out at their convenience, then return it either in-person or by mail. There are two types of vote by mail system -- comprehensive vote by mail and absentee ballots. To ensure the integrity of elections and the validity of each ballot, risk-limiting audits are implemented and ballot tracking services are provided. |
| 11 | +- Compatibility with [electionguard-python](https://github.com/microsoft/electionguard-python/) |
| 12 | +- Support for [modern](https://caniuse.com/bigint) browsers |
| 13 | +- Support for NodeJS >= 14 |
11 | 14 |
|
12 |
| -## ❓ What Is End-to-End Verifiable Voting? |
13 |
| - E2E verifiable voting is a way to guarantee voting system security, preventing someone other than the sender or recipient from accessing & modifying the ballots. The voters first vote the way they would traditionally on an electronic voting system, but in the end, an e2e system would use cryptography and generate a receipt of a long numeric sequence or a qrcode. This receipt is essentially a record of the vote that's been encrypted with a secret key the voter doesn't have. But it still allows voters to verify that their votes were counted. E2E verifiable voting is able to respond to voters' challenge on whether their ballots are included by providing mathematical proofs which show that the ballots add up to the officially announced totals. That is the mechanism of how the voters can get confident evidence of their ballot being effective without revealing which candidates were voted for nor requiring them to trust election official results, software, hardware, and so on. |
| 15 | +## Non-features |
14 | 16 |
|
| 17 | +- Ballot decryption |
| 18 | +- Verification |
15 | 19 |
|
16 |
| -## ❓ What Is ElectionGuard? |
17 |
| -ElectionGuard is an open source software development kit (SDK) that makes voting more secure, transparent and accessible. The ElectionGuard SDK leverages homomorphic encryption to ensure that votes recorded by electronic systems of any type remain encrypted, secure, and secret. Meanwhile, ElectionGuard also allows verifiable and accurate tallying of ballots by any 3rd party organization without compromising secrecy or security. |
| 20 | +## Installation |
18 | 21 |
|
19 |
| -## ❗️Here comes Electionguard Typescript! |
20 |
| -Our team focuses on building a bridge between the vote-by-mail system and end-to-end verifiable encryption. We want to create a user-friendly web application that not only allows user to vote and print out their ballot, but also performs chaum Peterson encryption while they are voting. This is actually an in-browser version of election guard. |
| 22 | +### Node |
21 | 23 |
|
22 |
| -To achieve this, for Microsoft team, we built a typescript frontend implementation that uses the exactly same encryption logic as election guard. For Front end web interface, we built a fully encapsulated API to add the feature of ballot encryption for them. You can just use approximately few lines of code that calls encrpt_ballot in the front-end typescript, and we will handle everything else for you. |
| 24 | +**Note**: we haven't published a npm package yet. |
23 | 25 |
|
24 |
| -## Workflow of ETS: |
25 |
| -Data pipeline: |
26 |
| - |
| 26 | +```sh |
| 27 | +npm install github:danwallach/electionguard |
| 28 | +# or |
| 29 | +yarn add electionguard@danwallach/electionguard |
| 30 | +``` |
| 31 | + |
| 32 | +### Browser |
| 33 | + |
| 34 | +As an **ES module**: |
| 35 | + |
| 36 | +```html |
| 37 | +<head> |
| 38 | + <!-- ... --> |
| 39 | + <script type="module"> |
| 40 | + import {ManifestParty, bigIntContext4096} from './dist/electionguard.js'; |
| 41 | + console.log(new ManifestParty(bigIntContext4096(), 'example')); |
| 42 | + </script> |
| 43 | +</head> |
| 44 | +``` |
| 45 | + |
| 46 | +As a **UMD module**: |
| 47 | + |
| 48 | +```html |
| 49 | +<head> |
| 50 | + <!-- ... --> |
| 51 | + <script src="./dist/electionguard.umd.js"></script> |
| 52 | +</head> |
| 53 | +<body> |
| 54 | + <!-- ... --> |
| 55 | + <script> |
| 56 | + console.log( |
| 57 | + new eg.ManifestParty(eg.bigIntContext4096(), 'example') |
| 58 | + ); |
| 59 | + </script> |
| 60 | +</body> |
| 61 | +``` |
| 62 | + |
| 63 | +## Usage |
| 64 | + |
| 65 | +```js |
| 66 | +import { |
| 67 | + AsyncBallotEncryptor, |
| 68 | + bigIntContext4096, |
| 69 | + EncryptionDevice, |
| 70 | + PlaintextBallot, |
| 71 | + PlaintextContest, |
| 72 | + PlaintextSelection, |
| 73 | +} from 'electionguard'; |
| 74 | + |
| 75 | +const context = bigIntContext4096(); |
| 76 | +const device = new EncryptionDevice(context, 55890250559315, 12345, 45678, 'polling-place'); |
| 77 | +let codeSeed = device.cryptoHashElement; |
| 78 | + |
| 79 | +const manifestObj = { |
| 80 | + election_scope_id: 'hamilton-county-general-election', |
| 81 | + spec_version: '1.0', |
| 82 | + // ... |
| 83 | +}; |
| 84 | +const electionContextObj = { |
| 85 | + number_of_guardians: 5, |
| 86 | + quorum: 3, |
| 87 | + // ... |
| 88 | +}; |
| 89 | +const ballot = new PlaintextBallot( |
| 90 | + 'ballot-8a27eaa6-f1c3-11ec-b605-aaf53b701db4', |
| 91 | + 'congress-district-5-hamilton-county', |
| 92 | + [ |
| 93 | + new PlaintextContest('president-vice-president-contest', [ |
| 94 | + new PlaintextSelection('cramer-vuocolo-selection', 1), |
| 95 | + ]), |
| 96 | + // ... |
| 97 | + ] |
| 98 | +); |
| 99 | + |
| 100 | +const encryptor = AsyncBallotEncryptor.create( |
| 101 | + context, |
| 102 | + manifestObj, |
| 103 | + electionContextObj, |
| 104 | + false, |
| 105 | + ballot.ballotStyleId, |
| 106 | + ballot.ballotId, |
| 107 | + codeSeed |
| 108 | +); |
| 109 | +ballot.contests.forEach(contest => encryptor.encrypt(contest)); |
| 110 | + |
| 111 | +(async () => { |
| 112 | + const result = await encryptor.getSerializedEncryptedBallot(); |
| 113 | + const {serializedEncryptedBallot, ballotHash} = result; |
| 114 | + |
| 115 | + const ballotHashModQ = context.createElementModQ(ballotHash); |
| 116 | + if (ballotHashModQ === undefined) { |
| 117 | + throw new Error('unable to create ElementModQ from ballotHash'); |
| 118 | + } |
| 119 | + codeSeed = ballotHashModQ; |
| 120 | + |
| 121 | + console.log(JSON.stringify(serializedEncryptedBallot, null, 2)); |
| 122 | +})(); |
| 123 | +``` |
| 124 | + |
| 125 | +<!-- See `examples/` for more examples. --> |
| 126 | + |
| 127 | +Check the [documentation](#documentation) for a full list of exports. |
| 128 | + |
| 129 | +## Documentation |
| 130 | + |
| 131 | +<!-- TODO: deploy these somewhere --> |
27 | 132 |
|
28 |
| -### Getting Started |
| 133 | +You can generate API documentation using [TypeDoc](https://typedoc.org/guides/doccomments/). |
| 134 | + |
| 135 | +```bash |
| 136 | +npm run docs |
| 137 | +``` |
| 138 | + |
| 139 | +### Development |
29 | 140 |
|
30 | 141 | ```bash
|
31 | 142 | # Install dependencies
|
32 | 143 | npm install
|
33 | 144 |
|
34 | 145 | # Now you can run various npm commands:
|
35 | 146 | npm run test
|
| 147 | +npm run coverage |
| 148 | +npm run build |
36 | 149 | npm run elgamal-bench
|
37 |
| -... |
| 150 | +# ... |
38 | 151 |
|
39 | 152 | # Auto-indenter and linter (uses gts)
|
40 | 153 | npm run fix
|
41 | 154 | ```
|
42 | 155 |
|
| 156 | +See also: |
43 | 157 |
|
44 |
| -### Documentation, published with CI |
45 |
| - |
46 |
| -You can auto-generate API documentation from the TypeScript source files using [TypeDoc](https://typedoc.org/guides/doccomments/). The generated documentation can be published to GitHub / GitLab pages through the CI. |
| 158 | +- [`NOTES.md`](./NOTES.md) |
| 159 | +- [`PRECOMPUTE.md`](./PRECOMPUTE.md) |
47 | 160 |
|
48 |
| -```bash |
49 |
| -npm run docs |
50 |
| -``` |
| 161 | +## License |
51 | 162 |
|
52 |
| -The resulting HTML is saved in `docs/`. |
53 |
| - |
54 |
| -You can publish the documentation through CI: |
55 |
| -* [GitHub pages](https://pages.github.com/): See [`.github/workflows/deploy-gh-pages.yml`](https://github.com/metachris/typescript-boilerplate/blob/master/.github/workflows/deploy-gh-pages.yml) |
56 |
| -* [GitLab pages](https://docs.gitlab.com/ee/user/project/pages/): [`.gitlab-ci.yml`](https://github.com/metachris/typescript-boilerplate/blob/master/.gitlab-ci.yml) |
57 |
| - |
58 |
| -This is the documentation for this boilerplate project: https://metachris.github.io/typescript-boilerplate/ |
| 163 | +[MIT License](./LICENSE) |
59 | 164 |
|
60 | 165 | ## Authors
|
| 166 | + |
61 | 167 |
|
62 | 168 |
|
63 | 169 | - Shreyas Minocha <[email protected]>
|
64 | 170 |
|
65 | 171 |
|
66 | 172 |
|
67 |
| - |
| 173 | + |
0 commit comments