Skip to main content

API Reference

Complete API reference for the Privacy Boost iOS SDK.

Generated Documentation

Full API documentation can be generated using cargo doc:
# From rust-sdk directory
make docs-rust

# iOS-specific docs
cargo doc --no-deps -p privacy-boost-ios

PrivacyBoostSdk

Main SDK class for iOS.

Constructor

init(config: SdkConfig) throws
Creates a new SDK instance. Parameters:
  • config - SDK configuration
Throws: SDKError.internalError if initialization fails

Properties

var isConnected: Bool { get }
var isAuthenticated: Bool { get }

Connection Methods

connect

func connect(wallet: WalletDelegate) throws -> ConnectResult
Connect a wallet and derive privacy keys. Parameters:
  • wallet - Implementation of WalletDelegate protocol
Returns: ConnectResult with wallet and privacy addresses Throws:
  • SDKError.chainMismatch if wallet is on wrong network
  • SDKError.walletError if signing fails

disconnect

func disconnect()
Disconnect the current wallet and clear state.

Authentication Methods

login

func login() throws -> LoginResult
Authenticate with the Privacy Boost backend. Returns: LoginResult with privacy address and MPK Throws:
  • SDKError.notConnected if wallet not connected
  • SDKError.networkError if backend unreachable

logout

func logout()
Log out and clear authentication state.

State Accessors

func getPrivacyAddress() -> String?
func getMpk() -> String?
func getWalletAddress() -> String?

Balance Methods

getBalance

func getBalance(tokenAddress: String) throws -> TokenBalance
Get balance for a specific token. Parameters:
  • tokenAddress - ERC-20 token contract address
Returns: TokenBalance with shielded and wallet amounts

getAllBalances

func getAllBalances() throws -> [TokenBalance]
Get all token balances.

Vault Operations

deposit

func deposit(tokenAddress: String, amount: String) throws -> DepositResult
Deposit tokens into the shielded pool. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
Returns: DepositResult with transaction hash

withdraw

func withdraw(tokenAddress: String, amount: String, recipient: String) throws -> WithdrawResult
Withdraw tokens from the shielded pool. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
  • recipient - Recipient Ethereum address
Returns: WithdrawResult with transaction hash

send

func send(tokenAddress: String, amount: String, recipientPrivacyAddress: String) throws -> TransferResult
Send a private transfer. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
  • recipientPrivacyAddress - Recipient’s 194-char privacy address
Returns: TransferResult with transaction hash

Transaction History

func getTransactionHistory(
    txType: String?,
    tokenAddress: String?,
    limit: UInt32?
) throws -> [Transaction]
Get transaction history. Parameters:
  • txType - Filter by type: “deposit”, “withdraw”, “transfer”
  • tokenAddress - Filter by token
  • limit - Maximum results

Session Persistence

exportSession

func exportSession() -> ExportedSession?
Export session data for persistence. Returns: ExportedSession or nil if not authenticated

importSession

func importSession(_ session: ExportedSession) throws -> Bool
Import a previously exported session. Returns: true if session is valid and imported

Utilities

func isValidPrivacyAddress(_ address: String) -> Bool
func isValidAddress(_ address: String) -> Bool
func parseAmount(_ amount: String, decimals: UInt8) throws -> String
func formatAmount(_ wei: String, decimals: UInt8) throws -> String

Types

SdkConfig

struct SdkConfig {
    let indexerUrl: String
    let proverUrl: String
    let chainId: UInt64
    let shieldContract: String
    let wethContract: String
}

ConnectResult

struct ConnectResult {
    let walletAddress: String
    let privacyAddress: String
    let mpk: String
}

LoginResult

struct LoginResult {
    let privacyAddress: String
    let mpk: String
}

TokenBalance

struct TokenBalance {
    let tokenAddress: String
    let shieldedBalance: String
    let walletBalance: String
    let symbol: String?
    let decimals: UInt8
}

DepositResult

struct DepositResult {
    let txHash: String
    let commitment: String
    let fee: String
}

WithdrawResult

struct WithdrawResult {
    let txHash: String
    let fee: String
}

TransferResult

struct TransferResult {
    let txHash: String
    let fee: String
}

Transaction

struct Transaction {
    let txHash: String
    let txType: String
    let tokenAddress: String
    let amount: String
    let direction: String
    let senderPubKey: String
    let receiverPubKeys: [String]
    let createdAt: UInt64
}

ExportedSession

struct ExportedSession {
    let walletPublicKeyX: String
    let walletPublicKeyY: String
    let viewingKey: String
    let viewingPublicKeyX: String
    let viewingPublicKeyY: String
    let nullifyingKey: String
    let nullifyingPublicKeyX: String
    let nullifyingPublicKeyY: String
    let mpk: String
    let jwt: String
    let jwtExpiry: UInt64
    let walletAddress: String
}

WalletDelegate Protocol

protocol WalletDelegate: AnyObject {
    func getAddress() throws -> String
    func getChainId() throws -> UInt64
    func signMessage(message: String) throws -> String
    func signTypedData(typedDataJson: String) throws -> String
    func sendTransaction(toAddress: String, value: String, data: String) throws -> String
}

SDKError

enum SDKError: Error {
    case notConnected
    case notAuthenticated
    case chainMismatch(expected: UInt64, actual: UInt64)
    case insufficientBalance
    case invalidAmount
    case invalidRecipient
    case invalidPrivacyAddress
    case sessionExpired
    case walletError(String)
    case networkError(String)
    case proofError(String)
    case internalError(String)
}

See Also