@veilo/sdk-core 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (481) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +449 -1243
  3. package/accounts.d.ts +2 -0
  4. package/accounts.js +3 -0
  5. package/cloak.d.ts +2 -0
  6. package/cloak.js +3 -0
  7. package/config.d.ts +2 -2
  8. package/config.js +2 -3
  9. package/dist/cjs/accounts/admin.d.ts +84 -0
  10. package/dist/cjs/accounts/admin.js +208 -0
  11. package/dist/cjs/accounts/errors.d.ts +6 -0
  12. package/dist/cjs/accounts/errors.js +98 -0
  13. package/dist/cjs/accounts/index.d.ts +4 -0
  14. package/dist/cjs/accounts/index.js +20 -0
  15. package/dist/cjs/accounts/pdas.d.ts +23 -0
  16. package/dist/cjs/accounts/pdas.js +44 -0
  17. package/dist/cjs/accounts/queries.d.ts +41 -0
  18. package/dist/cjs/accounts/queries.js +95 -0
  19. package/dist/cjs/client.d.ts +2 -407
  20. package/dist/cjs/client.js +6 -938
  21. package/dist/cjs/cloak/client.d.ts +28 -0
  22. package/dist/cjs/cloak/client.js +68 -0
  23. package/dist/cjs/cloak/errors.d.ts +13 -0
  24. package/dist/cjs/cloak/errors.js +25 -0
  25. package/dist/cjs/cloak/helpers.d.ts +6 -0
  26. package/dist/cjs/cloak/helpers.js +35 -0
  27. package/dist/cjs/cloak/index.d.ts +6 -0
  28. package/dist/cjs/cloak/index.js +24 -0
  29. package/dist/cjs/cloak/polling.d.ts +7 -0
  30. package/dist/cjs/cloak/polling.js +66 -0
  31. package/dist/cjs/cloak/transport.d.ts +15 -0
  32. package/dist/cjs/cloak/transport.js +119 -0
  33. package/dist/cjs/cloak/types.d.ts +188 -0
  34. package/dist/cjs/cloak/types.js +5 -0
  35. package/dist/cjs/cloak.d.ts +1 -0
  36. package/dist/cjs/cloak.js +18 -0
  37. package/dist/cjs/compactNote.d.ts +21 -0
  38. package/dist/cjs/compactNote.js +31 -7
  39. package/dist/cjs/events/index.d.ts +6 -0
  40. package/dist/cjs/events/index.js +22 -0
  41. package/dist/cjs/events/parsing.d.ts +25 -0
  42. package/dist/cjs/events/parsing.js +158 -0
  43. package/dist/cjs/events/position.d.ts +26 -0
  44. package/dist/cjs/events/position.js +53 -0
  45. package/dist/cjs/events/recovery.d.ts +87 -0
  46. package/dist/cjs/events/recovery.js +281 -0
  47. package/dist/cjs/events/scanning.d.ts +35 -0
  48. package/dist/cjs/events/scanning.js +98 -0
  49. package/dist/cjs/events/tree.d.ts +27 -0
  50. package/dist/cjs/events/tree.js +63 -0
  51. package/dist/cjs/events/types.d.ts +39 -0
  52. package/dist/cjs/events.d.ts +1 -77
  53. package/dist/cjs/events.js +6 -154
  54. package/dist/cjs/identity/encoding.d.ts +9 -0
  55. package/dist/cjs/identity/encoding.js +85 -0
  56. package/dist/cjs/identity/index.d.ts +4 -0
  57. package/dist/cjs/identity/index.js +20 -0
  58. package/dist/cjs/identity/noteKey.d.ts +33 -0
  59. package/dist/cjs/identity/noteKey.js +97 -0
  60. package/dist/cjs/identity/spending.d.ts +18 -0
  61. package/dist/cjs/identity/spending.js +46 -0
  62. package/dist/cjs/identity/viewKey.d.ts +38 -0
  63. package/dist/cjs/identity/viewKey.js +105 -0
  64. package/dist/cjs/idl/index.d.ts +18 -0
  65. package/dist/cjs/idl/index.js +24 -0
  66. package/dist/cjs/idl/privacy_pool.json +9907 -9907
  67. package/dist/cjs/idl/privacy_pool_legacy.js +3307 -0
  68. package/dist/cjs/idl/privacy_pool_legacy.json +2302 -0
  69. package/dist/cjs/idl/privacy_pool_legacy2.d.ts +5 -0
  70. package/dist/cjs/idl/privacy_pool_legacy2.js +3397 -0
  71. package/dist/cjs/idl/privacy_pool_legacy2.json +2376 -0
  72. package/dist/cjs/index.d.ts +9 -3
  73. package/dist/cjs/index.js +15 -2
  74. package/dist/cjs/notes/amount.d.ts +2 -0
  75. package/dist/cjs/notes/amount.js +21 -0
  76. package/dist/cjs/notes/encryption.d.ts +41 -0
  77. package/dist/cjs/notes/encryption.js +75 -0
  78. package/dist/cjs/notes/index.d.ts +8 -0
  79. package/dist/cjs/notes/index.js +24 -0
  80. package/dist/cjs/notes/mailbox.d.ts +70 -0
  81. package/dist/cjs/notes/mailbox.js +164 -0
  82. package/dist/cjs/notes/model.d.ts +91 -0
  83. package/dist/cjs/notes/model.js +109 -0
  84. package/dist/cjs/notes/nullifier.d.ts +27 -0
  85. package/dist/cjs/notes/nullifier.js +45 -0
  86. package/dist/cjs/notes/recovery.d.ts +20 -0
  87. package/dist/cjs/notes/recovery.js +48 -0
  88. package/dist/cjs/notes/selection.d.ts +77 -0
  89. package/dist/cjs/notes/selection.js +193 -0
  90. package/dist/cjs/notes/spent.d.ts +60 -0
  91. package/dist/cjs/notes/spent.js +101 -0
  92. package/dist/cjs/perps/constants.d.ts +16 -0
  93. package/dist/cjs/perps/constants.js +52 -0
  94. package/dist/cjs/perps/index.d.ts +5 -0
  95. package/dist/cjs/perps/index.js +21 -0
  96. package/dist/cjs/perps/keys.d.ts +16 -0
  97. package/dist/cjs/perps/keys.js +43 -0
  98. package/dist/cjs/perps/pdas.d.ts +29 -0
  99. package/dist/cjs/perps/pdas.js +55 -0
  100. package/dist/cjs/perps/relayer.d.ts +9 -0
  101. package/dist/cjs/perps/relayer.js +35 -0
  102. package/dist/cjs/perps/types.d.ts +126 -0
  103. package/dist/cjs/perps/types.js +2 -0
  104. package/dist/cjs/positions/index.d.ts +4 -0
  105. package/dist/cjs/positions/index.js +20 -0
  106. package/dist/cjs/positions/keys.d.ts +29 -0
  107. package/dist/cjs/positions/keys.js +71 -0
  108. package/dist/cjs/positions/pdas.d.ts +15 -0
  109. package/dist/cjs/positions/pdas.js +54 -0
  110. package/dist/cjs/positions/relayer.d.ts +4 -0
  111. package/dist/cjs/positions/relayer.js +15 -0
  112. package/dist/cjs/positions/types.d.ts +97 -0
  113. package/dist/cjs/positions/types.js +2 -0
  114. package/dist/cjs/predictions/client.d.ts +41 -0
  115. package/dist/cjs/predictions/client.js +147 -0
  116. package/dist/cjs/predictions/index.d.ts +5 -0
  117. package/dist/cjs/predictions/index.js +21 -0
  118. package/dist/cjs/predictions/keys.d.ts +14 -0
  119. package/dist/cjs/predictions/keys.js +40 -0
  120. package/dist/cjs/predictions/pdas.d.ts +6 -0
  121. package/dist/cjs/predictions/pdas.js +13 -0
  122. package/dist/cjs/predictions/relayer.d.ts +3 -0
  123. package/dist/cjs/predictions/relayer.js +11 -0
  124. package/dist/cjs/predictions/types.d.ts +178 -0
  125. package/dist/cjs/predictions/types.js +2 -0
  126. package/dist/cjs/program.d.ts +2 -0
  127. package/dist/cjs/program.js +8 -7
  128. package/dist/cjs/proof.d.ts +1 -183
  129. package/dist/cjs/proof.js +16 -290
  130. package/dist/cjs/proofs/encoding.d.ts +17 -0
  131. package/dist/cjs/proofs/encoding.js +72 -0
  132. package/dist/cjs/proofs/formatting.d.ts +6 -0
  133. package/dist/cjs/proofs/formatting.js +34 -0
  134. package/dist/cjs/proofs/index.d.ts +5 -0
  135. package/dist/cjs/proofs/index.js +21 -0
  136. package/dist/cjs/proofs/swap.d.ts +87 -0
  137. package/dist/cjs/proofs/swap.js +144 -0
  138. package/dist/cjs/proofs/transaction.d.ts +28 -0
  139. package/dist/cjs/proofs/transaction.js +110 -0
  140. package/dist/cjs/proofs/types.d.ts +70 -0
  141. package/dist/cjs/proofs/types.js +2 -0
  142. package/dist/cjs/prover.d.ts +30 -4
  143. package/dist/cjs/prover.js +118 -49
  144. package/dist/cjs/relayer/api.d.ts +31 -0
  145. package/dist/cjs/relayer/api.js +86 -0
  146. package/dist/cjs/relayer/client.d.ts +73 -0
  147. package/dist/cjs/relayer/client.js +206 -0
  148. package/dist/cjs/relayer/crypto.d.ts +5 -0
  149. package/dist/cjs/relayer/crypto.js +26 -0
  150. package/dist/cjs/relayer/encoding.d.ts +2 -0
  151. package/dist/cjs/relayer/encoding.js +23 -0
  152. package/dist/cjs/relayer/errors.d.ts +7 -0
  153. package/dist/cjs/relayer/errors.js +17 -0
  154. package/dist/cjs/relayer/index.d.ts +6 -0
  155. package/dist/cjs/relayer/index.js +19 -0
  156. package/dist/cjs/relayer/internal-config.d.ts +36 -0
  157. package/dist/cjs/relayer/internal-config.js +9 -0
  158. package/dist/cjs/relayer/internal.d.ts +6 -0
  159. package/dist/cjs/relayer/internal.js +14 -0
  160. package/dist/cjs/relayer/transport.d.ts +19 -0
  161. package/dist/cjs/relayer/transport.js +68 -0
  162. package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +53 -96
  163. package/dist/cjs/relayer/types.js +5 -0
  164. package/dist/cjs/relayer.d.ts +1 -318
  165. package/dist/cjs/relayer.js +15 -254
  166. package/dist/cjs/shield/alt.js +8 -8
  167. package/dist/cjs/shield/errors.js +2 -2
  168. package/dist/cjs/shield/finalize.js +2 -2
  169. package/dist/cjs/shield/ix.d.ts +1 -1
  170. package/dist/cjs/shield/owner.js +9 -11
  171. package/dist/cjs/shield/ports.js +3 -3
  172. package/dist/cjs/shield/preflight.js +3 -3
  173. package/dist/cjs/shield/shield.js +20 -19
  174. package/dist/cjs/shield/types.d.ts +1 -1
  175. package/dist/cjs/transactions/deposit.d.ts +94 -0
  176. package/dist/cjs/transactions/deposit.js +234 -0
  177. package/dist/cjs/transactions/index.d.ts +7 -0
  178. package/dist/cjs/transactions/index.js +26 -0
  179. package/dist/cjs/transactions/swap.d.ts +71 -0
  180. package/dist/cjs/transactions/swap.js +184 -0
  181. package/dist/cjs/transactions/transact.d.ts +34 -0
  182. package/dist/cjs/transactions/transact.js +146 -0
  183. package/dist/cjs/transactions/transfer.d.ts +51 -0
  184. package/dist/cjs/transactions/transfer.js +106 -0
  185. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  186. package/dist/cjs/transactions/withdraw.js +104 -0
  187. package/dist/cjs/utxo.d.ts +1 -235
  188. package/dist/cjs/utxo.js +15 -404
  189. package/dist/esm/accounts/admin.d.ts +84 -0
  190. package/dist/esm/accounts/admin.js +165 -0
  191. package/dist/esm/accounts/errors.d.ts +6 -0
  192. package/dist/esm/accounts/errors.js +95 -0
  193. package/dist/esm/accounts/index.d.ts +4 -0
  194. package/dist/esm/accounts/index.js +4 -0
  195. package/dist/esm/accounts/pdas.d.ts +23 -0
  196. package/dist/esm/accounts/pdas.js +38 -0
  197. package/dist/esm/accounts/queries.d.ts +41 -0
  198. package/dist/esm/accounts/queries.js +88 -0
  199. package/dist/esm/client.d.ts +2 -407
  200. package/dist/esm/client.js +3 -891
  201. package/dist/esm/cloak/client.d.ts +28 -0
  202. package/dist/esm/cloak/client.js +64 -0
  203. package/dist/esm/cloak/errors.d.ts +13 -0
  204. package/dist/esm/cloak/errors.js +21 -0
  205. package/dist/esm/cloak/helpers.d.ts +6 -0
  206. package/dist/esm/cloak/helpers.js +31 -0
  207. package/dist/esm/cloak/index.d.ts +6 -0
  208. package/dist/esm/cloak/index.js +6 -0
  209. package/dist/esm/cloak/polling.d.ts +7 -0
  210. package/dist/esm/cloak/polling.js +63 -0
  211. package/dist/esm/cloak/transport.d.ts +15 -0
  212. package/dist/esm/cloak/transport.js +115 -0
  213. package/dist/esm/cloak/types.d.ts +188 -0
  214. package/dist/esm/cloak/types.js +4 -0
  215. package/dist/esm/cloak.d.ts +1 -0
  216. package/dist/esm/cloak.js +2 -0
  217. package/dist/esm/compactNote.d.ts +21 -0
  218. package/dist/esm/compactNote.js +24 -1
  219. package/dist/esm/events/index.d.ts +6 -0
  220. package/dist/esm/events/index.js +6 -0
  221. package/dist/esm/events/parsing.d.ts +25 -0
  222. package/dist/esm/events/parsing.js +120 -0
  223. package/dist/esm/events/position.d.ts +26 -0
  224. package/dist/esm/events/position.js +48 -0
  225. package/dist/esm/events/recovery.d.ts +87 -0
  226. package/dist/esm/events/recovery.js +237 -0
  227. package/dist/esm/events/scanning.d.ts +35 -0
  228. package/dist/esm/events/scanning.js +92 -0
  229. package/dist/esm/events/tree.d.ts +27 -0
  230. package/dist/esm/events/tree.js +58 -0
  231. package/dist/esm/events/types.d.ts +39 -0
  232. package/dist/esm/events/types.js +1 -0
  233. package/dist/esm/events.d.ts +1 -77
  234. package/dist/esm/events.js +3 -129
  235. package/dist/esm/identity/encoding.d.ts +9 -0
  236. package/dist/esm/identity/encoding.js +75 -0
  237. package/dist/esm/identity/index.d.ts +4 -0
  238. package/dist/esm/identity/index.js +4 -0
  239. package/dist/esm/identity/noteKey.d.ts +33 -0
  240. package/dist/esm/identity/noteKey.js +91 -0
  241. package/dist/esm/identity/spending.d.ts +18 -0
  242. package/dist/esm/identity/spending.js +35 -0
  243. package/dist/esm/identity/viewKey.d.ts +38 -0
  244. package/dist/esm/identity/viewKey.js +96 -0
  245. package/dist/esm/idl/index.d.ts +18 -0
  246. package/dist/esm/idl/index.js +18 -0
  247. package/dist/esm/idl/privacy_pool.json +9907 -9907
  248. package/dist/esm/idl/privacy_pool_legacy.d.ts +5 -0
  249. package/dist/esm/idl/privacy_pool_legacy.js +3305 -0
  250. package/dist/esm/idl/privacy_pool_legacy.json +2302 -0
  251. package/dist/esm/idl/privacy_pool_legacy2.d.ts +5 -0
  252. package/dist/esm/idl/privacy_pool_legacy2.js +3395 -0
  253. package/dist/esm/idl/privacy_pool_legacy2.json +2376 -0
  254. package/dist/esm/index.d.ts +9 -3
  255. package/dist/esm/index.js +10 -3
  256. package/dist/esm/notes/amount.d.ts +2 -0
  257. package/dist/esm/notes/amount.js +18 -0
  258. package/dist/esm/notes/encryption.d.ts +41 -0
  259. package/dist/esm/notes/encryption.js +67 -0
  260. package/dist/esm/notes/index.d.ts +8 -0
  261. package/dist/esm/notes/index.js +8 -0
  262. package/dist/esm/notes/mailbox.d.ts +70 -0
  263. package/dist/esm/notes/mailbox.js +154 -0
  264. package/dist/esm/notes/model.d.ts +91 -0
  265. package/dist/esm/notes/model.js +99 -0
  266. package/dist/esm/notes/nullifier.d.ts +27 -0
  267. package/dist/esm/notes/nullifier.js +40 -0
  268. package/dist/esm/notes/recovery.d.ts +20 -0
  269. package/dist/esm/notes/recovery.js +45 -0
  270. package/dist/esm/notes/selection.d.ts +77 -0
  271. package/dist/esm/notes/selection.js +188 -0
  272. package/dist/esm/notes/spent.d.ts +60 -0
  273. package/dist/esm/notes/spent.js +96 -0
  274. package/dist/esm/perps/constants.d.ts +16 -0
  275. package/dist/esm/perps/constants.js +48 -0
  276. package/dist/esm/perps/index.d.ts +5 -0
  277. package/dist/esm/perps/index.js +5 -0
  278. package/dist/esm/perps/keys.d.ts +16 -0
  279. package/dist/esm/perps/keys.js +35 -0
  280. package/dist/esm/perps/pdas.d.ts +29 -0
  281. package/dist/esm/perps/pdas.js +47 -0
  282. package/dist/esm/perps/relayer.d.ts +9 -0
  283. package/dist/esm/perps/relayer.js +25 -0
  284. package/dist/esm/perps/types.d.ts +126 -0
  285. package/dist/esm/perps/types.js +1 -0
  286. package/dist/esm/positions/index.d.ts +4 -0
  287. package/dist/esm/positions/index.js +4 -0
  288. package/dist/esm/positions/keys.d.ts +29 -0
  289. package/dist/esm/positions/keys.js +65 -0
  290. package/dist/esm/positions/pdas.d.ts +15 -0
  291. package/dist/esm/positions/pdas.js +44 -0
  292. package/dist/esm/positions/relayer.d.ts +4 -0
  293. package/dist/esm/positions/relayer.js +10 -0
  294. package/dist/esm/positions/types.d.ts +97 -0
  295. package/dist/esm/positions/types.js +1 -0
  296. package/dist/esm/predictions/client.d.ts +41 -0
  297. package/dist/esm/predictions/client.js +141 -0
  298. package/dist/esm/predictions/index.d.ts +5 -0
  299. package/dist/esm/predictions/index.js +5 -0
  300. package/dist/esm/predictions/keys.d.ts +14 -0
  301. package/dist/esm/predictions/keys.js +33 -0
  302. package/dist/esm/predictions/pdas.d.ts +6 -0
  303. package/dist/esm/predictions/pdas.js +10 -0
  304. package/dist/esm/predictions/relayer.d.ts +3 -0
  305. package/dist/esm/predictions/relayer.js +7 -0
  306. package/dist/esm/predictions/types.d.ts +178 -0
  307. package/dist/esm/predictions/types.js +1 -0
  308. package/dist/esm/program.d.ts +2 -0
  309. package/dist/esm/program.js +4 -3
  310. package/dist/esm/proof.d.ts +1 -183
  311. package/dist/esm/proof.js +2 -281
  312. package/dist/esm/proofs/encoding.d.ts +17 -0
  313. package/dist/esm/proofs/encoding.js +68 -0
  314. package/dist/esm/proofs/formatting.d.ts +6 -0
  315. package/dist/esm/proofs/formatting.js +31 -0
  316. package/dist/esm/proofs/index.d.ts +5 -0
  317. package/dist/esm/proofs/index.js +5 -0
  318. package/dist/esm/proofs/swap.d.ts +87 -0
  319. package/dist/esm/proofs/swap.js +138 -0
  320. package/dist/esm/proofs/transaction.d.ts +28 -0
  321. package/dist/esm/proofs/transaction.js +105 -0
  322. package/dist/esm/proofs/types.d.ts +70 -0
  323. package/dist/esm/proofs/types.js +1 -0
  324. package/dist/esm/prover.d.ts +30 -4
  325. package/dist/esm/prover.js +115 -15
  326. package/dist/esm/relayer/api.d.ts +31 -0
  327. package/dist/esm/relayer/api.js +55 -0
  328. package/dist/esm/relayer/client.d.ts +73 -0
  329. package/dist/esm/relayer/client.js +199 -0
  330. package/dist/esm/relayer/crypto.d.ts +5 -0
  331. package/dist/esm/relayer/crypto.js +20 -0
  332. package/dist/esm/relayer/encoding.d.ts +2 -0
  333. package/dist/esm/relayer/encoding.js +19 -0
  334. package/dist/esm/relayer/errors.d.ts +7 -0
  335. package/dist/esm/relayer/errors.js +13 -0
  336. package/dist/esm/relayer/index.d.ts +6 -0
  337. package/dist/esm/relayer/index.js +3 -0
  338. package/dist/esm/relayer/internal-config.d.ts +36 -0
  339. package/dist/esm/relayer/internal-config.js +6 -0
  340. package/dist/esm/relayer/internal.d.ts +6 -0
  341. package/dist/esm/relayer/internal.js +10 -0
  342. package/dist/esm/relayer/transport.d.ts +19 -0
  343. package/dist/esm/relayer/transport.js +64 -0
  344. package/dist/esm/relayer/types.d.ts +275 -0
  345. package/dist/esm/relayer/types.js +4 -0
  346. package/dist/esm/relayer.d.ts +1 -318
  347. package/dist/esm/relayer.js +2 -249
  348. package/dist/esm/shield/alt.js +1 -1
  349. package/dist/esm/shield/errors.js +1 -1
  350. package/dist/esm/shield/finalize.js +1 -1
  351. package/dist/esm/shield/ix.d.ts +1 -1
  352. package/dist/esm/shield/owner.js +3 -5
  353. package/dist/esm/shield/ports.js +1 -1
  354. package/dist/esm/shield/preflight.js +1 -1
  355. package/dist/esm/shield/shield.js +4 -3
  356. package/dist/esm/shield/types.d.ts +1 -1
  357. package/dist/esm/transactions/deposit.d.ts +94 -0
  358. package/dist/esm/transactions/deposit.js +198 -0
  359. package/dist/esm/transactions/index.d.ts +7 -0
  360. package/dist/esm/transactions/index.js +7 -0
  361. package/dist/esm/transactions/swap.d.ts +71 -0
  362. package/dist/esm/transactions/swap.js +144 -0
  363. package/dist/esm/transactions/transact.d.ts +34 -0
  364. package/dist/esm/transactions/transact.js +110 -0
  365. package/dist/esm/transactions/transfer.d.ts +51 -0
  366. package/dist/esm/transactions/transfer.js +103 -0
  367. package/dist/esm/transactions/withdraw.d.ts +52 -0
  368. package/dist/esm/transactions/withdraw.js +101 -0
  369. package/dist/esm/utxo.d.ts +1 -235
  370. package/dist/esm/utxo.js +2 -382
  371. package/identity.d.ts +2 -0
  372. package/identity.js +3 -0
  373. package/idl.d.ts +2 -0
  374. package/idl.js +3 -0
  375. package/notes.d.ts +2 -0
  376. package/notes.js +3 -0
  377. package/package.json +131 -11
  378. package/perps.d.ts +2 -0
  379. package/perps.js +3 -0
  380. package/poseidon.d.ts +2 -2
  381. package/poseidon.js +2 -3
  382. package/positions.d.ts +2 -0
  383. package/positions.js +3 -0
  384. package/predictions.d.ts +2 -0
  385. package/predictions.js +3 -0
  386. package/proof.d.ts +2 -2
  387. package/proof.js +2 -3
  388. package/prover.d.ts +2 -2
  389. package/prover.js +2 -3
  390. package/relayer.d.ts +2 -0
  391. package/relayer.js +3 -0
  392. package/shield.d.ts +2 -2
  393. package/shield.js +2 -3
  394. package/transactions.d.ts +2 -0
  395. package/transactions.js +3 -0
  396. package/SHIELD_INTEGRATION.md +0 -143
  397. package/dist/src/client.d.ts +0 -407
  398. package/dist/src/client.js +0 -951
  399. package/dist/src/compactNote.d.ts +0 -107
  400. package/dist/src/compactNote.js +0 -167
  401. package/dist/src/config.d.ts +0 -82
  402. package/dist/src/config.js +0 -57
  403. package/dist/src/events.d.ts +0 -77
  404. package/dist/src/events.js +0 -167
  405. package/dist/src/idl/privacy_pool.js +0 -15218
  406. package/dist/src/index.d.ts +0 -16
  407. package/dist/src/index.js +0 -67
  408. package/dist/src/merkle.d.ts +0 -77
  409. package/dist/src/merkle.js +0 -156
  410. package/dist/src/poseidon.d.ts +0 -29
  411. package/dist/src/poseidon.js +0 -100
  412. package/dist/src/program.d.ts +0 -37
  413. package/dist/src/program.js +0 -61
  414. package/dist/src/proof.d.ts +0 -183
  415. package/dist/src/proof.js +0 -292
  416. package/dist/src/prover.d.ts +0 -54
  417. package/dist/src/prover.js +0 -112
  418. package/dist/src/random.d.ts +0 -16
  419. package/dist/src/random.js +0 -28
  420. package/dist/src/relayer.js +0 -257
  421. package/dist/src/retry.d.ts +0 -32
  422. package/dist/src/retry.js +0 -75
  423. package/dist/src/shield/alt.d.ts +0 -87
  424. package/dist/src/shield/alt.js +0 -194
  425. package/dist/src/shield/computeBudget.d.ts +0 -61
  426. package/dist/src/shield/computeBudget.js +0 -64
  427. package/dist/src/shield/errors.d.ts +0 -58
  428. package/dist/src/shield/errors.js +0 -121
  429. package/dist/src/shield/finalize.d.ts +0 -45
  430. package/dist/src/shield/finalize.js +0 -119
  431. package/dist/src/shield/index.d.ts +0 -35
  432. package/dist/src/shield/index.js +0 -68
  433. package/dist/src/shield/ix.d.ts +0 -54
  434. package/dist/src/shield/ix.js +0 -119
  435. package/dist/src/shield/owner.d.ts +0 -36
  436. package/dist/src/shield/owner.js +0 -126
  437. package/dist/src/shield/ports.d.ts +0 -43
  438. package/dist/src/shield/ports.js +0 -153
  439. package/dist/src/shield/preflight.d.ts +0 -30
  440. package/dist/src/shield/preflight.js +0 -154
  441. package/dist/src/shield/shield.d.ts +0 -68
  442. package/dist/src/shield/shield.js +0 -499
  443. package/dist/src/shield/types.d.ts +0 -202
  444. package/dist/src/utxo.d.ts +0 -235
  445. package/dist/src/utxo.js +0 -407
  446. package/dist/tests/compact-note.test.d.ts +0 -1
  447. package/dist/tests/compact-note.test.js +0 -173
  448. package/dist/tests/config.test.d.ts +0 -1
  449. package/dist/tests/config.test.js +0 -102
  450. package/dist/tests/edge-cases.test.d.ts +0 -1
  451. package/dist/tests/edge-cases.test.js +0 -220
  452. package/dist/tests/encryption.test.d.ts +0 -1
  453. package/dist/tests/encryption.test.js +0 -215
  454. package/dist/tests/events.test.d.ts +0 -1
  455. package/dist/tests/events.test.js +0 -78
  456. package/dist/tests/multi-tree.test.d.ts +0 -1
  457. package/dist/tests/multi-tree.test.js +0 -405
  458. package/dist/tests/pda.test.d.ts +0 -1
  459. package/dist/tests/pda.test.js +0 -229
  460. package/dist/tests/poseidon-builder-parity.test.d.ts +0 -1
  461. package/dist/tests/poseidon-builder-parity.test.js +0 -72
  462. package/dist/tests/poseidon.test.d.ts +0 -1
  463. package/dist/tests/poseidon.test.js +0 -142
  464. package/dist/tests/proof.test.d.ts +0 -1
  465. package/dist/tests/proof.test.js +0 -296
  466. package/dist/tests/relayer.test.d.ts +0 -1
  467. package/dist/tests/relayer.test.js +0 -271
  468. package/dist/tests/sdk.integration.test.d.ts +0 -1
  469. package/dist/tests/sdk.integration.test.js +0 -330
  470. package/dist/tests/shield-owner.test.d.ts +0 -1
  471. package/dist/tests/shield-owner.test.js +0 -89
  472. package/dist/tests/shield-preflight.test.d.ts +0 -1
  473. package/dist/tests/shield-preflight.test.js +0 -87
  474. package/dist/tests/shield-realproof.test.d.ts +0 -1
  475. package/dist/tests/shield-realproof.test.js +0 -272
  476. package/dist/tests/shield.test.d.ts +0 -1
  477. package/dist/tests/shield.test.js +0 -403
  478. package/dist/tests/utxo.test.d.ts +0 -1
  479. package/dist/tests/utxo.test.js +0 -140
  480. /package/dist/{src/shield → cjs/events}/types.js +0 -0
  481. /package/dist/{src/idl/privacy_pool.d.ts → cjs/idl/privacy_pool_legacy.d.ts} +0 -0
@@ -1,403 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- require("mocha");
7
- const assert_1 = require("assert");
8
- const web3_js_1 = require("@solana/web3.js");
9
- const spl_token_1 = require("@solana/spl-token");
10
- const tweetnacl_1 = __importDefault(require("tweetnacl"));
11
- const src_1 = require("../src");
12
- /**
13
- * The de-risking test for `shield()`.
14
- *
15
- * Everything expensive and non-deterministic is stubbed — the prover, the tree
16
- * source, the lookup table, the RPC — so what remains under test is the part
17
- * that actually decides whether a shield works: does the assembled transaction
18
- * fit in 1232 bytes, is it unsigned, does the note belong to the right person,
19
- * and does `rebuild()` really avoid re-proving.
20
- *
21
- * The size assertions are the point. A shield that is 40 bytes too large fails
22
- * at the wallet with an opaque error, and no amount of on-chain testing tells
23
- * you which account caused it.
24
- */
25
- const USDC = new web3_js_1.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
26
- const BLOCKHASH_2 = new web3_js_1.PublicKey(new Uint8Array(32).fill(2)).toBase58();
27
- const BLOCKHASH_3 = new web3_js_1.PublicKey(new Uint8Array(32).fill(3)).toBase58();
28
- const BLOCKHASH_4 = new web3_js_1.PublicKey(new Uint8Array(32).fill(4)).toBase58();
29
- // --- stubs -------------------------------------------------------------------
30
- let proverCalls = 0;
31
- /** A structurally valid Groth16 proof. The values are nonsense; the sizes are not. */
32
- const stubProver = async () => {
33
- proverCalls++;
34
- const f = (n) => n.toString();
35
- return {
36
- pi_a: [f(1), f(2), f(1)],
37
- pi_b: [
38
- [f(3), f(4)],
39
- [f(5), f(6)],
40
- [f(1), f(0)],
41
- ],
42
- pi_c: [f(7), f(8), f(1)],
43
- protocol: "groth16",
44
- curve: "bn128",
45
- };
46
- };
47
- function stubConnection(overrides = {}) {
48
- return {
49
- getLatestBlockhash: async () => ({
50
- blockhash: "11111111111111111111111111111111",
51
- lastValidBlockHeight: 123456789,
52
- }),
53
- getMinimumBalanceForRentExemption: async () => 961680,
54
- ...overrides,
55
- };
56
- }
57
- /** A lookup table containing exactly the accounts a shield needs compressed. */
58
- async function stubAlt(mint, outputTreeId, extra = []) {
59
- const required = (0, src_1.requiredAltKeys)({ mint, outputTreeId }).map((k) => k.address);
60
- const addresses = [...required, ...extra];
61
- return new web3_js_1.AddressLookupTableAccount({
62
- key: web3_js_1.PublicKey.unique(),
63
- state: {
64
- deactivationSlot: BigInt("18446744073709551615"),
65
- lastExtendedSlot: 0,
66
- lastExtendedSlotStartIndex: 0,
67
- authority: undefined,
68
- addresses,
69
- },
70
- });
71
- }
72
- function makeOwner() {
73
- const wallet = tweetnacl_1.default.sign.keyPair();
74
- return {
75
- owner: (0, src_1.unsafeShieldOwner)({
76
- veiloPublicKey: (0, src_1.generateKeypair)().publicKey,
77
- noteViewingKey: new web3_js_1.PublicKey(wallet.publicKey),
78
- acknowledgeOwnerInvariant: true,
79
- }),
80
- secretKey: wallet.secretKey,
81
- };
82
- }
83
- const TARGET = {
84
- inputTreeId: 0,
85
- inputRoot: new Uint8Array(32).fill(9),
86
- outputTreeId: 0,
87
- outputNextIndex: 4242,
88
- };
89
- // --- tests -------------------------------------------------------------------
90
- describe("shield()", function () {
91
- this.timeout(60000);
92
- before(async () => {
93
- await (0, src_1.initPoseidon)();
94
- });
95
- beforeEach(() => {
96
- proverCalls = 0;
97
- });
98
- async function buildShield(opts = {}) {
99
- const mint = opts.mint ?? src_1.NATIVE_SOL_MINT;
100
- const outputTreeId = opts.outputTreeId ?? 0;
101
- const { owner, secretKey } = opts.owner
102
- ? { owner: opts.owner, secretKey: new Uint8Array(64) }
103
- : makeOwner();
104
- const signerPubkey = web3_js_1.Keypair.generate().publicKey;
105
- const alt = await stubAlt(mint, outputTreeId);
106
- const result = await (0, src_1.shield)({
107
- connection: stubConnection(),
108
- amount: opts.amount ?? 1000000000n,
109
- mint,
110
- owner,
111
- signer: {
112
- publicKey: signerPubkey,
113
- tokenAccount: opts.signerTokenAccount,
114
- },
115
- prover: stubProver,
116
- treeSource: (0, src_1.staticTreeSource)({ ...TARGET, outputTreeId }),
117
- alt: (0, src_1.explicitAlt)(alt),
118
- cache: (0, src_1.noCache)(),
119
- preflight: false,
120
- computeUnitPriceMicroLamports: opts.computeUnitPriceMicroLamports,
121
- });
122
- return { result, owner, secretKey, alt, signerPubkey, mint };
123
- }
124
- describe("size budget", () => {
125
- it("fits under 1232 bytes for native SOL", async () => {
126
- const { result } = await buildShield();
127
- assert_1.strict.ok(result.quote.serializedSize <= src_1.MAX_TRANSACTION_BYTES, `SOL shield is ${result.quote.serializedSize} bytes, over ${src_1.MAX_TRANSACTION_BYTES}`);
128
- assert_1.strict.equal(result.quote.serializedSize, result.transaction.serialize().length, "size quote must match the actual wire transaction exactly");
129
- console.log(` SOL/tree0: ${result.quote.serializedSize} bytes ` +
130
- `(${src_1.MAX_TRANSACTION_BYTES - result.quote.serializedSize} spare)`);
131
- });
132
- it("fits for an SPL mint on tree 0", async () => {
133
- const signer = web3_js_1.Keypair.generate().publicKey;
134
- const ata = await (0, spl_token_1.getAssociatedTokenAddress)(USDC, signer);
135
- const { result } = await buildShield({ mint: USDC, signerTokenAccount: ata });
136
- assert_1.strict.ok(result.quote.serializedSize <= src_1.MAX_TRANSACTION_BYTES, `USDC shield is ${result.quote.serializedSize} bytes`);
137
- console.log(` USDC/tree0: ${result.quote.serializedSize} bytes ` +
138
- `(${src_1.MAX_TRANSACTION_BYTES - result.quote.serializedSize} spare)`);
139
- });
140
- it("fits for an SPL mint on a non-zero tree", async () => {
141
- const signer = web3_js_1.Keypair.generate().publicKey;
142
- const ata = await (0, spl_token_1.getAssociatedTokenAddress)(USDC, signer);
143
- const { result } = await buildShield({
144
- mint: USDC,
145
- outputTreeId: 3,
146
- signerTokenAccount: ata,
147
- });
148
- assert_1.strict.ok(result.quote.serializedSize <= src_1.MAX_TRANSACTION_BYTES, `USDC/tree3 shield is ${result.quote.serializedSize} bytes — this is the case ` +
149
- `that breaks first when the shared ALT only covers tree 0`);
150
- console.log(` USDC/tree3: ${result.quote.serializedSize} bytes ` +
151
- `(${src_1.MAX_TRANSACTION_BYTES - result.quote.serializedSize} spare)`);
152
- });
153
- it("reports which keys could not be compressed when it does not fit", async () => {
154
- // A table missing the pool PDAs forces them to static keys.
155
- const emptyAlt = new web3_js_1.AddressLookupTableAccount({
156
- key: web3_js_1.PublicKey.unique(),
157
- state: {
158
- deactivationSlot: BigInt("18446744073709551615"),
159
- lastExtendedSlot: 0,
160
- lastExtendedSlotStartIndex: 0,
161
- authority: undefined,
162
- addresses: [],
163
- },
164
- });
165
- const { owner } = makeOwner();
166
- await assert_1.strict.rejects((0, src_1.shield)({
167
- connection: stubConnection(),
168
- amount: 1000000n,
169
- mint: USDC,
170
- owner,
171
- signer: { publicKey: web3_js_1.Keypair.generate().publicKey },
172
- prover: stubProver,
173
- treeSource: (0, src_1.staticTreeSource)(TARGET),
174
- alt: (0, src_1.explicitAlt)(emptyAlt),
175
- cache: (0, src_1.noCache)(),
176
- preflight: false,
177
- }), (e) => {
178
- assert_1.strict.ok(e instanceof src_1.ShieldError);
179
- assert_1.strict.equal(e.code, "TX_TOO_LARGE");
180
- const keys = e.context?.uncompressedKeys;
181
- assert_1.strict.ok(Array.isArray(keys) && keys.length > 0, "expected uncompressed key list");
182
- return true;
183
- });
184
- });
185
- it("omitting the priority fee saves bytes", async () => {
186
- const withFee = await buildShield({ computeUnitPriceMicroLamports: 50000 });
187
- const withoutFee = await buildShield({ computeUnitPriceMicroLamports: 0 });
188
- assert_1.strict.ok(withoutFee.result.quote.serializedSize < withFee.result.quote.serializedSize, "dropping the priority-fee instruction should shrink the transaction");
189
- });
190
- });
191
- describe("transaction shape", () => {
192
- it("returns an unsigned v0 transaction with exactly one signature slot", async () => {
193
- const { result } = await buildShield();
194
- const tx = result.transaction;
195
- assert_1.strict.ok(tx instanceof web3_js_1.VersionedTransaction);
196
- assert_1.strict.equal(tx.signatures.length, 1, "expected exactly one signer");
197
- assert_1.strict.ok(tx.signatures[0].every((b) => b === 0), "transaction must be returned UNSIGNED — the SDK never holds a key");
198
- });
199
- it("uses exactly one address lookup table", async () => {
200
- const { result, alt } = await buildShield();
201
- const lookups = result.transaction.message.addressTableLookups;
202
- assert_1.strict.equal(lookups.length, 1);
203
- assert_1.strict.equal(lookups[0].accountKey.toBase58(), alt.key.toBase58());
204
- });
205
- it("makes the signer the fee payer", async () => {
206
- const { result, signerPubkey } = await buildShield();
207
- assert_1.strict.equal(result.transaction.message.staticAccountKeys[0].toBase58(), signerPubkey.toBase58());
208
- });
209
- it("targets the Veilo program", async () => {
210
- const { result } = await buildShield();
211
- const keys = [
212
- ...result.transaction.message.staticAccountKeys.map((k) => k.toBase58()),
213
- ];
214
- const lookups = result.transaction.message.addressTableLookups;
215
- assert_1.strict.ok(keys.includes(src_1.PRIVACY_POOL_PROGRAM_ID.toBase58()) || lookups.length > 0, "program id must be reachable");
216
- });
217
- });
218
- describe("note ownership", () => {
219
- it("creates a note the recipient — and only the recipient — can decrypt", async () => {
220
- const { result, secretKey } = await buildShield({ amount: 5000000n });
221
- const recovered = (0, src_1.decryptCompactNoteCipher)(secretKey, result.note.compact.ephemeralPublicKey, result.note.compact.compactBlob);
222
- assert_1.strict.ok(recovered, "the owner could not decrypt their own note");
223
- assert_1.strict.equal(recovered.amount, 5000000n);
224
- assert_1.strict.equal((0, src_1.bytesToBigIntBE)(recovered.blinding), result.note.blinding, "decrypted blinding must match the note");
225
- const stranger = tweetnacl_1.default.sign.keyPair();
226
- assert_1.strict.equal((0, src_1.decryptCompactNoteCipher)(stranger.secretKey, result.note.compact.ephemeralPublicKey, result.note.compact.compactBlob), null, "a stranger should not be able to decrypt this note");
227
- });
228
- it("binds the commitment to the owner's veilo key, not the signer", async () => {
229
- const { result, owner, mint } = await buildShield({ amount: 7n });
230
- const expected = (0, src_1.commitUTXO)({
231
- amount: 7n,
232
- pubkey: owner.veiloPublicKey,
233
- blinding: result.note.blinding,
234
- mintAddress: (0, src_1.pubkeyToField)(mint),
235
- });
236
- assert_1.strict.equal(Buffer.from(result.note.commitment).toString("hex"), Buffer.from(expected).toString("hex"));
237
- });
238
- it("refuses a hand-built owner that has not acknowledged the invariant", async () => {
239
- const alt = await stubAlt(src_1.NATIVE_SOL_MINT, 0);
240
- await assert_1.strict.rejects((0, src_1.shield)({
241
- connection: stubConnection(),
242
- amount: 1n,
243
- owner: {
244
- veiloPublicKey: (0, src_1.generateKeypair)().publicKey,
245
- noteViewingKey: web3_js_1.PublicKey.unique(),
246
- },
247
- signer: { publicKey: web3_js_1.PublicKey.unique() },
248
- prover: stubProver,
249
- treeSource: (0, src_1.staticTreeSource)(TARGET),
250
- alt: (0, src_1.explicitAlt)(alt),
251
- cache: (0, src_1.noCache)(),
252
- preflight: false,
253
- }), (e) => {
254
- assert_1.strict.ok(e instanceof src_1.ShieldError);
255
- assert_1.strict.equal(e.code, "OWNER_INVARIANT_UNACKNOWLEDGED");
256
- return true;
257
- });
258
- assert_1.strict.equal(proverCalls, 0, "should fail before spending time on a proof");
259
- });
260
- it("rejects a non-positive amount", async () => {
261
- const alt = await stubAlt(src_1.NATIVE_SOL_MINT, 0);
262
- const { owner } = makeOwner();
263
- await assert_1.strict.rejects((0, src_1.shield)({
264
- connection: stubConnection(),
265
- amount: 0n,
266
- owner,
267
- signer: { publicKey: web3_js_1.PublicKey.unique() },
268
- prover: stubProver,
269
- treeSource: (0, src_1.staticTreeSource)(TARGET),
270
- alt: (0, src_1.explicitAlt)(alt),
271
- cache: (0, src_1.noCache)(),
272
- preflight: false,
273
- }), /positive/);
274
- });
275
- it("rejects a full output tree before invoking the prover", async () => {
276
- const alt = await stubAlt(src_1.NATIVE_SOL_MINT, 0);
277
- const { owner } = makeOwner();
278
- await assert_1.strict.rejects((0, src_1.shield)({
279
- connection: stubConnection(),
280
- amount: 1n,
281
- owner,
282
- signer: { publicKey: web3_js_1.Keypair.generate().publicKey },
283
- prover: stubProver,
284
- treeSource: (0, src_1.staticTreeSource)({
285
- ...TARGET,
286
- outputNextIndex: 2 ** 22,
287
- }),
288
- alt: (0, src_1.explicitAlt)(alt),
289
- cache: (0, src_1.noCache)(),
290
- preflight: false,
291
- }), (error) => {
292
- assert_1.strict.ok(error instanceof src_1.ShieldError);
293
- assert_1.strict.equal(error.code, "TREE_FULL");
294
- return true;
295
- });
296
- assert_1.strict.equal(proverCalls, 0, "a full tree must fail before proof generation");
297
- });
298
- });
299
- describe("rebuild()", () => {
300
- it("does not invoke the prover again", async () => {
301
- const { result, alt } = await buildShield();
302
- assert_1.strict.equal(proverCalls, 1);
303
- await (0, src_1.rebuild)(result, {
304
- alt,
305
- blockhash: { blockhash: BLOCKHASH_2, lastValidBlockHeight: 2 },
306
- });
307
- await (0, src_1.rebuild)(result, {
308
- alt,
309
- blockhash: { blockhash: BLOCKHASH_3, lastValidBlockHeight: 3 },
310
- });
311
- await (0, src_1.rebuild)(result, {
312
- alt,
313
- blockhash: { blockhash: BLOCKHASH_4, lastValidBlockHeight: 4 },
314
- });
315
- assert_1.strict.equal(proverCalls, 1, "rebuild() must reuse the cached proof — re-proving costs 10-30s");
316
- });
317
- it("changes only the blockhash and the deadline bytes", async () => {
318
- const { result, alt } = await buildShield();
319
- const before = result.transaction.message.compiledInstructions;
320
- const again = await (0, src_1.rebuild)(result, {
321
- alt,
322
- blockhash: { blockhash: BLOCKHASH_2, lastValidBlockHeight: 2 },
323
- deadlineSeconds: 7200,
324
- });
325
- const after = again.transaction.message.compiledInstructions;
326
- assert_1.strict.equal(before.length, after.length);
327
- // The transact instruction is last; its data must differ ONLY in the
328
- // 8-byte deadline field.
329
- const b = Buffer.from(before[before.length - 1].data);
330
- const a = Buffer.from(after[after.length - 1].data);
331
- assert_1.strict.equal(a.length, b.length);
332
- const differing = [];
333
- for (let i = 0; i < a.length; i++)
334
- if (a[i] !== b[i])
335
- differing.push(i);
336
- assert_1.strict.ok(differing.length > 0 && differing.length <= 8, `expected only the deadline to change, but ${differing.length} bytes differ`);
337
- // Deadline sits after discriminator(8) + root(32) + treeIds(4) +
338
- // publicAmount(8) + extDataHash(32) + mint(32) + nullifiers/commitments(128).
339
- const deadlineOffset = 8 + 32 + 4 + 8 + 32 + 32 + 128;
340
- for (const i of differing) {
341
- assert_1.strict.ok(i >= deadlineOffset && i < deadlineOffset + 8, `byte ${i} changed but is outside the deadline field at ${deadlineOffset}..${deadlineOffset + 8}`);
342
- }
343
- });
344
- it("keeps the account keys identical", async () => {
345
- const { result, alt } = await buildShield();
346
- const again = await (0, src_1.rebuild)(result, {
347
- alt,
348
- blockhash: { blockhash: BLOCKHASH_2, lastValidBlockHeight: 2 },
349
- });
350
- assert_1.strict.deepEqual(result.transaction.message.staticAccountKeys.map((k) => k.toBase58()), again.transaction.message.staticAccountKeys.map((k) => k.toBase58()));
351
- });
352
- it("carries the new blockhash through to the result", async () => {
353
- const { result, alt } = await buildShield();
354
- const again = await (0, src_1.rebuild)(result, {
355
- alt,
356
- blockhash: { blockhash: BLOCKHASH_2, lastValidBlockHeight: 99 },
357
- });
358
- assert_1.strict.equal(again.blockhash, BLOCKHASH_2);
359
- assert_1.strict.equal(again.lastValidBlockHeight, 99);
360
- assert_1.strict.ok(again.deadline >= result.deadline);
361
- });
362
- it("preserves the note across rebuilds", async () => {
363
- const { result, alt, secretKey } = await buildShield();
364
- const again = await (0, src_1.rebuild)(result, {
365
- alt,
366
- blockhash: { blockhash: BLOCKHASH_2, lastValidBlockHeight: 2 },
367
- });
368
- assert_1.strict.equal(Buffer.from(again.note.commitment).toString("hex"), Buffer.from(result.note.commitment).toString("hex"));
369
- assert_1.strict.ok((0, src_1.decryptCompactNoteCipher)(secretKey, again.note.compact.ephemeralPublicKey, again.note.compact.compactBlob));
370
- });
371
- });
372
- describe("proof cache", () => {
373
- it("round-trips through JSON", async () => {
374
- const { result } = await buildShield();
375
- const back = (0, src_1.deserializeProofCache)((0, src_1.serializeProofCache)(result.proofCache));
376
- assert_1.strict.deepEqual(back, result.proofCache);
377
- });
378
- it("carries no secret material", async () => {
379
- const { result } = await buildShield();
380
- const json = (0, src_1.serializeProofCache)(result.proofCache);
381
- // The blinding is the secret that makes a note spendable. It must never
382
- // appear in the cache, which is explicitly documented as safe to transmit.
383
- const blindingHex = result.note.blinding.toString(16).padStart(64, "0");
384
- assert_1.strict.ok(!json.toLowerCase().includes(blindingHex.toLowerCase()), "the proof cache leaked the note blinding");
385
- assert_1.strict.ok(!json.includes("privateKey"));
386
- });
387
- it("rejects an unknown cache version", () => {
388
- assert_1.strict.throws(() => (0, src_1.deserializeProofCache)(JSON.stringify({ version: 99 })), /version/);
389
- });
390
- });
391
- describe("quote", () => {
392
- it("prices the burned nullifier-marker rent", async () => {
393
- const { result } = await buildShield();
394
- // Two markers at the stubbed rent-exemption minimum.
395
- assert_1.strict.equal(result.quote.estimatedRentLamports, 961680n * 2n);
396
- assert_1.strict.ok(result.quote.estimatedFeeLamports > 0n);
397
- });
398
- it("reports the predicted leaf index as given by the tree source", async () => {
399
- const { result } = await buildShield();
400
- assert_1.strict.equal(result.predictedLeafIndex, TARGET.outputNextIndex);
401
- });
402
- });
403
- });
@@ -1 +0,0 @@
1
- import "mocha";
@@ -1,140 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("mocha");
4
- const assert_1 = require("assert");
5
- const src_1 = require("../src");
6
- describe("UTXO helpers", function () {
7
- this.timeout(10000);
8
- before(async () => {
9
- await (0, src_1.initPoseidon)();
10
- });
11
- describe("Keypair generation", () => {
12
- it("generates a random keypair", () => {
13
- const kp = (0, src_1.generateKeypair)();
14
- assert_1.strict.ok(kp.privateKey > 0n, "privateKey should be positive");
15
- assert_1.strict.ok(kp.publicKey > 0n, "publicKey should be positive");
16
- assert_1.strict.ok(kp.privateKey < src_1.BN254_FR_MODULUS, "privateKey should be less than field modulus");
17
- assert_1.strict.ok(kp.publicKey < src_1.BN254_FR_MODULUS, "publicKey should be less than field modulus");
18
- });
19
- it("derives public key deterministically", () => {
20
- const privateKey = 12345n;
21
- const pubkey1 = (0, src_1.derivePublicKey)(privateKey);
22
- const pubkey2 = (0, src_1.derivePublicKey)(privateKey);
23
- assert_1.strict.equal(pubkey1, pubkey2, "public key derivation should be deterministic");
24
- });
25
- it("creates keypair from private key", () => {
26
- const privateKey = 67890n;
27
- const kp = (0, src_1.keypairFromPrivateKey)(privateKey);
28
- assert_1.strict.equal(kp.privateKey, privateKey);
29
- assert_1.strict.equal(kp.publicKey, (0, src_1.derivePublicKey)(privateKey));
30
- });
31
- });
32
- describe("UTXO creation", () => {
33
- it("creates a UTXO with commitment", () => {
34
- const kp = (0, src_1.generateKeypair)();
35
- const utxo = (0, src_1.createUTXO)({
36
- amount: 1000000n,
37
- pubkey: kp.publicKey,
38
- mintAddress: src_1.NATIVE_SOL_MINT,
39
- });
40
- assert_1.strict.equal(utxo.amount, 1000000n);
41
- assert_1.strict.equal(utxo.pubkey, kp.publicKey);
42
- assert_1.strict.ok(utxo.blinding > 0n, "blinding should be positive");
43
- assert_1.strict.equal(utxo.commitment.length, 32);
44
- });
45
- it("creates an owned UTXO with private key", () => {
46
- const privateKey = 11111n;
47
- const utxo = (0, src_1.createOwnedUTXO)({
48
- amount: 500000n,
49
- privateKey,
50
- mintAddress: src_1.NATIVE_SOL_MINT,
51
- });
52
- assert_1.strict.equal(utxo.amount, 500000n);
53
- assert_1.strict.equal(utxo.privateKey, privateKey);
54
- assert_1.strict.equal(utxo.pubkey, (0, src_1.derivePublicKey)(privateKey));
55
- assert_1.strict.equal(utxo.commitment.length, 32);
56
- });
57
- it("creates a zero UTXO", () => {
58
- const kp = (0, src_1.generateKeypair)();
59
- const utxo = (0, src_1.createZeroUTXO)(kp.publicKey, src_1.NATIVE_SOL_MINT);
60
- assert_1.strict.equal(utxo.amount, 0n);
61
- assert_1.strict.equal(utxo.pubkey, kp.publicKey);
62
- assert_1.strict.equal(utxo.commitment.length, 32);
63
- });
64
- it("creates an owned zero UTXO", () => {
65
- const privateKey = 22222n;
66
- const utxo = (0, src_1.createOwnedZeroUTXO)(privateKey, src_1.NATIVE_SOL_MINT);
67
- assert_1.strict.equal(utxo.amount, 0n);
68
- assert_1.strict.equal(utxo.privateKey, privateKey);
69
- assert_1.strict.equal(utxo.pubkey, (0, src_1.derivePublicKey)(privateKey));
70
- });
71
- });
72
- describe("UTXO commitment", () => {
73
- it("computes commitment deterministically", () => {
74
- const kp = (0, src_1.generateKeypair)();
75
- const utxo1 = {
76
- amount: 1000n,
77
- pubkey: kp.publicKey,
78
- blinding: 12345n,
79
- mintAddress: 0n,
80
- };
81
- const utxo2 = { ...utxo1 };
82
- const commitment1 = (0, src_1.commitUTXO)(utxo1);
83
- const commitment2 = (0, src_1.commitUTXO)(utxo2);
84
- assert_1.strict.equal(commitment1.length, 32);
85
- assert_1.strict.equal(Buffer.compare(Buffer.from(commitment1), Buffer.from(commitment2)), 0, "commitment should be deterministic");
86
- });
87
- it("produces different commitments for different amounts", () => {
88
- const kp = (0, src_1.generateKeypair)();
89
- const utxo1 = {
90
- amount: 1000n,
91
- pubkey: kp.publicKey,
92
- blinding: 12345n,
93
- mintAddress: 0n,
94
- };
95
- const utxo2 = {
96
- ...utxo1,
97
- amount: 2000n,
98
- };
99
- const commitment1 = (0, src_1.commitUTXO)(utxo1);
100
- const commitment2 = (0, src_1.commitUTXO)(utxo2);
101
- assert_1.strict.notEqual(Buffer.compare(Buffer.from(commitment1), Buffer.from(commitment2)), 0, "different amounts should produce different commitments");
102
- });
103
- });
104
- describe("Nullifier derivation", () => {
105
- it("derives nullifier from UTXO", () => {
106
- const privateKey = 33333n;
107
- const utxo = (0, src_1.createOwnedUTXO)({
108
- amount: 1000000n,
109
- privateKey,
110
- mintAddress: src_1.NATIVE_SOL_MINT,
111
- });
112
- const pathIndex = 5;
113
- const nullifier = (0, src_1.deriveNullifier)(utxo, pathIndex, privateKey);
114
- assert_1.strict.equal(nullifier.length, 32);
115
- });
116
- it("produces different nullifiers for different path indices", () => {
117
- const privateKey = 44444n;
118
- const utxo = (0, src_1.createOwnedUTXO)({
119
- amount: 1000000n,
120
- privateKey,
121
- mintAddress: src_1.NATIVE_SOL_MINT,
122
- });
123
- const nullifier1 = (0, src_1.deriveNullifier)(utxo, 0, privateKey);
124
- const nullifier2 = (0, src_1.deriveNullifier)(utxo, 1, privateKey);
125
- assert_1.strict.notEqual(Buffer.compare(Buffer.from(nullifier1), Buffer.from(nullifier2)), 0, "different path indices should produce different nullifiers");
126
- });
127
- it("produces same nullifier for same inputs", () => {
128
- const privateKey = 55555n;
129
- const utxo = (0, src_1.createOwnedUTXO)({
130
- amount: 1000000n,
131
- privateKey,
132
- mintAddress: src_1.NATIVE_SOL_MINT,
133
- });
134
- const pathIndex = 10;
135
- const nullifier1 = (0, src_1.deriveNullifier)(utxo, pathIndex, privateKey);
136
- const nullifier2 = (0, src_1.deriveNullifier)(utxo, pathIndex, privateKey);
137
- assert_1.strict.equal(Buffer.compare(Buffer.from(nullifier1), Buffer.from(nullifier2)), 0, "same inputs should produce same nullifier");
138
- });
139
- });
140
- });
File without changes