@unlink-xyz/core 0.1.2 → 0.1.3-canary.06c36a8

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 (348) 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 +108267 -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 +14 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +14 -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 +2 -2
  72. package/dist/prover/registry.d.ts.map +1 -1
  73. package/dist/prover/registry.js +62 -14
  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/memory.d.ts.map +1 -1
  112. package/dist/storage/memory.js +5 -1
  113. package/dist/transactions/deposit.d.ts +12 -15
  114. package/dist/transactions/deposit.d.ts.map +1 -1
  115. package/dist/transactions/deposit.js +203 -152
  116. package/dist/transactions/index.d.ts +7 -4
  117. package/dist/transactions/index.d.ts.map +1 -1
  118. package/dist/transactions/index.js +7 -2
  119. package/dist/transactions/note-selection.d.ts +17 -0
  120. package/dist/transactions/note-selection.d.ts.map +1 -0
  121. package/dist/transactions/note-selection.js +201 -0
  122. package/dist/transactions/note-sync.d.ts +5 -33
  123. package/dist/transactions/note-sync.d.ts.map +1 -1
  124. package/dist/transactions/note-sync.js +320 -155
  125. package/dist/transactions/reconcile.d.ts +10 -12
  126. package/dist/transactions/reconcile.d.ts.map +1 -1
  127. package/dist/transactions/reconcile.js +53 -7
  128. package/dist/transactions/transact.d.ts +13 -24
  129. package/dist/transactions/transact.d.ts.map +1 -1
  130. package/dist/transactions/transact.js +393 -507
  131. package/dist/transactions/transaction-planner.d.ts +34 -0
  132. package/dist/transactions/transaction-planner.d.ts.map +1 -0
  133. package/dist/transactions/transaction-planner.js +116 -0
  134. package/dist/transactions/transfer-planner.d.ts +36 -0
  135. package/dist/transactions/transfer-planner.d.ts.map +1 -0
  136. package/dist/transactions/transfer-planner.js +85 -0
  137. package/dist/transactions/types/deposit.d.ts +67 -0
  138. package/dist/transactions/types/deposit.d.ts.map +1 -0
  139. package/dist/transactions/types/domain.d.ts +67 -0
  140. package/dist/transactions/types/domain.d.ts.map +1 -0
  141. package/dist/transactions/types/domain.js +4 -0
  142. package/dist/transactions/types/index.d.ts +18 -0
  143. package/dist/transactions/types/index.d.ts.map +1 -0
  144. package/dist/transactions/types/index.js +17 -0
  145. package/dist/transactions/types/options.d.ts +45 -0
  146. package/dist/transactions/types/options.d.ts.map +1 -0
  147. package/dist/transactions/types/options.js +1 -0
  148. package/dist/transactions/types/planning.d.ts +80 -0
  149. package/dist/transactions/types/planning.d.ts.map +1 -0
  150. package/dist/transactions/types/planning.js +1 -0
  151. package/dist/transactions/types/state-stores.d.ts +103 -0
  152. package/dist/transactions/types/state-stores.d.ts.map +1 -0
  153. package/dist/transactions/types/state-stores.js +1 -0
  154. package/dist/transactions/types/transact.d.ts +76 -0
  155. package/dist/transactions/types/transact.d.ts.map +1 -0
  156. package/dist/transactions/types/transact.js +1 -0
  157. package/dist/transactions/withdrawal-planner.d.ts +58 -0
  158. package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
  159. package/dist/transactions/withdrawal-planner.js +128 -0
  160. package/dist/tsconfig.tsbuildinfo +1 -1
  161. package/dist/tsup.browser.config.d.ts +7 -0
  162. package/dist/tsup.browser.config.d.ts.map +1 -0
  163. package/dist/tsup.browser.config.js +34 -0
  164. package/dist/utils/amounts.d.ts +39 -0
  165. package/dist/utils/amounts.d.ts.map +1 -0
  166. package/dist/utils/amounts.js +89 -0
  167. package/dist/utils/async.d.ts +9 -0
  168. package/dist/utils/async.d.ts.map +1 -1
  169. package/dist/utils/async.js +24 -0
  170. package/dist/utils/bigint.js +7 -7
  171. package/dist/utils/crypto.d.ts +11 -5
  172. package/dist/utils/crypto.d.ts.map +1 -1
  173. package/dist/utils/crypto.js +12 -6
  174. package/dist/utils/format.d.ts +25 -0
  175. package/dist/utils/format.d.ts.map +1 -0
  176. package/dist/utils/format.js +33 -0
  177. package/dist/utils/notes.d.ts +15 -0
  178. package/dist/utils/notes.d.ts.map +1 -0
  179. package/dist/utils/notes.js +14 -0
  180. package/dist/utils/polling.d.ts +5 -0
  181. package/dist/utils/polling.d.ts.map +1 -1
  182. package/dist/utils/polling.js +5 -0
  183. package/dist/utils/random.d.ts +13 -0
  184. package/dist/utils/random.d.ts.map +1 -0
  185. package/dist/utils/random.js +27 -0
  186. package/dist/utils/secure-memory.d.ts +25 -0
  187. package/dist/utils/secure-memory.d.ts.map +1 -0
  188. package/dist/utils/secure-memory.js +28 -0
  189. package/dist/utils/signature.d.ts +6 -0
  190. package/dist/utils/signature.d.ts.map +1 -1
  191. package/dist/utils/signature.js +8 -6
  192. package/dist/utils/validators.d.ts +21 -10
  193. package/dist/utils/validators.d.ts.map +1 -1
  194. package/dist/utils/validators.js +37 -11
  195. package/dist/vitest.config.d.ts +3 -0
  196. package/dist/vitest.config.d.ts.map +1 -0
  197. package/dist/vitest.config.js +13 -0
  198. package/package.json +27 -7
  199. package/.eslintrc.json +0 -4
  200. package/account/zkAccount.test.ts +0 -316
  201. package/account/zkAccount.ts +0 -222
  202. package/clients/broadcaster.ts +0 -67
  203. package/clients/http.ts +0 -94
  204. package/clients/indexer.ts +0 -150
  205. package/config.ts +0 -39
  206. package/core.ts +0 -17
  207. package/dist/account/railgun-imports-prototype.d.ts +0 -12
  208. package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
  209. package/dist/account/railgun-imports-prototype.js +0 -30
  210. package/dist/account/zkAccount.d.ts.map +0 -1
  211. package/dist/key-derivation/babyjubjub.d.ts +0 -9
  212. package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
  213. package/dist/key-derivation/babyjubjub.js +0 -9
  214. package/dist/key-derivation/bech32.d.ts +0 -22
  215. package/dist/key-derivation/bech32.d.ts.map +0 -1
  216. package/dist/key-derivation/bech32.js +0 -86
  217. package/dist/key-derivation/bip32.d.ts +0 -17
  218. package/dist/key-derivation/bip32.d.ts.map +0 -1
  219. package/dist/key-derivation/bip32.js +0 -41
  220. package/dist/key-derivation/bip39.d.ts +0 -22
  221. package/dist/key-derivation/bip39.d.ts.map +0 -1
  222. package/dist/key-derivation/bip39.js +0 -56
  223. package/dist/key-derivation/bytes.d.ts +0 -19
  224. package/dist/key-derivation/bytes.d.ts.map +0 -1
  225. package/dist/key-derivation/bytes.js +0 -92
  226. package/dist/key-derivation/hash.d.ts +0 -3
  227. package/dist/key-derivation/hash.d.ts.map +0 -1
  228. package/dist/key-derivation/hash.js +0 -10
  229. package/dist/key-derivation/index.d.ts +0 -8
  230. package/dist/key-derivation/index.d.ts.map +0 -1
  231. package/dist/key-derivation/index.js +0 -7
  232. package/dist/key-derivation/wallet-node.d.ts +0 -45
  233. package/dist/key-derivation/wallet-node.d.ts.map +0 -1
  234. package/dist/key-derivation/wallet-node.js +0 -109
  235. package/dist/state/ciphertext-store.d.ts +0 -12
  236. package/dist/state/ciphertext-store.d.ts.map +0 -1
  237. package/dist/state/ciphertext-store.js +0 -25
  238. package/dist/state/hydrator.d.ts +0 -16
  239. package/dist/state/hydrator.d.ts.map +0 -1
  240. package/dist/state/hydrator.js +0 -18
  241. package/dist/state/job-store.d.ts +0 -12
  242. package/dist/state/job-store.d.ts.map +0 -1
  243. package/dist/state/job-store.js +0 -118
  244. package/dist/state/jobs.d.ts +0 -50
  245. package/dist/state/jobs.d.ts.map +0 -1
  246. package/dist/state/jobs.js +0 -1
  247. package/dist/state/leaf-store.d.ts +0 -17
  248. package/dist/state/leaf-store.d.ts.map +0 -1
  249. package/dist/state/leaf-store.js +0 -35
  250. package/dist/state/merkle-tree.d.ts +0 -34
  251. package/dist/state/merkle-tree.d.ts.map +0 -1
  252. package/dist/state/merkle-tree.js +0 -104
  253. package/dist/state/note-store.d.ts +0 -37
  254. package/dist/state/note-store.d.ts.map +0 -1
  255. package/dist/state/note-store.js +0 -133
  256. package/dist/state/nullifier-store.d.ts +0 -13
  257. package/dist/state/nullifier-store.d.ts.map +0 -1
  258. package/dist/state/nullifier-store.js +0 -21
  259. package/dist/state/records.d.ts +0 -57
  260. package/dist/state/records.d.ts.map +0 -1
  261. package/dist/state/root-store.d.ts +0 -13
  262. package/dist/state/root-store.d.ts.map +0 -1
  263. package/dist/state/root-store.js +0 -30
  264. package/dist/state/store.d.ts +0 -26
  265. package/dist/state/store.d.ts.map +0 -1
  266. package/dist/state/store.js +0 -19
  267. package/dist/state.d.ts +0 -83
  268. package/dist/state.d.ts.map +0 -1
  269. package/dist/state.js +0 -171
  270. package/dist/transactions/shield.d.ts +0 -5
  271. package/dist/transactions/shield.d.ts.map +0 -1
  272. package/dist/transactions/shield.js +0 -93
  273. package/dist/transactions/types.d.ts +0 -114
  274. package/dist/transactions/types.d.ts.map +0 -1
  275. package/dist/transactions/utils.d.ts +0 -10
  276. package/dist/transactions/utils.d.ts.map +0 -1
  277. package/dist/transactions/utils.js +0 -17
  278. package/dist/utils/time.d.ts +0 -2
  279. package/dist/utils/time.d.ts.map +0 -1
  280. package/dist/utils/time.js +0 -3
  281. package/dist/utils/witness.d.ts +0 -11
  282. package/dist/utils/witness.d.ts.map +0 -1
  283. package/dist/utils/witness.js +0 -19
  284. package/errors.ts +0 -20
  285. package/index.ts +0 -17
  286. package/key-derivation/babyjubjub.ts +0 -11
  287. package/key-derivation/bech32.test.ts +0 -90
  288. package/key-derivation/bech32.ts +0 -124
  289. package/key-derivation/bip32.ts +0 -56
  290. package/key-derivation/bip39.ts +0 -76
  291. package/key-derivation/bytes.ts +0 -118
  292. package/key-derivation/hash.ts +0 -13
  293. package/key-derivation/index.ts +0 -7
  294. package/key-derivation/wallet-node.ts +0 -155
  295. package/keys.ts +0 -47
  296. package/prover/config.ts +0 -104
  297. package/prover/index.ts +0 -1
  298. package/prover/prover.integration.test.ts +0 -162
  299. package/prover/prover.test.ts +0 -309
  300. package/prover/prover.ts +0 -405
  301. package/prover/registry.test.ts +0 -90
  302. package/prover/registry.ts +0 -82
  303. package/schema.ts +0 -17
  304. package/setup-artifacts.sh +0 -57
  305. package/state/index.ts +0 -2
  306. package/state/merkle/hydrator.ts +0 -69
  307. package/state/merkle/index.ts +0 -12
  308. package/state/merkle/merkle-tree.test.ts +0 -50
  309. package/state/merkle/merkle-tree.ts +0 -163
  310. package/state/store/ciphertext-store.ts +0 -28
  311. package/state/store/index.ts +0 -24
  312. package/state/store/job-store.ts +0 -162
  313. package/state/store/jobs.ts +0 -64
  314. package/state/store/leaf-store.ts +0 -39
  315. package/state/store/note-store.ts +0 -177
  316. package/state/store/nullifier-store.ts +0 -39
  317. package/state/store/records.ts +0 -61
  318. package/state/store/root-store.ts +0 -34
  319. package/state/store/store.ts +0 -25
  320. package/state.test.ts +0 -235
  321. package/storage/index.ts +0 -3
  322. package/storage/indexeddb.test.ts +0 -99
  323. package/storage/indexeddb.ts +0 -235
  324. package/storage/memory.test.ts +0 -59
  325. package/storage/memory.ts +0 -93
  326. package/transactions/deposit.test.ts +0 -160
  327. package/transactions/deposit.ts +0 -227
  328. package/transactions/index.ts +0 -20
  329. package/transactions/note-sync.test.ts +0 -155
  330. package/transactions/note-sync.ts +0 -452
  331. package/transactions/reconcile.ts +0 -73
  332. package/transactions/transact.test.ts +0 -451
  333. package/transactions/transact.ts +0 -811
  334. package/transactions/types.ts +0 -141
  335. package/tsconfig.json +0 -14
  336. package/types/global.d.ts +0 -15
  337. package/types.ts +0 -24
  338. package/utils/async.ts +0 -15
  339. package/utils/bigint.ts +0 -34
  340. package/utils/crypto.test.ts +0 -69
  341. package/utils/crypto.ts +0 -58
  342. package/utils/json-codec.ts +0 -38
  343. package/utils/polling.ts +0 -6
  344. package/utils/signature.ts +0 -16
  345. package/utils/validators.test.ts +0 -64
  346. package/utils/validators.ts +0 -86
  347. /package/dist/{transactions → history}/types.js +0 -0
  348. /package/dist/{state/records.js → transactions/types/deposit.js} +0 -0
@@ -1,141 +0,0 @@
1
- import { IMTMerkleProof } from "@zk-kit/imt";
2
-
3
- import type { ZkAccount } from "../account/zkAccount.js";
4
- import type { CommitmentRecord } from "../clients/indexer.js";
5
- import type {
6
- JobStatus,
7
- LeafRecord,
8
- NoteRecord,
9
- NullifierRecord,
10
- PendingJobKind,
11
- PendingJobRecord,
12
- RootRecord,
13
- } from "../state/index.js";
14
-
15
- /**
16
- * Base state store interface with common methods shared across services.
17
- */
18
- export type BaseStateStore = {
19
- putLeaf(record: LeafRecord): Promise<void>;
20
- getLeaf(chainId: number, index: number): Promise<LeafRecord | null>;
21
- clearLeaves(chainId: number): Promise<void>;
22
- putRoot(record: RootRecord): Promise<void>;
23
- putPendingJob(job: PendingJobRecord): Promise<void>;
24
- getPendingJob(relayId: string): Promise<PendingJobRecord | null>;
25
- listPendingJobs(filter?: {
26
- kind?: PendingJobKind;
27
- statuses?: JobStatus[];
28
- }): Promise<PendingJobRecord[]>;
29
- deletePendingJob(relayId: string): Promise<void>;
30
- };
31
-
32
- export type DepositStateStore = BaseStateStore;
33
-
34
- export type TransactStateStore = BaseStateStore & {
35
- getNote(chainId: number, index: number): Promise<NoteRecord | null>;
36
- markNoteSpent(
37
- chainId: number,
38
- index: number,
39
- spentAt?: number,
40
- ): Promise<NoteRecord>;
41
- putNullifier(record: NullifierRecord): Promise<void>;
42
- };
43
-
44
- export type DepositNoteInput = {
45
- mpk: bigint;
46
- random: bigint;
47
- token: string;
48
- amount: bigint;
49
- };
50
-
51
- export type DepositRequest = {
52
- zkAccount: ZkAccount;
53
- chainId: number;
54
- poolAddress: string;
55
- depositor: string;
56
- note: DepositNoteInput;
57
- };
58
-
59
- export type DepositRelayResult = {
60
- relayId: string;
61
- calldata: string;
62
- commitment: string;
63
- };
64
-
65
- export type DepositSyncResult = {
66
- chainId: number;
67
- index: number;
68
- commitment: string;
69
- root: string;
70
- };
71
-
72
- /**
73
- * Minimal reference to an input note; index resolves the canonical note state.
74
- */
75
- export type SpendNoteReference = {
76
- index: number;
77
- };
78
-
79
- export type WithdrawalNoteInput = {
80
- npk: bigint;
81
- amount: bigint;
82
- token: string;
83
- };
84
-
85
- /**
86
- * Private output note to append back into the pool after spending.
87
- */
88
- export type OutputNoteInput = {
89
- mpk: bigint;
90
- random: bigint;
91
- token: string;
92
- amount: bigint;
93
- };
94
-
95
- /**
96
- * Placeholder proof structure matching the pool interface; pubSignals remain meaningful.
97
- */
98
- export type Proof = {
99
- pA: [bigint, bigint];
100
- pB: [[bigint, bigint], [bigint, bigint]];
101
- pC: [bigint, bigint];
102
- pubSignals: bigint[];
103
- };
104
-
105
- /**
106
- * Parameters required to a mock transact call against the local state.
107
- */
108
- export type TransactRequest = {
109
- zkAccount: ZkAccount; // TODO: put zkAccount in parent?
110
- chainId: number;
111
- poolAddress: string;
112
- token: string;
113
- inputs: SpendNoteReference[];
114
- withdrawal: WithdrawalNoteInput;
115
- outputs: OutputNoteInput[];
116
- };
117
-
118
- /**
119
- * Result of the mock transact flow, including calldata and state deltas.
120
- */
121
- export type TransactRelayResult = {
122
- relayId: string;
123
- calldata: string;
124
- proof: Proof;
125
- witnesses: IMTMerkleProof[];
126
- nullifiers: string[];
127
- predictedCommitments: string[];
128
- };
129
-
130
- export type TransactSyncResult = {
131
- chainId: number;
132
- root: string;
133
- nullifiers: string[];
134
- newCommitments: string[];
135
- txHash?: string;
136
- indexedCommitments?: CommitmentRecord[];
137
- };
138
-
139
- export type Ciphertext = {
140
- data: [bigint, bigint, bigint];
141
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./",
6
- "composite": true,
7
- "declaration": true,
8
- "declarationMap": true,
9
- "noEmit": false,
10
- "typeRoots": ["./types", "../../node_modules/@types"]
11
- },
12
- "include": ["./**/*.ts"],
13
- "exclude": ["./dist/**/*", "./node_modules/**/*", "**/*.test.ts"]
14
- }
package/types/global.d.ts DELETED
@@ -1,15 +0,0 @@
1
- declare module "@railgun-community/circomlibjs" {
2
- export const babyjub: {
3
- Base8: [bigint, bigint];
4
- packPoint: (point: [bigint, bigint]) => Uint8Array;
5
- unpackPoint: (bytes: Uint8Array) => [bigint, bigint];
6
- };
7
- export const poseidon: (inputs: (bigint | number)[]) => bigint;
8
- export const eddsa: {
9
- prv2pub: (privKey: Uint8Array) => [bigint, bigint];
10
- signPoseidon: (
11
- privKey: Uint8Array,
12
- message: bigint,
13
- ) => { R8: [bigint, bigint]; S: bigint };
14
- };
15
- }
package/types.ts DELETED
@@ -1,24 +0,0 @@
1
- export type Bytes = Uint8Array;
2
-
3
- export type IterOptions = {
4
- prefix?: string;
5
- start?: string; // inclusive
6
- end?: string; // inclusive
7
- limit?: number;
8
- reverse?: boolean;
9
- };
10
-
11
- export type KvPair = { key: string; value: Bytes };
12
-
13
- export type BatchOp = { put?: [string, Bytes]; del?: string };
14
-
15
- export type Storage = {
16
- open(): Promise<void>;
17
- get(key: string): Promise<Bytes | null>;
18
- delete(key: string): Promise<void>;
19
- put(key: string, value: Bytes): Promise<void>;
20
- batch(ops: BatchOp[]): Promise<void>;
21
- iter(opts: IterOptions): Promise<KvPair[]>;
22
- getSchemaVersion(): Promise<number>;
23
- setSchemaVersion(v: number): Promise<void>;
24
- };
package/utils/async.ts DELETED
@@ -1,15 +0,0 @@
1
- import { HttpError } from "../clients/http.js";
2
-
3
- /**
4
- * Promise-based delay utility.
5
- */
6
- export function sleep(ms: number): Promise<void> {
7
- return new Promise((resolve) => setTimeout(resolve, ms));
8
- }
9
-
10
- /**
11
- * Type guard for HTTP 404 errors.
12
- */
13
- export function isNotFoundError(err: unknown): err is HttpError {
14
- return err instanceof HttpError && err.status === 404;
15
- }
package/utils/bigint.ts DELETED
@@ -1,34 +0,0 @@
1
- import { CoreError } from "../errors.js";
2
- import { ByteLength, ByteUtils } from "../key-derivation/bytes.js";
3
-
4
- /**
5
- * BigInt helpers shared across transaction builders to keep formatting consistent.
6
- */
7
- export function formatUint256(value: bigint): string {
8
- assertNonNegative("uint256", value);
9
- return ByteUtils.nToHex(value, ByteLength.UINT_256, true);
10
- }
11
-
12
- export function parseHexToBigInt(value: string): bigint {
13
- return ByteUtils.hexToBigInt(value);
14
- }
15
-
16
- export function parseNumToBigInt(value: string | undefined): bigint {
17
- if (value === undefined) {
18
- throw new CoreError("Value is undefined");
19
- }
20
- return BigInt(value);
21
- }
22
-
23
- export function assertNonNegative(label: string, value: bigint): void {
24
- if (value < 0n) {
25
- throw new CoreError(`${label} must be non-negative`);
26
- }
27
- }
28
-
29
- export function ensureBigint(label: string, value: unknown): bigint {
30
- if (typeof value !== "bigint") {
31
- throw new CoreError(`${label} must be provided as a bigint`);
32
- }
33
- return value;
34
- }
@@ -1,69 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { CoreError } from "../errors.js";
4
- import { Ciphertext, OutputNoteInput } from "../transactions/types.js";
5
- import { decryptNote, encryptNote } from "./crypto.js";
6
-
7
- describe("crypto", () => {
8
- describe("decryptNote", () => {
9
- it("successfully decrypts with correct key", () => {
10
- // Create a valid note
11
- const originalNote: OutputNoteInput = {
12
- mpk: 12345n,
13
- random: 67890n,
14
- token: "0x1111111111111111111111111111111111111111",
15
- amount: 1000n,
16
- };
17
-
18
- const ciphertext = encryptNote(originalNote);
19
-
20
- // Decrypt with the correct key (mpk)
21
- const decryptedNote = decryptNote(ciphertext, originalNote.mpk);
22
-
23
- // Verify decrypted data matches original
24
- expect(decryptedNote.mpk).toBe(originalNote.mpk);
25
- expect(decryptedNote.random).toBe(originalNote.random);
26
- expect(decryptedNote.token).toBe(originalNote.token);
27
- expect(decryptedNote.amount).toBe(originalNote.amount);
28
- });
29
-
30
- it("throws CoreError when decrypting with wrong key", () => {
31
- const originalNote: OutputNoteInput = {
32
- mpk: 12345n,
33
- random: 67890n,
34
- token: "0x1111111111111111111111111111111111111111",
35
- amount: 1000n,
36
- };
37
-
38
- // Encrypt the note with the correct key
39
- const ciphertext = encryptNote(originalNote);
40
-
41
- // Try to decrypt with a DIFFERENT key
42
- const wrongKey = 99999n;
43
-
44
- // Should throw CoreError with "Invalid Decrypt" message
45
- expect(() => decryptNote(ciphertext, wrongKey)).toThrow(CoreError);
46
- expect(() => decryptNote(ciphertext, wrongKey)).toThrow(
47
- "Invalid Decrypt",
48
- );
49
- });
50
-
51
- it("throws CoreError when decrypted token exceeds valid Ethereum address range", () => {
52
- const invalidCiphertext: Ciphertext = {
53
- data: [
54
- 123n,
55
- // This large value will decrypt to something > 160 bits
56
- 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,
57
- 456n,
58
- ],
59
- };
60
-
61
- const someKey = 12345n;
62
-
63
- expect(() => decryptNote(invalidCiphertext, someKey)).toThrow(CoreError);
64
- expect(() => decryptNote(invalidCiphertext, someKey)).toThrow(
65
- "Invalid Decrypt",
66
- );
67
- });
68
- });
69
- });
package/utils/crypto.ts DELETED
@@ -1,58 +0,0 @@
1
- import { poseidon } from "@railgun-community/circomlibjs";
2
-
3
- import { CoreError } from "../errors.js";
4
- import {
5
- Ciphertext,
6
- DepositNoteInput,
7
- DepositRequest,
8
- OutputNoteInput,
9
- } from "../transactions/types.js";
10
- import { parseHexToBigInt } from "./bigint.js";
11
-
12
- export function encryptNote(
13
- note: OutputNoteInput | DepositNoteInput,
14
- ): Ciphertext {
15
- return {
16
- data: [
17
- encrypt(note.random, note.mpk),
18
- encrypt(parseHexToBigInt(note.token), note.mpk),
19
- encrypt(note.amount, note.mpk),
20
- ],
21
- };
22
- }
23
-
24
- export function encrypt(data: bigint, key: bigint): bigint {
25
- return poseidon([0x556e6c696e6b, key]) ^ data;
26
- }
27
-
28
- export function decryptNote(c: Ciphertext, key: bigint): OutputNoteInput {
29
- const token_bigint = encrypt(c.data[1], key);
30
- if (token_bigint > 0xffffffffffffffffffffffffffffffffffffffffn) {
31
- throw new CoreError("Invalid Decrypt");
32
- }
33
- const result = {
34
- mpk: key,
35
- random: encrypt(c.data[0], key),
36
- token: "0x" + token_bigint.toString(16).padStart(40, "0"),
37
- amount: encrypt(c.data[2], key),
38
- };
39
- return result;
40
- }
41
-
42
- export function deriveCommitment(note: {
43
- npk: bigint;
44
- amount: bigint;
45
- token: string;
46
- }) {
47
- const tokenScalar = BigInt(note.token);
48
- return poseidon([note.npk, tokenScalar, note.amount]);
49
- }
50
-
51
- export function deriveNpk(request: DepositRequest) {
52
- return poseidon([request.note.mpk, request.note.random]);
53
- }
54
-
55
- export function computeCommitment(request: DepositRequest, npk: bigint) {
56
- const tokenScalar = BigInt(request.note.token);
57
- return poseidon([npk, tokenScalar, request.note.amount]);
58
- }
@@ -1,38 +0,0 @@
1
- import { CoreError } from "../errors.js";
2
- import { validateKey } from "../keys.js";
3
- import { Storage } from "../types.js";
4
-
5
- const encoder = new TextEncoder();
6
- const decoder = new TextDecoder();
7
-
8
- export type JsonRecord = { [key: string]: unknown };
9
-
10
- export function encodeJson(value: JsonRecord): Uint8Array {
11
- return encoder.encode(JSON.stringify(value));
12
- }
13
-
14
- export function decodeJson<T extends JsonRecord>(payload: Uint8Array): T {
15
- try {
16
- return JSON.parse(decoder.decode(payload)) as T;
17
- } catch (err) {
18
- throw new CoreError("failed to decode stored state payload");
19
- }
20
- }
21
-
22
- export async function putJson(
23
- storage: Storage,
24
- key: string,
25
- record: JsonRecord,
26
- ) {
27
- validateKey(key);
28
- await storage.put(key, encodeJson(record));
29
- }
30
-
31
- export async function getJson<T extends JsonRecord>(
32
- storage: Storage,
33
- key: string,
34
- ) {
35
- const payload = await storage.get(key);
36
- if (!payload) return null;
37
- return decodeJson<T>(payload);
38
- }
package/utils/polling.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Shared polling configuration constants.
3
- */
4
- export const DEFAULT_POLL_INTERVAL_MS = 500;
5
- export const DEFAULT_POLL_TIMEOUT_MS = 30_000;
6
- export const MAX_POLL_INTERVAL_MS = 5_000;
@@ -1,16 +0,0 @@
1
- import { Buffer } from "buffer";
2
- import { eddsa } from "@railgun-community/circomlibjs";
3
-
4
- /**
5
- * Generates an EdDSA signature over a poseidon-hashed message using the spending private key.
6
- * Used for transact public signal signing.
7
- */
8
- export function signTransactMessage(
9
- spendingPrivateKey: Uint8Array,
10
- message: bigint,
11
- ): { R8: [bigint, bigint]; S: bigint } {
12
- const key = Buffer.isBuffer(spendingPrivateKey)
13
- ? spendingPrivateKey
14
- : Buffer.from(spendingPrivateKey);
15
- return eddsa.signPoseidon(key, message);
16
- }
@@ -1,64 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import {
4
- ensureFieldElement,
5
- ensureNoteCommitmentInput,
6
- ensureWithdrawalInput,
7
- } from "./validators.js";
8
-
9
- const MAX =
10
- 21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617n;
11
-
12
- describe("validators", () => {
13
- describe("ensureWithdrawalInput", () => {
14
- it("accepts valid inputs", () => {
15
- const input = ensureWithdrawalInput("withdrawal", {
16
- npk: 1n,
17
- amount: 2n,
18
- token: "0x1111111111111111111111111111111111111111",
19
- });
20
- expect(input.amount).toBe(2n);
21
- });
22
-
23
- it.skip("rejects zero amounts", () => {
24
- // TODO: why would we want to do this?
25
- expect(() =>
26
- ensureWithdrawalInput("withdrawal", {
27
- npk: 1n,
28
- amount: 0n,
29
- token: "0x1111111111111111111111111111111111111111",
30
- }),
31
- ).toThrow("withdrawal.amount must be greater than zero");
32
- });
33
-
34
- it("rejects values outside the field", () => {
35
- expect(() =>
36
- ensureWithdrawalInput("withdrawal", {
37
- npk: MAX,
38
- amount: 1n,
39
- token: "0x1111111111111111111111111111111111111111",
40
- }),
41
- ).toThrow("must be less than the SNARK scalar field");
42
- });
43
- });
44
-
45
- describe("ensureNoteCommitmentInput", () => {
46
- it("rejects zero amounts", () => {
47
- expect(() =>
48
- ensureNoteCommitmentInput("note", {
49
- npk: 5n,
50
- amount: 0n,
51
- token: "0x1111111111111111111111111111111111111111",
52
- }),
53
- ).toThrow("note.amount must be greater than zero");
54
- });
55
- });
56
-
57
- describe("ensureFieldElement", () => {
58
- it("throws for negative values", () => {
59
- expect(() => ensureFieldElement("value", -1n)).toThrow(
60
- "value must be a non-negative field element",
61
- );
62
- });
63
- });
64
- });
@@ -1,86 +0,0 @@
1
- import { CoreError } from "../errors.js";
2
- import { assertNonNegative } from "./bigint.js";
3
-
4
- export const SNARK_SCALAR_FIELD =
5
- 21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617n;
6
-
7
- export function ensurePositiveInt(label: string, value: number) {
8
- if (!Number.isInteger(value) || value < 0) {
9
- throw new CoreError(`${label} must be a non-negative integer`);
10
- }
11
- }
12
-
13
- export function ensureChainId(chainId: number) {
14
- if (!Number.isInteger(chainId) || chainId <= 0) {
15
- throw new CoreError("chainId must be a positive integer");
16
- }
17
- }
18
-
19
- /** Guards master public key strings against empty values. */
20
- export function ensureMpk(mpk: string) {
21
- if (typeof mpk !== "string" || mpk.length === 0) {
22
- throw new CoreError("note mpk must be a non-empty string");
23
- }
24
- }
25
-
26
- export function ensureBigIntString(label: string, value: string) {
27
- let parsed: bigint;
28
- try {
29
- parsed = BigInt(value);
30
- } catch {
31
- throw new CoreError(`${label} must be a base-10 bigint string`);
32
- }
33
- if (parsed < 0n) {
34
- throw new CoreError(`${label} must be non-negative`);
35
- }
36
- }
37
-
38
- const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
39
-
40
- export function ensureAddress(label: string, value: string) {
41
- if (typeof value !== "string" || !ADDRESS_REGEX.test(value)) {
42
- throw new CoreError(`${label} must be a 0x-prefixed hex address`);
43
- }
44
- }
45
-
46
- /** Confirms the bigint resides in the SNARK scalar field range. */
47
- export function ensureFieldElement(label: string, value: bigint) {
48
- if (value < 0n) {
49
- throw new CoreError(`${label} must be a non-negative field element`);
50
- }
51
- if (value >= SNARK_SCALAR_FIELD) {
52
- throw new CoreError(`${label} must be less than the SNARK scalar field`);
53
- }
54
- }
55
-
56
- /** Validates withdrawal note public data before encoding calldata. */
57
- export function ensureWithdrawalInput(
58
- label: string,
59
- withdrawal: { npk: bigint; amount: bigint; token: string },
60
- ) {
61
- assertNonNegative(`${label}.npk`, withdrawal.npk);
62
- ensureFieldElement(`${label}.npk`, withdrawal.npk);
63
- assertNonNegative(`${label}.amount`, withdrawal.amount);
64
- // if (withdrawal.amount === 0n) {
65
- // throw new CoreError(`${label}.amount must be greater than zero`);
66
- // }
67
- ensureFieldElement(`${label}.amount`, withdrawal.amount);
68
- ensureAddress(`${label}.token`, withdrawal.token);
69
- return withdrawal;
70
- }
71
-
72
- /** Validates note parameters before producing a Poseidon commitment. */
73
- export function ensureNoteCommitmentInput(
74
- label: string,
75
- note: { npk: bigint; amount: bigint; token: string },
76
- ) {
77
- assertNonNegative(`${label}.npk`, note.npk);
78
- ensureFieldElement(`${label}.npk`, note.npk);
79
- assertNonNegative(`${label}.amount`, note.amount);
80
- if (note.amount === 0n) {
81
- throw new CoreError(`${label}.amount must be greater than zero`);
82
- }
83
- ensureFieldElement(`${label}.amount`, note.amount);
84
- ensureAddress(`${label}.token`, note.token);
85
- return note;
86
- }
File without changes