@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
package/dist/esm/proof.js CHANGED
@@ -1,281 +1,2 @@
1
- import { sha256 } from "@noble/hashes/sha256";
2
- import { BN254_FR_MODULUS, bigIntToBytesBE, bytesToBigIntBE, poseidon2, poseidon3, pubkeyToField, } from "./poseidon.js";
3
- import { deriveNullifier } from "./utxo.js";
4
- // -----------------------------------------------------------------------------
5
- // ExtData Hash Computation
6
- // -----------------------------------------------------------------------------
7
- /**
8
- * Compute the external data hash.
9
- * Matches on-chain computation:
10
- * hash1 = Poseidon(recipient, relayer)
11
- * hash2 = Poseidon(fee, refund)
12
- * extDataHash = Poseidon(hash1, hash2, claimant)
13
- */
14
- export function computeExtDataHash(extData) {
15
- const recipientField = pubkeyToField(extData.recipient);
16
- const relayerField = pubkeyToField(extData.relayer);
17
- const feeField = extData.fee % BN254_FR_MODULUS;
18
- const refundField = extData.refund % BN254_FR_MODULUS;
19
- const claimantField = pubkeyToField(extData.claimant);
20
- const hash1 = poseidon2(recipientField, relayerField);
21
- const hash2 = poseidon2(feeField, refundField);
22
- const finalHash = poseidon3(hash1, hash2, claimantField);
23
- return bigIntToBytesBE(finalHash);
24
- }
25
- // -----------------------------------------------------------------------------
26
- // Circuit Input Preparation
27
- // -----------------------------------------------------------------------------
28
- /**
29
- * Convert i64 to field element (handles negative via modular arithmetic).
30
- * For negative values, we add the field modulus to get the equivalent positive representation.
31
- */
32
- export function i64ToField(value) {
33
- if (value >= 0n) {
34
- return value % BN254_FR_MODULUS;
35
- }
36
- return (BN254_FR_MODULUS + value) % BN254_FR_MODULUS;
37
- }
38
- /**
39
- * Prepare transaction circuit inputs from high-level parameters.
40
- * This converts the SDK types into the format expected by the circuit.
41
- */
42
- export function prepareTransactionInputs(params) {
43
- const { inputUTXOs, outputUTXOs, root, publicAmount, extData, mintAddress } = params;
44
- const extDataHash = computeExtDataHash(extData);
45
- const mintField = pubkeyToField(mintAddress);
46
- // Prepare input UTXO data
47
- const inAmount = [
48
- inputUTXOs[0].amount,
49
- inputUTXOs[1].amount,
50
- ];
51
- const inPubkey = [
52
- inputUTXOs[0].pubkey,
53
- inputUTXOs[1].pubkey,
54
- ];
55
- const inBlinding = [
56
- inputUTXOs[0].blinding,
57
- inputUTXOs[1].blinding,
58
- ];
59
- const inPathIndex = [
60
- inputUTXOs[0].pathIndex,
61
- inputUTXOs[1].pathIndex,
62
- ];
63
- const inPathElements = [
64
- inputUTXOs[0].pathElements.map((e) => bytesToBigIntBE(e) % BN254_FR_MODULUS),
65
- inputUTXOs[1].pathElements.map((e) => bytesToBigIntBE(e) % BN254_FR_MODULUS),
66
- ];
67
- const inPrivateKey = [
68
- inputUTXOs[0].privateKey,
69
- inputUTXOs[1].privateKey,
70
- ];
71
- // Prepare output UTXO data
72
- const outAmount = [
73
- outputUTXOs[0].amount,
74
- outputUTXOs[1].amount,
75
- ];
76
- const outPubkey = [
77
- outputUTXOs[0].pubkey,
78
- outputUTXOs[1].pubkey,
79
- ];
80
- const outBlinding = [
81
- outputUTXOs[0].blinding,
82
- outputUTXOs[1].blinding,
83
- ];
84
- // Derive nullifiers for input UTXOs
85
- const inputNullifiers = [
86
- deriveNullifier(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
87
- deriveNullifier(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
88
- ];
89
- return {
90
- root,
91
- publicAmount,
92
- extDataHash,
93
- mintAddress,
94
- inputNullifiers,
95
- outputCommitments: [outputUTXOs[0].commitment, outputUTXOs[1].commitment],
96
- inAmount,
97
- inPubkey,
98
- inBlinding,
99
- inPathIndex,
100
- inPathElements,
101
- inPrivateKey,
102
- outAmount,
103
- outPubkey,
104
- outBlinding,
105
- };
106
- }
107
- // -----------------------------------------------------------------------------
108
- // Proof Packing
109
- // -----------------------------------------------------------------------------
110
- /**
111
- * Convert bigint to 32-byte big-endian representation.
112
- * The alt_bn128 Solana precompile (and ark-works via change_endianness) expect BE.
113
- */
114
- function bigintTo32BytesBE(x) {
115
- const out = new Uint8Array(32);
116
- let v = x;
117
- for (let i = 31; i >= 0; i--) {
118
- out[i] = Number(v & 0xffn);
119
- v >>= 8n;
120
- }
121
- return out;
122
- }
123
- /**
124
- * Turn a snarkjs Groth16 proof into 256 bytes:
125
- * A(G1) | B(G2) | C(G1)
126
- * where:
127
- * A = (ax, ay) -> 64 bytes
128
- * B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
129
- * C = (cx, cy) -> 64 bytes
130
- *
131
- * Each field element is encoded as 32-byte BE to match the on-chain verifier.
132
- * We ignore the extra projective/z components snarkjs keeps.
133
- */
134
- export function packProofToBytes(proof) {
135
- const chunks = [];
136
- const ax = BigInt(proof.pi_a[0]);
137
- const ay = BigInt(proof.pi_a[1]);
138
- chunks.push(bigintTo32BytesBE(ax), bigintTo32BytesBE(ay));
139
- const bx = proof.pi_b[0];
140
- const by = proof.pi_b[1];
141
- const bx0 = BigInt(bx[0]);
142
- const bx1 = BigInt(bx[1]);
143
- const by0 = BigInt(by[0]);
144
- const by1 = BigInt(by[1]);
145
- // alt_bn128 expects the G2 pairs swapped: bx1 before bx0, by1 before by0
146
- chunks.push(bigintTo32BytesBE(bx1), bigintTo32BytesBE(bx0), bigintTo32BytesBE(by1), bigintTo32BytesBE(by0));
147
- const cx = BigInt(proof.pi_c[0]);
148
- const cy = BigInt(proof.pi_c[1]);
149
- chunks.push(bigintTo32BytesBE(cx), bigintTo32BytesBE(cy));
150
- const out = new Uint8Array(32 * (2 + 4 + 2)); // 256
151
- let offset = 0;
152
- for (const c of chunks) {
153
- out.set(c, offset);
154
- offset += c.length;
155
- }
156
- return out;
157
- }
158
- /**
159
- * Encode a snarkjs proof into the TransactionProofStruct format expected by the on-chain program.
160
- */
161
- export function encodeSnarkjsProofToTransactionProof(proof) {
162
- const full = packProofToBytes(proof);
163
- if (full.length !== 256) {
164
- throw new Error(`Expected 256 proof bytes, got ${full.length}`);
165
- }
166
- const proofA = full.slice(0, 64);
167
- const proofB = full.slice(64, 192);
168
- const proofC = full.slice(192, 256);
169
- return {
170
- proofA: Array.from(proofA),
171
- proofB: Array.from(proofB),
172
- proofC: Array.from(proofC),
173
- };
174
- }
175
- // -----------------------------------------------------------------------------
176
- // Snarkjs Input Formatting
177
- // -----------------------------------------------------------------------------
178
- /**
179
- * Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
180
- * All values are converted to strings (snarkjs expects string inputs for field elements).
181
- */
182
- export function formatInputsForSnarkjs(inputs) {
183
- return {
184
- // Public inputs
185
- root: bytesToBigIntBE(inputs.root).toString(),
186
- publicAmount: i64ToField(inputs.publicAmount).toString(),
187
- extDataHash: bytesToBigIntBE(inputs.extDataHash).toString(),
188
- mintAddress: pubkeyToField(inputs.mintAddress).toString(),
189
- inputNullifier: inputs.inputNullifiers.map((n) => bytesToBigIntBE(n).toString()),
190
- outputCommitment: inputs.outputCommitments.map((c) => bytesToBigIntBE(c).toString()),
191
- // Private inputs - Input UTXOs
192
- inAmount: inputs.inAmount.map((a) => a.toString()),
193
- inPubkey: inputs.inPubkey.map((p) => p.toString()),
194
- inBlinding: inputs.inBlinding.map((b) => b.toString()),
195
- inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
196
- inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
197
- inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
198
- // Private inputs - Output UTXOs
199
- outAmount: inputs.outAmount.map((a) => a.toString()),
200
- outPubkey: inputs.outPubkey.map((p) => p.toString()),
201
- outBlinding: inputs.outBlinding.map((b) => b.toString()),
202
- };
203
- }
204
- /**
205
- * Convert SwapCircuitInputs into the shape expected by
206
- * snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
207
- * decimal string (or string array) because snarkjs only accepts field
208
- * elements as strings.
209
- *
210
- * Mirrors `generateSwapProof` in
211
- * relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
212
- * verify against the same circuit the relayer uses.
213
- */
214
- export function formatSwapInputsForSnarkjs(inputs) {
215
- return {
216
- // Public inputs
217
- sourceRoot: bytesToBigIntBE(inputs.sourceRoot).toString(),
218
- swapParamsHash: bytesToBigIntBE(inputs.swapParamsHash).toString(),
219
- extDataHash: bytesToBigIntBE(inputs.extDataHash).toString(),
220
- sourceMint: pubkeyToField(inputs.sourceMint).toString(),
221
- destMint: pubkeyToField(inputs.destMint).toString(),
222
- inputNullifier: inputs.inputNullifiers.map((n) => bytesToBigIntBE(n).toString()),
223
- changeCommitment: bytesToBigIntBE(inputs.changeCommitment).toString(),
224
- destCommitment: bytesToBigIntBE(inputs.destCommitment).toString(),
225
- swapAmount: inputs.swapAmount.toString(),
226
- // Private inputs - Input UTXOs
227
- inAmount: inputs.inAmount.map((a) => a.toString()),
228
- inPubkey: inputs.inPubkey.map((p) => p.toString()),
229
- inBlinding: inputs.inBlinding.map((b) => b.toString()),
230
- inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
231
- inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
232
- inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
233
- // Private inputs - Change UTXO
234
- changeAmount: inputs.changeAmount.toString(),
235
- changePubkey: inputs.changePubkey.toString(),
236
- changeBlinding: inputs.changeBlinding.toString(),
237
- // Private inputs - Destination UTXO
238
- destAmount: inputs.destAmount.toString(),
239
- destPubkey: inputs.destPubkey.toString(),
240
- destBlinding: inputs.destBlinding.toString(),
241
- // Swap params
242
- minAmountOut: inputs.minAmountOut.toString(),
243
- deadline: inputs.deadline.toString(),
244
- };
245
- }
246
- // -----------------------------------------------------------------------------
247
- // Swap Parameter Hashing
248
- // -----------------------------------------------------------------------------
249
- /**
250
- * Compute the swap params hash that the swap circuit and on-chain program verify.
251
- * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
252
- *
253
- * Circuit formula (swap.circom lines 293-307):
254
- * mintPairHash = Poseidon(sourceMint, destMint)
255
- * swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
256
- * swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
257
- *
258
- * @param sourceMint Source pool mint
259
- * @param destMint Destination pool mint
260
- * @param minAmountOut Minimum accepted output amount (slippage protected)
261
- * @param deadline Unix timestamp deadline (i64, 0 = no deadline)
262
- * @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
263
- * relayerFee). If omitted, defaults to minAmountOut.
264
- */
265
- export function computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destAmount) {
266
- const srcField = pubkeyToField(sourceMint);
267
- const dstField = pubkeyToField(destMint);
268
- const mintPairHash = poseidon2(srcField, dstField);
269
- const dest = destAmount ?? minAmountOut;
270
- const swapTermsHash = poseidon3(minAmountOut, deadline, dest);
271
- const paramsHash = poseidon2(mintPairHash, swapTermsHash);
272
- return bigIntToBytesBE(paramsHash);
273
- }
274
- /**
275
- * Compute the swap data hash committed on-chain for Jupiter instruction integrity.
276
- * SHA-256 of the raw Jupiter swap instruction data bytes.
277
- * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
278
- */
279
- export function computeSwapDataHash(swapData) {
280
- return sha256(swapData instanceof Buffer ? new Uint8Array(swapData) : swapData);
281
- }
1
+ // Backward-compatible entry point. Proof responsibilities live in src/proofs.
2
+ export * from "./proofs/index.js";
@@ -0,0 +1,17 @@
1
+ import type { RawProof, TransactionProofStruct } from "./types.js";
2
+ /**
3
+ * Turn a snarkjs Groth16 proof into 256 bytes:
4
+ * A(G1) | B(G2) | C(G1)
5
+ * where:
6
+ * A = (ax, ay) -> 64 bytes
7
+ * B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
8
+ * C = (cx, cy) -> 64 bytes
9
+ *
10
+ * Each field element is encoded as 32-byte BE to match the on-chain verifier.
11
+ * We ignore the extra projective/z components snarkjs keeps.
12
+ */
13
+ export declare function packProofToBytes(proof: RawProof): Uint8Array;
14
+ /**
15
+ * Encode a snarkjs proof into the TransactionProofStruct format expected by the on-chain program.
16
+ */
17
+ export declare function encodeSnarkjsProofToTransactionProof(proof: RawProof): TransactionProofStruct;
@@ -0,0 +1,68 @@
1
+ // -----------------------------------------------------------------------------
2
+ // Proof Packing
3
+ // -----------------------------------------------------------------------------
4
+ /**
5
+ * Convert bigint to 32-byte big-endian representation.
6
+ * The alt_bn128 Solana precompile (and ark-works via change_endianness) expect BE.
7
+ */
8
+ function bigintTo32BytesBE(x) {
9
+ const out = new Uint8Array(32);
10
+ let v = x;
11
+ for (let i = 31; i >= 0; i--) {
12
+ out[i] = Number(v & 0xffn);
13
+ v >>= 8n;
14
+ }
15
+ return out;
16
+ }
17
+ /**
18
+ * Turn a snarkjs Groth16 proof into 256 bytes:
19
+ * A(G1) | B(G2) | C(G1)
20
+ * where:
21
+ * A = (ax, ay) -> 64 bytes
22
+ * B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
23
+ * C = (cx, cy) -> 64 bytes
24
+ *
25
+ * Each field element is encoded as 32-byte BE to match the on-chain verifier.
26
+ * We ignore the extra projective/z components snarkjs keeps.
27
+ */
28
+ export function packProofToBytes(proof) {
29
+ const chunks = [];
30
+ const ax = BigInt(proof.pi_a[0]);
31
+ const ay = BigInt(proof.pi_a[1]);
32
+ chunks.push(bigintTo32BytesBE(ax), bigintTo32BytesBE(ay));
33
+ const bx = proof.pi_b[0];
34
+ const by = proof.pi_b[1];
35
+ const bx0 = BigInt(bx[0]);
36
+ const bx1 = BigInt(bx[1]);
37
+ const by0 = BigInt(by[0]);
38
+ const by1 = BigInt(by[1]);
39
+ // alt_bn128 expects the G2 pairs swapped: bx1 before bx0, by1 before by0
40
+ chunks.push(bigintTo32BytesBE(bx1), bigintTo32BytesBE(bx0), bigintTo32BytesBE(by1), bigintTo32BytesBE(by0));
41
+ const cx = BigInt(proof.pi_c[0]);
42
+ const cy = BigInt(proof.pi_c[1]);
43
+ chunks.push(bigintTo32BytesBE(cx), bigintTo32BytesBE(cy));
44
+ const out = new Uint8Array(32 * (2 + 4 + 2)); // 256
45
+ let offset = 0;
46
+ for (const c of chunks) {
47
+ out.set(c, offset);
48
+ offset += c.length;
49
+ }
50
+ return out;
51
+ }
52
+ /**
53
+ * Encode a snarkjs proof into the TransactionProofStruct format expected by the on-chain program.
54
+ */
55
+ export function encodeSnarkjsProofToTransactionProof(proof) {
56
+ const full = packProofToBytes(proof);
57
+ if (full.length !== 256) {
58
+ throw new Error(`Expected 256 proof bytes, got ${full.length}`);
59
+ }
60
+ const proofA = full.slice(0, 64);
61
+ const proofB = full.slice(64, 192);
62
+ const proofC = full.slice(192, 256);
63
+ return {
64
+ proofA: Array.from(proofA),
65
+ proofB: Array.from(proofB),
66
+ proofC: Array.from(proofC),
67
+ };
68
+ }
@@ -0,0 +1,6 @@
1
+ import type { TransactionCircuitInputs } from "./types.js";
2
+ /**
3
+ * Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
4
+ * All values are converted to strings (snarkjs expects string inputs for field elements).
5
+ */
6
+ export declare function formatInputsForSnarkjs(inputs: TransactionCircuitInputs): Record<string, any>;
@@ -0,0 +1,31 @@
1
+ import { bytesToBigIntBE, pubkeyToField } from "../poseidon.js";
2
+ import { i64ToField } from "./transaction.js";
3
+ // -----------------------------------------------------------------------------
4
+ // Snarkjs Input Formatting
5
+ // -----------------------------------------------------------------------------
6
+ /**
7
+ * Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
8
+ * All values are converted to strings (snarkjs expects string inputs for field elements).
9
+ */
10
+ export function formatInputsForSnarkjs(inputs) {
11
+ return {
12
+ // Public inputs
13
+ root: bytesToBigIntBE(inputs.root).toString(),
14
+ publicAmount: i64ToField(inputs.publicAmount).toString(),
15
+ extDataHash: bytesToBigIntBE(inputs.extDataHash).toString(),
16
+ mintAddress: pubkeyToField(inputs.mintAddress).toString(),
17
+ inputNullifier: inputs.inputNullifiers.map((n) => bytesToBigIntBE(n).toString()),
18
+ outputCommitment: inputs.outputCommitments.map((c) => bytesToBigIntBE(c).toString()),
19
+ // Private inputs - Input UTXOs
20
+ inAmount: inputs.inAmount.map((a) => a.toString()),
21
+ inPubkey: inputs.inPubkey.map((p) => p.toString()),
22
+ inBlinding: inputs.inBlinding.map((b) => b.toString()),
23
+ inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
24
+ inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
25
+ inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
26
+ // Private inputs - Output UTXOs
27
+ outAmount: inputs.outAmount.map((a) => a.toString()),
28
+ outPubkey: inputs.outPubkey.map((p) => p.toString()),
29
+ outBlinding: inputs.outBlinding.map((b) => b.toString()),
30
+ };
31
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./types.js";
2
+ export * from "./transaction.js";
3
+ export * from "./encoding.js";
4
+ export * from "./formatting.js";
5
+ export * from "./swap.js";
@@ -0,0 +1,5 @@
1
+ export * from "./types.js";
2
+ export * from "./transaction.js";
3
+ export * from "./encoding.js";
4
+ export * from "./formatting.js";
5
+ export * from "./swap.js";
@@ -0,0 +1,87 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import type { InputUTXO, SerializedUTXO } from "../notes/model.js";
3
+ import type { ExtData, RawProof } from "./types.js";
4
+ /**
5
+ * Swap circuit inputs. Matches the signal shape declared by swap.circom's
6
+ * main component (see zk-circuits/swap.circom lines 208-238). Unlike the
7
+ * transaction circuit, the swap circuit distinguishes a "change" output
8
+ * (same mint as source) from a "dest" output (dest mint) and takes a
9
+ * swap-specific params hash and swapAmount alongside the usual inputs.
10
+ */
11
+ export type SwapCircuitInputs = {
12
+ sourceRoot: Uint8Array;
13
+ swapParamsHash: Uint8Array;
14
+ extDataHash: Uint8Array;
15
+ sourceMint: PublicKey;
16
+ destMint: PublicKey;
17
+ inputNullifiers: [Uint8Array, Uint8Array];
18
+ changeCommitment: Uint8Array;
19
+ destCommitment: Uint8Array;
20
+ swapAmount: bigint;
21
+ inAmount: [bigint, bigint];
22
+ inPubkey: [bigint, bigint];
23
+ inBlinding: [bigint, bigint];
24
+ inPathIndex: [number, number];
25
+ inPathElements: [bigint[], bigint[]];
26
+ inPrivateKey: [bigint, bigint];
27
+ changeAmount: bigint;
28
+ changePubkey: bigint;
29
+ changeBlinding: bigint;
30
+ destAmount: bigint;
31
+ destPubkey: bigint;
32
+ destBlinding: bigint;
33
+ minAmountOut: bigint;
34
+ deadline: bigint;
35
+ };
36
+ /** Proof builder accepted by SDK-side private swap flows. */
37
+ export type SwapProofBuilder = (inputs: SwapCircuitInputs) => Promise<RawProof>;
38
+ /**
39
+ * Prepare the exact witness/public inputs used by the relayer's swap circuit.
40
+ * Output 0 must be source-mint change and output 1 the destination-mint note.
41
+ */
42
+ export declare function prepareSwapInputs(params: {
43
+ inputUTXOs: [InputUTXO, InputUTXO];
44
+ changeUTXO: SerializedUTXO;
45
+ destUTXO: SerializedUTXO;
46
+ sourceRoot: Uint8Array;
47
+ sourceMint: PublicKey;
48
+ destMint: PublicKey;
49
+ swapAmount: bigint;
50
+ minAmountOut: bigint;
51
+ deadline: bigint;
52
+ extData: ExtData;
53
+ }): SwapCircuitInputs;
54
+ /**
55
+ * Convert SwapCircuitInputs into the shape expected by
56
+ * snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
57
+ * decimal string (or string array) because snarkjs only accepts field
58
+ * elements as strings.
59
+ *
60
+ * Mirrors `generateSwapProof` in
61
+ * relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
62
+ * verify against the same circuit the relayer uses.
63
+ */
64
+ export declare function formatSwapInputsForSnarkjs(inputs: SwapCircuitInputs): Record<string, any>;
65
+ /**
66
+ * Compute the swap params hash that the swap circuit and on-chain program verify.
67
+ * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
68
+ *
69
+ * Circuit formula (swap.circom lines 293-307):
70
+ * mintPairHash = Poseidon(sourceMint, destMint)
71
+ * swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
72
+ * swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
73
+ *
74
+ * @param sourceMint Source pool mint
75
+ * @param destMint Destination pool mint
76
+ * @param minAmountOut Minimum accepted output amount (slippage protected)
77
+ * @param deadline Positive Unix timestamp deadline (the program rejects 0)
78
+ * @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
79
+ * relayerFee). If omitted, defaults to minAmountOut.
80
+ */
81
+ export declare function computeSwapParamsHash(sourceMint: PublicKey, destMint: PublicKey, minAmountOut: bigint, deadline: bigint, destAmount?: bigint): Uint8Array;
82
+ /**
83
+ * Compute the swap data hash committed on-chain for Jupiter instruction integrity.
84
+ * SHA-256 of the raw Jupiter swap instruction data bytes.
85
+ * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
86
+ */
87
+ export declare function computeSwapDataHash(swapData: Uint8Array | Buffer): Uint8Array;
@@ -0,0 +1,138 @@
1
+ import { sha256 } from "@noble/hashes/sha256";
2
+ import { BN254_FR_MODULUS, bigIntToBytesBE, bytesToBigIntBE, poseidon2, poseidon3, pubkeyToField, } from "../poseidon.js";
3
+ import { deriveNullifier } from "../notes/nullifier.js";
4
+ import { computeExtDataHash } from "./transaction.js";
5
+ /**
6
+ * Prepare the exact witness/public inputs used by the relayer's swap circuit.
7
+ * Output 0 must be source-mint change and output 1 the destination-mint note.
8
+ */
9
+ export function prepareSwapInputs(params) {
10
+ const { inputUTXOs, changeUTXO, destUTXO, sourceRoot, sourceMint, destMint, swapAmount, minAmountOut, deadline, extData, } = params;
11
+ const totalInput = inputUTXOs[0].amount + inputUTXOs[1].amount;
12
+ if (swapAmount <= 0n)
13
+ throw new Error("swapAmount must be positive");
14
+ if (deadline <= 0n) {
15
+ throw new Error("deadline must be a positive Unix timestamp");
16
+ }
17
+ if (totalInput !== swapAmount + changeUTXO.amount) {
18
+ throw new Error(`Swap balance mismatch: inputs=${totalInput}, swap=${swapAmount}, change=${changeUTXO.amount}`);
19
+ }
20
+ if (destUTXO.amount < minAmountOut) {
21
+ throw new Error("Destination note amount is below minAmountOut");
22
+ }
23
+ if (changeUTXO.mintAddress !== pubkeyToField(sourceMint)) {
24
+ throw new Error("Change UTXO must use the source mint");
25
+ }
26
+ if (destUTXO.mintAddress !== pubkeyToField(destMint)) {
27
+ throw new Error("Destination UTXO must use the destination mint");
28
+ }
29
+ return {
30
+ sourceRoot,
31
+ swapParamsHash: computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destUTXO.amount),
32
+ extDataHash: computeExtDataHash(extData),
33
+ sourceMint,
34
+ destMint,
35
+ inputNullifiers: [
36
+ deriveNullifier(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
37
+ deriveNullifier(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
38
+ ],
39
+ changeCommitment: changeUTXO.commitment,
40
+ destCommitment: destUTXO.commitment,
41
+ swapAmount,
42
+ inAmount: [inputUTXOs[0].amount, inputUTXOs[1].amount],
43
+ inPubkey: [inputUTXOs[0].pubkey, inputUTXOs[1].pubkey],
44
+ inBlinding: [inputUTXOs[0].blinding, inputUTXOs[1].blinding],
45
+ inPathIndex: [inputUTXOs[0].pathIndex, inputUTXOs[1].pathIndex],
46
+ inPathElements: [
47
+ inputUTXOs[0].pathElements.map((element) => bytesToBigIntBE(element) % BN254_FR_MODULUS),
48
+ inputUTXOs[1].pathElements.map((element) => bytesToBigIntBE(element) % BN254_FR_MODULUS),
49
+ ],
50
+ inPrivateKey: [inputUTXOs[0].privateKey, inputUTXOs[1].privateKey],
51
+ changeAmount: changeUTXO.amount,
52
+ changePubkey: changeUTXO.pubkey,
53
+ changeBlinding: changeUTXO.blinding,
54
+ destAmount: destUTXO.amount,
55
+ destPubkey: destUTXO.pubkey,
56
+ destBlinding: destUTXO.blinding,
57
+ minAmountOut,
58
+ deadline,
59
+ };
60
+ }
61
+ /**
62
+ * Convert SwapCircuitInputs into the shape expected by
63
+ * snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
64
+ * decimal string (or string array) because snarkjs only accepts field
65
+ * elements as strings.
66
+ *
67
+ * Mirrors `generateSwapProof` in
68
+ * relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
69
+ * verify against the same circuit the relayer uses.
70
+ */
71
+ export function formatSwapInputsForSnarkjs(inputs) {
72
+ return {
73
+ // Public inputs
74
+ sourceRoot: bytesToBigIntBE(inputs.sourceRoot).toString(),
75
+ swapParamsHash: bytesToBigIntBE(inputs.swapParamsHash).toString(),
76
+ extDataHash: bytesToBigIntBE(inputs.extDataHash).toString(),
77
+ sourceMint: pubkeyToField(inputs.sourceMint).toString(),
78
+ destMint: pubkeyToField(inputs.destMint).toString(),
79
+ inputNullifier: inputs.inputNullifiers.map((n) => bytesToBigIntBE(n).toString()),
80
+ changeCommitment: bytesToBigIntBE(inputs.changeCommitment).toString(),
81
+ destCommitment: bytesToBigIntBE(inputs.destCommitment).toString(),
82
+ swapAmount: inputs.swapAmount.toString(),
83
+ // Private inputs - Input UTXOs
84
+ inAmount: inputs.inAmount.map((a) => a.toString()),
85
+ inPubkey: inputs.inPubkey.map((p) => p.toString()),
86
+ inBlinding: inputs.inBlinding.map((b) => b.toString()),
87
+ inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
88
+ inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
89
+ inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
90
+ // Private inputs - Change UTXO
91
+ changeAmount: inputs.changeAmount.toString(),
92
+ changePubkey: inputs.changePubkey.toString(),
93
+ changeBlinding: inputs.changeBlinding.toString(),
94
+ // Private inputs - Destination UTXO
95
+ destAmount: inputs.destAmount.toString(),
96
+ destPubkey: inputs.destPubkey.toString(),
97
+ destBlinding: inputs.destBlinding.toString(),
98
+ // Swap params
99
+ minAmountOut: inputs.minAmountOut.toString(),
100
+ deadline: inputs.deadline.toString(),
101
+ };
102
+ }
103
+ // -----------------------------------------------------------------------------
104
+ // Swap Parameter Hashing
105
+ // -----------------------------------------------------------------------------
106
+ /**
107
+ * Compute the swap params hash that the swap circuit and on-chain program verify.
108
+ * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
109
+ *
110
+ * Circuit formula (swap.circom lines 293-307):
111
+ * mintPairHash = Poseidon(sourceMint, destMint)
112
+ * swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
113
+ * swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
114
+ *
115
+ * @param sourceMint Source pool mint
116
+ * @param destMint Destination pool mint
117
+ * @param minAmountOut Minimum accepted output amount (slippage protected)
118
+ * @param deadline Positive Unix timestamp deadline (the program rejects 0)
119
+ * @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
120
+ * relayerFee). If omitted, defaults to minAmountOut.
121
+ */
122
+ export function computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destAmount) {
123
+ const srcField = pubkeyToField(sourceMint);
124
+ const dstField = pubkeyToField(destMint);
125
+ const mintPairHash = poseidon2(srcField, dstField);
126
+ const dest = destAmount ?? minAmountOut;
127
+ const swapTermsHash = poseidon3(minAmountOut, deadline, dest);
128
+ const paramsHash = poseidon2(mintPairHash, swapTermsHash);
129
+ return bigIntToBytesBE(paramsHash);
130
+ }
131
+ /**
132
+ * Compute the swap data hash committed on-chain for Jupiter instruction integrity.
133
+ * SHA-256 of the raw Jupiter swap instruction data bytes.
134
+ * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
135
+ */
136
+ export function computeSwapDataHash(swapData) {
137
+ return sha256(swapData instanceof Buffer ? new Uint8Array(swapData) : swapData);
138
+ }
@@ -0,0 +1,28 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import type { InputUTXO, SerializedUTXO } from "../notes/model.js";
3
+ import type { ExtData, TransactionCircuitInputs } from "./types.js";
4
+ /**
5
+ * Compute the external data hash.
6
+ * Matches on-chain computation:
7
+ * hash1 = Poseidon(recipient, relayer)
8
+ * hash2 = Poseidon(fee, refund)
9
+ * extDataHash = Poseidon(hash1, hash2, claimant)
10
+ */
11
+ export declare function computeExtDataHash(extData: ExtData): Uint8Array;
12
+ /**
13
+ * Convert i64 to field element (handles negative via modular arithmetic).
14
+ * For negative values, we add the field modulus to get the equivalent positive representation.
15
+ */
16
+ export declare function i64ToField(value: bigint): bigint;
17
+ /**
18
+ * Prepare transaction circuit inputs from high-level parameters.
19
+ * This converts the SDK types into the format expected by the circuit.
20
+ */
21
+ export declare function prepareTransactionInputs(params: {
22
+ inputUTXOs: [InputUTXO, InputUTXO];
23
+ outputUTXOs: [SerializedUTXO, SerializedUTXO];
24
+ root: Uint8Array;
25
+ publicAmount: bigint;
26
+ extData: ExtData;
27
+ mintAddress: PublicKey;
28
+ }): TransactionCircuitInputs;