> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/concepts/permit-model.md).

# Permit model

How EIP-712 signed permits authorize FHE decryption for specific contracts.

Decrypting an on-chain FHE ciphertext requires two things: a transport key pair (generated once, stored persistently — see [Security Model](https://docs.zama.org/protocol/sdk/concepts/security-model.md#credential-storage)) and a **signed permit** that authorizes decryption for specific contract addresses. This page explains how permits work.

## What is a permit

A permit is an EIP-712 typed data signature from the user's wallet. It binds:

* A set of **contract addresses** (up to 10 per permit).
* A **chain ID**.
* A **start timestamp** and **duration** (derived from `permitTTL`).
* The **signer address**.
* An optional **delegator address** (for delegated decryption).

The relayer verifies this signature before re-encrypting any ciphertext. Without a valid permit covering the target contract, the relayer rejects the request.

## Key properties

* **Immutable** — the signed contract addresses are part of the EIP-712 payload and cannot be edited after signing.
* **Chunked** — each permit covers at most 10 contracts. When more are needed, the SDK chunks the addresses and requests one wallet signature per chunk.
* **Chain-scoped** — stored under `(signerAddress, chainId, delegatorAddress)`, so permits on Sepolia never collide with permits on Mainnet, and direct permits never collide with delegated ones.
* **Additive** — calling `permits.grantPermit()` with new contracts signs additional permits for the uncovered subset only. Existing permits remain valid and are not re-signed.
* **Time-bounded** — each permit records its creation timestamp and duration. Expired permits are pruned on next access.

## Lifecycle

### First visit

1. User connects wallet.
2. App calls `permits.grantPermit([contractA, contractB])`.
3. SDK checks storage — no permits cover these contracts yet.
4. SDK builds EIP-712 typed data (contract addresses, timestamp, duration) and requests a wallet signature.
5. Wallet signs → permit is stored (keyed by signer address, chain ID, and delegator).
6. Ready — subsequent decrypts reuse the stored permit silently.

### Returning visit

1. Page loads → SDK reads permits from storage.
2. Permits cover the requested contracts and haven't expired.
3. Ready — no wallet popup.

### New contract coverage

1. Decrypt request arrives for a contract not covered by existing permits.
2. SDK signs a new permit for the uncovered contracts only.
3. New permit is appended alongside existing ones — nothing is invalidated.

### Expiration

1. A permit's duration elapses (default: 30 days, configurable via `permitTTL`).
2. Permit is pruned from storage on next access.
3. The next decrypt for that contract set prompts a single wallet re-sign.
4. The transport key pair is not affected.

{% hint style="info" %}
Each permit records its start timestamp and duration at creation time. Changing `permitTTL` between sessions does not retroactively alter existing permits — they use their original duration.
{% endhint %}

## How additive permits work

Unlike a session model where re-authorizing replaces the previous authorization, permits are purely additive:

```ts
// Signs permits for all three contracts
await sdk.permits.grantPermit(["0xContractA", "0xContractB", "0xContractC"]);

// ContractA is already covered — only ContractD triggers a new signature
await sdk.permits.grantPermit(["0xContractA", "0xContractD"]);
```

This means users see fewer wallet popups over time. As they interact with more contracts, their permit coverage grows without invalidating earlier permits.

{% hint style="info" %}
Batch all contract addresses you expect to need into a single `permits.grantPermit()` call to minimize wallet popups. Each uncovered chunk of up to 10 contracts triggers one signature prompt.
{% endhint %}

## Revocation

Permits can be removed in two ways:

* **Selective** — `sdk.permits.revokePermits(["0xTokenA"])` removes permits touching those contracts on the current chain. Other permits are untouched.
* **Full wipe** — `sdk.permits.revokePermits()` removes all permits for the current signer across all chains and delegators. The transport key pair is not affected.

For a complete "log out" that also removes the transport key pair, use `sdk.permits.clear()`. See the [ZamaSDK reference](https://docs.zama.org/protocol/sdk/api-references/sdk/zamasdk.md#permits-revokepermits) for the full API.

### Two revocation tiers with a shared scope

Both `revokePermits()` and `clear()` are **signer-level**: they only ever act on the calling signer's own permits (and, for `clear()`, that signer's own key-pair slot). This holds even when `transportKeyPairScope` is configured — an end-user disconnecting never invalidates other signers sharing the scope's key pair, because the shared key pair was never stored under any individual signer's slot to begin with.

Invalidating the *shared* key pair is a separate, operator-level operation: `sdk.permits.revokeTransportKeyPair(scopeId)`. It deletes the scope's key pair — no permit needs to be touched directly, and no wallet needs to be connected. `hasPermit`/`grantPermit` then treat every permit in the scope as stale on next access, though not via one single mechanism: immediately after the revoke, `hasPermit()` returns `false` because there's no stored key pair left to compare against; once some later caller regenerates a key for the scope, it's the newly-mismatched embedded public key that `pruneUnusable` then filters existing permits on. Same end-user-visible outcome either way. Unlike other credential-store writes, this call is not best-effort: a storage failure rejects rather than being logged and swallowed, since a resolved promise here is expected to mean the key pair is actually gone — the primitive an operator reaches for on suspected compromise. This only stops the SDK from reissuing or reusing the key going forward; it does not revoke any permit already issued under it, which stays independently valid until its own `permitTTL` expiry — see [Security Model](https://docs.zama.org/protocol/sdk/concepts/security-model.md#shared-tenant-scope-b2b2c-waas-operators) for the full explanation and when a shared scope makes sense.

Each client exposes the same four calls:

{% tabs %}
{% tab title="Core SDK" %}

```ts
await sdk.permits.revokePermits(["0xTokenA"]); // selective
await sdk.permits.revokePermits(); // full wipe
await sdk.permits.clear(); // log out
await sdk.permits.revokeTransportKeyPair("tenant-123"); // shared scope
```

{% endtab %}

{% tab title="Go" %}

```go
err := sdk.RevokePermits(ctx, []common.Address{tokenA}) // selective
err = sdk.RevokePermits(ctx, nil)                       // full wipe
err = sdk.ClearPermits(ctx)                             // log out
err = sdk.RevokeTransportKeyPair(ctx, "tenant-123")     // shared scope
```

{% endtab %}

{% tab title="Rust" %}

```rust
let permits = sdk.permits();
permits.revoke_permits(Some(&[token_a])).await?; // selective
permits.revoke_permits(None).await?; // full wipe
permits.clear().await?; // log out
permits.revoke_transport_key_pair("tenant-123").await?; // shared scope
```

{% endtab %}
{% endtabs %}

## Wallet account changes

By default, the SDK clears the previous account's credentials when the wallet state changes:

| Event                 | Effect on permits                                                                                                                          |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| **Disconnect / lock** | All permits, the transport key pair, and the decrypt cache are cleared for the previous account                                            |
| **Account switch**    | Previous account's permits, transport key pair, and decrypt cache are cleared; the new account starts fresh                                |
| **Chain switch**      | Permits and the transport key pair are kept; permits are chain-scoped, so each chain keeps its own. The account's decrypt cache is cleared |

Set `clearCredentialsOnWalletChange: false` on `createConfig` to keep them instead. Permits and transport key pairs are stored per signer address, so one account can never read another's entries, and a permit is an EIP-712 signature the relayer only accepts from the address that signed it. Keeping them lets a multi-wallet user switch A → B → A without signing a new permit, and stops wallets that emit an empty account list on auto-lock (Rabby, Brave) from wiping credentials on every lock. Permits still expire on their own after `permitTTL` and transport key pairs after `transportKeyPairTTL`.

With the option off, handle sign-out yourself: call `sdk.permits.clear()` (or [`useClearCredentials`](https://docs.zama.org/protocol/sdk/api-references/react/useclearcredentials.md) in React) to remove the connected signer's transport key pair, permits, and decrypt cache. It needs a connected wallet account, so call it before the wallet disconnects. Once the wallet is gone, the SDK can no longer tell which account to clear.

See [ZamaSDK.onWalletAccountChange](https://docs.zama.org/protocol/sdk/api-references/sdk/zamasdk.md#onwalletaccountchange) for programmatic access to these transitions.

## Offline permits

The lifecycle above assumes a connected wallet signs `grantPermit`'s EIP-712 message in-process. Custody partners — HSMs, policy engines, out-of-process signers — cannot do that: `sdk.offline.preparePermit` builds the same EIP-712 typed data without signing it, and `sdk.permits.registerPermit` verifies and persists the signature once the custodian returns it. See the [Offline signing guide](https://docs.zama.org/protocol/sdk/guides/offline.md#offline-permits) for the workflow.

## Related

* [Security Model](https://docs.zama.org/protocol/sdk/concepts/security-model.md) — transport key pair storage, threat model, and trust assumptions
* [Configuration](https://docs.zama.org/protocol/sdk/guides/configuration.md#5-optional-configure-ttls-credential-cleanup-and-event-listener) — `transportKeyPairTTL` and `permitTTL` settings
* [ZamaSDK](https://docs.zama.org/protocol/sdk/api-references/sdk/zamasdk.md) — `permits.grantPermit()`, `permits.revokePermits()`, `permits.clear()` API


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/protocol/sdk/concepts/permit-model.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
