@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
@@ -0,0 +1,40 @@
1
+ import { BN254_FR_MODULUS, bigIntToBytesBE, bytesToBigIntBE, poseidon3, } from "../poseidon.js";
2
+ // -----------------------------------------------------------------------------
3
+ // Nullifier Functions
4
+ // -----------------------------------------------------------------------------
5
+ /**
6
+ * Compute signature for nullifier derivation.
7
+ * Matches circuit's Signature template:
8
+ * signature = Poseidon(privateKey, commitment, pathIndex)
9
+ */
10
+ export function computeSignature(privateKey, commitment, pathIndex) {
11
+ return poseidon3(privateKey, commitment, pathIndex);
12
+ }
13
+ /**
14
+ * Derive nullifier for a UTXO.
15
+ * Matches circuit's UTXONullifier template:
16
+ * signature = Poseidon(privateKey, commitment, pathIndex)
17
+ * nullifier = Poseidon(commitment, pathIndex, signature)
18
+ *
19
+ * The signature-based nullifier ensures only the private key holder can spend.
20
+ */
21
+ export function deriveNullifier(utxo, pathIndex, privateKey) {
22
+ const commitment = bytesToBigIntBE(utxo.commitment) % BN254_FR_MODULUS;
23
+ const pathIndexField = BigInt(pathIndex) % BN254_FR_MODULUS;
24
+ const signature = computeSignature(privateKey, commitment, pathIndexField);
25
+ const nullifier = poseidon3(commitment, pathIndexField, signature);
26
+ return bigIntToBytesBE(nullifier);
27
+ }
28
+ /**
29
+ * Convert InputUTXO to the format expected by the circuit.
30
+ */
31
+ export function inputUTXOToCircuitFormat(input) {
32
+ return {
33
+ amount: input.amount,
34
+ pubkey: input.pubkey,
35
+ blinding: input.blinding,
36
+ pathElements: input.pathElements.map((e) => bytesToBigIntBE(e) % BN254_FR_MODULUS),
37
+ pathIndex: input.pathIndex,
38
+ privateKey: input.privateKey,
39
+ };
40
+ }
@@ -0,0 +1,20 @@
1
+ import type { DecryptedNote } from "./mailbox.js";
2
+ /**
3
+ * Fetch this account's encrypted notes from the relayer and decrypt them.
4
+ *
5
+ * Goes through the managed relayer helper, so the network coordinates stay
6
+ * internal — there is no URL to pass. Notes that fail to decrypt are skipped:
7
+ * a query can return rows addressed to other keys, and one bad row must not
8
+ * lose the rest.
9
+ *
10
+ * @param authToken token from `register()` / `restore()`
11
+ * @param walletSecretKey full 64-byte keypair.secretKey, used for decryption
12
+ * @param walletPublicKey optional base58 filter, narrowing the query server-side
13
+ */
14
+ export declare function fetchAndDecryptNotes(params: {
15
+ authToken: string;
16
+ walletSecretKey: Uint8Array;
17
+ walletPublicKey?: string;
18
+ limit?: number;
19
+ offset?: number;
20
+ }): Promise<DecryptedNote[]>;
@@ -0,0 +1,45 @@
1
+ import { queryEncryptedNotes } from "../relayer/api.js";
2
+ import { decryptBlindMailboxNote } from "./mailbox.js";
3
+ /**
4
+ * Fetch this account's encrypted notes from the relayer and decrypt them.
5
+ *
6
+ * Goes through the managed relayer helper, so the network coordinates stay
7
+ * internal — there is no URL to pass. Notes that fail to decrypt are skipped:
8
+ * a query can return rows addressed to other keys, and one bad row must not
9
+ * lose the rest.
10
+ *
11
+ * @param authToken token from `register()` / `restore()`
12
+ * @param walletSecretKey full 64-byte keypair.secretKey, used for decryption
13
+ * @param walletPublicKey optional base58 filter, narrowing the query server-side
14
+ */
15
+ export async function fetchAndDecryptNotes(params) {
16
+ const { authToken, walletSecretKey, walletPublicKey, limit, offset } = params;
17
+ const { notes } = await queryEncryptedNotes(authToken, {
18
+ ...(walletPublicKey ? { walletPublicKey } : {}),
19
+ ...(limit === undefined ? {} : { limit }),
20
+ ...(offset === undefined ? {} : { offset }),
21
+ });
22
+ const results = [];
23
+ for (const note of notes ?? []) {
24
+ if (!note.ephemeralPublicKey || !note.encryptedBlob)
25
+ continue;
26
+ try {
27
+ results.push(decryptBlindMailboxNote(walletSecretKey, base64ToBytes(note.ephemeralPublicKey), note.encryptedBlob));
28
+ }
29
+ catch {
30
+ // Not addressed to this key, or corrupted — skip it.
31
+ }
32
+ }
33
+ return results;
34
+ }
35
+ /** Base64 → bytes without assuming a Node Buffer global. */
36
+ function base64ToBytes(value) {
37
+ if (typeof atob === "function") {
38
+ const binary = atob(value);
39
+ const out = new Uint8Array(binary.length);
40
+ for (let i = 0; i < binary.length; i++)
41
+ out[i] = binary.charCodeAt(i);
42
+ return out;
43
+ }
44
+ return new Uint8Array(Buffer.from(value, "base64"));
45
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Choosing which notes to spend.
3
+ *
4
+ * Two constraints drive everything here:
5
+ *
6
+ * 1. The transaction circuit is 2-in-2-out, so a single transaction can spend
7
+ * at most TWO notes.
8
+ * 2. Notes can only be co-spent if they live in the SAME Merkle tree, and the
9
+ * tree is derived from the MINT — see `canonicalTreeId`.
10
+ */
11
+ /** Inputs the transaction circuit accepts in one proof. */
12
+ export declare const MAX_INPUT_NOTES = 2;
13
+ /**
14
+ * The tree a note belongs to, derived from its mint.
15
+ *
16
+ * Mirrors the relayer's `mintAddressToTreeId` byte for byte: the all-zero
17
+ * native-SOL mint maps to 0, anything else to its first four mint bytes as a
18
+ * big-endian uint32.
19
+ *
20
+ * DERIVE THIS, NEVER TRUST A STORED `treeId`. Change notes are written with the
21
+ * on-chain shard index (a small 0/1/2…) while deposits and synced notes carry
22
+ * the mint-derived id. For native SOL both are 0 so the difference hides; for
23
+ * SPL tokens the two land in different buckets, and co-spending across them
24
+ * fails at proof time as a commitment mismatch.
25
+ *
26
+ * An undecodable mint falls back to the SOL bucket rather than inventing a
27
+ * phantom tree, matching the server.
28
+ */
29
+ export declare function canonicalTreeId(mintAddress?: string | null): number;
30
+ /** The minimum a note must carry to be selectable. */
31
+ export interface SelectableNote {
32
+ /** Base units. bigint preferred; strings and safe integers accepted. */
33
+ amount: bigint | string | number;
34
+ /** Mint address; determines the tree. Absent means native SOL. */
35
+ mint?: string | null;
36
+ }
37
+ export interface NoteSelection<T> {
38
+ ok: true;
39
+ /** The chosen notes, your own objects. */
40
+ notes: T[];
41
+ /** Tree every chosen note belongs to. */
42
+ treeId: number;
43
+ /** Sum of the chosen notes. */
44
+ total: bigint;
45
+ /** total - amount. Becomes the change note. */
46
+ change: bigint;
47
+ /**
48
+ * True when more than MAX_INPUT_NOTES were needed, so this cannot be proved
49
+ * as one transaction — the notes must be combined first.
50
+ */
51
+ requiresMerge: boolean;
52
+ }
53
+ export interface NoteSelectionFailure {
54
+ ok: false;
55
+ reason: "NO_NOTES" | "INSUFFICIENT_FUNDS";
56
+ /** Largest total reachable within a single tree. */
57
+ available: bigint;
58
+ message: string;
59
+ }
60
+ export type NoteSelectionResult<T> = NoteSelection<T> | NoteSelectionFailure;
61
+ /**
62
+ * Pick notes to cover `amount`, preferring the fewest notes and least change.
63
+ *
64
+ * Considers each tree separately, since notes cannot be co-spent across trees,
65
+ * and returns the best single-tree selection:
66
+ *
67
+ * 1. one note that covers the amount (smallest such note, least change);
68
+ * 2. otherwise the best PAIR, found by a two-pointer scan over the
69
+ * amount-sorted notes — O(n) rather than an O(n²) all-pairs search;
70
+ * 3. otherwise the largest notes greedily, flagged `requiresMerge` because
71
+ * more than two inputs cannot go into one proof.
72
+ *
73
+ * @param amount base units to cover
74
+ */
75
+ export declare function selectNotesForAmount<T extends SelectableNote>(notes: T[], amount: bigint | string | number, options?: {
76
+ mint?: string | null;
77
+ }): NoteSelectionResult<T>;
@@ -0,0 +1,188 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { toBaseUnits } from "./amount.js";
3
+ /**
4
+ * Choosing which notes to spend.
5
+ *
6
+ * Two constraints drive everything here:
7
+ *
8
+ * 1. The transaction circuit is 2-in-2-out, so a single transaction can spend
9
+ * at most TWO notes.
10
+ * 2. Notes can only be co-spent if they live in the SAME Merkle tree, and the
11
+ * tree is derived from the MINT — see `canonicalTreeId`.
12
+ */
13
+ /** Inputs the transaction circuit accepts in one proof. */
14
+ export const MAX_INPUT_NOTES = 2;
15
+ /**
16
+ * The tree a note belongs to, derived from its mint.
17
+ *
18
+ * Mirrors the relayer's `mintAddressToTreeId` byte for byte: the all-zero
19
+ * native-SOL mint maps to 0, anything else to its first four mint bytes as a
20
+ * big-endian uint32.
21
+ *
22
+ * DERIVE THIS, NEVER TRUST A STORED `treeId`. Change notes are written with the
23
+ * on-chain shard index (a small 0/1/2…) while deposits and synced notes carry
24
+ * the mint-derived id. For native SOL both are 0 so the difference hides; for
25
+ * SPL tokens the two land in different buckets, and co-spending across them
26
+ * fails at proof time as a commitment mismatch.
27
+ *
28
+ * An undecodable mint falls back to the SOL bucket rather than inventing a
29
+ * phantom tree, matching the server.
30
+ */
31
+ export function canonicalTreeId(mintAddress) {
32
+ if (!mintAddress || mintAddress.trim() === "")
33
+ return 0;
34
+ try {
35
+ const bytes = new PublicKey(mintAddress).toBytes();
36
+ if (bytes.every((byte) => byte === 0))
37
+ return 0;
38
+ return (((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) >>> 0);
39
+ }
40
+ catch {
41
+ return 0;
42
+ }
43
+ }
44
+ /**
45
+ * Pick notes to cover `amount`, preferring the fewest notes and least change.
46
+ *
47
+ * Considers each tree separately, since notes cannot be co-spent across trees,
48
+ * and returns the best single-tree selection:
49
+ *
50
+ * 1. one note that covers the amount (smallest such note, least change);
51
+ * 2. otherwise the best PAIR, found by a two-pointer scan over the
52
+ * amount-sorted notes — O(n) rather than an O(n²) all-pairs search;
53
+ * 3. otherwise the largest notes greedily, flagged `requiresMerge` because
54
+ * more than two inputs cannot go into one proof.
55
+ *
56
+ * @param amount base units to cover
57
+ */
58
+ export function selectNotesForAmount(notes, amount, options = {}) {
59
+ const target = toBaseUnits(amount, "amount");
60
+ if (target <= 0n) {
61
+ throw new Error(`amount must be positive, got ${target}`);
62
+ }
63
+ const wanted = options.mint === undefined ? undefined : canonicalTreeId(options.mint);
64
+ const byTree = new Map();
65
+ notes.forEach((note, index) => {
66
+ const treeId = canonicalTreeId(note.mint);
67
+ if (wanted !== undefined && treeId !== wanted)
68
+ return;
69
+ const entry = {
70
+ note,
71
+ amount: toBaseUnits(note.amount, `notes[${index}].amount`),
72
+ };
73
+ if (entry.amount <= 0n)
74
+ return;
75
+ const bucket = byTree.get(treeId);
76
+ if (bucket)
77
+ bucket.push(entry);
78
+ else
79
+ byTree.set(treeId, [entry]);
80
+ });
81
+ if (byTree.size === 0) {
82
+ return {
83
+ ok: false,
84
+ reason: "NO_NOTES",
85
+ available: 0n,
86
+ message: "No spendable notes for the requested mint.",
87
+ };
88
+ }
89
+ let best;
90
+ let available = 0n;
91
+ for (const [treeId, bucket] of byTree) {
92
+ const treeTotal = bucket.reduce((sum, entry) => sum + entry.amount, 0n);
93
+ if (treeTotal > available)
94
+ available = treeTotal;
95
+ const selection = selectWithinTree(bucket, target, treeId);
96
+ if (!selection)
97
+ continue;
98
+ if (!best || isBetter(selection, best))
99
+ best = selection;
100
+ }
101
+ if (!best) {
102
+ return {
103
+ ok: false,
104
+ reason: "INSUFFICIENT_FUNDS",
105
+ available,
106
+ message: `No single tree holds ${target} base units. Largest tree total is ` +
107
+ `${available}. Notes in different trees cannot be co-spent.`,
108
+ };
109
+ }
110
+ return best;
111
+ }
112
+ /** Fewer inputs first, then least change. */
113
+ function isBetter(a, b) {
114
+ if (a.notes.length !== b.notes.length)
115
+ return a.notes.length < b.notes.length;
116
+ return a.change < b.change;
117
+ }
118
+ function selectWithinTree(bucket, target, treeId) {
119
+ // Descending by amount, compared as bigint: Number() would lose precision
120
+ // above 2^53 base units.
121
+ const sorted = [...bucket].sort((a, b) => b.amount > a.amount ? 1 : b.amount < a.amount ? -1 : 0);
122
+ // 1. Smallest single note that covers the target — walk up from the end.
123
+ let single;
124
+ for (let i = sorted.length - 1; i >= 0; i--) {
125
+ if (sorted[i].amount >= target) {
126
+ single = sorted[i];
127
+ break;
128
+ }
129
+ }
130
+ if (single) {
131
+ return {
132
+ ok: true,
133
+ notes: [single.note],
134
+ treeId,
135
+ total: single.amount,
136
+ change: single.amount - target,
137
+ requiresMerge: false,
138
+ };
139
+ }
140
+ // 2. Best pair by two-pointer scan over the descending list.
141
+ let bestPair;
142
+ let bestChange = 0n;
143
+ let lo = 0;
144
+ let hi = sorted.length - 1;
145
+ while (lo < hi) {
146
+ const combined = sorted[lo].amount + sorted[hi].amount;
147
+ if (combined >= target) {
148
+ const change = combined - target;
149
+ if (!bestPair || change < bestChange) {
150
+ bestChange = change;
151
+ bestPair = [sorted[lo], sorted[hi]];
152
+ }
153
+ lo++;
154
+ }
155
+ else {
156
+ hi--;
157
+ }
158
+ }
159
+ if (bestPair) {
160
+ return {
161
+ ok: true,
162
+ notes: [bestPair[0].note, bestPair[1].note],
163
+ treeId,
164
+ total: bestPair[0].amount + bestPair[1].amount,
165
+ change: bestChange,
166
+ requiresMerge: false,
167
+ };
168
+ }
169
+ // 3. Greedy over the largest notes. More than two inputs, so it needs a merge.
170
+ const chosen = [];
171
+ let total = 0n;
172
+ for (const entry of sorted) {
173
+ chosen.push(entry);
174
+ total += entry.amount;
175
+ if (total >= target)
176
+ break;
177
+ }
178
+ if (total < target)
179
+ return undefined;
180
+ return {
181
+ ok: true,
182
+ notes: chosen.map((entry) => entry.note),
183
+ treeId,
184
+ total,
185
+ change: total - target,
186
+ requiresMerge: chosen.length > MAX_INPUT_NOTES,
187
+ };
188
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Spend status and private balance.
3
+ *
4
+ * A note is yours until its nullifier is published; nothing in the note itself
5
+ * says whether it has been spent. So a balance is always two steps: ask which
6
+ * nullifiers are spent, then sum what is left. This module is that pair.
7
+ */
8
+ /** Server-side cap per check-batch request (notes.constants MAX_NULLIFIERS_PER_CHECK). */
9
+ export declare const MAX_NULLIFIERS_PER_CHECK = 200;
10
+ /** Grouping key used for notes that carry no mint. */
11
+ export declare const UNKNOWN_MINT = "unknown";
12
+ /**
13
+ * Ask the relayer which of these nullifiers are spent.
14
+ *
15
+ * Deduplicates, lower-cases, and splits into MAX_NULLIFIERS_PER_CHECK batches
16
+ * that are issued concurrently. Returns a Set for membership testing; a
17
+ * nullifier absent from it is unspent as far as the relayer knows.
18
+ *
19
+ * @throws if any entry is not 64-char hex — a malformed nullifier that silently
20
+ * read as "unspent" would overstate a balance.
21
+ */
22
+ export declare function checkNullifiersSpent(nullifiers: string[]): Promise<Set<string>>;
23
+ /** The minimum a note must carry to be counted. */
24
+ export interface SpendableNote {
25
+ /** Base units. bigint preferred; strings and safe integers are accepted. */
26
+ amount: bigint | string | number;
27
+ /** 64-character hex nullifier for this note. */
28
+ nullifier: string;
29
+ /** Mint this note is denominated in. Groups the result; optional. */
30
+ mint?: string;
31
+ }
32
+ export interface PrivateBalance<T extends SpendableNote = SpendableNote> {
33
+ /** Sum of every unspent note, across all mints. */
34
+ total: bigint;
35
+ /** Unspent totals keyed by mint (UNKNOWN_MINT when a note carries none). */
36
+ byMint: Record<string, bigint>;
37
+ /** The caller's own note objects, partitioned. */
38
+ unspent: T[];
39
+ spent: T[];
40
+ }
41
+ export interface PrivateBalanceOptions {
42
+ /**
43
+ * Supply spend status yourself instead of asking the relayer — e.g. from a
44
+ * chain scan of nullifier events, or a local cache. Receives normalized
45
+ * lower-case hex.
46
+ */
47
+ resolveSpent?: (nullifiers: string[]) => Promise<Set<string>> | Set<string>;
48
+ }
49
+ /**
50
+ * Sum unspent notes, per mint and in total.
51
+ *
52
+ * ```ts
53
+ * const { total, byMint, unspent } = await getPrivateBalance(myNotes);
54
+ * ```
55
+ *
56
+ * Amounts are base units and stay bigint throughout — never sum note amounts as
57
+ * numbers. Notes are matched to spend status by nullifier, so every note needs
58
+ * one; the partitioned arrays hand back your own objects, not copies.
59
+ */
60
+ export declare function getPrivateBalance<T extends SpendableNote>(notes: T[], options?: PrivateBalanceOptions): Promise<PrivateBalance<T>>;
@@ -0,0 +1,96 @@
1
+ import { checkNullifiers } from "../relayer/api.js";
2
+ import { toBaseUnits } from "./amount.js";
3
+ /**
4
+ * Spend status and private balance.
5
+ *
6
+ * A note is yours until its nullifier is published; nothing in the note itself
7
+ * says whether it has been spent. So a balance is always two steps: ask which
8
+ * nullifiers are spent, then sum what is left. This module is that pair.
9
+ */
10
+ /** Server-side cap per check-batch request (notes.constants MAX_NULLIFIERS_PER_CHECK). */
11
+ export const MAX_NULLIFIERS_PER_CHECK = 200;
12
+ /** Grouping key used for notes that carry no mint. */
13
+ export const UNKNOWN_MINT = "unknown";
14
+ const HEX64 = /^[0-9a-f]{64}$/;
15
+ /**
16
+ * Normalize a nullifier to the form the relayer answers in.
17
+ *
18
+ * The endpoint's validator is case-INSENSITIVE, but it answers with
19
+ * `Buffer.toString("hex")` — always lowercase. Sending upper-case hex therefore
20
+ * returns a `spent` list that never matches what you sent, and every note reads
21
+ * as unspent. Normalizing here is what makes membership testing sound.
22
+ */
23
+ function normalizeNullifier(nullifier, index) {
24
+ const normalized = nullifier.trim().toLowerCase();
25
+ if (!HEX64.test(normalized)) {
26
+ throw new Error(`nullifiers[${index}] must be a 64-character hex string, got ` +
27
+ `${JSON.stringify(nullifier)}`);
28
+ }
29
+ return normalized;
30
+ }
31
+ function chunk(items, size) {
32
+ const out = [];
33
+ for (let i = 0; i < items.length; i += size)
34
+ out.push(items.slice(i, i + size));
35
+ return out;
36
+ }
37
+ /**
38
+ * Ask the relayer which of these nullifiers are spent.
39
+ *
40
+ * Deduplicates, lower-cases, and splits into MAX_NULLIFIERS_PER_CHECK batches
41
+ * that are issued concurrently. Returns a Set for membership testing; a
42
+ * nullifier absent from it is unspent as far as the relayer knows.
43
+ *
44
+ * @throws if any entry is not 64-char hex — a malformed nullifier that silently
45
+ * read as "unspent" would overstate a balance.
46
+ */
47
+ export async function checkNullifiersSpent(nullifiers) {
48
+ const unique = [...new Set(nullifiers.map(normalizeNullifier))];
49
+ if (unique.length === 0)
50
+ return new Set();
51
+ const batches = await Promise.all(chunk(unique, MAX_NULLIFIERS_PER_CHECK).map((batch) => checkNullifiers(batch)));
52
+ const spent = new Set();
53
+ for (const response of batches) {
54
+ for (const nullifier of response.spent ?? []) {
55
+ spent.add(nullifier.toLowerCase());
56
+ }
57
+ }
58
+ return spent;
59
+ }
60
+ /**
61
+ * Sum unspent notes, per mint and in total.
62
+ *
63
+ * ```ts
64
+ * const { total, byMint, unspent } = await getPrivateBalance(myNotes);
65
+ * ```
66
+ *
67
+ * Amounts are base units and stay bigint throughout — never sum note amounts as
68
+ * numbers. Notes are matched to spend status by nullifier, so every note needs
69
+ * one; the partitioned arrays hand back your own objects, not copies.
70
+ */
71
+ export async function getPrivateBalance(notes, options = {}) {
72
+ const normalized = notes.map((note, index) => ({
73
+ note,
74
+ amount: toBaseUnits(note.amount, `notes[${index}].amount`),
75
+ nullifier: normalizeNullifier(note.nullifier, index),
76
+ }));
77
+ const resolve = options.resolveSpent ?? checkNullifiersSpent;
78
+ const spentSet = await resolve(normalized.map((entry) => entry.nullifier));
79
+ const balance = {
80
+ total: 0n,
81
+ byMint: {},
82
+ unspent: [],
83
+ spent: [],
84
+ };
85
+ for (const entry of normalized) {
86
+ if (spentSet.has(entry.nullifier)) {
87
+ balance.spent.push(entry.note);
88
+ continue;
89
+ }
90
+ const mint = entry.note.mint ?? UNKNOWN_MINT;
91
+ balance.unspent.push(entry.note);
92
+ balance.total += entry.amount;
93
+ balance.byMint[mint] = (balance.byMint[mint] ?? 0n) + entry.amount;
94
+ }
95
+ return balance;
96
+ }
@@ -0,0 +1,16 @@
1
+ import type { JperpMarket, JperpMarketPayload, JperpSide } from "./types.js";
2
+ export declare const JUPITER_PERPS_PROGRAM_ID = "PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
3
+ export declare const JUPITER_PERPS_EVENT_AUTHORITY = "37hJBDnntwqhGbK7L6M1bLyvccj4u55CCUiLPdYkiqBN";
4
+ export declare const JUPITER_PERPS_POOL = "5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq";
5
+ export declare const JUPITER_JLP_MINT = "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4";
6
+ export declare const JPERP_USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
7
+ export declare const JPERP_NATIVE_SOL_MINT = "11111111111111111111111111111111";
8
+ export declare const JPERP_WRAPPED_SOL_MINT = "So11111111111111111111111111111111111111112";
9
+ export declare const JUPITER_PERPS_CUSTODIES: Record<JperpMarket | "USDC" | "USDT", string>;
10
+ export declare const JUPITER_PERPS_DOVES_ORACLES: Record<JperpMarket, string>;
11
+ export declare const JPERP_LONG_POOL_MINTS: Record<JperpMarket, string>;
12
+ export declare const JPERP_LONG_JUPITER_MINTS: Record<JperpMarket, string>;
13
+ export declare const JPERP_LONG_DECIMALS: Record<JperpMarket, number>;
14
+ export declare const JPERP_USD_DECIMALS = 6;
15
+ /** Resolve the exact market payload duplicated by the wallet-app reference. */
16
+ export declare function getJperpMarketPayload(market: JperpMarket, side: JperpSide): JperpMarketPayload;
@@ -0,0 +1,48 @@
1
+ export const JUPITER_PERPS_PROGRAM_ID = "PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
2
+ export const JUPITER_PERPS_EVENT_AUTHORITY = "37hJBDnntwqhGbK7L6M1bLyvccj4u55CCUiLPdYkiqBN";
3
+ export const JUPITER_PERPS_POOL = "5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq";
4
+ export const JUPITER_JLP_MINT = "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4";
5
+ export const JPERP_USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
6
+ export const JPERP_NATIVE_SOL_MINT = "11111111111111111111111111111111";
7
+ export const JPERP_WRAPPED_SOL_MINT = "So11111111111111111111111111111111111111112";
8
+ export const JUPITER_PERPS_CUSTODIES = {
9
+ SOL: "7xS2gz2bTp3fwCC7knJvUWTEU9Tycczu6VhJYKgi1wdz",
10
+ ETH: "AQCGyheWPLeo6Qp9WpYS9m3Qj479t7R636N9ey1rEjEn",
11
+ BTC: "5Pv3gM9JrFFH883SWAhvJC9RPYmo8UNxuFtv5bMMALkm",
12
+ USDC: "G18jKKXQwBbrHeiK3C9MRXhkHsLHf7XgCSisykV46EZa",
13
+ USDT: "4vkNeXiYEUizLdrpdPS1eC2mccyM4NUPRtERrk6ZETkk",
14
+ };
15
+ export const JUPITER_PERPS_DOVES_ORACLES = {
16
+ SOL: "FYq2BWQ1V5P1WFBqr3qB2Kb5yHVvSv7upzKodgQE5zXh",
17
+ ETH: "AFZnHPzy4mvVCffrVwhewHbFc93uTHvDSFrVH7GtfXF1",
18
+ BTC: "hUqAT1KQ7eW1i6Csp9CXYtpPfSAvi835V7wKi5fRfmC",
19
+ };
20
+ export const JPERP_LONG_POOL_MINTS = {
21
+ SOL: JPERP_NATIVE_SOL_MINT,
22
+ ETH: "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs",
23
+ BTC: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh",
24
+ };
25
+ export const JPERP_LONG_JUPITER_MINTS = {
26
+ SOL: JPERP_WRAPPED_SOL_MINT,
27
+ ETH: JPERP_LONG_POOL_MINTS.ETH,
28
+ BTC: JPERP_LONG_POOL_MINTS.BTC,
29
+ };
30
+ export const JPERP_LONG_DECIMALS = {
31
+ SOL: 9,
32
+ ETH: 8,
33
+ BTC: 8,
34
+ };
35
+ export const JPERP_USD_DECIMALS = 6;
36
+ /** Resolve the exact market payload duplicated by the wallet-app reference. */
37
+ export function getJperpMarketPayload(market, side) {
38
+ const isLong = side === "long";
39
+ return {
40
+ custody: JUPITER_PERPS_CUSTODIES[market],
41
+ collateralCustody: JUPITER_PERPS_CUSTODIES[isLong ? market : "USDC"],
42
+ inputMint: isLong ? JPERP_LONG_POOL_MINTS[market] : JPERP_USDC_MINT,
43
+ jupiterInputMint: isLong
44
+ ? JPERP_LONG_JUPITER_MINTS[market]
45
+ : JPERP_USDC_MINT,
46
+ dovesOracle: JUPITER_PERPS_DOVES_ORACLES[market],
47
+ };
48
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./types.js";
2
+ export * from "./constants.js";
3
+ export * from "./keys.js";
4
+ export * from "./pdas.js";
5
+ export * from "./relayer.js";
@@ -0,0 +1,5 @@
1
+ export * from "./types.js";
2
+ export * from "./constants.js";
3
+ export * from "./keys.js";
4
+ export * from "./pdas.js";
5
+ export * from "./relayer.js";
@@ -0,0 +1,16 @@
1
+ import { Keypair } from "@solana/web3.js";
2
+ export interface JperpKeyBundle {
3
+ withdrawalId: Uint8Array;
4
+ withdrawalIdHex: string;
5
+ claimant: Keypair;
6
+ claimantPublicKey: string;
7
+ claimantSecretKey: string;
8
+ }
9
+ export declare function deriveJperpWithdrawalId(spendingKey: Uint8Array, index: number): Uint8Array;
10
+ export declare function deriveJperpClaimantKeypair(spendingKey: Uint8Array, withdrawalId: Uint8Array): Keypair;
11
+ export declare function jperpWithdrawalIdToHex(withdrawalId: Uint8Array): string;
12
+ export declare function jperpWithdrawalIdFromHex(value: string): Uint8Array;
13
+ /** Derive every client-held key field needed across the jPerp lifecycle. */
14
+ export declare function deriveJperpKeyBundle(spendingKey: Uint8Array, index: number): JperpKeyBundle;
15
+ /** Match the client reference's per-request Jupiter PDA namespace. */
16
+ export declare function createJperpCounter(): string;
@@ -0,0 +1,35 @@
1
+ import { sha256 } from "@noble/hashes/sha256";
2
+ import { Keypair } from "@solana/web3.js";
3
+ import { assertBytes, bytesToHex, concatBytes, encodeBase58, hexToBytes, uint32Le, utf8, } from "../identity/encoding.js";
4
+ export function deriveJperpWithdrawalId(spendingKey, index) {
5
+ assertBytes(spendingKey, 32, "spending key");
6
+ return sha256(concatBytes(utf8("jperp_withdrawal_v1"), spendingKey, uint32Le(index, "jPerp position index")));
7
+ }
8
+ export function deriveJperpClaimantKeypair(spendingKey, withdrawalId) {
9
+ assertBytes(spendingKey, 32, "spending key");
10
+ assertBytes(withdrawalId, 32, "jPerp withdrawal ID");
11
+ return Keypair.fromSeed(sha256(concatBytes(utf8("jperp_claimant"), spendingKey, withdrawalId)));
12
+ }
13
+ export function jperpWithdrawalIdToHex(withdrawalId) {
14
+ assertBytes(withdrawalId, 32, "jPerp withdrawal ID");
15
+ return bytesToHex(withdrawalId);
16
+ }
17
+ export function jperpWithdrawalIdFromHex(value) {
18
+ return hexToBytes(value, 32, "jPerp withdrawal ID");
19
+ }
20
+ /** Derive every client-held key field needed across the jPerp lifecycle. */
21
+ export function deriveJperpKeyBundle(spendingKey, index) {
22
+ const withdrawalId = deriveJperpWithdrawalId(spendingKey, index);
23
+ const claimant = deriveJperpClaimantKeypair(spendingKey, withdrawalId);
24
+ return {
25
+ withdrawalId,
26
+ withdrawalIdHex: jperpWithdrawalIdToHex(withdrawalId),
27
+ claimant,
28
+ claimantPublicKey: claimant.publicKey.toBase58(),
29
+ claimantSecretKey: encodeBase58(claimant.secretKey),
30
+ };
31
+ }
32
+ /** Match the client reference's per-request Jupiter PDA namespace. */
33
+ export function createJperpCounter() {
34
+ return String(Math.floor(Math.random() * 1000000000000));
35
+ }