Skip to main content

API Reference

Complete API reference for the Privacy Boost Android SDK.

Generated Documentation

Full API documentation can be generated using cargo doc:

PrivacyBoost

Main SDK class for Android.

Constructor

Creates a new SDK instance. Parameters:
  • config - SDK configuration

Properties

Connection & Authentication Methods

authenticate

Connect a wallet, derive privacy keys, and authenticate with the Privacy Boost backend in a single call. Parameters:
  • wallet - Implementation of WalletDelegate interface
  • keySource - Optional key derivation source. If null and no persistence is configured, defaults to KeySource.WalletDerived. If null with persistence configured and no existing vault, an error is thrown.
  • tokenProvider - Optional custom token provider. If null, the SDK sends the login payload directly to the Privacy Boost backend. Supply a TokenProvider to route authentication through your own server.
Returns: AuthResult - either AuthResult.Authenticated(LoginResult) or AuthResult.CredentialRequired(CredentialChallenge) Throws:
  • SDKError.WalletError if signing fails
  • SDKError.InvalidConfig if configuration is invalid or keySource is required but missing
  • SDKError.NetworkError if backend unreachable

submitCredential

Submit a credential when authenticate() returns CredentialRequired. Parameters:
  • credential - The credential string
  • tokenProvider - Optional custom token provider for routing authentication through your own server
Returns: LoginResult with privacy address and MPK

logout

End session completely, clear all state.

clearSession

Clear JWT only, keep keys for quick re-auth.

State Accessors

Balance Methods

getBalance

Get balance for a specific token. Parameters:
  • tokenAddress - ERC-20 token contract address
Returns: TokenBalance with shielded and wallet amounts

getAllBalances

Get all token balances.

Vault Operations

deposit

Deposit tokens into the shielded pool. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
Returns: ShieldResult with transaction hash

withdraw

Withdraw tokens from the shielded pool. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
  • recipient - Recipient Ethereum address
Returns: UnshieldResult with transaction hash

send

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

prepareShield

Build a deposit payload without submitting it — for callers that relay the transaction themselves (a gasless relayer, an EIP-7702 session key, or a plain raw transaction). Returns the calldata to relay plus the note commitment; nothing is sent on-chain and no wallet is used. After relaying, pass the mined receipt to the top-level finalizeShield(...) to recover the on-chain request id. Parameters:
  • tokenAddress - Token contract address (zero address = native ETH)
  • amount - Amount in wei (as string)
  • recipient - (Optional) recipient privacy address. Pass null to shield to yourself.
Returns: PreparedShield with the calls to relay and the note commitment

Transaction History

Get transaction history. Parameters:
  • txType - Filter by type: “deposit”, “withdraw”, “transfer”
  • tokenAddress - Filter by token
  • limit - Maximum results

Session Persistence

exportSession

Export session data for persistence. Returns: ExportedSession or null if not authenticated

importSession

Import a previously exported session. Returns: true if session is valid and imported

Address Lookup

resolveIdentity

Look up a user’s privacy address by MPK or Ethereum address. Parameters:
  • identifier - MPK or Ethereum address
Returns: IdentityResult with privacy address and public keys

Utilities


Module Functions

  • sdkVersion() — Returns the SDK version string
  • generateMnemonic() — Generates a random 12-word BIP-39 mnemonic

Stateless shield helpers

Top-level functions for building a deposit payload without a signed-in session — for a backend that holds only a recipient’s privacy address. No wallet, no private keys.
buildShieldPayload builds a recipient-targeted deposit payload from public material only. Resolve tokenId, shieldContractAddress, and teePublicKey from the token catalog / config. An ephemeral sender keypair is generated and discarded internally, and the note is spendable only by recipient. wethContractAddress is required only when shielding native ETH; minShieldAmount (per-token minimum in wei) rejects below-minimum deposits; emitApprove emits the ERC-20 approve call (pass true by default). finalizeShield recovers the on-chain shield request id from the mined receipt of a relayed deposit. Stateless — the caller obtained the receipt from its own relay/RPC. Throws if the deposit reverted or the DepositRequested log is absent.

Types

PrivacyBoostConfig

KeySource

Specifies how privacy keys are derived. Passed as an optional parameter to authenticate().
  • WalletDerived - Derive keys from a deterministic wallet signature (default when no persistence configured)
  • Mnemonic - Derive keys from a BIP-39 mnemonic phrase
  • RawSeed - Derive keys from raw hex entropy (for testing)

AuthResult

LoginResult

TokenBalance

ShieldResult

Returned by shield and finalizeShield.

UnshieldResult

TransferResult

Call

A single on-chain call to relay. value and data are 0x-hex.

PreparedShield

Returned by prepareShield and buildShieldPayload.

TransactionReceipt

The mined-receipt type passed to finalizeShield.

Transaction

IdentityResult

ExportedSession

data is an opaque serialized core session. Store and pass it back unchanged; do not parse or persist individual key fields.

WalletDelegate Interface


TokenProvider Interface

Implement this interface to route authentication through your own server. The SDK serializes the login payload as a JSON string and passes it to getToken(). Your implementation should forward this payload to your backend, which adds its own credentials and calls the Privacy Boost API.

TokenResponse

Example


SDKError


Gift Methods

Claimable-transfer (gift) methods on the PrivacyBoost instance. Preview feature — pending external audit, enabled per deployment. See the Claimable Transfers guide for usage and the concept page for the trust model. Suspend methods should be called inside withContext(Dispatchers.IO).

giftFundToWallet

Fund a gift bound to a recipient wallet address that may not be registered yet. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
  • recipientWallet - Recipient’s Ethereum address the gift binds to (irrevocable)
  • refundAfterBlock - Block height after which an unclaimed gift may be reclaimed
  • currentBlock - Current chain head; pre-validates the refund delay
Returns: TransferResult with giftRecord (persist it) and claimLink

giftFund

Fund a gift when the recipient is already a Privacy Boost user. Seals the gift ciphertext to their viewing key for the smoothest discovery. Parameters:
  • tokenAddress - Token contract address
  • amount - Amount in wei (as string)
  • recipientPrivacyAddress - Recipient’s 194-char privacy address (ECDH target)
  • recipientWallet - Recipient’s Ethereum address the gift binds to (irrevocable)
  • refundAfterBlock - Block height after which an unclaimed gift may be reclaimed
  • currentBlock - Current chain head; pre-validates the refund delay
Returns: TransferResult with giftRecord (persist it) and claimLink

giftClaim

Claim a pending gift by its position in getPendingGifts(). Parameters:
  • index - Position in the pending-gift list
  • acknowledgeUnknownSender - Must be true; consents to funds from a hidden sender

giftClaimByCGift

Claim a pending gift by its stable commitment cGift. Preferred over index when the pending list may shift as gifts settle. Parameters:
  • cGift - Stable gift commitment
  • acknowledgeUnknownSender - Must be true
Claim directly from a pbgift:v1:... claim link without a server lookup first. Parameters:
  • link - A pbgift:v1:... claim link
  • acknowledgeUnknownSender - Must be true

giftRefundByRecord

Refund an unclaimed gift using the local gift record saved at funding time. Only valid after refundAfterBlock has elapsed. Parameters:
  • index - Position in getGiftRecords()

giftRefund

Refund an unclaimed gift by supplying every field manually — the fallback when the local gift record has been lost.

getPendingGifts

List pending gifts addressed to the authenticated wallet (TEE discovery).

getGiftRecords

List the local gift records the SDK persisted for gifts you funded. These are what make an unclaimed gift refundable and are included in an exported session.
Decode a pbgift:v1:... claim link into a preview. Synchronous and throwing — works fully offline, so it does not need withContext(Dispatchers.IO). Parameters:
  • link - A pbgift:v1:... claim link
Returns: GiftLinkPreview
giftFundSecretBearer(...) also exists but is experimental, disabled by default, and a bearer instrument (whoever holds the link can claim). See the concept page before considering it.

Gift Types

The gift fields are added to the existing TransferResult returned by the fund / claim / refund methods:

Portal

Portal deposit-address building blocks. Preview feature — pending external audit, enabled per deployment. Android exposes the low-level primitives only (no high-level portal resource); your app owns the EIP-7702 transaction orchestration. See the Portal Deposits guide for the lifecycle and the concept page for the trust model and launch limitations.

Instance Methods

publishPortalRegistry

Publish the private discovery registry entry so the indexer can credit deposits to the owner’s account. Suspend — call inside withContext(Dispatchers.IO). Parameters:
  • portal - The portal deposit address E

portalDelegateAddress

Returns the portal delegate address advertised by the server’s /info, or null if the server does not support portals.

Portal lifecycle

  • createPortal(index) — Derive portal E, gaslessly delegate and register it via the server relays, then publish the discovery entry. Pass null to use the next free derivation index.
  • listPortals() — List the authenticated account’s portals with status and derivation index.
  • listPortalDeposits(portal) — List deposits observed at a portal.
  • getPortalStatus(portal) — Return registry/on-chain status for one portal.
  • sweepPortal(portal, tokenId) — Send requestPortalDeposit from the connected wallet and return the transaction hash.
  • reclaimPortalDeposit(depositId) — Send cancelPortalDeposit from the connected wallet and return the transaction hash.
  • withdrawPortal(...) — Build a signed EIP-1559 transaction that withdraws raw funds resting at seed-derived portal E. Broadcast the returned raw transaction yourself.

Top-Level Functions

These package-level functions are low-level escape hatches for custodial integrations that manage their own portal EOA key. The seed-derived createPortal flow does not expose a private key.
  • generatePortalEoa() — Generate a fresh portal address E and its secret private key for custodial integrations.
  • encodePortalWithdraw(token, to, amount) — Encode PortalDelegate.withdraw calldata for a custodial integration that already controls E.

Portal Types

See Also