@unlink-xyz/core 0.1.2 → 0.1.3-canary.0877bfe

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 (350) hide show
  1. package/dist/account/{zkAccount.d.ts → account.d.ts} +7 -5
  2. package/dist/account/account.d.ts.map +1 -0
  3. package/dist/account/{zkAccount.js → account.js} +57 -43
  4. package/dist/browser/index.js +108202 -0
  5. package/dist/browser/index.js.map +1 -0
  6. package/dist/circuits.json +74 -0
  7. package/dist/clients/broadcaster.d.ts +7 -2
  8. package/dist/clients/broadcaster.d.ts.map +1 -1
  9. package/dist/clients/broadcaster.js +9 -1
  10. package/dist/clients/http.d.ts +6 -0
  11. package/dist/clients/http.d.ts.map +1 -1
  12. package/dist/clients/http.js +24 -9
  13. package/dist/clients/indexer.d.ts +11 -0
  14. package/dist/clients/indexer.d.ts.map +1 -1
  15. package/dist/clients/indexer.js +40 -11
  16. package/dist/config.d.ts +28 -9
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js +33 -26
  19. package/dist/constants.d.ts +6 -0
  20. package/dist/constants.d.ts.map +1 -0
  21. package/dist/constants.js +5 -0
  22. package/dist/core.d.ts.map +1 -1
  23. package/dist/core.js +5 -2
  24. package/dist/crypto-adapters/auto-init.d.ts +2 -0
  25. package/dist/crypto-adapters/auto-init.d.ts.map +1 -0
  26. package/dist/crypto-adapters/auto-init.js +7 -0
  27. package/dist/crypto-adapters/index.d.ts +22 -0
  28. package/dist/crypto-adapters/index.d.ts.map +1 -0
  29. package/dist/crypto-adapters/index.js +47 -0
  30. package/dist/crypto-adapters/polyfills.d.ts +5 -0
  31. package/dist/crypto-adapters/polyfills.d.ts.map +1 -0
  32. package/dist/crypto-adapters/polyfills.js +8 -0
  33. package/dist/errors.d.ts +9 -0
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +18 -0
  36. package/dist/history/index.d.ts +3 -0
  37. package/dist/history/index.d.ts.map +1 -0
  38. package/dist/history/index.js +2 -0
  39. package/dist/history/service.d.ts +46 -0
  40. package/dist/history/service.d.ts.map +1 -0
  41. package/dist/history/service.js +354 -0
  42. package/dist/history/types.d.ts +21 -0
  43. package/dist/history/types.d.ts.map +1 -0
  44. package/dist/index.d.ts +12 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +11 -4
  47. package/dist/keys/address.d.ts +13 -0
  48. package/dist/keys/address.d.ts.map +1 -0
  49. package/dist/keys/address.js +55 -0
  50. package/dist/keys/derive.d.ts +37 -0
  51. package/dist/keys/derive.d.ts.map +1 -0
  52. package/dist/keys/derive.js +112 -0
  53. package/dist/keys/hex.d.ts +17 -0
  54. package/dist/keys/hex.d.ts.map +1 -0
  55. package/dist/keys/hex.js +66 -0
  56. package/dist/keys/index.d.ts +5 -0
  57. package/dist/keys/index.d.ts.map +1 -0
  58. package/dist/keys/index.js +4 -0
  59. package/dist/keys/mnemonic.d.ts +8 -0
  60. package/dist/keys/mnemonic.d.ts.map +1 -0
  61. package/dist/keys/mnemonic.js +23 -0
  62. package/dist/keys.d.ts +4 -1
  63. package/dist/keys.d.ts.map +1 -1
  64. package/dist/keys.js +4 -0
  65. package/dist/prover/config.d.ts +1 -15
  66. package/dist/prover/config.d.ts.map +1 -1
  67. package/dist/prover/config.js +1 -11
  68. package/dist/prover/prover.d.ts +15 -4
  69. package/dist/prover/prover.d.ts.map +1 -1
  70. package/dist/prover/prover.js +115 -98
  71. package/dist/prover/registry.d.ts +3 -30
  72. package/dist/prover/registry.d.ts.map +1 -1
  73. package/dist/prover/registry.js +12 -51
  74. package/dist/state/merkle/hydrator.d.ts.map +1 -1
  75. package/dist/state/merkle/hydrator.js +3 -2
  76. package/dist/state/merkle/index.d.ts +1 -1
  77. package/dist/state/merkle/index.d.ts.map +1 -1
  78. package/dist/state/merkle/index.js +1 -1
  79. package/dist/state/merkle/merkle-tree.d.ts +8 -0
  80. package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
  81. package/dist/state/merkle/merkle-tree.js +16 -7
  82. package/dist/state/store/ciphertext-store.d.ts +4 -0
  83. package/dist/state/store/ciphertext-store.d.ts.map +1 -1
  84. package/dist/state/store/ciphertext-store.js +12 -0
  85. package/dist/state/store/history-store.d.ts +24 -0
  86. package/dist/state/store/history-store.d.ts.map +1 -0
  87. package/dist/state/store/history-store.js +53 -0
  88. package/dist/state/store/index.d.ts +3 -2
  89. package/dist/state/store/index.d.ts.map +1 -1
  90. package/dist/state/store/index.js +1 -0
  91. package/dist/state/store/job-store.d.ts +7 -7
  92. package/dist/state/store/job-store.d.ts.map +1 -1
  93. package/dist/state/store/job-store.js +65 -39
  94. package/dist/state/store/jobs.d.ts +65 -18
  95. package/dist/state/store/jobs.d.ts.map +1 -1
  96. package/dist/state/store/leaf-store.d.ts.map +1 -1
  97. package/dist/state/store/leaf-store.js +0 -3
  98. package/dist/state/store/note-store.d.ts +7 -7
  99. package/dist/state/store/note-store.d.ts.map +1 -1
  100. package/dist/state/store/note-store.js +38 -34
  101. package/dist/state/store/nullifier-store.d.ts +9 -0
  102. package/dist/state/store/nullifier-store.d.ts.map +1 -1
  103. package/dist/state/store/nullifier-store.js +32 -2
  104. package/dist/state/store/records.d.ts +31 -2
  105. package/dist/state/store/records.d.ts.map +1 -1
  106. package/dist/state/store/root-store.d.ts.map +1 -1
  107. package/dist/state/store/root-store.js +0 -4
  108. package/dist/state/store/store.d.ts +61 -27
  109. package/dist/state/store/store.d.ts.map +1 -1
  110. package/dist/state/store/store.js +92 -1
  111. package/dist/storage/indexeddb.js +1 -1
  112. package/dist/storage/memory.d.ts.map +1 -1
  113. package/dist/storage/memory.js +5 -1
  114. package/dist/transactions/deposit.d.ts +12 -15
  115. package/dist/transactions/deposit.d.ts.map +1 -1
  116. package/dist/transactions/deposit.js +203 -152
  117. package/dist/transactions/index.d.ts +7 -4
  118. package/dist/transactions/index.d.ts.map +1 -1
  119. package/dist/transactions/index.js +7 -2
  120. package/dist/transactions/note-selection.d.ts +17 -0
  121. package/dist/transactions/note-selection.d.ts.map +1 -0
  122. package/dist/transactions/note-selection.js +201 -0
  123. package/dist/transactions/note-sync.d.ts +5 -33
  124. package/dist/transactions/note-sync.d.ts.map +1 -1
  125. package/dist/transactions/note-sync.js +320 -155
  126. package/dist/transactions/reconcile.d.ts +10 -12
  127. package/dist/transactions/reconcile.d.ts.map +1 -1
  128. package/dist/transactions/reconcile.js +53 -7
  129. package/dist/transactions/transact.d.ts +13 -24
  130. package/dist/transactions/transact.d.ts.map +1 -1
  131. package/dist/transactions/transact.js +393 -507
  132. package/dist/transactions/transaction-planner.d.ts +34 -0
  133. package/dist/transactions/transaction-planner.d.ts.map +1 -0
  134. package/dist/transactions/transaction-planner.js +116 -0
  135. package/dist/transactions/transfer-planner.d.ts +36 -0
  136. package/dist/transactions/transfer-planner.d.ts.map +1 -0
  137. package/dist/transactions/transfer-planner.js +85 -0
  138. package/dist/transactions/types/deposit.d.ts +67 -0
  139. package/dist/transactions/types/deposit.d.ts.map +1 -0
  140. package/dist/transactions/types/domain.d.ts +67 -0
  141. package/dist/transactions/types/domain.d.ts.map +1 -0
  142. package/dist/transactions/types/domain.js +4 -0
  143. package/dist/transactions/types/index.d.ts +18 -0
  144. package/dist/transactions/types/index.d.ts.map +1 -0
  145. package/dist/transactions/types/index.js +17 -0
  146. package/dist/transactions/types/options.d.ts +45 -0
  147. package/dist/transactions/types/options.d.ts.map +1 -0
  148. package/dist/transactions/types/options.js +1 -0
  149. package/dist/transactions/types/planning.d.ts +80 -0
  150. package/dist/transactions/types/planning.d.ts.map +1 -0
  151. package/dist/transactions/types/planning.js +1 -0
  152. package/dist/transactions/types/state-stores.d.ts +103 -0
  153. package/dist/transactions/types/state-stores.d.ts.map +1 -0
  154. package/dist/transactions/types/state-stores.js +1 -0
  155. package/dist/transactions/types/transact.d.ts +76 -0
  156. package/dist/transactions/types/transact.d.ts.map +1 -0
  157. package/dist/transactions/types/transact.js +1 -0
  158. package/dist/transactions/withdrawal-planner.d.ts +58 -0
  159. package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
  160. package/dist/transactions/withdrawal-planner.js +128 -0
  161. package/dist/tsconfig.tsbuildinfo +1 -1
  162. package/dist/tsup.browser.config.d.ts +7 -0
  163. package/dist/tsup.browser.config.d.ts.map +1 -0
  164. package/dist/tsup.browser.config.js +34 -0
  165. package/dist/utils/amounts.d.ts +39 -0
  166. package/dist/utils/amounts.d.ts.map +1 -0
  167. package/dist/utils/amounts.js +89 -0
  168. package/dist/utils/async.d.ts +9 -0
  169. package/dist/utils/async.d.ts.map +1 -1
  170. package/dist/utils/async.js +24 -0
  171. package/dist/utils/bigint.js +7 -7
  172. package/dist/utils/crypto.d.ts +11 -5
  173. package/dist/utils/crypto.d.ts.map +1 -1
  174. package/dist/utils/crypto.js +12 -6
  175. package/dist/utils/format.d.ts +25 -0
  176. package/dist/utils/format.d.ts.map +1 -0
  177. package/dist/utils/format.js +33 -0
  178. package/dist/utils/json-codec.js +1 -1
  179. package/dist/utils/notes.d.ts +15 -0
  180. package/dist/utils/notes.d.ts.map +1 -0
  181. package/dist/utils/notes.js +14 -0
  182. package/dist/utils/polling.d.ts +5 -0
  183. package/dist/utils/polling.d.ts.map +1 -1
  184. package/dist/utils/polling.js +5 -0
  185. package/dist/utils/random.d.ts +13 -0
  186. package/dist/utils/random.d.ts.map +1 -0
  187. package/dist/utils/random.js +27 -0
  188. package/dist/utils/secure-memory.d.ts +25 -0
  189. package/dist/utils/secure-memory.d.ts.map +1 -0
  190. package/dist/utils/secure-memory.js +28 -0
  191. package/dist/utils/signature.d.ts +6 -0
  192. package/dist/utils/signature.d.ts.map +1 -1
  193. package/dist/utils/signature.js +8 -6
  194. package/dist/utils/validators.d.ts +21 -10
  195. package/dist/utils/validators.d.ts.map +1 -1
  196. package/dist/utils/validators.js +37 -11
  197. package/dist/vitest.config.d.ts +3 -0
  198. package/dist/vitest.config.d.ts.map +1 -0
  199. package/dist/vitest.config.js +13 -0
  200. package/package.json +28 -11
  201. package/.eslintrc.json +0 -4
  202. package/account/zkAccount.test.ts +0 -316
  203. package/account/zkAccount.ts +0 -222
  204. package/clients/broadcaster.ts +0 -67
  205. package/clients/http.ts +0 -94
  206. package/clients/indexer.ts +0 -150
  207. package/config.ts +0 -39
  208. package/core.ts +0 -17
  209. package/dist/account/railgun-imports-prototype.d.ts +0 -12
  210. package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
  211. package/dist/account/railgun-imports-prototype.js +0 -30
  212. package/dist/account/zkAccount.d.ts.map +0 -1
  213. package/dist/key-derivation/babyjubjub.d.ts +0 -9
  214. package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
  215. package/dist/key-derivation/babyjubjub.js +0 -9
  216. package/dist/key-derivation/bech32.d.ts +0 -22
  217. package/dist/key-derivation/bech32.d.ts.map +0 -1
  218. package/dist/key-derivation/bech32.js +0 -86
  219. package/dist/key-derivation/bip32.d.ts +0 -17
  220. package/dist/key-derivation/bip32.d.ts.map +0 -1
  221. package/dist/key-derivation/bip32.js +0 -41
  222. package/dist/key-derivation/bip39.d.ts +0 -22
  223. package/dist/key-derivation/bip39.d.ts.map +0 -1
  224. package/dist/key-derivation/bip39.js +0 -56
  225. package/dist/key-derivation/bytes.d.ts +0 -19
  226. package/dist/key-derivation/bytes.d.ts.map +0 -1
  227. package/dist/key-derivation/bytes.js +0 -92
  228. package/dist/key-derivation/hash.d.ts +0 -3
  229. package/dist/key-derivation/hash.d.ts.map +0 -1
  230. package/dist/key-derivation/hash.js +0 -10
  231. package/dist/key-derivation/index.d.ts +0 -8
  232. package/dist/key-derivation/index.d.ts.map +0 -1
  233. package/dist/key-derivation/index.js +0 -7
  234. package/dist/key-derivation/wallet-node.d.ts +0 -45
  235. package/dist/key-derivation/wallet-node.d.ts.map +0 -1
  236. package/dist/key-derivation/wallet-node.js +0 -109
  237. package/dist/state/ciphertext-store.d.ts +0 -12
  238. package/dist/state/ciphertext-store.d.ts.map +0 -1
  239. package/dist/state/ciphertext-store.js +0 -25
  240. package/dist/state/hydrator.d.ts +0 -16
  241. package/dist/state/hydrator.d.ts.map +0 -1
  242. package/dist/state/hydrator.js +0 -18
  243. package/dist/state/job-store.d.ts +0 -12
  244. package/dist/state/job-store.d.ts.map +0 -1
  245. package/dist/state/job-store.js +0 -118
  246. package/dist/state/jobs.d.ts +0 -50
  247. package/dist/state/jobs.d.ts.map +0 -1
  248. package/dist/state/jobs.js +0 -1
  249. package/dist/state/leaf-store.d.ts +0 -17
  250. package/dist/state/leaf-store.d.ts.map +0 -1
  251. package/dist/state/leaf-store.js +0 -35
  252. package/dist/state/merkle-tree.d.ts +0 -34
  253. package/dist/state/merkle-tree.d.ts.map +0 -1
  254. package/dist/state/merkle-tree.js +0 -104
  255. package/dist/state/note-store.d.ts +0 -37
  256. package/dist/state/note-store.d.ts.map +0 -1
  257. package/dist/state/note-store.js +0 -133
  258. package/dist/state/nullifier-store.d.ts +0 -13
  259. package/dist/state/nullifier-store.d.ts.map +0 -1
  260. package/dist/state/nullifier-store.js +0 -21
  261. package/dist/state/records.d.ts +0 -57
  262. package/dist/state/records.d.ts.map +0 -1
  263. package/dist/state/root-store.d.ts +0 -13
  264. package/dist/state/root-store.d.ts.map +0 -1
  265. package/dist/state/root-store.js +0 -30
  266. package/dist/state/store.d.ts +0 -26
  267. package/dist/state/store.d.ts.map +0 -1
  268. package/dist/state/store.js +0 -19
  269. package/dist/state.d.ts +0 -83
  270. package/dist/state.d.ts.map +0 -1
  271. package/dist/state.js +0 -171
  272. package/dist/transactions/shield.d.ts +0 -5
  273. package/dist/transactions/shield.d.ts.map +0 -1
  274. package/dist/transactions/shield.js +0 -93
  275. package/dist/transactions/types.d.ts +0 -114
  276. package/dist/transactions/types.d.ts.map +0 -1
  277. package/dist/transactions/utils.d.ts +0 -10
  278. package/dist/transactions/utils.d.ts.map +0 -1
  279. package/dist/transactions/utils.js +0 -17
  280. package/dist/utils/time.d.ts +0 -2
  281. package/dist/utils/time.d.ts.map +0 -1
  282. package/dist/utils/time.js +0 -3
  283. package/dist/utils/witness.d.ts +0 -11
  284. package/dist/utils/witness.d.ts.map +0 -1
  285. package/dist/utils/witness.js +0 -19
  286. package/errors.ts +0 -20
  287. package/index.ts +0 -17
  288. package/key-derivation/babyjubjub.ts +0 -11
  289. package/key-derivation/bech32.test.ts +0 -90
  290. package/key-derivation/bech32.ts +0 -124
  291. package/key-derivation/bip32.ts +0 -56
  292. package/key-derivation/bip39.ts +0 -76
  293. package/key-derivation/bytes.ts +0 -118
  294. package/key-derivation/hash.ts +0 -13
  295. package/key-derivation/index.ts +0 -7
  296. package/key-derivation/wallet-node.ts +0 -155
  297. package/keys.ts +0 -47
  298. package/prover/config.ts +0 -104
  299. package/prover/index.ts +0 -1
  300. package/prover/prover.integration.test.ts +0 -162
  301. package/prover/prover.test.ts +0 -309
  302. package/prover/prover.ts +0 -405
  303. package/prover/registry.test.ts +0 -90
  304. package/prover/registry.ts +0 -82
  305. package/schema.ts +0 -17
  306. package/setup-artifacts.sh +0 -57
  307. package/state/index.ts +0 -2
  308. package/state/merkle/hydrator.ts +0 -69
  309. package/state/merkle/index.ts +0 -12
  310. package/state/merkle/merkle-tree.test.ts +0 -50
  311. package/state/merkle/merkle-tree.ts +0 -163
  312. package/state/store/ciphertext-store.ts +0 -28
  313. package/state/store/index.ts +0 -24
  314. package/state/store/job-store.ts +0 -162
  315. package/state/store/jobs.ts +0 -64
  316. package/state/store/leaf-store.ts +0 -39
  317. package/state/store/note-store.ts +0 -177
  318. package/state/store/nullifier-store.ts +0 -39
  319. package/state/store/records.ts +0 -61
  320. package/state/store/root-store.ts +0 -34
  321. package/state/store/store.ts +0 -25
  322. package/state.test.ts +0 -235
  323. package/storage/index.ts +0 -3
  324. package/storage/indexeddb.test.ts +0 -99
  325. package/storage/indexeddb.ts +0 -235
  326. package/storage/memory.test.ts +0 -59
  327. package/storage/memory.ts +0 -93
  328. package/transactions/deposit.test.ts +0 -160
  329. package/transactions/deposit.ts +0 -227
  330. package/transactions/index.ts +0 -20
  331. package/transactions/note-sync.test.ts +0 -155
  332. package/transactions/note-sync.ts +0 -452
  333. package/transactions/reconcile.ts +0 -73
  334. package/transactions/transact.test.ts +0 -451
  335. package/transactions/transact.ts +0 -811
  336. package/transactions/types.ts +0 -141
  337. package/tsconfig.json +0 -14
  338. package/types/global.d.ts +0 -15
  339. package/types.ts +0 -24
  340. package/utils/async.ts +0 -15
  341. package/utils/bigint.ts +0 -34
  342. package/utils/crypto.test.ts +0 -69
  343. package/utils/crypto.ts +0 -58
  344. package/utils/json-codec.ts +0 -38
  345. package/utils/polling.ts +0 -6
  346. package/utils/signature.ts +0 -16
  347. package/utils/validators.test.ts +0 -64
  348. package/utils/validators.ts +0 -86
  349. /package/dist/{transactions → history}/types.js +0 -0
  350. /package/dist/{state/records.js → transactions/types/deposit.js} +0 -0
@@ -0,0 +1,74 @@
1
+ {
2
+ "joinsplit_1x1_16": {
3
+ "file": "joinsplit",
4
+ "template": "JoinSplit",
5
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
6
+ "params": [1, 1, 16]
7
+ },
8
+ "joinsplit_1x2_16": {
9
+ "file": "joinsplit",
10
+ "template": "JoinSplit",
11
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
12
+ "params": [1, 2, 16]
13
+ },
14
+ "joinsplit_2x1_16": {
15
+ "file": "joinsplit",
16
+ "template": "JoinSplit",
17
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
18
+ "params": [2, 1, 16]
19
+ },
20
+ "joinsplit_2x2_16": {
21
+ "file": "joinsplit",
22
+ "template": "JoinSplit",
23
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
24
+ "params": [2, 2, 16]
25
+ },
26
+ "joinsplit_2x3_16": {
27
+ "file": "joinsplit",
28
+ "template": "JoinSplit",
29
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
30
+ "params": [2, 3, 16]
31
+ },
32
+ "joinsplit_3x1_16": {
33
+ "file": "joinsplit",
34
+ "template": "JoinSplit",
35
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
36
+ "params": [3, 1, 16]
37
+ },
38
+ "joinsplit_3x2_16": {
39
+ "file": "joinsplit",
40
+ "template": "JoinSplit",
41
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
42
+ "params": [3, 2, 16]
43
+ },
44
+ "joinsplit_3x3_16": {
45
+ "file": "joinsplit",
46
+ "template": "JoinSplit",
47
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
48
+ "params": [3, 3, 16]
49
+ },
50
+ "joinsplit_4x1_16": {
51
+ "file": "joinsplit",
52
+ "template": "JoinSplit",
53
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
54
+ "params": [4, 1, 16]
55
+ },
56
+ "joinsplit_4x2_16": {
57
+ "file": "joinsplit",
58
+ "template": "JoinSplit",
59
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
60
+ "params": [4, 2, 16]
61
+ },
62
+ "joinsplit_5x1_16": {
63
+ "file": "joinsplit",
64
+ "template": "JoinSplit",
65
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
66
+ "params": [5, 1, 16]
67
+ },
68
+ "joinsplit_5x2_16": {
69
+ "file": "joinsplit",
70
+ "template": "JoinSplit",
71
+ "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
72
+ "params": [5, 2, 16]
73
+ }
74
+ }
@@ -14,12 +14,17 @@ export type SubmitRelayResponse = {
14
14
  accepted: boolean;
15
15
  message?: string | null;
16
16
  };
17
- export type RelayState = "pending" | "broadcasting" | "succeeded" | "failed" | "dead";
17
+ export type RelayState = "pending" | "broadcasting" | "submitted" | "succeeded" | "reverted" | "failed" | "dead";
18
+ export type TransactionReceipt = {
19
+ blockNumber?: number;
20
+ blockHash?: string;
21
+ transactionIndex?: number;
22
+ };
18
23
  export type RelayStatusResponse = {
19
24
  id: string;
20
25
  state: RelayState;
21
26
  txHash?: string | null;
22
- receipt?: unknown;
27
+ receipt?: TransactionReceipt | null;
23
28
  error?: string | null;
24
29
  };
25
30
  type BroadcasterClientDeps = {
@@ -1 +1 @@
1
- {"version":3,"file":"broadcaster.d.ts","sourceRoot":"","sources":["../../clients/broadcaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,cAAc,GACd,WAAW,GACX,QAAQ,GACR,MAAM,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,qBAAq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f,IAAI,EAAE,qBAAqB;wBAKC,iBAAiB;4BAYb,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;EAetE"}
@@ -14,10 +14,18 @@ export function createBroadcasterClient(baseUrl, deps) {
14
14
  });
15
15
  },
16
16
  async getRelayStatus(relayId) {
17
- return http.request({
17
+ const raw = await http.request({
18
18
  method: "GET",
19
19
  path: `/relays/${relayId}`,
20
20
  });
21
+ // Transform snake_case to camelCase for consistency
22
+ return {
23
+ id: raw.id,
24
+ state: raw.state,
25
+ txHash: raw.tx_hash,
26
+ receipt: raw.receipt,
27
+ error: raw.error,
28
+ };
21
29
  },
22
30
  };
23
31
  }
@@ -1,4 +1,10 @@
1
1
  export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
2
+ /**
3
+ * Resolve fetch implementation from options or global.
4
+ * @param providedFetch - Optional fetch implementation
5
+ * @returns Fetch function or undefined if not available
6
+ */
7
+ export declare function resolveFetch(providedFetch?: FetchLike): typeof fetch | undefined;
2
8
  export type JsonHttpDeps = {
3
9
  fetch: FetchLike;
4
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../clients/http.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IAC9D,IAAI,CAAC,EAAE,OA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,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAClD,CAAC;AAEF,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAK3D;AAWD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,GACjB,cAAc,CAqDhB"}
@@ -1,4 +1,13 @@
1
- import ky, { HTTPError, TimeoutError } from "ky";
1
+ import ky, { TimeoutError } from "ky";
2
+ import { InitializationError } from "../errors.js";
3
+ /**
4
+ * Resolve fetch implementation from options or global.
5
+ * @param providedFetch - Optional fetch implementation
6
+ * @returns Fetch function or undefined if not available
7
+ */
8
+ export function resolveFetch(providedFetch) {
9
+ return providedFetch ?? (typeof fetch === "function" ? fetch : undefined);
10
+ }
2
11
  export class HttpError extends Error {
3
12
  status;
4
13
  body;
@@ -19,20 +28,24 @@ async function readErrorBodySafe(res) {
19
28
  }
20
29
  export function createJsonHttpClient(baseUrl, deps) {
21
30
  if (!baseUrl)
22
- throw new Error("baseUrl is required");
31
+ throw new InitializationError("baseUrl is required");
23
32
  if (!deps?.fetch)
24
- throw new Error("deps.fetch is required");
33
+ throw new InitializationError("deps.fetch is required");
25
34
  // Ensure `fetch` is invoked with a global `this` to avoid "Illegal invocation"
26
35
  // errors in some browser environments when the function is extracted. // TODO: can we fix this in another way?
27
36
  const fetchImpl = (...args) => deps.fetch.apply(globalThis, args);
28
37
  const api = ky.create({
29
38
  prefixUrl: baseUrl.replace(/\/+$/, ""),
30
39
  fetch: fetchImpl,
40
+ // Disable ky's automatic error throwing to prevent browser DevTools
41
+ // from logging expected 404s as network errors
42
+ throwHttpErrors: false,
31
43
  });
32
44
  return {
33
45
  async request(opts) {
46
+ let res;
34
47
  try {
35
- const res = api(opts.path.replace(/^\//, ""), {
48
+ res = await api(opts.path.replace(/^\//, ""), {
36
49
  method: opts.method,
37
50
  searchParams: opts.query,
38
51
  json: opts.json,
@@ -40,18 +53,20 @@ export function createJsonHttpClient(baseUrl, deps) {
40
53
  headers: opts.headers,
41
54
  signal: opts.signal,
42
55
  });
43
- return await res.json();
44
56
  }
45
57
  catch (err) {
46
- if (err instanceof HTTPError) {
47
- const body = await readErrorBodySafe(err.response);
48
- throw new HttpError(`HTTP ${err.response.status} ${err.response.statusText}`.trim(), err.response.status, body);
49
- }
58
+ // Only network-level errors reach here (timeout, connection refused, etc.)
50
59
  if (err instanceof TimeoutError) {
51
60
  throw new HttpError("HTTP timeout", 408, null);
52
61
  }
53
62
  throw new HttpError(err instanceof Error ? err.message : "Network error", 0, null);
54
63
  }
64
+ // HTTP status errors handled outside try-catch - no redundant catch/rethrow
65
+ if (!res.ok) {
66
+ const body = await readErrorBodySafe(res);
67
+ throw new HttpError(`HTTP ${res.status} ${res.statusText}`.trim(), res.status, body);
68
+ }
69
+ return (await res.json());
55
70
  },
56
71
  };
57
72
  }
@@ -6,6 +6,7 @@ export type CommitmentRecord = {
6
6
  root: string;
7
7
  txHash: string;
8
8
  insertedAt: number;
9
+ eventType: string;
9
10
  };
10
11
  export type IndexerNullifierRecord = {
11
12
  nullifier: string;
@@ -31,13 +32,23 @@ export type GetNullifierParams = {
31
32
  chainId: number;
32
33
  nullifier: string;
33
34
  };
35
+ export type CheckNullifiersParams = {
36
+ chainId: number;
37
+ nullifiers: string[];
38
+ };
34
39
  type IndexerClientDeps = {
35
40
  fetch: FetchLike;
36
41
  };
37
42
  export declare function createIndexerClient(baseUrl: string, deps: IndexerClientDeps): {
38
43
  fetchCommitmentBatch(params: FetchCommitmentsParams): Promise<CommitmentBatchResponse>;
39
44
  getCommitment(params: GetCommitmentParams): Promise<CommitmentRecord>;
45
+ /**
46
+ * Like getCommitment but returns null when the commitment doesn't exist.
47
+ * Used for polling pending deposits without generating console errors.
48
+ */
49
+ tryGetCommitment(params: GetCommitmentParams): Promise<CommitmentRecord | null>;
40
50
  getNullifier(params: GetNullifierParams): Promise<IndexerNullifierRecord | null>;
51
+ checkNullifiers(params: CheckNullifiersParams): Promise<IndexerNullifierRecord[]>;
41
52
  getNullifierCount(chainId: number): Promise<number>;
42
53
  };
43
54
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../clients/indexer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAe3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AASF,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAQF,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CA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W,EAAE,gBAAgB,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAWF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB;iCA0B9D,sBAAsB,GAC7B,OAAO,CAAC,uBAAuB,CAAC;0BAgBzB,mBAAmB,GAC1B,OAAO,CAAC,gBAAgB,CAAC;IAU5B;;;OAGG;6BAEO,mBAAmB,GAC1B,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;yBAQzB,kBAAkB,GACzB,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC;4BAQ/B,qBAAqB,GAC5B,OAAO,CAAC,sBAAsB,EAAE,CAAC;+BAwBH,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;EAQ5D"}
@@ -1,5 +1,4 @@
1
- import { createJsonHttpClient } from "./http.js";
2
- import { isNotFoundError } from "../utils/async.js";
1
+ import { createJsonHttpClient, HttpError } from "./http.js";
3
2
  export function createIndexerClient(baseUrl, deps) {
4
3
  const http = createJsonHttpClient(baseUrl, deps);
5
4
  // Converts the snake_case record from the REST API into the camelCase shape
@@ -11,6 +10,7 @@ export function createIndexerClient(baseUrl, deps) {
11
10
  root: record.root,
12
11
  txHash: record.tx_hash,
13
12
  insertedAt: record.inserted_at,
13
+ eventType: record.event_type ?? "unknown",
14
14
  });
15
15
  const normalizeNullifierRecord = (record) => ({
16
16
  nullifier: record.nullifier,
@@ -39,22 +39,51 @@ export function createIndexerClient(baseUrl, deps) {
39
39
  method: "GET",
40
40
  path: `/chains/${params.chainId}/commitments/${params.commitment}`,
41
41
  });
42
+ if (!raw) {
43
+ throw new HttpError("commitment not found", 404, null);
44
+ }
42
45
  return normalizeRecord(raw);
43
46
  },
47
+ /**
48
+ * Like getCommitment but returns null when the commitment doesn't exist.
49
+ * Used for polling pending deposits without generating console errors.
50
+ */
51
+ async tryGetCommitment(params) {
52
+ const raw = await http.request({
53
+ method: "GET",
54
+ path: `/chains/${params.chainId}/commitments/${params.commitment}`,
55
+ });
56
+ return raw ? normalizeRecord(raw) : null;
57
+ },
44
58
  async getNullifier(params) {
45
- try {
59
+ const raw = await http.request({
60
+ method: "GET",
61
+ path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
62
+ });
63
+ return raw ? normalizeNullifierRecord(raw) : null;
64
+ },
65
+ async checkNullifiers(params) {
66
+ const CHUNK_SIZE = 1000;
67
+ if (params.nullifiers.length <= CHUNK_SIZE) {
46
68
  const raw = await http.request({
47
- method: "GET",
48
- path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
69
+ method: "POST",
70
+ path: `/chains/${params.chainId}/nullifiers/check`,
71
+ json: { nullifiers: params.nullifiers },
49
72
  });
50
- return normalizeNullifierRecord(raw);
73
+ return raw.found.map(normalizeNullifierRecord);
51
74
  }
52
- catch (err) {
53
- if (isNotFoundError(err)) {
54
- return null; // Nullifier not spent on-chain
55
- }
56
- throw err;
75
+ // Chunk into batches of 1000, run sequentially to avoid overwhelming server
76
+ const results = [];
77
+ for (let i = 0; i < params.nullifiers.length; i += CHUNK_SIZE) {
78
+ const chunk = params.nullifiers.slice(i, i + CHUNK_SIZE);
79
+ const raw = await http.request({
80
+ method: "POST",
81
+ path: `/chains/${params.chainId}/nullifiers/check`,
82
+ json: { nullifiers: chunk },
83
+ });
84
+ results.push(...raw.found.map(normalizeNullifierRecord));
57
85
  }
86
+ return results;
58
87
  },
59
88
  async getNullifierCount(chainId) {
60
89
  const raw = await http.request({
package/dist/config.d.ts CHANGED
@@ -1,12 +1,31 @@
1
- export declare const serviceConfig: {
2
- /**
3
- * Base URL for the Broadcaster HTTP API (default: http://localhost:8081).
4
- */
1
+ export type Environment = "mainnet" | "testnet" | "local";
2
+ /**
3
+ * Configuration for a specific environment.
4
+ */
5
+ export interface EnvironmentConfig {
6
+ rpcUrl: string;
7
+ poolAddress: string;
8
+ }
9
+ /**
10
+ * Service configuration with broadcaster and indexer URLs.
11
+ */
12
+ export interface ServiceConfig {
5
13
  broadcasterBaseUrl: string;
6
- /**
7
- * Base URL for the Indexer HTTP API (default: http://localhost:8082).
8
- */
9
14
  indexerBaseUrl: string;
10
- };
11
- export type ServiceConfig = typeof serviceConfig;
15
+ }
16
+ /**
17
+ * Fetch environment configuration from the hosted config file.
18
+ *
19
+ * @param env - The environment to fetch config for
20
+ * @returns Promise resolving to the environment configuration
21
+ * @throws If fetch fails or environment is not found
22
+ */
23
+ export declare function fetchEnvironmentConfig(env: Environment): Promise<EnvironmentConfig>;
24
+ /**
25
+ * Create service configuration from an RPC URL.
26
+ *
27
+ * @param rpcUrl - The base RPC URL
28
+ * @returns Service configuration with broadcaster and indexer URLs
29
+ */
30
+ export declare function createServiceConfig(rpcUrl: string): ServiceConfig;
12
31
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,aAAa;IACxB;;OAEG;;IAGH;;OAEG;;CAGJ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB;AAKD;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,iBAAiB,CAAC,CAU5B;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAMjE"}
package/dist/config.js CHANGED
@@ -1,29 +1,36 @@
1
- const DEFAULT_RPC_URL = "http://localhost:3000";
2
- function readEnv(key) {
3
- if (typeof process !== "undefined" && process?.env) {
4
- return process.env[key];
1
+ /**
2
+ * Environment types for SDK configuration.
3
+ */
4
+ import { InitializationError } from "./errors.js";
5
+ const CONFIG_URL = "https://raw.githubusercontent.com/unlink-xyz/config/main/environments.json";
6
+ /**
7
+ * Fetch environment configuration from the hosted config file.
8
+ *
9
+ * @param env - The environment to fetch config for
10
+ * @returns Promise resolving to the environment configuration
11
+ * @throws If fetch fails or environment is not found
12
+ */
13
+ export async function fetchEnvironmentConfig(env) {
14
+ const res = await fetch(CONFIG_URL);
15
+ if (!res.ok) {
16
+ throw new InitializationError(`Failed to fetch SDK config: ${res.status}`);
5
17
  }
6
- // Support environments where process isn't defined but a shim sets globalThis.process
7
- const globalProcess = globalThis.process;
8
- return globalProcess?.env?.[key];
9
- }
10
- function readServiceUrl(envKey, fallback) {
11
- const raw = readEnv(envKey);
12
- if (!raw)
13
- return fallback;
14
- const trimmed = raw.trim();
15
- if (!trimmed) {
16
- throw new Error(`${envKey} must not be empty when set`);
18
+ const config = (await res.json());
19
+ if (!config[env]) {
20
+ throw new InitializationError(`Unknown environment: ${env}`);
17
21
  }
18
- return trimmed.replace(/\/+$/, "");
22
+ return config[env];
23
+ }
24
+ /**
25
+ * Create service configuration from an RPC URL.
26
+ *
27
+ * @param rpcUrl - The base RPC URL
28
+ * @returns Service configuration with broadcaster and indexer URLs
29
+ */
30
+ export function createServiceConfig(rpcUrl) {
31
+ const baseUrl = rpcUrl.replace(/\/+$/, "");
32
+ return {
33
+ broadcasterBaseUrl: baseUrl + "/broadcaster",
34
+ indexerBaseUrl: baseUrl + "/indexer",
35
+ };
19
36
  }
20
- export const serviceConfig = {
21
- /**
22
- * Base URL for the Broadcaster HTTP API (default: http://localhost:8081).
23
- */
24
- broadcasterBaseUrl: readServiceUrl("UNLINK_RPC_URL", DEFAULT_RPC_URL) + "/broadcaster",
25
- /**
26
- * Base URL for the Indexer HTTP API (default: http://localhost:8082).
27
- */
28
- indexerBaseUrl: readServiceUrl("UNLINK_RPC_URL", DEFAULT_RPC_URL) + "/indexer",
29
- };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sentinel address for native ETH, matching the Solidity Constants.ETH_TOKEN.
3
+ * Used as the token address in notes to indicate a native ETH deposit/withdrawal.
4
+ */
5
+ export declare const ETH_TOKEN = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,SAAS,+CAA+C,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Sentinel address for native ETH, matching the Solidity Constants.ETH_TOKEN.
3
+ * Used as the token address in notes to indicate a native ETH deposit/withdrawal.
4
+ */
5
+ export const ETH_TOKEN = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,UAAU,CAAC;CAChC,CAAC;AAEF,wBAAsB,QAAQ,CAAC,IAAI,EAAE,QAAQ;;aAHlC,MAAM,KAAK,UAAU;GAW/B"}
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../core.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,UAAU,CAAC;CAChC,CAAC;AAEF,wBAAsB,QAAQ,CAAC,IAAI,EAAE,QAAQ;;aAHlC,MAAM,KAAK,UAAU;GAa/B"}
package/dist/core.js CHANGED
@@ -1,9 +1,12 @@
1
+ import { initCrypto } from "./crypto-adapters/index.js";
2
+ import { InitializationError } from "./errors.js";
1
3
  import { migrate } from "./schema.js";
2
4
  export async function initCore(deps) {
3
5
  if (!deps?.storage)
4
- throw new Error("storage dep required");
6
+ throw new InitializationError("storage dep required");
5
7
  if (!deps?.rng)
6
- throw new Error("rng dep required");
8
+ throw new InitializationError("rng dep required");
9
+ await initCrypto();
7
10
  await migrate(deps.storage);
8
11
  return {
9
12
  storage: deps.storage,
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auto-init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-init.d.ts","sourceRoot":"","sources":["../../crypto-adapters/auto-init.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Auto-initialization module for tests.
3
+ * Import this at the top of test files to automatically initialize crypto, not in production code.
4
+ */
5
+ import { initCrypto } from "./index.js";
6
+ await initCrypto();
7
+ console.log("[crypto] Auto-initialized for tests");
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Crypto adapters for browser-compatible cryptographic operations.
3
+ *
4
+ * Exports:
5
+ * - poseidon: Poseidon hash from circomlibjs (iden3)
6
+ * - deriveSpendingPublicKey, signMessage, verifySignature: EdDSA from @zk-kit/eddsa-poseidon
7
+ * - initCrypto: Async function to initialize crypto primitives (must be called before using poseidon)
8
+ */
9
+ import "./polyfills.js";
10
+ /**
11
+ * Initialize the crypto primitives (Poseidon hash function).
12
+ * This must be called before using the poseidon function.
13
+ * Safe to call multiple times - subsequent calls return the same promise.
14
+ */
15
+ export declare function initCrypto(): Promise<void>;
16
+ /**
17
+ * Poseidon hash function compatible with circomlib circuits.
18
+ * Wraps circomlibjs buildPoseidon to return bigint directly.
19
+ */
20
+ export declare const poseidon: (inputs: (bigint | number)[]) => bigint;
21
+ export { derivePublicKey as deriveSpendingPublicKey, signMessage, verifySignature, } from "@zk-kit/eddsa-poseidon";
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../crypto-adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,gBAAgB,CAAC;AAWxB;;;;GAIG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAehD;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAG,MAQtD,CAAC;AAEF,OAAO,EACL,eAAe,IAAI,uBAAuB,EAC1C,WAAW,EACX,eAAe,GAChB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Crypto adapters for browser-compatible cryptographic operations.
3
+ *
4
+ * Exports:
5
+ * - poseidon: Poseidon hash from circomlibjs (iden3)
6
+ * - deriveSpendingPublicKey, signMessage, verifySignature: EdDSA from @zk-kit/eddsa-poseidon
7
+ * - initCrypto: Async function to initialize crypto primitives (must be called before using poseidon)
8
+ */
9
+ // Polyfill must be the first import
10
+ import "./polyfills.js";
11
+ import { InitializationError } from "../errors.js";
12
+ let _poseidon = null;
13
+ let _initPromise = null;
14
+ /**
15
+ * Initialize the crypto primitives (Poseidon hash function).
16
+ * This must be called before using the poseidon function.
17
+ * Safe to call multiple times - subsequent calls return the same promise.
18
+ */
19
+ export async function initCrypto() {
20
+ if (_poseidon)
21
+ return; // Already initialized
22
+ if (_initPromise)
23
+ return _initPromise; // Initialization in progress
24
+ _initPromise = (async () => {
25
+ try {
26
+ const { buildPoseidon } = await import("circomlibjs");
27
+ _poseidon = await buildPoseidon();
28
+ }
29
+ catch (error) {
30
+ _initPromise = null; // Reset to allow retry
31
+ throw error;
32
+ }
33
+ })();
34
+ return _initPromise;
35
+ }
36
+ /**
37
+ * Poseidon hash function compatible with circomlib circuits.
38
+ * Wraps circomlibjs buildPoseidon to return bigint directly.
39
+ */
40
+ export const poseidon = (inputs) => {
41
+ if (!_poseidon) {
42
+ throw new InitializationError("Crypto not initialized. Call initCrypto() before using poseidon().");
43
+ }
44
+ const hash = _poseidon(inputs);
45
+ return _poseidon.F.toObject(hash);
46
+ };
47
+ export { derivePublicKey as deriveSpendingPublicKey, signMessage, verifySignature, } from "@zk-kit/eddsa-poseidon";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Browser polyfills for Node.js-specific APIs used by circomlibjs.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../../crypto-adapters/polyfills.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Browser polyfills for Node.js-specific APIs used by circomlibjs.
3
+ */
4
+ import { Buffer } from "buffer";
5
+ // Make Buffer available globally for circomlibjs
6
+ if (typeof globalThis.Buffer === "undefined") {
7
+ globalThis.Buffer = Buffer;
8
+ }
package/dist/errors.d.ts CHANGED
@@ -7,4 +7,13 @@ export declare class KeyValidationError extends CoreError {
7
7
  export declare class SchemaMismatchError extends CoreError {
8
8
  constructor(current: number, expected: number);
9
9
  }
10
+ export declare class ValidationError extends CoreError {
11
+ constructor(message: string);
12
+ }
13
+ export declare class ProofError extends CoreError {
14
+ constructor(message: string);
15
+ }
16
+ export declare class InitializationError extends CoreError {
17
+ constructor(message: string);
18
+ }
10
19
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI9C"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI9C;AAED,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,UAAW,SAAQ,SAAS;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM;CAI5B"}
package/dist/errors.js CHANGED
@@ -16,3 +16,21 @@ export class SchemaMismatchError extends CoreError {
16
16
  this.name = "SchemaMismatchError";
17
17
  }
18
18
  }
19
+ export class ValidationError extends CoreError {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "ValidationError";
23
+ }
24
+ }
25
+ export class ProofError extends CoreError {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = "ProofError";
29
+ }
30
+ }
31
+ export class InitializationError extends CoreError {
32
+ constructor(message) {
33
+ super(message);
34
+ this.name = "InitializationError";
35
+ }
36
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./types.js";
2
+ export * from "./service.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../history/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}