@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
@@ -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