@unlink-xyz/core 0.1.3 → 0.1.4

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 (369) hide show
  1. package/README.md +9 -0
  2. package/dist/account/{zkAccount.d.ts → account.d.ts} +36 -5
  3. package/dist/account/account.d.ts.map +1 -0
  4. package/dist/account/accounts.d.ts +42 -0
  5. package/dist/account/accounts.d.ts.map +1 -0
  6. package/dist/account/seed.d.ts +45 -0
  7. package/dist/account/seed.d.ts.map +1 -0
  8. package/dist/account/serialization.d.ts +6 -0
  9. package/dist/account/serialization.d.ts.map +1 -0
  10. package/dist/browser/index.js +56221 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/browser/wallet/index.js +55942 -0
  13. package/dist/browser/wallet/index.js.map +1 -0
  14. package/dist/clients/broadcaster.d.ts +8 -2
  15. package/dist/clients/broadcaster.d.ts.map +1 -1
  16. package/dist/clients/http.d.ts +6 -0
  17. package/dist/clients/http.d.ts.map +1 -1
  18. package/dist/clients/indexer.d.ts +16 -0
  19. package/dist/clients/indexer.d.ts.map +1 -1
  20. package/dist/config.d.ts +30 -9
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/constants.d.ts +6 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/core.d.ts.map +1 -1
  25. package/dist/crypto/adapters/index.d.ts +17 -0
  26. package/dist/crypto/adapters/index.d.ts.map +1 -0
  27. package/dist/crypto/adapters/polyfills.d.ts +5 -0
  28. package/dist/crypto/adapters/polyfills.d.ts.map +1 -0
  29. package/dist/crypto/encrypt.d.ts +33 -0
  30. package/dist/crypto/encrypt.d.ts.map +1 -0
  31. package/dist/crypto/secure-memory.d.ts +25 -0
  32. package/dist/crypto/secure-memory.d.ts.map +1 -0
  33. package/dist/errors.d.ts +17 -0
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/history/index.d.ts +3 -0
  36. package/dist/history/index.d.ts.map +1 -0
  37. package/dist/history/service.d.ts +46 -0
  38. package/dist/history/service.d.ts.map +1 -0
  39. package/dist/history/types.d.ts +21 -0
  40. package/dist/history/types.d.ts.map +1 -0
  41. package/dist/index.d.ts +16 -7
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +6721 -19
  44. package/dist/index.js.map +1 -0
  45. package/dist/keys/address.d.ts +13 -0
  46. package/dist/keys/address.d.ts.map +1 -0
  47. package/dist/keys/derive.d.ts +37 -0
  48. package/dist/keys/derive.d.ts.map +1 -0
  49. package/dist/keys/hex.d.ts +14 -0
  50. package/dist/keys/hex.d.ts.map +1 -0
  51. package/dist/keys/index.d.ts +5 -0
  52. package/dist/keys/index.d.ts.map +1 -0
  53. package/dist/keys/mnemonic.d.ts +6 -0
  54. package/dist/keys/mnemonic.d.ts.map +1 -0
  55. package/dist/keys.d.ts +5 -1
  56. package/dist/keys.d.ts.map +1 -1
  57. package/dist/prover/config.d.ts +53 -22
  58. package/dist/prover/config.d.ts.map +1 -1
  59. package/dist/prover/integrity.d.ts +20 -0
  60. package/dist/prover/integrity.d.ts.map +1 -0
  61. package/dist/prover/prover.d.ts +16 -20
  62. package/dist/prover/prover.d.ts.map +1 -1
  63. package/dist/prover/registry.d.ts +3 -30
  64. package/dist/prover/registry.d.ts.map +1 -1
  65. package/dist/state/merkle/hydrator.d.ts +21 -19
  66. package/dist/state/merkle/hydrator.d.ts.map +1 -1
  67. package/dist/state/merkle/index.d.ts +2 -2
  68. package/dist/state/merkle/index.d.ts.map +1 -1
  69. package/dist/state/merkle/merkle-tree.d.ts +8 -0
  70. package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
  71. package/dist/state/store/ciphertext-store.d.ts +11 -0
  72. package/dist/state/store/ciphertext-store.d.ts.map +1 -1
  73. package/dist/state/store/history-store.d.ts +24 -0
  74. package/dist/state/store/history-store.d.ts.map +1 -0
  75. package/dist/state/store/index.d.ts +3 -2
  76. package/dist/state/store/index.d.ts.map +1 -1
  77. package/dist/state/store/job-store.d.ts +7 -7
  78. package/dist/state/store/job-store.d.ts.map +1 -1
  79. package/dist/state/store/jobs.d.ts +70 -25
  80. package/dist/state/store/jobs.d.ts.map +1 -1
  81. package/dist/state/store/leaf-store.d.ts +4 -0
  82. package/dist/state/store/leaf-store.d.ts.map +1 -1
  83. package/dist/state/store/note-store.d.ts +7 -7
  84. package/dist/state/store/note-store.d.ts.map +1 -1
  85. package/dist/state/store/nullifier-store.d.ts +9 -0
  86. package/dist/state/store/nullifier-store.d.ts.map +1 -1
  87. package/dist/state/store/records.d.ts +39 -2
  88. package/dist/state/store/records.d.ts.map +1 -1
  89. package/dist/state/store/root-store.d.ts.map +1 -1
  90. package/dist/state/store/store.d.ts +79 -27
  91. package/dist/state/store/store.d.ts.map +1 -1
  92. package/dist/storage/indexeddb.d.ts.map +1 -1
  93. package/dist/storage/memory.d.ts.map +1 -1
  94. package/dist/transactions/adapter.d.ts +31 -0
  95. package/dist/transactions/adapter.d.ts.map +1 -0
  96. package/dist/transactions/deposit.d.ts +12 -15
  97. package/dist/transactions/deposit.d.ts.map +1 -1
  98. package/dist/transactions/index.d.ts +9 -4
  99. package/dist/transactions/index.d.ts.map +1 -1
  100. package/dist/transactions/note-selection.d.ts +17 -0
  101. package/dist/transactions/note-selection.d.ts.map +1 -0
  102. package/dist/transactions/note-sync.d.ts +5 -33
  103. package/dist/transactions/note-sync.d.ts.map +1 -1
  104. package/dist/transactions/reconcile.d.ts +9 -11
  105. package/dist/transactions/reconcile.d.ts.map +1 -1
  106. package/dist/transactions/transact.d.ts +30 -22
  107. package/dist/transactions/transact.d.ts.map +1 -1
  108. package/dist/transactions/transaction-planner.d.ts +34 -0
  109. package/dist/transactions/transaction-planner.d.ts.map +1 -0
  110. package/dist/transactions/transfer-planner.d.ts +37 -0
  111. package/dist/transactions/transfer-planner.d.ts.map +1 -0
  112. package/dist/transactions/types/deposit.d.ts +67 -0
  113. package/dist/transactions/types/deposit.d.ts.map +1 -0
  114. package/dist/transactions/types/domain.d.ts +70 -0
  115. package/dist/transactions/types/domain.d.ts.map +1 -0
  116. package/dist/transactions/types/index.d.ts +18 -0
  117. package/dist/transactions/types/index.d.ts.map +1 -0
  118. package/dist/transactions/types/options.d.ts +54 -0
  119. package/dist/transactions/types/options.d.ts.map +1 -0
  120. package/dist/transactions/types/planning.d.ts +82 -0
  121. package/dist/transactions/types/planning.d.ts.map +1 -0
  122. package/dist/transactions/types/state-stores.d.ts +151 -0
  123. package/dist/transactions/types/state-stores.d.ts.map +1 -0
  124. package/dist/transactions/types/transact.d.ts +83 -0
  125. package/dist/transactions/types/transact.d.ts.map +1 -0
  126. package/dist/transactions/withdrawal-planner.d.ts +58 -0
  127. package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
  128. package/dist/tsconfig.tsbuildinfo +1 -1
  129. package/dist/tsup.browser.config.d.ts +7 -0
  130. package/dist/tsup.browser.config.d.ts.map +1 -0
  131. package/dist/tsup.config.d.ts +8 -0
  132. package/dist/tsup.config.d.ts.map +1 -0
  133. package/dist/types.d.ts +1 -0
  134. package/dist/types.d.ts.map +1 -1
  135. package/dist/utils/amounts.d.ts +26 -0
  136. package/dist/utils/amounts.d.ts.map +1 -0
  137. package/dist/utils/async.d.ts +9 -0
  138. package/dist/utils/async.d.ts.map +1 -1
  139. package/dist/utils/async.js +38 -11
  140. package/dist/utils/async.js.map +1 -0
  141. package/dist/utils/bigint.d.ts +0 -2
  142. package/dist/utils/bigint.d.ts.map +1 -1
  143. package/dist/utils/format.d.ts +25 -0
  144. package/dist/utils/format.d.ts.map +1 -0
  145. package/dist/utils/notes.d.ts +15 -0
  146. package/dist/utils/notes.d.ts.map +1 -0
  147. package/dist/utils/polling.d.ts +5 -0
  148. package/dist/utils/polling.d.ts.map +1 -1
  149. package/dist/utils/random.d.ts +18 -0
  150. package/dist/utils/random.d.ts.map +1 -0
  151. package/dist/utils/signature.d.ts +6 -0
  152. package/dist/utils/signature.d.ts.map +1 -1
  153. package/dist/utils/validators.d.ts +21 -10
  154. package/dist/utils/validators.d.ts.map +1 -1
  155. package/dist/vitest.config.d.ts +3 -0
  156. package/dist/vitest.config.d.ts.map +1 -0
  157. package/dist/wallet/adapter.d.ts +21 -0
  158. package/dist/wallet/adapter.d.ts.map +1 -0
  159. package/dist/wallet/burner/service.d.ts +32 -0
  160. package/dist/wallet/burner/service.d.ts.map +1 -0
  161. package/dist/wallet/burner/types.d.ts +47 -0
  162. package/dist/wallet/burner/types.d.ts.map +1 -0
  163. package/dist/wallet/index.d.ts +20 -0
  164. package/dist/wallet/index.d.ts.map +1 -0
  165. package/dist/wallet/index.js +6462 -0
  166. package/dist/wallet/index.js.map +1 -0
  167. package/dist/wallet/sdk.d.ts +48 -0
  168. package/dist/wallet/sdk.d.ts.map +1 -0
  169. package/dist/wallet/types.d.ts +457 -0
  170. package/dist/wallet/types.d.ts.map +1 -0
  171. package/dist/wallet/unlink-wallet.d.ts +187 -0
  172. package/dist/wallet/unlink-wallet.d.ts.map +1 -0
  173. package/package.json +38 -15
  174. package/.eslintrc.json +0 -4
  175. package/account/zkAccount.test.ts +0 -316
  176. package/account/zkAccount.ts +0 -222
  177. package/circuits.json +0 -26
  178. package/clients/broadcaster.ts +0 -67
  179. package/clients/http.ts +0 -94
  180. package/clients/indexer.ts +0 -150
  181. package/config.ts +0 -39
  182. package/core.ts +0 -17
  183. package/dist/account/railgun-imports-prototype.d.ts +0 -12
  184. package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
  185. package/dist/account/railgun-imports-prototype.js +0 -30
  186. package/dist/account/zkAccount.d.ts.map +0 -1
  187. package/dist/account/zkAccount.js +0 -128
  188. package/dist/circuits.json +0 -26
  189. package/dist/clients/broadcaster.js +0 -23
  190. package/dist/clients/http.js +0 -57
  191. package/dist/clients/indexer.js +0 -67
  192. package/dist/config.js +0 -29
  193. package/dist/core.js +0 -12
  194. package/dist/errors.js +0 -18
  195. package/dist/key-derivation/babyjubjub.d.ts +0 -9
  196. package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
  197. package/dist/key-derivation/babyjubjub.js +0 -9
  198. package/dist/key-derivation/bech32.d.ts +0 -22
  199. package/dist/key-derivation/bech32.d.ts.map +0 -1
  200. package/dist/key-derivation/bech32.js +0 -86
  201. package/dist/key-derivation/bip32.d.ts +0 -17
  202. package/dist/key-derivation/bip32.d.ts.map +0 -1
  203. package/dist/key-derivation/bip32.js +0 -41
  204. package/dist/key-derivation/bip39.d.ts +0 -22
  205. package/dist/key-derivation/bip39.d.ts.map +0 -1
  206. package/dist/key-derivation/bip39.js +0 -56
  207. package/dist/key-derivation/bytes.d.ts +0 -19
  208. package/dist/key-derivation/bytes.d.ts.map +0 -1
  209. package/dist/key-derivation/bytes.js +0 -92
  210. package/dist/key-derivation/hash.d.ts +0 -3
  211. package/dist/key-derivation/hash.d.ts.map +0 -1
  212. package/dist/key-derivation/hash.js +0 -10
  213. package/dist/key-derivation/index.d.ts +0 -8
  214. package/dist/key-derivation/index.d.ts.map +0 -1
  215. package/dist/key-derivation/index.js +0 -7
  216. package/dist/key-derivation/wallet-node.d.ts +0 -45
  217. package/dist/key-derivation/wallet-node.d.ts.map +0 -1
  218. package/dist/key-derivation/wallet-node.js +0 -109
  219. package/dist/keys.js +0 -41
  220. package/dist/prover/config.js +0 -80
  221. package/dist/prover/index.js +0 -1
  222. package/dist/prover/prover.js +0 -274
  223. package/dist/prover/registry.js +0 -57
  224. package/dist/schema.js +0 -14
  225. package/dist/state/ciphertext-store.d.ts +0 -12
  226. package/dist/state/ciphertext-store.d.ts.map +0 -1
  227. package/dist/state/ciphertext-store.js +0 -25
  228. package/dist/state/hydrator.d.ts +0 -16
  229. package/dist/state/hydrator.d.ts.map +0 -1
  230. package/dist/state/hydrator.js +0 -18
  231. package/dist/state/index.js +0 -2
  232. package/dist/state/job-store.d.ts +0 -12
  233. package/dist/state/job-store.d.ts.map +0 -1
  234. package/dist/state/job-store.js +0 -118
  235. package/dist/state/jobs.d.ts +0 -50
  236. package/dist/state/jobs.d.ts.map +0 -1
  237. package/dist/state/jobs.js +0 -1
  238. package/dist/state/leaf-store.d.ts +0 -17
  239. package/dist/state/leaf-store.d.ts.map +0 -1
  240. package/dist/state/leaf-store.js +0 -35
  241. package/dist/state/merkle/hydrator.js +0 -36
  242. package/dist/state/merkle/index.js +0 -2
  243. package/dist/state/merkle/merkle-tree.js +0 -104
  244. package/dist/state/merkle-tree.d.ts +0 -34
  245. package/dist/state/merkle-tree.d.ts.map +0 -1
  246. package/dist/state/merkle-tree.js +0 -104
  247. package/dist/state/note-store.d.ts +0 -37
  248. package/dist/state/note-store.d.ts.map +0 -1
  249. package/dist/state/note-store.js +0 -133
  250. package/dist/state/nullifier-store.d.ts +0 -13
  251. package/dist/state/nullifier-store.d.ts.map +0 -1
  252. package/dist/state/nullifier-store.js +0 -21
  253. package/dist/state/records.d.ts +0 -57
  254. package/dist/state/records.d.ts.map +0 -1
  255. package/dist/state/records.js +0 -1
  256. package/dist/state/root-store.d.ts +0 -13
  257. package/dist/state/root-store.d.ts.map +0 -1
  258. package/dist/state/root-store.js +0 -30
  259. package/dist/state/store/ciphertext-store.js +0 -25
  260. package/dist/state/store/index.js +0 -8
  261. package/dist/state/store/job-store.js +0 -118
  262. package/dist/state/store/jobs.js +0 -1
  263. package/dist/state/store/leaf-store.js +0 -35
  264. package/dist/state/store/note-store.js +0 -142
  265. package/dist/state/store/nullifier-store.js +0 -30
  266. package/dist/state/store/records.js +0 -1
  267. package/dist/state/store/root-store.js +0 -30
  268. package/dist/state/store/store.js +0 -22
  269. package/dist/state/store.d.ts +0 -26
  270. package/dist/state/store.d.ts.map +0 -1
  271. package/dist/state/store.js +0 -19
  272. package/dist/state.d.ts +0 -83
  273. package/dist/state.d.ts.map +0 -1
  274. package/dist/state.js +0 -171
  275. package/dist/storage/index.js +0 -2
  276. package/dist/storage/indexeddb.js +0 -205
  277. package/dist/storage/memory.js +0 -87
  278. package/dist/transactions/deposit.js +0 -169
  279. package/dist/transactions/index.js +0 -4
  280. package/dist/transactions/note-sync.js +0 -320
  281. package/dist/transactions/reconcile.js +0 -39
  282. package/dist/transactions/shield.d.ts +0 -5
  283. package/dist/transactions/shield.d.ts.map +0 -1
  284. package/dist/transactions/shield.js +0 -93
  285. package/dist/transactions/transact.js +0 -561
  286. package/dist/transactions/types.d.ts +0 -114
  287. package/dist/transactions/types.d.ts.map +0 -1
  288. package/dist/transactions/types.js +0 -1
  289. package/dist/transactions/utils.d.ts +0 -10
  290. package/dist/transactions/utils.d.ts.map +0 -1
  291. package/dist/transactions/utils.js +0 -17
  292. package/dist/types.js +0 -1
  293. package/dist/utils/bigint.js +0 -29
  294. package/dist/utils/crypto.d.ts +0 -12
  295. package/dist/utils/crypto.d.ts.map +0 -1
  296. package/dist/utils/crypto.js +0 -39
  297. package/dist/utils/json-codec.js +0 -25
  298. package/dist/utils/polling.js +0 -6
  299. package/dist/utils/signature.js +0 -12
  300. package/dist/utils/time.d.ts +0 -2
  301. package/dist/utils/time.d.ts.map +0 -1
  302. package/dist/utils/time.js +0 -3
  303. package/dist/utils/validators.js +0 -70
  304. package/dist/utils/witness.d.ts +0 -11
  305. package/dist/utils/witness.d.ts.map +0 -1
  306. package/dist/utils/witness.js +0 -19
  307. package/errors.ts +0 -20
  308. package/index.ts +0 -21
  309. package/key-derivation/babyjubjub.ts +0 -11
  310. package/key-derivation/bech32.test.ts +0 -90
  311. package/key-derivation/bech32.ts +0 -124
  312. package/key-derivation/bip32.ts +0 -56
  313. package/key-derivation/bip39.ts +0 -76
  314. package/key-derivation/bytes.ts +0 -118
  315. package/key-derivation/hash.ts +0 -13
  316. package/key-derivation/index.ts +0 -7
  317. package/key-derivation/wallet-node.ts +0 -155
  318. package/keys.ts +0 -47
  319. package/prover/config.ts +0 -104
  320. package/prover/index.ts +0 -1
  321. package/prover/prover.integration.test.ts +0 -162
  322. package/prover/prover.test.ts +0 -309
  323. package/prover/prover.ts +0 -405
  324. package/prover/registry.test.ts +0 -90
  325. package/prover/registry.ts +0 -82
  326. package/schema.ts +0 -17
  327. package/setup-artifacts.sh +0 -57
  328. package/state/index.ts +0 -2
  329. package/state/merkle/hydrator.ts +0 -69
  330. package/state/merkle/index.ts +0 -12
  331. package/state/merkle/merkle-tree.test.ts +0 -50
  332. package/state/merkle/merkle-tree.ts +0 -163
  333. package/state/store/ciphertext-store.ts +0 -28
  334. package/state/store/index.ts +0 -24
  335. package/state/store/job-store.ts +0 -162
  336. package/state/store/jobs.ts +0 -64
  337. package/state/store/leaf-store.ts +0 -39
  338. package/state/store/note-store.ts +0 -177
  339. package/state/store/nullifier-store.ts +0 -39
  340. package/state/store/records.ts +0 -61
  341. package/state/store/root-store.ts +0 -34
  342. package/state/store/store.ts +0 -25
  343. package/state.test.ts +0 -235
  344. package/storage/index.ts +0 -3
  345. package/storage/indexeddb.test.ts +0 -99
  346. package/storage/indexeddb.ts +0 -235
  347. package/storage/memory.test.ts +0 -59
  348. package/storage/memory.ts +0 -93
  349. package/transactions/deposit.test.ts +0 -160
  350. package/transactions/deposit.ts +0 -227
  351. package/transactions/index.ts +0 -20
  352. package/transactions/note-sync.test.ts +0 -155
  353. package/transactions/note-sync.ts +0 -452
  354. package/transactions/reconcile.ts +0 -73
  355. package/transactions/transact.test.ts +0 -451
  356. package/transactions/transact.ts +0 -811
  357. package/transactions/types.ts +0 -141
  358. package/tsconfig.json +0 -15
  359. package/types/global.d.ts +0 -15
  360. package/types.ts +0 -24
  361. package/utils/async.ts +0 -15
  362. package/utils/bigint.ts +0 -34
  363. package/utils/crypto.test.ts +0 -69
  364. package/utils/crypto.ts +0 -58
  365. package/utils/json-codec.ts +0 -38
  366. package/utils/polling.ts +0 -6
  367. package/utils/signature.ts +0 -16
  368. package/utils/validators.test.ts +0 -64
  369. package/utils/validators.ts +0 -86
@@ -1,90 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import {
4
- CIRCUIT_REGISTRY,
5
- getCircuitConfig,
6
- isCircuitSupported,
7
- SUPPORTED_CIRCUITS,
8
- type CircuitKey,
9
- } from "./registry.js";
10
-
11
- describe("Circuit Registry", () => {
12
- it("should have all expected circuits", () => {
13
- const expectedCircuits: CircuitKey[] = ["1x1", "1x2", "2x3", "3x3"];
14
- expect(SUPPORTED_CIRCUITS).toEqual(
15
- expect.arrayContaining(expectedCircuits),
16
- );
17
- });
18
-
19
- it("should correctly map circuit keys to configurations", () => {
20
- const config2x3 = CIRCUIT_REGISTRY["2x3"];
21
- expect(config2x3).toBeDefined();
22
- expect(config2x3.name).toBe("joinsplit_2x3_16");
23
- expect(config2x3.inputs).toBe(2);
24
- expect(config2x3.outputs).toBe(3);
25
- expect(config2x3.depth).toBe(16);
26
- });
27
-
28
- describe("getCircuitConfig", () => {
29
- it("should return config for valid circuit dimensions", () => {
30
- const config = getCircuitConfig(2, 3);
31
- expect(config).toBeDefined();
32
- expect(config?.name).toBe("joinsplit_2x3_16");
33
- expect(config?.inputs).toBe(2);
34
- expect(config?.outputs).toBe(3);
35
- });
36
-
37
- it("should return undefined for unsupported dimensions", () => {
38
- const config = getCircuitConfig(4, 5);
39
- expect(config).toBeUndefined();
40
- });
41
-
42
- it("should handle all supported circuit dimensions", () => {
43
- const testCases = [
44
- { inputs: 1, outputs: 1, name: "joinsplit_1x1_16" },
45
- { inputs: 1, outputs: 2, name: "joinsplit_1x2_16" },
46
- { inputs: 2, outputs: 3, name: "joinsplit_2x3_16" },
47
- { inputs: 3, outputs: 3, name: "joinsplit_3x3_16" },
48
- ];
49
-
50
- for (const testCase of testCases) {
51
- const config = getCircuitConfig(testCase.inputs, testCase.outputs);
52
- expect(config).toBeDefined();
53
- expect(config?.name).toBe(testCase.name);
54
- expect(config?.inputs).toBe(testCase.inputs);
55
- expect(config?.outputs).toBe(testCase.outputs);
56
- }
57
- });
58
- });
59
-
60
- describe("isCircuitSupported", () => {
61
- it("should return true for supported circuits", () => {
62
- expect(isCircuitSupported(1, 1)).toBe(true);
63
- expect(isCircuitSupported(1, 2)).toBe(true);
64
- expect(isCircuitSupported(2, 3)).toBe(true);
65
- expect(isCircuitSupported(3, 3)).toBe(true);
66
- });
67
-
68
- it("should return false for unsupported circuits", () => {
69
- expect(isCircuitSupported(4, 4)).toBe(false);
70
- expect(isCircuitSupported(0, 0)).toBe(false);
71
- expect(isCircuitSupported(1, 3)).toBe(false);
72
- expect(isCircuitSupported(2, 2)).toBe(false);
73
- });
74
- });
75
-
76
- it("should have consistent registry entries", () => {
77
- for (const [key, config] of Object.entries(CIRCUIT_REGISTRY)) {
78
- // Key should match inputs x outputs
79
- const [inputs, outputs] = key.split("x").map(Number);
80
- expect(config.inputs).toBe(inputs);
81
- expect(config.outputs).toBe(outputs);
82
-
83
- // Name should contain the key
84
- expect(config.name).toContain(`${inputs}x${outputs}`);
85
-
86
- // Depth should be 16 for all current circuits
87
- expect(config.depth).toBe(16);
88
- }
89
- });
90
- });
@@ -1,82 +0,0 @@
1
- // AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
2
- // Generated by scripts/generate-registry.ts
3
- // Source: circuits/circuits.json
4
- // Generated at: 2025-11-25T13:26:58.576Z
5
-
6
- /**
7
- * Circuit registry for automatic prover selection
8
- * Maps circuit dimensions (inputs x outputs) to circuit configurations
9
- */
10
-
11
- export interface CircuitConfig {
12
- /** Full circuit name (e.g., "joinsplit_2x3_16") */
13
- readonly name: string;
14
- /** Number of inputs (nullifiers) */
15
- readonly inputs: number;
16
- /** Number of outputs (commitments) */
17
- readonly outputs: number;
18
- /** Merkle tree depth */
19
- readonly depth: number;
20
- }
21
-
22
- export type CircuitKey = "3x3" | "2x3" | "1x2" | "1x1";
23
-
24
- /**
25
- * Registry of available circuits
26
- * Auto-generated from circuits/circuits.json
27
- */
28
- export const CIRCUIT_REGISTRY: Record<CircuitKey, CircuitConfig> = {
29
- "3x3": {
30
- name: "joinsplit_3x3_16",
31
- inputs: 3,
32
- outputs: 3,
33
- depth: 16,
34
- },
35
- "2x3": {
36
- name: "joinsplit_2x3_16",
37
- inputs: 2,
38
- outputs: 3,
39
- depth: 16,
40
- },
41
- "1x2": {
42
- name: "joinsplit_1x2_16",
43
- inputs: 1,
44
- outputs: 2,
45
- depth: 16,
46
- },
47
- "1x1": {
48
- name: "joinsplit_1x1_16",
49
- inputs: 1,
50
- outputs: 1,
51
- depth: 16,
52
- },
53
- } as const;
54
-
55
- /**
56
- * Get list of all supported circuit keys
57
- */
58
- export const SUPPORTED_CIRCUITS = Object.keys(CIRCUIT_REGISTRY) as CircuitKey[];
59
-
60
- /**
61
- * Get circuit configuration by dimensions
62
- * @param inputs Number of inputs (nullifiers)
63
- * @param outputs Number of outputs (commitments)
64
- * @returns Circuit configuration or undefined if not supported
65
- */
66
- export function getCircuitConfig(
67
- inputs: number,
68
- outputs: number,
69
- ): CircuitConfig | undefined {
70
- const key = `${inputs}x${outputs}` as CircuitKey;
71
- return CIRCUIT_REGISTRY[key];
72
- }
73
-
74
- /**
75
- * Check if a circuit configuration is supported
76
- * @param inputs Number of inputs (nullifiers)
77
- * @param outputs Number of outputs (commitments)
78
- * @returns True if supported
79
- */
80
- export function isCircuitSupported(inputs: number, outputs: number): boolean {
81
- return getCircuitConfig(inputs, outputs) !== undefined;
82
- }
package/schema.ts DELETED
@@ -1,17 +0,0 @@
1
- import { SchemaMismatchError } from "./errors.js";
2
- import type { Storage } from "./types.js";
3
-
4
- export const CORE_SCHEMA_VERSION = 1;
5
-
6
- export async function migrate(storage: Storage) {
7
- await storage.open();
8
- const current = await storage.getSchemaVersion();
9
- if (current === 0) {
10
- // seed structures if needed
11
- await storage.setSchemaVersion(CORE_SCHEMA_VERSION);
12
- return;
13
- }
14
- if (current !== CORE_SCHEMA_VERSION) {
15
- throw new SchemaMismatchError(current, CORE_SCHEMA_VERSION);
16
- }
17
- }
@@ -1,57 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Script to setup SDK artifacts from circuits build
4
- # Creates symlinks to avoid duplicating large files
5
-
6
- set -e
7
-
8
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
- SDK_ARTIFACTS="$SCRIPT_DIR/artifacts/circuits"
10
- CIRCUITS_ARTIFACTS="$SCRIPT_DIR/../../circuits/artifacts"
11
-
12
- echo "Setting up SDK circuit artifacts..."
13
- echo "Source: $CIRCUITS_ARTIFACTS"
14
- echo "Target: $SDK_ARTIFACTS"
15
-
16
- mkdir -p "$SDK_ARTIFACTS"
17
-
18
- # Check if circuits artifacts exist
19
- if [ ! -d "$CIRCUITS_ARTIFACTS" ]; then
20
- echo "❌ Error: Circuit artifacts not found at $CIRCUITS_ARTIFACTS"
21
- echo "Please run 'pnpm run circuits:build' in the root directory first."
22
- exit 1
23
- fi
24
-
25
- # Remove old flat structure if it exists
26
- if [ -f "$SDK_ARTIFACTS/joinsplit.wasm" ]; then
27
- echo "Removing old artifact structure..."
28
- rm -f "$SDK_ARTIFACTS/joinsplit.wasm"
29
- rm -f "$SDK_ARTIFACTS/joinsplit.zkey"
30
- rm -f "$SDK_ARTIFACTS/joinsplit.vkey.json"
31
- fi
32
-
33
- # Create circuit-specific directories and symlink artifacts
34
- for circuit_dir in "$CIRCUITS_ARTIFACTS"/*; do
35
- if [ -d "$circuit_dir" ]; then
36
- circuit_name=$(basename "$circuit_dir")
37
- target_dir="$SDK_ARTIFACTS/$circuit_name"
38
-
39
- echo "Setting up $circuit_name..."
40
-
41
- # Create target directory
42
- mkdir -p "$target_dir"
43
-
44
- # Create symlinks
45
- ln -sf "$circuit_dir/joinsplit.wasm" "$target_dir/joinsplit.wasm"
46
- ln -sf "$circuit_dir/joinsplit.zkey" "$target_dir/joinsplit.zkey"
47
- ln -sf "$circuit_dir/joinsplit.vkey.json" "$target_dir/joinsplit.vkey.json"
48
-
49
- echo " ✓ Linked $circuit_name artifacts"
50
- fi
51
- done
52
-
53
- echo ""
54
- echo "✓ SDK artifacts setup complete!"
55
- echo ""
56
- echo "Available circuits:"
57
- ls -1 "$SDK_ARTIFACTS"
package/state/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./merkle/index.js";
2
- export * from "./store/index.js";
@@ -1,69 +0,0 @@
1
- import { parseHexToBigInt } from "../../utils/bigint.js";
2
-
3
- export type LeafLoader = (
4
- chainId: number,
5
- index: number,
6
- ) => Promise<{ commitment: string } | null>;
7
-
8
- export async function rebuildTreeFromStore({
9
- chainId,
10
- trees,
11
- loadLeaf,
12
- }: {
13
- chainId: number;
14
- trees: {
15
- reset(chainId: number): void;
16
- addLeaf(chainId: number, value: bigint): { index: number };
17
- getLeafCount?(chainId: number): number;
18
- };
19
- loadLeaf: LeafLoader;
20
- }) {
21
- trees.reset(chainId);
22
- let idx = 0;
23
- for (;;) {
24
- const leaf = await loadLeaf(chainId, idx);
25
- if (!leaf) break;
26
- const { index } = trees.addLeaf(chainId, parseHexToBigInt(leaf.commitment));
27
- if (index !== idx) {
28
- throw new Error(
29
- `stored leaves are inconsistent with local tree, expected ${idx}, got ${index}`,
30
- );
31
- }
32
- idx += 1;
33
- }
34
- return idx;
35
- }
36
-
37
- export type HydrateChainParams = {
38
- chainId: number;
39
- trees: {
40
- reset(chainId: number): void;
41
- addLeaf(chainId: number, value: bigint): { index: number };
42
- };
43
- loadLeaf: LeafLoader;
44
- hydrated: Set<number>;
45
- };
46
-
47
- // TODO: Will be used for inmemory merkle tree handling for caching.
48
- // Atm everytime we need to access the tree we have to rebuild it from the store.
49
- // This function will help to avoid multiple rebuilds for the same chain
50
- export async function hydrateChain({
51
- chainId,
52
- trees,
53
- loadLeaf,
54
- hydrated,
55
- }: HydrateChainParams) {
56
- if (hydrated.has(chainId)) return;
57
- trees.reset(chainId);
58
- let idx = 0;
59
- for (;;) {
60
- const leaf = await loadLeaf(chainId, idx);
61
- if (!leaf) break;
62
- const { index } = trees.addLeaf(chainId, parseHexToBigInt(leaf.commitment));
63
- if (index !== idx) {
64
- throw new Error("stored leaves are inconsistent with local tree");
65
- }
66
- idx += 1;
67
- }
68
- hydrated.add(chainId);
69
- }
@@ -1,12 +0,0 @@
1
- export {
2
- createLocalMerkleTree,
3
- createMerkleTrees,
4
- type LocalMerkleTree,
5
- type LocalMerkleTrees,
6
- type MerkleProof,
7
- } from "./merkle-tree.js";
8
- export {
9
- hydrateChain,
10
- rebuildTreeFromStore,
11
- type HydrateChainParams,
12
- } from "./hydrator.js";
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { createLocalMerkleTree } from "./merkle-tree.js";
4
-
5
- describe("local merkle tree", () => {
6
- it("returns deterministic roots for identical insert sequences", () => {
7
- const inserts = [0x01n, 0x02n, 0x03n];
8
-
9
- const treeA = createLocalMerkleTree();
10
- const rootsA = inserts.map((leaf) => treeA.addLeaf(leaf).root);
11
-
12
- const treeB = createLocalMerkleTree();
13
- const rootsB = inserts.map((leaf) => treeB.addLeaf(leaf).root);
14
-
15
- expect(rootsA).toEqual(rootsB);
16
- expect(treeA.getRoot()).toBe(treeB.getRoot());
17
- });
18
-
19
- it("tracks inserted leaf count and updates root", () => {
20
- const tree = createLocalMerkleTree();
21
- const initialRoot = tree.getRoot();
22
-
23
- const first = tree.addLeaf(1n);
24
- expect(tree.getLeafCount()).toBe(1);
25
- expect(first.index).toBe(0);
26
- expect(first.root).not.toBe(initialRoot);
27
-
28
- const second = tree.addLeaf(0x02n);
29
- expect(tree.getLeafCount()).toBe(2);
30
- expect(second.index).toBe(1);
31
- expect(second.root).not.toBe(first.root);
32
- });
33
-
34
- it("exposes zero hashes for valid levels and rejects invalid ones", () => {
35
- const tree = createLocalMerkleTree();
36
-
37
- expect(tree.getZero(0)).toMatch(/^0x[0-9a-f]+$/);
38
- expect(() => tree.getZero(-1)).toThrow("invalid level");
39
- expect(() => tree.getZero(tree.depth + 1)).toThrow("invalid level");
40
- });
41
-
42
- it("starts with zero root until the first insert", () => {
43
- const tree = createLocalMerkleTree();
44
- const emptyRoot = tree.getRoot();
45
-
46
- expect(emptyRoot).toBe(tree.getZero(tree.depth));
47
- tree.addLeaf(5n);
48
- expect(tree.getRoot()).not.toBe(emptyRoot);
49
- });
50
- });
@@ -1,163 +0,0 @@
1
- import { poseidon } from "@railgun-community/circomlibjs";
2
- import {
3
- IMT,
4
- IMTMerkleProof,
5
- type IMTHashFunction,
6
- type IMTNode,
7
- } from "@zk-kit/imt";
8
-
9
- import { ByteLength, ByteUtils } from "../../key-derivation/bytes.js";
10
- import { ensureChainId } from "../../utils/validators.js";
11
-
12
- type BigIntTree = IMT & {
13
- root: bigint;
14
- zeroes: bigint[];
15
- leaves: bigint[];
16
- };
17
-
18
- export type AddLeafResult = {
19
- index: number;
20
- root: string;
21
- };
22
-
23
- export type MerkleProof = {
24
- root: string;
25
- leaf: string;
26
- pathElements: string[][];
27
- pathIndices: number[];
28
- leafIndex: number;
29
- };
30
-
31
- const DEFAULT_DEPTH = 16;
32
- const DEFAULT_ARITY = 2;
33
- const ZERO_BYTE_LENGTH = ByteLength.UINT_256;
34
-
35
- // Simple adapter: IMTNode[] -> poseidon(bigint[])
36
- const hash: IMTHashFunction = (values: IMTNode[]) =>
37
- poseidon(values.map((v) => BigInt(v)));
38
-
39
- const formatNode = (value: bigint) =>
40
- ByteUtils.nToHex(value, ZERO_BYTE_LENGTH, true);
41
-
42
- export function createLocalMerkleTree() {
43
- const zeroLeaf = 0n;
44
- const capacity = 2 ** DEFAULT_DEPTH;
45
- const tree = new IMT(
46
- hash,
47
- DEFAULT_DEPTH,
48
- zeroLeaf,
49
- DEFAULT_ARITY,
50
- ) as BigIntTree;
51
-
52
- function addLeaf(value: bigint): AddLeafResult {
53
- if (tree.leaves.length >= capacity) {
54
- throw new Error("merkle tree is full");
55
- }
56
-
57
- const insertedIndex = tree.leaves.length;
58
- tree.insert(value);
59
-
60
- return {
61
- index: insertedIndex,
62
- root: formatNode(tree.root),
63
- };
64
- }
65
-
66
- function getRoot() {
67
- return formatNode(tree.root);
68
- }
69
-
70
- function getLeafCount() {
71
- return tree.leaves.length;
72
- }
73
-
74
- function getLeaf(index: number) {
75
- const leaf = tree.leaves[index];
76
- if (leaf === undefined) {
77
- throw new Error("leaf does not exist in this tree");
78
- }
79
- return formatNode(BigInt(leaf));
80
- }
81
-
82
- function createMerkleProof(index: number): IMTMerkleProof {
83
- return tree.createProof(index);
84
- }
85
-
86
- return {
87
- addLeaf,
88
- getRoot,
89
- getLeafCount,
90
- getLeaf,
91
- createMerkleProof,
92
- getZero(level: number) {
93
- if (level === tree.depth) {
94
- return getRoot();
95
- }
96
- const zero = tree.zeroes[level];
97
- if (zero === undefined) {
98
- throw new Error("invalid level");
99
- }
100
- return formatNode(zero);
101
- },
102
- get depth() {
103
- return tree.depth;
104
- },
105
- get capacity() {
106
- return capacity;
107
- },
108
- };
109
- }
110
-
111
- export type LocalMerkleTree = ReturnType<typeof createLocalMerkleTree>;
112
-
113
- export type LocalMerkleTrees = {
114
- get(chainId: number): LocalMerkleTree | undefined;
115
- getOrCreate(chainId: number): LocalMerkleTree;
116
- addLeaf(chainId: number, value: bigint): AddLeafResult;
117
- createMerkleProof(chainId: number, index: number): IMTMerkleProof;
118
- getRoot(chainId: number): string;
119
- getLeafCount(chainId: number): number;
120
- reset(chainId: number): void;
121
- };
122
-
123
- export function createMerkleTrees(): LocalMerkleTrees {
124
- const trees = new Map<number, LocalMerkleTree>();
125
-
126
- const resetTree = (chainId: number) => {
127
- ensureChainId(chainId);
128
- const tree = createLocalMerkleTree();
129
- trees.set(chainId, tree);
130
- return tree;
131
- };
132
- const getOrCreate = (chainId: number) => {
133
- ensureChainId(chainId);
134
- let tree = trees.get(chainId);
135
- if (!tree) {
136
- tree = resetTree(chainId);
137
- }
138
- return tree;
139
- };
140
-
141
- return {
142
- get(chainId) {
143
- ensureChainId(chainId);
144
- return trees.get(chainId);
145
- },
146
- getOrCreate,
147
- addLeaf(chainId, value) {
148
- return getOrCreate(chainId).addLeaf(value);
149
- },
150
- createMerkleProof(chainId, index) {
151
- return getOrCreate(chainId).createMerkleProof(index);
152
- },
153
- getRoot(chainId) {
154
- return getOrCreate(chainId).getRoot();
155
- },
156
- getLeafCount(chainId) {
157
- return getOrCreate(chainId).getLeafCount();
158
- },
159
- reset(chainId) {
160
- resetTree(chainId);
161
- },
162
- };
163
- }
@@ -1,28 +0,0 @@
1
- import { keys, validateKey } from "../../keys.js";
2
- import type { Storage } from "../../types.js";
3
- import { ensureChainId, ensurePositiveInt } from "../../utils/validators.js";
4
-
5
- export function createCiphertextStore(storage: Storage) {
6
- return {
7
- /**
8
- * Store encrypted note payloads alongside their on-chain commitments.
9
- */
10
- async putCiphertext(chainId: number, index: number, payload: Uint8Array) {
11
- ensureChainId(chainId);
12
- ensurePositiveInt("ciphertext index", index);
13
- const key = keys.ciphertext(chainId, index);
14
- validateKey(key);
15
- await storage.put(key, new Uint8Array(payload));
16
- },
17
-
18
- /**
19
- * Retrieve encrypted note payloads; returns null when the ciphertext is missing.
20
- */
21
- async getCiphertext(chainId: number, index: number) {
22
- ensureChainId(chainId);
23
- ensurePositiveInt("ciphertext index", index);
24
- const data = await storage.get(keys.ciphertext(chainId, index));
25
- return data ? new Uint8Array(data) : null;
26
- },
27
- };
28
- }
@@ -1,24 +0,0 @@
1
- export { createStateStore } from "./store.js";
2
- export { createLeafStore } from "./leaf-store.js";
3
- export { createNoteStore } from "./note-store.js";
4
- export { createNullifierStore } from "./nullifier-store.js";
5
- export { createRootStore } from "./root-store.js";
6
- export { createCiphertextStore } from "./ciphertext-store.js";
7
- export { createJobStore } from "./job-store.js";
8
- export {
9
- DEFAULT_JOB_TIMEOUT_MS,
10
- type JobStatus,
11
- type PendingJobKind,
12
- type PendingJobRecord,
13
- type PendingDepositJob,
14
- type PendingTransactJob,
15
- type PendingTransactContext,
16
- type PendingTransactOutput,
17
- } from "./jobs.js";
18
- export type {
19
- LeafRecord,
20
- NoteInsert,
21
- NoteRecord,
22
- NullifierRecord,
23
- RootRecord,
24
- } from "./records.js";