@veilo/sdk-core 0.4.0 → 0.6.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 (481) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +449 -1243
  3. package/accounts.d.ts +2 -0
  4. package/accounts.js +3 -0
  5. package/cloak.d.ts +2 -0
  6. package/cloak.js +3 -0
  7. package/config.d.ts +2 -2
  8. package/config.js +2 -3
  9. package/dist/cjs/accounts/admin.d.ts +84 -0
  10. package/dist/cjs/accounts/admin.js +208 -0
  11. package/dist/cjs/accounts/errors.d.ts +6 -0
  12. package/dist/cjs/accounts/errors.js +98 -0
  13. package/dist/cjs/accounts/index.d.ts +4 -0
  14. package/dist/cjs/accounts/index.js +20 -0
  15. package/dist/cjs/accounts/pdas.d.ts +23 -0
  16. package/dist/cjs/accounts/pdas.js +44 -0
  17. package/dist/cjs/accounts/queries.d.ts +41 -0
  18. package/dist/cjs/accounts/queries.js +95 -0
  19. package/dist/cjs/client.d.ts +2 -407
  20. package/dist/cjs/client.js +6 -938
  21. package/dist/cjs/cloak/client.d.ts +28 -0
  22. package/dist/cjs/cloak/client.js +68 -0
  23. package/dist/cjs/cloak/errors.d.ts +13 -0
  24. package/dist/cjs/cloak/errors.js +25 -0
  25. package/dist/cjs/cloak/helpers.d.ts +6 -0
  26. package/dist/cjs/cloak/helpers.js +35 -0
  27. package/dist/cjs/cloak/index.d.ts +6 -0
  28. package/dist/cjs/cloak/index.js +24 -0
  29. package/dist/cjs/cloak/polling.d.ts +7 -0
  30. package/dist/cjs/cloak/polling.js +66 -0
  31. package/dist/cjs/cloak/transport.d.ts +15 -0
  32. package/dist/cjs/cloak/transport.js +119 -0
  33. package/dist/cjs/cloak/types.d.ts +188 -0
  34. package/dist/cjs/cloak/types.js +5 -0
  35. package/dist/cjs/cloak.d.ts +1 -0
  36. package/dist/cjs/cloak.js +18 -0
  37. package/dist/cjs/compactNote.d.ts +21 -0
  38. package/dist/cjs/compactNote.js +31 -7
  39. package/dist/cjs/events/index.d.ts +6 -0
  40. package/dist/cjs/events/index.js +22 -0
  41. package/dist/cjs/events/parsing.d.ts +25 -0
  42. package/dist/cjs/events/parsing.js +158 -0
  43. package/dist/cjs/events/position.d.ts +26 -0
  44. package/dist/cjs/events/position.js +53 -0
  45. package/dist/cjs/events/recovery.d.ts +87 -0
  46. package/dist/cjs/events/recovery.js +281 -0
  47. package/dist/cjs/events/scanning.d.ts +35 -0
  48. package/dist/cjs/events/scanning.js +98 -0
  49. package/dist/cjs/events/tree.d.ts +27 -0
  50. package/dist/cjs/events/tree.js +63 -0
  51. package/dist/cjs/events/types.d.ts +39 -0
  52. package/dist/cjs/events.d.ts +1 -77
  53. package/dist/cjs/events.js +6 -154
  54. package/dist/cjs/identity/encoding.d.ts +9 -0
  55. package/dist/cjs/identity/encoding.js +85 -0
  56. package/dist/cjs/identity/index.d.ts +4 -0
  57. package/dist/cjs/identity/index.js +20 -0
  58. package/dist/cjs/identity/noteKey.d.ts +33 -0
  59. package/dist/cjs/identity/noteKey.js +97 -0
  60. package/dist/cjs/identity/spending.d.ts +18 -0
  61. package/dist/cjs/identity/spending.js +46 -0
  62. package/dist/cjs/identity/viewKey.d.ts +38 -0
  63. package/dist/cjs/identity/viewKey.js +105 -0
  64. package/dist/cjs/idl/index.d.ts +18 -0
  65. package/dist/cjs/idl/index.js +24 -0
  66. package/dist/cjs/idl/privacy_pool.json +9907 -9907
  67. package/dist/cjs/idl/privacy_pool_legacy.js +3307 -0
  68. package/dist/cjs/idl/privacy_pool_legacy.json +2302 -0
  69. package/dist/cjs/idl/privacy_pool_legacy2.d.ts +5 -0
  70. package/dist/cjs/idl/privacy_pool_legacy2.js +3397 -0
  71. package/dist/cjs/idl/privacy_pool_legacy2.json +2376 -0
  72. package/dist/cjs/index.d.ts +9 -3
  73. package/dist/cjs/index.js +15 -2
  74. package/dist/cjs/notes/amount.d.ts +2 -0
  75. package/dist/cjs/notes/amount.js +21 -0
  76. package/dist/cjs/notes/encryption.d.ts +41 -0
  77. package/dist/cjs/notes/encryption.js +75 -0
  78. package/dist/cjs/notes/index.d.ts +8 -0
  79. package/dist/cjs/notes/index.js +24 -0
  80. package/dist/cjs/notes/mailbox.d.ts +70 -0
  81. package/dist/cjs/notes/mailbox.js +164 -0
  82. package/dist/cjs/notes/model.d.ts +91 -0
  83. package/dist/cjs/notes/model.js +109 -0
  84. package/dist/cjs/notes/nullifier.d.ts +27 -0
  85. package/dist/cjs/notes/nullifier.js +45 -0
  86. package/dist/cjs/notes/recovery.d.ts +20 -0
  87. package/dist/cjs/notes/recovery.js +48 -0
  88. package/dist/cjs/notes/selection.d.ts +77 -0
  89. package/dist/cjs/notes/selection.js +193 -0
  90. package/dist/cjs/notes/spent.d.ts +60 -0
  91. package/dist/cjs/notes/spent.js +101 -0
  92. package/dist/cjs/perps/constants.d.ts +16 -0
  93. package/dist/cjs/perps/constants.js +52 -0
  94. package/dist/cjs/perps/index.d.ts +5 -0
  95. package/dist/cjs/perps/index.js +21 -0
  96. package/dist/cjs/perps/keys.d.ts +16 -0
  97. package/dist/cjs/perps/keys.js +43 -0
  98. package/dist/cjs/perps/pdas.d.ts +29 -0
  99. package/dist/cjs/perps/pdas.js +55 -0
  100. package/dist/cjs/perps/relayer.d.ts +9 -0
  101. package/dist/cjs/perps/relayer.js +35 -0
  102. package/dist/cjs/perps/types.d.ts +126 -0
  103. package/dist/cjs/perps/types.js +2 -0
  104. package/dist/cjs/positions/index.d.ts +4 -0
  105. package/dist/cjs/positions/index.js +20 -0
  106. package/dist/cjs/positions/keys.d.ts +29 -0
  107. package/dist/cjs/positions/keys.js +71 -0
  108. package/dist/cjs/positions/pdas.d.ts +15 -0
  109. package/dist/cjs/positions/pdas.js +54 -0
  110. package/dist/cjs/positions/relayer.d.ts +4 -0
  111. package/dist/cjs/positions/relayer.js +15 -0
  112. package/dist/cjs/positions/types.d.ts +97 -0
  113. package/dist/cjs/positions/types.js +2 -0
  114. package/dist/cjs/predictions/client.d.ts +41 -0
  115. package/dist/cjs/predictions/client.js +147 -0
  116. package/dist/cjs/predictions/index.d.ts +5 -0
  117. package/dist/cjs/predictions/index.js +21 -0
  118. package/dist/cjs/predictions/keys.d.ts +14 -0
  119. package/dist/cjs/predictions/keys.js +40 -0
  120. package/dist/cjs/predictions/pdas.d.ts +6 -0
  121. package/dist/cjs/predictions/pdas.js +13 -0
  122. package/dist/cjs/predictions/relayer.d.ts +3 -0
  123. package/dist/cjs/predictions/relayer.js +11 -0
  124. package/dist/cjs/predictions/types.d.ts +178 -0
  125. package/dist/cjs/predictions/types.js +2 -0
  126. package/dist/cjs/program.d.ts +2 -0
  127. package/dist/cjs/program.js +8 -7
  128. package/dist/cjs/proof.d.ts +1 -183
  129. package/dist/cjs/proof.js +16 -290
  130. package/dist/cjs/proofs/encoding.d.ts +17 -0
  131. package/dist/cjs/proofs/encoding.js +72 -0
  132. package/dist/cjs/proofs/formatting.d.ts +6 -0
  133. package/dist/cjs/proofs/formatting.js +34 -0
  134. package/dist/cjs/proofs/index.d.ts +5 -0
  135. package/dist/cjs/proofs/index.js +21 -0
  136. package/dist/cjs/proofs/swap.d.ts +87 -0
  137. package/dist/cjs/proofs/swap.js +144 -0
  138. package/dist/cjs/proofs/transaction.d.ts +28 -0
  139. package/dist/cjs/proofs/transaction.js +110 -0
  140. package/dist/cjs/proofs/types.d.ts +70 -0
  141. package/dist/cjs/proofs/types.js +2 -0
  142. package/dist/cjs/prover.d.ts +30 -4
  143. package/dist/cjs/prover.js +118 -49
  144. package/dist/cjs/relayer/api.d.ts +31 -0
  145. package/dist/cjs/relayer/api.js +86 -0
  146. package/dist/cjs/relayer/client.d.ts +73 -0
  147. package/dist/cjs/relayer/client.js +206 -0
  148. package/dist/cjs/relayer/crypto.d.ts +5 -0
  149. package/dist/cjs/relayer/crypto.js +26 -0
  150. package/dist/cjs/relayer/encoding.d.ts +2 -0
  151. package/dist/cjs/relayer/encoding.js +23 -0
  152. package/dist/cjs/relayer/errors.d.ts +7 -0
  153. package/dist/cjs/relayer/errors.js +17 -0
  154. package/dist/cjs/relayer/index.d.ts +6 -0
  155. package/dist/cjs/relayer/index.js +19 -0
  156. package/dist/cjs/relayer/internal-config.d.ts +36 -0
  157. package/dist/cjs/relayer/internal-config.js +9 -0
  158. package/dist/cjs/relayer/internal.d.ts +6 -0
  159. package/dist/cjs/relayer/internal.js +14 -0
  160. package/dist/cjs/relayer/transport.d.ts +19 -0
  161. package/dist/cjs/relayer/transport.js +68 -0
  162. package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +53 -96
  163. package/dist/cjs/relayer/types.js +5 -0
  164. package/dist/cjs/relayer.d.ts +1 -318
  165. package/dist/cjs/relayer.js +15 -254
  166. package/dist/cjs/shield/alt.js +8 -8
  167. package/dist/cjs/shield/errors.js +2 -2
  168. package/dist/cjs/shield/finalize.js +2 -2
  169. package/dist/cjs/shield/ix.d.ts +1 -1
  170. package/dist/cjs/shield/owner.js +9 -11
  171. package/dist/cjs/shield/ports.js +3 -3
  172. package/dist/cjs/shield/preflight.js +3 -3
  173. package/dist/cjs/shield/shield.js +20 -19
  174. package/dist/cjs/shield/types.d.ts +1 -1
  175. package/dist/cjs/transactions/deposit.d.ts +94 -0
  176. package/dist/cjs/transactions/deposit.js +234 -0
  177. package/dist/cjs/transactions/index.d.ts +7 -0
  178. package/dist/cjs/transactions/index.js +26 -0
  179. package/dist/cjs/transactions/swap.d.ts +71 -0
  180. package/dist/cjs/transactions/swap.js +184 -0
  181. package/dist/cjs/transactions/transact.d.ts +34 -0
  182. package/dist/cjs/transactions/transact.js +146 -0
  183. package/dist/cjs/transactions/transfer.d.ts +51 -0
  184. package/dist/cjs/transactions/transfer.js +106 -0
  185. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  186. package/dist/cjs/transactions/withdraw.js +104 -0
  187. package/dist/cjs/utxo.d.ts +1 -235
  188. package/dist/cjs/utxo.js +15 -404
  189. package/dist/esm/accounts/admin.d.ts +84 -0
  190. package/dist/esm/accounts/admin.js +165 -0
  191. package/dist/esm/accounts/errors.d.ts +6 -0
  192. package/dist/esm/accounts/errors.js +95 -0
  193. package/dist/esm/accounts/index.d.ts +4 -0
  194. package/dist/esm/accounts/index.js +4 -0
  195. package/dist/esm/accounts/pdas.d.ts +23 -0
  196. package/dist/esm/accounts/pdas.js +38 -0
  197. package/dist/esm/accounts/queries.d.ts +41 -0
  198. package/dist/esm/accounts/queries.js +88 -0
  199. package/dist/esm/client.d.ts +2 -407
  200. package/dist/esm/client.js +3 -891
  201. package/dist/esm/cloak/client.d.ts +28 -0
  202. package/dist/esm/cloak/client.js +64 -0
  203. package/dist/esm/cloak/errors.d.ts +13 -0
  204. package/dist/esm/cloak/errors.js +21 -0
  205. package/dist/esm/cloak/helpers.d.ts +6 -0
  206. package/dist/esm/cloak/helpers.js +31 -0
  207. package/dist/esm/cloak/index.d.ts +6 -0
  208. package/dist/esm/cloak/index.js +6 -0
  209. package/dist/esm/cloak/polling.d.ts +7 -0
  210. package/dist/esm/cloak/polling.js +63 -0
  211. package/dist/esm/cloak/transport.d.ts +15 -0
  212. package/dist/esm/cloak/transport.js +115 -0
  213. package/dist/esm/cloak/types.d.ts +188 -0
  214. package/dist/esm/cloak/types.js +4 -0
  215. package/dist/esm/cloak.d.ts +1 -0
  216. package/dist/esm/cloak.js +2 -0
  217. package/dist/esm/compactNote.d.ts +21 -0
  218. package/dist/esm/compactNote.js +24 -1
  219. package/dist/esm/events/index.d.ts +6 -0
  220. package/dist/esm/events/index.js +6 -0
  221. package/dist/esm/events/parsing.d.ts +25 -0
  222. package/dist/esm/events/parsing.js +120 -0
  223. package/dist/esm/events/position.d.ts +26 -0
  224. package/dist/esm/events/position.js +48 -0
  225. package/dist/esm/events/recovery.d.ts +87 -0
  226. package/dist/esm/events/recovery.js +237 -0
  227. package/dist/esm/events/scanning.d.ts +35 -0
  228. package/dist/esm/events/scanning.js +92 -0
  229. package/dist/esm/events/tree.d.ts +27 -0
  230. package/dist/esm/events/tree.js +58 -0
  231. package/dist/esm/events/types.d.ts +39 -0
  232. package/dist/esm/events/types.js +1 -0
  233. package/dist/esm/events.d.ts +1 -77
  234. package/dist/esm/events.js +3 -129
  235. package/dist/esm/identity/encoding.d.ts +9 -0
  236. package/dist/esm/identity/encoding.js +75 -0
  237. package/dist/esm/identity/index.d.ts +4 -0
  238. package/dist/esm/identity/index.js +4 -0
  239. package/dist/esm/identity/noteKey.d.ts +33 -0
  240. package/dist/esm/identity/noteKey.js +91 -0
  241. package/dist/esm/identity/spending.d.ts +18 -0
  242. package/dist/esm/identity/spending.js +35 -0
  243. package/dist/esm/identity/viewKey.d.ts +38 -0
  244. package/dist/esm/identity/viewKey.js +96 -0
  245. package/dist/esm/idl/index.d.ts +18 -0
  246. package/dist/esm/idl/index.js +18 -0
  247. package/dist/esm/idl/privacy_pool.json +9907 -9907
  248. package/dist/esm/idl/privacy_pool_legacy.d.ts +5 -0
  249. package/dist/esm/idl/privacy_pool_legacy.js +3305 -0
  250. package/dist/esm/idl/privacy_pool_legacy.json +2302 -0
  251. package/dist/esm/idl/privacy_pool_legacy2.d.ts +5 -0
  252. package/dist/esm/idl/privacy_pool_legacy2.js +3395 -0
  253. package/dist/esm/idl/privacy_pool_legacy2.json +2376 -0
  254. package/dist/esm/index.d.ts +9 -3
  255. package/dist/esm/index.js +10 -3
  256. package/dist/esm/notes/amount.d.ts +2 -0
  257. package/dist/esm/notes/amount.js +18 -0
  258. package/dist/esm/notes/encryption.d.ts +41 -0
  259. package/dist/esm/notes/encryption.js +67 -0
  260. package/dist/esm/notes/index.d.ts +8 -0
  261. package/dist/esm/notes/index.js +8 -0
  262. package/dist/esm/notes/mailbox.d.ts +70 -0
  263. package/dist/esm/notes/mailbox.js +154 -0
  264. package/dist/esm/notes/model.d.ts +91 -0
  265. package/dist/esm/notes/model.js +99 -0
  266. package/dist/esm/notes/nullifier.d.ts +27 -0
  267. package/dist/esm/notes/nullifier.js +40 -0
  268. package/dist/esm/notes/recovery.d.ts +20 -0
  269. package/dist/esm/notes/recovery.js +45 -0
  270. package/dist/esm/notes/selection.d.ts +77 -0
  271. package/dist/esm/notes/selection.js +188 -0
  272. package/dist/esm/notes/spent.d.ts +60 -0
  273. package/dist/esm/notes/spent.js +96 -0
  274. package/dist/esm/perps/constants.d.ts +16 -0
  275. package/dist/esm/perps/constants.js +48 -0
  276. package/dist/esm/perps/index.d.ts +5 -0
  277. package/dist/esm/perps/index.js +5 -0
  278. package/dist/esm/perps/keys.d.ts +16 -0
  279. package/dist/esm/perps/keys.js +35 -0
  280. package/dist/esm/perps/pdas.d.ts +29 -0
  281. package/dist/esm/perps/pdas.js +47 -0
  282. package/dist/esm/perps/relayer.d.ts +9 -0
  283. package/dist/esm/perps/relayer.js +25 -0
  284. package/dist/esm/perps/types.d.ts +126 -0
  285. package/dist/esm/perps/types.js +1 -0
  286. package/dist/esm/positions/index.d.ts +4 -0
  287. package/dist/esm/positions/index.js +4 -0
  288. package/dist/esm/positions/keys.d.ts +29 -0
  289. package/dist/esm/positions/keys.js +65 -0
  290. package/dist/esm/positions/pdas.d.ts +15 -0
  291. package/dist/esm/positions/pdas.js +44 -0
  292. package/dist/esm/positions/relayer.d.ts +4 -0
  293. package/dist/esm/positions/relayer.js +10 -0
  294. package/dist/esm/positions/types.d.ts +97 -0
  295. package/dist/esm/positions/types.js +1 -0
  296. package/dist/esm/predictions/client.d.ts +41 -0
  297. package/dist/esm/predictions/client.js +141 -0
  298. package/dist/esm/predictions/index.d.ts +5 -0
  299. package/dist/esm/predictions/index.js +5 -0
  300. package/dist/esm/predictions/keys.d.ts +14 -0
  301. package/dist/esm/predictions/keys.js +33 -0
  302. package/dist/esm/predictions/pdas.d.ts +6 -0
  303. package/dist/esm/predictions/pdas.js +10 -0
  304. package/dist/esm/predictions/relayer.d.ts +3 -0
  305. package/dist/esm/predictions/relayer.js +7 -0
  306. package/dist/esm/predictions/types.d.ts +178 -0
  307. package/dist/esm/predictions/types.js +1 -0
  308. package/dist/esm/program.d.ts +2 -0
  309. package/dist/esm/program.js +4 -3
  310. package/dist/esm/proof.d.ts +1 -183
  311. package/dist/esm/proof.js +2 -281
  312. package/dist/esm/proofs/encoding.d.ts +17 -0
  313. package/dist/esm/proofs/encoding.js +68 -0
  314. package/dist/esm/proofs/formatting.d.ts +6 -0
  315. package/dist/esm/proofs/formatting.js +31 -0
  316. package/dist/esm/proofs/index.d.ts +5 -0
  317. package/dist/esm/proofs/index.js +5 -0
  318. package/dist/esm/proofs/swap.d.ts +87 -0
  319. package/dist/esm/proofs/swap.js +138 -0
  320. package/dist/esm/proofs/transaction.d.ts +28 -0
  321. package/dist/esm/proofs/transaction.js +105 -0
  322. package/dist/esm/proofs/types.d.ts +70 -0
  323. package/dist/esm/proofs/types.js +1 -0
  324. package/dist/esm/prover.d.ts +30 -4
  325. package/dist/esm/prover.js +115 -15
  326. package/dist/esm/relayer/api.d.ts +31 -0
  327. package/dist/esm/relayer/api.js +55 -0
  328. package/dist/esm/relayer/client.d.ts +73 -0
  329. package/dist/esm/relayer/client.js +199 -0
  330. package/dist/esm/relayer/crypto.d.ts +5 -0
  331. package/dist/esm/relayer/crypto.js +20 -0
  332. package/dist/esm/relayer/encoding.d.ts +2 -0
  333. package/dist/esm/relayer/encoding.js +19 -0
  334. package/dist/esm/relayer/errors.d.ts +7 -0
  335. package/dist/esm/relayer/errors.js +13 -0
  336. package/dist/esm/relayer/index.d.ts +6 -0
  337. package/dist/esm/relayer/index.js +3 -0
  338. package/dist/esm/relayer/internal-config.d.ts +36 -0
  339. package/dist/esm/relayer/internal-config.js +6 -0
  340. package/dist/esm/relayer/internal.d.ts +6 -0
  341. package/dist/esm/relayer/internal.js +10 -0
  342. package/dist/esm/relayer/transport.d.ts +19 -0
  343. package/dist/esm/relayer/transport.js +64 -0
  344. package/dist/esm/relayer/types.d.ts +275 -0
  345. package/dist/esm/relayer/types.js +4 -0
  346. package/dist/esm/relayer.d.ts +1 -318
  347. package/dist/esm/relayer.js +2 -249
  348. package/dist/esm/shield/alt.js +1 -1
  349. package/dist/esm/shield/errors.js +1 -1
  350. package/dist/esm/shield/finalize.js +1 -1
  351. package/dist/esm/shield/ix.d.ts +1 -1
  352. package/dist/esm/shield/owner.js +3 -5
  353. package/dist/esm/shield/ports.js +1 -1
  354. package/dist/esm/shield/preflight.js +1 -1
  355. package/dist/esm/shield/shield.js +4 -3
  356. package/dist/esm/shield/types.d.ts +1 -1
  357. package/dist/esm/transactions/deposit.d.ts +94 -0
  358. package/dist/esm/transactions/deposit.js +198 -0
  359. package/dist/esm/transactions/index.d.ts +7 -0
  360. package/dist/esm/transactions/index.js +7 -0
  361. package/dist/esm/transactions/swap.d.ts +71 -0
  362. package/dist/esm/transactions/swap.js +144 -0
  363. package/dist/esm/transactions/transact.d.ts +34 -0
  364. package/dist/esm/transactions/transact.js +110 -0
  365. package/dist/esm/transactions/transfer.d.ts +51 -0
  366. package/dist/esm/transactions/transfer.js +103 -0
  367. package/dist/esm/transactions/withdraw.d.ts +52 -0
  368. package/dist/esm/transactions/withdraw.js +101 -0
  369. package/dist/esm/utxo.d.ts +1 -235
  370. package/dist/esm/utxo.js +2 -382
  371. package/identity.d.ts +2 -0
  372. package/identity.js +3 -0
  373. package/idl.d.ts +2 -0
  374. package/idl.js +3 -0
  375. package/notes.d.ts +2 -0
  376. package/notes.js +3 -0
  377. package/package.json +131 -11
  378. package/perps.d.ts +2 -0
  379. package/perps.js +3 -0
  380. package/poseidon.d.ts +2 -2
  381. package/poseidon.js +2 -3
  382. package/positions.d.ts +2 -0
  383. package/positions.js +3 -0
  384. package/predictions.d.ts +2 -0
  385. package/predictions.js +3 -0
  386. package/proof.d.ts +2 -2
  387. package/proof.js +2 -3
  388. package/prover.d.ts +2 -2
  389. package/prover.js +2 -3
  390. package/relayer.d.ts +2 -0
  391. package/relayer.js +3 -0
  392. package/shield.d.ts +2 -2
  393. package/shield.js +2 -3
  394. package/transactions.d.ts +2 -0
  395. package/transactions.js +3 -0
  396. package/SHIELD_INTEGRATION.md +0 -143
  397. package/dist/src/client.d.ts +0 -407
  398. package/dist/src/client.js +0 -951
  399. package/dist/src/compactNote.d.ts +0 -107
  400. package/dist/src/compactNote.js +0 -167
  401. package/dist/src/config.d.ts +0 -82
  402. package/dist/src/config.js +0 -57
  403. package/dist/src/events.d.ts +0 -77
  404. package/dist/src/events.js +0 -167
  405. package/dist/src/idl/privacy_pool.js +0 -15218
  406. package/dist/src/index.d.ts +0 -16
  407. package/dist/src/index.js +0 -67
  408. package/dist/src/merkle.d.ts +0 -77
  409. package/dist/src/merkle.js +0 -156
  410. package/dist/src/poseidon.d.ts +0 -29
  411. package/dist/src/poseidon.js +0 -100
  412. package/dist/src/program.d.ts +0 -37
  413. package/dist/src/program.js +0 -61
  414. package/dist/src/proof.d.ts +0 -183
  415. package/dist/src/proof.js +0 -292
  416. package/dist/src/prover.d.ts +0 -54
  417. package/dist/src/prover.js +0 -112
  418. package/dist/src/random.d.ts +0 -16
  419. package/dist/src/random.js +0 -28
  420. package/dist/src/relayer.js +0 -257
  421. package/dist/src/retry.d.ts +0 -32
  422. package/dist/src/retry.js +0 -75
  423. package/dist/src/shield/alt.d.ts +0 -87
  424. package/dist/src/shield/alt.js +0 -194
  425. package/dist/src/shield/computeBudget.d.ts +0 -61
  426. package/dist/src/shield/computeBudget.js +0 -64
  427. package/dist/src/shield/errors.d.ts +0 -58
  428. package/dist/src/shield/errors.js +0 -121
  429. package/dist/src/shield/finalize.d.ts +0 -45
  430. package/dist/src/shield/finalize.js +0 -119
  431. package/dist/src/shield/index.d.ts +0 -35
  432. package/dist/src/shield/index.js +0 -68
  433. package/dist/src/shield/ix.d.ts +0 -54
  434. package/dist/src/shield/ix.js +0 -119
  435. package/dist/src/shield/owner.d.ts +0 -36
  436. package/dist/src/shield/owner.js +0 -126
  437. package/dist/src/shield/ports.d.ts +0 -43
  438. package/dist/src/shield/ports.js +0 -153
  439. package/dist/src/shield/preflight.d.ts +0 -30
  440. package/dist/src/shield/preflight.js +0 -154
  441. package/dist/src/shield/shield.d.ts +0 -68
  442. package/dist/src/shield/shield.js +0 -499
  443. package/dist/src/shield/types.d.ts +0 -202
  444. package/dist/src/utxo.d.ts +0 -235
  445. package/dist/src/utxo.js +0 -407
  446. package/dist/tests/compact-note.test.d.ts +0 -1
  447. package/dist/tests/compact-note.test.js +0 -173
  448. package/dist/tests/config.test.d.ts +0 -1
  449. package/dist/tests/config.test.js +0 -102
  450. package/dist/tests/edge-cases.test.d.ts +0 -1
  451. package/dist/tests/edge-cases.test.js +0 -220
  452. package/dist/tests/encryption.test.d.ts +0 -1
  453. package/dist/tests/encryption.test.js +0 -215
  454. package/dist/tests/events.test.d.ts +0 -1
  455. package/dist/tests/events.test.js +0 -78
  456. package/dist/tests/multi-tree.test.d.ts +0 -1
  457. package/dist/tests/multi-tree.test.js +0 -405
  458. package/dist/tests/pda.test.d.ts +0 -1
  459. package/dist/tests/pda.test.js +0 -229
  460. package/dist/tests/poseidon-builder-parity.test.d.ts +0 -1
  461. package/dist/tests/poseidon-builder-parity.test.js +0 -72
  462. package/dist/tests/poseidon.test.d.ts +0 -1
  463. package/dist/tests/poseidon.test.js +0 -142
  464. package/dist/tests/proof.test.d.ts +0 -1
  465. package/dist/tests/proof.test.js +0 -296
  466. package/dist/tests/relayer.test.d.ts +0 -1
  467. package/dist/tests/relayer.test.js +0 -271
  468. package/dist/tests/sdk.integration.test.d.ts +0 -1
  469. package/dist/tests/sdk.integration.test.js +0 -330
  470. package/dist/tests/shield-owner.test.d.ts +0 -1
  471. package/dist/tests/shield-owner.test.js +0 -89
  472. package/dist/tests/shield-preflight.test.d.ts +0 -1
  473. package/dist/tests/shield-preflight.test.js +0 -87
  474. package/dist/tests/shield-realproof.test.d.ts +0 -1
  475. package/dist/tests/shield-realproof.test.js +0 -272
  476. package/dist/tests/shield.test.d.ts +0 -1
  477. package/dist/tests/shield.test.js +0 -403
  478. package/dist/tests/utxo.test.d.ts +0 -1
  479. package/dist/tests/utxo.test.js +0 -140
  480. /package/dist/{src/shield → cjs/events}/types.js +0 -0
  481. /package/dist/{src/idl/privacy_pool.d.ts → cjs/idl/privacy_pool_legacy.d.ts} +0 -0
@@ -1,891 +1,3 @@
1
- import * as anchor from "@coral-xyz/anchor";
2
- // Pulled off the namespace rather than named-imported. @coral-xyz/anchor is CJS
3
- // with no `exports` map, and Node ESM's named-export detection cannot see `BN`
4
- // (it is re-exported from bn.js), so `import { BN }` throws at runtime under ESM.
5
- const { BN } = anchor;
6
- import { PublicKey, SystemProgram, Transaction, SYSVAR_INSTRUCTIONS_PUBKEY, ComputeBudgetProgram, } from "@solana/web3.js";
7
- import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, getAssociatedTokenAddress, } from "@solana/spl-token";
8
- import { computeExtDataHash, prepareTransactionInputs, encodeSnarkjsProofToTransactionProof, } from "./proof.js";
9
- import { createUTXO, createOwnedZeroUTXO, generateKeypair, } from "./utxo.js";
10
- import { NATIVE_SOL_MINT } from "./config.js";
11
- import { withRpcRetry } from "./retry.js";
12
- // -----------------------------------------------------------------------------
13
- // PDA Helpers
14
- // -----------------------------------------------------------------------------
15
- /**
16
- * Get pool PDAs for a given mint address.
17
- * Note: All seeds use "v3" suffix.
18
- */
19
- export function getPoolPdas(programId, mintAddress) {
20
- const [config] = PublicKey.findProgramAddressSync([Buffer.from("privacy_config_v3"), mintAddress.toBuffer()], programId);
21
- const [vault] = PublicKey.findProgramAddressSync([Buffer.from("privacy_vault_v3"), mintAddress.toBuffer()], programId);
22
- const [nullifiers] = PublicKey.findProgramAddressSync([Buffer.from("privacy_nullifiers_v3"), mintAddress.toBuffer()], programId);
23
- return { config, vault, nullifiers };
24
- }
25
- /**
26
- * Get the note tree PDA for a specific tree ID.
27
- */
28
- export function getNoteTreePda(programId, mintAddress, treeId) {
29
- const treeIdBuffer = Buffer.alloc(2);
30
- treeIdBuffer.writeUInt16LE(treeId);
31
- const [noteTree] = PublicKey.findProgramAddressSync([Buffer.from("privacy_note_tree_v3"), mintAddress.toBuffer(), treeIdBuffer], programId);
32
- return noteTree;
33
- }
34
- /**
35
- * Get the global config PDA.
36
- */
37
- export function getGlobalConfigPda(programId) {
38
- const [globalConfig] = PublicKey.findProgramAddressSync([Buffer.from("global_config_v1")], programId);
39
- return globalConfig;
40
- }
41
- /**
42
- * Get the nullifier marker PDA for a specific nullifier.
43
- * NOTE: Nullifier markers are global (no tree_id) to prevent cross-tree double-spend.
44
- */
45
- export function getNullifierMarkerPda(programId, mintAddress, nullifier) {
46
- const [marker] = PublicKey.findProgramAddressSync([Buffer.from("nullifier_v3"), mintAddress.toBuffer(), nullifier], programId);
47
- return marker;
48
- }
49
- // -----------------------------------------------------------------------------
50
- // On-Chain Account Fetchers
51
- // -----------------------------------------------------------------------------
52
- /**
53
- * Fetch and decode the on-chain PrivacyConfig account for a pool.
54
- */
55
- export async function fetchPoolConfig(program, mintAddress) {
56
- const { config } = getPoolPdas(program.programId, mintAddress);
57
- return program.account.privacyConfig.fetch(config);
58
- }
59
- /**
60
- * Check whether a nullifier has been spent on-chain.
61
- * Returns true if the nullifier marker PDA exists (funds already spent).
62
- */
63
- export async function checkNullifierSpent(program, mintAddress, nullifier) {
64
- const marker = getNullifierMarkerPda(program.programId, mintAddress, nullifier);
65
- const info = await program.provider.connection.getAccountInfo(marker);
66
- return info !== null;
67
- }
68
- const TREE_CAPACITY = Math.pow(2, 22); // 4,194,304 leaves (depth 22)
69
- /**
70
- * Fetch utilization info for a specific tree.
71
- * Returns null if the tree does not exist yet.
72
- */
73
- export async function getTreeInfo(program, mintAddress, treeId) {
74
- try {
75
- const treePDA = getNoteTreePda(program.programId, mintAddress, treeId);
76
- const tree = await program.account.merkleTreeAccount.fetch(treePDA);
77
- const leafCount = Number(tree.nextIndex);
78
- const remainingCapacity = TREE_CAPACITY - leafCount;
79
- return {
80
- treeId,
81
- leafCount,
82
- capacity: TREE_CAPACITY,
83
- utilizationPercent: (leafCount / TREE_CAPACITY) * 100,
84
- remainingCapacity,
85
- isFull: leafCount >= TREE_CAPACITY,
86
- treePDA,
87
- };
88
- }
89
- catch {
90
- return null;
91
- }
92
- }
93
- /**
94
- * Fetch utilization info for all trees in a pool.
95
- */
96
- export async function getAllTreeInfo(program, mintAddress) {
97
- try {
98
- const { config } = getPoolPdas(program.programId, mintAddress);
99
- const cfg = await program.account.privacyConfig.fetch(config);
100
- const numTrees = Number(cfg.numTrees);
101
- const results = [];
102
- for (let id = 0; id < numTrees; id++) {
103
- const info = await getTreeInfo(program, mintAddress, id);
104
- if (info)
105
- results.push(info);
106
- }
107
- return results;
108
- }
109
- catch {
110
- return [];
111
- }
112
- }
113
- /**
114
- * Find the best tree to deposit into.
115
- *
116
- * Strategy (matches veilo-dapp):
117
- * 1. Discard full trees.
118
- * 2. Prefer the LOWEST tree ID with remaining capacity ≥ minCapacity (default 0.01%).
119
- * 3. Ensures trees fill sequentially: 0 → 1 → 2 → …
120
- * 4. Fallback to the tree with the most remaining capacity.
121
- */
122
- export async function getBestTreeForDeposit(program, mintAddress, minCapacity = Math.floor(TREE_CAPACITY * 0.0001)) {
123
- const trees = await getAllTreeInfo(program, mintAddress);
124
- const available = trees.filter((t) => !t.isFull);
125
- if (available.length === 0)
126
- return null;
127
- // Prefer lowest-id tree that still has meaningful capacity
128
- const preferred = available
129
- .filter((t) => t.remainingCapacity >= minCapacity)
130
- .sort((a, b) => a.treeId - b.treeId);
131
- if (preferred.length > 0)
132
- return preferred[0];
133
- // Fallback: most remaining capacity
134
- return available.sort((a, b) => b.remainingCapacity - a.remainingCapacity)[0];
135
- }
136
- // -----------------------------------------------------------------------------
137
- // Error Parsing
138
- // -----------------------------------------------------------------------------
139
- /**
140
- * Convert a Solana/Anchor transaction error into a user-friendly message.
141
- * Maps privacy_pool program error codes (6000–6060) to readable strings.
142
- * Mirrors relayer-server/src/controllers/transaction.helpers.ts `parseOnChainError`.
143
- */
144
- export function parseOnChainError(error) {
145
- const raw = (error?.message ?? error?.toString() ?? "").toLowerCase();
146
- const hexMatch = raw.match(/custom program error:\s*0x([0-9a-f]+)/);
147
- const numMatch = raw.match(/error number:\s*(\d+)/);
148
- const code = hexMatch
149
- ? parseInt(hexMatch[1], 16)
150
- : numMatch
151
- ? parseInt(numMatch[1], 10)
152
- : null;
153
- const PROGRAM_ERRORS = {
154
- 6000: "The pool is temporarily paused. Please try again later.",
155
- 6001: "No denominations configured for this pool.",
156
- 6002: "Too many denominations configured.",
157
- 6003: "Bad denomination index.",
158
- 6004: "Math overflow in the contract. Please try again.",
159
- 6005: "These funds have already been spent.",
160
- 6006: "The nullifier table is full. Please contact support.",
161
- 6007: "The relayer is out of sync with the network. Please wait a moment and try again.",
162
- 6008: "This relayer is not authorised for this pool.",
163
- 6009: "The pool does not have enough funds to fulfil this request.",
164
- 6010: "Too many relayers registered for this pool.",
165
- 6011: "Proof encoding is invalid. Please try again.",
166
- 6012: "Zero-knowledge proof verification failed. Please try again.",
167
- 6013: "The pool is at capacity. Please try again later.",
168
- 6014: "Merkle hash computation failed. Please try again.",
169
- 6015: "Transaction data mismatch. Please refresh and try again.",
170
- 6016: "Recipient address mismatch.",
171
- 6017: "Invalid token address.",
172
- 6018: "The fee exceeds the allowed limit.",
173
- 6019: "The relayer fee was insufficient. Please try again.",
174
- 6020: "Arithmetic error in the contract. Please try again.",
175
- 6021: "Your balance is not enough to cover the withdrawal including network fees.",
176
- 6022: "Your balance is not enough to cover the fee.",
177
- 6023: "Invalid transaction amount. Please try again.",
178
- 6024: "Invalid fee amount. Please try again.",
179
- 6025: "Duplicate fund inputs detected. Please refresh and try again.",
180
- 6026: "Duplicate output detected. Please refresh and try again.",
181
- 6027: "Token account required for SPL token operations.",
182
- 6028: "Token program required for SPL token operations.",
183
- 6029: "Invalid token account authority.",
184
- 6030: "Relayer account does not match the expected relayer.",
185
- 6031: "Relayer token account not owned by the expected relayer.",
186
- 6032: "Recipient token account not owned by the expected recipient.",
187
- 6033: "Depositor token account not owned or delegated to the relayer.",
188
- 6034: "Private transfers must have zero fee and refund.",
189
- 6035: "Amount is below the pool minimum.",
190
- 6036: "Amount exceeds the pool maximum.",
191
- 6037: "Withdrawal amount is below the pool minimum.",
192
- 6038: "Withdrawal amount exceeds the pool maximum.",
193
- 6039: "Invalid pool configuration: minimum exceeds maximum.",
194
- 6040: "Fee basis points exceed the maximum allowed (1%).",
195
- 6041: "Fee error margin exceeds the maximum allowed (50%).",
196
- 6042: "Only the authorized admin can initialize.",
197
- 6043: "Unauthorized: only admin or relayers can perform this action.",
198
- 6044: "Invalid tree ID: tree does not exist.",
199
- 6045: "Maximum number of Merkle trees reached for this pool.",
200
- 6046: "Deposits must use zero nullifiers (no notes consumed).",
201
- 6047: "Nullifier cannot be zero for withdrawals or transfers.",
202
- 6048: "Output commitment cannot be zero.",
203
- 6049: "Token account must be owned by SPL Token Program.",
204
- 6050: "Vault token account must be the canonical Associated Token Account.",
205
- 6051: "Amount is too small to cover the minimum fee. Try a larger amount.",
206
- 6052: "Nullifier marker account does not correspond to zero nullifier for deposits.",
207
- 6053: "Insufficient token delegation for deposit.",
208
- 6054: "Invalid swap program. Please try again.",
209
- 6055: "Invalid swap accounts. Please refresh and try again.",
210
- 6056: "Jupiter swap requires additional routing accounts.",
211
- 6057: "Swap instruction is invalid or unsupported. Please try again.",
212
- 6058: "Swap parameters are inconsistent. Please refresh and try again.",
213
- 6059: "Missing required swap instructions in transaction. Both fund_native_source and transact_swap must be present.",
214
- 6060: "The transaction deadline expired. Please try again.",
215
- };
216
- if (code !== null && PROGRAM_ERRORS[code])
217
- return PROGRAM_ERRORS[code];
218
- if (raw.includes("blockhash not found") ||
219
- raw.includes("block height exceeded"))
220
- return "The transaction expired before it could be confirmed. Please try again.";
221
- if (raw.includes("insufficient funds") ||
222
- raw.includes("insufficient lamports"))
223
- return "Insufficient SOL to pay for the transaction fee.";
224
- if (raw.includes("timeout") || raw.includes("timed out"))
225
- return "The request timed out. Please try again.";
226
- if (raw.includes("simulation failed"))
227
- return "Transaction simulation failed. Please refresh and try again.";
228
- return "The transaction could not be completed. Your funds are safe — please try again.";
229
- }
230
- // -----------------------------------------------------------------------------
231
- // Global Config Initialization
232
- // -----------------------------------------------------------------------------
233
- /**
234
- * Initialize the global config (one-time setup).
235
- */
236
- export async function initializeGlobalConfig(params) {
237
- const { program, admin, payer } = params;
238
- const globalConfig = getGlobalConfigPda(program.programId);
239
- await program.methods
240
- .initializeGlobalConfig()
241
- .accounts({
242
- globalConfig,
243
- admin: admin.publicKey,
244
- payer: payer.publicKey,
245
- systemProgram: SystemProgram.programId,
246
- })
247
- .signers([payer])
248
- .rpc();
249
- }
250
- // -----------------------------------------------------------------------------
251
- // Pool Initialization
252
- // -----------------------------------------------------------------------------
253
- /**
254
- * Initialize a privacy pool with the new parameters.
255
- * Creates the first merkle tree (tree ID 0).
256
- */
257
- export async function initializePool(params) {
258
- const { program, admin, payer, feeBps, mintAddress, minDepositAmount, maxDepositAmount, minWithdrawAmount, maxWithdrawAmount, } = params;
259
- const { config, vault, nullifiers } = getPoolPdas(program.programId, mintAddress);
260
- const noteTree = getNoteTreePda(program.programId, mintAddress, 0);
261
- await program.methods
262
- .initialize(feeBps, mintAddress, minDepositAmount ? new BN(minDepositAmount.toString()) : null, maxDepositAmount ? new BN(maxDepositAmount.toString()) : null, minWithdrawAmount ? new BN(minWithdrawAmount.toString()) : null, maxWithdrawAmount ? new BN(maxWithdrawAmount.toString()) : null)
263
- .accounts({
264
- config,
265
- vault,
266
- noteTree,
267
- nullifiers,
268
- admin: admin.publicKey,
269
- payer: payer.publicKey,
270
- systemProgram: SystemProgram.programId,
271
- })
272
- .signers([payer])
273
- .rpc();
274
- }
275
- // -----------------------------------------------------------------------------
276
- // Pool Config Updates
277
- // -----------------------------------------------------------------------------
278
- /**
279
- * Update pool configuration.
280
- */
281
- export async function updatePoolConfig(params) {
282
- const { program, admin, mintAddress, minDepositAmount, maxDepositAmount, minWithdrawAmount, maxWithdrawAmount, feeBps, feeErrorMarginBps, minWithdrawalFee, minSwapFee, swapFeeBps, } = params;
283
- const { config } = getPoolPdas(program.programId, mintAddress);
284
- await program.methods
285
- .updatePoolConfig(mintAddress, minDepositAmount ? new BN(minDepositAmount.toString()) : null, maxDepositAmount ? new BN(maxDepositAmount.toString()) : null, minWithdrawAmount ? new BN(minWithdrawAmount.toString()) : null, maxWithdrawAmount ? new BN(maxWithdrawAmount.toString()) : null, feeBps != null ? new BN(feeBps) : null, minWithdrawalFee ? new BN(minWithdrawalFee.toString()) : null, feeErrorMarginBps != null ? new BN(feeErrorMarginBps) : null, minSwapFee ? new BN(minSwapFee.toString()) : null, swapFeeBps != null ? new BN(swapFeeBps) : null)
286
- .accounts({
287
- config,
288
- admin: admin.publicKey,
289
- })
290
- .rpc();
291
- }
292
- /**
293
- * Add a new Merkle tree to the pool.
294
- * The treeId must equal the current num_trees value in the pool config.
295
- */
296
- export async function addMerkleTree(params) {
297
- const { program, relayer, mintAddress, treeId } = params;
298
- const { config } = getPoolPdas(program.programId, mintAddress);
299
- const noteTree = getNoteTreePda(program.programId, mintAddress, treeId);
300
- await program.methods
301
- .addMerkleTree(mintAddress, treeId)
302
- .accounts({
303
- config,
304
- noteTree,
305
- relayer: relayer.publicKey,
306
- systemProgram: SystemProgram.programId,
307
- })
308
- .signers([relayer])
309
- .rpc();
310
- }
311
- /**
312
- * Get the pool configuration account.
313
- */
314
- export async function getPoolConfig(program, mintAddress) {
315
- const { config } = getPoolPdas(program.programId, mintAddress);
316
- const account = await program.account.privacyConfig.fetch(config);
317
- return {
318
- bump: account.bump,
319
- vaultBump: account.vaultBump,
320
- admin: account.admin,
321
- feeBps: account.feeBps,
322
- feeErrorMarginBps: account.feeErrorMarginBps,
323
- minWithdrawalFee: BigInt(account.minWithdrawalFee.toString()),
324
- minSwapFee: account.minSwapFee != null ? BigInt(account.minSwapFee.toString()) : 0n,
325
- swapFeeBps: account.swapFeeBps ?? 0,
326
- totalTvl: BigInt(account.totalTvl.toString()),
327
- mintAddress: account.mintAddress,
328
- minDepositAmount: BigInt(account.minDepositAmount.toString()),
329
- maxDepositAmount: BigInt(account.maxDepositAmount.toString()),
330
- minWithdrawAmount: BigInt(account.minWithdrawAmount.toString()),
331
- maxWithdrawAmount: BigInt(account.maxWithdrawAmount.toString()),
332
- numRelayers: account.numRelayers,
333
- relayers: account.relayers,
334
- numTrees: account.numTrees,
335
- nextTreeIndex: account.nextTreeIndex,
336
- };
337
- }
338
- // -----------------------------------------------------------------------------
339
- // Relayer Management
340
- // -----------------------------------------------------------------------------
341
- /**
342
- * Add a relayer to the pool.
343
- */
344
- export async function addRelayer(params) {
345
- const { program, admin, mintAddress, newRelayer } = params;
346
- const { config } = getPoolPdas(program.programId, mintAddress);
347
- await program.methods
348
- .addRelayer(mintAddress, newRelayer)
349
- .accounts({
350
- config,
351
- admin: admin.publicKey,
352
- })
353
- .rpc();
354
- }
355
- // -----------------------------------------------------------------------------
356
- // Pause/Unpause
357
- // -----------------------------------------------------------------------------
358
- /**
359
- * Set the paused state of a pool.
360
- */
361
- export async function setPaused(params) {
362
- const { program, admin, mintAddress, paused } = params;
363
- const { config } = getPoolPdas(program.programId, mintAddress);
364
- await program.methods
365
- .setPaused(mintAddress, paused)
366
- .accounts({
367
- config,
368
- admin: admin.publicKey,
369
- })
370
- .rpc();
371
- }
372
- // -----------------------------------------------------------------------------
373
- // Main Transaction Instruction
374
- // -----------------------------------------------------------------------------
375
- /**
376
- * Execute a transaction on the privacy pool.
377
- * This is the low-level function that calls the on-chain `transact` instruction.
378
- *
379
- * @param publicAmount - Positive for deposits, negative for withdrawals, 0 for transfers
380
- * @param inputTreeId - The tree ID where input UTXOs are located
381
- * @param outputTreeId - The tree ID where output commitments will be inserted
382
- */
383
- export async function transact(params) {
384
- const { program, relayer, recipient, mintAddress, root, inputTreeId, outputTreeId, publicAmount, inputNullifiers, outputCommitments, extData, proof, deadline = 0n, vaultTokenAccount, userTokenAccount, recipientTokenAccount, relayerTokenAccount, } = params;
385
- const { config, vault, nullifiers } = getPoolPdas(program.programId, mintAddress);
386
- const globalConfig = getGlobalConfigPda(program.programId);
387
- const inputTree = getNoteTreePda(program.programId, mintAddress, inputTreeId);
388
- const outputTree = getNoteTreePda(program.programId, mintAddress, outputTreeId);
389
- // Nullifier markers are global (no tree_id) to prevent cross-tree double-spend
390
- const nullifierMarker0 = getNullifierMarkerPda(program.programId, mintAddress, inputNullifiers[0]);
391
- const nullifierMarker1 = getNullifierMarkerPda(program.programId, mintAddress, inputNullifiers[1]);
392
- const extDataHash = computeExtDataHash(extData);
393
- const isNativeSol = mintAddress.equals(NATIVE_SOL_MINT);
394
- // For SPL tokens, resolve token accounts
395
- let vaultTA = vaultTokenAccount;
396
- let userTA = userTokenAccount;
397
- let recipientTA = recipientTokenAccount;
398
- let relayerTA = relayerTokenAccount;
399
- if (!isNativeSol) {
400
- if (!vaultTA) {
401
- vaultTA = await getAssociatedTokenAddress(mintAddress, vault, true);
402
- }
403
- if (!userTA) {
404
- userTA = await getAssociatedTokenAddress(mintAddress, relayer.publicKey);
405
- }
406
- if (!recipientTA) {
407
- recipientTA = await getAssociatedTokenAddress(mintAddress, recipient);
408
- }
409
- if (!relayerTA) {
410
- relayerTA = await getAssociatedTokenAddress(mintAddress, relayer.publicKey);
411
- }
412
- }
413
- const tx = program.methods
414
- .transact(Array.from(root), inputTreeId, outputTreeId, new BN(publicAmount.toString()), Array.from(extDataHash), mintAddress, Array.from(inputNullifiers[0]), Array.from(inputNullifiers[1]), Array.from(outputCommitments[0]), Array.from(outputCommitments[1]), new BN(deadline.toString()), {
415
- recipient: extData.recipient,
416
- relayer: extData.relayer,
417
- fee: new BN(extData.fee.toString()),
418
- refund: new BN(extData.refund.toString()),
419
- }, {
420
- proofA: proof.proofA,
421
- proofB: proof.proofB,
422
- proofC: proof.proofC,
423
- })
424
- .accounts({
425
- config,
426
- globalConfig,
427
- vault,
428
- inputTree,
429
- outputTree,
430
- nullifiers,
431
- nullifierMarker0,
432
- nullifierMarker1,
433
- relayer: relayer.publicKey,
434
- recipient,
435
- vaultTokenAccount: vaultTA ?? vault,
436
- userTokenAccount: userTA ?? relayer.publicKey,
437
- recipientTokenAccount: recipientTA ?? recipient,
438
- relayerTokenAccount: relayerTA ?? relayer.publicKey,
439
- tokenProgram: isNativeSol ? SystemProgram.programId : TOKEN_PROGRAM_ID,
440
- systemProgram: SystemProgram.programId,
441
- })
442
- .signers([relayer]);
443
- return withRpcRetry(() => tx.rpc());
444
- }
445
- /**
446
- * Build an unsigned deposit {@link Transaction} for the privacy pool.
447
- *
448
- * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs
449
- * with the deposit amount. `publicAmount` is positive. The caller is
450
- * responsible for signing and submitting the returned transaction, and then
451
- * calling `commit()` once it confirms.
452
- *
453
- * @param amount - Amount to deposit in lamports/token units
454
- * @param recipientPubkey - UTXO public key that will own the deposited funds
455
- * @param treeId - The tree ID to deposit into (defaults to 0)
456
- */
457
- export async function deposit(params) {
458
- const { program, depositor, amount, mintAddress, recipientPubkey, tree, proofBuilder, treeId = 0, extData: partialExtData, } = params;
459
- // Create a random keypair for the zero inputs (they don't matter since amount is 0)
460
- const zeroKeypair = generateKeypair();
461
- // Create zero input UTXOs (for deposits, we don't spend any existing UTXOs)
462
- const zeroInput0 = createOwnedZeroUTXO(zeroKeypair.privateKey, mintAddress);
463
- const zeroInput1 = createOwnedZeroUTXO(zeroKeypair.privateKey, mintAddress);
464
- // The circuit skips the Merkle proof check for zero-amount inputs (amount == 0
465
- // causes `enabled = 0` in MerkleProofIfEnabled). So we provide a dummy path using
466
- // the tree's pre-computed zero chain without inserting anything into the tree.
467
- const dummyPath = tree.zeroes.slice(0, tree.depth);
468
- const currentRoot = tree.root;
469
- const inputUTXOs = [
470
- {
471
- ...zeroInput0,
472
- pathIndex: 0,
473
- pathElements: dummyPath,
474
- privateKey: zeroKeypair.privateKey,
475
- },
476
- {
477
- ...zeroInput1,
478
- pathIndex: 0,
479
- pathElements: dummyPath,
480
- privateKey: zeroKeypair.privateKey,
481
- },
482
- ];
483
- const outputUTXO0 = createUTXO({
484
- amount: amount,
485
- pubkey: recipientPubkey,
486
- mintAddress,
487
- });
488
- const outputUTXO1 = createUTXO({
489
- amount: 0n,
490
- pubkey: recipientPubkey,
491
- mintAddress,
492
- });
493
- const outputUTXOs = [
494
- outputUTXO0,
495
- outputUTXO1,
496
- ];
497
- const depositorPubkey = depositor.publicKey;
498
- const extData = {
499
- recipient: partialExtData?.recipient ?? depositorPubkey,
500
- relayer: partialExtData?.relayer ?? depositorPubkey,
501
- fee: partialExtData?.fee ?? 0n,
502
- refund: partialExtData?.refund ?? 0n,
503
- claimant: partialExtData?.claimant ?? SystemProgram.programId,
504
- };
505
- const circuitInputs = prepareTransactionInputs({
506
- inputUTXOs,
507
- outputUTXOs,
508
- root: currentRoot,
509
- publicAmount: amount, // Positive for deposits
510
- extData,
511
- mintAddress,
512
- });
513
- const rawProof = await proofBuilder(circuitInputs);
514
- const proof = encodeSnarkjsProofToTransactionProof(rawProof);
515
- // -----------------------------------------------------------------------
516
- // Build the transact instruction inline (duplicated from `transact()`).
517
- //
518
- // We intentionally don't reuse the `transact()` helper: it submits via
519
- // anchor's `.rpc()` with `.signers([relayer])`, which assumes the caller
520
- // holds a real Keypair. For deposit, we want to return an unsigned
521
- // Transaction so the caller (typically a browser wallet) can sign it
522
- // themselves. Duplicating ~40 lines here keeps the change contained to
523
- // this function and leaves the relayer path (`transact()` →
524
- // `withdraw`/`privateTransfer`/`transactSwap`) completely untouched.
525
- // -----------------------------------------------------------------------
526
- const { config, vault, nullifiers } = getPoolPdas(program.programId, mintAddress);
527
- const globalConfig = getGlobalConfigPda(program.programId);
528
- const inputTree = getNoteTreePda(program.programId, mintAddress, treeId);
529
- const outputTree = getNoteTreePda(program.programId, mintAddress, treeId);
530
- const nullifierMarker0 = getNullifierMarkerPda(program.programId, mintAddress, circuitInputs.inputNullifiers[0]);
531
- const nullifierMarker1 = getNullifierMarkerPda(program.programId, mintAddress, circuitInputs.inputNullifiers[1]);
532
- const extDataHash = computeExtDataHash(extData);
533
- const isNativeSol = mintAddress.equals(NATIVE_SOL_MINT);
534
- let vaultTA;
535
- let userTA;
536
- let recipientTA;
537
- let relayerTA;
538
- if (!isNativeSol) {
539
- vaultTA = await getAssociatedTokenAddress(mintAddress, vault, true);
540
- userTA = await getAssociatedTokenAddress(mintAddress, depositorPubkey);
541
- recipientTA = await getAssociatedTokenAddress(mintAddress, extData.recipient);
542
- relayerTA = await getAssociatedTokenAddress(mintAddress, depositorPubkey);
543
- }
544
- const builtTx = await program.methods
545
- .transact(Array.from(currentRoot), treeId, treeId, new BN(amount.toString()), Array.from(extDataHash), mintAddress, Array.from(circuitInputs.inputNullifiers[0]), Array.from(circuitInputs.inputNullifiers[1]), Array.from(circuitInputs.outputCommitments[0]), Array.from(circuitInputs.outputCommitments[1]), new BN(Math.floor(Date.now() / 1000) + 3600), // 1-hour window from build time
546
- {
547
- recipient: extData.recipient,
548
- relayer: extData.relayer,
549
- fee: new BN(extData.fee.toString()),
550
- refund: new BN(extData.refund.toString()),
551
- }, {
552
- proofA: proof.proofA,
553
- proofB: proof.proofB,
554
- proofC: proof.proofC,
555
- })
556
- .accounts({
557
- config,
558
- globalConfig,
559
- vault,
560
- inputTree,
561
- outputTree,
562
- nullifiers,
563
- nullifierMarker0,
564
- nullifierMarker1,
565
- relayer: depositorPubkey,
566
- recipient: extData.recipient,
567
- vaultTokenAccount: vaultTA ?? vault,
568
- userTokenAccount: userTA ?? depositorPubkey,
569
- recipientTokenAccount: recipientTA ?? extData.recipient,
570
- relayerTokenAccount: relayerTA ?? depositorPubkey,
571
- tokenProgram: isNativeSol ? SystemProgram.programId : TOKEN_PROGRAM_ID,
572
- systemProgram: SystemProgram.programId,
573
- })
574
- .transaction();
575
- // Add compute budget instruction for higher CU limit
576
- const computeBudgetIx = ComputeBudgetProgram.setComputeUnitLimit({
577
- units: 1400000,
578
- });
579
- builtTx.instructions.unshift(computeBudgetIx);
580
- // Populate feePayer + recentBlockhash so the wallet only has to sign.
581
- const provider = program.provider;
582
- builtTx.feePayer = depositorPubkey;
583
- const { blockhash } = await provider.connection.getLatestBlockhash();
584
- builtTx.recentBlockhash = blockhash;
585
- const commit = () => {
586
- const { index: outIdx0 } = tree.insert(outputUTXOs[0].commitment);
587
- const { index: outIdx1, root: newRoot } = tree.insert(outputUTXOs[1].commitment);
588
- return {
589
- outputUTXOs,
590
- leafIndices: [outIdx0, outIdx1],
591
- root: newRoot,
592
- };
593
- };
594
- return {
595
- transaction: builtTx,
596
- outputUTXOs,
597
- commit,
598
- };
599
- }
600
- /**
601
- * Withdraw funds from the privacy pool.
602
- *
603
- * For withdrawals, we spend input UTXOs and create change output UTXOs.
604
- * The publicAmount is negative (funds flowing out).
605
- *
606
- * @param withdrawAmount - Amount to withdraw in lamports/token units
607
- * @param inputUTXOs - The UTXOs being spent
608
- * @param changePubkey - UTXO public key for the change output
609
- * @param inputTreeId - The tree ID where input UTXOs are located
610
- * @param outputTreeId - The tree ID where change outputs will be inserted
611
- */
612
- export async function withdraw(params) {
613
- const { program, relayer, recipient, mintAddress, inputUTXOs, changePubkey, withdrawAmount, fee, refund, root, inputTreeId, outputTreeId, tree, proofBuilder, } = params;
614
- const totalInput = inputUTXOs[0].amount + inputUTXOs[1].amount;
615
- const changeAmount = totalInput - withdrawAmount - fee;
616
- if (changeAmount < 0n) {
617
- throw new Error("Insufficient input balance for withdrawal");
618
- }
619
- const changeUTXO = createUTXO({
620
- amount: changeAmount,
621
- pubkey: changePubkey,
622
- mintAddress,
623
- });
624
- const zeroUTXO = createUTXO({
625
- amount: 0n,
626
- pubkey: changePubkey,
627
- mintAddress,
628
- });
629
- const outputUTXOs = [changeUTXO, zeroUTXO];
630
- const extData = {
631
- recipient,
632
- relayer: relayer.publicKey,
633
- fee,
634
- refund,
635
- claimant: SystemProgram.programId,
636
- };
637
- // publicAmount is negative for withdrawals
638
- const publicAmount = -withdrawAmount;
639
- const circuitInputs = prepareTransactionInputs({
640
- inputUTXOs,
641
- outputUTXOs,
642
- root,
643
- publicAmount,
644
- extData,
645
- mintAddress,
646
- });
647
- const rawProof = await proofBuilder(circuitInputs);
648
- const proof = encodeSnarkjsProofToTransactionProof(rawProof);
649
- await transact({
650
- program,
651
- relayer,
652
- recipient,
653
- mintAddress,
654
- root,
655
- inputTreeId,
656
- outputTreeId,
657
- publicAmount,
658
- inputNullifiers: circuitInputs.inputNullifiers,
659
- outputCommitments: circuitInputs.outputCommitments,
660
- extData,
661
- proof,
662
- });
663
- const { index: changeIdx, root: newRoot } = tree.insert(changeUTXO.commitment);
664
- tree.insert(zeroUTXO.commitment);
665
- return {
666
- changeUTXO,
667
- leafIndex: changeIdx,
668
- root: newRoot,
669
- };
670
- }
671
- /**
672
- * Execute a private transfer within the pool.
673
- *
674
- * For transfers, the publicAmount is 0 (no funds enter or leave the pool).
675
- * Input amounts must equal output amounts.
676
- *
677
- * @param inputUTXOs - The UTXOs being spent
678
- * @param outputPubkeys - UTXO public keys for the recipients
679
- * @param outputAmounts - Amounts for each output (must sum to input total)
680
- * @param inputTreeId - The tree ID where input UTXOs are located
681
- * @param outputTreeId - The tree ID where output commitments will be inserted
682
- */
683
- export async function privateTransfer(params) {
684
- const { program, relayer, mintAddress, inputUTXOs, outputPubkeys, outputAmounts, root, inputTreeId, outputTreeId, tree, proofBuilder, fee = 0n, } = params;
685
- const totalInput = inputUTXOs[0].amount + inputUTXOs[1].amount;
686
- const totalOutput = outputAmounts[0] + outputAmounts[1] + fee;
687
- if (totalInput !== totalOutput) {
688
- throw new Error(`Balance mismatch: inputs=${totalInput}, outputs=${totalOutput}`);
689
- }
690
- const outputUTXO0 = createUTXO({
691
- amount: outputAmounts[0],
692
- pubkey: outputPubkeys[0],
693
- mintAddress,
694
- });
695
- const outputUTXO1 = createUTXO({
696
- amount: outputAmounts[1],
697
- pubkey: outputPubkeys[1],
698
- mintAddress,
699
- });
700
- const outputUTXOs = [
701
- outputUTXO0,
702
- outputUTXO1,
703
- ];
704
- // Prepare ext data (for transfers, recipient can be anyone)
705
- const extData = {
706
- recipient: relayer.publicKey, // No external recipient for transfers
707
- relayer: relayer.publicKey,
708
- fee,
709
- refund: 0n,
710
- claimant: SystemProgram.programId,
711
- };
712
- // publicAmount is 0 for transfers
713
- const publicAmount = 0n;
714
- const circuitInputs = prepareTransactionInputs({
715
- inputUTXOs,
716
- outputUTXOs,
717
- root,
718
- publicAmount,
719
- extData,
720
- mintAddress,
721
- });
722
- const rawProof = await proofBuilder(circuitInputs);
723
- const proof = encodeSnarkjsProofToTransactionProof(rawProof);
724
- await transact({
725
- program,
726
- relayer,
727
- recipient: relayer.publicKey,
728
- mintAddress,
729
- root,
730
- inputTreeId,
731
- outputTreeId,
732
- publicAmount,
733
- inputNullifiers: circuitInputs.inputNullifiers,
734
- outputCommitments: circuitInputs.outputCommitments,
735
- extData,
736
- proof,
737
- });
738
- const { index: outIdx0 } = tree.insert(outputUTXOs[0].commitment);
739
- const { index: outIdx1, root: newRoot } = tree.insert(outputUTXOs[1].commitment);
740
- return {
741
- outputUTXOs,
742
- leafIndices: [outIdx0, outIdx1],
743
- root: newRoot,
744
- };
745
- }
746
- // -----------------------------------------------------------------------------
747
- // Global Config
748
- // -----------------------------------------------------------------------------
749
- /**
750
- * Update the global config.
751
- * Currently takes no extra args — only admin verification.
752
- */
753
- export async function updateGlobalConfig(params) {
754
- const { program, admin } = params;
755
- const globalConfig = getGlobalConfigPda(program.programId);
756
- await program.methods
757
- .updateGlobalConfig()
758
- .accounts({
759
- globalConfig,
760
- admin: admin.publicKey,
761
- })
762
- .rpc();
763
- }
764
- // -----------------------------------------------------------------------------
765
- // Swap Helpers
766
- // -----------------------------------------------------------------------------
767
- /**
768
- * Get the swap executor PDA.
769
- * Seeds: ["swap_executor", source_mint, dest_mint, input_nullifier_0, relayer]
770
- */
771
- export function getSwapExecutorPda(programId, sourceMint, destMint, inputNullifier0, relayer) {
772
- const [executor] = PublicKey.findProgramAddressSync([
773
- Buffer.from("swap_executor"),
774
- sourceMint.toBuffer(),
775
- destMint.toBuffer(),
776
- inputNullifier0,
777
- relayer.toBuffer(),
778
- ], programId);
779
- return executor;
780
- }
781
- /**
782
- * Build the `fund_native_source` instruction that pre-funds the swap executor
783
- * with native SOL from the source vault. Only for native SOL source pools.
784
- *
785
- * This instruction MUST be the first instruction in the same atomic transaction
786
- * as `transactSwap`. Call `transactSwap` directly — it handles this internally.
787
- */
788
- export async function fundNativeSource(params) {
789
- const { program, relayer, sourceMint, destMint, inputNullifier0, swapAmount, } = params;
790
- const { vault: sourceVault, config: sourceConfig } = getPoolPdas(program.programId, sourceMint);
791
- const executor = getSwapExecutorPda(program.programId, sourceMint, destMint, inputNullifier0, relayer.publicKey);
792
- const executorSourceToken = await getAssociatedTokenAddress(NATIVE_MINT, executor, true);
793
- return program.methods
794
- .fundNativeSource(sourceMint, destMint, Array.from(inputNullifier0), new BN(swapAmount.toString()))
795
- .accounts({
796
- executor,
797
- executorSourceToken,
798
- sourceVault,
799
- sourceConfig,
800
- sourceMintAccount: NATIVE_MINT,
801
- relayer: relayer.publicKey,
802
- instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
803
- tokenProgram: TOKEN_PROGRAM_ID,
804
- systemProgram: SystemProgram.programId,
805
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
806
- })
807
- .instruction();
808
- }
809
- /**
810
- * Execute an atomic cross-pool private swap.
811
- *
812
- * For native SOL source pools (`sourceMint === NATIVE_SOL_MINT`), this function
813
- * automatically prepends the `fund_native_source` instruction in the same
814
- * transaction so the on-chain atomicity requirement is always satisfied.
815
- *
816
- * @param swapProgram - Jupiter/Raydium CPMM/AMM program ID
817
- * @param swapData - Raw DEX instruction bytes
818
- */
819
- export async function transactSwap(params) {
820
- const { program, relayer, sourceMint, destMint, sourceRoot, sourceTreeId, destTreeId, inputNullifiers, outputCommitments, proof, swapParams, swapAmount, swapData, extData, sourceVaultTokenAccount, sourceMintAccount, destVaultTokenAccount, destMintAccount, relayerTokenAccount, swapProgram, jupiterEventAuthority, } = params;
821
- const { config: sourceConfig, vault: sourceVault, nullifiers: sourceNullifiers, } = getPoolPdas(program.programId, sourceMint);
822
- const { config: destConfig, vault: destVault } = getPoolPdas(program.programId, destMint);
823
- const globalConfig = getGlobalConfigPda(program.programId);
824
- const sourceTree = getNoteTreePda(program.programId, sourceMint, sourceTreeId);
825
- const destTree = getNoteTreePda(program.programId, destMint, destTreeId);
826
- const sourceNullifierMarker0 = getNullifierMarkerPda(program.programId, sourceMint, inputNullifiers[0]);
827
- const sourceNullifierMarker1 = getNullifierMarkerPda(program.programId, sourceMint, inputNullifiers[1]);
828
- const executor = getSwapExecutorPda(program.programId, sourceMint, destMint, inputNullifiers[0], relayer.publicKey);
829
- const executorSourceToken = await getAssociatedTokenAddress(sourceMintAccount, executor, true);
830
- const executorDestToken = await getAssociatedTokenAddress(destMintAccount, executor, true);
831
- const swapIx = await program.methods
832
- .transactSwap({
833
- proofA: proof.proofA,
834
- proofB: proof.proofB,
835
- proofC: proof.proofC,
836
- }, Array.from(sourceRoot), sourceTreeId, sourceMint, Array.from(inputNullifiers[0]), Array.from(inputNullifiers[1]), destTreeId, destMint, Array.from(outputCommitments[0]), Array.from(outputCommitments[1]), {
837
- minAmountOut: new BN(swapParams.minAmountOut.toString()),
838
- deadline: new BN(swapParams.deadline.toString()),
839
- sourceMint: swapParams.sourceMint,
840
- destMint: swapParams.destMint,
841
- destAmount: new BN(swapParams.destAmount.toString()),
842
- swapDataHash: Array.from(swapParams.swapDataHash),
843
- }, new BN(swapAmount.toString()), swapData, {
844
- recipient: extData.recipient,
845
- relayer: extData.relayer,
846
- fee: new BN(extData.fee.toString()),
847
- refund: new BN(extData.refund.toString()),
848
- })
849
- .accounts({
850
- sourceConfig,
851
- globalConfig,
852
- sourceVault,
853
- sourceTree,
854
- sourceNullifiers,
855
- sourceNullifierMarker0,
856
- sourceNullifierMarker1,
857
- sourceVaultTokenAccount,
858
- sourceMintAccount,
859
- destConfig,
860
- destVault,
861
- destTree,
862
- destVaultTokenAccount,
863
- destMintAccount,
864
- executor,
865
- executorSourceToken,
866
- executorDestToken,
867
- relayer: relayer.publicKey,
868
- relayerTokenAccount,
869
- swapProgram,
870
- jupiterEventAuthority,
871
- tokenProgram: TOKEN_PROGRAM_ID,
872
- systemProgram: SystemProgram.programId,
873
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
874
- })
875
- .instruction();
876
- const provider = program.provider;
877
- const tx = new Transaction();
878
- if (sourceMint.equals(NATIVE_SOL_MINT)) {
879
- const fundIx = await fundNativeSource({
880
- program,
881
- relayer,
882
- sourceMint,
883
- destMint,
884
- inputNullifier0: inputNullifiers[0],
885
- swapAmount,
886
- });
887
- tx.add(fundIx);
888
- }
889
- tx.add(swapIx);
890
- return withRpcRetry(() => provider.sendAndConfirm(tx, [relayer]));
891
- }
1
+ // Backward-compatible entry point. Implementations are grouped by domain.
2
+ export * from "./accounts/index.js";
3
+ export * from "./transactions/index.js";