Using the SDK

NOTE: As the SDK is still in development, the APIs might change drastically.

Getting started

Google Client API key You will need a Google Oauth token if you want users to be able to directly query emails from their inbox. Go to Google Cloud's dashboard to enable the Gmail API.

React Project The SDK currently only works with reactjs. If you are using nextjs, you might need some workarounds to make sure the page you integrate the SDK runs fully on the client side. Refer to this for reference example

Wiring it up

Surround a page with the ZkEmailSDKProvider given by the SDK. If you are using nextjs, it is recommended that you only include this in a page that uses the SDK. Else, your entire application will need to be client-side rendered.

import { ZkEmailSDKProvider } from "@zk-email/zk-email-sdk";

function TryPage(props: Props) {
  return (
    <ZkEmailSDKProvider clientId={GOOGLE_CLIENT_ID} zkEmailSDKRegistryUrl='https://registry-dev.zkregex.com'>
        <Page {...props}/>
    </ZkEmailSDKProvider>
  );
};

In your page, the SDK exposes a few hooks to interact with the library.

export function Page(props: Props) {
    const {
        googleAuthToken,
        isGoogleAuthed,
        loggedInGmail,
        googleLogIn,
        googleLogOut,
    } = useGoogleAuth();

    const {
        createInputWorker,
        generateInputFromEmail,
        generateProofRemotely,
        proofStatus,
        inputWorkers
    } = useZkEmailSDK();
}
interface ProofStatus {
    status: string;
    id: string;
    pollUrl: string;
    estimatedTimeLeft: number;
    publicOutput: any;
    proof: any;
}

Example integration

First, create an inputWorker:

createInputWorker("<slug-name>");

Once the input worker is created, it will be populated in the inputWorkers variable. You can monitor this variable. As soon as the inputWorker is created, you can call the generateProofRemotely method:

const [externalInputs, setExternalInputs] = useState<Record<string,string>>({});

// externalInputs - External inputs added when submitting a new pattern at https://registry-dev.zkregex.com/submit
const entryExternalInputs = externalInputs as {name: string, maxLength: number}[] || [];

for (const input of entryExternalInputs) {
    setExternalInputs({
        ...externalInputs,
        [input.name]: "",
    });
}


const input = await generateInputFromEmail(
  "<slug-name>",
  emailFull,
  externalInputs
);

const proofRes = await generateProofRemotely(
  "<slug-name>",
  input
);

Last updated