mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
* refactor: use singular ETHERSCAN_API_KEY in .env Etherscan has unified all keys of associated explorers like Celoscan into a singular key rather than different keys for different networks. * refactor: use one .env instead of separate .env.test + .env files * refactor: deploy contracts with runs of 1000 instead of 200 Decreases gas cost of function calls on deployed contracts * clean: remove duplicate/redundant deploy modules + scripts * clean: cleanup empty script file * refactor: cleanup default network of scripts Read network from .env instead of using defaults of alfajores (outdated) or staging * clean: remove references to Alfajores, replace with Sepolia * chore: add default .env variables * chore: update build-all script to include aardhaar circuit * chore: update broken Powers of Tau download link (use iden3) * chore: remove duplicate script * fix: use stable version 18 for disclose circuits * test: update test import paths to allow for .ts version of generateProof * test: fix broken tests * test: uncomment critical code for registration, change error names to updated names, fix broken import paths, update disclose tests for new scope generation/handling * fix: broken import path * test: fix Airdrop tests to use V2 logic * docs: update docs for necessary prerequisite programs * chore: yarn prettier formatting * fix: CI errors occuring when deploying contracts as can't read .env Using a dummy key for CI builds * chore: yarn prettier * refactor: change runs to 100000
146 lines
5.4 KiB
TypeScript
146 lines
5.4 KiB
TypeScript
import { buildModule, IgnitionModuleBuilder } from "@nomicfoundation/ignition-core";
|
|
import hre from "hardhat";
|
|
import { readFileSync } from "fs";
|
|
import path from "path";
|
|
import { circuitIds, CircuitName } from "../verifiers/deployAllVerifiers";
|
|
|
|
// Attestation IDs from the contract
|
|
const AttestationId = {
|
|
E_PASSPORT: "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
EU_ID_CARD: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
AADHAAR: "0x0000000000000000000000000000000000000000000000000000000000000003",
|
|
};
|
|
|
|
// Circuit type mappings based on circuit names
|
|
const getCircuitType = (
|
|
circuitName: CircuitName,
|
|
): { attestationId: string; typeId: number; circuitType: "register" | "dsc" | "vc_and_disclose" } => {
|
|
if (circuitName.startsWith("register_")) {
|
|
const [shouldDeploy, typeId] = circuitIds[circuitName];
|
|
if (circuitName.startsWith("register_id_")) {
|
|
return { attestationId: AttestationId.EU_ID_CARD, typeId, circuitType: "register" };
|
|
} else if (circuitName === "register_aadhaar") {
|
|
return { attestationId: AttestationId.AADHAAR, typeId, circuitType: "register" };
|
|
} else {
|
|
return { attestationId: AttestationId.E_PASSPORT, typeId, circuitType: "register" };
|
|
}
|
|
} else if (circuitName.startsWith("dsc_")) {
|
|
const [shouldDeploy, typeId] = circuitIds[circuitName];
|
|
// DSC circuits are used for both passport and ID card
|
|
return { attestationId: AttestationId.E_PASSPORT, typeId, circuitType: "dsc" };
|
|
} else if (circuitName.startsWith("vc_and_disclose")) {
|
|
if (circuitName === "vc_and_disclose_id") {
|
|
return { attestationId: AttestationId.EU_ID_CARD, typeId: 0, circuitType: "vc_and_disclose" };
|
|
} else if (circuitName === "vc_and_disclose_aadhaar") {
|
|
return { attestationId: AttestationId.AADHAAR, typeId: 0, circuitType: "vc_and_disclose" };
|
|
} else {
|
|
return { attestationId: AttestationId.E_PASSPORT, typeId: 0, circuitType: "vc_and_disclose" };
|
|
}
|
|
}
|
|
throw new Error(`Unknown circuit type: ${circuitName}`);
|
|
};
|
|
|
|
const ids = (() => {
|
|
let id = 0;
|
|
return () => {
|
|
id++;
|
|
return "a" + id.toString();
|
|
};
|
|
})();
|
|
|
|
export function updateHubVerifiers(m: IgnitionModuleBuilder, hubAddress: string, deployedAddresses: any) {
|
|
const hubContract = m.contractAt("IdentityVerificationHubImplV2", hubAddress);
|
|
|
|
// Get all deployed verifiers
|
|
const verifiers: Record<string, any> = {};
|
|
|
|
for (const circuitName of Object.keys(circuitIds) as CircuitName[]) {
|
|
const [shouldDeploy] = circuitIds[circuitName];
|
|
if (!shouldDeploy) continue;
|
|
|
|
const verifierName = `Verifier_${circuitName}`;
|
|
const verifierAddress = deployedAddresses[`DeployAllVerifiers#${verifierName}`];
|
|
|
|
if (verifierAddress) {
|
|
verifiers[circuitName] = verifierAddress;
|
|
}
|
|
}
|
|
|
|
// Prepare batch arrays for register circuit verifiers
|
|
const registerAttestationIds: string[] = [];
|
|
const registerTypeIds: number[] = [];
|
|
const registerVerifierAddresses: string[] = [];
|
|
|
|
// Prepare batch arrays for DSC circuit verifiers
|
|
const dscAttestationIds: string[] = [];
|
|
const dscTypeIds: number[] = [];
|
|
const dscVerifierAddresses: string[] = [];
|
|
|
|
// Process all verifiers and categorize them
|
|
for (const [circuitName, verifierAddress] of Object.entries(verifiers)) {
|
|
const { attestationId, typeId, circuitType } = getCircuitType(circuitName as CircuitName);
|
|
|
|
if (circuitType === "register") {
|
|
registerAttestationIds.push(attestationId);
|
|
registerTypeIds.push(typeId);
|
|
registerVerifierAddresses.push(verifierAddress);
|
|
} else if (circuitType === "dsc") {
|
|
// Add for passport
|
|
dscAttestationIds.push(AttestationId.E_PASSPORT);
|
|
dscTypeIds.push(typeId);
|
|
dscVerifierAddresses.push(verifierAddress);
|
|
|
|
// Add for ID card
|
|
dscAttestationIds.push(AttestationId.EU_ID_CARD);
|
|
dscTypeIds.push(typeId);
|
|
dscVerifierAddresses.push(verifierAddress);
|
|
}
|
|
}
|
|
|
|
// Batch update register circuit verifiers
|
|
if (registerAttestationIds.length > 0) {
|
|
m.call(hubContract, "batchUpdateRegisterCircuitVerifiers", [
|
|
registerAttestationIds,
|
|
registerTypeIds,
|
|
registerVerifierAddresses,
|
|
]);
|
|
}
|
|
|
|
// Batch update DSC circuit verifiers
|
|
if (dscAttestationIds.length > 0) {
|
|
m.call(hubContract, "batchUpdateDscCircuitVerifiers", [dscAttestationIds, dscTypeIds, dscVerifierAddresses]);
|
|
}
|
|
|
|
// Update VC and Disclose circuit verifiers (no batch function available)
|
|
for (const [circuitName, verifierAddress] of Object.entries(verifiers)) {
|
|
const { attestationId, typeId, circuitType } = getCircuitType(circuitName as CircuitName);
|
|
|
|
if (circuitType === "vc_and_disclose") {
|
|
m.call(hubContract, "updateVcAndDiscloseCircuit", [attestationId, verifierAddress], { id: ids() });
|
|
}
|
|
}
|
|
|
|
return hubContract;
|
|
}
|
|
|
|
export default buildModule("UpdateVerifiers", (m) => {
|
|
const chainId = hre.network.config.chainId;
|
|
|
|
const deployedAddressesPath = path.join(__dirname, `../../deployments/chain-${chainId}/deployed_addresses.json`);
|
|
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
|
|
|
|
// Get the hub address
|
|
//do I get the hub or the implementation address?
|
|
const hubAddress = deployedAddresses["DeployHubV2#IdentityVerificationHub"];
|
|
|
|
if (!hubAddress) {
|
|
throw new Error("Hub address not found in deployed addresses");
|
|
}
|
|
|
|
const hubContract = updateHubVerifiers(m, hubAddress, deployedAddresses);
|
|
|
|
return {
|
|
hubContract,
|
|
};
|
|
});
|