Skip to main content

Wallet Integration

The WalletDelegate protocol is the bridge between the Privacy Boost SDK and your wallet. This guide covers implementing it for various wallet types, expanding on the brief examples in Authentication.

Protocol Definition

Implementation Requirements

Return Values

  • Addresses: Checksummed hex strings with 0x prefix (42 characters)
  • Signatures: Hex strings with 0x prefix (132 characters for 65 bytes)
  • Transaction hashes: Hex strings with 0x prefix (66 characters)
  • Transaction receipts: Mined receipt status and logs from eth_getTransactionReceipt
  • Chain ID: Integer matching expected network

Async Behavior

All WalletDelegate methods are async throws. The SDK awaits each call, so your implementation can use native Swift concurrency (async/await). The SDK calls waitForTransactionReceipt after sendTransaction to confirm on-chain inclusion and read emitted events.

WalletConnect Integration

Example using WalletConnect Swift SDK:

Web3.swift Integration

Example using web3.swift with a local keystore:

Testing with Mock Wallet

For testing, create a mock delegate:

Error Handling

Throw appropriate errors from delegate methods:

Best Practices

  1. Validate inputs - Check addresses and data formats before processing
  2. Handle timeouts - Set reasonable timeouts for wallet operations
  3. User feedback - Show loading indicators during signing/transactions
  4. Error messages - Provide clear error messages for user-facing errors
  5. Thread safety - Ensure delegate methods can be called from any thread

Next Steps