@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,35 +0,0 @@
1
- import { keys } from "../keys.js";
2
- import { getJson, putJson } from "../utils/json-codec.js";
3
- import { ensureChainId, ensurePositiveInt } from "../utils/validators.js";
4
- export function createLeafStore(storage) {
5
- return {
6
- /**
7
- * Cache public leaf data pulled from the on-chain Merkle tree.
8
- */
9
- async putLeaf(leaf) {
10
- ensureChainId(leaf.chainId);
11
- ensurePositiveInt("leaf index", leaf.index);
12
- await putJson(storage, keys.leaf(leaf.chainId, leaf.index), leaf);
13
- },
14
- /**
15
- * Load a leaf commitment by tree index.
16
- */
17
- async getLeaf(chainId, index) {
18
- ensureChainId(chainId);
19
- ensurePositiveInt("leaf index", index);
20
- return getJson(storage, keys.leaf(chainId, index));
21
- },
22
- /**
23
- * Remove all cached leaves for a chain.
24
- */
25
- async clearLeaves(chainId) {
26
- ensureChainId(chainId);
27
- const prefix = `leaves:${chainId}:`;
28
- const entries = await storage.iter({ prefix });
29
- if (entries.length === 0)
30
- return;
31
- const deletions = entries.map(({ key }) => ({ del: key }));
32
- await storage.batch(deletions);
33
- },
34
- };
35
- }
@@ -1,36 +0,0 @@
1
- import { parseHexToBigInt } from "../../utils/bigint.js";
2
- export async function rebuildTreeFromStore({ chainId, trees, loadLeaf, }) {
3
- trees.reset(chainId);
4
- let idx = 0;
5
- for (;;) {
6
- const leaf = await loadLeaf(chainId, idx);
7
- if (!leaf)
8
- break;
9
- const { index } = trees.addLeaf(chainId, parseHexToBigInt(leaf.commitment));
10
- if (index !== idx) {
11
- throw new Error(`stored leaves are inconsistent with local tree, expected ${idx}, got ${index}`);
12
- }
13
- idx += 1;
14
- }
15
- return idx;
16
- }
17
- // TODO: Will be used for inmemory merkle tree handling for caching.
18
- // Atm everytime we need to access the tree we have to rebuild it from the store.
19
- // This function will help to avoid multiple rebuilds for the same chain
20
- export async function hydrateChain({ chainId, trees, loadLeaf, hydrated, }) {
21
- if (hydrated.has(chainId))
22
- return;
23
- trees.reset(chainId);
24
- let idx = 0;
25
- for (;;) {
26
- const leaf = await loadLeaf(chainId, idx);
27
- if (!leaf)
28
- break;
29
- const { index } = trees.addLeaf(chainId, parseHexToBigInt(leaf.commitment));
30
- if (index !== idx) {
31
- throw new Error("stored leaves are inconsistent with local tree");
32
- }
33
- idx += 1;
34
- }
35
- hydrated.add(chainId);
36
- }
@@ -1,2 +0,0 @@
1
- export { createLocalMerkleTree, createMerkleTrees, } from "./merkle-tree.js";
2
- export { hydrateChain, rebuildTreeFromStore, } from "./hydrator.js";
@@ -1,104 +0,0 @@
1
- import { poseidon } from "@railgun-community/circomlibjs";
2
- import { IMT, } from "@zk-kit/imt";
3
- import { ByteLength, ByteUtils } from "../../key-derivation/bytes.js";
4
- import { ensureChainId } from "../../utils/validators.js";
5
- const DEFAULT_DEPTH = 16;
6
- const DEFAULT_ARITY = 2;
7
- const ZERO_BYTE_LENGTH = ByteLength.UINT_256;
8
- // Simple adapter: IMTNode[] -> poseidon(bigint[])
9
- const hash = (values) => poseidon(values.map((v) => BigInt(v)));
10
- const formatNode = (value) => ByteUtils.nToHex(value, ZERO_BYTE_LENGTH, true);
11
- export function createLocalMerkleTree() {
12
- const zeroLeaf = 0n;
13
- const capacity = 2 ** DEFAULT_DEPTH;
14
- const tree = new IMT(hash, DEFAULT_DEPTH, zeroLeaf, DEFAULT_ARITY);
15
- function addLeaf(value) {
16
- if (tree.leaves.length >= capacity) {
17
- throw new Error("merkle tree is full");
18
- }
19
- const insertedIndex = tree.leaves.length;
20
- tree.insert(value);
21
- return {
22
- index: insertedIndex,
23
- root: formatNode(tree.root),
24
- };
25
- }
26
- function getRoot() {
27
- return formatNode(tree.root);
28
- }
29
- function getLeafCount() {
30
- return tree.leaves.length;
31
- }
32
- function getLeaf(index) {
33
- const leaf = tree.leaves[index];
34
- if (leaf === undefined) {
35
- throw new Error("leaf does not exist in this tree");
36
- }
37
- return formatNode(BigInt(leaf));
38
- }
39
- function createMerkleProof(index) {
40
- return tree.createProof(index);
41
- }
42
- return {
43
- addLeaf,
44
- getRoot,
45
- getLeafCount,
46
- getLeaf,
47
- createMerkleProof,
48
- getZero(level) {
49
- if (level === tree.depth) {
50
- return getRoot();
51
- }
52
- const zero = tree.zeroes[level];
53
- if (zero === undefined) {
54
- throw new Error("invalid level");
55
- }
56
- return formatNode(zero);
57
- },
58
- get depth() {
59
- return tree.depth;
60
- },
61
- get capacity() {
62
- return capacity;
63
- },
64
- };
65
- }
66
- export function createMerkleTrees() {
67
- const trees = new Map();
68
- const resetTree = (chainId) => {
69
- ensureChainId(chainId);
70
- const tree = createLocalMerkleTree();
71
- trees.set(chainId, tree);
72
- return tree;
73
- };
74
- const getOrCreate = (chainId) => {
75
- ensureChainId(chainId);
76
- let tree = trees.get(chainId);
77
- if (!tree) {
78
- tree = resetTree(chainId);
79
- }
80
- return tree;
81
- };
82
- return {
83
- get(chainId) {
84
- ensureChainId(chainId);
85
- return trees.get(chainId);
86
- },
87
- getOrCreate,
88
- addLeaf(chainId, value) {
89
- return getOrCreate(chainId).addLeaf(value);
90
- },
91
- createMerkleProof(chainId, index) {
92
- return getOrCreate(chainId).createMerkleProof(index);
93
- },
94
- getRoot(chainId) {
95
- return getOrCreate(chainId).getRoot();
96
- },
97
- getLeafCount(chainId) {
98
- return getOrCreate(chainId).getLeafCount();
99
- },
100
- reset(chainId) {
101
- resetTree(chainId);
102
- },
103
- };
104
- }
@@ -1,34 +0,0 @@
1
- import { IMTMerkleProof } from "@zk-kit/imt";
2
- export type AddLeafResult = {
3
- index: number;
4
- root: string;
5
- };
6
- export type MerkleProof = {
7
- root: string;
8
- leaf: string;
9
- pathElements: string[][];
10
- pathIndices: number[];
11
- leafIndex: number;
12
- };
13
- export declare function createLocalMerkleTree(): {
14
- addLeaf: (value: bigint) => AddLeafResult;
15
- getRoot: () => string;
16
- getLeafCount: () => number;
17
- getLeaf: (index: number) => string;
18
- createMerkleProof: (index: number) => IMTMerkleProof;
19
- getZero(level: number): string;
20
- readonly depth: number;
21
- readonly capacity: number;
22
- };
23
- export type LocalMerkleTree = ReturnType<typeof createLocalMerkleTree>;
24
- export type LocalMerkleTrees = {
25
- get(chainId: number): LocalMerkleTree | undefined;
26
- getOrCreate(chainId: number): LocalMerkleTree;
27
- addLeaf(chainId: number, value: bigint): AddLeafResult;
28
- createMerkleProof(chainId: number, index: number): IMTMerkleProof;
29
- getRoot(chainId: number): string;
30
- getLeafCount(chainId: number): number;
31
- reset(chainId: number): void;
32
- };
33
- export declare function createMerkleTrees(): LocalMerkleTrees;
34
- //# sourceMappingURL=merkle-tree.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merkle-tree.d.ts","sourceRoot":"","sources":["../../state/merkle-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EAGf,MAAM,aAAa,CAAC;AAWrB,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAaF,wBAAgB,qBAAqB;qBAUX,MAAM,KAAG,aAAa;;;qBAsBtB,MAAM;+BAQI,MAAM,KAAG,cAAc;mBAUxC,MAAM;;;EAiBxB;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEvE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAClD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAC;IAC9C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC;IACvD,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC;IAClE,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAgB,iBAAiB,IAAI,gBAAgB,CAwCpD"}
@@ -1,104 +0,0 @@
1
- import { poseidon } from "@railgun-community/circomlibjs";
2
- import { IMT, } from "@zk-kit/imt";
3
- import { ByteLength, ByteUtils } from "../key-derivation/bytes.js";
4
- import { ensureChainId } from "../utils/validators.js";
5
- const DEFAULT_DEPTH = 16;
6
- const DEFAULT_ARITY = 2;
7
- const ZERO_BYTE_LENGTH = ByteLength.UINT_256;
8
- // Simple adapter: IMTNode[] -> poseidon(bigint[])
9
- const hash = (values) => poseidon(values.map((v) => BigInt(v)));
10
- const formatNode = (value) => ByteUtils.nToHex(value, ZERO_BYTE_LENGTH, true);
11
- export function createLocalMerkleTree() {
12
- const zeroLeaf = 0n;
13
- const capacity = 2 ** DEFAULT_DEPTH;
14
- const tree = new IMT(hash, DEFAULT_DEPTH, zeroLeaf, DEFAULT_ARITY);
15
- function addLeaf(value) {
16
- if (tree.leaves.length >= capacity) {
17
- throw new Error("merkle tree is full");
18
- }
19
- const insertedIndex = tree.leaves.length;
20
- tree.insert(value);
21
- return {
22
- index: insertedIndex,
23
- root: formatNode(tree.root),
24
- };
25
- }
26
- function getRoot() {
27
- return formatNode(tree.root);
28
- }
29
- function getLeafCount() {
30
- return tree.leaves.length;
31
- }
32
- function getLeaf(index) {
33
- const leaf = tree.leaves[index];
34
- if (leaf === undefined) {
35
- throw new Error("leaf does not exist in this tree");
36
- }
37
- return formatNode(BigInt(leaf));
38
- }
39
- function createMerkleProof(index) {
40
- return tree.createProof(index);
41
- }
42
- return {
43
- addLeaf,
44
- getRoot,
45
- getLeafCount,
46
- getLeaf,
47
- createMerkleProof,
48
- getZero(level) {
49
- if (level === tree.depth) {
50
- return getRoot();
51
- }
52
- const zero = tree.zeroes[level];
53
- if (zero === undefined) {
54
- throw new Error("invalid level");
55
- }
56
- return formatNode(zero);
57
- },
58
- get depth() {
59
- return tree.depth;
60
- },
61
- get capacity() {
62
- return capacity;
63
- },
64
- };
65
- }
66
- export function createMerkleTrees() {
67
- const trees = new Map();
68
- const resetTree = (chainId) => {
69
- ensureChainId(chainId);
70
- const tree = createLocalMerkleTree();
71
- trees.set(chainId, tree);
72
- return tree;
73
- };
74
- const getOrCreate = (chainId) => {
75
- ensureChainId(chainId);
76
- let tree = trees.get(chainId);
77
- if (!tree) {
78
- tree = resetTree(chainId);
79
- }
80
- return tree;
81
- };
82
- return {
83
- get(chainId) {
84
- ensureChainId(chainId);
85
- return trees.get(chainId);
86
- },
87
- getOrCreate,
88
- addLeaf(chainId, value) {
89
- return getOrCreate(chainId).addLeaf(value);
90
- },
91
- createMerkleProof(chainId, index) {
92
- return getOrCreate(chainId).createMerkleProof(index);
93
- },
94
- getRoot(chainId) {
95
- return getOrCreate(chainId).getRoot();
96
- },
97
- getLeafCount(chainId) {
98
- return getOrCreate(chainId).getLeafCount();
99
- },
100
- reset(chainId) {
101
- resetTree(chainId);
102
- },
103
- };
104
- }
@@ -1,37 +0,0 @@
1
- import type { Storage } from "../types.js";
2
- import type { NoteInsert, NoteRecord } from "./records.js";
3
- export declare const emptyBytes: () => Uint8Array<ArrayBuffer>;
4
- export declare function createNoteStore(storage: Storage): {
5
- /**
6
- * Upsert a note record and maintain the unspent-note index for fast balance queries.
7
- */
8
- putNote(note: NoteInsert): Promise<void>;
9
- /**
10
- * Fetch a note by (chainId, index) if it exists in local storage.
11
- */
12
- getNote(chainId: number, index: number): Promise<NoteRecord | null>;
13
- /**
14
- * List notes matching optional filters (by chainId, mpk) and spent state.
15
- */
16
- listNotes(options?: {
17
- chainId?: number;
18
- mpk?: string;
19
- token?: string;
20
- includeSpent?: boolean;
21
- }): Promise<NoteRecord[]>;
22
- /**
23
- * Mark a cached note as spent by setting its timestamp and re-indexing metadata.
24
- */
25
- markNoteSpent(chainId: number, index: number, spentAt?: number): Promise<NoteRecord>;
26
- /**
27
- * Drop the spent marker from a cached note, returning it to the unspent index.
28
- */
29
- markNoteUnspent(chainId: number, index: number): Promise<NoteRecord>;
30
- /**
31
- * Aggregate unspent note balances per token for a given master public key.
32
- */
33
- getZkBalances(mpk: string, options?: {
34
- chainId?: number;
35
- }): Promise<Record<string, bigint>>;
36
- };
37
- //# sourceMappingURL=note-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"note-store.d.ts","sourceRoot":"","sources":["../../state/note-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,aAAa,CAAC;AAapD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,+BAA0B,CAAC;AAElD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO;IAyC5C;;OAEG;kBACiB,UAAU;IAI9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;IAM5C;;OAEG;wBAEQ;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB;IAyBH;;OAEG;2BAC0B,MAAM,SAAS,MAAM;IAgBlD;;OAEG;6BAC4B,MAAM,SAAS,MAAM;IAgBpD;;OAEG;uBACsB,MAAM,YAAW;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;EAiBjE"}
@@ -1,133 +0,0 @@
1
- import { CoreError } from "../errors.js";
2
- import { keys } from "../keys.js";
3
- import { decodeJson, encodeJson, getJson, } from "../utils/json-codec.js";
4
- import { ensureBigIntString, ensureChainId, ensureMpk, ensurePositiveInt, } from "../utils/validators.js";
5
- export const emptyBytes = () => new Uint8Array(0);
6
- export function createNoteStore(storage) {
7
- const persistNote = async (record) => {
8
- ensureChainId(record.chainId);
9
- ensurePositiveInt("note index", record.index);
10
- ensureMpk(record.mpk);
11
- ensureBigIntString("note value", record.value);
12
- if (record.spentAt !== undefined) {
13
- ensurePositiveInt("note spentAt", record.spentAt);
14
- }
15
- const noteKey = keys.note(record.chainId, record.index);
16
- const previous = await getJson(storage, noteKey);
17
- const ops = [
18
- { put: [noteKey, encodeJson(record)] },
19
- ];
20
- if (previous && previous.spentAt === undefined) {
21
- ops.push({
22
- del: keys.unspent(previous.chainId, previous.mpk, previous.index),
23
- });
24
- }
25
- if (record.spentAt === undefined) {
26
- // idx:notes:unspent functions as a set, so we only persist the sentinel bytes.
27
- ops.push({
28
- put: [
29
- keys.unspent(record.chainId, record.mpk, record.index),
30
- emptyBytes(),
31
- ],
32
- });
33
- }
34
- else {
35
- ops.push({
36
- del: keys.unspent(record.chainId, record.mpk, record.index),
37
- });
38
- }
39
- await storage.batch(ops);
40
- };
41
- const store = {
42
- /**
43
- * Upsert a note record and maintain the unspent-note index for fast balance queries.
44
- */
45
- async putNote(note) {
46
- await persistNote({ ...note });
47
- },
48
- /**
49
- * Fetch a note by (chainId, index) if it exists in local storage.
50
- */
51
- async getNote(chainId, index) {
52
- ensureChainId(chainId);
53
- ensurePositiveInt("note index", index);
54
- return getJson(storage, keys.note(chainId, index));
55
- },
56
- /**
57
- * List notes matching optional filters (by chainId, mpk) and spent state.
58
- */
59
- async listNotes(options = {}) {
60
- const { chainId, mpk, token, includeSpent = true } = options;
61
- if (chainId !== undefined) {
62
- ensureChainId(chainId);
63
- }
64
- if (mpk !== undefined) {
65
- ensureMpk(mpk);
66
- }
67
- const prefix = chainId !== undefined ? `notes:${chainId}:` : "notes:";
68
- const entries = await storage.iter({ prefix });
69
- const filtered = entries
70
- .map(({ value }) => decodeJson(value))
71
- .filter((note) => (chainId === undefined || note.chainId === chainId) &&
72
- (mpk === undefined || note.mpk === mpk) &&
73
- (token === undefined || note.token === token) &&
74
- (includeSpent || note.spentAt === undefined));
75
- filtered.sort((a, b) => a.index - b.index);
76
- return filtered;
77
- },
78
- /**
79
- * Mark a cached note as spent by setting its timestamp and re-indexing metadata.
80
- */
81
- async markNoteSpent(chainId, index, spentAt = Date.now()) {
82
- ensureChainId(chainId);
83
- ensurePositiveInt("note index", index);
84
- ensurePositiveInt("note spentAt", spentAt);
85
- const existing = await store.getNote(chainId, index);
86
- if (!existing) {
87
- throw new CoreError("note not found");
88
- }
89
- if (existing.spentAt === spentAt) {
90
- return existing;
91
- }
92
- const updated = { ...existing, spentAt };
93
- await persistNote(updated);
94
- return updated;
95
- },
96
- /**
97
- * Drop the spent marker from a cached note, returning it to the unspent index.
98
- */
99
- async markNoteUnspent(chainId, index) {
100
- ensureChainId(chainId);
101
- ensurePositiveInt("note index", index);
102
- const existing = await store.getNote(chainId, index);
103
- if (!existing) {
104
- throw new CoreError("note not found");
105
- }
106
- if (existing.spentAt === undefined) {
107
- return existing;
108
- }
109
- const updated = { ...existing };
110
- delete updated.spentAt;
111
- await persistNote(updated);
112
- return updated;
113
- },
114
- /**
115
- * Aggregate unspent note balances per token for a given master public key.
116
- */
117
- async getZkBalances(mpk, options = {}) {
118
- ensureMpk(mpk);
119
- const notes = await store.listNotes({
120
- chainId: options.chainId,
121
- mpk,
122
- includeSpent: false,
123
- });
124
- const totals = {};
125
- for (const note of notes) {
126
- const amount = BigInt(note.value);
127
- totals[note.token] = (totals[note.token] ?? 0n) + amount;
128
- }
129
- return totals;
130
- },
131
- };
132
- return store;
133
- }
@@ -1,13 +0,0 @@
1
- import type { Storage } from "../types.js";
2
- import type { NullifierRecord } from "./records.js";
3
- export declare function createNullifierStore(storage: Storage): {
4
- /**
5
- * Record a nullifier observation so later syncs can de-duplicate work.
6
- */
7
- putNullifier(nullifier: NullifierRecord): Promise<void>;
8
- /**
9
- * Lookup a previously observed nullifier by value.
10
- */
11
- getNullifier(chainId: number, value: string): Promise<NullifierRecord | null>;
12
- };
13
- //# sourceMappingURL=nullifier-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nullifier-store.d.ts","sourceRoot":"","sources":["../../state/nullifier-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAEjD;;OAEG;4BAC2B,eAAe;IAS7C;;OAEG;0BACyB,MAAM,SAAS,MAAM;EAKpD"}
@@ -1,21 +0,0 @@
1
- import { keys } from "../keys.js";
2
- import { getJson, putJson } from "../utils/json-codec.js";
3
- import { ensureChainId } from "../utils/validators.js";
4
- export function createNullifierStore(storage) {
5
- return {
6
- /**
7
- * Record a nullifier observation so later syncs can de-duplicate work.
8
- */
9
- async putNullifier(nullifier) {
10
- ensureChainId(nullifier.chainId);
11
- await putJson(storage, keys.nullifier(nullifier.chainId, nullifier.nullifier), nullifier);
12
- },
13
- /**
14
- * Lookup a previously observed nullifier by value.
15
- */
16
- async getNullifier(chainId, value) {
17
- ensureChainId(chainId);
18
- return getJson(storage, keys.nullifier(chainId, value));
19
- },
20
- };
21
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * Locally cached metadata for a deposit note we consider owned.
3
- */
4
- export type NoteRecord = {
5
- chainId: number;
6
- /** Leaf index within the on-chain tree (zero-based, monotonic). */
7
- index: number;
8
- /** Canonical asset identifier, typically the ERC-20 address lowercased. */
9
- token: string;
10
- /** Amount expressed as an unsigned BigInt serialized to a base-10 string. */
11
- value: string;
12
- /** Commitment stored on-chain (Poseidon(note)). */
13
- commitment: string;
14
- /** Note public key derived from the master public key. */
15
- npk: string;
16
- /**
17
- * Master public key for the account (Poseidon(spendingPk.public, nullifyingKey)).
18
- * Acts as the stable account identifier when grouping notes locally.
19
- */
20
- mpk: string;
21
- /** Randomizer used when committing the note. */
22
- random: string;
23
- /** Nullifier that will be revealed when the note is spent. */
24
- nullifier: string;
25
- /** Optional timestamp when the note was marked as spent. */
26
- spentAt?: number;
27
- };
28
- export type NoteInsert = Omit<NoteRecord, 'spentAt'>;
29
- /**
30
- * Details about a nullifier observed on-chain, whether or not we own the note.
31
- */
32
- export type NullifierRecord = {
33
- chainId: number;
34
- /** Nullifier value (expected to match NoteRecord.nullifier). */
35
- nullifier: string;
36
- /** Leaf index of the corresponding note when known. */
37
- noteIndex?: number;
38
- };
39
- /**
40
- * Public information about a leaf commitment inserted into the pool's tree.
41
- */
42
- export type LeafRecord = {
43
- chainId: number;
44
- /** Leaf index inside the tree (zero-based). */
45
- index: number;
46
- /** Commitment value stored in the tree. */
47
- commitment: string;
48
- };
49
- /**
50
- * Historical merkle root snapshot used for proof construction.
51
- */
52
- export type RootRecord = {
53
- chainId: number;
54
- /** Merkle root value committed on-chain. */
55
- root: string;
56
- };
57
- //# sourceMappingURL=records.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../state/records.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import type { Storage } from "../types.js";
2
- import type { RootRecord } from "./records.js";
3
- export declare function createRootStore(storage: Storage): {
4
- /**
5
- * Persist a historical root snapshot for proof generation.
6
- */
7
- putRoot(root: RootRecord): Promise<void>;
8
- /**
9
- * Retrieve a root snapshot by Merkle root value.
10
- */
11
- getRoot(chainId: number, value: string): Promise<RootRecord | null>;
12
- };
13
- //# sourceMappingURL=root-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"root-store.d.ts","sourceRoot":"","sources":["../../state/root-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO;IAE5C;;OAEG;kBACiB,UAAU;IAU9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;EAQ/C"}
@@ -1,30 +0,0 @@
1
- import { CoreError } from "../errors.js";
2
- import { keys, validateKey } from "../keys.js";
3
- import { getJson, putJson } from "../utils/json-codec.js";
4
- import { ensureChainId } from "../utils/validators.js";
5
- export function createRootStore(storage) {
6
- return {
7
- /**
8
- * Persist a historical root snapshot for proof generation.
9
- */
10
- async putRoot(root) {
11
- ensureChainId(root.chainId);
12
- if (typeof root.root !== "string" || root.root.length === 0) {
13
- throw new CoreError("root value must be a non-empty string");
14
- }
15
- const key = keys.root(root.chainId, root.root);
16
- validateKey(key);
17
- await putJson(storage, key, root);
18
- },
19
- /**
20
- * Retrieve a root snapshot by Merkle root value.
21
- */
22
- async getRoot(chainId, value) {
23
- ensureChainId(chainId);
24
- if (typeof value !== "string" || value.length === 0) {
25
- throw new CoreError("root value must be a non-empty string");
26
- }
27
- return getJson(storage, keys.root(chainId, value));
28
- },
29
- };
30
- }