Skip to main content

API Reference

Complete API reference for the Privacy Boost React SDK.

Generated Documentation

Full API documentation can be generated using TypeDoc:
# From packages/privacy-boost-react directory
npm run docs

# Documentation will be generated in docs/api/
The generated docs include:
  • All hook signatures and return types
  • JSDoc comments with usage examples
  • Type definitions and interfaces

Provider

PrivacyBoostProvider

Main provider component that initializes the SDK.
<PrivacyBoostProvider
  config={PrivacyBoostConfig}
  loadingComponent?: ReactNode
  errorComponent?: (error: Error) => ReactNode
>
  {children}
</PrivacyBoostProvider>

// Or with pre-initialized SDK
<PrivacyBoostProvider sdk={PrivacyBoost}>
  {children}
</PrivacyBoostProvider>

Context Hooks

usePrivacyBoost()

Get direct access to the SDK instance.
function usePrivacyBoost(): PrivacyBoost | null

usePrivacyBoostState()

Get provider initialization state.
function usePrivacyBoostState(): {
  loading: boolean;
  error: Error | null;
  initialized: boolean;
}

useAuth

Authentication hook.
function useAuth(): UseAuthResult

interface UseAuthResult {
  // State
  isConnected: boolean;
  isAuthenticated: boolean;
  isWalletAvailable: boolean;
  address: string | null;
  privacyAddress: string | null;
  mpk: string | null;

  // Methods
  connect(adapter: WalletAdapter): Promise<{ address: string; chainId: number }>;
  connectInjected(): Promise<{ address: string; chainId: number }>;
  disconnect(): Promise<void>;
  login(): Promise<LoginResult>;
  logout(): Promise<void>;
  authenticate(adapter: WalletAdapter): Promise<LoginResult>;
  authenticateInjected(): Promise<LoginResult>;
}

useVault

Vault operations hook.
function useVault(): UseVaultResult

interface UseVaultResult {
  deposit(params: SimpleDepositParams): Promise<DepositResult>;
  withdraw(params: SimpleWithdrawParams): Promise<WithdrawResult>;
  send(params: SimpleSendParams): Promise<TransactionResult>;
  getBalance(tokenAddress: string): Promise<bigint>;
  getAllBalances(): Promise<TokenBalance[]>;
  syncBalance(tokenAddress: Hex): Promise<void>;
  syncAllBalances(): Promise<void>;
}

interface SimpleDepositParams {
  tokenAddress: Hex;
  amount: string | bigint;
  onProgress?: OnProgress;
}

interface SimpleWithdrawParams {
  tokenAddress: Hex;
  amount: string | bigint;
  recipientAddress?: Hex;
  unwrapWeth?: boolean;
  onProgress?: OnProgress;
}

interface SimpleSendParams {
  to: Hex | string;
  tokenAddress: Hex;
  amount: string | bigint;
}

useBalances

Reactive balance data hook.
function useBalances(): UseBalancesResult

interface UseBalancesResult {
  balances: FormattedBalance[];
  loading: boolean;
  lastSynced: number | null;
  getBalance(tokenAddress: string): FormattedBalance | undefined;
  getShieldedBalance(tokenAddress: string): bigint;
  getWalletBalance(tokenAddress: string): bigint;
  totalShielded: bigint;
  tokenCount: number;
}

interface FormattedBalance extends TokenBalance {
  formattedShielded: string;
  formattedWallet: string;
}

useContacts

Contact management hook.
function useContacts(): UseContactsResult

interface UseContactsResult {
  contacts: Contact[];
  addContact(params: CreateContactParams): Promise<Contact>;
  removeContact(privacyAddress: string): Promise<void>;
  updateContact(privacyAddress: string, params: UpdateContactParams): Promise<Contact>;
  findByAddress(privacyAddress: string): Contact | undefined;
  search(query: string): Contact[];
}

useTransactions

Transaction history hook.
function useTransactions(): UseTransactionsResult

interface UseTransactionsResult {
  transactions: Transaction[];
  loading: boolean;
  fetchHistory(params?: TransactionHistoryParams): Promise<void>;
}

interface TransactionHistoryParams {
  type?: 'deposit' | 'withdraw' | 'transfer';
  tokenAddress?: string;
  limit?: number;
}

Helper Functions

createInjectedAdapter()

Create wallet adapter from window.ethereum.
function createInjectedAdapter(): WalletAdapter

Types

PrivacyBoostConfig

interface PrivacyBoostConfig {
  indexerUrl: string;
  proverUrl: string;
  chainId: number;
  shieldContract: `0x${string}`;
  wethContract?: `0x${string}`;
}

Contact

interface Contact {
  id: string;
  name: string;
  privacyAddress: PrivacyAddress;
  note?: string;
  createdAt: number;
  updatedAt: number;
}

Transaction

interface Transaction {
  txHash: Hex;
  type: 'deposit' | 'withdraw' | 'transfer';
  direction: 'incoming' | 'outgoing';
  status: 'pending' | 'completed' | 'failed';
  tokenAddress: Hex;
  amount: bigint;
  createdAt: number;
  updatedAt: number;
  to?: Hex;
  from?: Hex;
  error?: string;
}

TokenBalance

interface TokenBalance {
  tokenAddress: Hex;
  shielded: bigint;
  wallet: bigint;
  symbol?: string;
  decimals?: number;
}

OnProgress

type OnProgress = (progress: {
  step: DepositStep | WithdrawStep;
  message: string;
  txHash?: Hex;
}) => void;