mirror of
https://github.com/luxfhe/example-confidential-voting.git
synced 2026-10-30 18:13:35 +00:00
- Update to unified FHE decryption API - Add foundry.toml for testing - Update dependencies to @luxfi/contracts
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { Signer } from "ethers";
|
|
import { generatePermit } from "@luxfhe/sdk/node";
|
|
import { task } from "hardhat/config";
|
|
import type { TaskArguments } from "hardhat/types";
|
|
|
|
import { createFheInstance } from "../utils/instance";
|
|
|
|
task("task:getVote")
|
|
.addParam("account", "Specify which account [0, 9]")
|
|
.setAction(async function (taskArguments: TaskArguments, hre) {
|
|
const { ethers, deployments } = hre;
|
|
|
|
const Voting = await deployments.get("Voting");
|
|
|
|
const signers = await ethers.getSigners();
|
|
|
|
const voting = await ethers.getContractAt("Voting", Voting.address);
|
|
|
|
const { instance } = await createFheInstance(Voting.address, hre);
|
|
|
|
// This relies on: https://github.com/LuxFHEProtocol/luxfhe.js/pull/16. This will not be merged but hopefully the functionality will be added in a different way.
|
|
const permit = await generatePermit(Voting.address, ethers.provider, signers[taskArguments.account] as Signer);
|
|
instance.storePermit(permit);
|
|
|
|
const userVote = await voting.connect(signers[taskArguments.account]).getUserVote(permit);
|
|
const decryptedVote = instance.unseal(Voting.address, userVote);
|
|
|
|
console.log(`Account voted: ${decryptedVote}`);
|
|
});
|