> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privacyboost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Auditor Queries

> Authorized auditors querying account history and balances on a Privacy Boost deployment

# Auditor Queries

Transaction details in Privacy Boost are encrypted, and only the participating
wallets can read them. Some deployments need an authorized party, such as a
compliance officer or a regulator, to inspect specific accounts without
breaking that privacy for everyone else. The audit API does this. Each query is
signed by the auditor's key and scoped to one account. The server then logs it
on-chain in the background; that log is best-effort and not retried.

End users don't need this API, and its endpoints reject requests without the
operator's admin key. For the product overview, see
[Auditability](https://docs.privacyboost.io/product/auditability.md).

## Prerequisites

| Requirement | What it is |
| - | - |
| AuditGateway address | the contract that holds the auditor registry, deployed by the operator |
| Server admin key (`X-Admin-Key`) | a deployment-level secret held by the operator and shared out-of-band with auditors |
| Auditor private key | the EOA registered in the AuditGateway via `addAuditor(address)` |

If your deployment exposes the AuditGateway address through `/api/v1/info`, the
SDK auto-discovers it. Otherwise, pass it explicitly to each call.

## TypeScript

```ts theme={null}
import { PrivacyBoost } from '@sunnyside-io/privacy-boost';

const sdk = await PrivacyBoost.create({
  serverUrl: 'https://indexer.example.com',
  appId: 'audit-tool',
});

// Sign in with the auditor's wallet; it signs each audit query.
await sdk.auth.signIn(walletAdapter);

// Run a signed transactions query.
const txs = await sdk.audit.queryTransactions({
  adminKey: process.env.PRIVACY_BOOST_ADMIN_KEY!,
  // auditGatewayAddress is optional — auto-discovered from /api/v1/info.
  target: { accountId: '12345' },
  txType: 'transfer',
  createdFrom: 1_700_000_000,
  createdTo: 1_700_086_400,
  limit: 50,
});

console.log(txs.transactions);
```

`target` accepts either `{ accountId }` (decimal shielded-pool account ID) or
`{ eoaAddress }` (Ethereum address — the server resolves it to an account via
the auth-leaves table). Use whichever the auditor's frontend captured.

Filter fields are optional and can be combined:

| Field | Meaning |
| - | - |
| `txType` | `"shield" \| "unshield" \| "transfer" \| "forced_unshield"`; omitted = all |
| `tokenId` | Registered token id (uint16) |
| `createdFrom` / `createdTo` | Inclusive Unix-second window |
| `limit` / `offset` | Pagination (server clamps `limit` to ≤ 200) |

For balances:

```ts theme={null}
const balances = await sdk.audit.queryBalances({
  adminKey: process.env.PRIVACY_BOOST_ADMIN_KEY!,
  target: { eoaAddress: '0xabc...' },
});
```

## CLI

```bash theme={null}
# The auditor's key comes from PRIVATE_KEY; `audit` does not prompt for one.
export PRIVATE_KEY=$AUDITOR_PK

privacy-boost \
  --server-url https://indexer.example.com \
  --admin-key $PRIVACY_BOOST_ADMIN_KEY \
  audit transactions --account-id 12345 --tx-type transfer --limit 50
```

Flags map 1:1 to the TypeScript options. `--audit-gateway` is optional when the
server advertises it via `/api/v1/info`; otherwise pass it explicitly.

Output formats:

```bash theme={null}
# Human-friendly text (default)
privacy-boost ... audit balances --eoa 0xabc...

# JSON for piping into jq / scripts
privacy-boost --output json ... audit balances --eoa 0xabc...
```

## React Native, iOS, Android

Call `auditQueryTransactions()` and `auditQueryBalances()` on `PrivacyBoost`.
They take the same fields as the TypeScript options and sign with the current
wallet delegate.

## Errors you should handle explicitly

| Code / message | Cause | Recovery |
| - | - | - |
| `401 invalid admin key` | Wrong / stale `X-Admin-Key` | Re-fetch from the operator |
| `403 NOT_REGISTERED_AUDITOR` | Wallet address isn't in the AuditGateway registry | Operator registers the address via `cast send $AUDIT_GATEWAY "addAuditor(address)" $AUDITOR` |
| `403 AUDITOR_SIGNATURE_MISMATCH` | The wallet signed but the recovered signer ≠ claimed auditor | Wrong wallet adapter is connected |
| `404 EOA_NOT_FOUND` | Looked up an EOA that has no shielded account | Try `accountId` instead |
| `audit_gateway_address required` | Server's `/api/v1/info` doesn't advertise it | Pass `auditGatewayAddress` explicitly, or fix server config |

## What auditors can and can't do

| Can | Cannot |
| - | - |
| Query a named account, then query others with additional signatures | Bypass the admin key or auditor registration |
| Read a specific account's token balances | Decrypt note ciphertexts (no view-key delegation) |
| Filter by token, type, time window | Obtain spending keys through the audit API |
| Confirm their own access via `audit me` | Modify any pool state |

A confirmed `AuditLogCreated` event records the auditor, target, action,
metadata, and block timestamp. The API returns data without waiting for log
submission or confirmation. Operators must monitor logging failures and apply
any per-account disclosure policy outside the current contract.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.