Skip to main content

API Reference

Complete API reference for the Privacy Boost CLI library (Rust).

Generated Documentation

Full API documentation can be generated using cargo doc:

PrivacyBoostCLI

Main CLI SDK interface for Rust applications.

Constructor

Creates a new CLI SDK instance. Parameters:
  • config - CLI configuration
Returns: Result<PrivacyBoostCLI, CliError> Example:

Connection & Authentication Methods

authenticate

Connect wallet using a private key, derive privacy keys, and authenticate with the Privacy Boost backend in a single call. Parameters:
  • private_key - Hex-encoded private key
  • key_source - Optional key derivation source. None defaults to WalletDerived. Options: KeySource::WalletDerived, KeySource::Mnemonic { phrase }, KeySource::RawSeed { hex_seed }
  • token_provider - Optional custom token provider for server-mediated auth flows
Returns: Result<AuthResult, CliError> - either Authenticated(LoginResult) or CredentialRequired(CredentialChallenge)

submit_credential

Submit a credential when authenticate() returns CredentialRequired. Returns: Result<LoginResult, CliError>

logout

End session completely, clear all state.

clear_session

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

is_authenticated

Check if authenticated.

State Accessors

Balance Methods

get_balance

Get balance for a specific token.

get_all_balances

Get all token balances.

Vault Operations

deposit

Deposit tokens into the shielded pool. Parameters:
  • token_address - Token contract address
  • amount - Amount in wei (as string)

withdraw

Withdraw tokens from the shielded pool. Parameters:
  • token_address - Token contract address
  • amount - Amount in wei (as string)
  • recipient - Recipient Ethereum address

send

Send a private transfer. Parameters:
  • token_address - Token contract address
  • amount - Amount in wei (as string)
  • recipient_privacy_address - Recipient’s 194-char privacy address

send_batch

Send one private transfer paying several recipients: one request, one fee, one set of input notes. Parameters:
  • token_address - Token contract address
  • recipients - (recipient, amount) pairs in output order, at least one. Amounts are wei strings
Shape limits: the transfer’s output count is the recipient count plus a change note, and the server only proves specific (inputs, outputs) combinations, so a longer recipient list limits how many input notes can be spent — past two recipients, at most four. Requests no enabled circuit can serve fail with UNSUPPORTED_TRANSFER_SHAPE before submission.

prepare_shield

Build a deposit payload without submitting it — for relaying the transaction yourself (a gasless relayer, an EIP-7702 session key, or a plain raw transaction). Returns the wrap/approve/requestDeposit calldata plus the note commitment; nothing is sent on-chain. Needs an authenticated session (keys) but no wallet. After relaying, settle from the mined receipt with privacy_boost_core::operations::finalize_shield. Parameters:
  • token_address - Token contract address (use 0x0 for ETH)
  • amount - Amount in wei (as string)
  • recipient - Recipient privacy address; None shields to yourself
CLI subcommands prepare-shield and finalize-shield wrap these for shell use — see the Commands Reference.

list_shields_by_status

Find a deposit request id the app never kept. Lists the authenticated wallet’s own shield requests in the given public statuses (pending, processing, preconfirmed, completed, failed), oldest first; an empty slice asks the server for its default of pending. Served by the server, so it needs no chain access. Returns: UnsettledShieldResponse per row — request_id, status, and the optional tx_hash, block_number, created_at, updated_at and error.

deposit_request_ids_from_transaction

The fallback when the app has the shield’s transaction hash but not its request id. Reads the receipt and returns every DepositRequested id the pool emitted, in log order — more than one when an aggregating relayer settled several callers in one transaction. Empty means the transaction emitted no DepositRequested from the configured pool.
CLI subcommands deposit list and deposit ids wrap these for shell use. See the Commands Reference.

get_deposit_cancellation

Report whether a stuck shield deposit can be cancelled right now. A shield whose deposit never settles into the note tree leaves the tokens escrowed in the pool. get_shield_status will tell you the shield failed, but nothing server-side describes the escrow behind it — whether the pool still holds it, who may reclaim it, and when — so this reads the pool directly through the connected wallet. Costs three eth_calls plus one eth_blockNumber. Parameters:
  • deposit_request_id - The DepositRequested event’s indexed topic1, a uint256. It’s the same request id a shield reports. Decimal or 0x-hex; the result normalizes it to decimal.
Returns: DepositCancellation with the escrowed amount, the block the delay expires at, and a reason you can print as-is

cancel_deposit

Cancel a stuck shield deposit, refunding its full escrowed amount to the depositor. Returns the transaction hash. Preflights the same checks as get_deposit_cancellation and fails locally, before anything is signed, when the pool would revert. The error carries the status reason, so a deposit that can’t be cancelled reports why instead of burning gas on an opaque revert. If the wallet can’t run the preflight, the transaction is submitted anyway and the chain arbitrates. Only the address that submitted the deposit can cancel it, and the refund goes to that address. For a relayer-submitted shield that’s the relayer, not the note recipient.
CLI subcommands deposit status and deposit cancel wrap these for shell use. See the Commands Reference.

Transaction History

Get transaction history.

Session Persistence

export_session

Export session data for persistence.

import_session

Import session from persistence.

Address Lookup

resolve_identity

Look up a user’s privacy address by MPK or Ethereum address. Parameters:
  • identifier - MPK or Ethereum address
Returns: Result<IdentityResult, CliError>

Utilities


Module Functions

Returns the SDK version string.

CliConfig

CLI configuration struct.

Constructor

Builder Methods

File Operations

Environment


NetworkPreset

Network preset enumeration.

Methods

Parse aliases:
  • Local: "local", "localhost", "dev"
  • OpSepolia: "op-sepolia", "optimism-sepolia", "opsepolia"
Example:

Types

KeySource

Key derivation source, passed to authenticate(). WalletDerived derives keys from a wallet signature, Mnemonic from a BIP-39 phrase, and RawSeed from a raw 32-byte hex seed.

AuthResult

LoginResult

TokenBalance

ShieldResult

UnshieldResult

TransferResult

PreparedShield

Returned by prepare_shield. Re-exported from privacy_boost_core::operations. Carries no private material, so it is safe to hand to a relayer. Each Call is a single on-chain call to relay; value and data are 0x-hex.

DepositCancellation

Returned by get_deposit_cancellation. Re-exported from privacy_boost_core::operations. Amounts are decimal strings and blocks are absolute chain heights. DepositCancelState mirrors the reverts in the pool’s cancelDeposit, reported permanent-blocker first rather than in the pool’s own check order: the pool checks the depositor before anything else, and that check would mask the two conditions no caller can clear. A gateway-origin deposit stores the gateway contract as its depositor, so it reports GatewayOrigin for every caller and at every point in the delay window — waiting never makes it cancellable.
The cancel delay is measured in blocks and read from the pool’s cancelDelay(). Read the deployed value instead of hardcoding a delay, using cancel_delay, cancellable_at_block, and blocks_remaining from the status.

Transaction

StatusInfo

IdentityResult

ExportedSession

Re-exported from privacy_boost_core::sdk_state::ExportedSession:

CliError


Default Values


Complete Example

Gift & Portal Commands

Claimable transfers and portal deposit addresses are exposed as CLI subcommands:
  • Claimable Transfers — gift-fund-to-wallet, gift-fund, gift-list, gift-claim, gift-claim-from-link, gift-refund-by-record, gift-refund, gift-decode-link
  • Portal Deposits — portal create | list | status | deposits | sweep | reclaim | withdraw

See Also