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

# TypeScript private balances API reference

> Complete public API reference for @polygonlabs/oms-wallet-privacy, the OMS Wallet TypeScript private balances extension.

## Setup

### `privacy`

Adds `oms.privacy` to an `OMSWallet`:

```ts theme={null}
const oms = new OMSWallet({ publishableKey }).extend(privacy());
const quote = await oms.privacy.quoteShield({ network: Networks.polygon, token, amount });
await oms.privacy.shield(quote);
```

```typescript theme={null}
export declare function privacy(options?: PrivacyOptions): OMSWalletExtension<{
    readonly privacy: PrivacyActions;
}>;
```

### `PrivacyOptions`

Options for `privacy()`.

```typescript theme={null}
export interface PrivacyOptions {
    storage?: StorageManager;
}
```

### `PrivacyActions.networks`

Networks with private balances.

```typescript theme={null}
readonly networks: ReadonlyArray<Network>;
```

## Balances

### `PrivacyActions.getBalances`

Private balances of the active wallet with a non-zero amount.

```typescript theme={null}
getBalances(params?: GetPrivateBalancesParams): Promise<PrivateBalance[]>;
```

### `GetPrivateBalancesParams`

```typescript theme={null}
export interface GetPrivateBalancesParams {
    networks?: ReadonlyArray<Network>;
}
```

### `PrivateBalance`

A token in a private balance. The native token is `0x0000000000000000000000000000000000000000`.

```typescript theme={null}
export interface PrivateBalance {
    readonly network: Network;
    readonly token: Address;
    readonly amount: bigint;
    readonly recoverable: bigint;
}
```

## Quotes

### `PrivacyActions.quoteShield`

Quotes moving tokens from the wallet into its private balance; `shield` runs it.

```typescript theme={null}
quoteShield(params: QuoteShieldParams): Promise<PrivacyQuote<"shield">>;
```

### `PrivacyActions.quoteUnshield`

Quotes moving tokens from the private balance to an address; `unshield` runs it.

```typescript theme={null}
quoteUnshield(params: QuoteUnshieldParams): Promise<PrivacyQuote<"unshield">>;
```

### `PrivacyActions.quotePrivateSend`

Quotes sending tokens from the wallet to an address without an on-chain link between the two;
`privateSend` runs it.

```typescript theme={null}
quotePrivateSend(params: QuotePrivateSendParams): Promise<PrivacyQuote<"privateSend">>;
```

### `QuoteShieldParams`

```typescript theme={null}
export interface QuoteShieldParams {
    network: Network;
    token: Address;
    amount: bigint;
}
```

### `QuoteUnshieldParams`

```typescript theme={null}
export interface QuoteUnshieldParams {
    network: Network;
    token: Address;
    amount: bigint;
    to?: Address;
}
```

### `QuotePrivateSendParams`

```typescript theme={null}
export interface QuotePrivateSendParams {
    network: Network;
    token: Address;
    amount: bigint;
    to: Address;
}
```

### `PrivacyQuote`

The terms of one shield, unshield or private send for the active wallet. Pass it to the matching
call before `expiresAt`; each quote can be used once. Quotes are frozen and only come from the
`quote*` calls.

```typescript theme={null}
export interface PrivacyQuote<K extends PrivacyQuoteKind = PrivacyQuoteKind> {
    readonly kind: K;
    readonly network: Network;
    readonly token: Address;
    readonly amount: bigint;
    readonly fee: bigint;
    readonly total: bigint;
    readonly to?: Address;
    readonly expiresAt: string;
}
```

### `PrivacyQuoteKind`

```typescript theme={null}
export type PrivacyQuoteKind = "shield" | "unshield" | "privateSend";
```

## Shield and private send

### `PrivacyActions.shield`

```typescript theme={null}
shield(quote: PrivacyQuote<"shield">, options?: DepositOptions): Promise<ShieldResult>;
```

### `PrivacyActions.privateSend`

```typescript theme={null}
privateSend(quote: PrivacyQuote<"privateSend">, options?: PrivateSendOptions): Promise<PrivateSendResult>;
```

### `DepositOptions`

```typescript theme={null}
export interface DepositOptions {
    selectFeeOption?: FeeOptionSelector;
    maxNetworkFee?: bigint;
    onProgress?: (event: PrivacyProgressEvent) => void | Promise<void>;
}
```

### `PrivateSendOptions`

```typescript theme={null}
export interface PrivateSendOptions extends DepositOptions {
    waitForDelivery?: boolean;
    deliveryPolling?: DeliveryPollingOptions;
}
```

### `DeliveryPollingOptions`

```typescript theme={null}
export interface DeliveryPollingOptions {
    timeoutMs?: number;
    intervalMs?: number;
}
```

### `PrivacyProgressEvent`

```typescript theme={null}
export type PrivacyProgressEvent = {
    readonly step: PrivacyTransactionStep;
    readonly state: "prepared" | "confirmed";
    readonly txnId: string;
    readonly txnHash?: Hex;
    readonly networkFee?: NetworkFee;
} | {
    readonly step: "delivery";
    readonly state: "pending" | "delivered";
    readonly deliveryId: string;
    readonly txnHash?: Hex;
};
```

### `PrivacyTransactionStep`

A wallet transaction step. Steps that are not needed are skipped.

```typescript theme={null}
export type PrivacyTransactionStep = "reset-approval" | "approve" | "deposit";
```

### `PrivacyTransaction`

```typescript theme={null}
export interface PrivacyTransaction {
    readonly step: PrivacyTransactionStep;
    readonly response: SendTransactionResponse;
    readonly networkFee?: NetworkFee;
}
```

### `NetworkFee`

A network fee paid for one wallet transaction.

```typescript theme={null}
export interface NetworkFee {
    readonly token: Address;
    readonly amount: bigint;
}
```

### `ShieldResult`

```typescript theme={null}
export interface ShieldResult {
    readonly transactions: ReadonlyArray<PrivacyTransaction>;
}
```

### `PrivateSendResult`

```typescript theme={null}
export interface PrivateSendResult {
    readonly transactions: ReadonlyArray<PrivacyTransaction>;
    readonly deliveryId: string;
    readonly delivery?: DeliveryStatus;
}
```

## Unshield, delivery and recovery

### `PrivacyActions.unshield`

Sends no wallet transaction: the privacy service submits the withdrawal.

```typescript theme={null}
unshield(quote: PrivacyQuote<"unshield">): Promise<UnshieldResult>;
```

### `UnshieldResult`

```typescript theme={null}
export interface UnshieldResult {
    readonly txnHash: Hex;
}
```

### `PrivacyActions.getDeliveryStatus`

```typescript theme={null}
getDeliveryStatus(params: GetDeliveryStatusParams): Promise<DeliveryStatus>;
```

### `GetDeliveryStatusParams`

```typescript theme={null}
export interface GetDeliveryStatusParams {
    deliveryId: string;
}
```

### `DeliveryStatus`

```typescript theme={null}
export interface DeliveryStatus {
    readonly status: "pending" | "delivered" | "failed";
    readonly txnHash?: Hex;
}
```

### `PrivacyActions.recover`

Pays all recoverable funds of a token back to the active wallet.

```typescript theme={null}
recover(params: RecoverParams): Promise<RecoverResult>;
```

### `RecoverParams`

```typescript theme={null}
export interface RecoverParams {
    network: Network;
    token: Address;
}
```

### `RecoverResult`

```typescript theme={null}
export interface RecoverResult {
    readonly txnHashes: ReadonlyArray<Hex>;
}
```

## Errors

### `OMSWalletPrivacyError`

An error from `oms.privacy`. `txnIds` lists every wallet transaction the operation had created
when it failed, so for `shield` and `privateSend` an app can tell "no wallet transaction was sent"
(empty) from "a deposit may have been sent" and reconcile with `wallet.getTransactionStatus` and
`oms.privacy.getBalances`. `unshield` and `recover` send no wallet transaction, so their `txnIds`
is always empty; the message says whether the withdrawal may have been submitted.
`cause` is only set to an `OMSWalletError` from the wallet.

```typescript theme={null}
export declare class OMSWalletPrivacyError extends Error {
    readonly code: OMSWalletPrivacyErrorCode;
    readonly operation: string;
    readonly stage?: OMSWalletPrivacyStage;
    readonly txnIds: ReadonlyArray<string>;
    readonly txnHash?: Hex;
    readonly deliveryId?: string;
    constructor(params: OMSWalletPrivacyErrorParams);
}
```

### `isOMSWalletPrivacyError`

```typescript theme={null}
export declare function isOMSWalletPrivacyError(error: unknown): error is OMSWalletPrivacyError;
```

### `OMSWalletPrivacyErrorCode`

```typescript theme={null}
export type OMSWalletPrivacyErrorCode = "OMS_PRIVACY_UNSUPPORTED_NETWORK" | "OMS_PRIVACY_INVALID_PARAMS" | "OMS_PRIVACY_QUOTE_INVALID" | "OMS_PRIVACY_NO_WALLET" | "OMS_PRIVACY_WALLET_CHANGED" | "OMS_PRIVACY_WALLET_ERROR" | "OMS_PRIVACY_INSUFFICIENT_BALANCE" | "OMS_PRIVACY_NOTHING_TO_RECOVER" | "OMS_PRIVACY_NETWORK_FEE" | "OMS_PRIVACY_UNAUTHORIZED_TRANSACTION" | "OMS_PRIVACY_TRANSACTION_FAILED" | "OMS_PRIVACY_DELIVERY_FAILED" | "OMS_PRIVACY_DELIVERY_TIMEOUT" | "OMS_PRIVACY_KEY_MISMATCH" | "OMS_PRIVACY_SERVICE_ERROR";
```

### `OMSWalletPrivacyErrorParams`

```typescript theme={null}
export interface OMSWalletPrivacyErrorParams {
    code: OMSWalletPrivacyErrorCode;
    message: string;
    operation: string;
    stage?: OMSWalletPrivacyStage;
    txnIds?: ReadonlyArray<string>;
    txnHash?: Hex;
    deliveryId?: string;
    cause?: unknown;
}
```

### `OMSWalletPrivacyStage`

Which part of an operation had run when it failed.

```typescript theme={null}
export type OMSWalletPrivacyStage = "setup" | "quote" | PrivacyTransactionStep | "withdraw" | "delivery";
```
