Skip to main content

ZkpClient — internals

High-level usage is documented on ZkpClient. This page lists internal services and architecture for tooling, debugging, or custom flows.

Architecture

ZkpClient is a thin composition root. It holds no business logic — it wires platform-specific backends into services and exposes a ClientContext that wallets consume internally.

ZkpClient (composition root)
├── SolverService ← ISolverBackend (WASM / native)
├── ProverService ← IProverBackend (WASM / native) + CircuitLoader
├── publicClient ← viem (chain reads)
├── RelayerClient ← optional HTTP relayer
└── tokens map ← currency → contract address

ClientContext

The internal interface passed to ZkpWallet. Not part of the public SDK API.

FieldTypeDescription
solverServiceSolverServiceSelf-initializing — ElGamal decrypt + discrete-log solve
proverServiceProverServiceSelf-initializing — circuit loading + proof generation
publicClientPublicClientviem client for chain reads
chainChainviem chain object
rpcUrlstringRPC endpoint
storageStorageAdapter?Persistent cache for history and balances
relayerAccessIRelayerAccesshasRelayer() / getRelayer()
tokensReadonlyMap<string, Address>Currency → token contract address
createWalletClient(account) => WalletClientFactory for viem write clients

Services

SolverService

Wraps an ISolverBackend. Self-initializing — calls ensureReady() on first decrypt.

  • decrypt(ct, sk) — ElGamal decrypt + discrete-log solve
  • ensureReady() — eagerly init the solver backend
  • destroy() — teardown

ProverService

Wraps an IProverBackend + CircuitLoader. Self-initializing — loads circuits on first proof generation.

  • generateTransferProof(witness) — concealed transfer proof
  • generateToPublicProof(params) — concealed → public proof
  • ensureReady() — eagerly load circuits
  • prewarm() — dummy proof to warm JIT
  • destroy() — teardown

Transaction decoding (standalone helpers)

FunctionDescription
decryptTransferFromTx(publicClient, solverService, txHash, sk, bpk)Incoming transfer amount
decryptOutgoingTransferFromTx(publicClient, solverService, txHash, sk, bpk)Outgoing transfer amount
getTransferParties(publicClient, txHash)Parse sender/recipient BPKs from calldata

Default backends (web / Node)

  • DlogSolverBackend — WASM discrete-log solver (ISolverBackend).
  • WasmProverBackend — Noir JS + bb.js (IProverBackend with prove).

Custom mobile/native stacks implement the interfaces in @zk-privacy/core/types and pass them in ZkpClientConfig.

Helpers

  • DEFAULT_CHAIN_CONFIG — per-chain token addresses, RPC, relayer URL presets.
  • resolveRecipient(to: Recipient) — normalize zk1 string or Point recipient.