Skip to content

Commit

Permalink
Merge pull request #1640 from privacy-scaling-explorations/chore/gate…
Browse files Browse the repository at this point in the history
…keeper-data

chore: add function to get semaphore gatekeeper details
  • Loading branch information
0xmad authored Jul 11, 2024
2 parents 30984d0 + c877d21 commit 9fd54df
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
34 changes: 31 additions & 3 deletions cli/ts/commands/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type ContractTransactionReceipt, isBytesLike } from "ethers";
import {
MACI__factory as MACIFactory,
SignUpGatekeeper__factory as SignUpGatekeeperFactory,
SemaphoreGatekeeper__factory as SemaphoreGatekeeperFactory,
} from "maci-contracts/typechain-types";
import { PubKey } from "maci-domainobjs";

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

import { banner } from "../utils/banner";
Expand Down Expand Up @@ -167,10 +170,7 @@ export const isRegisteredUser = async ({
export const getGatekeeperTrait = async ({
maciAddress,
signer,
quiet = true,
}: IGetGatekeeperTraitArgs): Promise<GatekeeperTrait> => {
banner(quiet);

const maciContract = MACIFactory.connect(maciAddress, signer);

// get the address of the signup gatekeeper
Expand All @@ -182,3 +182,31 @@ export const getGatekeeperTrait = async ({

return gatekeeperType as GatekeeperTrait;
};

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

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

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

// get the group ID and semaphore contract address
const [groupId, semaphoreContractAddress] = await Promise.all([
gatekeeperContract.groupId(),
gatekeeperContract.semaphoreContract(),
]);

return {
address: semaphoreContractAddress,
groupId: groupId.toString(),
};
};
5 changes: 4 additions & 1 deletion cli/ts/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 } from "../commands/signup";
import { signup, isRegisteredUser, getGatekeeperTrait, getSemaphoreGatekeeperData } from "../commands/signup";
import { verify } from "../commands/verify";

export {
Expand All @@ -21,6 +21,7 @@ export {
mergeSignups,
mergeMessages,
getGatekeeperTrait,
getSemaphoreGatekeeperData,
};

export type { ISnarkJSVerificationKey } from "maci-circuits";
Expand Down Expand Up @@ -53,4 +54,6 @@ export type {
IGenKeypairArgs,
IPublishBatchData,
IPublishMessage,
IGetSemaphoreGatekeeperDataArgs,
ISemaphoreGatekeeperData,
} from "../utils";
2 changes: 2 additions & 0 deletions cli/ts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export type {
IPublishMessage,
IParseSignupEventsArgs,
IGetGatekeeperTraitArgs,
ISemaphoreGatekeeperData,
IGetSemaphoreGatekeeperDataArgs,
} from "./interfaces";
export { GatekeeperTrait } from "./interfaces";
export { compareVks } from "./vks";
Expand Down
35 changes: 30 additions & 5 deletions cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,6 @@ export interface IGetGatekeeperTraitArgs {
* A signer object
*/
signer: Signer;

/**
* Whether to log the output
*/
quiet?: boolean;
}

/**
Expand All @@ -1150,3 +1145,33 @@ export enum GatekeeperTrait {
Token = "Token",
Zupass = "Zupass",
}

/**
* Interface for the arguments to the get semaphore gatekeeper data command
*/
export interface IGetSemaphoreGatekeeperDataArgs {
/**
* The address of the MACI contract
*/
maciAddress: string;

/**
* A signer object
*/
signer: Signer;
}

/**
* Interface for the semaphore gatekeeper data
*/
export interface ISemaphoreGatekeeperData {
/**
* The address of the semaphore gatekeeper
*/
address: string;

/**
* The group ID
*/
groupId: string;
}

0 comments on commit 9fd54df

Please sign in to comment.