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:
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.
Parameters: Example:

sdk.auth

Authentication resource.

auth.authenticate(adapter, options?)

Connect a wallet, derive privacy keys, and authenticate with the server in a single call.
Parameters: Returns: AuthResult - either { status: 'authenticated', privacyAddress, mpk } or { status: 'credentialRequired', action, unlockType, submit }. If credential is required, call result.submit(credential) to complete authentication.

auth.logout()

End session completely, clear all state.

auth.clearSession()

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

auth.isConnected()

Check if wallet is connected.

auth.isAuthenticated()

Check if user is authenticated.

auth.getPrivacyAddress()

Get user’s privacy address.

auth.getMpk()

Get user’s master public key.

sdk.vault

Vault resource for privacy operations.

vault.shield(params)

Deposit tokens to private balance.

vault.unshield(params)

Withdraw tokens to public address.

vault.send(params)

Send private transfer.

vault.prepareShield(params)

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 eth_sendRawTransaction). Returns the calldata to relay plus the note commitment; nothing is sent on-chain and no wallet is used. After relaying, call the top-level finalizeShield with the mined receipt to recover the on-chain request id. recipient shields to another privacy address; omit it to shield to yourself.

vault.getBalance(tokenAddress)

Get the cached balance entry for a token. Reads from the local store and may fetch from the server on a cache miss. To force a network refresh, call vault.refreshBalance(tokenAddress) first.

vault.getAllBalances()

Get all token balances.

vault.refreshBalance(tokenAddress)

Refresh a single token balance from the server.

vault.refreshBalances()

Refresh all tracked balances from the server.

vault.getToken(address)

Get token metadata for a single token.

vault.getTokens()

Get metadata for every token registered with the protocol.

parseAmount(amount, decimals)

Parse a human-readable amount to a bigint. Exported as a standalone utility from the SDK package.

formatAmount(amount, decimals)

Format a bigint amount as a human-readable string. Exported as a standalone utility from the SDK package.

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. Imported from the package root.

buildShieldPayload(params)

Build 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.

finalizeShield(params)

Recover the on-chain shield request id from the mined receipt of a relayed deposit (see vault.prepareShield). Stateless — the caller obtained the receipt from its own relay/RPC, so no signed-in session is needed. Throws if the deposit reverted or the DepositRequested log is absent.

sdk.transactions

Transactions resource.

transactions.fetchHistory(params?)

Get transaction history.

sdk.campaigns

Campaign mission progress for the authenticated user. Every method here reports on the session’s own user. These routes accept no user identifier — the server derives the user from the JWT — so there is no way to ask this resource about somebody else.

campaigns.getStartaleProgress()

Get lifetime Startale mission progress. Requires the full auth tier, which the vault reaches after auth.authenticate() completes.
hasDepositedAtLeast10Usd is priced at query time against the server’s current indexed token prices, so it is not monotonic: a deposit worth $10.50 in a volatile token can report true today and false after a price drop. If you award something on it, record the first true and never downgrade. campaignTokenId tells you what that total covers. When the server is configured with a campaign token, only deposits of that token count, and this reports the registry token ID they were counted under. When it is absent, the server has no campaign token configured and values every token the user shielded, summed, so two sub-threshold deposits in different tokens can complete the mission. Read it rather than hardcoding a token if your UI names the one to deposit, since the server decides what it judged the user against and an operator can change it without a client release. It is the same registry token ID buildShieldPayload and portal.sweep take, so resolve it to an address or symbol through the token catalog the way you resolve those. hasMadeTransfer counts private transfers with a positive amount to a non-self recipient. Consolidations, unshields, self/change outputs, and failed or reorged requests do not count. It stays token-agnostic even when the deposit mission is scoped. The call rejects rather than defaulting a field to false, so a truncated response cannot read as “mission incomplete”. A campaignTokenId that is present but not a valid registry ID is rejected for the same reason: dropping it would report a single-token total as an all-token one. The server answers 503 when a shield token price is unavailable, or when a configured campaign token resolves to no registered price; treat that as unknown, not as “not eligible”. Progress is scoped to the chain the server is deployed for. In a multi-chain setup, read it from the ChainClient for the chain you care about rather than from the root SDK.

sdk.portal

Hidden-recipient portal deposit addresses. Preview feature — pending external audit.

portal.create(opts?)

Derive a portal address E, delegate it, register the owner binding, and publish the discovery entry — in one call.

portal.list()

portal.deposits(address)

portal.status(address)

Launch limitation: delegated always reports false.

portal.sweep(address, tokenId)

Self-service sweep backstop (operator-run at launch). Returns the tx hash.

portal.reclaim(depositId)

Reclaim an un-credited deposit after the cancel delay; funds return to E. Returns the tx hash.

portal.withdraw(params)

Build a signed raw EIP-1559 tx that withdraws funds resting at E (escape hatch). Broadcast it yourself.

portal.delegateAddress()

The portal delegate address from /info, or undefined if unsupported.
See the portal guide for the Portal, PortalInfo, PortalStatus, PortalDeposit, PortalDepositState, CreatePortalOptions, and WithdrawPortalParams types.

Gift Methods (sdk.wasm)

Claimable transfers. Preview feature — exposed on the underlying WASM SDK via sdk.wasm. Each fund/claim/refund returns a TransferResult (extended with optional giftRecord and claimLink). giftFundSecretBearer(params) also exists but is experimental, disabled by default, and a bearer instrument — see the concept page. Full parameter shapes and the GiftRecord / PendingGift / GiftLinkPreview types are in the gift guide.

Utility Functions

isValidPrivacyAddress(address)

Check if address is valid privacy address.

validatePrivacyAddress(address)

Validate a privacy address.

encodePrivacyAddress(mpk, viewingPublicKey)

Encode MPK and viewing public key to privacy address.

decodePrivacyAddress(address)

Decode privacy address to components.

extractMpkFromPrivacyAddress(address)

Extract MPK from privacy address.

isEvmAddress(address)

Check if valid EVM address.

isNativeEth(address)

Check if address represents native ETH.

Types

KeySource

Key derivation source, passed to authenticate().

Hex

PrivacyAddress

The payload encodes the master public key (32 bytes) and the viewing public key X/Y (32 bytes each). Hex-encoded, that is 192 characters; including the 0x prefix the string is 194 characters.

WalletAdapter

OnProgress

FeeRates

Fee schedule applied to vault operations.
Schema-v1 responses omit the optional fields and mean transfer=flat, unshield=bps. In schema v2, each operation selects its own mode. BPS uses floor(base * bps / 10000): the unshield base is the public exit amount, while the transfer base is only volume sent to external recipients. A pure self-transfer therefore has zero transfer BPS fee. Pass externalVolume (or isSelfTransfer) when the transfer amount is not entirely external.

Fee math

The fee functions are plain exports, so code that cannot use a React hook — max-amount clamping before a send, CLI tooling, tests — derives the same number the UI shows. useFees() is a reactive wrapper around them.
calculateFee and formatFeeRate validate the half of the payload they read before using it, so they never derive a fee from a rate the SDK would reject. Both throw FEE_SCHEMA_UPGRADE_REQUIRED when the operation needs a newer schema than this SDK supports, and INVALID_INPUT for an unknown fee mode or a malformed or out-of-range rate. sdk.vault.getFees() already screens its response, so an explicit validateFeeRates call is only needed for rates that arrive some other way. The React hook’s calculateFee returns bigint | null, yielding null while rates are unavailable (first fetch in flight, or the last one failed) so an unknown fee never looks like a zero fee. When feeModel is 'app_pays', the fee is settled out of band by the application — users see the gross amount. Shield fee schedules are available from vault.getFees(); the shield response does not currently surface the actual charged fee.

ComplianceStatus


Constants