Skip to content

Commit

Permalink
feat(scripts): added merkleproof gatekeeper to signup script and utils (
Browse files Browse the repository at this point in the history
#1823)

Co-authored-by: Crisgarner <@crisgarner>
  • Loading branch information
crisgarner committed Sep 16, 2024
1 parent 80db080 commit f5d7e6d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/cli/ts/commands/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -20,6 +21,7 @@ import type {
IZupassGatekeeperData,
IEASGatekeeperData,
IHatsGatekeeperData,
IMerkleProofGatekeeperData,
} from "../utils/interfaces";

import { banner } from "../utils/banner";
Expand Down Expand Up @@ -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<IMerkleProofGatekeeperData> => {
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(),
};
};
3 changes: 3 additions & 0 deletions packages/cli/ts/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getZupassGatekeeperData,
getEASGatekeeperData,
getHatsSingleGatekeeperData,
getMerkleProofGatekeeperData,
} from "../commands/signup";
import { verify } from "../commands/verify";

Expand All @@ -33,6 +34,7 @@ export {
getZupassGatekeeperData,
getEASGatekeeperData,
getHatsSingleGatekeeperData,
getMerkleProofGatekeeperData,
};

export type { ISnarkJSVerificationKey } from "maci-circuits";
Expand Down Expand Up @@ -69,4 +71,5 @@ export type {
ISemaphoreGatekeeperData,
IZupassGatekeeperData,
IHatsGatekeeperData,
IMerkleProofGatekeeperData,
} from "../utils";
1 change: 1 addition & 0 deletions packages/cli/ts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type {
IZupassGatekeeperData,
IEASGatekeeperData,
IHatsGatekeeperData,
IMerkleProofGatekeeperData,
} from "./interfaces";
export { GatekeeperTrait } from "./interfaces";
export { compareVks } from "./vks";
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ export enum GatekeeperTrait {
Semaphore = "Semaphore",
Token = "Token",
Zupass = "Zupass",
MerkleProof = "MerkleProof",
}

/**
Expand Down Expand Up @@ -1220,3 +1221,13 @@ export interface IHatsGatekeeperData {
*/
hatsContract: string;
}

/**
* Interface for the MerkleProof gatekeeper data
*/
export interface IMerkleProofGatekeeperData {
/**
* The merkle tree root
*/
root: string;
}

0 comments on commit f5d7e6d

Please sign in to comment.