Skip to content

Commit a89b675

Browse files
authored
docs(common): add wallet integration guide for partners (#1382)
* docs: Initialise wallet guide * docs(example): Initialise wallet guide * docs: Add images to guide * docs(example): Add images to guide * docs: Add wallet guide to menu list * docs(example): Add wallet guide to menu list * docs(example): Initialise wallet guide * docs(example): Add images to guide * docs(example): Add wallet guide to menu list * docs(common): fix issue with re-encrypt terminology
1 parent 70a45d8 commit a89b675

File tree

6 files changed

+103
-0
lines changed

6 files changed

+103
-0
lines changed
193 KB
Loading
660 KB
Loading
199 KB
Loading
203 KB
Loading

docs/examples/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
- [Swap ERC7984 to ERC20](openzeppelin/swapERC7984ToERC20.md)
2323
- [Swap ERC7984 to ERC7984](openzeppelin/swapERC7984ToERC7984.md)
2424
- [Vesting Wallet](openzeppelin/vesting-wallet.md)
25+
- [Integration guide for wallets](./wallet-guide.md)

docs/examples/wallet-guide.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Confidential token integration guide for Wallets
2+
3+
This guide is for wallet and dApp developers who want to support confidential tokens on Zama Protocol. It focuses on ERC-7984 wallet flows: showing balances (user decryption) and sending transfers (encrypted inputs). For deeper SDK details, follow the [Relayer SDK guide](https://docs.zama.org/protocol/relayer-sdk-guides/).
4+
5+
By the end of this guide, you will be able to:
6+
7+
- Understand [Zama Protocol](../protocol/architecture/overview.md) at a high-level.
8+
- Build ERC-7984 confidential token transfers using encrypted inputs.
9+
- Display ERC-7984 confidential token balances.
10+
11+
## **Core concepts in this guide**
12+
13+
While building support for ERC-7984 confidential tokens in your wallet/app, you might come across the following terminology related to [various parts of the Zama Protocol](../protocol/architecture/overview.md). A brief explanation of common terms you might encounter are:
14+
15+
- **FHEVM**: Zama’s [FHEVM library](../protocol/architecture/library.md) that supports computations on encrypted values. Encrypted values are represented on‑chain as **ciphertext handles** (bytes32).
16+
- **Host chain**: The EVM network your users connect to in a wallet with confidential smart contracts. Example: Ethereum / Ethereum Sepolia.
17+
- **Gateway chain**: Zama’s Arbitrum L3 [Gateway chain](../protocol/architecture/gateway.md) that coordinates FHE encryptions/decryptions.
18+
- **Relayer**: Off‑chain [Relayer](../protocol/architecture/relayer_oracle.md) that registers encrypted inputs, coordinate decryptions, and return results to users or contracts. Wallets and dApps talk to the Relayer via the JavaScript SDK.
19+
- **ACL:** Access control for ciphertext handles. Contracts grant per‑address permissions so a user can read data they should have access to.
20+
21+
## Wallet integration at a glance
22+
23+
At a high-level, to integrate Zama Protocol into a wallet, you do **not** need to run FHE infrastructure. You can interact with the Zama Protocol using [Relayer SDK](https://docs.zama.org/protocol/relayer-sdk-guides) in your wallet or app. These are the steps at a high-level:
24+
25+
1. **Relayer SDK initialisation** in web app, browser extension, or mobile app. Follow the [setup guide for Relayer SDK](https://docs.zama.org/protocol/relayer-sdk-guides/development-guide/webapp). In browser contexts, importing the library via the CDN links is easiest. Alternatively, do this by importing the `@zama-fhe/relayer-sdk` NPM package.
26+
2. [Configure and initialise settings](https://docs.zama.org/protocol/relayer-sdk-guides/fhevm-relayer/initialization) for the library.
27+
3. **Confidential token (ERC-7984) basics**:
28+
- Show encrypted balances using **user decryption**.
29+
- Build **transfers** using encrypted inputs. Refer to [OpenZeppelin’s ERC-7984 token guide](https://docs.openzeppelin.com/confidential-contracts/token).
30+
- Manage **operators** for delegated transfers with an expiry, including clear revoke UX.
31+
32+
### **What wallets should support**
33+
34+
- **Transfers**: Support the ERC-7984 transfer variants documented by OpenZeppelin, including forms that use an input proof and optional receiver callbacks.
35+
- **Operators**: Operators can move any amount during an active window. Your UX must capture an expiry, show risk clearly, and make revoke easy.
36+
- **Events and metadata**: Names and symbols behave like conventional tokens, but on-chain amounts remain encrypted. Render user-specific amounts after user decryption.
37+
38+
## Quick start: ERC-7984 example app
39+
40+
To see these concepts in action, check out the [ERC-7984 demo](https://github.com/zama-ai/dapps/tree/main/packages/erc7984example) from the [zama-ai/dapps](https://github.com/zama-ai/dapps) Github repository.
41+
42+
The demo shows how a frontend or wallet app:
43+
44+
1. [**Register encrypted inputs**](https://docs.zama.org/protocol/relayer-sdk-guides/fhevm-relayer/input) for contract calls such as confidential token transfers.
45+
2. Request [**User decryption**](https://docs.zama.org/protocol/relayer-sdk-guides/fhevm-relayer/decryption/user-decryption) so users can view private data like balances.
46+
47+
### Run locally
48+
49+
1. Clone the [zama-ai/dapps](https://github.com/zama-ai/dapps) Github repository
50+
2. Install dependencies and deploy a local Hardhat chain
51+
52+
```bash
53+
pnpm install
54+
pnpm chain
55+
pnpm deploy:localhost
56+
```
57+
58+
1. Navigate to the [ERC-7984 demo](https://github.com/zama-ai/dapps/tree/main/packages/erc7984example) folder in the cloned repo
59+
60+
```bash
61+
cd packages/erc7984example
62+
```
63+
64+
1. Run the demo application on local Hardhat chain
65+
66+
```bash
67+
pnpm run start
68+
```
69+
70+
### Steps demonstrated by the ERC-7984 demo app
71+
72+
**Step 1**: On initially logging in and connect a wallet, a user’s confidential token balances are not yet visible/decrypted.
73+
74+
![Connect wallet to demo app](../.gitbook/assets/wallet-guide-1.png)
75+
76+
**Step 2**: User can now sign and fetch their decrypted ERC-7984 confidential token balance. Balances are stored as ciphertext handles. To display a user’s balance, read the balance handle from your token and [perform **user decryption**](https://docs.zama.ai/protocol/relayer-sdk-guides/v0.1/fhevm-relayer/decryption/user-decryption) with an EIP-712-authorised session in the wallet. Ensure the token grants ACL permission to the user before decrypting.
77+
78+
![Sign user decryption request](../.gitbook/assets/wallet-guide-2.png)
79+
80+
![View confidential token balance](../.gitbook/assets/wallet-guide-3.png)
81+
82+
**Step 3**: User chooses ERC-7984 confidential token amount to send, which is encrypted, signed and sent to destination address. Follow [**OpenZeppelin’s ERC-7984 transfer documentation**](https://docs.openzeppelin.com/confidential-contracts/token#transfer) for function variants and receiver callbacks. Amounts are passed as encrypted inputs that your wallet prepares with the Relayer SDK.
83+
84+
![Send confidential tokens](../.gitbook/assets/wallet-guide-4.png)
85+
86+
## **UI and UX recommendations**
87+
88+
- **Caching**: Cache decrypted values client‑side for the session lifetime. Offer a refresh action that repeats the flow.
89+
- **Permissions:** treat user decryption as a permission grant with scope and duration. Show which contracts are included and when access expires.
90+
- **Indicators:** use distinct icons or badges for encrypted amounts. Avoid showing zero when a value is simply undisclosed.
91+
- **Operator visibility**: always show current operator approvals with expiry and a one-tap revoke
92+
- **Failure modes:** differentiate between decryption denied, missing ACL grant, and expired decryption session. Offer guided recovery actions.
93+
94+
## **Testing and environments**
95+
96+
- **Testnet configuration:** Start with the SDK’s built‑in Sepolia configuration or a local Hardhat network. Swap to other supported networks by replacing the config object. Keep chain selection in a single source of truth in your app.
97+
- **Mocks:** for unit tests, prefer SDK mocked mode or local fixtures that bypass the Gateway but maintain identical call shapes for your UI logic.
98+
99+
## Further reading
100+
101+
- Detailed [**confidential contracts guide from OpenZeppelin**](https://docs.openzeppelin.com/confidential-contracts) (besides ERC-7984)
102+
- [**ERC-7984 tutorial and examples**](./openzeppelin/README.md)

0 commit comments

Comments
 (0)