Skip to content

Commit

Permalink
Merge pull request #1745 from privacy-scaling-explorations/feat/get-h…
Browse files Browse the repository at this point in the history
…ats-gatekeeper-data

feat(sdk): get hats gatekeeper data
  • Loading branch information
0xmad authored Aug 7, 2024
2 parents 1032f7a + a06fa6b commit d644eae
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/cli/ts/commands/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SemaphoreGatekeeper__factory as SemaphoreGatekeeperFactory,
ZupassGatekeeper__factory as ZupassGatekeeperFactory,
EASGatekeeper__factory as EASGatekeeperFactory,
HatsGatekeeperSingle__factory as HatsSingleGatekeeperFactory,
} from "maci-contracts/typechain-types";
import { PubKey } from "maci-domainobjs";

Expand All @@ -18,6 +19,7 @@ import type {
ISemaphoreGatekeeperData,
IZupassGatekeeperData,
IEASGatekeeperData,
IHatsGatekeeperData,
} from "../utils/interfaces";

import { banner } from "../utils/banner";
Expand Down Expand Up @@ -271,3 +273,29 @@ export const getEASGatekeeperData = async ({
attester: attester.toString(),
};
};

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

const gatekeeperContractAddress = await maciContract.signUpGatekeeper();

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

const [criterionHat, hatsContract] = await Promise.all([
gatekeeperContract.criterionHat(),
gatekeeperContract.hats(),
]);

return {
criterionHat: [criterionHat.toString()],
hatsContract: hatsContract.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 @@ -12,6 +12,7 @@ import {
getSemaphoreGatekeeperData,
getZupassGatekeeperData,
getEASGatekeeperData,
getHatsSingleGatekeeperData,
} from "../commands/signup";
import { verify } from "../commands/verify";

Expand All @@ -31,6 +32,7 @@ export {
getSemaphoreGatekeeperData,
getZupassGatekeeperData,
getEASGatekeeperData,
getHatsSingleGatekeeperData,
};

export type { ISnarkJSVerificationKey } from "maci-circuits";
Expand Down Expand Up @@ -66,4 +68,5 @@ export type {
IGetGatekeeperDataArgs,
ISemaphoreGatekeeperData,
IZupassGatekeeperData,
IHatsGatekeeperData,
} 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 @@ -50,6 +50,7 @@ export type {
IGetGatekeeperDataArgs,
IZupassGatekeeperData,
IEASGatekeeperData,
IHatsGatekeeperData,
} from "./interfaces";
export { GatekeeperTrait } from "./interfaces";
export { compareVks } from "./vks";
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1195,3 +1195,18 @@ export interface IEASGatekeeperData {
*/
attester: string;
}

/**
* Interface for the Hats gatekeeper data
*/
export interface IHatsGatekeeperData {
/**
* The criterion hat(s)
*/
criterionHat: string[];

/**
* The hats contract
*/
hatsContract: string;
}

0 comments on commit d644eae

Please sign in to comment.