@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,76 +0,0 @@
1
- import {
2
- entropyToMnemonic,
3
- generateMnemonic,
4
- mnemonicToEntropy,
5
- mnemonicToSeedSync,
6
- validateMnemonic,
7
- } from "@scure/bip39";
8
- import { wordlist } from "@scure/bip39/wordlists/english.js";
9
- import { HDKey } from "ethereum-cryptography/hdkey";
10
- import { Mnemonic as EthersMnemonic, HDNodeWallet } from "ethers";
11
-
12
- import { ByteUtils } from "./bytes.js";
13
-
14
- /**
15
- * Standard ETH derivation path helper for convenience utilities below.
16
- * Not used for 0zk accounts but kept for backwards compatibility.
17
- */
18
- const derivationPath = (index = 0): string => {
19
- return `m/44'/60'/0'/0/${index}`;
20
- };
21
-
22
- export class Mnemonic {
23
- /**
24
- * Generate a BIP-39 mnemonic using the English wordlist.
25
- */
26
- static generate(strength: 128 | 192 | 256 = 128): string {
27
- return generateMnemonic(wordlist, strength);
28
- }
29
-
30
- /**
31
- * Validate a mnemonic against the English wordlist checksum.
32
- */
33
- static validate(mnemonic: string): boolean {
34
- return validateMnemonic(mnemonic, wordlist);
35
- }
36
-
37
- /**
38
- * Convert a mnemonic to a hex-encoded BIP-39 seed. Optional password supported.
39
- */
40
- static toSeed(mnemonic: string, password: string = ""): string {
41
- const seed = mnemonicToSeedSync(mnemonic, password);
42
- return ByteUtils.bytesToHex(seed);
43
- }
44
-
45
- static toEntropy(mnemonic: string): string {
46
- const entropy = mnemonicToEntropy(mnemonic, wordlist);
47
- return ByteUtils.bytesToHex(entropy);
48
- }
49
-
50
- static fromEntropy(entropyHex: string): string {
51
- const entropy = ByteUtils.hexStringToBytes(entropyHex);
52
- return entropyToMnemonic(entropy, wordlist);
53
- }
54
-
55
- /**
56
- * Convenience helper: derive a 0x private key for non-0zk flows.
57
- */
58
- static to0xPrivateKey(mnemonic: string, derivationIndex?: number): string {
59
- const seed = mnemonicToSeedSync(mnemonic);
60
- const node = HDKey.fromMasterSeed(Buffer.from(seed)).derive(
61
- derivationPath(derivationIndex),
62
- );
63
- if (!node.privateKey) {
64
- throw new Error("Failed to derive private key");
65
- }
66
- return ByteUtils.bytesToHex(node.privateKey);
67
- }
68
-
69
- static to0xAddress(mnemonic: string, derivationIndex?: number): string {
70
- const wallet = HDNodeWallet.fromMnemonic(
71
- EthersMnemonic.fromPhrase(mnemonic),
72
- derivationPath(derivationIndex),
73
- );
74
- return wallet.address;
75
- }
76
- }
@@ -1,118 +0,0 @@
1
- export enum ByteLength {
2
- UINT_256 = 32,
3
- UINT_512 = 64,
4
- }
5
-
6
- export type BytesData =
7
- | string
8
- | number
9
- | bigint
10
- | Uint8Array
11
- | ArrayLike<number>;
12
-
13
- const HEX_REGEX = /^[0-9a-f]*$/i;
14
-
15
- const isPrefixed = (value: string): boolean => value.startsWith("0x");
16
-
17
- const assertEvenLength = (hex: string): void => {
18
- if (hex.length % 2 !== 0) {
19
- throw new Error("Hex string must have an even length");
20
- }
21
- };
22
-
23
- const assertHex = (hex: string): void => {
24
- if (!HEX_REGEX.test(hex)) {
25
- throw new Error("Invalid hex string");
26
- }
27
- };
28
-
29
- export class ByteUtils {
30
- static prefix0x(value: string): string {
31
- return isPrefixed(value) ? value : `0x${value}`;
32
- }
33
-
34
- static strip0x(value: string): string {
35
- return isPrefixed(value) ? value.slice(2) : value;
36
- }
37
-
38
- static hexlify(data: BytesData): string {
39
- if (typeof data === "string") {
40
- return ByteUtils.strip0x(data).toLowerCase();
41
- }
42
- if (typeof data === "number" || typeof data === "bigint") {
43
- if (data < 0) throw new Error("Cannot hexlify negative values");
44
- const hex = data.toString(16);
45
- return hex.length % 2 === 0 ? hex : `0${hex}`;
46
- }
47
- const view = data instanceof Uint8Array ? data : Uint8Array.from(data);
48
- return ByteUtils.bytesToHex(view);
49
- }
50
-
51
- static bytesToHex(bytes: Uint8Array): string {
52
- let hex = "";
53
- for (const byte of bytes) {
54
- hex += byte.toString(16).padStart(2, "0");
55
- }
56
- return hex;
57
- }
58
-
59
- static hexStringToBytes(hex: string): Uint8Array {
60
- const normalized = ByteUtils.strip0x(hex).toLowerCase();
61
- assertEvenLength(normalized);
62
- assertHex(normalized);
63
- const byteLength = normalized.length / 2;
64
- return Uint8Array.from({ length: byteLength }, (_, index) =>
65
- parseInt(normalized.slice(index * 2, index * 2 + 2), 16),
66
- );
67
- }
68
-
69
- static arrayify(data: BytesData): Uint8Array {
70
- if (data instanceof Uint8Array) {
71
- return new Uint8Array(data);
72
- }
73
- if (typeof data === "string") {
74
- return ByteUtils.hexStringToBytes(data);
75
- }
76
- if (typeof data === "number" || typeof data === "bigint") {
77
- return ByteUtils.hexStringToBytes(ByteUtils.hexlify(data));
78
- }
79
- return Uint8Array.from(data);
80
- }
81
-
82
- static hexToBigInt(hex: string): bigint {
83
- return BigInt(`0x${ByteUtils.strip0x(hex)}`);
84
- }
85
-
86
- static padToLength(
87
- data: BytesData,
88
- length: number,
89
- side: "left" | "right" = "left",
90
- ): string {
91
- const hex = ByteUtils.hexlify(data);
92
- const targetLength = length * 2;
93
- if (hex.length > targetLength) {
94
- throw new Error("Cannot pad data that exceeds target length");
95
- }
96
- return side === "left"
97
- ? hex.padStart(targetLength, "0")
98
- : hex.padEnd(targetLength, "0");
99
- }
100
-
101
- static formatToByteLength(data: BytesData, length: ByteLength): string {
102
- const hex = ByteUtils.hexlify(data);
103
- if (hex.length > length * 2) {
104
- return hex.slice(0, length * 2);
105
- }
106
- return hex.padStart(length * 2, "0");
107
- }
108
-
109
- static nToHex(value: bigint, length: ByteLength, prefix = false): string {
110
- const hex = value.toString(16).padStart(length * 2, "0");
111
- return prefix ? `0x${hex}` : hex;
112
- }
113
- }
114
-
115
- export function fromUTF8String(value: string): string {
116
- const encoder = new TextEncoder();
117
- return ByteUtils.hexlify(encoder.encode(value));
118
- }
@@ -1,13 +0,0 @@
1
- import { hmac } from "@noble/hashes/hmac";
2
- import { sha512 } from "@noble/hashes/sha2";
3
-
4
- import { BytesData, ByteUtils } from "./bytes.js";
5
-
6
- const toBytes = (data: BytesData): Uint8Array => {
7
- return ByteUtils.arrayify(data);
8
- };
9
-
10
- export function sha512HMAC(key: BytesData, data: BytesData): string {
11
- const mac = hmac(sha512, toBytes(key), toBytes(data));
12
- return ByteUtils.bytesToHex(mac);
13
- }
@@ -1,7 +0,0 @@
1
- export * from "./babyjubjub.js";
2
- export * from "./bip32.js";
3
- export * from "./bip39.js";
4
- export * from "./bech32.js";
5
- export * from "./bytes.js";
6
- export * from "./hash.js";
7
- export * from "./wallet-node.js";
@@ -1,155 +0,0 @@
1
- import { Buffer } from "buffer";
2
- import { getPublicKey, hashes } from "@noble/ed25519";
3
- import { sha512 } from "@noble/hashes/sha2";
4
- import { eddsa, poseidon } from "@railgun-community/circomlibjs";
5
-
6
- import {
7
- childKeyDerivationHardened,
8
- getMasterKeyFromSeed,
9
- getPathSegments,
10
- KeyNode,
11
- } from "./bip32.js";
12
- import { Mnemonic } from "./bip39.js";
13
- import { ByteUtils } from "./bytes.js";
14
-
15
- hashes.sha512 = sha512;
16
- hashes.sha512Async = async (message: Uint8Array) => sha512(message);
17
-
18
- const HARDENED_OFFSET = 0x80000000;
19
-
20
- export type SpendingPublicKey = [bigint, bigint];
21
- export type SpendingKeyPair = {
22
- privateKey: Uint8Array;
23
- pubkey: SpendingPublicKey;
24
- };
25
- export type ViewingKeyPair = { privateKey: Uint8Array; pubkey: Uint8Array };
26
-
27
- /**
28
- * Hardened base paths for spending/viewing keys. The final path becomes
29
- * m/.../{index}' for each account slot.
30
- */
31
- const DERIVATION_PATH_PREFIXES = {
32
- SPENDING: "m/44'/1984'/0'/0'/",
33
- VIEWING: "m/420'/1984'/0'/0'/",
34
- };
35
-
36
- const derivePathsForIndex = (index: number = 0) => ({
37
- spending: `${DERIVATION_PATH_PREFIXES.SPENDING}${index}'`,
38
- viewing: `${DERIVATION_PATH_PREFIXES.VIEWING}${index}'`,
39
- });
40
-
41
- export type WalletNodes = { spending: WalletNode; viewing: WalletNode };
42
-
43
- export const deriveNodes = (
44
- mnemonic: string,
45
- index: number = 0,
46
- ): WalletNodes => {
47
- const paths = derivePathsForIndex(index);
48
- const root = WalletNode.fromMnemonic(mnemonic);
49
- return {
50
- spending: root.derive(paths.spending),
51
- viewing: root.derive(paths.viewing),
52
- };
53
- };
54
-
55
- export const deriveNodesFromSeed = (
56
- seed: Uint8Array,
57
- index: number = 0,
58
- ): WalletNodes => {
59
- const paths = derivePathsForIndex(index);
60
- const root = WalletNode.fromSeed(seed);
61
- return {
62
- spending: root.derive(paths.spending),
63
- viewing: root.derive(paths.viewing),
64
- };
65
- };
66
-
67
- export class WalletNode {
68
- private readonly chainKey: string;
69
-
70
- private readonly chainCode: string;
71
-
72
- constructor(node: KeyNode) {
73
- this.chainKey = node.chainKey;
74
- this.chainCode = node.chainCode;
75
- }
76
-
77
- static fromMnemonic(mnemonic: string): WalletNode {
78
- const seedHex = Mnemonic.toSeed(mnemonic);
79
- return new WalletNode(getMasterKeyFromSeed(seedHex));
80
- }
81
-
82
- /**
83
- * Convenience constructor for callers that already hold a seed or mnemonic-derived hex.
84
- */
85
- static fromSeed(seed: Uint8Array | string): WalletNode {
86
- const seedHex =
87
- typeof seed === "string"
88
- ? ByteUtils.hexlify(seed)
89
- : ByteUtils.bytesToHex(seed);
90
- return new WalletNode(getMasterKeyFromSeed(seedHex));
91
- }
92
-
93
- /**
94
- * Traverse a derivation path, returning the resulting hardened node.
95
- */
96
- derive(path: string): WalletNode {
97
- const segments = getPathSegments(path);
98
- const derived = segments.reduce(
99
- (parent, segment) =>
100
- childKeyDerivationHardened(parent, segment, HARDENED_OFFSET),
101
- { chainKey: this.chainKey, chainCode: this.chainCode },
102
- );
103
- return new WalletNode(derived);
104
- }
105
-
106
- /**
107
- * Derive the BabyJubJub spending key pair (private scalar + affine point).
108
- */
109
- getSpendingKeyPair(): SpendingKeyPair {
110
- const privateKey = ByteUtils.hexStringToBytes(this.chainKey);
111
- if (privateKey.length !== 32) {
112
- throw new Error("Spending private key must be 32 bytes");
113
- }
114
- const pubkey = eddsa.prv2pub(Buffer.from(privateKey)) as SpendingPublicKey;
115
- return { privateKey, pubkey };
116
- }
117
-
118
- static getMasterPublicKey(
119
- spendingPublicKey: SpendingPublicKey,
120
- nullifyingKey: bigint,
121
- ): bigint {
122
- return poseidon([...spendingPublicKey, nullifyingKey]);
123
- }
124
-
125
- static getNullifyingKey(viewingPrivateKey: Uint8Array): bigint {
126
- if (!(viewingPrivateKey instanceof Uint8Array)) {
127
- throw new Error("Viewing private key must be a Uint8Array");
128
- }
129
- if (viewingPrivateKey.length !== 32) {
130
- throw new Error("Viewing private key must be 32 bytes");
131
- }
132
- const privateKeyHex = ByteUtils.bytesToHex(viewingPrivateKey);
133
- return poseidon([ByteUtils.hexToBigInt(privateKeyHex)]);
134
- }
135
-
136
- /**
137
- * Derive the Ed25519 viewing key pair for encrypted note retrieval.
138
- */
139
- async getViewingKeyPair(): Promise<ViewingKeyPair> {
140
- const privateKey = ByteUtils.hexStringToBytes(this.chainKey);
141
- if (privateKey.length !== 32) {
142
- throw new Error("Viewing private key must be 32 bytes");
143
- }
144
- const pubkey = await getPublicKey(privateKey);
145
- return { privateKey, pubkey };
146
- }
147
-
148
- /**
149
- * Compute the Poseidon-based nullifying key used in note nullifier generation.
150
- */
151
- async getNullifyingKey(): Promise<bigint> {
152
- const { privateKey } = await this.getViewingKeyPair();
153
- return WalletNode.getNullifyingKey(privateKey);
154
- }
155
- }
package/keys.ts DELETED
@@ -1,47 +0,0 @@
1
- import { KeyValidationError } from "./errors.js";
2
-
3
- export const RESERVED_PREFIXES = [
4
- "meta:",
5
- "notes:",
6
- "leaves:",
7
- "roots:",
8
- "nullifiers:",
9
- "ciphertexts:",
10
- "jobs:",
11
- "proof_cache:",
12
- "cfg:",
13
- "idx:",
14
- "locks:",
15
- ] as const;
16
-
17
- /** Canonical builders for storage key namespaces used across core */
18
- export const keys = {
19
- note: (c: number, i: number) => `notes:${c}:${i}`,
20
- leaf: (c: number, i: number) => `leaves:${c}:${i}`,
21
- ciphertext: (c: number, i: number) => `ciphertexts:${c}:${i}`,
22
- /** Track note indices that remain unspent for a given master public key (mpk acts as the account identifier). */
23
- unspent: (c: number, mpk: string, i: number) =>
24
- `idx:notes:unspent:${c}:${mpk}:${i}`,
25
- unspentPrefix: (c: number, mpk: string) => `idx:notes:unspent:${c}:${mpk}:`,
26
- nullifierObs: (c: number, n: string) => `nullifiers:${c}:${n}`,
27
- nullToIndex: (c: number, n: string) => `idx:nullifier:${c}:${n}`,
28
- nullifier: (c: number, n: string) => `nullifiers:${c}:${n}`,
29
- root: (c: number, value: string) => `roots:${c}:${value}`,
30
- latestRoot: (c: number) => `roots:latest:${c}`,
31
- rootCursor: (c: number) => `meta:roots:cursor:${c}`,
32
- cursor: (c: number) => `meta:sync:cursors:${c}`,
33
- aggregate: (c: number, a: string) => `idx:notes:agg:${c}:${a}`,
34
- job: (relayId: string) => `jobs:${relayId}`,
35
- };
36
-
37
- export const MAX_KEY_LEN = 512;
38
-
39
- export function validateKey(key: string) {
40
- if (!key) throw new KeyValidationError("key must not be empty");
41
- if (key.length > MAX_KEY_LEN)
42
- throw new KeyValidationError(`key exceeds ${MAX_KEY_LEN}`);
43
- if (!RESERVED_PREFIXES.some((p) => key.startsWith(p)))
44
- throw new KeyValidationError(
45
- "key must start with a reserved namespace prefix",
46
- );
47
- }
package/prover/config.ts DELETED
@@ -1,104 +0,0 @@
1
- /**
2
- * Configuration for the prover system
3
- * Handles artifact loading from local files or remote artifact server
4
- */
5
-
6
- /**
7
- * Environment-based configuration for artifact loading
8
- */
9
- export interface ProverConfig {
10
- /** Base URL for the artifact server (browser mode) */
11
- rpcUrl: string;
12
- /** Whether to enable artifact caching */
13
- enableCache: boolean;
14
- }
15
-
16
- /**
17
- * Default configuration
18
- * Can be overridden via environment variables
19
- */
20
- export const DEFAULT_CONFIG: ProverConfig = {
21
- rpcUrl:
22
- typeof process !== "undefined" && process.env?.UNLINK_RPC_URL
23
- ? process.env.UNLINK_RPC_URL
24
- : "http://localhost:3000",
25
- enableCache: true,
26
- };
27
-
28
- /**
29
- * Artifact file types
30
- */
31
- export enum ArtifactType {
32
- WASM = "joinsplit.wasm",
33
- ZKEY = "joinsplit.zkey",
34
- VKEY = "joinsplit.vkey.json",
35
- }
36
-
37
- /**
38
- * Build artifact URL for a given circuit and artifact type
39
- * @param circuitName Full circuit name (e.g., "joinsplit_2x3_16")
40
- * @param artifactType Type of artifact to fetch
41
- * @param baseUrl Base URL of the artifact server
42
- * @returns Full URL to the artifact
43
- */
44
- export function buildArtifactUrl(
45
- circuitName: string,
46
- artifactType: ArtifactType,
47
- baseUrl: string = DEFAULT_CONFIG.rpcUrl,
48
- ): string {
49
- // Remove trailing slash from baseUrl
50
- const cleanBaseUrl = baseUrl.replace(/\/$/, "");
51
- return `${cleanBaseUrl}/artifacts/${circuitName}/${artifactType}`;
52
- }
53
-
54
- /**
55
- * Get relative path for local artifact loading
56
- * Used in Node.js environment when artifacts are bundled
57
- * @param circuitName Full circuit name (e.g., "joinsplit_2x3_16")
58
- * @param artifactType Type of artifact
59
- * @returns Relative path to artifact
60
- */
61
- export function getLocalArtifactPath(
62
- circuitName: string,
63
- artifactType: ArtifactType,
64
- ): string[] {
65
- // Return multiple candidate paths for different build scenarios
66
- return [
67
- // When compiled: dist/prover/ -> ../../artifacts/circuits/{circuit}/
68
- `../../artifacts/circuits/${circuitName}/${artifactType}`,
69
- // When in source: prover/ -> ../artifacts/circuits/{circuit}/
70
- `../artifacts/circuits/${circuitName}/${artifactType}`,
71
- ];
72
- }
73
-
74
- /**
75
- * Runtime detection utilities
76
- */
77
- export const Runtime = {
78
- /**
79
- * Check if running in browser environment
80
- */
81
- isBrowser(): boolean {
82
- return typeof window !== "undefined" && typeof document !== "undefined";
83
- },
84
-
85
- /**
86
- * Check if running in Node.js environment
87
- */
88
- isNode(): boolean {
89
- return (
90
- typeof process !== "undefined" &&
91
- process.versions != null &&
92
- process.versions.node != null
93
- );
94
- },
95
-
96
- /**
97
- * Get environment description for debugging
98
- */
99
- getEnvironment(): string {
100
- if (this.isBrowser()) return "browser";
101
- if (this.isNode()) return "node";
102
- return "unknown";
103
- },
104
- };
package/prover/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./prover.js";
@@ -1,162 +0,0 @@
1
- import { access } from "fs/promises";
2
- import { dirname, join } from "path";
3
- import { fileURLToPath } from "url";
4
- import * as snarkjs from "snarkjs";
5
- import { beforeAll, describe, expect, it } from "vitest";
6
-
7
- import {
8
- getVerificationKey,
9
- proveTransaction,
10
- type JoinsplitProofInput,
11
- } from "./prover.js";
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
15
-
16
- describe("prover integration tests", () => {
17
- beforeAll(async () => {
18
- // Check if artifacts exist for 2x3 circuit (used in integration tests)
19
- try {
20
- await access(
21
- join(
22
- __dirname,
23
- "../artifacts/circuits/joinsplit_2x3_16/joinsplit.wasm",
24
- ),
25
- );
26
- await access(
27
- join(
28
- __dirname,
29
- "../artifacts/circuits/joinsplit_2x3_16/joinsplit.zkey",
30
- ),
31
- );
32
- await access(
33
- join(
34
- __dirname,
35
- "../artifacts/circuits/joinsplit_2x3_16/joinsplit.vkey.json",
36
- ),
37
- );
38
- } catch (error) {
39
- throw new Error(
40
- "Circuit artifacts not found. Please run 'pnpm run circuits:build' first.",
41
- );
42
- }
43
- });
44
-
45
- it("generates and verifies a proof generated from circuits input data", async () => {
46
- const rawInput = {
47
- merkleRoot:
48
- "6651503891008261868318637545520517015441423030408583353730529205210575769897",
49
- boundParamsHash:
50
- "4367284183670237676694687139389936823583752501847632190787848034614846786866",
51
- nullifiers: [
52
- "11485370912550667629147418652010973429416469356401563507077544465653018582229",
53
- "12458947539527367086074368910577127304083837870968412606004383792911977699092",
54
- ],
55
- commitmentsOut: [
56
- "21220431320512498255211940241902464585964672736998306204392012684848332107713",
57
- "10812352772790655187825976376417683652931326614980053685809861928409318557101",
58
- "2361786391388492851501376027004057215483918983555223791892300314116572980398",
59
- ],
60
- token: "611382286831621467233887798921843936019654057231",
61
- publicKey: [
62
- "17403090114984634995691076088606286689905312870166298587771402004938333701956",
63
- "11686443728124206965533675395218715181279824020209406379329530395240161730269",
64
- ],
65
- signature: [
66
- "13337325824273672513648456655099758722924690095445255254284844332733013061113",
67
- "11478044465897161338488651611555416955979346707535934533682695529282557178771",
68
- "2690614056970046123325708657516589911150638516730022213521930951131599801259",
69
- ],
70
- randomIn: [
71
- "311410881652967579423188304066739460260",
72
- "161576146678088229090350665564580980145",
73
- ],
74
- valueIn: ["10000000000", "20000000000"],
75
- pathElements: [
76
- [
77
- "14943413005531767156170859665453505874291109952298492592265028467982121566535",
78
- "17140872132393658386372884137443465756166862794960926853080892710475197765189",
79
- "6371505487407425546372285321506278506957375353941268479986307401454583028710",
80
- "14682603619753984551536111997488330801501968646131197748838572499913532539651",
81
- "4177329909171803290170279196019319447087145475250139657920728261184066492383",
82
- "9144726083425293457189930182175584375755866170755203037168330473435257599943",
83
- "8236371367060628245320813572019740297071112030680295018688014025332724941914",
84
- "20704513355749821470300998799414731362245300238021178553122435057113528378476",
85
- "16736886623818773524263138779809916105169520362832964900272252437275369959388",
86
- "16415580715665869864634788741927065679186058985255106992778939765291984104497",
87
- "5715205213015845364387052206849889843188282449933545435544812025608946666822",
88
- "11013175031749877081979736330659999751637067247483574805902945041305483682579",
89
- "10708260192616993577686743465610377735773279483333447100671640147037242870779",
90
- "17708681376628530799996447981717676562184543188562031708516142906406141650368",
91
- "3967876508977884960877910167550068853181553556854105674925421366723704424223",
92
- "18077967785446169488603147322170139942753858441115263187838141084900323103797",
93
- ],
94
- [
95
- "17155689016641574060256511555039569894135211745581590863068780884287641639347",
96
- "17140872132393658386372884137443465756166862794960926853080892710475197765189",
97
- "6371505487407425546372285321506278506957375353941268479986307401454583028710",
98
- "14682603619753984551536111997488330801501968646131197748838572499913532539651",
99
- "4177329909171803290170279196019319447087145475250139657920728261184066492383",
100
- "9144726083425293457189930182175584375755866170755203037168330473435257599943",
101
- "8236371367060628245320813572019740297071112030680295018688014025332724941914",
102
- "20704513355749821470300998799414731362245300238021178553122435057113528378476",
103
- "16736886623818773524263138779809916105169520362832964900272252437275369959388",
104
- "16415580715665869864634788741927065679186058985255106992778939765291984104497",
105
- "5715205213015845364387052206849889843188282449933545435544812025608946666822",
106
- "11013175031749877081979736330659999751637067247483574805902945041305483682579",
107
- "10708260192616993577686743465610377735773279483333447100671640147037242870779",
108
- "17708681376628530799996447981717676562184543188562031708516142906406141650368",
109
- "3967876508977884960877910167550068853181553556854105674925421366723704424223",
110
- "18077967785446169488603147322170139942753858441115263187838141084900323103797",
111
- ],
112
- ],
113
- leavesIndices: [0, 1],
114
- nullifyingKey:
115
- "18659841675752504949640201002407906598138517454751630186524244551004513393000",
116
- npkOut: [
117
- "5969622909025228762817370697760280284869505282539549033240181049624056088653",
118
- "2100582032716223613287570049117084073292258181991442907862227237312284306360",
119
- "742175203644052806963513562623187657396500499529893903278346823527475860966",
120
- ],
121
- valueOut: ["10000000000", "10000000000", "10000000000"],
122
- };
123
-
124
- // Format circuit inputs (convert strings to bigints)
125
- // Using the exact field names the circuit expects
126
- const circuitInput: JoinsplitProofInput = {
127
- merkleRoot: BigInt(rawInput.merkleRoot),
128
- boundParamsHash: BigInt(rawInput.boundParamsHash),
129
- nullifiers: rawInput.nullifiers.map((n: string) => BigInt(n)),
130
- commitmentsOut: rawInput.commitmentsOut.map((c: string) => BigInt(c)),
131
- token: BigInt(rawInput.token),
132
- publicKey: rawInput.publicKey.map((pk: string) => BigInt(pk)),
133
- signature: rawInput.signature.map((s: string) => BigInt(s)),
134
- randomIn: rawInput.randomIn.map((r: string) => BigInt(r)),
135
- valueIn: rawInput.valueIn.map((v: string) => BigInt(v)),
136
- pathElements: rawInput.pathElements.map((pe: string[]) =>
137
- pe.map((e) => BigInt(e)),
138
- ),
139
- leavesIndices: rawInput.leavesIndices.map((i: number) => BigInt(i)),
140
- nullifyingKey: BigInt(rawInput.nullifyingKey),
141
- npkOut: rawInput.npkOut.map((npk: string) => BigInt(npk)),
142
- valueOut: rawInput.valueOut.map((v: string) => BigInt(v)),
143
- };
144
-
145
- // Generate proof using real circuit (automatically selects 2x3 based on input dimensions)
146
- const { proof, publicSignals } = await proveTransaction(circuitInput);
147
-
148
- // Verify the generated proof (2 inputs, 3 outputs)
149
- const vkey = await getVerificationKey(2, 3);
150
- const isValid = await snarkjs.groth16.verify(vkey, publicSignals, proof);
151
-
152
- // Assertions
153
- expect(isValid).toBe(true);
154
- expect(proof.protocol).toBe("groth16");
155
- expect(proof.curve).toBe("bn128");
156
- expect(publicSignals).toHaveLength(7); // Should match nPublic
157
-
158
- // Verify public signals match expected values from circuit
159
- expect(publicSignals[0]).toBe(rawInput.merkleRoot);
160
- expect(publicSignals[1]).toBe(rawInput.boundParamsHash);
161
- }, 30000); // Increase timeout as proof generation can take time
162
- });