useProver
Hook to access the proving client from within ProverProvider.
Usage
import { useProver } from "@succinctlabs/react-native-zcam1/proving";
function ProveButton() {
const { provingClient, isInitializing, error } = useProver();
if (isInitializing) return <Text>Loading...</Text>;
if (error) return <Text>Error: {error.message}</Text>;
// Use provingClient...
}Returns
type ProverContextValue = {
provingClient: ProvingClient | null; // The proving client instance
provingTasks: ProvingTasksState; // Active proof requests
provingTasksCount: number; // Number of active requests
isInitializing: boolean; // Whether proving client is initializing
error: unknown; // Any initialization error
}
type ProvingTasksState = Record<string, ProvingTask>;
type ProvingTask = {
photoPath: string;
createdAtMs: number;
}See ProverContextValue type reference for details.
Example
import { useState } from "react";
import { Button, Text, ActivityIndicator } from "react-native";
import { useProver } from "@succinctlabs/react-native-zcam1/proving";
import { launchImageLibrary } from "react-native-image-picker";
function ProveScreen() {
const { provingClient, isInitializing, provingTasksCount } = useProver();
const [result, setResult] = useState<string>();
const handleProve = async () => {
if (!provingClient) return;
const response = await launchImageLibrary({ mediaType: "photo" });
const uri = response.assets?.[0]?.uri;
if (!uri) return;
try {
const provenPath = await provingClient.waitAndEmbedProof(uri);
setResult(`Proven: ${provenPath}`);
} catch (error: any) {
setResult(`Error: ${error.message}`);
}
};
if (isInitializing) {
return <ActivityIndicator />;
}
return (
<>
<Button title="Prove Photo" onPress={handleProve} />
{provingTasksCount > 0 && (
<Text>{provingTasksCount} proofs in progress...</Text>
)}
{result && <Text>{result}</Text>}
</>
);
}Notes
- Must be used within a
ProverProvider provingClientisnulluntil initialization completesprovingTaskstracks all active proof requests when using the provider's callbacks- The proving client provides methods:
requestProof,getProofStatus,embedProof,waitAndEmbedProof