Skip to content

Commit f3e2f09

Browse files
abxhrkeithrfung
andauthored
Add Jupyter Notebook Support (#450)
* Add Jupyter Notebook Support * Add mkdocs-jupyter dependency * Add dependency for mkdocs-jupyter * 📝. Add Configure Election as Jupyter Notebook - Remove excess items in poetry lock - Add mkdocs-jupyter and underlying dependencies - Convert 0_Configure_Election to Jupyter notebook Co-authored-by: Keith Fung <[email protected]> Co-authored-by: Keith Fung <[email protected]>
1 parent bbb4bc8 commit f3e2f09

File tree

7 files changed

+932
-86
lines changed

7 files changed

+932
-86
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ bench:
147147
# Documentation
148148
install-mkdocs:
149149
pip install mkdocs
150+
pip install mkdocs-jupyter
150151

151152
docs-serve:
152153
mkdocs serve

docs/0_Configure_Election.ipynb

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"source": [
6+
"# Election Configuration\n",
7+
"\n",
8+
"An election in ElectionGuard is defined as a set of metadata and cryptographic artifacts necessary to encrypt, conduct, tally, decrypt, and verify an election. The Data format used for election metadata is based on the [NIST Election Common Standard Data Specification](https://www.nist.gov/itl/voting/interoperability) but includes some modifications to support the end-to-end cryptography of ElectionGuard.\n",
9+
"\n",
10+
"Election metadata is described in a specific format parseable into an `Manifest` and it's validity is checked to ensure that it is of an appropriate structure to conduct an End-to-End Verified ElectionGuard Election. ElectionGuard only verifies the components of the election metadata that are necessary to encrypt and decrypt the election. Some components of the election metadata are not checked for structural validity, but are used when generating a hash representation of the `Manifest`.\n",
11+
"\n",
12+
"From an `Manifest` we derive an `InternalManifest` that includes a subset of the elements from the `Manifest` required to verify ballots are correct. Additionally a `CiphertextElectionContext` is created during the [Key Ceremony](/1_Key_Ceremony.md) that includes the cryptographic artifacts necessary for encrypting ballots.\n",
13+
"\n",
14+
"## Glossary\n",
15+
"\n",
16+
"- **Election Manifest** The election metadata in json format that is parsed into an Election Description\n",
17+
"- **Election Description** The election metadata that describes the structure and type of the election, including geopolitical units, contests, candidates, and ballot styles, etc.\n",
18+
"- **Internal Election Description** The subset of the `Manifest` required by ElectionGuard to validate ballots are correctly associated with an election. This component mutates the state of the Election Description.\n",
19+
"- **Ciphertext Election Context** The cryptographic context of an election that is configured during the `Key Ceremony`\n",
20+
"- **Description Hash** a Hash representation of the original Manifest.\n",
21+
"\n",
22+
"## Process\n",
23+
"\n",
24+
"1. Define an election according to the `Manifest` requirements.\n",
25+
"2. Use the [NIST Common Standard Data Specification](https://www.nist.gov/itl/voting/interoperability) as a guide, but note the differences in [election.py](https://github.com/microsoft/electionguard-python/tree/main/src/electionguard.election.py) and the provided [sample manifest](https://github.com/microsoft/electionguard-python/tree/main/data/election_manifest_simple.json).\n",
26+
"3. Parse the `Manifest` into the application.\n",
27+
"4. Define the encryption parameters necessary for conducting an election (see `Key Ceremony`).\n",
28+
"5. Create the Pubic Key either from a single secret, or from the Key Ceremony.\n",
29+
"6. Build the `InternalManifest` and `CiphertextElectionContext` from the `Manifest` and `ElGamalKeyPair.public_key`.\n",
30+
"\n",
31+
"## Usage Example"
32+
],
33+
"metadata": {}
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"source": [
39+
"\n",
40+
"import os\n",
41+
"from electionguard.election import CiphertextElectionContext\n",
42+
"from electionguard.election_builder import ElectionBuilder\n",
43+
"from electionguard.elgamal import ElGamalKeyPair, elgamal_keypair_from_secret\n",
44+
"from electionguard.manifest import Manifest, InternalManifest\n",
45+
"\n",
46+
"# Open an election manifest file\n",
47+
"with open(os.path.join(some_path, \"election-manifest.json\"), \"r\") as manifest:\n",
48+
" string_representation = manifest.read()\n",
49+
" election_description = Manifest.from_json(string_representation)\n",
50+
"\n",
51+
"# Create an election builder instance, and configure it for a single public-private keypair.\n",
52+
"# in a real election, you would configure this for a group of guardians. See Key Ceremony for more information.\n",
53+
"builder = ElectionBuilder(\n",
54+
" number_of_guardians=1, # since we will generate a single public-private keypair, we set this to 1\n",
55+
" quorum=1, # since we will generate a single public-private keypair, we set this to 1\n",
56+
" description=election_description\n",
57+
")\n",
58+
"\n",
59+
"# Generate an ElGamal Keypair from a secret. In a real election you would use the Key Ceremony instead.\n",
60+
"some_secret_value: int = 12345\n",
61+
"keypair: ElGamalKeyPair = elgamal_keypair_from_secret(some_secret_value)\n",
62+
"\n",
63+
"builder.set_public_key(keypair.public_key)\n",
64+
"\n",
65+
"# get an `InternalElectionDescription` and `CiphertextElectionContext`\n",
66+
"# that are used for the remainder of the election.\n",
67+
"(internal_manifest, context) = builder.build()"
68+
],
69+
"outputs": [],
70+
"metadata": {
71+
"attributes": {
72+
"classes": [
73+
"code-cell"
74+
],
75+
"id": ""
76+
}
77+
}
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"source": [
82+
"## Constants\n",
83+
"\n",
84+
"The election constants are the four constants that sit underneath most of the mathematical operations. The election constants can be configured, but there is a standard set which is recommended for most use cases. These can be found in `constants.py`.\n",
85+
"\n",
86+
"**⚠️ Warning ⚠️**\n",
87+
"\n",
88+
"There are some test constants used for testing code, but these are never to be used in any production system. The small and extra small constants are unlikely to be used except in rare cases for property testing due to collisions that will happen for smaller number sets."
89+
],
90+
"metadata": {}
91+
}
92+
],
93+
"metadata": {
94+
"language_info": {
95+
"name": "python"
96+
}
97+
},
98+
"nbformat": 4,
99+
"nbformat_minor": 5
100+
}

docs/0_Configure_Election.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Sections:
7272

7373
Step-by-Step Process:
7474

75-
0. [Configure Election](0_Configure_Election.md)
75+
0. [Configure Election](0_Configure_Election.ipynb)
7676
1. [Key Ceremony](1_Key_Ceremony.md)
7777
2. [Encrypt Ballots](2_Encrypt_Ballots.md)
7878
3. [Cast and Spoil](3_Cast_and_Spoil.md)

mkdocs.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ site_name: ElectionGuard Python
22
site_url: https://electionguard-python.readthedocs.io/
33
# site_description:
44
site_author: Microsoft
5-
# google_analytics:
5+
# google_analytics:
66
# remote_branch: for gh-deploy to GithubPages
77
# remote_name: for gh-deploy to Github Pages
8-
copyright: '© Microsoft 2020'
9-
docs_dir: 'docs'
8+
copyright: "© Microsoft 2020"
9+
docs_dir: "docs"
1010
repo_url: https://github.com/microsoft/electionguard-python/
1111
nav:
12-
- Home: index.md
13-
- Design and Architecture: Design_and_Architecture.md
14-
- Build and Run: Build_and_Run.md
15-
- Project Workflow: Project_Workflow.md
16-
- Election Manifest: Election_Manifest.md
17-
- Steps:
18-
- 0. Configure Election: 0_Configure_Election.md
19-
- 1. Key Ceremony: 1_Key_Ceremony.md
20-
- 2. Encrypt Ballots: 2_Encrypt_Ballots.md
21-
- 3. Cast and Spoil: 3_Cast_and_Spoil.md
22-
- 4. Decrypt Tally: 4_Decrypt_Tally.md
23-
- 5. Publish and Verify: 5_Publish_and_Verify.md
24-
theme: readthedocs
12+
- Home: index.md
13+
- Design and Architecture: Design_and_Architecture.md
14+
- Build and Run: Build_and_Run.md
15+
- Project Workflow: Project_Workflow.md
16+
- Election Manifest: Election_Manifest.md
17+
- Steps:
18+
- 0. Configure Election: 0_Configure_Election.ipynb
19+
- 1. Key Ceremony: 1_Key_Ceremony.md
20+
- 2. Encrypt Ballots: 2_Encrypt_Ballots.md
21+
- 3. Cast and Spoil: 3_Cast_and_Spoil.md
22+
- 4. Decrypt Tally: 4_Decrypt_Tally.md
23+
- 5. Publish and Verify: 5_Publish_and_Verify.md
24+
theme: readthedocs
25+
plugins:
26+
- mkdocs-jupyter

0 commit comments

Comments
 (0)