Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #23

Merged
merged 19 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: 20.x

- name: Set up Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "nova collective"

- name: Install dependencies
run: node ci --function installDeps
Expand Down
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,48 @@ For the local network the parameter to pass is `localhost`, there is no need to

### Prerequisites

* edit the scripts mocks file: `election-scripts/__mocks__.ts`;
* Edit the scripts mocks file: `election-scripts/__mocks__.ts`;
* edit the municipality election contract data, in particular registrationStart and registrationEnd are timestamps in seconds;
* edit the data of the parties and candidates as you prefer;
* edit the data of the Voter as you prefer;
* Compile the smart contracts in order to produce the artifacts: `npm run compile`;
* Creates the `typechain-types` folder with the command: `npx hardhat typechain`;
* start the local network (unless you want to run the scripts on Sepolia): `npm run node:start`;

### 1. The Public Authority / Admin creates the DECs Registry
For the creation of the registry we deploy the DECs Registry smart contract using ignition:
For the creation of the registry we deploy the DECs Registry smart contract:

`npm run deploy-contract Registry localhost`;
`npx hardhat run election-scripts/create-decs-registry.ts --network localhost`;

Take note of the contract address returned by the script;

### 2. The Public Authority / Admin creates the EOA for the Voter
If you are using the local network, you can skip this step and just take note of one EOA returned by the start of the local network.

Execute the `create-voter` scripts and take note of the resulting `address` and `privateKey`:

`npx hardhat run election-scripts/create-voter-eoa.ts`

### 3. The Public Authority / Admin creates the DEC for the Voter and register the DEC into the DECs Registry
[TO DO]
in the `election-scripts/create-dec.ts` file, insert the Voter's private key and save the file.
Then, deploy the contract encrypting the Voter's data with the command:

`npx hardhat run election-scripts/create-dec.ts --network localhost`

Take note of the DEC contract address returned by the script;

### 4. The Public Authority / Admin registers the Voters DECs on the DECs Registry
Write in the `__mock__.ts` file the data required in the `DECsRegistryData`. The data are retrieved by the previous scripts.
Then run the script in order to register the Voter DEC into the DECsRegistry:

`npx hardhat run election-scripts/register-dec.ts --network localhost`

### 4. The Public Authority / Admin creates a Municipality Election
### 5. The Public Authority / Admin creates a Municipality Election
At this point we have the EOA credentials and the DEC for our voters, and the DECs are registered on the DECs Registry. It's time to create an election: as an example we implemented a smart contract for a municipality election, that elects the major and the council.

Now it's time to deploy the smart contract election and register parties, councilor and major candidates, parties coalitions in the municipality election contract, run the command:

`npx hardhat run election-scripts/create-election.ts`
`npx hardhat run election-scripts/create-election.ts --network localhost`

Please note that to make the registration of parties and coalition working, the functions must be called in the registration period set before.

Expand Down
39 changes: 23 additions & 16 deletions contracts/DEC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ pragma solidity ^0.8.24;
/// @custom:experimental This is an experimental contract.
contract DEC {
address public owner;
bytes taxCode;
bytes municipality;
bytes region;
bytes country;
Encrypted taxCode;
Encrypted municipality;
Encrypted region;
Encrypted country;

struct Encrypted {
string iv;
string ephemPublicKey;
string ciphertext;
string mac;
}

constructor(
bytes memory _taxCode,
bytes memory _municipality,
bytes memory _region,
bytes memory _country
Encrypted memory _taxCode,
Encrypted memory _municipality,
Encrypted memory _region,
Encrypted memory _country
) {
/// @dev only the owner of the contract has write permissions
owner = msg.sender;
Expand All @@ -30,35 +37,35 @@ contract DEC {
_;
}

function setTaxCode(bytes memory _taxCode) external onlyOwner {
function setTaxCode(Encrypted memory _taxCode) external onlyOwner {
taxCode = _taxCode;
}

function getTaxCode() external view returns (bytes memory) {
function getTaxCode() external view returns (Encrypted memory) {
return taxCode;
}

function setMunicipality(bytes memory _municipality) external onlyOwner {
function setMunicipality(Encrypted memory _municipality) external onlyOwner {
municipality = _municipality;
}

function getMunicipality() external view returns (bytes memory) {
function getMunicipality() external view returns (Encrypted memory) {
return municipality;
}

function setRegion(bytes memory _region) external onlyOwner {
function setRegion(Encrypted memory _region) external onlyOwner {
region = _region;
}

function getRegion() external view returns (bytes memory) {
function getRegion() external view returns (Encrypted memory) {
return region;
}

function setCountry(bytes memory _country) external onlyOwner {
function setCountry(Encrypted memory _country) external onlyOwner {
country = _country;
}

function getCountry() external view returns (bytes memory) {
function getCountry() external view returns (Encrypted memory) {
return country;
}

Expand Down
Binary file modified docs/assets/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading