Skip to content

Commit

Permalink
feat(sdk): add function to get zupass gatekeeper data (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 authored Jul 15, 2024
1 parent bb5d1bd commit 49794ab
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cli/ts/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ export { publish, publishBatch } from "./publish";
export { setVerifyingKeys } from "./setVerifyingKeys";
export { showContracts } from "./showContracts";
export { timeTravel } from "./timeTravel";
export { signup, isRegisteredUser, getGatekeeperTrait, getSemaphoreGatekeeperData } from "./signup";
export {
signup,
isRegisteredUser,
getGatekeeperTrait,
getSemaphoreGatekeeperData,
getZupassGatekeeperData,
} from "./signup";
export { verify } from "./verify";
export { genProofs } from "./genProofs";
export { fundWallet } from "./fundWallet";
Expand Down
35 changes: 33 additions & 2 deletions cli/ts/commands/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
MACI__factory as MACIFactory,
SignUpGatekeeper__factory as SignUpGatekeeperFactory,
SemaphoreGatekeeper__factory as SemaphoreGatekeeperFactory,
ZupassGatekeeper__factory as ZupassGatekeeperFactory,
} from "maci-contracts/typechain-types";
import { PubKey } from "maci-domainobjs";

Expand All @@ -12,8 +13,9 @@ import type {
IRegisteredUserArgs,
ISignupData,
SignupArgs,
IGetSemaphoreGatekeeperDataArgs,
IGetGatekeeperDataArgs,
ISemaphoreGatekeeperData,
IZupassGatekeeperData,
} from "../utils/interfaces";

import { banner } from "../utils/banner";
Expand Down Expand Up @@ -191,7 +193,7 @@ export const getGatekeeperTrait = async ({
export const getSemaphoreGatekeeperData = async ({
maciAddress,
signer,
}: IGetSemaphoreGatekeeperDataArgs): Promise<ISemaphoreGatekeeperData> => {
}: IGetGatekeeperDataArgs): Promise<ISemaphoreGatekeeperData> => {
const maciContract = MACIFactory.connect(maciAddress, signer);

// get the address of the signup gatekeeper
Expand All @@ -210,3 +212,32 @@ export const getSemaphoreGatekeeperData = async ({
groupId: groupId.toString(),
};
};

/**
* Get the zupass gatekeeper data
* @param IGetGatekeeperDataArgs - The arguments for the get zupass gatekeeper data command
* @returns The zupass gatekeeper data
*/
export const getZupassGatekeeperData = async ({
maciAddress,
signer,
}: IGetGatekeeperDataArgs): Promise<IZupassGatekeeperData> => {
const maciContract = MACIFactory.connect(maciAddress, signer);

// get the address of the signup gatekeeper
const gatekeeperContractAddress = await maciContract.signUpGatekeeper();

const gatekeeperContract = ZupassGatekeeperFactory.connect(gatekeeperContractAddress, signer);

const [validEventId, validSigner1, validSigner2] = await Promise.all([
gatekeeperContract.validEventId(),
gatekeeperContract.validSigner1(),
gatekeeperContract.validSigner2(),
]);

return {
eventId: validEventId.toString(),
signer1: validSigner1.toString(),
signer2: validSigner2.toString(),
};
};
12 changes: 10 additions & 2 deletions cli/ts/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { mergeMessages } from "../commands/mergeMessages";
import { mergeSignups } from "../commands/mergeSignups";
import { getPoll } from "../commands/poll";
import { publish, publishBatch } from "../commands/publish";
import { signup, isRegisteredUser, getGatekeeperTrait, getSemaphoreGatekeeperData } from "../commands/signup";
import {
signup,
isRegisteredUser,
getGatekeeperTrait,
getSemaphoreGatekeeperData,
getZupassGatekeeperData,
} from "../commands/signup";
import { verify } from "../commands/verify";

export {
Expand All @@ -22,6 +28,7 @@ export {
mergeMessages,
getGatekeeperTrait,
getSemaphoreGatekeeperData,
getZupassGatekeeperData,
};

export type { ISnarkJSVerificationKey } from "maci-circuits";
Expand Down Expand Up @@ -54,6 +61,7 @@ export type {
IGenKeypairArgs,
IPublishBatchData,
IPublishMessage,
IGetSemaphoreGatekeeperDataArgs,
IGetGatekeeperDataArgs,
ISemaphoreGatekeeperData,
IZupassGatekeeperData,
} from "../utils";
3 changes: 2 additions & 1 deletion cli/ts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export type {
IParseSignupEventsArgs,
IGetGatekeeperTraitArgs,
ISemaphoreGatekeeperData,
IGetSemaphoreGatekeeperDataArgs,
IGetGatekeeperDataArgs,
IZupassGatekeeperData,
} from "./interfaces";
export { GatekeeperTrait } from "./interfaces";
export { compareVks } from "./vks";
Expand Down
21 changes: 19 additions & 2 deletions cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,9 +1147,9 @@ export enum GatekeeperTrait {
}

/**
* Interface for the arguments to the get semaphore gatekeeper data command
* Interface for the arguments to the get a gatekeeper's data command
*/
export interface IGetSemaphoreGatekeeperDataArgs {
export interface IGetGatekeeperDataArgs {
/**
* The address of the MACI contract
*/
Expand All @@ -1175,3 +1175,20 @@ export interface ISemaphoreGatekeeperData {
*/
groupId: string;
}

export interface IZupassGatekeeperData {
/**
* The event ID
*/
eventId: string;

/**
* The first signer
*/
signer1: string;

/**
* The second signer
*/
signer2: string;
}

0 comments on commit 49794ab

Please sign in to comment.