@zama-fhe/react-sdk 3.0.0-alpha.2 → 3.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -73
- package/dist/index.d.ts +165 -197
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/wagmi/index.d.ts +47 -8
- package/dist/wagmi/index.js +1 -1
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,32 +30,31 @@ yarn add @zama-fhe/react-sdk @tanstack/react-query
|
|
|
30
30
|
|
|
31
31
|
```tsx
|
|
32
32
|
import { WagmiProvider, createConfig, http } from "wagmi";
|
|
33
|
-
import {
|
|
33
|
+
import { sepolia } from "wagmi/chains";
|
|
34
34
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
35
|
-
import { ZamaProvider
|
|
36
|
-
import {
|
|
35
|
+
import { ZamaProvider } from "@zama-fhe/react-sdk";
|
|
36
|
+
import { createConfig as createZamaFheConfig } from "@zama-fhe/react-sdk/wagmi";
|
|
37
|
+
import { web } from "@zama-fhe/sdk";
|
|
38
|
+
import { sepolia as sepoliaFhe } from "@zama-fhe/sdk/chains";
|
|
39
|
+
import type { FheChain } from "@zama-fhe/sdk/chains";
|
|
40
|
+
|
|
41
|
+
const mySepolia = {
|
|
42
|
+
...sepoliaFhe,
|
|
43
|
+
relayerUrl: "https://your-app.com/api/relayer/11155111",
|
|
44
|
+
} as const satisfies FheChain;
|
|
37
45
|
|
|
38
46
|
const wagmiConfig = createConfig({
|
|
39
|
-
chains: [
|
|
47
|
+
chains: [sepolia],
|
|
40
48
|
transports: {
|
|
41
|
-
[mainnet.id]: http("https://mainnet.infura.io/v3/YOUR_KEY"),
|
|
42
49
|
[sepolia.id]: http("https://sepolia.infura.io/v3/YOUR_KEY"),
|
|
43
50
|
},
|
|
44
51
|
});
|
|
45
52
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[mainnet.id]: {
|
|
52
|
-
relayerUrl: "https://your-app.com/api/relayer/1",
|
|
53
|
-
network: "https://mainnet.infura.io/v3/YOUR_KEY",
|
|
54
|
-
},
|
|
55
|
-
[sepolia.id]: {
|
|
56
|
-
relayerUrl: "https://your-app.com/api/relayer/11155111",
|
|
57
|
-
network: "https://sepolia.infura.io/v3/YOUR_KEY",
|
|
58
|
-
},
|
|
53
|
+
const zamaConfig = createZamaFheConfig({
|
|
54
|
+
chains: [mySepolia],
|
|
55
|
+
wagmiConfig,
|
|
56
|
+
relayers: {
|
|
57
|
+
[mySepolia.id]: web(),
|
|
59
58
|
},
|
|
60
59
|
});
|
|
61
60
|
|
|
@@ -65,7 +64,7 @@ function App() {
|
|
|
65
64
|
return (
|
|
66
65
|
<WagmiProvider config={wagmiConfig}>
|
|
67
66
|
<QueryClientProvider client={queryClient}>
|
|
68
|
-
<ZamaProvider
|
|
67
|
+
<ZamaProvider config={zamaConfig}>
|
|
69
68
|
<TokenBalance />
|
|
70
69
|
</ZamaProvider>
|
|
71
70
|
</QueryClientProvider>
|
|
@@ -85,26 +84,22 @@ function TokenBalance() {
|
|
|
85
84
|
|
|
86
85
|
```tsx
|
|
87
86
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
88
|
-
import {
|
|
89
|
-
import {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
[sepolia.id]: {
|
|
105
|
-
relayerUrl: "https://your-app.com/api/relayer/11155111",
|
|
106
|
-
network: "https://sepolia.infura.io/v3/YOUR_KEY",
|
|
107
|
-
},
|
|
87
|
+
import { ZamaProvider, useConfidentialBalance, useConfidentialTransfer } from "@zama-fhe/react-sdk";
|
|
88
|
+
import { createConfig } from "@zama-fhe/react-sdk/wagmi";
|
|
89
|
+
import { web } from "@zama-fhe/sdk";
|
|
90
|
+
import { sepolia } from "@zama-fhe/sdk/chains";
|
|
91
|
+
import type { FheChain } from "@zama-fhe/sdk/chains";
|
|
92
|
+
|
|
93
|
+
const mySepolia = {
|
|
94
|
+
...sepolia,
|
|
95
|
+
relayerUrl: "https://your-app.com/api/relayer/11155111",
|
|
96
|
+
} as const satisfies FheChain;
|
|
97
|
+
|
|
98
|
+
const zamaConfig = createConfig({
|
|
99
|
+
chains: [mySepolia],
|
|
100
|
+
signer: yourCustomSigner,
|
|
101
|
+
relayers: {
|
|
102
|
+
[mySepolia.id]: web(),
|
|
108
103
|
},
|
|
109
104
|
});
|
|
110
105
|
|
|
@@ -113,7 +108,7 @@ const queryClient = new QueryClient();
|
|
|
113
108
|
function App() {
|
|
114
109
|
return (
|
|
115
110
|
<QueryClientProvider client={queryClient}>
|
|
116
|
-
<ZamaProvider
|
|
111
|
+
<ZamaProvider config={zamaConfig}>
|
|
117
112
|
<TransferForm />
|
|
118
113
|
</ZamaProvider>
|
|
119
114
|
</QueryClientProvider>
|
|
@@ -144,22 +139,32 @@ function TransferForm() {
|
|
|
144
139
|
|
|
145
140
|
## Provider Setup
|
|
146
141
|
|
|
147
|
-
All setups use `ZamaProvider
|
|
142
|
+
All setups use `ZamaProvider` with a config object from `createConfig`.
|
|
148
143
|
|
|
149
144
|
```tsx
|
|
150
145
|
import { ZamaProvider } from "@zama-fhe/react-sdk";
|
|
146
|
+
import { createConfig } from "@zama-fhe/react-sdk/wagmi";
|
|
147
|
+
import { web } from "@zama-fhe/sdk";
|
|
148
|
+
import { sepolia } from "@zama-fhe/sdk/chains";
|
|
149
|
+
import type { FheChain } from "@zama-fhe/sdk/chains";
|
|
150
|
+
|
|
151
|
+
const mySepolia = { ...sepolia, relayerUrl: "/api/relayer/11155111" } as const satisfies FheChain;
|
|
152
|
+
|
|
153
|
+
const zamaConfig = createConfig({
|
|
154
|
+
chains: [mySepolia],
|
|
155
|
+
wagmiConfig, // or use createConfig from @zama-fhe/sdk/viem or @zama-fhe/sdk/ethers
|
|
156
|
+
relayers: {
|
|
157
|
+
[mySepolia.id]: web(),
|
|
158
|
+
},
|
|
159
|
+
// Optional fields:
|
|
160
|
+
// storage: indexedDBStorage,
|
|
161
|
+
// sessionStorage: chromeSessionStorage,
|
|
162
|
+
// keypairTTL: 2592000, // 30 days (default)
|
|
163
|
+
// sessionTTL: 2592000, // 30 days (default). 0 = re-sign every operation.
|
|
164
|
+
// onEvent: (event) => console.debug(event),
|
|
165
|
+
});
|
|
151
166
|
|
|
152
|
-
<ZamaProvider
|
|
153
|
-
relayer={relayer} // RelayerSDK (RelayerWeb or RelayerNode instance)
|
|
154
|
-
signer={signer} // GenericSigner (WagmiSigner, ViemSigner, EthersSigner, or custom)
|
|
155
|
-
storage={storage} // GenericStorage
|
|
156
|
-
sessionStorage={sessionStorage} // Optional. Session storage for wallet signatures. Default: in-memory (lost on reload).
|
|
157
|
-
keypairTTL={2592000} // Optional. Seconds the ML-KEM keypair remains valid. Default: 2592000 (30 days).
|
|
158
|
-
sessionTTL={2592000} // Optional. Seconds the session signature remains valid. Default: 2592000 (30 days). 0 = re-sign every operation.
|
|
159
|
-
onEvent={(event) => console.debug(event)} // Optional. Structured event listener for debugging.
|
|
160
|
-
>
|
|
161
|
-
{children}
|
|
162
|
-
</ZamaProvider>;
|
|
167
|
+
<ZamaProvider config={zamaConfig}>{children}</ZamaProvider>;
|
|
163
168
|
```
|
|
164
169
|
|
|
165
170
|
## Which Hooks Should I Use?
|
|
@@ -497,15 +502,27 @@ Save the unwrap tx hash before finalization so interrupted unshields can be resu
|
|
|
497
502
|
import {
|
|
498
503
|
savePendingUnshield,
|
|
499
504
|
loadPendingUnshield,
|
|
505
|
+
loadPendingUnshieldRequest,
|
|
500
506
|
clearPendingUnshield,
|
|
507
|
+
type PendingUnshieldRequest,
|
|
501
508
|
} from "@zama-fhe/react-sdk";
|
|
502
509
|
|
|
503
|
-
// Save before the finalize step
|
|
504
|
-
|
|
510
|
+
// Save before the finalize step.
|
|
511
|
+
// Pass unwrapRequestId from upgraded UnwrapRequested events when available.
|
|
512
|
+
const event = findUnwrapRequested(receipt.logs);
|
|
513
|
+
await savePendingUnshield(storage, wrapperAddress, unwrapTxHash, event.unwrapRequestId);
|
|
505
514
|
|
|
506
|
-
//
|
|
515
|
+
// On next visit: resume with the tx hash (works for both legacy and upgraded wrappers)
|
|
507
516
|
const pending = await loadPendingUnshield(storage, wrapperAddress);
|
|
508
517
|
|
|
518
|
+
// Or load the full request to access unwrapRequestId directly
|
|
519
|
+
const request: PendingUnshieldRequest | null = await loadPendingUnshieldRequest(
|
|
520
|
+
storage,
|
|
521
|
+
wrapperAddress,
|
|
522
|
+
);
|
|
523
|
+
// request.unwrapTxHash — always present
|
|
524
|
+
// request.unwrapRequestId — present only for requests from upgraded wrappers
|
|
525
|
+
|
|
509
526
|
// Clear after successful finalization
|
|
510
527
|
await clearPendingUnshield(storage, wrapperAddress);
|
|
511
528
|
```
|
|
@@ -547,12 +564,12 @@ Complete an unwrap by providing the decryption proof.
|
|
|
547
564
|
```ts
|
|
548
565
|
function useFinalizeUnwrap(
|
|
549
566
|
config: UseZamaConfig,
|
|
550
|
-
options?: UseMutationOptions<
|
|
551
|
-
): UseMutationResult<
|
|
567
|
+
options?: UseMutationOptions<TransactionResult, Error, FinalizeUnwrapParams>,
|
|
568
|
+
): UseMutationResult<TransactionResult, Error, FinalizeUnwrapParams>;
|
|
552
569
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
570
|
+
type FinalizeUnwrapParams =
|
|
571
|
+
| { unwrapRequestId: Hex; burnAmountHandle?: never }
|
|
572
|
+
| { unwrapRequestId?: never; burnAmountHandle: Hex };
|
|
556
573
|
```
|
|
557
574
|
|
|
558
575
|
### Delegation Hooks
|
|
@@ -837,14 +854,25 @@ FHE decrypt credentials are generated once per wallet + contract set and cached
|
|
|
837
854
|
By default, wallet signatures are stored in memory and lost on page reload (or service worker restart). For MV3 web extensions, use the built-in `chromeSessionStorage` singleton so signatures survive service worker restarts and are shared across popup, background, and content script contexts:
|
|
838
855
|
|
|
839
856
|
```tsx
|
|
840
|
-
import { chromeSessionStorage } from "@zama-fhe/react-sdk";
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
857
|
+
import { chromeSessionStorage, indexedDBStorage } from "@zama-fhe/react-sdk";
|
|
858
|
+
import { createConfig } from "@zama-fhe/react-sdk/wagmi";
|
|
859
|
+
import { web } from "@zama-fhe/sdk";
|
|
860
|
+
import { sepolia } from "@zama-fhe/sdk/chains";
|
|
861
|
+
import type { FheChain } from "@zama-fhe/sdk/chains";
|
|
862
|
+
|
|
863
|
+
const mySepolia = { ...sepolia, relayerUrl: "/api/relayer/11155111" } as const satisfies FheChain;
|
|
864
|
+
|
|
865
|
+
const zamaConfig = createConfig({
|
|
866
|
+
chains: [mySepolia],
|
|
867
|
+
wagmiConfig,
|
|
868
|
+
storage: indexedDBStorage,
|
|
869
|
+
sessionStorage: chromeSessionStorage,
|
|
870
|
+
relayers: {
|
|
871
|
+
[mySepolia.id]: web(),
|
|
872
|
+
},
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
<ZamaProvider config={zamaConfig}>
|
|
848
876
|
<App />
|
|
849
877
|
</ZamaProvider>;
|
|
850
878
|
```
|
|
@@ -908,22 +936,24 @@ queryClient.invalidateQueries({ queryKey: zamaQueryKeys.confidentialBalance.all
|
|
|
908
936
|
|
|
909
937
|
All public exports from `@zama-fhe/sdk` are re-exported from the main entry point. You never need to import from the core package directly.
|
|
910
938
|
|
|
939
|
+
**Config:** `web`, `cleartext`. Use `createConfig` from `@zama-fhe/react-sdk/wagmi`, `@zama-fhe/sdk/viem`, or `@zama-fhe/sdk/ethers` as appropriate. Use `node` from `@zama-fhe/sdk/node`.
|
|
940
|
+
|
|
911
941
|
**Classes:** `RelayerWeb`, `ZamaSDK`, `Token`, `ReadonlyToken`, `MemoryStorage`, `memoryStorage`, `IndexedDBStorage`, `indexedDBStorage`, `CredentialsManager`.
|
|
912
942
|
|
|
913
|
-
**Network configs:** `SepoliaConfig`, `MainnetConfig`, `HardhatConfig`.
|
|
943
|
+
**Network configs:** `SepoliaConfig`, `MainnetConfig`, `HardhatConfig`. Chain objects are available from `@zama-fhe/sdk/chains`.
|
|
914
944
|
|
|
915
|
-
**Pending unshield:** `savePendingUnshield`, `loadPendingUnshield`, `clearPendingUnshield`.
|
|
945
|
+
**Pending unshield:** `savePendingUnshield`, `loadPendingUnshield`, `loadPendingUnshieldRequest`, `clearPendingUnshield`. Type: `PendingUnshieldRequest`.
|
|
916
946
|
|
|
917
947
|
**Types:** `Address`, `ZamaSDKConfig`, `ReadonlyTokenConfig`, `NetworkType`, `RelayerSDK`, `RelayerSDKStatus`, `EncryptResult`, `EncryptParams`, `UserDecryptParams`, `PublicDecryptResult`, `KeypairType`, `EIP712TypedData`, `DelegatedUserDecryptParams`, `KmsDelegatedUserDecryptEIP712Type`, `ZKProofLike`, `InputProofBytesType`, `StoredCredentials`, `GenericSigner`, `GenericStorage`, `TransactionReceipt`, `TransactionResult`, `UnshieldCallbacks`.
|
|
918
948
|
|
|
919
949
|
**Errors:** `ZamaError`, `ZamaErrorCode`, `SigningRejectedError`, `SigningFailedError`, `EncryptionFailedError`, `DecryptionFailedError`, `ApprovalFailedError`, `TransactionRevertedError`, `InvalidKeypairError`, `NoCiphertextError`, `RelayerRequestFailedError`, `matchZamaError`.
|
|
920
950
|
|
|
921
|
-
**Constants:** `ZERO_HANDLE`, `ERC7984_INTERFACE_ID`, `ERC7984_WRAPPER_INTERFACE_ID`.
|
|
951
|
+
**Constants:** `ZERO_HANDLE`, `ERC7984_INTERFACE_ID`, `ERC7984_WRAPPER_INTERFACE_ID`, `ERC7984_WRAPPER_INTERFACE_ID_LEGACY`.
|
|
922
952
|
|
|
923
953
|
**ABIs:** `ERC20_ABI`, `ERC20_METADATA_ABI`, `DEPLOYMENT_COORDINATOR_ABI`, `ERC165_ABI`, `ENCRYPTION_ABI`, `TRANSFER_BATCHER_ABI`, `WRAPPER_ABI`, `BATCH_SWAP_ABI`.
|
|
924
954
|
|
|
925
|
-
**Events:** `RawLog`, `ConfidentialTransferEvent`, `WrappedEvent`, `UnwrapRequestedEvent`, `UnwrappedFinalizedEvent`, `UnwrappedStartedEvent`, `OnChainEvent`, `Topics`, `TOKEN_TOPICS`.
|
|
955
|
+
**Events:** `RawLog`, `ConfidentialTransferEvent`, `WrappedEvent`, `UnwrapRequestedEvent`, `UnwrapFinalizedEvent`, `UnwrappedFinalizedEvent`, `UnwrappedStartedEvent`, `OnChainEvent`, `Topics`, `TOKEN_TOPICS`.
|
|
926
956
|
|
|
927
|
-
**Event decoders:** `decodeConfidentialTransfer`, `decodeWrapped`, `decodeUnwrapRequested`, `decodeUnwrappedFinalized`, `decodeUnwrappedStarted`, `decodeOnChainEvent`, `decodeOnChainEvents`, `findUnwrapRequested`, `findWrapped`.
|
|
957
|
+
**Event decoders:** `decodeConfidentialTransfer`, `decodeWrapped`, `decodeUnwrapRequested`, `decodeUnwrapFinalized`, `decodeUnwrappedFinalized`, `decodeUnwrappedStarted`, `decodeOnChainEvent`, `decodeOnChainEvents`, `findUnwrapRequested`, `findWrapped`.
|
|
928
958
|
|
|
929
959
|
**Contract call builders:** `confidentialBalanceOfContract`, `confidentialTransferContract`, `confidentialTransferFromContract`, `isOperatorContract`, `unwrapContract`, `unwrapFromBalanceContract`, `finalizeUnwrapContract`, `setOperatorContract`, `underlyingContract`, `inferredTotalSupplyContract`, `wrapContract`, `supportsInterfaceContract`, `isConfidentialTokenContract`, `isConfidentialWrapperContract`, `nameContract`, `symbolContract`, `decimalsContract`, `allowanceContract`, `approveContract`, `confidentialTotalSupplyContract`, `totalSupplyContract`, `rateContract`.
|