@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,249 +1,2 @@
1
- import nacl from "tweetnacl";
2
- const DEFAULT_RELAYER_URL = "https://relayer-server.onrender.com";
3
- // =============================================================================
4
- // Structured Error
5
- // =============================================================================
6
- /** Structured error thrown by VeiloRelayerClient on API failures. */
7
- export class VeiloApiError extends Error {
8
- constructor(code, message, status, details) {
9
- super(message);
10
- this.name = "VeiloApiError";
11
- this.code = code;
12
- this.status = status;
13
- this.details = details;
14
- }
15
- }
16
- const DEFAULT_RETRY = {
17
- maxRetries: 3,
18
- baseDelayMs: 1000,
19
- retryableStatuses: [429, 502, 503, 504],
20
- };
21
- // =============================================================================
22
- // Base64 helpers (no dependency on tweetnacl-util)
23
- // =============================================================================
24
- function toBase64(bytes) {
25
- if (typeof Buffer !== "undefined") {
26
- return Buffer.from(bytes).toString("base64");
27
- }
28
- return btoa(String.fromCharCode(...bytes));
29
- }
30
- function fromBase64(str) {
31
- if (typeof Buffer !== "undefined") {
32
- return new Uint8Array(Buffer.from(str, "base64"));
33
- }
34
- const binary = atob(str);
35
- const bytes = new Uint8Array(binary.length);
36
- for (let i = 0; i < binary.length; i++)
37
- bytes[i] = binary.charCodeAt(i);
38
- return bytes;
39
- }
40
- // =============================================================================
41
- // Encryption
42
- // =============================================================================
43
- /**
44
- * Encrypt a JSON-serializable payload for the relayer using NaCl box.
45
- * Layout: [ephemeralPubKey (32)] [nonce (24)] [ciphertext (...)]
46
- */
47
- function encryptForRelayer(data, relayerPublicKey) {
48
- const ephemeral = nacl.box.keyPair();
49
- const message = new TextEncoder().encode(JSON.stringify(data));
50
- const nonce = nacl.randomBytes(nacl.box.nonceLength);
51
- const ciphertext = nacl.box(message, nonce, relayerPublicKey, ephemeral.secretKey);
52
- const payload = new Uint8Array(ephemeral.publicKey.length + nonce.length + ciphertext.length);
53
- payload.set(ephemeral.publicKey, 0);
54
- payload.set(nonce, ephemeral.publicKey.length);
55
- payload.set(ciphertext, ephemeral.publicKey.length + nonce.length);
56
- return toBase64(payload);
57
- }
58
- // =============================================================================
59
- // Relayer Client
60
- // =============================================================================
61
- /**
62
- * HTTP client for the Veilo relayer API.
63
- *
64
- * Handles auth, notes, merkle, and encrypted transact endpoints with
65
- * automatic retry on transient failures and NaCl box payload encryption.
66
- *
67
- * @example
68
- * ```ts
69
- * const client = new VeiloRelayerClient({
70
- * apiKey: "your-api-key",
71
- * relayerPublicKey: "<base64 NaCl public key>",
72
- * });
73
- * const root = await client.getMerkleRoot("So111...");
74
- * ```
75
- */
76
- export class VeiloRelayerClient {
77
- constructor(config, retry) {
78
- this.baseUrl = (config.relayerUrl?.trim() || DEFAULT_RELAYER_URL).replace(/\/+$/, "");
79
- this.apiKey = config.apiKey;
80
- this.relayerPubKey = fromBase64(config.relayerPublicKey);
81
- this.authToken = config.authToken;
82
- this.retry = { ...DEFAULT_RETRY, ...retry };
83
- }
84
- /** Update the auth token (e.g. after register/restore). */
85
- setAuthToken(token) {
86
- this.authToken = token;
87
- }
88
- // ---------------------------------------------------------------------------
89
- // Internal helpers
90
- // ---------------------------------------------------------------------------
91
- headers(authenticated) {
92
- const h = {
93
- "Content-Type": "application/json",
94
- };
95
- if (this.apiKey)
96
- h["x-api-key"] = this.apiKey;
97
- if (authenticated && this.authToken) {
98
- h["Authorization"] = `Bearer ${this.authToken}`;
99
- }
100
- return h;
101
- }
102
- async request(method, path, opts = {}) {
103
- const url = `${this.baseUrl}/api${path}`;
104
- const { body, authenticated = false, retryable = true } = opts;
105
- const maxAttempts = retryable ? this.retry.maxRetries + 1 : 1;
106
- let lastError;
107
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
108
- if (attempt > 0) {
109
- const delay = this.retry.baseDelayMs * Math.pow(2, attempt - 1) +
110
- Math.random() * 200;
111
- await new Promise((r) => setTimeout(r, delay));
112
- }
113
- let res;
114
- try {
115
- res = await fetch(url, {
116
- method,
117
- headers: this.headers(authenticated),
118
- body: body != null ? JSON.stringify(body) : undefined,
119
- });
120
- }
121
- catch (err) {
122
- lastError = new VeiloApiError("NETWORK_ERROR", err.message || "Network request failed", 0);
123
- continue;
124
- }
125
- const data = await res.json().catch(() => ({}));
126
- if (res.ok && data.success !== false) {
127
- return data;
128
- }
129
- lastError = new VeiloApiError(data.error || "UNKNOWN", data.message || data.error || `Request failed: ${res.status}`, res.status, data);
130
- // Only retry on transient statuses
131
- if (!this.retry.retryableStatuses.includes(res.status)) {
132
- throw lastError;
133
- }
134
- }
135
- throw lastError;
136
- }
137
- encrypt(data) {
138
- return encryptForRelayer({
139
- ...data,
140
- timestamp: Date.now(),
141
- nonce: toBase64(nacl.randomBytes(32)),
142
- }, this.relayerPubKey);
143
- }
144
- // ---------------------------------------------------------------------------
145
- // Auth
146
- // ---------------------------------------------------------------------------
147
- /** Request a signature challenge for wallet authentication. */
148
- async getChallenge(walletPublicKey) {
149
- return this.request("POST", "/auth/challenge", {
150
- body: { walletPublicKey },
151
- });
152
- }
153
- /** Register a new account with a signed challenge. Returns a JWT auth token. */
154
- async register(data) {
155
- return this.request("POST", "/auth/register", { body: data });
156
- }
157
- /** Restore an existing account using a signed challenge. Returns a JWT auth token. */
158
- async restore(data) {
159
- return this.request("POST", "/auth/restore", { body: data });
160
- }
161
- /** Check whether a username is available for registration. */
162
- async checkUsername(username) {
163
- return this.request("GET", `/auth/checkUsername?username=${encodeURIComponent(username)}`);
164
- }
165
- /** Look up a user's Veilo public key by username or wallet public key. */
166
- async getVeiloPublicKey(params) {
167
- const query = "username" in params && params.username
168
- ? `username=${encodeURIComponent(params.username)}`
169
- : `publicKey=${encodeURIComponent(params.publicKey)}`;
170
- return this.request("GET", `/auth/veiloPublicKey?${query}`);
171
- }
172
- /**
173
- * Provision (or retrieve) the Veilo spend key paired with a Solana address.
174
- * Public and idempotent; the response contains public key material only.
175
- */
176
- async preRegisterKey(solanaAddress) {
177
- return this.request("POST", "/auth/pre-register-key", {
178
- body: { solanaAddress },
179
- });
180
- }
181
- // ---------------------------------------------------------------------------
182
- // Notes
183
- // ---------------------------------------------------------------------------
184
- /** Save an encrypted note to the relayer's database. */
185
- async saveEncryptedNote(data) {
186
- return this.request("POST", "/notes/save", { body: data });
187
- }
188
- /** Query encrypted notes for the authenticated user. Requires auth token. */
189
- async queryEncryptedNotes(params = {}) {
190
- return this.request("POST", "/notes/query", {
191
- body: params,
192
- authenticated: true,
193
- });
194
- }
195
- /** Delete all stored data for the authenticated user. Requires auth token. */
196
- async deleteUserData() {
197
- return this.request("POST", "/notes/delete", { authenticated: true });
198
- }
199
- // ---------------------------------------------------------------------------
200
- // Merkle
201
- // ---------------------------------------------------------------------------
202
- /** Fetch the current Merkle root for a pool, optionally filtered by mint and tree ID. */
203
- async getMerkleRoot(mintAddress, treeId) {
204
- const params = new URLSearchParams();
205
- if (mintAddress)
206
- params.append("mintAddress", mintAddress);
207
- if (treeId !== undefined)
208
- params.append("treeId", treeId.toString());
209
- const qs = params.toString();
210
- return this.request("GET", `/merkle/root${qs ? `?${qs}` : ""}`);
211
- }
212
- /** Fetch the full Merkle tree (all leaves) for a pool. */
213
- async getMerkleTree(mintAddress, treeId) {
214
- const params = new URLSearchParams();
215
- if (mintAddress)
216
- params.append("mintAddress", mintAddress);
217
- if (treeId !== undefined)
218
- params.append("treeId", treeId.toString());
219
- const qs = params.toString();
220
- return this.request("GET", `/merkle/tree${qs ? `?${qs}` : ""}`);
221
- }
222
- // ---------------------------------------------------------------------------
223
- // Transact (encrypted payloads)
224
- // ---------------------------------------------------------------------------
225
- /** Submit an encrypted withdrawal request to the relayer. Not retried on failure. */
226
- async submitWithdraw(data) {
227
- const encryptedPayload = this.encrypt(data);
228
- return this.request("POST", "/transact/withdra", {
229
- body: { encryptedPayload },
230
- retryable: false,
231
- });
232
- }
233
- /** Submit an encrypted private transfer request. Not retried on failure. */
234
- async submitPrivateTransfer(data) {
235
- const encryptedPayload = this.encrypt(data);
236
- return this.request("POST", "/transact/private-transfer", {
237
- body: { encryptedPayload },
238
- retryable: false,
239
- });
240
- }
241
- /** Submit an encrypted private swap request. Not retried on failure. */
242
- async submitPrivateSwap(data) {
243
- const encryptedPayload = this.encrypt(data);
244
- return this.request("POST", "/transact/private-swap", {
245
- body: { encryptedPayload },
246
- retryable: false,
247
- });
248
- }
249
- }
1
+ // Backward-compatible entry point. Relayer responsibilities live in src/relayer.
2
+ export * from "./relayer/index.js";
@@ -1,6 +1,6 @@
1
1
  import { ComputeBudgetProgram, PublicKey, SystemProgram, } from "@solana/web3.js";
2
2
  import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress, getAssociatedTokenAddressSync, } from "@solana/spl-token";
3
- import { getGlobalConfigPda, getNoteTreePda, getPoolPdas, } from "../client.js";
3
+ import { getGlobalConfigPda, getNoteTreePda, getPoolPdas, } from "../accounts/pdas.js";
4
4
  import { PRIVACY_POOL_PROGRAM_ID } from "../program.js";
5
5
  import { NATIVE_SOL_MINT } from "../config.js";
6
6
  import { ShieldError } from "./errors.js";
@@ -1,4 +1,4 @@
1
- import { parseOnChainError } from "../client.js";
1
+ import { parseOnChainError } from "../accounts/errors.js";
2
2
  export class ShieldError extends Error {
3
3
  constructor(code, message, opts = {}) {
4
4
  super(message);
@@ -1,6 +1,6 @@
1
1
  import * as anchor from "@coral-xyz/anchor";
2
2
  import { PRIVACY_POOL_IDL, PRIVACY_POOL_PROGRAM_ID } from "../program.js";
3
- import { encryptBlindMailboxNote } from "../utxo.js";
3
+ import { encryptBlindMailboxNote } from "../notes/mailbox.js";
4
4
  import { bigIntToBytesBE } from "../poseidon.js";
5
5
  import { ShieldError } from "./errors.js";
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
- import type { TransactionProofStruct } from "../proof.js";
2
+ import type { TransactionProofStruct } from "../proofs/types.js";
3
3
  /**
4
4
  * `transact` instruction assembly, driven by the IDL rather than by a
5
5
  * hand-written account list.
@@ -1,5 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { VeiloApiError, VeiloRelayerClient } from "../relayer.js";
2
+ import { VeiloRelayerClient } from "../relayer/client.js";
3
+ import { VeiloApiError } from "../relayer/errors.js";
3
4
  import { ShieldError } from "./errors.js";
4
5
  /**
5
6
  * Owner resolution is a Veilo protocol service, not an integrator-selected
@@ -12,10 +13,7 @@ import { ShieldError } from "./errors.js";
12
13
  * inspectable. The two owner endpoints used below are intentionally public and
13
14
  * return public key material only.
14
15
  */
15
- const OWNER_RELAYER = new VeiloRelayerClient({
16
- apiKey: "",
17
- relayerPublicKey: "utVxnA7zax09qJCZ7UJsa8PAOoWLRcCwOkdxg/ZGmD4=",
18
- });
16
+ const OWNER_RELAYER = new VeiloRelayerClient();
19
17
  /**
20
18
  * Resolve a shield recipient into the pair of keys that must belong to the same
21
19
  * account.
@@ -1,5 +1,5 @@
1
1
  import { createReadonlyVeiloProgram, PRIVACY_POOL_PROGRAM_ID } from "../program.js";
2
- import { getNoteTreePda, getPoolPdas } from "../client.js";
2
+ import { getNoteTreePda, getPoolPdas } from "../accounts/pdas.js";
3
3
  import { MERKLE_TREE_DEPTH } from "../config.js";
4
4
  import { ShieldError } from "./errors.js";
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { createRevokeInstruction, getAccount, getAssociatedTokenAddress, TokenAccountNotFoundError, } from "@solana/spl-token";
2
- import { getPoolPdas } from "../client.js";
2
+ import { getPoolPdas } from "../accounts/pdas.js";
3
3
  import { createReadonlyVeiloProgram, PRIVACY_POOL_PROGRAM_ID } from "../program.js";
4
4
  import { NATIVE_SOL_MINT } from "../config.js";
5
5
  import { ShieldError } from "./errors.js";
@@ -1,12 +1,13 @@
1
1
  import { ComputeBudgetProgram, PublicKey, SystemProgram, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
2
2
  import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token";
3
3
  import { PRIVACY_POOL_PROGRAM_ID } from "../program.js";
4
- import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../client.js";
4
+ import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../accounts/pdas.js";
5
5
  import { MERKLE_TREE_DEPTH, NATIVE_SOL_MINT } from "../config.js";
6
6
  import { bigIntToBytesBE, bytesToBigIntBE, BN254_FR_MODULUS, } from "../poseidon.js";
7
7
  import { poseidonZeroChain } from "../merkle.js";
8
- import { createUTXO, createOwnedZeroUTXO, generateKeypair, } from "../utxo.js";
9
- import { computeExtDataHash, encodeSnarkjsProofToTransactionProof, prepareTransactionInputs, } from "../proof.js";
8
+ import { createUTXO, createOwnedZeroUTXO, generateKeypair, } from "../notes/model.js";
9
+ import { computeExtDataHash, prepareTransactionInputs, } from "../proofs/transaction.js";
10
+ import { encodeSnarkjsProofToTransactionProof } from "../proofs/encoding.js";
10
11
  import { createCompactNoteCipher, emptyNoteCipher } from "../compactNote.js";
11
12
  import { buildTransactInstruction } from "./ix.js";
12
13
  import { sharedDepositAlt } from "./alt.js";
@@ -1,5 +1,5 @@
1
1
  import { AddressLookupTableAccount, Connection, PublicKey, VersionedTransaction } from "@solana/web3.js";
2
- import type { TransactionProofBuilder, TransactionProofStruct } from "../proof.js";
2
+ import type { TransactionProofBuilder, TransactionProofStruct } from "../proofs/types.js";
3
3
  import type { CompactNoteCipher } from "../compactNote.js";
4
4
  /**
5
5
  * Who owns the resulting note. Both halves are required and neither is derived
@@ -0,0 +1,94 @@
1
+ import type { Program, Idl } from "@coral-xyz/anchor";
2
+ import { PublicKey, Transaction } from "@solana/web3.js";
3
+ import type { ExtData, TransactionProofBuilder } from "../proofs/types.js";
4
+ import type { SerializedUTXO } from "../notes/model.js";
5
+ import { MerkleTree } from "../merkle.js";
6
+ import { type NoteCiphers } from "../compactNote.js";
7
+ /**
8
+ * Result of a deposit operation, produced by `DepositBuild.commit()` after the
9
+ * caller has successfully submitted the deposit transaction on-chain.
10
+ */
11
+ export type DepositResult = {
12
+ /** The output UTXOs created by the deposit */
13
+ outputUTXOs: [SerializedUTXO, SerializedUTXO];
14
+ /** The leaf indices where the UTXOs were inserted */
15
+ leafIndices: [number, number];
16
+ /** The new Merkle root after insertion */
17
+ root: Uint8Array;
18
+ };
19
+ /**
20
+ * The return of `deposit()`. Instead of submitting the transaction itself,
21
+ * `deposit()` hands back an unsigned {@link Transaction} so the caller can
22
+ * sign it with whatever wallet they control (Solana wallet-adapter, Ledger,
23
+ * anchor NodeWallet, etc.) and submit it on their own terms.
24
+ *
25
+ * Usage pattern (browser / wallet-adapter):
26
+ *
27
+ * const { transaction, commit } = await deposit({ ... });
28
+ * const signed = await wallet.signTransaction(transaction);
29
+ * const sig = await connection.sendRawTransaction(signed.serialize());
30
+ * await connection.confirmTransaction(sig, "confirmed");
31
+ * const result = commit(); // updates the local tree, returns DepositResult
32
+ */
33
+ export type DepositBuild = {
34
+ /**
35
+ * Unsigned {@link Transaction} for the deposit. `feePayer` and
36
+ * `recentBlockhash` are already populated, so the caller only needs to sign
37
+ * and send.
38
+ */
39
+ transaction: Transaction;
40
+ /**
41
+ * Output UTXOs created by this deposit. Safe to read before submission —
42
+ * the commitment values are deterministic from the circuit inputs and do
43
+ * not depend on the on-chain result.
44
+ */
45
+ outputUTXOs: [SerializedUTXO, SerializedUTXO];
46
+ /**
47
+ * Inserts the two output commitments into the local {@link MerkleTree} and
48
+ * returns the receipt. Call this **only after** the on-chain transaction
49
+ * has been confirmed — deferring the insert keeps the local tree
50
+ * consistent with chain state if the submission fails.
51
+ *
52
+ * Calling `commit()` more than once is unsupported and will corrupt the
53
+ * local tree.
54
+ */
55
+ commit: () => DepositResult;
56
+ };
57
+ /**
58
+ * Build an unsigned deposit {@link Transaction} for the privacy pool.
59
+ *
60
+ * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs
61
+ * with the deposit amount. `publicAmount` is positive. The caller is
62
+ * responsible for signing and submitting the returned transaction, and then
63
+ * calling `commit()` once it confirms.
64
+ *
65
+ * @param amount - Amount to deposit in lamports/token units
66
+ * @param recipientPubkey - UTXO public key that will own the deposited funds
67
+ * @param treeId - The tree ID to deposit into (defaults to 0)
68
+ */
69
+ export declare function deposit<T extends Idl>(params: {
70
+ program: Program<T>;
71
+ /**
72
+ * Account that will pay for and sign the deposit transaction. Only
73
+ * `publicKey` is read — `deposit()` never touches a secret key. A browser
74
+ * wallet-adapter wallet, a Node `anchor.Wallet`, or a raw `Keypair` are all
75
+ * structurally acceptable.
76
+ */
77
+ depositor: {
78
+ publicKey: PublicKey;
79
+ };
80
+ amount: bigint;
81
+ mintAddress: PublicKey;
82
+ recipientPubkey: bigint;
83
+ tree: MerkleTree;
84
+ proofBuilder: TransactionProofBuilder;
85
+ treeId?: number;
86
+ extData?: Partial<ExtData>;
87
+ /** Solana wallet key used to make output note 0 recoverable from chain events. */
88
+ noteRecipientWallet?: PublicKey | Uint8Array;
89
+ /** Prebuilt recovery payload. Takes precedence over noteRecipientWallet. */
90
+ noteCiphers?: NoteCiphers | null;
91
+ }): Promise<DepositBuild>;
92
+ /**
93
+ * Result of a withdrawal operation.
94
+ */
@@ -0,0 +1,198 @@
1
+ import * as anchor from "@coral-xyz/anchor";
2
+ import { ComputeBudgetProgram, PublicKey, SystemProgram, } from "@solana/web3.js";
3
+ import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token";
4
+ import { computeExtDataHash, prepareTransactionInputs, } from "../proofs/transaction.js";
5
+ import { encodeSnarkjsProofToTransactionProof } from "../proofs/encoding.js";
6
+ import { createOwnedZeroUTXO, createUTXO, generateKeypair, } from "../notes/model.js";
7
+ import { NATIVE_SOL_MINT } from "../config.js";
8
+ import { bigIntToBytesBE } from "../poseidon.js";
9
+ import { createNoteCiphers, } from "../compactNote.js";
10
+ import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../accounts/pdas.js";
11
+ // Anchor is CJS and does not expose BN as a detectable Node ESM named export.
12
+ const { BN } = anchor;
13
+ /**
14
+ * Build an unsigned deposit {@link Transaction} for the privacy pool.
15
+ *
16
+ * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs
17
+ * with the deposit amount. `publicAmount` is positive. The caller is
18
+ * responsible for signing and submitting the returned transaction, and then
19
+ * calling `commit()` once it confirms.
20
+ *
21
+ * @param amount - Amount to deposit in lamports/token units
22
+ * @param recipientPubkey - UTXO public key that will own the deposited funds
23
+ * @param treeId - The tree ID to deposit into (defaults to 0)
24
+ */
25
+ export async function deposit(params) {
26
+ const { program, depositor, amount, mintAddress, recipientPubkey, tree, proofBuilder, treeId = 0, extData: partialExtData, noteRecipientWallet, noteCiphers, } = params;
27
+ if (amount <= 0n) {
28
+ throw new Error("Deposit amount must be positive");
29
+ }
30
+ // Create zero input UTXOs (for deposits, we don't spend any existing UTXOs)
31
+ const zeroKeypair0 = generateKeypair();
32
+ const zeroKeypair1 = generateKeypair();
33
+ const zeroInput0 = createOwnedZeroUTXO(zeroKeypair0.privateKey, mintAddress);
34
+ const zeroInput1 = createOwnedZeroUTXO(zeroKeypair1.privateKey, mintAddress);
35
+ // The circuit skips the Merkle proof check for zero-amount inputs (amount == 0
36
+ // causes `enabled = 0` in MerkleProofIfEnabled). So we provide a dummy path using
37
+ // the tree's pre-computed zero chain without inserting anything into the tree.
38
+ const dummyPath = tree.zeroes.slice(0, tree.depth);
39
+ const currentRoot = tree.root;
40
+ const inputUTXOs = [
41
+ {
42
+ ...zeroInput0,
43
+ pathIndex: 0,
44
+ pathElements: dummyPath,
45
+ privateKey: zeroKeypair0.privateKey,
46
+ },
47
+ {
48
+ ...zeroInput1,
49
+ pathIndex: 0,
50
+ pathElements: dummyPath,
51
+ privateKey: zeroKeypair1.privateKey,
52
+ },
53
+ ];
54
+ const outputUTXO0 = createUTXO({
55
+ amount: amount,
56
+ pubkey: recipientPubkey,
57
+ mintAddress,
58
+ });
59
+ const outputUTXO1 = createUTXO({
60
+ amount: 0n,
61
+ pubkey: generateKeypair().publicKey,
62
+ mintAddress,
63
+ });
64
+ const outputUTXOs = [
65
+ outputUTXO0,
66
+ outputUTXO1,
67
+ ];
68
+ const depositorPubkey = depositor.publicKey;
69
+ const extData = {
70
+ recipient: partialExtData?.recipient ?? depositorPubkey,
71
+ relayer: partialExtData?.relayer ?? depositorPubkey,
72
+ fee: partialExtData?.fee ?? 0n,
73
+ refund: partialExtData?.refund ?? 0n,
74
+ claimant: partialExtData?.claimant ?? SystemProgram.programId,
75
+ };
76
+ if (!extData.relayer.equals(depositorPubkey)) {
77
+ throw new Error("Deposit extData.relayer must be the signing depositor");
78
+ }
79
+ if (extData.fee !== 0n || extData.refund !== 0n) {
80
+ throw new Error("Deposits require extData fee and refund to be zero");
81
+ }
82
+ const circuitInputs = prepareTransactionInputs({
83
+ inputUTXOs,
84
+ outputUTXOs,
85
+ root: currentRoot,
86
+ publicAmount: amount, // Positive for deposits
87
+ extData,
88
+ mintAddress,
89
+ });
90
+ const rawProof = await proofBuilder(circuitInputs);
91
+ const proof = encodeSnarkjsProofToTransactionProof(rawProof);
92
+ const depositNoteCiphers = noteCiphers !== undefined
93
+ ? noteCiphers
94
+ : noteRecipientWallet
95
+ ? createNoteCiphers({
96
+ recipientWalletPubkey: noteRecipientWallet instanceof PublicKey
97
+ ? noteRecipientWallet.toBytes()
98
+ : noteRecipientWallet,
99
+ blinding: bigIntToBytesBE(outputUTXO0.blinding),
100
+ amount: outputUTXO0.amount,
101
+ }, null)
102
+ : null;
103
+ // -----------------------------------------------------------------------
104
+ // Build the transact instruction inline because deposits return an unsigned
105
+ // wallet-signable transaction while `transact()` submits with a Keypair.
106
+ //
107
+ // We intentionally don't reuse the `transact()` helper: it submits via
108
+ // anchor's `.rpc()` with `.signers([relayer])`, which assumes the caller
109
+ // holds a real Keypair. For deposit, we want to return an unsigned
110
+ // Transaction so the caller (typically a browser wallet) can sign it.
111
+ // -----------------------------------------------------------------------
112
+ const { config, vault, nullifiers } = getPoolPdas(program.programId, mintAddress);
113
+ const globalConfig = getGlobalConfigPda(program.programId);
114
+ const inputTree = getNoteTreePda(program.programId, mintAddress, treeId);
115
+ const outputTree = getNoteTreePda(program.programId, mintAddress, treeId);
116
+ const nullifierMarker0 = getNullifierMarkerPda(program.programId, mintAddress, circuitInputs.inputNullifiers[0]);
117
+ const nullifierMarker1 = getNullifierMarkerPda(program.programId, mintAddress, circuitInputs.inputNullifiers[1]);
118
+ const extDataHash = computeExtDataHash(extData);
119
+ const isNativeSol = mintAddress.equals(NATIVE_SOL_MINT);
120
+ let vaultTA;
121
+ let userTA;
122
+ let recipientTA;
123
+ let relayerTA;
124
+ if (!isNativeSol) {
125
+ vaultTA = await getAssociatedTokenAddress(mintAddress, vault, true);
126
+ userTA = await getAssociatedTokenAddress(mintAddress, depositorPubkey);
127
+ recipientTA = await getAssociatedTokenAddress(mintAddress, extData.recipient);
128
+ relayerTA = await getAssociatedTokenAddress(mintAddress, depositorPubkey);
129
+ }
130
+ const builtTx = await program.methods
131
+ .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
132
+ {
133
+ recipient: extData.recipient,
134
+ relayer: extData.relayer,
135
+ fee: new BN(extData.fee.toString()),
136
+ refund: new BN(extData.refund.toString()),
137
+ claimant: extData.claimant,
138
+ }, {
139
+ proofA: proof.proofA,
140
+ proofB: proof.proofB,
141
+ proofC: proof.proofC,
142
+ }, depositNoteCiphers
143
+ ? {
144
+ note0EphemeralKey: Array.from(depositNoteCiphers.note0EphemeralKey),
145
+ note0Encrypted: Array.from(depositNoteCiphers.note0Encrypted),
146
+ note0ViewTag: depositNoteCiphers.note0ViewTag,
147
+ note1EphemeralKey: Array.from(depositNoteCiphers.note1EphemeralKey),
148
+ note1Encrypted: Array.from(depositNoteCiphers.note1Encrypted),
149
+ note1ViewTag: depositNoteCiphers.note1ViewTag,
150
+ }
151
+ : null)
152
+ .accountsStrict({
153
+ config,
154
+ globalConfig,
155
+ vault,
156
+ inputTree,
157
+ outputTree,
158
+ nullifiers,
159
+ nullifierMarker0,
160
+ nullifierMarker1,
161
+ relayer: depositorPubkey,
162
+ recipient: extData.recipient,
163
+ vaultTokenAccount: vaultTA ?? depositorPubkey,
164
+ userTokenAccount: userTA ?? depositorPubkey,
165
+ recipientTokenAccount: recipientTA ?? extData.recipient,
166
+ relayerTokenAccount: relayerTA ?? depositorPubkey,
167
+ tokenProgram: isNativeSol ? SystemProgram.programId : TOKEN_PROGRAM_ID,
168
+ systemProgram: SystemProgram.programId,
169
+ })
170
+ .transaction();
171
+ // Add compute budget instruction for higher CU limit
172
+ const computeBudgetIx = ComputeBudgetProgram.setComputeUnitLimit({
173
+ units: 1000000,
174
+ });
175
+ builtTx.instructions.unshift(computeBudgetIx);
176
+ // Populate feePayer + recentBlockhash so the wallet only has to sign.
177
+ const provider = program.provider;
178
+ builtTx.feePayer = depositorPubkey;
179
+ const { blockhash } = await provider.connection.getLatestBlockhash();
180
+ builtTx.recentBlockhash = blockhash;
181
+ const commit = () => {
182
+ const { index: outIdx0 } = tree.insert(outputUTXOs[0].commitment);
183
+ const { index: outIdx1, root: newRoot } = tree.insert(outputUTXOs[1].commitment);
184
+ return {
185
+ outputUTXOs,
186
+ leafIndices: [outIdx0, outIdx1],
187
+ root: newRoot,
188
+ };
189
+ };
190
+ return {
191
+ transaction: builtTx,
192
+ outputUTXOs,
193
+ commit,
194
+ };
195
+ }
196
+ /**
197
+ * Result of a withdrawal operation.
198
+ */
@@ -0,0 +1,7 @@
1
+ export * from "./transact.js";
2
+ export * from "./deposit.js";
3
+ export * from "./withdraw.js";
4
+ export * from "./transfer.js";
5
+ export * from "./swap.js";
6
+ export { buildTransactInstruction as buildRawTransactInstruction, TRANSACT_ACCOUNT_NAMES, } from "../shield/ix.js";
7
+ export type { TransactAccounts as RawTransactAccounts, TransactArgs as RawTransactArgs, } from "../shield/ix.js";
@@ -0,0 +1,7 @@
1
+ export * from "./transact.js";
2
+ export * from "./deposit.js";
3
+ export * from "./withdraw.js";
4
+ export * from "./transfer.js";
5
+ export * from "./swap.js";
6
+ // Raw IDL-correct builder for custom v0/ALT transaction composition.
7
+ export { buildTransactInstruction as buildRawTransactInstruction, TRANSACT_ACCOUNT_NAMES, } from "../shield/ix.js";