@permissionless-technologies/upp-sdk 0.1.0

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.
Files changed (140) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +194 -0
  3. package/dist/asp-TXSAFFD3.cjs +53 -0
  4. package/dist/asp-TXSAFFD3.cjs.map +1 -0
  5. package/dist/asp-ZA3RGN7G.js +4 -0
  6. package/dist/asp-ZA3RGN7G.js.map +1 -0
  7. package/dist/babyjubjub-2MGQVCKB.js +5 -0
  8. package/dist/babyjubjub-2MGQVCKB.js.map +1 -0
  9. package/dist/babyjubjub-MWZLJOVZ.cjs +66 -0
  10. package/dist/babyjubjub-MWZLJOVZ.cjs.map +1 -0
  11. package/dist/chunk-2JQISXBD.js +150 -0
  12. package/dist/chunk-2JQISXBD.js.map +1 -0
  13. package/dist/chunk-3HQ7A6ZM.cjs +61 -0
  14. package/dist/chunk-3HQ7A6ZM.cjs.map +1 -0
  15. package/dist/chunk-5AKBSMEQ.cjs +1008 -0
  16. package/dist/chunk-5AKBSMEQ.cjs.map +1 -0
  17. package/dist/chunk-5V5HSN6Y.js +81 -0
  18. package/dist/chunk-5V5HSN6Y.js.map +1 -0
  19. package/dist/chunk-BH24DZ5S.cjs +91 -0
  20. package/dist/chunk-BH24DZ5S.cjs.map +1 -0
  21. package/dist/chunk-C7QQOJ7T.cjs +67 -0
  22. package/dist/chunk-C7QQOJ7T.cjs.map +1 -0
  23. package/dist/chunk-ERQE57IA.cjs +404 -0
  24. package/dist/chunk-ERQE57IA.cjs.map +1 -0
  25. package/dist/chunk-EUP7MBAH.cjs +165 -0
  26. package/dist/chunk-EUP7MBAH.cjs.map +1 -0
  27. package/dist/chunk-G7VZBCD6.cjs +35 -0
  28. package/dist/chunk-G7VZBCD6.cjs.map +1 -0
  29. package/dist/chunk-GQV47S3N.cjs +10 -0
  30. package/dist/chunk-GQV47S3N.cjs.map +1 -0
  31. package/dist/chunk-GXZ3MTCQ.cjs +527 -0
  32. package/dist/chunk-GXZ3MTCQ.cjs.map +1 -0
  33. package/dist/chunk-JWNXBALH.cjs +57 -0
  34. package/dist/chunk-JWNXBALH.cjs.map +1 -0
  35. package/dist/chunk-KIKBPJXJ.cjs +348 -0
  36. package/dist/chunk-KIKBPJXJ.cjs.map +1 -0
  37. package/dist/chunk-NCW4AE7L.js +8 -0
  38. package/dist/chunk-NCW4AE7L.js.map +1 -0
  39. package/dist/chunk-NDM5EJEV.cjs +70 -0
  40. package/dist/chunk-NDM5EJEV.cjs.map +1 -0
  41. package/dist/chunk-NUIQHTSA.js +489 -0
  42. package/dist/chunk-NUIQHTSA.js.map +1 -0
  43. package/dist/chunk-OQDSHMXU.js +1002 -0
  44. package/dist/chunk-OQDSHMXU.js.map +1 -0
  45. package/dist/chunk-P37MRZ73.js +58 -0
  46. package/dist/chunk-P37MRZ73.js.map +1 -0
  47. package/dist/chunk-PWHOUQOZ.js +335 -0
  48. package/dist/chunk-PWHOUQOZ.js.map +1 -0
  49. package/dist/chunk-S4B7GYLN.js +112 -0
  50. package/dist/chunk-S4B7GYLN.js.map +1 -0
  51. package/dist/chunk-SGZZL5AC.js +59 -0
  52. package/dist/chunk-SGZZL5AC.js.map +1 -0
  53. package/dist/chunk-SQKBT2SH.cjs +122 -0
  54. package/dist/chunk-SQKBT2SH.cjs.map +1 -0
  55. package/dist/chunk-TSF6HEVS.cjs +201 -0
  56. package/dist/chunk-TSF6HEVS.cjs.map +1 -0
  57. package/dist/chunk-V23OSL25.js +48 -0
  58. package/dist/chunk-V23OSL25.js.map +1 -0
  59. package/dist/chunk-W77GRBO4.js +53 -0
  60. package/dist/chunk-W77GRBO4.js.map +1 -0
  61. package/dist/chunk-XV72HNHN.js +399 -0
  62. package/dist/chunk-XV72HNHN.js.map +1 -0
  63. package/dist/chunk-YOWDERVC.js +186 -0
  64. package/dist/chunk-YOWDERVC.js.map +1 -0
  65. package/dist/chunk-Z6ZWNWWR.js +30 -0
  66. package/dist/chunk-Z6ZWNWWR.js.map +1 -0
  67. package/dist/chunk-ZKZV6OI3.cjs +165 -0
  68. package/dist/chunk-ZKZV6OI3.cjs.map +1 -0
  69. package/dist/chunk-ZU6J7KMY.js +159 -0
  70. package/dist/chunk-ZU6J7KMY.js.map +1 -0
  71. package/dist/core/index.cjs +300 -0
  72. package/dist/core/index.cjs.map +1 -0
  73. package/dist/core/index.d.cts +9 -0
  74. package/dist/core/index.d.ts +9 -0
  75. package/dist/core/index.js +11 -0
  76. package/dist/core/index.js.map +1 -0
  77. package/dist/index-BBzvvrhG.d.ts +757 -0
  78. package/dist/index-BGvapsJy.d.cts +2811 -0
  79. package/dist/index-C-jSNw6j.d.cts +757 -0
  80. package/dist/index-ChGaGPzP.d.ts +2811 -0
  81. package/dist/index.cjs +3652 -0
  82. package/dist/index.cjs.map +1 -0
  83. package/dist/index.d.cts +12 -0
  84. package/dist/index.d.ts +12 -0
  85. package/dist/index.js +3112 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/indexer/index.cjs +58 -0
  88. package/dist/indexer/index.cjs.map +1 -0
  89. package/dist/indexer/index.d.cts +206 -0
  90. package/dist/indexer/index.d.ts +206 -0
  91. package/dist/indexer/index.js +5 -0
  92. package/dist/indexer/index.js.map +1 -0
  93. package/dist/keccak-m31-B_AqBbRF.d.cts +70 -0
  94. package/dist/keccak-m31-B_AqBbRF.d.ts +70 -0
  95. package/dist/keys/index.cjs +68 -0
  96. package/dist/keys/index.cjs.map +1 -0
  97. package/dist/keys/index.d.cts +158 -0
  98. package/dist/keys/index.d.ts +158 -0
  99. package/dist/keys/index.js +7 -0
  100. package/dist/keys/index.js.map +1 -0
  101. package/dist/merkle-7KS2EHRF.js +5 -0
  102. package/dist/merkle-7KS2EHRF.js.map +1 -0
  103. package/dist/merkle-HGDC6OB4.cjs +30 -0
  104. package/dist/merkle-HGDC6OB4.cjs.map +1 -0
  105. package/dist/merkle-mteVOlDf.d.cts +188 -0
  106. package/dist/merkle-mteVOlDf.d.ts +188 -0
  107. package/dist/poseidon-UHTJLWQM.js +7 -0
  108. package/dist/poseidon-UHTJLWQM.js.map +1 -0
  109. package/dist/poseidon-WHJSZSNP.cjs +45 -0
  110. package/dist/poseidon-WHJSZSNP.cjs.map +1 -0
  111. package/dist/proof-5OECB3RQ.cjs +45 -0
  112. package/dist/proof-5OECB3RQ.cjs.map +1 -0
  113. package/dist/proof-C4YBP6RY.js +4 -0
  114. package/dist/proof-C4YBP6RY.js.map +1 -0
  115. package/dist/react/index.cjs +2641 -0
  116. package/dist/react/index.cjs.map +1 -0
  117. package/dist/react/index.d.cts +757 -0
  118. package/dist/react/index.d.ts +757 -0
  119. package/dist/react/index.js +2598 -0
  120. package/dist/react/index.js.map +1 -0
  121. package/dist/transfer-2UDHDS7Q.cjs +37 -0
  122. package/dist/transfer-2UDHDS7Q.cjs.map +1 -0
  123. package/dist/transfer-BlmbO-Rd.d.ts +1270 -0
  124. package/dist/transfer-DKZuJnRM.d.cts +1270 -0
  125. package/dist/transfer-KTCXKHS4.js +8 -0
  126. package/dist/transfer-KTCXKHS4.js.map +1 -0
  127. package/dist/types-CJSbxv4q.d.cts +143 -0
  128. package/dist/types-mLybMxNR.d.ts +143 -0
  129. package/dist/utils/index.cjs +178 -0
  130. package/dist/utils/index.cjs.map +1 -0
  131. package/dist/utils/index.d.cts +88 -0
  132. package/dist/utils/index.d.ts +88 -0
  133. package/dist/utils/index.js +9 -0
  134. package/dist/utils/index.js.map +1 -0
  135. package/package.json +119 -0
  136. package/src/contracts/interfaces/IASPRegistry.sol +36 -0
  137. package/src/contracts/interfaces/IUniversalPrivatePool.sol +260 -0
  138. package/src/contracts/interfaces/IVerifiers.sol +68 -0
  139. package/src/deployments/11155111.json +19 -0
  140. package/src/deployments/31337.json +19 -0
@@ -0,0 +1,757 @@
1
+ import { ay as NoteCreationResult, az as ShieldedNote, Q as TransferStage, J as SwapOrderEvent } from '../transfer-DKZuJnRM.cjs';
2
+ export { A as ASPProof, aG as ASP_TREE_DEPTH, aE as IndexerConfig, aD as ProofSystemType, aF as SignTypedDataFn, aC as UPPAccountContextType, aB as UPPAccountProvider, Z as buildASPTree, a3 as computeMultiOriginASPRoot, a6 as computeSingleOriginASPRoot, af as generateASPProof, ah as generateMultiOriginASPProof, aj as generateSingleOriginASPProof, aA as useUPPAccount } from '../transfer-DKZuJnRM.cjs';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as react from 'react';
5
+ import { CSSProperties } from 'react';
6
+ import { P as Point } from '../merkle-mteVOlDf.cjs';
7
+ import { Address, Hex, PublicClient } from 'viem';
8
+ import '../keccak-m31-B_AqBbRF.cjs';
9
+ import '@permissionless-technologies/upc-sdk';
10
+ import '../types-CJSbxv4q.cjs';
11
+
12
+ interface UPPPrivateButtonProps {
13
+ /** Additional inline styles for the outer button */
14
+ style?: CSSProperties;
15
+ /** Label when private account is not activated (default: "Private Account") */
16
+ label?: string;
17
+ /** Optional slot for app-level settings rendered in the account modal */
18
+ settingsSlot?: React.ReactNode;
19
+ }
20
+ /**
21
+ * Standalone private account pill button.
22
+ *
23
+ * Place alongside RainbowKit's `<ConnectButton />` — no RainbowKit dependency required.
24
+ * Only needs `UPPAccountProvider` in the component tree.
25
+ *
26
+ * Two states:
27
+ * - Not setup: dashed-border pill with shield icon + label → opens setup modal
28
+ * - Setup: emerald pill with UPPAvatar + chevron → opens account modal
29
+ */
30
+ declare function UPPPrivateButton({ style: externalStyle, label, settingsSlot, }: UPPPrivateButtonProps): react_jsx_runtime.JSX.Element;
31
+
32
+ interface UPPModalProps {
33
+ isOpen: boolean;
34
+ onClose: () => void;
35
+ /** Optional slot for app-level settings (e.g. proof system toggle) */
36
+ settingsSlot?: React.ReactNode;
37
+ }
38
+ declare function UPPModal({ isOpen, onClose, settingsSlot }: UPPModalProps): react.ReactPortal | null;
39
+
40
+ interface UPPAvatarProps {
41
+ address: string;
42
+ size?: number;
43
+ className?: string;
44
+ style?: CSSProperties;
45
+ }
46
+ declare function UPPAvatar({ address, size, className, style }: UPPAvatarProps): react_jsx_runtime.JSX.Element;
47
+
48
+ /**
49
+ * Deterministic geometric avatar generation from an address string.
50
+ * Uses a simple hash to derive colors and shape parameters.
51
+ *
52
+ * No external dependencies — uses a basic string hash for portability
53
+ * (keccak256 from viem is async/heavy, not needed for visual identity).
54
+ */
55
+ interface AvatarShape {
56
+ type: "circle" | "rect" | "triangle";
57
+ x: number;
58
+ y: number;
59
+ size: number;
60
+ color: string;
61
+ opacity: number;
62
+ rotation: number;
63
+ }
64
+ interface AvatarData {
65
+ background: string;
66
+ shapes: AvatarShape[];
67
+ }
68
+ /**
69
+ * Generate avatar data from an address string.
70
+ * Produces a background color and 3-4 geometric shapes.
71
+ */
72
+ declare function generateAvatarData(address: string): AvatarData;
73
+ /**
74
+ * Render avatar data to an SVG string (for non-React contexts).
75
+ */
76
+ declare function renderAvatarSVG(data: AvatarData, size?: number): string;
77
+
78
+ /**
79
+ * Hook return type
80
+ */
81
+ interface UseUPPCryptoReturn {
82
+ /** Whether crypto libraries are ready */
83
+ isReady: boolean;
84
+ /** Initialize crypto (called automatically, but can be called manually) */
85
+ init: () => Promise<void>;
86
+ /** Poseidon hash */
87
+ poseidon: (inputs: bigint[]) => Promise<bigint>;
88
+ /** Generate random field element */
89
+ randomFieldElement: () => Promise<bigint>;
90
+ /** Compute shared secret (ECDH) */
91
+ computeSharedSecret: (privateKey: bigint, publicKey: Point) => Promise<Point>;
92
+ /** Get public key from private key */
93
+ privateToPublic: (privateKey: bigint) => Promise<Point>;
94
+ /** Add two points */
95
+ addPoints: (p1: Point, p2: Point) => Promise<Point>;
96
+ /** Multiply point by scalar */
97
+ mulPointScalar: (point: Point, scalar: bigint) => Promise<Point>;
98
+ /** Get BabyJubJub subgroup order */
99
+ getSubOrder: () => Promise<bigint>;
100
+ }
101
+ /**
102
+ * Hook for UPP crypto utilities
103
+ *
104
+ * Provides lazy-loaded cryptographic functions.
105
+ *
106
+ * @example
107
+ * ```tsx
108
+ * function MyComponent() {
109
+ * const { isReady, poseidon, randomFieldElement } = useUPPCrypto()
110
+ *
111
+ * if (!isReady) return <div>Loading crypto...</div>
112
+ *
113
+ * // Use crypto functions
114
+ * const hash = await poseidon([1n, 2n, 3n])
115
+ * }
116
+ * ```
117
+ */
118
+ declare function useUPPCrypto(): UseUPPCryptoReturn;
119
+
120
+ /**
121
+ * Shield configuration
122
+ */
123
+ interface ShieldConfig {
124
+ /** UniversalPrivatePool contract address */
125
+ poolAddress: Address;
126
+ /** Token address to shield */
127
+ tokenAddress: Address;
128
+ }
129
+ /**
130
+ * Shield parameters
131
+ */
132
+ interface ShieldParams {
133
+ /** Amount to shield (in wei/smallest unit) */
134
+ amount: bigint;
135
+ /** Origin address (the depositor/shielder's wallet address) */
136
+ originAddress: Address;
137
+ }
138
+ /**
139
+ * Shield build data - everything needed to call the contract
140
+ */
141
+ interface ShieldBuildData {
142
+ /** Amount being shielded */
143
+ amount: bigint;
144
+ /** Token address */
145
+ token: Address;
146
+ /** Commitment hash (bytes32) */
147
+ commitment: Hex;
148
+ /** Encrypted note data */
149
+ encryptedNote: Hex;
150
+ /** Raw note data for local storage */
151
+ noteData: NoteCreationResult;
152
+ }
153
+ /**
154
+ * useShield return type
155
+ */
156
+ interface UseShieldReturn {
157
+ /** Build shield transaction data */
158
+ build: (params: ShieldParams) => Promise<ShieldBuildData>;
159
+ /** Whether building is in progress */
160
+ isPending: boolean;
161
+ /** Current stage for UI feedback */
162
+ stage: 'creating_note' | null;
163
+ /** Error from last attempt */
164
+ error: Error | null;
165
+ /** Reset error state */
166
+ reset: () => void;
167
+ }
168
+ /**
169
+ * Hook for shielding tokens into UniversalPrivatePool
170
+ *
171
+ * @param config - Shield configuration (pool and token addresses)
172
+ * @returns Shield functions and state
173
+ *
174
+ * @example
175
+ * ```tsx
176
+ * function ShieldForm() {
177
+ * const { address } = useAccount() // from wagmi
178
+ * const { build, isPending, error } = useShield({
179
+ * poolAddress: '0x...',
180
+ * tokenAddress: '0x...',
181
+ * })
182
+ *
183
+ * const handleShield = async () => {
184
+ * // 1. Build shield data (originAddress is the depositor's wallet)
185
+ * const data = await build({
186
+ * amount: parseUnits('100', 18),
187
+ * originAddress: address!,
188
+ * })
189
+ *
190
+ * // 2. Approve token (using wagmi or viem)
191
+ * await writeContract({
192
+ * address: data.token,
193
+ * abi: erc20Abi,
194
+ * functionName: 'approve',
195
+ * args: [poolAddress, data.amount],
196
+ * })
197
+ *
198
+ * // 3. Shield into pool
199
+ * await writeContract({
200
+ * address: poolAddress,
201
+ * abi: UNIVERSAL_PRIVATE_POOL_ABI,
202
+ * functionName: 'shield',
203
+ * args: [data.token, data.amount, data.commitment, data.encryptedNote],
204
+ * })
205
+ *
206
+ * // 4. Track note locally
207
+ * addNote({
208
+ * amount: data.amount,
209
+ * commitment: data.noteData.commitment,
210
+ * // ... other note fields
211
+ * })
212
+ * }
213
+ *
214
+ * return (
215
+ * <button onClick={handleShield} disabled={isPending}>
216
+ * {isPending ? 'Creating note...' : 'Shield'}
217
+ * </button>
218
+ * )
219
+ * }
220
+ * ```
221
+ */
222
+ declare function useShield(config: ShieldConfig): UseShieldReturn;
223
+
224
+ /**
225
+ * Pool transfer configuration
226
+ */
227
+ interface PoolTransferConfig {
228
+ /** UniversalPrivatePool contract address */
229
+ poolAddress: Address;
230
+ /** Token address being transferred */
231
+ tokenAddress: Address;
232
+ /** viem PublicClient for reading chain data */
233
+ publicClient: PublicClient;
234
+ /** Circuit artifacts base URL (default: '/circuits/') */
235
+ circuitBaseUrl?: string;
236
+ /** ASP ID to use (default: DEMO_ASP_ID) */
237
+ aspId?: bigint;
238
+ /** All approved origins in the ASP tree (enables multi-origin proofs) */
239
+ aspApprovedOrigins?: bigint[];
240
+ }
241
+ /**
242
+ * Pool transfer parameters
243
+ */
244
+ interface PoolTransferParams {
245
+ /** Amount to send (in wei) */
246
+ amount: bigint;
247
+ /** Recipient stealth address (0zk... format) */
248
+ recipient: string;
249
+ }
250
+ /**
251
+ * Pool transfer build data - everything needed to call the contract
252
+ */
253
+ interface PoolTransferBuildData {
254
+ /** Circuit used: 'transfer' for UPP 1-in-2-out */
255
+ circuit: 'transfer';
256
+ /** Formatted proof as uint256[8] */
257
+ proof: bigint[];
258
+ /** Nullifier */
259
+ nullifier: Hex;
260
+ /** Merkle state root */
261
+ stateRoot: bigint;
262
+ /** ASP root */
263
+ aspRoot: bigint;
264
+ /** Token address */
265
+ token: Address;
266
+ /** Recipient output commitment */
267
+ outputCommitment1: Hex;
268
+ /** Change output commitment */
269
+ outputCommitment2: Hex;
270
+ /** Recipient encrypted note (packed format) */
271
+ encryptedNote1: Hex;
272
+ /** Change encrypted note (packed format) */
273
+ encryptedNote2: Hex;
274
+ /** Note that will be spent */
275
+ spentNote: ShieldedNote;
276
+ /** Raw note data for local tracking */
277
+ recipientNoteData: NoteCreationResult;
278
+ changeNoteData: NoteCreationResult;
279
+ }
280
+ /**
281
+ * usePoolTransfer return type
282
+ */
283
+ interface UsePoolTransferReturn {
284
+ /** Build transfer transaction data */
285
+ build: (params: PoolTransferParams) => Promise<PoolTransferBuildData>;
286
+ /** Whether building is in progress */
287
+ isPending: boolean;
288
+ /** Current stage for UI feedback */
289
+ stage: TransferStage | null;
290
+ /** Error from last attempt */
291
+ error: Error | null;
292
+ /** Reset error state */
293
+ reset: () => void;
294
+ }
295
+ /**
296
+ * Hook for building private transfer transactions on UniversalPrivatePool
297
+ *
298
+ * Uses UPP transfer circuit (1-in-2-out) with ASP membership proof.
299
+ *
300
+ * NOTE: Transfer requires STARK circuits. Currently throws at proof generation.
301
+ */
302
+ declare function usePoolTransfer(config: PoolTransferConfig): UsePoolTransferReturn;
303
+
304
+ /**
305
+ * Withdraw configuration
306
+ */
307
+ interface WithdrawConfig {
308
+ /** UniversalPrivatePool contract address */
309
+ poolAddress: Address;
310
+ /** Token address being withdrawn */
311
+ tokenAddress: Address;
312
+ /** viem PublicClient for reading chain data */
313
+ publicClient: PublicClient;
314
+ /** Circuit artifacts base URL (default: '/circuits/') */
315
+ circuitBaseUrl?: string;
316
+ }
317
+ /**
318
+ * Withdraw parameters
319
+ */
320
+ interface WithdrawParams {
321
+ /** Amount to withdraw (in wei) */
322
+ amount: bigint;
323
+ /** Public recipient address for the withdrawn tokens */
324
+ recipient: Address;
325
+ /** ASP ID to use for compliance (default: 0) */
326
+ aspId?: bigint;
327
+ /** ASP root for compliance (default: 0 for ragequit) */
328
+ aspRoot?: bigint;
329
+ /** Enable ragequit mode (bypass ASP check, requires recipient = origin) */
330
+ isRagequit?: boolean;
331
+ }
332
+ /**
333
+ * Withdraw build data - everything needed to call the contract
334
+ */
335
+ interface WithdrawBuildData {
336
+ /** Formatted proof as uint256[8] */
337
+ proof: bigint[];
338
+ /** Nullifier of the note being spent */
339
+ nullifier: Hex;
340
+ /** Merkle state root */
341
+ stateRoot: bigint;
342
+ /** ASP root */
343
+ aspRoot: bigint;
344
+ /** ASP ID */
345
+ aspId: bigint;
346
+ /** Token address */
347
+ token: Address;
348
+ /** Amount being withdrawn */
349
+ amount: bigint;
350
+ /** Public recipient address */
351
+ recipient: Address;
352
+ /** Whether this is a ragequit withdrawal */
353
+ isRagequit: boolean;
354
+ /** Note being spent */
355
+ spentNote: ShieldedNote;
356
+ /** Change note data (if any change remains) */
357
+ changeNoteData: NoteCreationResult | null;
358
+ /** Change output commitment (if any) */
359
+ changeCommitment: Hex | null;
360
+ /** Change encrypted note (if any) */
361
+ changeEncryptedNote: Hex | null;
362
+ }
363
+ /**
364
+ * useWithdraw return type
365
+ */
366
+ interface UseWithdrawReturn {
367
+ /** Build withdraw transaction data */
368
+ build: (params: WithdrawParams) => Promise<WithdrawBuildData>;
369
+ /** Whether building is in progress */
370
+ isPending: boolean;
371
+ /** Current stage for UI feedback */
372
+ stage: TransferStage | null;
373
+ /** Error from last attempt */
374
+ error: Error | null;
375
+ /** Reset error state */
376
+ reset: () => void;
377
+ }
378
+ /**
379
+ * Hook for building withdrawal transactions from UniversalPrivatePool
380
+ *
381
+ * @param config - Withdraw configuration
382
+ * @returns Withdraw build functions and state
383
+ *
384
+ * @example
385
+ * ```tsx
386
+ * function WithdrawForm() {
387
+ * const { address } = useAccount()
388
+ * const { build, isPending, stage, error } = useWithdraw({
389
+ * poolAddress: '0x...',
390
+ * tokenAddress: '0x...',
391
+ * publicClient,
392
+ * })
393
+ *
394
+ * const handleWithdraw = async () => {
395
+ * // 1. Build withdrawal data
396
+ * const data = await build({
397
+ * amount: parseUnits('100', 18),
398
+ * recipient: address,
399
+ * isRagequit: true, // Emergency exit without ASP check
400
+ * })
401
+ *
402
+ * // 2. Submit to pool contract
403
+ * await writeContract({
404
+ * address: poolAddress,
405
+ * abi: UNIVERSAL_PRIVATE_POOL_ABI,
406
+ * functionName: 'withdraw',
407
+ * args: [
408
+ * data.proof,
409
+ * data.nullifier,
410
+ * data.stateRoot,
411
+ * data.aspRoot,
412
+ * data.aspId,
413
+ * data.token,
414
+ * data.amount,
415
+ * data.recipient,
416
+ * data.isRagequit,
417
+ * ],
418
+ * })
419
+ *
420
+ * // 3. Track spent note locally
421
+ * markNoteSpent(data.spentNote.commitment)
422
+ * if (data.changeNoteData) {
423
+ * addNote(/* change note *\/)
424
+ * }
425
+ * }
426
+ *
427
+ * return (
428
+ * <div>
429
+ * {stage && <p>Stage: {stage}</p>}
430
+ * <button onClick={handleWithdraw} disabled={isPending}>
431
+ * {isPending ? 'Building proof...' : 'Withdraw'}
432
+ * </button>
433
+ * </div>
434
+ * )
435
+ * }
436
+ * ```
437
+ */
438
+ declare function useWithdraw(config: WithdrawConfig): UseWithdrawReturn;
439
+
440
+ interface PersonalASPConfig {
441
+ /** ASP Registry Hub contract address */
442
+ aspHubAddress: Address;
443
+ /** viem PublicClient for reading chain data */
444
+ publicClient: PublicClient;
445
+ /** User's wallet address */
446
+ userAddress?: Address;
447
+ }
448
+ interface PersonalASPInfo {
449
+ /** ASP ID (0 if not registered) */
450
+ aspId: bigint;
451
+ /** Current root (0 if not set) */
452
+ currentRoot: bigint;
453
+ /** Whether the ASP is registered */
454
+ isRegistered: boolean;
455
+ /** Whether the root is set to the user's origin */
456
+ isApproved: boolean;
457
+ }
458
+ interface UsePersonalASPReturn {
459
+ /** Personal ASP info */
460
+ aspInfo: PersonalASPInfo | null;
461
+ /** Whether loading initial state */
462
+ isLoading: boolean;
463
+ /** Error from last operation */
464
+ error: Error | null;
465
+ /** Check if a specific origin is approved in this ASP */
466
+ isOriginApproved: (origin: bigint) => Promise<boolean>;
467
+ /** Get the ASP ID for use in transactions */
468
+ getASPId: () => bigint | null;
469
+ /** Get the ASP root for a given origin (for single-origin tree) */
470
+ getASPRootForOrigin: (origin: bigint) => Promise<bigint>;
471
+ /** Refresh ASP info from contract */
472
+ refresh: () => Promise<void>;
473
+ }
474
+ /**
475
+ * Hook for managing a personal ASP
476
+ *
477
+ * @example
478
+ * ```tsx
479
+ * function ApproveButton() {
480
+ * const { aspInfo, refresh } = usePersonalASP({
481
+ * aspHubAddress: '0x...',
482
+ * publicClient,
483
+ * userAddress: address,
484
+ * })
485
+ *
486
+ * // Check if approved
487
+ * if (aspInfo?.isApproved) {
488
+ * return <span>Approved!</span>
489
+ * }
490
+ *
491
+ * return <button onClick={handleApprove}>Approve Yourself</button>
492
+ * }
493
+ * ```
494
+ */
495
+ declare function usePersonalASP(config: PersonalASPConfig): UsePersonalASPReturn;
496
+ /**
497
+ * Store a newly registered ASP ID
498
+ * Call this after successfully registering an ASP via contract
499
+ */
500
+ declare function storePersonalASPId(chainId: number, address: Address, aspId: bigint): void;
501
+
502
+ type SwapStage = 'idle' | 'preparing' | 'generating_proof' | 'submitting_tx' | 'confirming' | 'done' | 'error';
503
+ interface SwapOrderBookConfig {
504
+ /** UniversalPrivatePool contract address */
505
+ poolAddress: Address;
506
+ /** viem PublicClient for reading chain data */
507
+ publicClient: PublicClient;
508
+ /** Token pair filter (optional) */
509
+ sellToken?: Address;
510
+ buyToken?: Address;
511
+ /** ASP filter: only show orders from these ASP IDs */
512
+ acceptableAspIds?: bigint[];
513
+ /** Polling interval for order book updates (ms, default: 15000) */
514
+ pollInterval?: number;
515
+ /** Start block for event scanning (default: 0) */
516
+ fromBlock?: bigint;
517
+ }
518
+ interface UseSwapOrderBookReturn {
519
+ /** Active swap orders */
520
+ orders: SwapOrderEvent[];
521
+ /** Whether the order book is loading */
522
+ isLoading: boolean;
523
+ /** Error if any */
524
+ error: string | null;
525
+ /** Manually refresh the order book */
526
+ refresh: () => Promise<void>;
527
+ }
528
+ interface SwapConfig {
529
+ /** UniversalPrivatePool contract address */
530
+ poolAddress: Address;
531
+ /** viem PublicClient for reading chain data */
532
+ publicClient: PublicClient;
533
+ /** Circuit artifacts base URL (default: '/circuits/') */
534
+ circuitBaseUrl?: string;
535
+ /** All approved origins in the ASP tree (enables multi-origin proofs) */
536
+ aspApprovedOrigins?: bigint[];
537
+ }
538
+ /**
539
+ * Build data returned by buildPlaceOrder — everything needed for the contract call
540
+ */
541
+ interface PlaceOrderBuildData {
542
+ /** Formatted proof as uint256[8] */
543
+ proof: bigint[];
544
+ /** Nullifier (= orderId) */
545
+ nullifier: Hex;
546
+ /** Merkle state root */
547
+ stateRoot: bigint;
548
+ /** ASP root */
549
+ aspRoot: bigint;
550
+ /** ASP ID */
551
+ aspId: bigint;
552
+ /** Sell token address */
553
+ sellToken: Address;
554
+ /** Sell amount */
555
+ sellAmount: bigint;
556
+ /** Buy token address */
557
+ buyToken: Address;
558
+ /** Rate (1e18 fixed-point) */
559
+ rate: bigint;
560
+ /** Cancel key hash */
561
+ cancelKeyHash: Hex;
562
+ /** Cancel secret (store in localStorage!) */
563
+ cancelSecret: Hex;
564
+ /** Required filler ASP ID */
565
+ requiredFillerAspId: bigint;
566
+ /** Expiry (block number) */
567
+ expiry: bigint;
568
+ /** Note being spent */
569
+ spentNote: ShieldedNote;
570
+ }
571
+ /**
572
+ * Build data returned by buildFillOrder
573
+ */
574
+ interface FillOrderBuildData {
575
+ /** Formatted proof as uint256[8] */
576
+ proof: bigint[];
577
+ /** Filler's nullifier */
578
+ nullifier: Hex;
579
+ /** Merkle state root */
580
+ stateRoot: bigint;
581
+ /** ASP root */
582
+ aspRoot: bigint;
583
+ /** ASP ID */
584
+ aspId: bigint;
585
+ /** Order being filled */
586
+ orderId: Hex;
587
+ /** Take amount (sellToken from order) */
588
+ takeAmount: bigint;
589
+ /** Filler's output commitment (receives sellToken) */
590
+ fillerOutputCommitment: Hex;
591
+ /** Encrypted note for filler's output */
592
+ fillerEncryptedNote: Hex;
593
+ /** Note being spent */
594
+ spentNote: ShieldedNote;
595
+ /** Filler's new note data */
596
+ fillerNoteData: NoteCreationResult;
597
+ }
598
+ /**
599
+ * Build data returned by buildClaimOrder
600
+ */
601
+ interface ClaimOrderBuildData {
602
+ /** Order being claimed */
603
+ orderId: Hex;
604
+ /** Cancel secret */
605
+ cancelSecret: Hex;
606
+ /** Buy output commitment (receives accumulated buyToken) */
607
+ buyOutputCommitment: Hex;
608
+ /** Refund commitment (remaining sellToken) */
609
+ refundCommitment: Hex;
610
+ /** Encrypted buy output note */
611
+ buyEncryptedNote: Hex;
612
+ /** Encrypted refund note */
613
+ refundEncryptedNote: Hex;
614
+ /** Buy note data (null if no fills) */
615
+ buyNoteData: NoteCreationResult | null;
616
+ /** Refund note data (null if fully filled) */
617
+ refundNoteData: NoteCreationResult | null;
618
+ }
619
+ /**
620
+ * Build data returned by buildCancelOrder
621
+ */
622
+ interface CancelOrderBuildData {
623
+ /** Order being cancelled */
624
+ orderId: Hex;
625
+ /** Cancel secret */
626
+ cancelSecret: Hex;
627
+ /** Refund commitment */
628
+ refundCommitment: Hex;
629
+ /** Encrypted refund note */
630
+ refundEncryptedNote: Hex;
631
+ /** Refund note data */
632
+ refundNoteData: NoteCreationResult;
633
+ }
634
+ interface SplitNoteParams {
635
+ /** Note to split */
636
+ note: ShieldedNote;
637
+ /** Desired amount for the first output (the rest becomes change) */
638
+ targetAmount: bigint;
639
+ /** ASP ID to use for the proof (defaults to DEMO_ASP_ID if not provided) */
640
+ aspId?: bigint;
641
+ }
642
+ interface SplitNoteBuildData {
643
+ /** Transfer proof for contract call */
644
+ proof: bigint[];
645
+ /** Nullifier */
646
+ nullifier: Hex;
647
+ /** Merkle state root */
648
+ stateRoot: bigint;
649
+ /** ASP root (for transfer circuit) */
650
+ aspRoot: bigint;
651
+ /** Token address */
652
+ token: Address;
653
+ /** Exact-amount output commitment */
654
+ outputCommitment1: Hex;
655
+ /** Change output commitment */
656
+ outputCommitment2: Hex;
657
+ /** Exact-amount encrypted note */
658
+ encryptedNote1: Hex;
659
+ /** Change encrypted note */
660
+ encryptedNote2: Hex;
661
+ /** The exact-amount note — use as noteOverride for buildPlaceOrder/buildFillOrder */
662
+ exactNote: ShieldedNote;
663
+ /** The change note */
664
+ changeNote: ShieldedNote;
665
+ /** Original note being spent */
666
+ spentNote: ShieldedNote;
667
+ /** Raw creation data for local tracking */
668
+ exactNoteData: NoteCreationResult;
669
+ /** Raw creation data for local tracking */
670
+ changeNoteData: NoteCreationResult;
671
+ }
672
+ interface UseSwapReturn {
673
+ /** Current operation stage */
674
+ stage: TransferStage | null;
675
+ /** Whether building is in progress */
676
+ isPending: boolean;
677
+ /** Error from last attempt */
678
+ error: Error | null;
679
+ /** Build a self-transfer to split a note into exact amount + change */
680
+ buildNoteSplit: (params: SplitNoteParams) => Promise<SplitNoteBuildData>;
681
+ /** Build place order data (returns everything needed for contract call) */
682
+ buildPlaceOrder: (params: PlaceOrderParams) => Promise<PlaceOrderBuildData>;
683
+ /** Build fill order data */
684
+ buildFillOrder: (params: FillOrderParams) => Promise<FillOrderBuildData>;
685
+ /** Build claim order data (no proof needed) */
686
+ buildClaimOrder: (params: ClaimOrderParams) => Promise<ClaimOrderBuildData>;
687
+ /** Build cancel order data (no proof needed) */
688
+ buildCancelOrder: (params: CancelOrderParams) => Promise<CancelOrderBuildData>;
689
+ /** Reset state */
690
+ reset: () => void;
691
+ }
692
+ interface PlaceOrderParams {
693
+ /** Token to sell */
694
+ sellToken: Address;
695
+ /** Amount to sell */
696
+ sellAmount: bigint;
697
+ /** Token to buy */
698
+ buyToken: Address;
699
+ /** Price: buyToken per sellToken (1e18 fixed-point) */
700
+ rate: bigint;
701
+ /** Required filler ASP (0n = accept any) */
702
+ requiredFillerAspId?: bigint;
703
+ /** Number of blocks until expiry */
704
+ expiryBlocks: bigint;
705
+ /** ASP ID — must be a registered personal ASP */
706
+ aspId: bigint;
707
+ /** Explicit note to spend (skips note selection). Used after auto-split. */
708
+ noteOverride?: ShieldedNote;
709
+ }
710
+ interface FillOrderParams {
711
+ /** Order to fill */
712
+ orderId: Hex;
713
+ /** How much sellToken to take */
714
+ takeAmount: bigint;
715
+ /** The order's rate */
716
+ rate: bigint;
717
+ /** The order's sellToken (filler receives this) */
718
+ sellToken: Address;
719
+ /** The order's buyToken (filler pays this) */
720
+ buyToken: Address;
721
+ /** ASP ID — must be a registered personal ASP */
722
+ aspId: bigint;
723
+ /** Explicit note to spend (skips note selection). Used after auto-split. */
724
+ noteOverride?: ShieldedNote;
725
+ }
726
+ interface ClaimOrderParams {
727
+ /** Order to claim */
728
+ orderId: Hex;
729
+ /** Cancel secret used when placing the order */
730
+ cancelSecret: Hex;
731
+ /** On-chain remaining sell amount */
732
+ remainingSellAmount: bigint;
733
+ /** On-chain accumulated buy amount */
734
+ accumulatedBuyAmount: bigint;
735
+ /** The order's sell token */
736
+ sellToken: Address;
737
+ /** The order's buy token */
738
+ buyToken: Address;
739
+ }
740
+ interface CancelOrderParams {
741
+ /** Order to cancel */
742
+ orderId: Hex;
743
+ /** Cancel secret used when placing the order */
744
+ cancelSecret: Hex;
745
+ /** The full sell amount (refunded on cancel) */
746
+ sellAmount: bigint;
747
+ /** The order's sell token */
748
+ sellToken: Address;
749
+ }
750
+ declare function useSwapOrderBook(config: SwapOrderBookConfig): UseSwapOrderBookReturn;
751
+ /**
752
+ * Hook for swap operations with real proof generation.
753
+ * Mirrors useWithdraw — returns build functions that produce contract call data.
754
+ */
755
+ declare function useSwap(config: SwapConfig): UseSwapReturn;
756
+
757
+ export { type AvatarData, type AvatarShape, type CancelOrderBuildData, type CancelOrderParams, type ClaimOrderBuildData, type ClaimOrderParams, type FillOrderBuildData, type FillOrderParams, NoteCreationResult, type PersonalASPConfig, type PersonalASPInfo, type PlaceOrderBuildData, type PlaceOrderParams, type PoolTransferBuildData, type PoolTransferConfig, type PoolTransferParams, type ShieldBuildData, type ShieldConfig, type ShieldParams, ShieldedNote, type SplitNoteBuildData, type SplitNoteParams, type SwapConfig, type SwapOrderBookConfig, type SwapStage, TransferStage, UPPAvatar, type UPPAvatarProps, UPPModal, type UPPModalProps, UPPPrivateButton, type UPPPrivateButtonProps, type UsePersonalASPReturn, type UsePoolTransferReturn, type UseShieldReturn, type UseSwapOrderBookReturn, type UseSwapReturn, type UseWithdrawReturn, type WithdrawBuildData, type WithdrawConfig, type WithdrawParams, generateAvatarData, renderAvatarSVG, storePersonalASPId, usePersonalASP, usePoolTransfer, useShield, useSwap, useSwapOrderBook, useUPPCrypto, useWithdraw };