Documentation Index
Fetch the complete documentation index at: https://docs.privora.xyz/llms.txt
Use this file to discover all available pages before exploring further.
PrivoraProvider
Provider component that wraps your app to provide Privora state to all child components.
function PrivoraProvider(props: PrivoraProviderProps): React.ReactElement
Props
interface PrivoraProviderProps {
/** The Privora sequencer RPC URL */
rpcUrl: string;
/** Custom message for deriving encryption keys */
signatureMessage?: string;
/** Whether to auto-initialize when signMessage is available */
autoInitialize?: boolean;
/** The signMessage function from wallet adapter (for auto-init) */
signMessage?: SignMessageFn | null;
/** Children components */
children: ReactNode;
}
type SignMessageFn = (message: Uint8Array) => Promise<Uint8Array>;
Example
import { PrivoraProvider } from '@privora/react';
// Basic usage
function App() {
return (
<PrivoraProvider rpcUrl="http://localhost:8899">
<MyApp />
</PrivoraProvider>
);
}
// With auto-initialization
function App() {
const { signMessage } = useWallet();
return (
<PrivoraProvider
rpcUrl="http://localhost:8899"
autoInitialize
signMessage={signMessage}
>
<MyApp />
</PrivoraProvider>
);
}
PrivoraContext
The React context object. Typically you’ll use the hooks below instead of accessing this directly.
const PrivoraContext: React.Context<PrivoraContextValue | null>
usePrivoraContext
Hook to access the full Privora context. Must be used within a PrivoraProvider.
function usePrivoraContext(): PrivoraContextValue
Return Value
interface PrivoraContextValue {
/** The connected Privora instance */
privora: Privora | null;
/** The user's crypto instance for local encryption/decryption */
userCrypto: UserCrypto | null;
/** The user's derived keypair */
userKeypair: Keypair | null;
/** Whether Privora is fully initialized */
isInitialized: boolean;
/** Whether initialization is in progress */
isInitializing: boolean;
/** Any error that occurred during initialization */
error: string | null;
/** Initialize Privora with a wallet signature */
initialize: (signMessage: SignMessageFn) => Promise<void>;
/** Reset the Privora state */
reset: () => void;
}
Example
import { usePrivoraContext } from '@privora/react';
function MyComponent() {
const { privora, userCrypto, isInitialized, error } = usePrivoraContext();
if (error) return <div>Error: {error}</div>;
if (!isInitialized) return <div>Loading...</div>;
// Use privora and userCrypto
}
Throws
Throws an error if used outside of a PrivoraProvider.
usePrivoraInstance
Hook to access just the Privora instance from context.
function usePrivoraInstance(): Privora | null
Returns null if Privora is not initialized or if used outside a provider.
Example
const privora = usePrivoraInstance();
if (privora) {
const hash = await privora.submit(encrypted);
}
useUserCrypto
Hook to access just the UserCrypto instance from context.
function useUserCrypto(): UserCrypto | null
Returns null if Privora is not initialized or if used outside a provider.
Example
const userCrypto = useUserCrypto();
if (userCrypto) {
const decrypted = userCrypto.decryptFromSelf(ciphertext, nonce);
}
useUserKeypair
Hook to access the user’s derived keypair from context.
function useUserKeypair(): Keypair | null
Returns null if Privora is not initialized or if used outside a provider.
Example
const userKeypair = useUserKeypair();
if (userKeypair) {
console.log('User pubkey:', userKeypair.publicKey.toBase58());
}