@veilo/sdk-core 0.3.3 → 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 (251) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +289 -1262
  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 +17 -912
  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 +128 -0
  32. package/dist/cjs/compactNote.js +191 -0
  33. package/dist/cjs/events.d.ts +1 -1
  34. package/dist/cjs/events.js +2 -2
  35. package/dist/cjs/idl/privacy_pool.d.ts +5 -0
  36. package/dist/cjs/idl/privacy_pool.js +15218 -0
  37. package/dist/cjs/index.d.ts +17 -13
  38. package/dist/cjs/index.js +43 -30
  39. package/dist/cjs/merkle.d.ts +13 -0
  40. package/dist/cjs/merkle.js +31 -8
  41. package/dist/cjs/notes/encryption.d.ts +41 -0
  42. package/dist/cjs/notes/encryption.js +75 -0
  43. package/dist/cjs/notes/index.d.ts +5 -0
  44. package/dist/cjs/notes/index.js +21 -0
  45. package/dist/cjs/notes/mailbox.d.ts +70 -0
  46. package/dist/cjs/notes/mailbox.js +164 -0
  47. package/dist/cjs/notes/model.d.ts +91 -0
  48. package/dist/cjs/notes/model.js +109 -0
  49. package/dist/cjs/notes/nullifier.d.ts +27 -0
  50. package/dist/cjs/notes/nullifier.js +45 -0
  51. package/dist/cjs/notes/recovery.d.ts +10 -0
  52. package/dist/cjs/notes/recovery.js +31 -0
  53. package/dist/cjs/program.d.ts +11 -0
  54. package/dist/cjs/program.js +26 -3
  55. package/dist/cjs/proof.d.ts +1 -183
  56. package/dist/cjs/proof.js +16 -290
  57. package/dist/cjs/proofs/encoding.d.ts +17 -0
  58. package/dist/cjs/proofs/encoding.js +72 -0
  59. package/dist/cjs/proofs/formatting.d.ts +6 -0
  60. package/dist/cjs/proofs/formatting.js +34 -0
  61. package/dist/cjs/proofs/index.d.ts +5 -0
  62. package/dist/cjs/proofs/index.js +21 -0
  63. package/dist/cjs/proofs/swap.d.ts +87 -0
  64. package/dist/cjs/proofs/swap.js +144 -0
  65. package/dist/cjs/proofs/transaction.d.ts +28 -0
  66. package/dist/cjs/proofs/transaction.js +110 -0
  67. package/dist/cjs/proofs/types.d.ts +70 -0
  68. package/dist/cjs/proofs/types.js +2 -0
  69. package/dist/cjs/prover.d.ts +4 -1
  70. package/dist/cjs/prover.js +12 -2
  71. package/dist/cjs/random.d.ts +16 -0
  72. package/dist/cjs/random.js +28 -0
  73. package/dist/cjs/relayer/client.d.ts +61 -0
  74. package/dist/cjs/relayer/client.js +151 -0
  75. package/dist/cjs/relayer/crypto.d.ts +5 -0
  76. package/dist/cjs/relayer/crypto.js +26 -0
  77. package/dist/cjs/relayer/encoding.d.ts +2 -0
  78. package/dist/cjs/relayer/encoding.js +23 -0
  79. package/dist/cjs/relayer/errors.d.ts +7 -0
  80. package/dist/cjs/relayer/errors.js +17 -0
  81. package/dist/cjs/relayer/index.d.ts +3 -0
  82. package/dist/cjs/relayer/index.js +19 -0
  83. package/dist/cjs/relayer/transport.d.ts +17 -0
  84. package/dist/cjs/relayer/transport.js +63 -0
  85. package/dist/cjs/relayer/types.d.ts +276 -0
  86. package/dist/cjs/relayer/types.js +5 -0
  87. package/dist/cjs/relayer.d.ts +1 -295
  88. package/dist/cjs/relayer.js +15 -243
  89. package/dist/cjs/shield/alt.d.ts +87 -0
  90. package/dist/cjs/shield/alt.js +194 -0
  91. package/dist/cjs/shield/computeBudget.d.ts +61 -0
  92. package/dist/cjs/shield/computeBudget.js +64 -0
  93. package/dist/cjs/shield/errors.d.ts +58 -0
  94. package/dist/cjs/shield/errors.js +121 -0
  95. package/dist/cjs/shield/finalize.d.ts +45 -0
  96. package/dist/cjs/shield/finalize.js +119 -0
  97. package/dist/cjs/shield/index.d.ts +35 -0
  98. package/dist/cjs/shield/index.js +68 -0
  99. package/dist/cjs/shield/ix.d.ts +54 -0
  100. package/dist/cjs/shield/ix.js +119 -0
  101. package/dist/cjs/shield/owner.d.ts +36 -0
  102. package/dist/cjs/shield/owner.js +127 -0
  103. package/dist/cjs/shield/ports.d.ts +43 -0
  104. package/dist/cjs/shield/ports.js +153 -0
  105. package/dist/cjs/shield/preflight.d.ts +30 -0
  106. package/dist/cjs/shield/preflight.js +154 -0
  107. package/dist/cjs/shield/shield.d.ts +68 -0
  108. package/dist/cjs/shield/shield.js +500 -0
  109. package/dist/cjs/shield/types.d.ts +202 -0
  110. package/dist/cjs/shield/types.js +2 -0
  111. package/dist/cjs/transactions/deposit.d.ts +94 -0
  112. package/dist/cjs/transactions/deposit.js +234 -0
  113. package/dist/cjs/transactions/index.d.ts +7 -0
  114. package/dist/cjs/transactions/index.js +26 -0
  115. package/dist/cjs/transactions/swap.d.ts +71 -0
  116. package/dist/cjs/transactions/swap.js +184 -0
  117. package/dist/cjs/transactions/transact.d.ts +34 -0
  118. package/dist/cjs/transactions/transact.js +146 -0
  119. package/dist/cjs/transactions/transfer.d.ts +51 -0
  120. package/dist/cjs/transactions/transfer.js +106 -0
  121. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  122. package/dist/cjs/transactions/withdraw.js +104 -0
  123. package/dist/cjs/utxo.d.ts +1 -215
  124. package/dist/cjs/utxo.js +15 -391
  125. package/dist/esm/accounts/admin.d.ts +84 -0
  126. package/dist/esm/accounts/admin.js +165 -0
  127. package/dist/esm/accounts/errors.d.ts +6 -0
  128. package/dist/esm/accounts/errors.js +95 -0
  129. package/dist/esm/accounts/index.d.ts +4 -0
  130. package/dist/esm/accounts/index.js +4 -0
  131. package/dist/esm/accounts/pdas.d.ts +23 -0
  132. package/dist/esm/accounts/pdas.js +38 -0
  133. package/dist/esm/accounts/queries.d.ts +41 -0
  134. package/dist/esm/accounts/queries.js +88 -0
  135. package/dist/esm/client.d.ts +2 -0
  136. package/dist/esm/client.js +3 -887
  137. package/dist/esm/cloak/client.d.ts +28 -0
  138. package/dist/esm/cloak/client.js +64 -0
  139. package/dist/esm/cloak/errors.d.ts +13 -0
  140. package/dist/esm/cloak/errors.js +21 -0
  141. package/dist/esm/cloak/helpers.d.ts +6 -0
  142. package/dist/esm/cloak/helpers.js +31 -0
  143. package/dist/esm/cloak/index.d.ts +6 -0
  144. package/dist/esm/cloak/index.js +6 -0
  145. package/dist/esm/cloak/polling.d.ts +7 -0
  146. package/dist/esm/cloak/polling.js +63 -0
  147. package/dist/esm/cloak/transport.d.ts +15 -0
  148. package/dist/esm/cloak/transport.js +115 -0
  149. package/dist/esm/cloak/types.d.ts +188 -0
  150. package/dist/esm/cloak/types.js +4 -0
  151. package/dist/esm/cloak.d.ts +1 -0
  152. package/dist/esm/cloak.js +2 -0
  153. package/dist/esm/compactNote.d.ts +128 -0
  154. package/dist/esm/compactNote.js +179 -0
  155. package/dist/esm/config.d.ts +82 -0
  156. package/dist/esm/events.d.ts +77 -0
  157. package/dist/esm/events.js +1 -1
  158. package/dist/esm/idl/privacy_pool.d.ts +5 -0
  159. package/dist/esm/idl/privacy_pool.js +15216 -0
  160. package/dist/esm/index.d.ts +17 -0
  161. package/dist/esm/index.js +20 -11
  162. package/dist/esm/merkle.d.ts +77 -0
  163. package/dist/esm/merkle.js +23 -1
  164. package/dist/esm/notes/encryption.d.ts +41 -0
  165. package/dist/esm/notes/encryption.js +67 -0
  166. package/dist/esm/notes/index.d.ts +5 -0
  167. package/dist/esm/notes/index.js +5 -0
  168. package/dist/esm/notes/mailbox.d.ts +70 -0
  169. package/dist/esm/notes/mailbox.js +154 -0
  170. package/dist/esm/notes/model.d.ts +91 -0
  171. package/dist/esm/notes/model.js +99 -0
  172. package/dist/esm/notes/nullifier.d.ts +27 -0
  173. package/dist/esm/notes/nullifier.js +40 -0
  174. package/dist/esm/notes/recovery.d.ts +10 -0
  175. package/dist/esm/notes/recovery.js +28 -0
  176. package/dist/esm/package.json +1 -0
  177. package/dist/esm/poseidon.d.ts +29 -0
  178. package/dist/esm/program.d.ts +37 -0
  179. package/dist/esm/program.js +23 -1
  180. package/dist/esm/proof.d.ts +1 -0
  181. package/dist/esm/proof.js +2 -281
  182. package/dist/esm/proofs/encoding.d.ts +17 -0
  183. package/dist/esm/proofs/encoding.js +68 -0
  184. package/dist/esm/proofs/formatting.d.ts +6 -0
  185. package/dist/esm/proofs/formatting.js +31 -0
  186. package/dist/esm/proofs/index.d.ts +5 -0
  187. package/dist/esm/proofs/index.js +5 -0
  188. package/dist/esm/proofs/swap.d.ts +87 -0
  189. package/dist/esm/proofs/swap.js +138 -0
  190. package/dist/esm/proofs/transaction.d.ts +28 -0
  191. package/dist/esm/proofs/transaction.js +105 -0
  192. package/dist/esm/proofs/types.d.ts +70 -0
  193. package/dist/esm/proofs/types.js +1 -0
  194. package/dist/esm/prover.d.ts +57 -0
  195. package/dist/esm/prover.js +10 -1
  196. package/dist/esm/random.d.ts +16 -0
  197. package/dist/esm/random.js +21 -0
  198. package/dist/esm/relayer/client.d.ts +61 -0
  199. package/dist/esm/relayer/client.js +144 -0
  200. package/dist/esm/relayer/crypto.d.ts +5 -0
  201. package/dist/esm/relayer/crypto.js +20 -0
  202. package/dist/esm/relayer/encoding.d.ts +2 -0
  203. package/dist/esm/relayer/encoding.js +19 -0
  204. package/dist/esm/relayer/errors.d.ts +7 -0
  205. package/dist/esm/relayer/errors.js +13 -0
  206. package/dist/esm/relayer/index.d.ts +3 -0
  207. package/dist/esm/relayer/index.js +3 -0
  208. package/dist/esm/relayer/transport.d.ts +17 -0
  209. package/dist/esm/relayer/transport.js +59 -0
  210. package/dist/esm/relayer/types.d.ts +276 -0
  211. package/dist/esm/relayer/types.js +4 -0
  212. package/dist/esm/relayer.d.ts +1 -0
  213. package/dist/esm/relayer.js +2 -238
  214. package/dist/esm/retry.d.ts +32 -0
  215. package/dist/esm/shield/alt.d.ts +87 -0
  216. package/dist/esm/shield/alt.js +186 -0
  217. package/dist/esm/shield/computeBudget.d.ts +61 -0
  218. package/dist/esm/shield/computeBudget.js +61 -0
  219. package/dist/esm/shield/errors.d.ts +58 -0
  220. package/dist/esm/shield/errors.js +115 -0
  221. package/dist/esm/shield/finalize.d.ts +45 -0
  222. package/dist/esm/shield/finalize.js +83 -0
  223. package/dist/esm/shield/index.d.ts +35 -0
  224. package/dist/esm/shield/index.js +32 -0
  225. package/dist/esm/shield/ix.d.ts +54 -0
  226. package/dist/esm/shield/ix.js +82 -0
  227. package/dist/esm/shield/owner.d.ts +36 -0
  228. package/dist/esm/shield/owner.js +123 -0
  229. package/dist/esm/shield/ports.d.ts +43 -0
  230. package/dist/esm/shield/ports.js +147 -0
  231. package/dist/esm/shield/preflight.d.ts +30 -0
  232. package/dist/esm/shield/preflight.js +151 -0
  233. package/dist/esm/shield/shield.d.ts +68 -0
  234. package/dist/esm/shield/shield.js +493 -0
  235. package/dist/esm/shield/types.d.ts +202 -0
  236. package/dist/esm/shield/types.js +1 -0
  237. package/dist/esm/transactions/deposit.d.ts +94 -0
  238. package/dist/esm/transactions/deposit.js +198 -0
  239. package/dist/esm/transactions/index.d.ts +7 -0
  240. package/dist/esm/transactions/index.js +7 -0
  241. package/dist/esm/transactions/swap.d.ts +71 -0
  242. package/dist/esm/transactions/swap.js +144 -0
  243. package/dist/esm/transactions/transact.d.ts +34 -0
  244. package/dist/esm/transactions/transact.js +110 -0
  245. package/dist/esm/transactions/transfer.d.ts +51 -0
  246. package/dist/esm/transactions/transfer.js +103 -0
  247. package/dist/esm/transactions/withdraw.d.ts +52 -0
  248. package/dist/esm/transactions/withdraw.js +101 -0
  249. package/dist/esm/utxo.d.ts +1 -0
  250. package/dist/esm/utxo.js +2 -372
  251. package/package.json +111 -15
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareSwapInputs = prepareSwapInputs;
4
+ exports.formatSwapInputsForSnarkjs = formatSwapInputsForSnarkjs;
5
+ exports.computeSwapParamsHash = computeSwapParamsHash;
6
+ exports.computeSwapDataHash = computeSwapDataHash;
7
+ const sha256_1 = require("@noble/hashes/sha256");
8
+ const poseidon_js_1 = require("../poseidon.js");
9
+ const nullifier_js_1 = require("../notes/nullifier.js");
10
+ const transaction_js_1 = require("./transaction.js");
11
+ /**
12
+ * Prepare the exact witness/public inputs used by the relayer's swap circuit.
13
+ * Output 0 must be source-mint change and output 1 the destination-mint note.
14
+ */
15
+ function prepareSwapInputs(params) {
16
+ const { inputUTXOs, changeUTXO, destUTXO, sourceRoot, sourceMint, destMint, swapAmount, minAmountOut, deadline, extData, } = params;
17
+ const totalInput = inputUTXOs[0].amount + inputUTXOs[1].amount;
18
+ if (swapAmount <= 0n)
19
+ throw new Error("swapAmount must be positive");
20
+ if (deadline <= 0n) {
21
+ throw new Error("deadline must be a positive Unix timestamp");
22
+ }
23
+ if (totalInput !== swapAmount + changeUTXO.amount) {
24
+ throw new Error(`Swap balance mismatch: inputs=${totalInput}, swap=${swapAmount}, change=${changeUTXO.amount}`);
25
+ }
26
+ if (destUTXO.amount < minAmountOut) {
27
+ throw new Error("Destination note amount is below minAmountOut");
28
+ }
29
+ if (changeUTXO.mintAddress !== (0, poseidon_js_1.pubkeyToField)(sourceMint)) {
30
+ throw new Error("Change UTXO must use the source mint");
31
+ }
32
+ if (destUTXO.mintAddress !== (0, poseidon_js_1.pubkeyToField)(destMint)) {
33
+ throw new Error("Destination UTXO must use the destination mint");
34
+ }
35
+ return {
36
+ sourceRoot,
37
+ swapParamsHash: computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destUTXO.amount),
38
+ extDataHash: (0, transaction_js_1.computeExtDataHash)(extData),
39
+ sourceMint,
40
+ destMint,
41
+ inputNullifiers: [
42
+ (0, nullifier_js_1.deriveNullifier)(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
43
+ (0, nullifier_js_1.deriveNullifier)(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
44
+ ],
45
+ changeCommitment: changeUTXO.commitment,
46
+ destCommitment: destUTXO.commitment,
47
+ swapAmount,
48
+ inAmount: [inputUTXOs[0].amount, inputUTXOs[1].amount],
49
+ inPubkey: [inputUTXOs[0].pubkey, inputUTXOs[1].pubkey],
50
+ inBlinding: [inputUTXOs[0].blinding, inputUTXOs[1].blinding],
51
+ inPathIndex: [inputUTXOs[0].pathIndex, inputUTXOs[1].pathIndex],
52
+ inPathElements: [
53
+ inputUTXOs[0].pathElements.map((element) => (0, poseidon_js_1.bytesToBigIntBE)(element) % poseidon_js_1.BN254_FR_MODULUS),
54
+ inputUTXOs[1].pathElements.map((element) => (0, poseidon_js_1.bytesToBigIntBE)(element) % poseidon_js_1.BN254_FR_MODULUS),
55
+ ],
56
+ inPrivateKey: [inputUTXOs[0].privateKey, inputUTXOs[1].privateKey],
57
+ changeAmount: changeUTXO.amount,
58
+ changePubkey: changeUTXO.pubkey,
59
+ changeBlinding: changeUTXO.blinding,
60
+ destAmount: destUTXO.amount,
61
+ destPubkey: destUTXO.pubkey,
62
+ destBlinding: destUTXO.blinding,
63
+ minAmountOut,
64
+ deadline,
65
+ };
66
+ }
67
+ /**
68
+ * Convert SwapCircuitInputs into the shape expected by
69
+ * snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
70
+ * decimal string (or string array) because snarkjs only accepts field
71
+ * elements as strings.
72
+ *
73
+ * Mirrors `generateSwapProof` in
74
+ * relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
75
+ * verify against the same circuit the relayer uses.
76
+ */
77
+ function formatSwapInputsForSnarkjs(inputs) {
78
+ return {
79
+ // Public inputs
80
+ sourceRoot: (0, poseidon_js_1.bytesToBigIntBE)(inputs.sourceRoot).toString(),
81
+ swapParamsHash: (0, poseidon_js_1.bytesToBigIntBE)(inputs.swapParamsHash).toString(),
82
+ extDataHash: (0, poseidon_js_1.bytesToBigIntBE)(inputs.extDataHash).toString(),
83
+ sourceMint: (0, poseidon_js_1.pubkeyToField)(inputs.sourceMint).toString(),
84
+ destMint: (0, poseidon_js_1.pubkeyToField)(inputs.destMint).toString(),
85
+ inputNullifier: inputs.inputNullifiers.map((n) => (0, poseidon_js_1.bytesToBigIntBE)(n).toString()),
86
+ changeCommitment: (0, poseidon_js_1.bytesToBigIntBE)(inputs.changeCommitment).toString(),
87
+ destCommitment: (0, poseidon_js_1.bytesToBigIntBE)(inputs.destCommitment).toString(),
88
+ swapAmount: inputs.swapAmount.toString(),
89
+ // Private inputs - Input UTXOs
90
+ inAmount: inputs.inAmount.map((a) => a.toString()),
91
+ inPubkey: inputs.inPubkey.map((p) => p.toString()),
92
+ inBlinding: inputs.inBlinding.map((b) => b.toString()),
93
+ inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
94
+ inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
95
+ inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
96
+ // Private inputs - Change UTXO
97
+ changeAmount: inputs.changeAmount.toString(),
98
+ changePubkey: inputs.changePubkey.toString(),
99
+ changeBlinding: inputs.changeBlinding.toString(),
100
+ // Private inputs - Destination UTXO
101
+ destAmount: inputs.destAmount.toString(),
102
+ destPubkey: inputs.destPubkey.toString(),
103
+ destBlinding: inputs.destBlinding.toString(),
104
+ // Swap params
105
+ minAmountOut: inputs.minAmountOut.toString(),
106
+ deadline: inputs.deadline.toString(),
107
+ };
108
+ }
109
+ // -----------------------------------------------------------------------------
110
+ // Swap Parameter Hashing
111
+ // -----------------------------------------------------------------------------
112
+ /**
113
+ * Compute the swap params hash that the swap circuit and on-chain program verify.
114
+ * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
115
+ *
116
+ * Circuit formula (swap.circom lines 293-307):
117
+ * mintPairHash = Poseidon(sourceMint, destMint)
118
+ * swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
119
+ * swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
120
+ *
121
+ * @param sourceMint Source pool mint
122
+ * @param destMint Destination pool mint
123
+ * @param minAmountOut Minimum accepted output amount (slippage protected)
124
+ * @param deadline Positive Unix timestamp deadline (the program rejects 0)
125
+ * @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
126
+ * relayerFee). If omitted, defaults to minAmountOut.
127
+ */
128
+ function computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destAmount) {
129
+ const srcField = (0, poseidon_js_1.pubkeyToField)(sourceMint);
130
+ const dstField = (0, poseidon_js_1.pubkeyToField)(destMint);
131
+ const mintPairHash = (0, poseidon_js_1.poseidon2)(srcField, dstField);
132
+ const dest = destAmount ?? minAmountOut;
133
+ const swapTermsHash = (0, poseidon_js_1.poseidon3)(minAmountOut, deadline, dest);
134
+ const paramsHash = (0, poseidon_js_1.poseidon2)(mintPairHash, swapTermsHash);
135
+ return (0, poseidon_js_1.bigIntToBytesBE)(paramsHash);
136
+ }
137
+ /**
138
+ * Compute the swap data hash committed on-chain for Jupiter instruction integrity.
139
+ * SHA-256 of the raw Jupiter swap instruction data bytes.
140
+ * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
141
+ */
142
+ function computeSwapDataHash(swapData) {
143
+ return (0, sha256_1.sha256)(swapData instanceof Buffer ? new Uint8Array(swapData) : swapData);
144
+ }
@@ -0,0 +1,28 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import type { InputUTXO, SerializedUTXO } from "../notes/model.js";
3
+ import type { ExtData, TransactionCircuitInputs } from "./types.js";
4
+ /**
5
+ * Compute the external data hash.
6
+ * Matches on-chain computation:
7
+ * hash1 = Poseidon(recipient, relayer)
8
+ * hash2 = Poseidon(fee, refund)
9
+ * extDataHash = Poseidon(hash1, hash2, claimant)
10
+ */
11
+ export declare function computeExtDataHash(extData: ExtData): Uint8Array;
12
+ /**
13
+ * Convert i64 to field element (handles negative via modular arithmetic).
14
+ * For negative values, we add the field modulus to get the equivalent positive representation.
15
+ */
16
+ export declare function i64ToField(value: bigint): bigint;
17
+ /**
18
+ * Prepare transaction circuit inputs from high-level parameters.
19
+ * This converts the SDK types into the format expected by the circuit.
20
+ */
21
+ export declare function prepareTransactionInputs(params: {
22
+ inputUTXOs: [InputUTXO, InputUTXO];
23
+ outputUTXOs: [SerializedUTXO, SerializedUTXO];
24
+ root: Uint8Array;
25
+ publicAmount: bigint;
26
+ extData: ExtData;
27
+ mintAddress: PublicKey;
28
+ }): TransactionCircuitInputs;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeExtDataHash = computeExtDataHash;
4
+ exports.i64ToField = i64ToField;
5
+ exports.prepareTransactionInputs = prepareTransactionInputs;
6
+ const poseidon_js_1 = require("../poseidon.js");
7
+ const nullifier_js_1 = require("../notes/nullifier.js");
8
+ // -----------------------------------------------------------------------------
9
+ // ExtData Hash Computation
10
+ // -----------------------------------------------------------------------------
11
+ /**
12
+ * Compute the external data hash.
13
+ * Matches on-chain computation:
14
+ * hash1 = Poseidon(recipient, relayer)
15
+ * hash2 = Poseidon(fee, refund)
16
+ * extDataHash = Poseidon(hash1, hash2, claimant)
17
+ */
18
+ function computeExtDataHash(extData) {
19
+ const recipientField = (0, poseidon_js_1.pubkeyToField)(extData.recipient);
20
+ const relayerField = (0, poseidon_js_1.pubkeyToField)(extData.relayer);
21
+ const feeField = extData.fee % poseidon_js_1.BN254_FR_MODULUS;
22
+ const refundField = extData.refund % poseidon_js_1.BN254_FR_MODULUS;
23
+ const claimantField = (0, poseidon_js_1.pubkeyToField)(extData.claimant);
24
+ const hash1 = (0, poseidon_js_1.poseidon2)(recipientField, relayerField);
25
+ const hash2 = (0, poseidon_js_1.poseidon2)(feeField, refundField);
26
+ const finalHash = (0, poseidon_js_1.poseidon3)(hash1, hash2, claimantField);
27
+ return (0, poseidon_js_1.bigIntToBytesBE)(finalHash);
28
+ }
29
+ // -----------------------------------------------------------------------------
30
+ // Circuit Input Preparation
31
+ // -----------------------------------------------------------------------------
32
+ /**
33
+ * Convert i64 to field element (handles negative via modular arithmetic).
34
+ * For negative values, we add the field modulus to get the equivalent positive representation.
35
+ */
36
+ function i64ToField(value) {
37
+ if (value >= 0n) {
38
+ return value % poseidon_js_1.BN254_FR_MODULUS;
39
+ }
40
+ return (poseidon_js_1.BN254_FR_MODULUS + value) % poseidon_js_1.BN254_FR_MODULUS;
41
+ }
42
+ /**
43
+ * Prepare transaction circuit inputs from high-level parameters.
44
+ * This converts the SDK types into the format expected by the circuit.
45
+ */
46
+ function prepareTransactionInputs(params) {
47
+ const { inputUTXOs, outputUTXOs, root, publicAmount, extData, mintAddress } = params;
48
+ const extDataHash = computeExtDataHash(extData);
49
+ const mintField = (0, poseidon_js_1.pubkeyToField)(mintAddress);
50
+ // Prepare input UTXO data
51
+ const inAmount = [
52
+ inputUTXOs[0].amount,
53
+ inputUTXOs[1].amount,
54
+ ];
55
+ const inPubkey = [
56
+ inputUTXOs[0].pubkey,
57
+ inputUTXOs[1].pubkey,
58
+ ];
59
+ const inBlinding = [
60
+ inputUTXOs[0].blinding,
61
+ inputUTXOs[1].blinding,
62
+ ];
63
+ const inPathIndex = [
64
+ inputUTXOs[0].pathIndex,
65
+ inputUTXOs[1].pathIndex,
66
+ ];
67
+ const inPathElements = [
68
+ inputUTXOs[0].pathElements.map((e) => (0, poseidon_js_1.bytesToBigIntBE)(e) % poseidon_js_1.BN254_FR_MODULUS),
69
+ inputUTXOs[1].pathElements.map((e) => (0, poseidon_js_1.bytesToBigIntBE)(e) % poseidon_js_1.BN254_FR_MODULUS),
70
+ ];
71
+ const inPrivateKey = [
72
+ inputUTXOs[0].privateKey,
73
+ inputUTXOs[1].privateKey,
74
+ ];
75
+ // Prepare output UTXO data
76
+ const outAmount = [
77
+ outputUTXOs[0].amount,
78
+ outputUTXOs[1].amount,
79
+ ];
80
+ const outPubkey = [
81
+ outputUTXOs[0].pubkey,
82
+ outputUTXOs[1].pubkey,
83
+ ];
84
+ const outBlinding = [
85
+ outputUTXOs[0].blinding,
86
+ outputUTXOs[1].blinding,
87
+ ];
88
+ // Derive nullifiers for input UTXOs
89
+ const inputNullifiers = [
90
+ (0, nullifier_js_1.deriveNullifier)(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
91
+ (0, nullifier_js_1.deriveNullifier)(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
92
+ ];
93
+ return {
94
+ root,
95
+ publicAmount,
96
+ extDataHash,
97
+ mintAddress,
98
+ inputNullifiers,
99
+ outputCommitments: [outputUTXOs[0].commitment, outputUTXOs[1].commitment],
100
+ inAmount,
101
+ inPubkey,
102
+ inBlinding,
103
+ inPathIndex,
104
+ inPathElements,
105
+ inPrivateKey,
106
+ outAmount,
107
+ outPubkey,
108
+ outBlinding,
109
+ };
110
+ }
@@ -0,0 +1,70 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ /**
3
+ * External data that gets hashed into ext_data_hash.
4
+ * These are public parameters that affect financial flows.
5
+ */
6
+ export type ExtData = {
7
+ /** Who receives withdrawal (for withdrawals) */
8
+ recipient: PublicKey;
9
+ /** Who submits tx and gets fee */
10
+ relayer: PublicKey;
11
+ /** Fee to relayer in lamports/token units */
12
+ fee: bigint;
13
+ /** Refund to user in lamports/token units (for gas compensation) */
14
+ refund: bigint;
15
+ /** Claimant key committed into the proof */
16
+ claimant: PublicKey;
17
+ };
18
+ /**
19
+ * Transaction circuit inputs (8 public inputs, many private inputs).
20
+ * This structure is used to prepare inputs for the snarkjs prover.
21
+ */
22
+ export type TransactionCircuitInputs = {
23
+ /** Merkle root of UTXO tree */
24
+ root: Uint8Array;
25
+ /** Net deposit/withdrawal amount (positive = deposit, negative = withdrawal) */
26
+ publicAmount: bigint;
27
+ /** Hash of external data (recipient, relayer, fee, refund) */
28
+ extDataHash: Uint8Array;
29
+ /** Token mint address */
30
+ mintAddress: PublicKey;
31
+ /** Nullifiers for the two input UTXOs */
32
+ inputNullifiers: [Uint8Array, Uint8Array];
33
+ /** Commitments for the two output UTXOs */
34
+ outputCommitments: [Uint8Array, Uint8Array];
35
+ inAmount: [bigint, bigint];
36
+ inPubkey: [bigint, bigint];
37
+ inBlinding: [bigint, bigint];
38
+ inPathIndex: [number, number];
39
+ inPathElements: [bigint[], bigint[]];
40
+ inPrivateKey: [bigint, bigint];
41
+ outAmount: [bigint, bigint];
42
+ outPubkey: [bigint, bigint];
43
+ outBlinding: [bigint, bigint];
44
+ };
45
+ /**
46
+ * Proof structure matching the on-chain TransactionProof struct.
47
+ * Total size: 256 bytes (64 + 128 + 64)
48
+ */
49
+ export type TransactionProofStruct = {
50
+ /** G1 point A (64 bytes) */
51
+ proofA: number[];
52
+ /** G2 point B (128 bytes) */
53
+ proofB: number[];
54
+ /** G1 point C (64 bytes) */
55
+ proofC: number[];
56
+ };
57
+ /**
58
+ * Shape of a Groth16 proof produced by snarkjs.
59
+ */
60
+ export type RawProof = {
61
+ pi_a: [string, string, string];
62
+ pi_b: [[string, string], [string, string], [string, string]];
63
+ pi_c: [string, string, string];
64
+ protocol: string;
65
+ curve: string;
66
+ };
67
+ /**
68
+ * Proof builder function type - takes circuit inputs and returns a raw snarkjs proof.
69
+ */
70
+ export type TransactionProofBuilder = (inputs: TransactionCircuitInputs) => Promise<RawProof>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
- import { TransactionProofBuilder, RawProof } from "./proof";
1
+ import type { TransactionProofBuilder, RawProof } from "./proofs/types.js";
2
+ import { type SwapProofBuilder } from "./proofs/swap.js";
2
3
  /**
3
4
  * Circuit artifact paths required by snarkjs.
4
5
  *
@@ -41,6 +42,8 @@ export interface CircuitArtifacts {
41
42
  * ```
42
43
  */
43
44
  export declare function createTransactionProver(artifacts: CircuitArtifacts): TransactionProofBuilder;
45
+ /** Create a proof builder for the current `swap.circom` witness shape. */
46
+ export declare function createSwapProver(artifacts: CircuitArtifacts): SwapProofBuilder;
44
47
  /**
45
48
  * Verify a Groth16 proof against public signals and a verification key.
46
49
  *
@@ -34,8 +34,10 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createTransactionProver = createTransactionProver;
37
+ exports.createSwapProver = createSwapProver;
37
38
  exports.verifyProof = verifyProof;
38
- const proof_1 = require("./proof");
39
+ const formatting_js_1 = require("./proofs/formatting.js");
40
+ const swap_js_1 = require("./proofs/swap.js");
39
41
  /** Lazy-load snarkjs — works in both CJS and ESM contexts. */
40
42
  async function loadSnarkjs() {
41
43
  try {
@@ -75,11 +77,19 @@ async function loadSnarkjs() {
75
77
  function createTransactionProver(artifacts) {
76
78
  return async (inputs) => {
77
79
  const snarkjs = await loadSnarkjs();
78
- const formattedInputs = (0, proof_1.formatInputsForSnarkjs)(inputs);
80
+ const formattedInputs = (0, formatting_js_1.formatInputsForSnarkjs)(inputs);
79
81
  const { proof } = await snarkjs.groth16.fullProve(formattedInputs, artifacts.wasmPath, artifacts.zkeyPath);
80
82
  return proof;
81
83
  };
82
84
  }
85
+ /** Create a proof builder for the current `swap.circom` witness shape. */
86
+ function createSwapProver(artifacts) {
87
+ return async (inputs) => {
88
+ const snarkjs = await loadSnarkjs();
89
+ const { proof } = await snarkjs.groth16.fullProve((0, swap_js_1.formatSwapInputsForSnarkjs)(inputs), artifacts.wasmPath, artifacts.zkeyPath);
90
+ return proof;
91
+ };
92
+ }
83
93
  /**
84
94
  * Verify a Groth16 proof against public signals and a verification key.
85
95
  *
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Cross-platform CSPRNG.
3
+ *
4
+ * Deliberately backed by `nacl.randomBytes` rather than Node's `crypto.randomBytes`:
5
+ * tweetnacl resolves to `crypto.getRandomValues` in browsers and to Node's CSPRNG
6
+ * under Node, so this module carries no `node:crypto` import. That matters because
7
+ * every deposit path reaches this code via `createUTXO`/`generateKeypair`, and a
8
+ * bare `import { randomBytes } from "crypto"` throws at bundle time in browser
9
+ * builds that have no Node polyfill.
10
+ *
11
+ * tweetnacl is already a hard dependency, so this adds no install weight.
12
+ */
13
+ /** `length` cryptographically-secure random bytes. */
14
+ export declare function randomBytes(length: number): Uint8Array;
15
+ /** 32 cryptographically-secure random bytes — the common case for blindings and seeds. */
16
+ export declare function randomBytes32(): Uint8Array;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.randomBytes = randomBytes;
7
+ exports.randomBytes32 = randomBytes32;
8
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
9
+ /**
10
+ * Cross-platform CSPRNG.
11
+ *
12
+ * Deliberately backed by `nacl.randomBytes` rather than Node's `crypto.randomBytes`:
13
+ * tweetnacl resolves to `crypto.getRandomValues` in browsers and to Node's CSPRNG
14
+ * under Node, so this module carries no `node:crypto` import. That matters because
15
+ * every deposit path reaches this code via `createUTXO`/`generateKeypair`, and a
16
+ * bare `import { randomBytes } from "crypto"` throws at bundle time in browser
17
+ * builds that have no Node polyfill.
18
+ *
19
+ * tweetnacl is already a hard dependency, so this adds no install weight.
20
+ */
21
+ /** `length` cryptographically-secure random bytes. */
22
+ function randomBytes(length) {
23
+ return tweetnacl_1.default.randomBytes(length);
24
+ }
25
+ /** 32 cryptographically-secure random bytes — the common case for blindings and seeds. */
26
+ function randomBytes32() {
27
+ return tweetnacl_1.default.randomBytes(32);
28
+ }
@@ -0,0 +1,61 @@
1
+ import type { ChallengeResponse, CheckUsernameResponse, DeleteUserDataResponse, MerkleRootResponse, MerkleTreeResponse, PreRegisterKeyResponse, PrivateSwapRequest, PrivateSwapResponse, PrivateTransferRequest, PrivateTransferResponse, QueryNotesRequest, QueryNotesResponse, RegisterRequest, RegisterResponse, RestoreRequest, RestoreResponse, RetryPolicy, SaveEncryptedNoteRequest, SaveEncryptedNoteResponse, VeiloPublicKeyResponse, VeiloRelayerConfig, WithdrawRequest, WithdrawResponse } from "./types.js";
2
+ /**
3
+ * HTTP client for the Veilo relayer API.
4
+ *
5
+ * Handles auth, notes, merkle, and encrypted transact endpoints with
6
+ * automatic retry on transient failures and NaCl box payload encryption.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const client = new VeiloRelayerClient({
11
+ * apiKey: "your-api-key",
12
+ * relayerPublicKey: "<base64 NaCl public key>",
13
+ * });
14
+ * const root = await client.getMerkleRoot("So111...");
15
+ * ```
16
+ */
17
+ export declare class VeiloRelayerClient {
18
+ private readonly transport;
19
+ private readonly relayerPubKey;
20
+ constructor(config: VeiloRelayerConfig, retry?: Partial<RetryPolicy>);
21
+ /** Update the auth token (e.g. after register/restore). */
22
+ setAuthToken(token: string): void;
23
+ private encryptPayload;
24
+ /** Request a signature challenge for wallet authentication. */
25
+ getChallenge(walletPublicKey: string): Promise<ChallengeResponse>;
26
+ /** Register a new account with a signed challenge. Returns a JWT auth token. */
27
+ register(data: RegisterRequest): Promise<RegisterResponse>;
28
+ /** Restore an existing account using a signed challenge. Returns a JWT auth token. */
29
+ restore(data: RestoreRequest): Promise<RestoreResponse>;
30
+ /** Check whether a username is available for registration. */
31
+ checkUsername(username: string): Promise<CheckUsernameResponse>;
32
+ /** Look up a user's Veilo public key by username or wallet public key. */
33
+ getVeiloPublicKey(params: {
34
+ username: string;
35
+ publicKey?: never;
36
+ } | {
37
+ publicKey: string;
38
+ username?: never;
39
+ }): Promise<VeiloPublicKeyResponse>;
40
+ /**
41
+ * Provision (or retrieve) the Veilo spend key paired with a Solana address.
42
+ * Public and idempotent; the response contains public key material only.
43
+ */
44
+ preRegisterKey(solanaAddress: string): Promise<PreRegisterKeyResponse>;
45
+ /** Save an encrypted note to the relayer's database. */
46
+ saveEncryptedNote(data: SaveEncryptedNoteRequest): Promise<SaveEncryptedNoteResponse>;
47
+ /** Query encrypted notes for the authenticated user. Requires auth token. */
48
+ queryEncryptedNotes(params?: QueryNotesRequest): Promise<QueryNotesResponse>;
49
+ /** Delete all stored data for the authenticated user. Requires auth token. */
50
+ deleteUserData(): Promise<DeleteUserDataResponse>;
51
+ /** Fetch the current Merkle root for a pool, optionally filtered by mint and tree ID. */
52
+ getMerkleRoot(mintAddress?: string, treeId?: number): Promise<MerkleRootResponse>;
53
+ /** Fetch the full Merkle tree (all leaves) for a pool. */
54
+ getMerkleTree(mintAddress?: string, treeId?: number): Promise<MerkleTreeResponse>;
55
+ /** Submit an encrypted withdrawal request to the relayer. Not retried on failure. */
56
+ submitWithdraw(data: WithdrawRequest): Promise<WithdrawResponse>;
57
+ /** Submit an encrypted private transfer request. Not retried on failure. */
58
+ submitPrivateTransfer(data: PrivateTransferRequest): Promise<PrivateTransferResponse>;
59
+ /** Submit an encrypted private swap request. Not retried on failure. */
60
+ submitPrivateSwap(data: PrivateSwapRequest): Promise<PrivateSwapResponse>;
61
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VeiloRelayerClient = void 0;
7
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
8
+ const crypto_js_1 = require("./crypto.js");
9
+ const encoding_js_1 = require("./encoding.js");
10
+ const transport_js_1 = require("./transport.js");
11
+ // =============================================================================
12
+ // Relayer Client
13
+ // =============================================================================
14
+ /**
15
+ * HTTP client for the Veilo relayer API.
16
+ *
17
+ * Handles auth, notes, merkle, and encrypted transact endpoints with
18
+ * automatic retry on transient failures and NaCl box payload encryption.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const client = new VeiloRelayerClient({
23
+ * apiKey: "your-api-key",
24
+ * relayerPublicKey: "<base64 NaCl public key>",
25
+ * });
26
+ * const root = await client.getMerkleRoot("So111...");
27
+ * ```
28
+ */
29
+ class VeiloRelayerClient {
30
+ constructor(config, retry) {
31
+ this.transport = new transport_js_1.RelayerHttpTransport(config, retry);
32
+ this.relayerPubKey = (0, encoding_js_1.fromBase64)(config.relayerPublicKey);
33
+ }
34
+ /** Update the auth token (e.g. after register/restore). */
35
+ setAuthToken(token) {
36
+ this.transport.setAuthToken(token);
37
+ }
38
+ encryptPayload(data) {
39
+ return (0, crypto_js_1.encryptForRelayer)({
40
+ ...data,
41
+ timestamp: Date.now(),
42
+ nonce: (0, encoding_js_1.toBase64)(tweetnacl_1.default.randomBytes(32)),
43
+ }, this.relayerPubKey);
44
+ }
45
+ // ---------------------------------------------------------------------------
46
+ // Auth
47
+ // ---------------------------------------------------------------------------
48
+ /** Request a signature challenge for wallet authentication. */
49
+ async getChallenge(walletPublicKey) {
50
+ return this.transport.request("POST", "/auth/challenge", {
51
+ body: { walletPublicKey },
52
+ });
53
+ }
54
+ /** Register a new account with a signed challenge. Returns a JWT auth token. */
55
+ async register(data) {
56
+ return this.transport.request("POST", "/auth/register", { body: data });
57
+ }
58
+ /** Restore an existing account using a signed challenge. Returns a JWT auth token. */
59
+ async restore(data) {
60
+ return this.transport.request("POST", "/auth/restore", { body: data });
61
+ }
62
+ /** Check whether a username is available for registration. */
63
+ async checkUsername(username) {
64
+ return this.transport.request("GET", `/auth/checkUsername?username=${encodeURIComponent(username)}`);
65
+ }
66
+ /** Look up a user's Veilo public key by username or wallet public key. */
67
+ async getVeiloPublicKey(params) {
68
+ const query = "username" in params && params.username
69
+ ? `username=${encodeURIComponent(params.username)}`
70
+ : `publicKey=${encodeURIComponent(params.publicKey)}`;
71
+ return this.transport.request("GET", `/auth/veiloPublicKey?${query}`);
72
+ }
73
+ /**
74
+ * Provision (or retrieve) the Veilo spend key paired with a Solana address.
75
+ * Public and idempotent; the response contains public key material only.
76
+ */
77
+ async preRegisterKey(solanaAddress) {
78
+ return this.transport.request("POST", "/auth/pre-register-key", {
79
+ body: { solanaAddress },
80
+ });
81
+ }
82
+ // ---------------------------------------------------------------------------
83
+ // Notes
84
+ // ---------------------------------------------------------------------------
85
+ /** Save an encrypted note to the relayer's database. */
86
+ async saveEncryptedNote(data) {
87
+ return this.transport.request("POST", "/notes/save", { body: data });
88
+ }
89
+ /** Query encrypted notes for the authenticated user. Requires auth token. */
90
+ async queryEncryptedNotes(params = {}) {
91
+ return this.transport.request("POST", "/notes/query", {
92
+ body: params,
93
+ authenticated: true,
94
+ });
95
+ }
96
+ /** Delete all stored data for the authenticated user. Requires auth token. */
97
+ async deleteUserData() {
98
+ return this.transport.request("POST", "/notes/delete", { authenticated: true });
99
+ }
100
+ // ---------------------------------------------------------------------------
101
+ // Merkle
102
+ // ---------------------------------------------------------------------------
103
+ /** Fetch the current Merkle root for a pool, optionally filtered by mint and tree ID. */
104
+ async getMerkleRoot(mintAddress, treeId) {
105
+ const params = new URLSearchParams();
106
+ if (mintAddress)
107
+ params.append("mintAddress", mintAddress);
108
+ if (treeId !== undefined)
109
+ params.append("treeId", treeId.toString());
110
+ const qs = params.toString();
111
+ return this.transport.request("GET", `/merkle/root${qs ? `?${qs}` : ""}`);
112
+ }
113
+ /** Fetch the full Merkle tree (all leaves) for a pool. */
114
+ async getMerkleTree(mintAddress, treeId) {
115
+ const params = new URLSearchParams();
116
+ if (mintAddress)
117
+ params.append("mintAddress", mintAddress);
118
+ if (treeId !== undefined)
119
+ params.append("treeId", treeId.toString());
120
+ const qs = params.toString();
121
+ return this.transport.request("GET", `/merkle/tree${qs ? `?${qs}` : ""}`);
122
+ }
123
+ // ---------------------------------------------------------------------------
124
+ // Transact (encrypted payloads)
125
+ // ---------------------------------------------------------------------------
126
+ /** Submit an encrypted withdrawal request to the relayer. Not retried on failure. */
127
+ async submitWithdraw(data) {
128
+ const encryptedPayload = this.encryptPayload(data);
129
+ return this.transport.request("POST", "/transact/withdraw", {
130
+ body: { encryptedPayload },
131
+ retryable: false,
132
+ });
133
+ }
134
+ /** Submit an encrypted private transfer request. Not retried on failure. */
135
+ async submitPrivateTransfer(data) {
136
+ const encryptedPayload = this.encryptPayload(data);
137
+ return this.transport.request("POST", "/transact/private-transfer", {
138
+ body: { encryptedPayload },
139
+ retryable: false,
140
+ });
141
+ }
142
+ /** Submit an encrypted private swap request. Not retried on failure. */
143
+ async submitPrivateSwap(data) {
144
+ const encryptedPayload = this.encryptPayload(data);
145
+ return this.transport.request("POST", "/transact/private-swap", {
146
+ body: { encryptedPayload },
147
+ retryable: false,
148
+ });
149
+ }
150
+ }
151
+ exports.VeiloRelayerClient = VeiloRelayerClient;