From f5d7e6df2aab2dc264235264a9593282054bdfa2 Mon Sep 17 00:00:00 2001 From: Crisgarner Date: Mon, 16 Sep 2024 13:20:41 -0600 Subject: [PATCH] feat(scripts): added merkleproof gatekeeper to signup script and utils (#1823) Co-authored-by: Crisgarner <@crisgarner> --- packages/cli/ts/commands/signup.ts | 25 +++++++++++++++++++++++++ packages/cli/ts/sdk/index.ts | 3 +++ packages/cli/ts/utils/index.ts | 1 + packages/cli/ts/utils/interfaces.ts | 11 +++++++++++ 4 files changed, 40 insertions(+) diff --git a/packages/cli/ts/commands/signup.ts b/packages/cli/ts/commands/signup.ts index b4e0d65997..f7e3aa1859 100644 --- a/packages/cli/ts/commands/signup.ts +++ b/packages/cli/ts/commands/signup.ts @@ -6,6 +6,7 @@ import { ZupassGatekeeper__factory as ZupassGatekeeperFactory, EASGatekeeper__factory as EASGatekeeperFactory, HatsGatekeeperSingle__factory as HatsSingleGatekeeperFactory, + MerkleProofGatekeeper__factory as MerkleProofGatekeeperFactory, } from "maci-contracts/typechain-types"; import { PubKey } from "maci-domainobjs"; @@ -20,6 +21,7 @@ import type { IZupassGatekeeperData, IEASGatekeeperData, IHatsGatekeeperData, + IMerkleProofGatekeeperData, } from "../utils/interfaces"; import { banner } from "../utils/banner"; @@ -301,3 +303,26 @@ export const getHatsSingleGatekeeperData = async ({ hatsContract: hatsContract.toString(), }; }; + +/** + * Get the merkleproof gatekeeper data + * @param IGetGatekeeperDataArgs - The arguments for the get merkleproof gatekeeper data command + * @returns The merkleproof gatekeeper data + */ +export const getMerkleProofGatekeeperData = async ({ + maciAddress, + signer, +}: IGetGatekeeperDataArgs): Promise => { + const maciContract = MACIFactory.connect(maciAddress, signer); + + // get the address of the signup gatekeeper + const gatekeeperContractAddress = await maciContract.signUpGatekeeper(); + + const gatekeeperContract = MerkleProofGatekeeperFactory.connect(gatekeeperContractAddress, signer); + + const [validRoot] = await Promise.all([gatekeeperContract.root()]); + + return { + root: validRoot.toString(), + }; +}; diff --git a/packages/cli/ts/sdk/index.ts b/packages/cli/ts/sdk/index.ts index f5b7f64726..35c495e736 100644 --- a/packages/cli/ts/sdk/index.ts +++ b/packages/cli/ts/sdk/index.ts @@ -13,6 +13,7 @@ import { getZupassGatekeeperData, getEASGatekeeperData, getHatsSingleGatekeeperData, + getMerkleProofGatekeeperData, } from "../commands/signup"; import { verify } from "../commands/verify"; @@ -33,6 +34,7 @@ export { getZupassGatekeeperData, getEASGatekeeperData, getHatsSingleGatekeeperData, + getMerkleProofGatekeeperData, }; export type { ISnarkJSVerificationKey } from "maci-circuits"; @@ -69,4 +71,5 @@ export type { ISemaphoreGatekeeperData, IZupassGatekeeperData, IHatsGatekeeperData, + IMerkleProofGatekeeperData, } from "../utils"; diff --git a/packages/cli/ts/utils/index.ts b/packages/cli/ts/utils/index.ts index 9b7f22dad5..d7c67531a9 100644 --- a/packages/cli/ts/utils/index.ts +++ b/packages/cli/ts/utils/index.ts @@ -51,6 +51,7 @@ export type { IZupassGatekeeperData, IEASGatekeeperData, IHatsGatekeeperData, + IMerkleProofGatekeeperData, } from "./interfaces"; export { GatekeeperTrait } from "./interfaces"; export { compareVks } from "./vks"; diff --git a/packages/cli/ts/utils/interfaces.ts b/packages/cli/ts/utils/interfaces.ts index 247b633716..bb570d6cf0 100644 --- a/packages/cli/ts/utils/interfaces.ts +++ b/packages/cli/ts/utils/interfaces.ts @@ -1134,6 +1134,7 @@ export enum GatekeeperTrait { Semaphore = "Semaphore", Token = "Token", Zupass = "Zupass", + MerkleProof = "MerkleProof", } /** @@ -1220,3 +1221,13 @@ export interface IHatsGatekeeperData { */ hatsContract: string; } + +/** + * Interface for the MerkleProof gatekeeper data + */ +export interface IMerkleProofGatekeeperData { + /** + * The merkle tree root + */ + root: string; +}