@veilo/sdk-core 0.4.0 → 0.5.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 (296) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +286 -1298
  3. package/dist/cjs/accounts/admin.d.ts +84 -0
  4. package/dist/cjs/accounts/admin.js +208 -0
  5. package/dist/cjs/accounts/errors.d.ts +6 -0
  6. package/dist/cjs/accounts/errors.js +98 -0
  7. package/dist/cjs/accounts/index.d.ts +4 -0
  8. package/dist/cjs/accounts/index.js +20 -0
  9. package/dist/cjs/accounts/pdas.d.ts +23 -0
  10. package/dist/cjs/accounts/pdas.js +44 -0
  11. package/dist/cjs/accounts/queries.d.ts +41 -0
  12. package/dist/cjs/accounts/queries.js +95 -0
  13. package/dist/cjs/client.d.ts +2 -407
  14. package/dist/cjs/client.js +6 -938
  15. package/dist/cjs/cloak/client.d.ts +28 -0
  16. package/dist/cjs/cloak/client.js +68 -0
  17. package/dist/cjs/cloak/errors.d.ts +13 -0
  18. package/dist/cjs/cloak/errors.js +25 -0
  19. package/dist/cjs/cloak/helpers.d.ts +6 -0
  20. package/dist/cjs/cloak/helpers.js +35 -0
  21. package/dist/cjs/cloak/index.d.ts +6 -0
  22. package/dist/cjs/cloak/index.js +24 -0
  23. package/dist/cjs/cloak/polling.d.ts +7 -0
  24. package/dist/cjs/cloak/polling.js +66 -0
  25. package/dist/cjs/cloak/transport.d.ts +15 -0
  26. package/dist/cjs/cloak/transport.js +119 -0
  27. package/dist/cjs/cloak/types.d.ts +188 -0
  28. package/dist/cjs/cloak/types.js +5 -0
  29. package/dist/cjs/cloak.d.ts +1 -0
  30. package/dist/cjs/cloak.js +18 -0
  31. package/dist/cjs/compactNote.d.ts +21 -0
  32. package/dist/cjs/compactNote.js +31 -7
  33. package/dist/cjs/index.d.ts +2 -1
  34. package/dist/cjs/index.js +4 -1
  35. package/dist/cjs/notes/encryption.d.ts +41 -0
  36. package/dist/cjs/notes/encryption.js +75 -0
  37. package/dist/cjs/notes/index.d.ts +5 -0
  38. package/dist/cjs/notes/index.js +21 -0
  39. package/dist/cjs/notes/mailbox.d.ts +70 -0
  40. package/dist/cjs/notes/mailbox.js +164 -0
  41. package/dist/cjs/notes/model.d.ts +91 -0
  42. package/dist/cjs/notes/model.js +109 -0
  43. package/dist/cjs/notes/nullifier.d.ts +27 -0
  44. package/dist/cjs/notes/nullifier.js +45 -0
  45. package/dist/cjs/notes/recovery.d.ts +10 -0
  46. package/dist/cjs/notes/recovery.js +31 -0
  47. package/dist/cjs/proof.d.ts +1 -183
  48. package/dist/cjs/proof.js +16 -290
  49. package/dist/cjs/proofs/encoding.d.ts +17 -0
  50. package/dist/cjs/proofs/encoding.js +72 -0
  51. package/dist/cjs/proofs/formatting.d.ts +6 -0
  52. package/dist/cjs/proofs/formatting.js +34 -0
  53. package/dist/cjs/proofs/index.d.ts +5 -0
  54. package/dist/cjs/proofs/index.js +21 -0
  55. package/dist/cjs/proofs/swap.d.ts +87 -0
  56. package/dist/cjs/proofs/swap.js +144 -0
  57. package/dist/cjs/proofs/transaction.d.ts +28 -0
  58. package/dist/cjs/proofs/transaction.js +110 -0
  59. package/dist/cjs/proofs/types.d.ts +70 -0
  60. package/dist/cjs/prover.d.ts +4 -1
  61. package/dist/cjs/prover.js +12 -2
  62. package/dist/cjs/relayer/client.d.ts +61 -0
  63. package/dist/cjs/relayer/client.js +151 -0
  64. package/dist/cjs/relayer/crypto.d.ts +5 -0
  65. package/dist/cjs/relayer/crypto.js +26 -0
  66. package/dist/cjs/relayer/encoding.d.ts +2 -0
  67. package/dist/cjs/relayer/encoding.js +23 -0
  68. package/dist/cjs/relayer/errors.d.ts +7 -0
  69. package/dist/cjs/relayer/errors.js +17 -0
  70. package/dist/cjs/relayer/index.d.ts +3 -0
  71. package/dist/cjs/relayer/index.js +19 -0
  72. package/dist/cjs/relayer/transport.d.ts +17 -0
  73. package/dist/cjs/relayer/transport.js +63 -0
  74. package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +44 -86
  75. package/dist/cjs/relayer/types.js +5 -0
  76. package/dist/cjs/relayer.d.ts +1 -318
  77. package/dist/cjs/relayer.js +15 -254
  78. package/dist/cjs/shield/alt.js +8 -8
  79. package/dist/cjs/shield/errors.js +2 -2
  80. package/dist/cjs/shield/finalize.js +2 -2
  81. package/dist/cjs/shield/ix.d.ts +1 -1
  82. package/dist/cjs/shield/owner.js +9 -8
  83. package/dist/cjs/shield/ports.js +3 -3
  84. package/dist/cjs/shield/preflight.js +3 -3
  85. package/dist/cjs/shield/shield.js +20 -19
  86. package/dist/cjs/shield/types.d.ts +1 -1
  87. package/dist/cjs/transactions/deposit.d.ts +94 -0
  88. package/dist/cjs/transactions/deposit.js +234 -0
  89. package/dist/cjs/transactions/index.d.ts +7 -0
  90. package/dist/cjs/transactions/index.js +26 -0
  91. package/dist/cjs/transactions/swap.d.ts +71 -0
  92. package/dist/cjs/transactions/swap.js +184 -0
  93. package/dist/cjs/transactions/transact.d.ts +34 -0
  94. package/dist/cjs/transactions/transact.js +146 -0
  95. package/dist/cjs/transactions/transfer.d.ts +51 -0
  96. package/dist/cjs/transactions/transfer.js +106 -0
  97. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  98. package/dist/cjs/transactions/withdraw.js +104 -0
  99. package/dist/cjs/utxo.d.ts +1 -235
  100. package/dist/cjs/utxo.js +15 -404
  101. package/dist/esm/accounts/admin.d.ts +84 -0
  102. package/dist/esm/accounts/admin.js +165 -0
  103. package/dist/esm/accounts/errors.d.ts +6 -0
  104. package/dist/esm/accounts/errors.js +95 -0
  105. package/dist/esm/accounts/index.d.ts +4 -0
  106. package/dist/esm/accounts/index.js +4 -0
  107. package/dist/esm/accounts/pdas.d.ts +23 -0
  108. package/dist/esm/accounts/pdas.js +38 -0
  109. package/dist/esm/accounts/queries.d.ts +41 -0
  110. package/dist/esm/accounts/queries.js +88 -0
  111. package/dist/esm/client.d.ts +2 -407
  112. package/dist/esm/client.js +3 -891
  113. package/dist/esm/cloak/client.d.ts +28 -0
  114. package/dist/esm/cloak/client.js +64 -0
  115. package/dist/esm/cloak/errors.d.ts +13 -0
  116. package/dist/esm/cloak/errors.js +21 -0
  117. package/dist/esm/cloak/helpers.d.ts +6 -0
  118. package/dist/esm/cloak/helpers.js +31 -0
  119. package/dist/esm/cloak/index.d.ts +6 -0
  120. package/dist/esm/cloak/index.js +6 -0
  121. package/dist/esm/cloak/polling.d.ts +7 -0
  122. package/dist/esm/cloak/polling.js +63 -0
  123. package/dist/esm/cloak/transport.d.ts +15 -0
  124. package/dist/esm/cloak/transport.js +115 -0
  125. package/dist/esm/cloak/types.d.ts +188 -0
  126. package/dist/esm/cloak/types.js +4 -0
  127. package/dist/esm/cloak.d.ts +1 -0
  128. package/dist/esm/cloak.js +2 -0
  129. package/dist/esm/compactNote.d.ts +21 -0
  130. package/dist/esm/compactNote.js +24 -1
  131. package/dist/esm/index.d.ts +2 -1
  132. package/dist/esm/index.js +3 -1
  133. package/dist/esm/notes/encryption.d.ts +41 -0
  134. package/dist/esm/notes/encryption.js +67 -0
  135. package/dist/esm/notes/index.d.ts +5 -0
  136. package/dist/esm/notes/index.js +5 -0
  137. package/dist/esm/notes/mailbox.d.ts +70 -0
  138. package/dist/esm/notes/mailbox.js +154 -0
  139. package/dist/esm/notes/model.d.ts +91 -0
  140. package/dist/esm/notes/model.js +99 -0
  141. package/dist/esm/notes/nullifier.d.ts +27 -0
  142. package/dist/esm/notes/nullifier.js +40 -0
  143. package/dist/esm/notes/recovery.d.ts +10 -0
  144. package/dist/esm/notes/recovery.js +28 -0
  145. package/dist/esm/proof.d.ts +1 -183
  146. package/dist/esm/proof.js +2 -281
  147. package/dist/esm/proofs/encoding.d.ts +17 -0
  148. package/dist/esm/proofs/encoding.js +68 -0
  149. package/dist/esm/proofs/formatting.d.ts +6 -0
  150. package/dist/esm/proofs/formatting.js +31 -0
  151. package/dist/esm/proofs/index.d.ts +5 -0
  152. package/dist/esm/proofs/index.js +5 -0
  153. package/dist/esm/proofs/swap.d.ts +87 -0
  154. package/dist/esm/proofs/swap.js +138 -0
  155. package/dist/esm/proofs/transaction.d.ts +28 -0
  156. package/dist/esm/proofs/transaction.js +105 -0
  157. package/dist/esm/proofs/types.d.ts +70 -0
  158. package/dist/esm/proofs/types.js +1 -0
  159. package/dist/esm/prover.d.ts +4 -1
  160. package/dist/esm/prover.js +10 -1
  161. package/dist/esm/relayer/client.d.ts +61 -0
  162. package/dist/esm/relayer/client.js +144 -0
  163. package/dist/esm/relayer/crypto.d.ts +5 -0
  164. package/dist/esm/relayer/crypto.js +20 -0
  165. package/dist/esm/relayer/encoding.d.ts +2 -0
  166. package/dist/esm/relayer/encoding.js +19 -0
  167. package/dist/esm/relayer/errors.d.ts +7 -0
  168. package/dist/esm/relayer/errors.js +13 -0
  169. package/dist/esm/relayer/index.d.ts +3 -0
  170. package/dist/esm/relayer/index.js +3 -0
  171. package/dist/esm/relayer/transport.d.ts +17 -0
  172. package/dist/esm/relayer/transport.js +59 -0
  173. package/dist/esm/relayer/types.d.ts +276 -0
  174. package/dist/esm/relayer/types.js +4 -0
  175. package/dist/esm/relayer.d.ts +1 -318
  176. package/dist/esm/relayer.js +2 -249
  177. package/dist/esm/shield/alt.js +1 -1
  178. package/dist/esm/shield/errors.js +1 -1
  179. package/dist/esm/shield/finalize.js +1 -1
  180. package/dist/esm/shield/ix.d.ts +1 -1
  181. package/dist/esm/shield/owner.js +2 -1
  182. package/dist/esm/shield/ports.js +1 -1
  183. package/dist/esm/shield/preflight.js +1 -1
  184. package/dist/esm/shield/shield.js +4 -3
  185. package/dist/esm/shield/types.d.ts +1 -1
  186. package/dist/esm/transactions/deposit.d.ts +94 -0
  187. package/dist/esm/transactions/deposit.js +198 -0
  188. package/dist/esm/transactions/index.d.ts +7 -0
  189. package/dist/esm/transactions/index.js +7 -0
  190. package/dist/esm/transactions/swap.d.ts +71 -0
  191. package/dist/esm/transactions/swap.js +144 -0
  192. package/dist/esm/transactions/transact.d.ts +34 -0
  193. package/dist/esm/transactions/transact.js +110 -0
  194. package/dist/esm/transactions/transfer.d.ts +51 -0
  195. package/dist/esm/transactions/transfer.js +103 -0
  196. package/dist/esm/transactions/withdraw.d.ts +52 -0
  197. package/dist/esm/transactions/withdraw.js +101 -0
  198. package/dist/esm/utxo.d.ts +1 -235
  199. package/dist/esm/utxo.js +2 -382
  200. package/package.json +54 -16
  201. package/SHIELD_INTEGRATION.md +0 -143
  202. package/config.d.ts +0 -2
  203. package/config.js +0 -4
  204. package/dist/src/client.d.ts +0 -407
  205. package/dist/src/client.js +0 -951
  206. package/dist/src/compactNote.d.ts +0 -107
  207. package/dist/src/compactNote.js +0 -167
  208. package/dist/src/config.d.ts +0 -82
  209. package/dist/src/config.js +0 -57
  210. package/dist/src/events.d.ts +0 -77
  211. package/dist/src/events.js +0 -167
  212. package/dist/src/idl/privacy_pool.d.ts +0 -5
  213. package/dist/src/idl/privacy_pool.js +0 -15218
  214. package/dist/src/index.d.ts +0 -16
  215. package/dist/src/index.js +0 -67
  216. package/dist/src/merkle.d.ts +0 -77
  217. package/dist/src/merkle.js +0 -156
  218. package/dist/src/poseidon.d.ts +0 -29
  219. package/dist/src/poseidon.js +0 -100
  220. package/dist/src/program.d.ts +0 -37
  221. package/dist/src/program.js +0 -61
  222. package/dist/src/proof.d.ts +0 -183
  223. package/dist/src/proof.js +0 -292
  224. package/dist/src/prover.d.ts +0 -54
  225. package/dist/src/prover.js +0 -112
  226. package/dist/src/random.d.ts +0 -16
  227. package/dist/src/random.js +0 -28
  228. package/dist/src/relayer.js +0 -257
  229. package/dist/src/retry.d.ts +0 -32
  230. package/dist/src/retry.js +0 -75
  231. package/dist/src/shield/alt.d.ts +0 -87
  232. package/dist/src/shield/alt.js +0 -194
  233. package/dist/src/shield/computeBudget.d.ts +0 -61
  234. package/dist/src/shield/computeBudget.js +0 -64
  235. package/dist/src/shield/errors.d.ts +0 -58
  236. package/dist/src/shield/errors.js +0 -121
  237. package/dist/src/shield/finalize.d.ts +0 -45
  238. package/dist/src/shield/finalize.js +0 -119
  239. package/dist/src/shield/index.d.ts +0 -35
  240. package/dist/src/shield/index.js +0 -68
  241. package/dist/src/shield/ix.d.ts +0 -54
  242. package/dist/src/shield/ix.js +0 -119
  243. package/dist/src/shield/owner.d.ts +0 -36
  244. package/dist/src/shield/owner.js +0 -126
  245. package/dist/src/shield/ports.d.ts +0 -43
  246. package/dist/src/shield/ports.js +0 -153
  247. package/dist/src/shield/preflight.d.ts +0 -30
  248. package/dist/src/shield/preflight.js +0 -154
  249. package/dist/src/shield/shield.d.ts +0 -68
  250. package/dist/src/shield/shield.js +0 -499
  251. package/dist/src/shield/types.d.ts +0 -202
  252. package/dist/src/utxo.d.ts +0 -235
  253. package/dist/src/utxo.js +0 -407
  254. package/dist/tests/compact-note.test.d.ts +0 -1
  255. package/dist/tests/compact-note.test.js +0 -173
  256. package/dist/tests/config.test.d.ts +0 -1
  257. package/dist/tests/config.test.js +0 -102
  258. package/dist/tests/edge-cases.test.d.ts +0 -1
  259. package/dist/tests/edge-cases.test.js +0 -220
  260. package/dist/tests/encryption.test.d.ts +0 -1
  261. package/dist/tests/encryption.test.js +0 -215
  262. package/dist/tests/events.test.d.ts +0 -1
  263. package/dist/tests/events.test.js +0 -78
  264. package/dist/tests/multi-tree.test.d.ts +0 -1
  265. package/dist/tests/multi-tree.test.js +0 -405
  266. package/dist/tests/pda.test.d.ts +0 -1
  267. package/dist/tests/pda.test.js +0 -229
  268. package/dist/tests/poseidon-builder-parity.test.d.ts +0 -1
  269. package/dist/tests/poseidon-builder-parity.test.js +0 -72
  270. package/dist/tests/poseidon.test.d.ts +0 -1
  271. package/dist/tests/poseidon.test.js +0 -142
  272. package/dist/tests/proof.test.d.ts +0 -1
  273. package/dist/tests/proof.test.js +0 -296
  274. package/dist/tests/relayer.test.d.ts +0 -1
  275. package/dist/tests/relayer.test.js +0 -271
  276. package/dist/tests/sdk.integration.test.d.ts +0 -1
  277. package/dist/tests/sdk.integration.test.js +0 -330
  278. package/dist/tests/shield-owner.test.d.ts +0 -1
  279. package/dist/tests/shield-owner.test.js +0 -89
  280. package/dist/tests/shield-preflight.test.d.ts +0 -1
  281. package/dist/tests/shield-preflight.test.js +0 -87
  282. package/dist/tests/shield-realproof.test.d.ts +0 -1
  283. package/dist/tests/shield-realproof.test.js +0 -272
  284. package/dist/tests/shield.test.d.ts +0 -1
  285. package/dist/tests/shield.test.js +0 -403
  286. package/dist/tests/utxo.test.d.ts +0 -1
  287. package/dist/tests/utxo.test.js +0 -140
  288. package/poseidon.d.ts +0 -2
  289. package/poseidon.js +0 -4
  290. package/proof.d.ts +0 -2
  291. package/proof.js +0 -4
  292. package/prover.d.ts +0 -2
  293. package/prover.js +0 -4
  294. package/shield.d.ts +0 -2
  295. package/shield.js +0 -4
  296. /package/dist/{src/shield → cjs/proofs}/types.js +0 -0
@@ -1,407 +0,0 @@
1
- import * as anchor from "@coral-xyz/anchor";
2
- import type { Program, Idl } from "@coral-xyz/anchor";
3
- import { PublicKey, Transaction, Keypair } from "@solana/web3.js";
4
- import { TransactionProofStruct, TransactionProofBuilder, ExtData } from "./proof.js";
5
- import { SerializedUTXO, InputUTXO } from "./utxo.js";
6
- import { MerkleTree } from "./merkle.js";
7
- import { PrivacyConfigAccount } from "./config.js";
8
- /**
9
- * Get pool PDAs for a given mint address.
10
- * Note: All seeds use "v3" suffix.
11
- */
12
- export declare function getPoolPdas(programId: PublicKey, mintAddress: PublicKey): {
13
- config: anchor.web3.PublicKey;
14
- vault: anchor.web3.PublicKey;
15
- nullifiers: anchor.web3.PublicKey;
16
- };
17
- /**
18
- * Get the note tree PDA for a specific tree ID.
19
- */
20
- export declare function getNoteTreePda(programId: PublicKey, mintAddress: PublicKey, treeId: number): PublicKey;
21
- /**
22
- * Get the global config PDA.
23
- */
24
- export declare function getGlobalConfigPda(programId: PublicKey): PublicKey;
25
- /**
26
- * Get the nullifier marker PDA for a specific nullifier.
27
- * NOTE: Nullifier markers are global (no tree_id) to prevent cross-tree double-spend.
28
- */
29
- export declare function getNullifierMarkerPda(programId: PublicKey, mintAddress: PublicKey, nullifier: Uint8Array): PublicKey;
30
- /**
31
- * Fetch and decode the on-chain PrivacyConfig account for a pool.
32
- */
33
- export declare function fetchPoolConfig<T extends Idl>(program: Program<T>, mintAddress: PublicKey): Promise<PrivacyConfigAccount>;
34
- /**
35
- * Check whether a nullifier has been spent on-chain.
36
- * Returns true if the nullifier marker PDA exists (funds already spent).
37
- */
38
- export declare function checkNullifierSpent<T extends Idl>(program: Program<T>, mintAddress: PublicKey, nullifier: Uint8Array): Promise<boolean>;
39
- /** On-chain tree utilization info */
40
- export type TreeInfo = {
41
- treeId: number;
42
- leafCount: number;
43
- capacity: number;
44
- utilizationPercent: number;
45
- remainingCapacity: number;
46
- isFull: boolean;
47
- treePDA: PublicKey;
48
- };
49
- /**
50
- * Fetch utilization info for a specific tree.
51
- * Returns null if the tree does not exist yet.
52
- */
53
- export declare function getTreeInfo<T extends Idl>(program: Program<T>, mintAddress: PublicKey, treeId: number): Promise<TreeInfo | null>;
54
- /**
55
- * Fetch utilization info for all trees in a pool.
56
- */
57
- export declare function getAllTreeInfo<T extends Idl>(program: Program<T>, mintAddress: PublicKey): Promise<TreeInfo[]>;
58
- /**
59
- * Find the best tree to deposit into.
60
- *
61
- * Strategy (matches veilo-dapp):
62
- * 1. Discard full trees.
63
- * 2. Prefer the LOWEST tree ID with remaining capacity ≥ minCapacity (default 0.01%).
64
- * 3. Ensures trees fill sequentially: 0 → 1 → 2 → …
65
- * 4. Fallback to the tree with the most remaining capacity.
66
- */
67
- export declare function getBestTreeForDeposit<T extends Idl>(program: Program<T>, mintAddress: PublicKey, minCapacity?: number): Promise<TreeInfo | null>;
68
- /**
69
- * Convert a Solana/Anchor transaction error into a user-friendly message.
70
- * Maps privacy_pool program error codes (6000–6060) to readable strings.
71
- * Mirrors relayer-server/src/controllers/transaction.helpers.ts `parseOnChainError`.
72
- */
73
- export declare function parseOnChainError(error: any): string;
74
- /**
75
- * Initialize the global config (one-time setup).
76
- */
77
- export declare function initializeGlobalConfig<T extends Idl>(params: {
78
- program: Program<T>;
79
- admin: anchor.Wallet;
80
- payer: Keypair;
81
- }): Promise<void>;
82
- /**
83
- * Initialize a privacy pool with the new parameters.
84
- * Creates the first merkle tree (tree ID 0).
85
- */
86
- export declare function initializePool<T extends Idl>(params: {
87
- program: Program<T>;
88
- admin: anchor.Wallet;
89
- payer: Keypair;
90
- feeBps: number;
91
- mintAddress: PublicKey;
92
- minDepositAmount?: bigint;
93
- maxDepositAmount?: bigint;
94
- minWithdrawAmount?: bigint;
95
- maxWithdrawAmount?: bigint;
96
- }): Promise<void>;
97
- /**
98
- * Update pool configuration.
99
- */
100
- export declare function updatePoolConfig<T extends Idl>(params: {
101
- program: Program<T>;
102
- admin: anchor.Wallet;
103
- mintAddress: PublicKey;
104
- minDepositAmount?: bigint;
105
- maxDepositAmount?: bigint;
106
- minWithdrawAmount?: bigint;
107
- maxWithdrawAmount?: bigint;
108
- feeBps?: number;
109
- feeErrorMarginBps?: number;
110
- minWithdrawalFee?: bigint;
111
- minSwapFee?: bigint;
112
- swapFeeBps?: number;
113
- }): Promise<void>;
114
- /**
115
- * Add a new Merkle tree to the pool.
116
- * The treeId must equal the current num_trees value in the pool config.
117
- */
118
- export declare function addMerkleTree<T extends Idl>(params: {
119
- program: Program<T>;
120
- relayer: Keypair;
121
- mintAddress: PublicKey;
122
- treeId: number;
123
- }): Promise<void>;
124
- /**
125
- * Get the pool configuration account.
126
- */
127
- export declare function getPoolConfig<T extends Idl>(program: Program<T>, mintAddress: PublicKey): Promise<PrivacyConfigAccount>;
128
- /**
129
- * Add a relayer to the pool.
130
- */
131
- export declare function addRelayer<T extends Idl>(params: {
132
- program: Program<T>;
133
- admin: anchor.Wallet;
134
- mintAddress: PublicKey;
135
- newRelayer: PublicKey;
136
- }): Promise<void>;
137
- /**
138
- * Set the paused state of a pool.
139
- */
140
- export declare function setPaused<T extends Idl>(params: {
141
- program: Program<T>;
142
- admin: anchor.Wallet;
143
- mintAddress: PublicKey;
144
- paused: boolean;
145
- }): Promise<void>;
146
- /**
147
- * Execute a transaction on the privacy pool.
148
- * This is the low-level function that calls the on-chain `transact` instruction.
149
- *
150
- * @param publicAmount - Positive for deposits, negative for withdrawals, 0 for transfers
151
- * @param inputTreeId - The tree ID where input UTXOs are located
152
- * @param outputTreeId - The tree ID where output commitments will be inserted
153
- */
154
- export declare function transact<T extends Idl>(params: {
155
- program: Program<T>;
156
- relayer: Keypair;
157
- recipient: PublicKey;
158
- mintAddress: PublicKey;
159
- root: Uint8Array;
160
- inputTreeId: number;
161
- outputTreeId: number;
162
- publicAmount: bigint;
163
- inputNullifiers: [Uint8Array, Uint8Array];
164
- outputCommitments: [Uint8Array, Uint8Array];
165
- extData: ExtData;
166
- proof: TransactionProofStruct;
167
- /** Unix timestamp after which the tx is invalid. Defaults to 0 (no deadline). */
168
- deadline?: bigint;
169
- vaultTokenAccount?: PublicKey;
170
- userTokenAccount?: PublicKey;
171
- recipientTokenAccount?: PublicKey;
172
- relayerTokenAccount?: PublicKey;
173
- }): Promise<string>;
174
- /**
175
- * Result of a deposit operation, produced by `DepositBuild.commit()` after the
176
- * caller has successfully submitted the deposit transaction on-chain.
177
- */
178
- export type DepositResult = {
179
- /** The output UTXOs created by the deposit */
180
- outputUTXOs: [SerializedUTXO, SerializedUTXO];
181
- /** The leaf indices where the UTXOs were inserted */
182
- leafIndices: [number, number];
183
- /** The new Merkle root after insertion */
184
- root: Uint8Array;
185
- };
186
- /**
187
- * The return of `deposit()`. Instead of submitting the transaction itself,
188
- * `deposit()` hands back an unsigned {@link Transaction} so the caller can
189
- * sign it with whatever wallet they control (Solana wallet-adapter, Ledger,
190
- * anchor NodeWallet, etc.) and submit it on their own terms.
191
- *
192
- * Usage pattern (browser / wallet-adapter):
193
- *
194
- * const { transaction, commit } = await deposit({ ... });
195
- * const signed = await wallet.signTransaction(transaction);
196
- * const sig = await connection.sendRawTransaction(signed.serialize());
197
- * await connection.confirmTransaction(sig, "confirmed");
198
- * const result = commit(); // updates the local tree, returns DepositResult
199
- */
200
- export type DepositBuild = {
201
- /**
202
- * Unsigned {@link Transaction} for the deposit. `feePayer` and
203
- * `recentBlockhash` are already populated, so the caller only needs to sign
204
- * and send.
205
- */
206
- transaction: Transaction;
207
- /**
208
- * Output UTXOs created by this deposit. Safe to read before submission —
209
- * the commitment values are deterministic from the circuit inputs and do
210
- * not depend on the on-chain result.
211
- */
212
- outputUTXOs: [SerializedUTXO, SerializedUTXO];
213
- /**
214
- * Inserts the two output commitments into the local {@link MerkleTree} and
215
- * returns the receipt. Call this **only after** the on-chain transaction
216
- * has been confirmed — deferring the insert keeps the local tree
217
- * consistent with chain state if the submission fails.
218
- *
219
- * Calling `commit()` more than once is unsupported and will corrupt the
220
- * local tree.
221
- */
222
- commit: () => DepositResult;
223
- };
224
- /**
225
- * Build an unsigned deposit {@link Transaction} for the privacy pool.
226
- *
227
- * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs
228
- * with the deposit amount. `publicAmount` is positive. The caller is
229
- * responsible for signing and submitting the returned transaction, and then
230
- * calling `commit()` once it confirms.
231
- *
232
- * @param amount - Amount to deposit in lamports/token units
233
- * @param recipientPubkey - UTXO public key that will own the deposited funds
234
- * @param treeId - The tree ID to deposit into (defaults to 0)
235
- */
236
- export declare function deposit<T extends Idl>(params: {
237
- program: Program<T>;
238
- /**
239
- * Account that will pay for and sign the deposit transaction. Only
240
- * `publicKey` is read — `deposit()` never touches a secret key. A browser
241
- * wallet-adapter wallet, a Node `anchor.Wallet`, or a raw `Keypair` are all
242
- * structurally acceptable.
243
- */
244
- depositor: {
245
- publicKey: PublicKey;
246
- };
247
- amount: bigint;
248
- mintAddress: PublicKey;
249
- recipientPubkey: bigint;
250
- tree: MerkleTree;
251
- proofBuilder: TransactionProofBuilder;
252
- treeId?: number;
253
- extData?: Partial<ExtData>;
254
- }): Promise<DepositBuild>;
255
- /**
256
- * Result of a withdrawal operation.
257
- */
258
- export type WithdrawResult = {
259
- /** Change UTXO (remaining balance) */
260
- changeUTXO: SerializedUTXO;
261
- /** Leaf index of the change UTXO */
262
- leafIndex: number;
263
- /** New Merkle root after insertion */
264
- root: Uint8Array;
265
- };
266
- /**
267
- * Withdraw funds from the privacy pool.
268
- *
269
- * For withdrawals, we spend input UTXOs and create change output UTXOs.
270
- * The publicAmount is negative (funds flowing out).
271
- *
272
- * @param withdrawAmount - Amount to withdraw in lamports/token units
273
- * @param inputUTXOs - The UTXOs being spent
274
- * @param changePubkey - UTXO public key for the change output
275
- * @param inputTreeId - The tree ID where input UTXOs are located
276
- * @param outputTreeId - The tree ID where change outputs will be inserted
277
- */
278
- export declare function withdraw<T extends Idl>(params: {
279
- program: Program<T>;
280
- relayer: Keypair;
281
- recipient: PublicKey;
282
- mintAddress: PublicKey;
283
- inputUTXOs: [InputUTXO, InputUTXO];
284
- changePubkey: bigint;
285
- withdrawAmount: bigint;
286
- fee: bigint;
287
- refund: bigint;
288
- root: Uint8Array;
289
- inputTreeId: number;
290
- outputTreeId: number;
291
- tree: MerkleTree;
292
- proofBuilder: TransactionProofBuilder;
293
- }): Promise<WithdrawResult>;
294
- /**
295
- * Result of a private transfer operation.
296
- */
297
- export type TransferResult = {
298
- /** Output UTXOs created by the transfer */
299
- outputUTXOs: [SerializedUTXO, SerializedUTXO];
300
- /** Leaf indices where the UTXOs were inserted */
301
- leafIndices: [number, number];
302
- /** New Merkle root after insertion */
303
- root: Uint8Array;
304
- };
305
- /**
306
- * Execute a private transfer within the pool.
307
- *
308
- * For transfers, the publicAmount is 0 (no funds enter or leave the pool).
309
- * Input amounts must equal output amounts.
310
- *
311
- * @param inputUTXOs - The UTXOs being spent
312
- * @param outputPubkeys - UTXO public keys for the recipients
313
- * @param outputAmounts - Amounts for each output (must sum to input total)
314
- * @param inputTreeId - The tree ID where input UTXOs are located
315
- * @param outputTreeId - The tree ID where output commitments will be inserted
316
- */
317
- export declare function privateTransfer<T extends Idl>(params: {
318
- program: Program<T>;
319
- relayer: Keypair;
320
- mintAddress: PublicKey;
321
- inputUTXOs: [InputUTXO, InputUTXO];
322
- outputPubkeys: [bigint, bigint];
323
- outputAmounts: [bigint, bigint];
324
- root: Uint8Array;
325
- inputTreeId: number;
326
- outputTreeId: number;
327
- tree: MerkleTree;
328
- proofBuilder: TransactionProofBuilder;
329
- fee?: bigint;
330
- }): Promise<TransferResult>;
331
- /**
332
- * Update the global config.
333
- * Currently takes no extra args — only admin verification.
334
- */
335
- export declare function updateGlobalConfig<T extends Idl>(params: {
336
- program: Program<T>;
337
- admin: anchor.Wallet;
338
- }): Promise<void>;
339
- /**
340
- * Get the swap executor PDA.
341
- * Seeds: ["swap_executor", source_mint, dest_mint, input_nullifier_0, relayer]
342
- */
343
- export declare function getSwapExecutorPda(programId: PublicKey, sourceMint: PublicKey, destMint: PublicKey, inputNullifier0: Uint8Array, relayer: PublicKey): PublicKey;
344
- /**
345
- * Build the `fund_native_source` instruction that pre-funds the swap executor
346
- * with native SOL from the source vault. Only for native SOL source pools.
347
- *
348
- * This instruction MUST be the first instruction in the same atomic transaction
349
- * as `transactSwap`. Call `transactSwap` directly — it handles this internally.
350
- */
351
- export declare function fundNativeSource<T extends Idl>(params: {
352
- program: Program<T>;
353
- relayer: Keypair;
354
- sourceMint: PublicKey;
355
- destMint: PublicKey;
356
- inputNullifier0: Uint8Array;
357
- swapAmount: bigint;
358
- }): Promise<anchor.web3.TransactionInstruction>;
359
- /**
360
- * Swap proof struct (same encoding as TransactionProofStruct).
361
- */
362
- export type SwapProofStruct = TransactionProofStruct;
363
- /**
364
- * Swap params committed to in the ZK proof.
365
- */
366
- export type SwapParams = {
367
- minAmountOut: bigint;
368
- deadline: bigint;
369
- sourceMint: PublicKey;
370
- destMint: PublicKey;
371
- destAmount: bigint;
372
- /** SHA-256 of raw swap instruction bytes; use all-zeros for CPMM/AMM swaps. */
373
- swapDataHash: Uint8Array;
374
- };
375
- /**
376
- * Execute an atomic cross-pool private swap.
377
- *
378
- * For native SOL source pools (`sourceMint === NATIVE_SOL_MINT`), this function
379
- * automatically prepends the `fund_native_source` instruction in the same
380
- * transaction so the on-chain atomicity requirement is always satisfied.
381
- *
382
- * @param swapProgram - Jupiter/Raydium CPMM/AMM program ID
383
- * @param swapData - Raw DEX instruction bytes
384
- */
385
- export declare function transactSwap<T extends Idl>(params: {
386
- program: Program<T>;
387
- relayer: Keypair;
388
- sourceMint: PublicKey;
389
- destMint: PublicKey;
390
- sourceRoot: Uint8Array;
391
- sourceTreeId: number;
392
- destTreeId: number;
393
- inputNullifiers: [Uint8Array, Uint8Array];
394
- outputCommitments: [Uint8Array, Uint8Array];
395
- proof: SwapProofStruct;
396
- swapParams: SwapParams;
397
- swapAmount: bigint;
398
- swapData: Buffer;
399
- extData: ExtData;
400
- sourceVaultTokenAccount: PublicKey;
401
- sourceMintAccount: PublicKey;
402
- destVaultTokenAccount: PublicKey;
403
- destMintAccount: PublicKey;
404
- relayerTokenAccount: PublicKey;
405
- swapProgram: PublicKey;
406
- jupiterEventAuthority: PublicKey;
407
- }): Promise<string>;