Files
Fuma Nama 60fa53a134 refactor(fhe): unify API - reveal() replaces getDecryptResult()
- Update to unified FHE decryption API
- Add foundry.toml for testing
- Update dependencies to @luxfi/contracts
2025-12-31 21:11:04 -08:00

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}`);
});