Skip to main content

API Reference

Complete API reference for the Privacy Boost TypeScript SDK.

Generated Documentation

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

# Documentation will be generated in docs/api/
The generated docs include:
  • All exported types and interfaces
  • JSDoc comments and examples
  • Type signatures and inheritance

PrivacyBoost

Main SDK class.

PrivacyBoost.create(config)

Creates and initializes a new SDK instance.
static async create(config: PrivacyBoostConfig): Promise<PrivacyBoost>
Parameters:
NameTypeDescription
config.indexerUrlstringIndexer service URL
config.proverUrlstringProver service URL
config.chainIdnumberEVM chain ID
config.shieldContractstringShield contract address
config.wethContractstring(Optional) WETH contract address
Example:
const sdk = await PrivacyBoost.create({
  indexerUrl: 'https://test-api.privacy-boost.sunnyside.io/indexer',
  proverUrl: 'https://test-api.privacy-boost.sunnyside.io/prover',
  chainId: 11155420,
  shieldContract: "0xB22fD661b322F10d4B7cd0cFcb9578C485423119",
  wethContract: "0x4200000000000000000000000000000000000006"
});

sdk.auth

Authentication resource.

auth.connect(adapter)

Connect a wallet.
async connect(adapter: WalletAdapter): Promise<{ address: string; chainId: number }>

auth.disconnect()

Disconnect the wallet.
async disconnect(): Promise<void>

auth.login()

Derive privacy keys and authenticate.
async login(): Promise<{ privacyAddress: string; mpk: string }>

auth.logout()

Clear all authentication state.
async logout(): Promise<void>

auth.isConnected()

Check if wallet is connected.
isConnected(): boolean

auth.isAuthenticated()

Check if user is authenticated.
isAuthenticated(): boolean

auth.getAddress()

Get connected wallet address.
getAddress(): string | null

auth.getPrivacyAddress()

Get user’s privacy address.
getPrivacyAddress(): string | null

auth.getMpk()

Get user’s master public key.
getMpk(): string | null

auth.exportSession()

Export session for persistence.
exportSession(): ExportableSession

auth.importSession(session)

Import a saved session.
async importSession(session: unknown): Promise<void>

auth.getSessionInfo()

Get session validity information.
async getSessionInfo(): Promise<SessionInfo | null>

sdk.vault

Vault resource for privacy operations.

vault.deposit(params)

Deposit tokens to private balance.
async deposit(params: DepositParams): Promise<DepositResult>

interface DepositParams {
  tokenAddress: Hex;
  amount: bigint;
  recipientMpk?: bigint;
  onProgress?: OnProgress;
}

interface DepositResult {
  txHash: Hex;
  commitment: Hex;
  fee: bigint;
  wrapTxHash?: Hex;
}

vault.withdraw(params)

Withdraw tokens to public address.
async withdraw(params: WithdrawParams): Promise<WithdrawResult>

interface WithdrawParams {
  tokenAddress: Hex;
  amount: bigint;
  recipientAddress: Hex;
  unwrapWeth?: boolean;
  onProgress?: OnProgress;
}

interface WithdrawResult {
  txHash: Hex;
  amount: bigint;
  unwrapTxHash?: Hex;
}

vault.send(params)

Send private transfer.
async send(params: SendParams): Promise<TransactionResult>

interface SendParams {
  to: PrivacyAddress;
  tokenAddress: Hex;
  amount: bigint;
}

interface TransactionResult {
  txHash: Hex;
}

vault.getBalance(tokenAddress)

Get shielded balance for a token.
async getBalance(tokenAddress: string): Promise<bigint>

vault.getAllBalances()

Get all token balances.
async getAllBalances(): Promise<TokenBalance[]>

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

vault.syncBalance(tokenAddress)

Sync balance from indexer.
async syncBalance(tokenAddress: Hex): Promise<void>

vault.syncAllBalances()

Sync all balances from indexer.
async syncAllBalances(): Promise<void>

vault.getToken(address)

Get token metadata.
async getToken(address: string): Promise<TokenMetadata>

interface TokenMetadata {
  address: Hex;
  symbol: string;
  decimals: number;
  name: string;
}

vault.getSupportedTokens()

Get list of supported tokens.
async getSupportedTokens(): Promise<TokenMetadata[]>

vault.parseAmount(tokenAddress, amount)

Parse string amount to bigint.
async parseAmount(tokenAddress: string, amount: string): Promise<bigint>

vault.formatAmount(amount, decimals)

Format bigint to string.
formatAmount(amount: bigint, decimals: number): string

sdk.contacts

Contacts resource.

contacts.getContacts()

Get all contacts.
getContacts(): Contact[]

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

contacts.addContact(params)

Add a new contact.
async addContact(params: CreateContactParams): Promise<Contact>

interface CreateContactParams {
  name: string;
  privacyAddress: PrivacyAddress;
  note?: string;
}

contacts.removeContact(privacyAddress)

Remove a contact.
async removeContact(privacyAddress: string): Promise<void>

contacts.updateContact(privacyAddress, params)

Update a contact.
async updateContact(
  privacyAddress: string,
  params: UpdateContactParams
): Promise<Contact>

interface UpdateContactParams {
  name?: string;
  privacyAddress?: PrivacyAddress;
  note?: string;
}

contacts.findByAddress(privacyAddress)

Find contact by privacy address.
findByAddress(privacyAddress: string): Contact | undefined

contacts.search(query)

Search contacts by name.
search(query: string): Contact[]

sdk.transactions

Transactions resource.

transactions.fetchHistory(params?)

Get transaction history.
async fetchHistory(params?: TransactionHistoryParams): Promise<Transaction[]>

interface TransactionHistoryParams {
  type?: TransactionType;
  tokenAddress?: string;
  limit?: number;
}

interface Transaction {
  txHash: Hex;
  type: TransactionType;
  direction: TransactionDirection;
  status: TransactionStatus;
  tokenAddress: Hex;
  amount: bigint;
  createdAt: number;
  updatedAt: number;
  to?: Hex;
  from?: Hex;
  error?: string;
}

enum TransactionType {
  deposit = 'deposit',
  withdraw = 'withdraw',
  transfer = 'transfer',
}

enum TransactionDirection {
  incoming = 'incoming',
  outgoing = 'outgoing',
}

enum TransactionStatus {
  pending = 'pending',
  completed = 'completed',
  failed = 'failed',
}

Wallet Adapters

Eip1193WalletAdapter

class Eip1193WalletAdapter implements WalletAdapter {
  constructor(provider: EIP1193Provider)
}

WalletConnectAdapter

Note: WalletConnectAdapter is not directly exported from the main entry point. Access it via createWalletRegistry():
const registry = createWalletRegistry();
const adapter = registry.get('walletconnect')!.create({ projectId: '...' });
class WalletConnectAdapter implements WalletAdapter {
  constructor(options: {
    projectId: string;
    chains: number[];
    showQrModal?: boolean;
    metadata?: {
      name: string;
      description: string;
      url: string;
      icons: string[];
    };
  })
}

CoinbaseWalletAdapter

Note: CoinbaseWalletAdapter is not directly exported from the main entry point. Access it via createWalletRegistry():
const registry = createWalletRegistry();
const adapter = registry.get('coinbase')!.create({ appName: '...' });
class CoinbaseWalletAdapter implements WalletAdapter {
  constructor(options: {
    appName: string;
    appLogoUrl?: string;
    chainId: number;
    jsonRpcUrl: string;
  })
}

PrivateKeyWalletAdapter

class PrivateKeyWalletAdapter implements WalletAdapter {
  constructor(options: {
    privateKey: string;
    chainId: number;
    rpcUrl: string;
  })
}

Utility Functions

isValidPrivacyAddress(address)

Check if address is valid privacy address.
function isValidPrivacyAddress(address: string): boolean

validatePrivacyAddress(address)

Validate and throw on invalid.
function validatePrivacyAddress(address: string): void

encodePrivacyAddress(mpk, viewingKey)

Encode MPK and viewing key to privacy address.
function encodePrivacyAddress(mpk: bigint, viewingKey: bigint): PrivacyAddress

decodePrivacyAddress(address)

Decode privacy address to components.
function decodePrivacyAddress(address: PrivacyAddress): {
  mpk: bigint;
  viewingKey: bigint;
}

extractMpkFromPrivacyAddress(address)

Extract MPK from privacy address.
function extractMpkFromPrivacyAddress(address: PrivacyAddress): bigint

isEvmAddress(address)

Check if valid EVM address.
function isEvmAddress(address: string): boolean

isNativeEth(address)

Check if address represents native ETH.
function isNativeEth(address: string): boolean

Types

Hex

type Hex = `0x${string}`

PrivacyAddress

type PrivacyAddress = string // 66-byte encoded address

WalletAdapter

interface WalletAdapter {
  connect(): Promise<{ address: string; chainId: number }>;
  disconnect(): Promise<void>;
  signMessage(message: string): Promise<string>;
  signTypedData(typedData: string): Promise<string>;
  sendTransaction(tx: TransactionRequest): Promise<string>;
  getAddress(): Promise<string>;
  getChainId(): Promise<number>;
}

OnProgress

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

Constants

const NATIVE_ETH_ADDRESS = '0x0000000000000000000000000000000000000000';
const PRIVACY_ADDRESS_LENGTH = 65;
const PRIVACY_ADDRESS_HEX_LENGTH = 132;