From bd894d8378413d54f878b2b076cdbf16e498f012 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Fri, 26 Jul 2024 21:46:51 +0100 Subject: [PATCH] feat(cli): add sdk command to get eas gatekeeper data (#1701) --- cli/ts/commands/index.ts | 1 + cli/ts/commands/signup.ts | 30 +++++++++++++++++++ cli/ts/sdk/index.ts | 2 ++ cli/ts/utils/index.ts | 1 + cli/ts/utils/interfaces.ts | 23 ++++++++++++++ .../contracts/trees/EmptyBallotRoots.sol | 30 ------------------- 6 files changed, 57 insertions(+), 30 deletions(-) delete mode 100644 contracts/contracts/trees/EmptyBallotRoots.sol diff --git a/cli/ts/commands/index.ts b/cli/ts/commands/index.ts index 2aafe46024..13877710dc 100644 --- a/cli/ts/commands/index.ts +++ b/cli/ts/commands/index.ts @@ -16,6 +16,7 @@ export { getGatekeeperTrait, getSemaphoreGatekeeperData, getZupassGatekeeperData, + getEASGatekeeperData, } from "./signup"; export { verify } from "./verify"; export { genProofs } from "./genProofs"; diff --git a/cli/ts/commands/signup.ts b/cli/ts/commands/signup.ts index 8d18fbcc9b..a8c97d8dbf 100644 --- a/cli/ts/commands/signup.ts +++ b/cli/ts/commands/signup.ts @@ -4,6 +4,7 @@ import { SignUpGatekeeper__factory as SignUpGatekeeperFactory, SemaphoreGatekeeper__factory as SemaphoreGatekeeperFactory, ZupassGatekeeper__factory as ZupassGatekeeperFactory, + EASGatekeeper__factory as EASGatekeeperFactory, } from "maci-contracts/typechain-types"; import { PubKey } from "maci-domainobjs"; @@ -16,6 +17,7 @@ import type { IGetGatekeeperDataArgs, ISemaphoreGatekeeperData, IZupassGatekeeperData, + IEASGatekeeperData, } from "../utils/interfaces"; import { banner } from "../utils/banner"; @@ -241,3 +243,31 @@ export const getZupassGatekeeperData = async ({ signer2: validSigner2.toString(), }; }; + +/** + * Get the EAS gatekeeper data + * @param IGetGatekeeperDataArgs - The arguments for the get eas gatekeeper data command + * @returns The eas gatekeeper data + */ +export const getEASGatekeeperData = async ({ + maciAddress, + signer, +}: IGetGatekeeperDataArgs): Promise => { + const maciContract = MACIFactory.connect(maciAddress, signer); + + const gatekeeperContractAddress = await maciContract.signUpGatekeeper(); + + const gatekeeperContract = EASGatekeeperFactory.connect(gatekeeperContractAddress, signer); + + const [eas, schema, attester] = await Promise.all([ + gatekeeperContract.eas(), + gatekeeperContract.schema(), + gatekeeperContract.attester(), + ]); + + return { + eas: eas.toString(), + schema: schema.toString(), + attester: attester.toString(), + }; +}; diff --git a/cli/ts/sdk/index.ts b/cli/ts/sdk/index.ts index 68c9aca114..5324a45064 100644 --- a/cli/ts/sdk/index.ts +++ b/cli/ts/sdk/index.ts @@ -11,6 +11,7 @@ import { getGatekeeperTrait, getSemaphoreGatekeeperData, getZupassGatekeeperData, + getEASGatekeeperData, } from "../commands/signup"; import { verify } from "../commands/verify"; @@ -29,6 +30,7 @@ export { getGatekeeperTrait, getSemaphoreGatekeeperData, getZupassGatekeeperData, + getEASGatekeeperData, }; export type { ISnarkJSVerificationKey } from "maci-circuits"; diff --git a/cli/ts/utils/index.ts b/cli/ts/utils/index.ts index 9c5791e05d..b6f6696451 100644 --- a/cli/ts/utils/index.ts +++ b/cli/ts/utils/index.ts @@ -49,6 +49,7 @@ export type { ISemaphoreGatekeeperData, IGetGatekeeperDataArgs, IZupassGatekeeperData, + IEASGatekeeperData, } from "./interfaces"; export { GatekeeperTrait } from "./interfaces"; export { compareVks } from "./vks"; diff --git a/cli/ts/utils/interfaces.ts b/cli/ts/utils/interfaces.ts index c8e319a176..be18bd3798 100644 --- a/cli/ts/utils/interfaces.ts +++ b/cli/ts/utils/interfaces.ts @@ -1176,6 +1176,9 @@ export interface ISemaphoreGatekeeperData { groupId: string; } +/** + * Interface for the zupass gatekeeper data + */ export interface IZupassGatekeeperData { /** * The event ID @@ -1192,3 +1195,23 @@ export interface IZupassGatekeeperData { */ signer2: string; } + +/** + * Interface for the EAS gatekeeper data + */ +export interface IEASGatekeeperData { + /** + * The EAS + */ + eas: string; + + /** + * The schema + */ + schema: string; + + /** + * The attester + */ + attester: string; +} diff --git a/contracts/contracts/trees/EmptyBallotRoots.sol b/contracts/contracts/trees/EmptyBallotRoots.sol deleted file mode 100644 index 89a4e9d910..0000000000 --- a/contracts/contracts/trees/EmptyBallotRoots.sol +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -abstract contract EmptyBallotRoots { - // emptyBallotRoots contains the roots of Ballot trees of five leaf - // configurations. - // Each tree has a depth of 10, which is the hardcoded state tree depth. - // Each leaf is an empty ballot. A configuration refers to the depth of the - // voice option tree for that ballot. - - // The leaf for the root at index 0 contains hash(0, root of a VO tree with - // depth 1 and zero-value 0) - - // The leaf for the root at index 1 contains hash(0, root of a VO tree with - // depth 2 and zero-value 0) - - // ... and so on. - - // The first parameter to the hash function is the nonce, which is 0. - - uint256[5] internal emptyBallotRoots; - - constructor() { - emptyBallotRoots[0] = uint256(16015576667038038422103932363190100635991292382181099511410843174865570503661); - emptyBallotRoots[1] = uint256(166510078825589460025300915201657086611944528317298994959376081297530246971); - emptyBallotRoots[2] = uint256(10057734083972610459557695472359628128485394923403014377687504571662791937025); - emptyBallotRoots[3] = uint256(4904828619307091008204672239231377290495002626534171783829482835985709082773); - emptyBallotRoots[4] = uint256(18694062287284245784028624966421731916526814537891066525886866373016385890569); - } -}