API Reference
Components
ZkEmailSDKProvider
The ZkEmailSDKProvider is a wrapper component that provides the ZK Email SDK context to its children. It manages the core functionalities of the SDK, including input generation, proof creation, and interaction with the ZK Email SDK registry.
Props
children
ReactNode
Child components to be wrapped
clientId
string
Google OAuth client ID
zkEmailSDKRegistryUrl
string
URL for the ZK Email SDK registry
Ensure that your clientId is kept secret and not exposed in client-side code.
Usage
import { ZkEmailSDKProvider } from "@zk-email/zk-email-sdk";
function App() {
return (
<ZkEmailSDKProvider
clientId={import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID}
zkEmailSDKRegistryUrl='https://registry-dev.zkregex.com'
>
{/* Your app components */}
</ZkEmailSDKProvider>
);
}
export default App;// src/app/providers.tsx
'use client'
import { ZkEmailSDKProvider } from "@zk-email/zk-email-sdk";
export function Providers({ children }: { children: React.ReactNode }) {
return (
<ZkEmailSDKProvider
clientId={process.env.NEXT_PUBLIC_GOOGLE_OAUTH_CLIENT_ID}
zkEmailSDKRegistryUrl='https://registry-dev.zkregex.com'
>
{children}
</ZkEmailSDKProvider>
);
}// src/app/layout.tsx
import { Providers } from './providers'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<Providers>{children}</Providers>
</body>
</html>
)
}GoogleAuthProvider
The GoogleAuthProvider is a wrapper component that manages Google authentication state and provides authentication-related functions to its child components. It's an essential part of the ZK Email SDK that simplifies the process of integrating Google authentication into your application.
Props
children
ReactNode
Child components that will have access to the authentication context
Hooks
useZkEmailSDK
The useZkEmailSDK hook provides access to ZK Email SDK functionalities, allowing components to interact with the core features of the SDK.
Returns
zkEmailSDKRegistryUrl
string
URL of the ZK Email SDK registry
inputWorkers
Record<string, Worker>
Object containing input workers
createInputWorker
(name: string) => void
Creates an input worker
deleteInputWorker
(name: string) => void
Deletes an input worker
generateInputFromEmail
(name: string, email: string, externalInputs: Record<string, string>) => Promise
Generates input from an email
loadProofsFromStorage
(name: string) => void
Loads proofs from local storage
proofStatus
Record<string, ProofStatus>
Object containing proof statuses
generateProofRemotely
(name: string, input: any) => Promise
Generates a proof remotely
deleteProofFromStorage
(id: string) => void
Deletes a proof from storage
Ensure that you're calling this hook within a component that is a child of ZkEmailSDKProvider, otherwise it will throw an error.
useGoogleAuth
The useGoogleAuth hook provides access to Google authentication functionalities, allowing components to check authentication status and perform login/logout operations.
Returns
googleAuthToken
any | null
Google authentication token
isGoogleAuthed
boolean
Whether the user is authenticated with Google
loggedInGmail
string | null
Email of the logged-in user
scopesApproved
boolean
Whether all required scopes are approved
googleLogIn
() => void
Initiates Google login
googleLogOut
() => void
Logs out from Google
Utility Functions
fetchEmailList, fetchEmailsRaw, fetchProfile
These functions fetch email data and user profile information using the provided Google authentication token.
These functions should only be called after successful Google authentication and with a valid token.
Usage
Last updated