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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (350) hide show
  1. package/dist/account/{zkAccount.d.ts → account.d.ts} +7 -5
  2. package/dist/account/account.d.ts.map +1 -0
  3. package/dist/account/{zkAccount.js → account.js} +57 -43
  4. package/dist/browser/index.js +108202 -0
  5. package/dist/browser/index.js.map +1 -0
  6. package/dist/circuits.json +74 -0
  7. package/dist/clients/broadcaster.d.ts +7 -2
  8. package/dist/clients/broadcaster.d.ts.map +1 -1
  9. package/dist/clients/broadcaster.js +9 -1
  10. package/dist/clients/http.d.ts +6 -0
  11. package/dist/clients/http.d.ts.map +1 -1
  12. package/dist/clients/http.js +24 -9
  13. package/dist/clients/indexer.d.ts +11 -0
  14. package/dist/clients/indexer.d.ts.map +1 -1
  15. package/dist/clients/indexer.js +40 -11
  16. package/dist/config.d.ts +28 -9
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js +33 -26
  19. package/dist/constants.d.ts +6 -0
  20. package/dist/constants.d.ts.map +1 -0
  21. package/dist/constants.js +5 -0
  22. package/dist/core.d.ts.map +1 -1
  23. package/dist/core.js +5 -2
  24. package/dist/crypto-adapters/auto-init.d.ts +2 -0
  25. package/dist/crypto-adapters/auto-init.d.ts.map +1 -0
  26. package/dist/crypto-adapters/auto-init.js +7 -0
  27. package/dist/crypto-adapters/index.d.ts +22 -0
  28. package/dist/crypto-adapters/index.d.ts.map +1 -0
  29. package/dist/crypto-adapters/index.js +47 -0
  30. package/dist/crypto-adapters/polyfills.d.ts +5 -0
  31. package/dist/crypto-adapters/polyfills.d.ts.map +1 -0
  32. package/dist/crypto-adapters/polyfills.js +8 -0
  33. package/dist/errors.d.ts +9 -0
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +18 -0
  36. package/dist/history/index.d.ts +3 -0
  37. package/dist/history/index.d.ts.map +1 -0
  38. package/dist/history/index.js +2 -0
  39. package/dist/history/service.d.ts +46 -0
  40. package/dist/history/service.d.ts.map +1 -0
  41. package/dist/history/service.js +354 -0
  42. package/dist/history/types.d.ts +21 -0
  43. package/dist/history/types.d.ts.map +1 -0
  44. package/dist/index.d.ts +12 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +11 -4
  47. package/dist/keys/address.d.ts +13 -0
  48. package/dist/keys/address.d.ts.map +1 -0
  49. package/dist/keys/address.js +55 -0
  50. package/dist/keys/derive.d.ts +37 -0
  51. package/dist/keys/derive.d.ts.map +1 -0
  52. package/dist/keys/derive.js +112 -0
  53. package/dist/keys/hex.d.ts +17 -0
  54. package/dist/keys/hex.d.ts.map +1 -0
  55. package/dist/keys/hex.js +66 -0
  56. package/dist/keys/index.d.ts +5 -0
  57. package/dist/keys/index.d.ts.map +1 -0
  58. package/dist/keys/index.js +4 -0
  59. package/dist/keys/mnemonic.d.ts +8 -0
  60. package/dist/keys/mnemonic.d.ts.map +1 -0
  61. package/dist/keys/mnemonic.js +23 -0
  62. package/dist/keys.d.ts +4 -1
  63. package/dist/keys.d.ts.map +1 -1
  64. package/dist/keys.js +4 -0
  65. package/dist/prover/config.d.ts +1 -15
  66. package/dist/prover/config.d.ts.map +1 -1
  67. package/dist/prover/config.js +1 -11
  68. package/dist/prover/prover.d.ts +15 -4
  69. package/dist/prover/prover.d.ts.map +1 -1
  70. package/dist/prover/prover.js +115 -98
  71. package/dist/prover/registry.d.ts +3 -30
  72. package/dist/prover/registry.d.ts.map +1 -1
  73. package/dist/prover/registry.js +12 -51
  74. package/dist/state/merkle/hydrator.d.ts.map +1 -1
  75. package/dist/state/merkle/hydrator.js +3 -2
  76. package/dist/state/merkle/index.d.ts +1 -1
  77. package/dist/state/merkle/index.d.ts.map +1 -1
  78. package/dist/state/merkle/index.js +1 -1
  79. package/dist/state/merkle/merkle-tree.d.ts +8 -0
  80. package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
  81. package/dist/state/merkle/merkle-tree.js +16 -7
  82. package/dist/state/store/ciphertext-store.d.ts +4 -0
  83. package/dist/state/store/ciphertext-store.d.ts.map +1 -1
  84. package/dist/state/store/ciphertext-store.js +12 -0
  85. package/dist/state/store/history-store.d.ts +24 -0
  86. package/dist/state/store/history-store.d.ts.map +1 -0
  87. package/dist/state/store/history-store.js +53 -0
  88. package/dist/state/store/index.d.ts +3 -2
  89. package/dist/state/store/index.d.ts.map +1 -1
  90. package/dist/state/store/index.js +1 -0
  91. package/dist/state/store/job-store.d.ts +7 -7
  92. package/dist/state/store/job-store.d.ts.map +1 -1
  93. package/dist/state/store/job-store.js +65 -39
  94. package/dist/state/store/jobs.d.ts +65 -18
  95. package/dist/state/store/jobs.d.ts.map +1 -1
  96. package/dist/state/store/leaf-store.d.ts.map +1 -1
  97. package/dist/state/store/leaf-store.js +0 -3
  98. package/dist/state/store/note-store.d.ts +7 -7
  99. package/dist/state/store/note-store.d.ts.map +1 -1
  100. package/dist/state/store/note-store.js +38 -34
  101. package/dist/state/store/nullifier-store.d.ts +9 -0
  102. package/dist/state/store/nullifier-store.d.ts.map +1 -1
  103. package/dist/state/store/nullifier-store.js +32 -2
  104. package/dist/state/store/records.d.ts +31 -2
  105. package/dist/state/store/records.d.ts.map +1 -1
  106. package/dist/state/store/root-store.d.ts.map +1 -1
  107. package/dist/state/store/root-store.js +0 -4
  108. package/dist/state/store/store.d.ts +61 -27
  109. package/dist/state/store/store.d.ts.map +1 -1
  110. package/dist/state/store/store.js +92 -1
  111. package/dist/storage/indexeddb.js +1 -1
  112. package/dist/storage/memory.d.ts.map +1 -1
  113. package/dist/storage/memory.js +5 -1
  114. package/dist/transactions/deposit.d.ts +12 -15
  115. package/dist/transactions/deposit.d.ts.map +1 -1
  116. package/dist/transactions/deposit.js +203 -152
  117. package/dist/transactions/index.d.ts +7 -4
  118. package/dist/transactions/index.d.ts.map +1 -1
  119. package/dist/transactions/index.js +7 -2
  120. package/dist/transactions/note-selection.d.ts +17 -0
  121. package/dist/transactions/note-selection.d.ts.map +1 -0
  122. package/dist/transactions/note-selection.js +201 -0
  123. package/dist/transactions/note-sync.d.ts +5 -33
  124. package/dist/transactions/note-sync.d.ts.map +1 -1
  125. package/dist/transactions/note-sync.js +320 -155
  126. package/dist/transactions/reconcile.d.ts +10 -12
  127. package/dist/transactions/reconcile.d.ts.map +1 -1
  128. package/dist/transactions/reconcile.js +53 -7
  129. package/dist/transactions/transact.d.ts +13 -24
  130. package/dist/transactions/transact.d.ts.map +1 -1
  131. package/dist/transactions/transact.js +393 -507
  132. package/dist/transactions/transaction-planner.d.ts +34 -0
  133. package/dist/transactions/transaction-planner.d.ts.map +1 -0
  134. package/dist/transactions/transaction-planner.js +116 -0
  135. package/dist/transactions/transfer-planner.d.ts +36 -0
  136. package/dist/transactions/transfer-planner.d.ts.map +1 -0
  137. package/dist/transactions/transfer-planner.js +85 -0
  138. package/dist/transactions/types/deposit.d.ts +67 -0
  139. package/dist/transactions/types/deposit.d.ts.map +1 -0
  140. package/dist/transactions/types/domain.d.ts +67 -0
  141. package/dist/transactions/types/domain.d.ts.map +1 -0
  142. package/dist/transactions/types/domain.js +4 -0
  143. package/dist/transactions/types/index.d.ts +18 -0
  144. package/dist/transactions/types/index.d.ts.map +1 -0
  145. package/dist/transactions/types/index.js +17 -0
  146. package/dist/transactions/types/options.d.ts +45 -0
  147. package/dist/transactions/types/options.d.ts.map +1 -0
  148. package/dist/transactions/types/options.js +1 -0
  149. package/dist/transactions/types/planning.d.ts +80 -0
  150. package/dist/transactions/types/planning.d.ts.map +1 -0
  151. package/dist/transactions/types/planning.js +1 -0
  152. package/dist/transactions/types/state-stores.d.ts +103 -0
  153. package/dist/transactions/types/state-stores.d.ts.map +1 -0
  154. package/dist/transactions/types/state-stores.js +1 -0
  155. package/dist/transactions/types/transact.d.ts +76 -0
  156. package/dist/transactions/types/transact.d.ts.map +1 -0
  157. package/dist/transactions/types/transact.js +1 -0
  158. package/dist/transactions/withdrawal-planner.d.ts +58 -0
  159. package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
  160. package/dist/transactions/withdrawal-planner.js +128 -0
  161. package/dist/tsconfig.tsbuildinfo +1 -1
  162. package/dist/tsup.browser.config.d.ts +7 -0
  163. package/dist/tsup.browser.config.d.ts.map +1 -0
  164. package/dist/tsup.browser.config.js +34 -0
  165. package/dist/utils/amounts.d.ts +39 -0
  166. package/dist/utils/amounts.d.ts.map +1 -0
  167. package/dist/utils/amounts.js +89 -0
  168. package/dist/utils/async.d.ts +9 -0
  169. package/dist/utils/async.d.ts.map +1 -1
  170. package/dist/utils/async.js +24 -0
  171. package/dist/utils/bigint.js +7 -7
  172. package/dist/utils/crypto.d.ts +11 -5
  173. package/dist/utils/crypto.d.ts.map +1 -1
  174. package/dist/utils/crypto.js +12 -6
  175. package/dist/utils/format.d.ts +25 -0
  176. package/dist/utils/format.d.ts.map +1 -0
  177. package/dist/utils/format.js +33 -0
  178. package/dist/utils/json-codec.js +1 -1
  179. package/dist/utils/notes.d.ts +15 -0
  180. package/dist/utils/notes.d.ts.map +1 -0
  181. package/dist/utils/notes.js +14 -0
  182. package/dist/utils/polling.d.ts +5 -0
  183. package/dist/utils/polling.d.ts.map +1 -1
  184. package/dist/utils/polling.js +5 -0
  185. package/dist/utils/random.d.ts +13 -0
  186. package/dist/utils/random.d.ts.map +1 -0
  187. package/dist/utils/random.js +27 -0
  188. package/dist/utils/secure-memory.d.ts +25 -0
  189. package/dist/utils/secure-memory.d.ts.map +1 -0
  190. package/dist/utils/secure-memory.js +28 -0
  191. package/dist/utils/signature.d.ts +6 -0
  192. package/dist/utils/signature.d.ts.map +1 -1
  193. package/dist/utils/signature.js +8 -6
  194. package/dist/utils/validators.d.ts +21 -10
  195. package/dist/utils/validators.d.ts.map +1 -1
  196. package/dist/utils/validators.js +37 -11
  197. package/dist/vitest.config.d.ts +3 -0
  198. package/dist/vitest.config.d.ts.map +1 -0
  199. package/dist/vitest.config.js +13 -0
  200. package/package.json +28 -11
  201. package/.eslintrc.json +0 -4
  202. package/account/zkAccount.test.ts +0 -316
  203. package/account/zkAccount.ts +0 -222
  204. package/clients/broadcaster.ts +0 -67
  205. package/clients/http.ts +0 -94
  206. package/clients/indexer.ts +0 -150
  207. package/config.ts +0 -39
  208. package/core.ts +0 -17
  209. package/dist/account/railgun-imports-prototype.d.ts +0 -12
  210. package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
  211. package/dist/account/railgun-imports-prototype.js +0 -30
  212. package/dist/account/zkAccount.d.ts.map +0 -1
  213. package/dist/key-derivation/babyjubjub.d.ts +0 -9
  214. package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
  215. package/dist/key-derivation/babyjubjub.js +0 -9
  216. package/dist/key-derivation/bech32.d.ts +0 -22
  217. package/dist/key-derivation/bech32.d.ts.map +0 -1
  218. package/dist/key-derivation/bech32.js +0 -86
  219. package/dist/key-derivation/bip32.d.ts +0 -17
  220. package/dist/key-derivation/bip32.d.ts.map +0 -1
  221. package/dist/key-derivation/bip32.js +0 -41
  222. package/dist/key-derivation/bip39.d.ts +0 -22
  223. package/dist/key-derivation/bip39.d.ts.map +0 -1
  224. package/dist/key-derivation/bip39.js +0 -56
  225. package/dist/key-derivation/bytes.d.ts +0 -19
  226. package/dist/key-derivation/bytes.d.ts.map +0 -1
  227. package/dist/key-derivation/bytes.js +0 -92
  228. package/dist/key-derivation/hash.d.ts +0 -3
  229. package/dist/key-derivation/hash.d.ts.map +0 -1
  230. package/dist/key-derivation/hash.js +0 -10
  231. package/dist/key-derivation/index.d.ts +0 -8
  232. package/dist/key-derivation/index.d.ts.map +0 -1
  233. package/dist/key-derivation/index.js +0 -7
  234. package/dist/key-derivation/wallet-node.d.ts +0 -45
  235. package/dist/key-derivation/wallet-node.d.ts.map +0 -1
  236. package/dist/key-derivation/wallet-node.js +0 -109
  237. package/dist/state/ciphertext-store.d.ts +0 -12
  238. package/dist/state/ciphertext-store.d.ts.map +0 -1
  239. package/dist/state/ciphertext-store.js +0 -25
  240. package/dist/state/hydrator.d.ts +0 -16
  241. package/dist/state/hydrator.d.ts.map +0 -1
  242. package/dist/state/hydrator.js +0 -18
  243. package/dist/state/job-store.d.ts +0 -12
  244. package/dist/state/job-store.d.ts.map +0 -1
  245. package/dist/state/job-store.js +0 -118
  246. package/dist/state/jobs.d.ts +0 -50
  247. package/dist/state/jobs.d.ts.map +0 -1
  248. package/dist/state/jobs.js +0 -1
  249. package/dist/state/leaf-store.d.ts +0 -17
  250. package/dist/state/leaf-store.d.ts.map +0 -1
  251. package/dist/state/leaf-store.js +0 -35
  252. package/dist/state/merkle-tree.d.ts +0 -34
  253. package/dist/state/merkle-tree.d.ts.map +0 -1
  254. package/dist/state/merkle-tree.js +0 -104
  255. package/dist/state/note-store.d.ts +0 -37
  256. package/dist/state/note-store.d.ts.map +0 -1
  257. package/dist/state/note-store.js +0 -133
  258. package/dist/state/nullifier-store.d.ts +0 -13
  259. package/dist/state/nullifier-store.d.ts.map +0 -1
  260. package/dist/state/nullifier-store.js +0 -21
  261. package/dist/state/records.d.ts +0 -57
  262. package/dist/state/records.d.ts.map +0 -1
  263. package/dist/state/root-store.d.ts +0 -13
  264. package/dist/state/root-store.d.ts.map +0 -1
  265. package/dist/state/root-store.js +0 -30
  266. package/dist/state/store.d.ts +0 -26
  267. package/dist/state/store.d.ts.map +0 -1
  268. package/dist/state/store.js +0 -19
  269. package/dist/state.d.ts +0 -83
  270. package/dist/state.d.ts.map +0 -1
  271. package/dist/state.js +0 -171
  272. package/dist/transactions/shield.d.ts +0 -5
  273. package/dist/transactions/shield.d.ts.map +0 -1
  274. package/dist/transactions/shield.js +0 -93
  275. package/dist/transactions/types.d.ts +0 -114
  276. package/dist/transactions/types.d.ts.map +0 -1
  277. package/dist/transactions/utils.d.ts +0 -10
  278. package/dist/transactions/utils.d.ts.map +0 -1
  279. package/dist/transactions/utils.js +0 -17
  280. package/dist/utils/time.d.ts +0 -2
  281. package/dist/utils/time.d.ts.map +0 -1
  282. package/dist/utils/time.js +0 -3
  283. package/dist/utils/witness.d.ts +0 -11
  284. package/dist/utils/witness.d.ts.map +0 -1
  285. package/dist/utils/witness.js +0 -19
  286. package/errors.ts +0 -20
  287. package/index.ts +0 -17
  288. package/key-derivation/babyjubjub.ts +0 -11
  289. package/key-derivation/bech32.test.ts +0 -90
  290. package/key-derivation/bech32.ts +0 -124
  291. package/key-derivation/bip32.ts +0 -56
  292. package/key-derivation/bip39.ts +0 -76
  293. package/key-derivation/bytes.ts +0 -118
  294. package/key-derivation/hash.ts +0 -13
  295. package/key-derivation/index.ts +0 -7
  296. package/key-derivation/wallet-node.ts +0 -155
  297. package/keys.ts +0 -47
  298. package/prover/config.ts +0 -104
  299. package/prover/index.ts +0 -1
  300. package/prover/prover.integration.test.ts +0 -162
  301. package/prover/prover.test.ts +0 -309
  302. package/prover/prover.ts +0 -405
  303. package/prover/registry.test.ts +0 -90
  304. package/prover/registry.ts +0 -82
  305. package/schema.ts +0 -17
  306. package/setup-artifacts.sh +0 -57
  307. package/state/index.ts +0 -2
  308. package/state/merkle/hydrator.ts +0 -69
  309. package/state/merkle/index.ts +0 -12
  310. package/state/merkle/merkle-tree.test.ts +0 -50
  311. package/state/merkle/merkle-tree.ts +0 -163
  312. package/state/store/ciphertext-store.ts +0 -28
  313. package/state/store/index.ts +0 -24
  314. package/state/store/job-store.ts +0 -162
  315. package/state/store/jobs.ts +0 -64
  316. package/state/store/leaf-store.ts +0 -39
  317. package/state/store/note-store.ts +0 -177
  318. package/state/store/nullifier-store.ts +0 -39
  319. package/state/store/records.ts +0 -61
  320. package/state/store/root-store.ts +0 -34
  321. package/state/store/store.ts +0 -25
  322. package/state.test.ts +0 -235
  323. package/storage/index.ts +0 -3
  324. package/storage/indexeddb.test.ts +0 -99
  325. package/storage/indexeddb.ts +0 -235
  326. package/storage/memory.test.ts +0 -59
  327. package/storage/memory.ts +0 -93
  328. package/transactions/deposit.test.ts +0 -160
  329. package/transactions/deposit.ts +0 -227
  330. package/transactions/index.ts +0 -20
  331. package/transactions/note-sync.test.ts +0 -155
  332. package/transactions/note-sync.ts +0 -452
  333. package/transactions/reconcile.ts +0 -73
  334. package/transactions/transact.test.ts +0 -451
  335. package/transactions/transact.ts +0 -811
  336. package/transactions/types.ts +0 -141
  337. package/tsconfig.json +0 -14
  338. package/types/global.d.ts +0 -15
  339. package/types.ts +0 -24
  340. package/utils/async.ts +0 -15
  341. package/utils/bigint.ts +0 -34
  342. package/utils/crypto.test.ts +0 -69
  343. package/utils/crypto.ts +0 -58
  344. package/utils/json-codec.ts +0 -38
  345. package/utils/polling.ts +0 -6
  346. package/utils/signature.ts +0 -16
  347. package/utils/validators.test.ts +0 -64
  348. package/utils/validators.ts +0 -86
  349. /package/dist/{transactions → history}/types.js +0 -0
  350. /package/dist/{state/records.js → transactions/types/deposit.js} +0 -0
@@ -0,0 +1,34 @@
1
+ import type { Recipient, SelectableNote, TransactionPlan } from "./types/index.js";
2
+ /**
3
+ * Plan a transaction: select notes, choose circuit, generate outputs.
4
+ *
5
+ * This function handles:
6
+ * 1. Note selection using consolidation-first algorithm
7
+ * 2. Circuit selection (smallest that fits)
8
+ * 3. Output generation with cryptographic derivations
9
+ *
10
+ * @param notes - Available unspent notes (pre-filtered by token/chain by caller)
11
+ * @param recipients - List of recipients with their amounts
12
+ * @param senderMpk - Sender's master public key (for change output)
13
+ * @param token - Token address being transferred
14
+ * @returns Complete transaction plan ready for building TransactRequest
15
+ * @throws ValidationError if insufficient balance, no valid circuit, or other constraints fail
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const plan = planTransaction(
20
+ * spendableNotes,
21
+ * [{ mpk: recipientMpk, amount: 100n }],
22
+ * senderMpk,
23
+ * "0x...",
24
+ * );
25
+ * // plan.inputs - selected notes to spend
26
+ * // plan.outputs - generated outputs (recipient + change)
27
+ * // plan.circuit - circuit to use for proof
28
+ * ```
29
+ */
30
+ export declare function planTransaction<T extends {
31
+ index: number;
32
+ value: bigint | string;
33
+ }>(notes: SelectableNote<T>[], recipients: Recipient[], senderMpk: bigint, token: string): TransactionPlan<T>;
34
+ //# sourceMappingURL=transaction-planner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-planner.d.ts","sourceRoot":"","sources":["../../transactions/transaction-planner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,SAAS,EACT,cAAc,EACd,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAqD1B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,CAC7B,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAEnD,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,EAC1B,UAAU,EAAE,SAAS,EAAE,EACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,eAAe,CAAC,CAAC,CAAC,CAkEpB"}
@@ -0,0 +1,116 @@
1
+ import { poseidon } from "../crypto-adapters/index.js";
2
+ import { ProofError, ValidationError } from "../errors.js";
3
+ import { CIRCUIT_REGISTRY } from "../prover/registry.js";
4
+ import { randomBigint } from "../utils/random.js";
5
+ import { selectNotesForAmount } from "./note-selection.js";
6
+ /**
7
+ * Select the smallest circuit that fits the given input/output counts.
8
+ */
9
+ function selectCircuitForTransaction(inputCount, outputCount) {
10
+ // Sort circuits by total size (inputs + outputs) ascending
11
+ const circuits = Object.values(CIRCUIT_REGISTRY).sort((a, b) => a.inputs + a.outputs - (b.inputs + b.outputs));
12
+ const circuit = circuits.find((c) => c.inputs >= inputCount && c.outputs >= outputCount);
13
+ if (!circuit) {
14
+ throw new ProofError(`No circuit supports ${inputCount} inputs and ${outputCount} outputs. ` +
15
+ `Available: ${circuits.map((c) => `${c.inputs}x${c.outputs}`).join(", ")}`);
16
+ }
17
+ return circuit;
18
+ }
19
+ /**
20
+ * Generate a planned output note with derived npk and commitment.
21
+ */
22
+ function generateOutput(mpk, amount, token, owner) {
23
+ const random = randomBigint();
24
+ const npk = poseidon([mpk, random]);
25
+ const tokenScalar = BigInt(token);
26
+ const commitment = poseidon([npk, tokenScalar, amount]);
27
+ return {
28
+ mpk,
29
+ random,
30
+ token,
31
+ amount,
32
+ owner,
33
+ npk,
34
+ commitment,
35
+ };
36
+ }
37
+ /**
38
+ * Plan a transaction: select notes, choose circuit, generate outputs.
39
+ *
40
+ * This function handles:
41
+ * 1. Note selection using consolidation-first algorithm
42
+ * 2. Circuit selection (smallest that fits)
43
+ * 3. Output generation with cryptographic derivations
44
+ *
45
+ * @param notes - Available unspent notes (pre-filtered by token/chain by caller)
46
+ * @param recipients - List of recipients with their amounts
47
+ * @param senderMpk - Sender's master public key (for change output)
48
+ * @param token - Token address being transferred
49
+ * @returns Complete transaction plan ready for building TransactRequest
50
+ * @throws ValidationError if insufficient balance, no valid circuit, or other constraints fail
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const plan = planTransaction(
55
+ * spendableNotes,
56
+ * [{ mpk: recipientMpk, amount: 100n }],
57
+ * senderMpk,
58
+ * "0x...",
59
+ * );
60
+ * // plan.inputs - selected notes to spend
61
+ * // plan.outputs - generated outputs (recipient + change)
62
+ * // plan.circuit - circuit to use for proof
63
+ * ```
64
+ */
65
+ export function planTransaction(notes, recipients, senderMpk, token) {
66
+ // Validate inputs
67
+ if (!recipients.length) {
68
+ throw new ValidationError("At least one recipient is required");
69
+ }
70
+ // Validate each recipient has a positive amount
71
+ for (let i = 0; i < recipients.length; i++) {
72
+ const recipient = recipients[i];
73
+ if (recipient && recipient.amount <= 0n) {
74
+ throw new ValidationError(`Recipient at index ${i} has invalid amount: ${recipient.amount}. All recipients must have amount > 0`);
75
+ }
76
+ }
77
+ const totalSent = recipients.reduce((sum, r) => sum + r.amount, 0n);
78
+ // Select notes using consolidation-first algorithm
79
+ // Note: maxInputs/maxOutputs defaults are derived from CIRCUIT_REGISTRY in selectNotesForAmount
80
+ const selection = selectNotesForAmount(notes, totalSent, {
81
+ recipientCount: recipients.length,
82
+ });
83
+ const { selected: inputs, totalInput, change } = selection;
84
+ // Determine output count: 1 per recipient + 1 for change (if any)
85
+ const outputCount = recipients.length + (change > 0n ? 1 : 0);
86
+ // Select smallest fitting circuit
87
+ const circuit = selectCircuitForTransaction(inputs.length, outputCount);
88
+ // Generate outputs
89
+ const outputs = [];
90
+ // Recipient outputs
91
+ for (const recipient of recipients) {
92
+ outputs.push(generateOutput(recipient.mpk, recipient.amount, token, "recipient"));
93
+ }
94
+ // Change output (if any)
95
+ if (change > 0n) {
96
+ outputs.push(generateOutput(senderMpk, change, token, "self"));
97
+ }
98
+ // Create outputNotes for TransactParams (without derived fields, but with owner metadata)
99
+ const outputNotes = outputs.map((o) => ({
100
+ mpk: o.mpk,
101
+ random: o.random,
102
+ token: o.token,
103
+ amount: o.amount,
104
+ owner: o.owner,
105
+ }));
106
+ return {
107
+ inputs,
108
+ outputs,
109
+ outputNotes,
110
+ circuit,
111
+ totalInput,
112
+ totalSent,
113
+ change,
114
+ token,
115
+ };
116
+ }
@@ -0,0 +1,36 @@
1
+ import type { SelectableNote, TransactionPlan } from "./types/index.js";
2
+ /**
3
+ * Input for a single transfer in a batch.
4
+ */
5
+ export type TransferInput = {
6
+ token: string;
7
+ amount: bigint;
8
+ recipientMpk: bigint;
9
+ };
10
+ /**
11
+ * Plan transfer transaction(s).
12
+ * Accepts 1 or more transfers. When multiple transfers use the same token,
13
+ * notes are tracked across transfers to avoid double-spending.
14
+ *
15
+ * @param notes - Available unspent notes (all tokens)
16
+ * @param transfers - Transfers to plan (each with token, amount, recipientMpk)
17
+ * @param senderMpk - Sender's master public key (for change outputs)
18
+ * @returns Array of transaction plans, one per transfer input
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Single transfer
23
+ * const [plan] = planTransfers(notes, [{ token, amount: 100n, recipientMpk }], senderMpk);
24
+ *
25
+ * // Multiple transfers (possibly same token)
26
+ * const plans = planTransfers(notes, [
27
+ * { token: ETH, amount: 100n, recipientMpk: recipient1Mpk },
28
+ * { token: USDC, amount: 50n, recipientMpk: recipient2Mpk },
29
+ * ], senderMpk);
30
+ * ```
31
+ */
32
+ export declare function planTransfers<T extends {
33
+ index: number;
34
+ value: bigint | string;
35
+ }>(notes: SelectableNote<T>[], transfers: TransferInput[], senderMpk: bigint): TransactionPlan<T>[];
36
+ //# sourceMappingURL=transfer-planner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer-planner.d.ts","sourceRoot":"","sources":["../../transactions/transfer-planner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAEnD,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,EAC1B,SAAS,EAAE,aAAa,EAAE,EAC1B,SAAS,EAAE,MAAM,GAChB,eAAe,CAAC,CAAC,CAAC,EAAE,CAqFtB"}
@@ -0,0 +1,85 @@
1
+ import { ValidationError } from "../errors.js";
2
+ import { planTransaction } from "./transaction-planner.js";
3
+ /**
4
+ * Plan transfer transaction(s).
5
+ * Accepts 1 or more transfers. When multiple transfers use the same token,
6
+ * notes are tracked across transfers to avoid double-spending.
7
+ *
8
+ * @param notes - Available unspent notes (all tokens)
9
+ * @param transfers - Transfers to plan (each with token, amount, recipientMpk)
10
+ * @param senderMpk - Sender's master public key (for change outputs)
11
+ * @returns Array of transaction plans, one per transfer input
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Single transfer
16
+ * const [plan] = planTransfers(notes, [{ token, amount: 100n, recipientMpk }], senderMpk);
17
+ *
18
+ * // Multiple transfers (possibly same token)
19
+ * const plans = planTransfers(notes, [
20
+ * { token: ETH, amount: 100n, recipientMpk: recipient1Mpk },
21
+ * { token: USDC, amount: 50n, recipientMpk: recipient2Mpk },
22
+ * ], senderMpk);
23
+ * ```
24
+ */
25
+ export function planTransfers(notes, transfers, senderMpk) {
26
+ if (!transfers.length) {
27
+ throw new ValidationError("At least one transfer is required");
28
+ }
29
+ // Validate all transfers upfront
30
+ for (const t of transfers) {
31
+ if (!t.token) {
32
+ throw new ValidationError(`Missing token address in transfer: ${JSON.stringify(t)}`);
33
+ }
34
+ // Convert amount to bigint if needed (handles string amounts from frontend)
35
+ const amount = typeof t.amount === "bigint" ? t.amount : BigInt(t.amount);
36
+ if (amount <= 0n) {
37
+ throw new ValidationError(`Invalid transfer amount for ${t.token}: ${t.amount}`);
38
+ }
39
+ // Update amount to bigint for downstream use
40
+ t.amount = amount;
41
+ }
42
+ // Pre-validate total balances per token (use normalized tokens for comparison)
43
+ const requiredByToken = new Map();
44
+ for (const t of transfers) {
45
+ const tokenLower = t.token.toLowerCase();
46
+ const existing = requiredByToken.get(tokenLower) ?? 0n;
47
+ requiredByToken.set(tokenLower, existing + t.amount);
48
+ }
49
+ for (const [tokenLower, required] of requiredByToken) {
50
+ const available = notes
51
+ .filter((n) => {
52
+ const noteToken = n.token;
53
+ return noteToken && noteToken.toLowerCase() === tokenLower;
54
+ })
55
+ .reduce((sum, n) => sum + BigInt(n.value), 0n);
56
+ if (available < required) {
57
+ throw new ValidationError(`Insufficient balance for ${tokenLower}: need ${required}, have ${available}`);
58
+ }
59
+ }
60
+ // Track used note indices per token to avoid double-spending
61
+ const usedNotesByToken = new Map();
62
+ const plans = [];
63
+ for (const t of transfers) {
64
+ const tokenLower = t.token.toLowerCase();
65
+ // Get available notes for this token, excluding already-used ones
66
+ const usedIndices = usedNotesByToken.get(tokenLower) ?? new Set();
67
+ const availableNotes = notes.filter((n) => {
68
+ const noteToken = n.token;
69
+ return (noteToken &&
70
+ noteToken.toLowerCase() === tokenLower &&
71
+ !usedIndices.has(n.index));
72
+ });
73
+ // Plan this transfer using the existing planTransaction function
74
+ const plan = planTransaction(availableNotes, [{ mpk: t.recipientMpk, amount: t.amount }], senderMpk, t.token);
75
+ // Mark selected notes as used
76
+ if (!usedNotesByToken.has(tokenLower)) {
77
+ usedNotesByToken.set(tokenLower, new Set());
78
+ }
79
+ for (const input of plan.inputs) {
80
+ usedNotesByToken.get(tokenLower).add(input.index);
81
+ }
82
+ plans.push(plan);
83
+ }
84
+ return plans;
85
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Types for deposit operations.
3
+ */
4
+ import type { Account } from "../../account/account.js";
5
+ import type { NoteInput } from "./domain.js";
6
+ /**
7
+ * Parameters required to execute a deposit.
8
+ * Always accepts an array of notes - single deposits just pass [note].
9
+ */
10
+ export type DepositParams = {
11
+ /** Account with keys for signing and viewing */
12
+ account: Account;
13
+ /** Chain ID for the target blockchain */
14
+ chainId: number;
15
+ /** Pool contract address */
16
+ poolAddress: string;
17
+ /** Depositor address (on-chain account) */
18
+ depositor: string;
19
+ /** Notes to deposit (can be different tokens) */
20
+ notes: NoteInput[];
21
+ };
22
+ /**
23
+ * Individual commitment info in a deposit result.
24
+ */
25
+ export type DepositCommitmentInfo = {
26
+ /** Commitment hex string */
27
+ commitment: string;
28
+ /** Token address */
29
+ token: string;
30
+ /** Amount deposited */
31
+ amount: bigint;
32
+ };
33
+ /**
34
+ * Result of a deposit request.
35
+ * The user must submit this transaction on-chain using their EOA.
36
+ */
37
+ export type DepositRelayResult = {
38
+ /** Relay ID for tracking */
39
+ relayId: string;
40
+ /** Pool contract address to submit transaction to */
41
+ to: string;
42
+ /** Calldata to submit on-chain */
43
+ calldata: string;
44
+ /** msg.value to attach: sum of ETH note amounts, or 0n for pure ERC20 */
45
+ value: bigint;
46
+ /** Individual commitment results */
47
+ commitments: DepositCommitmentInfo[];
48
+ };
49
+ /**
50
+ * Result of syncing a pending deposit.
51
+ */
52
+ export type DepositSyncResult = {
53
+ /** Chain ID */
54
+ chainId: number;
55
+ /** Individual commitment sync results */
56
+ commitments: Array<{
57
+ /** Index of the commitment in the tree */
58
+ index: number;
59
+ /** Commitment hex string */
60
+ commitment: string;
61
+ /** Merkle root after insertion */
62
+ root: string;
63
+ }>;
64
+ /** Final merkle root after all insertions */
65
+ finalRoot: string;
66
+ };
67
+ //# sourceMappingURL=deposit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../../transactions/types/deposit.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,WAAW,EAAE,qBAAqB,EAAE,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,WAAW,EAAE,KAAK,CAAC;QACjB,0CAA0C;QAC1C,KAAK,EAAE,MAAM,CAAC;QACd,4BAA4B;QAC5B,UAAU,EAAE,MAAM,CAAC;QACnB,kCAAkC;QAClC,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Core domain types for cryptographic operations.
3
+ */
4
+ /**
5
+ * Placeholder proof structure matching the pool interface.
6
+ */
7
+ export type Proof = {
8
+ pA: [bigint, bigint];
9
+ pB: [[bigint, bigint], [bigint, bigint]];
10
+ pC: [bigint, bigint];
11
+ pubSignals: bigint[];
12
+ };
13
+ /**
14
+ * Encrypted note ciphertext.
15
+ */
16
+ export type Ciphertext = {
17
+ data: [bigint, bigint, bigint];
18
+ };
19
+ /**
20
+ * Generic note input for deposits and transaction outputs.
21
+ */
22
+ export type NoteInput = {
23
+ /** Master public key */
24
+ mpk: bigint;
25
+ /** Random nonce */
26
+ random: bigint;
27
+ /** Token address */
28
+ token: string;
29
+ /** Amount */
30
+ amount: bigint;
31
+ /** Whether this output goes to a recipient or back to sender as change */
32
+ owner?: "recipient" | "self";
33
+ };
34
+ /**
35
+ * Withdrawal note input for extracting funds from the pool.
36
+ */
37
+ export type WithdrawalNoteInput = {
38
+ /** Note public key (derived) */
39
+ npk: bigint;
40
+ /** Amount to withdraw */
41
+ amount: bigint;
42
+ /** Token address */
43
+ token: string;
44
+ };
45
+ /**
46
+ * Minimal reference to an input note.
47
+ */
48
+ export type SpendNoteReference = {
49
+ /** Index of the note in the commitment tree */
50
+ index: number;
51
+ };
52
+ /**
53
+ * Serialized witness for merkle proof.
54
+ */
55
+ export type SerializedWitness = {
56
+ /** Merkle root as hex string */
57
+ root: string;
58
+ /** Leaf value as hex string */
59
+ leaf: string;
60
+ /** Path elements (siblings) as hex strings */
61
+ pathElements: string[][];
62
+ /** Path indices for merkle proof */
63
+ pathIndices: number[];
64
+ /** Leaf index in the tree */
65
+ leafIndex: number;
66
+ };
67
+ //# sourceMappingURL=domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../transactions/types/domain.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACzC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,KAAK,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB,oCAAoC;IACpC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Core domain types for cryptographic operations.
3
+ */
4
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Transaction type definitions.
3
+ *
4
+ * Organized by concern:
5
+ * - state-stores: Database/storage interfaces
6
+ * - options: Configuration for services
7
+ * - domain: Core cryptographic types
8
+ * - deposit: Deposit-specific types
9
+ * - transact: Transaction-specific types
10
+ * - planning: Transaction planning types
11
+ */
12
+ export * from "./state-stores.js";
13
+ export * from "./options.js";
14
+ export * from "./domain.js";
15
+ export * from "./deposit.js";
16
+ export * from "./transact.js";
17
+ export * from "./planning.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../transactions/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Transaction type definitions.
3
+ *
4
+ * Organized by concern:
5
+ * - state-stores: Database/storage interfaces
6
+ * - options: Configuration for services
7
+ * - domain: Core cryptographic types
8
+ * - deposit: Deposit-specific types
9
+ * - transact: Transaction-specific types
10
+ * - planning: Transaction planning types
11
+ */
12
+ export * from "./state-stores.js";
13
+ export * from "./options.js";
14
+ export * from "./domain.js";
15
+ export * from "./deposit.js";
16
+ export * from "./transact.js";
17
+ export * from "./planning.js";
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Configuration options for transaction services.
3
+ */
4
+ import type { FetchLike } from "../../clients/http.js";
5
+ import type { LocalMerkleTrees } from "../../state/index.js";
6
+ /**
7
+ * Polling configuration for async operations.
8
+ */
9
+ export type PollingOptions = {
10
+ /** Polling interval in milliseconds */
11
+ pollIntervalMs?: number;
12
+ /** Polling timeout in milliseconds */
13
+ pollTimeoutMs?: number;
14
+ /** Initial delay before first poll (reduces 404s for fresh operations). Set to 0 in tests. */
15
+ initialPollDelayMs?: number;
16
+ };
17
+ /**
18
+ * Common options for transaction services (deposit, transact).
19
+ */
20
+ export type ServiceOptions = PollingOptions & {
21
+ /** RPC URL for the Unlink backend services */
22
+ rpcUrl: string;
23
+ /** Fetch implementation for HTTP requests */
24
+ fetch?: FetchLike;
25
+ /** Merkle tree instances for local state */
26
+ merkleTrees?: LocalMerkleTrees;
27
+ /** Timeout for proof generation in milliseconds (default: 60000) */
28
+ proofTimeoutMs?: number;
29
+ };
30
+ /**
31
+ * Options for note synchronization operations.
32
+ */
33
+ export type NoteSyncOptions = {
34
+ /** RPC URL for the Unlink backend services (required if indexerClient not provided) */
35
+ rpcUrl?: string;
36
+ /** Merkle tree instances for local state */
37
+ merkleTrees?: LocalMerkleTrees;
38
+ /** Indexer client instance (if provided, rpcUrl is not needed) */
39
+ indexerClient?: ReturnType<any>;
40
+ /** Fetch implementation for HTTP requests */
41
+ fetch?: FetchLike;
42
+ /** Batch size for fetching commitments */
43
+ limit?: number;
44
+ };
45
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../transactions/types/options.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,uCAAuC;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8FAA8F;IAC9F,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG;IAC5C,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,kEAAkE;IAElE,aAAa,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAChC,6CAA6C;IAC7C,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Types for transaction planning and note selection.
3
+ */
4
+ import type { NoteInput } from "./domain.js";
5
+ /**
6
+ * A recipient of funds in a transaction.
7
+ */
8
+ export type Recipient = {
9
+ /** Recipient's master public key */
10
+ mpk: bigint;
11
+ /** Amount to send */
12
+ amount: bigint;
13
+ };
14
+ /**
15
+ * A planned output note with derived cryptographic values.
16
+ */
17
+ export type PlannedOutput = NoteInput & {
18
+ /** Whether this output goes to a recipient or back to sender as change */
19
+ owner: "recipient" | "self";
20
+ /** Derived note public key: poseidon([mpk, random]) */
21
+ npk: bigint;
22
+ /** Derived commitment: poseidon([npk, tokenScalar, amount]) */
23
+ commitment: bigint;
24
+ };
25
+ /**
26
+ * Complete transaction plan with selected inputs, planned outputs, and circuit.
27
+ */
28
+ export type TransactionPlan<T> = {
29
+ /** Selected input notes */
30
+ inputs: SelectableNote<T>[];
31
+ /** Planned output notes (recipients + change) */
32
+ outputs: PlannedOutput[];
33
+ /** Output notes formatted for TransactParams (without derived fields) */
34
+ outputNotes: NoteInput[];
35
+ /** Selected circuit configuration */
36
+ circuit: any;
37
+ /** Total input amount from selected notes */
38
+ totalInput: bigint;
39
+ /** Total amount sent to recipients */
40
+ totalSent: bigint;
41
+ /** Change amount returned to sender */
42
+ change: bigint;
43
+ /** Token address */
44
+ token: string;
45
+ };
46
+ /**
47
+ * Minimal note representation for selection algorithm.
48
+ * Generic over T to allow passing through additional note fields.
49
+ */
50
+ export type SelectableNote<T = unknown> = T & {
51
+ /** Note index in the commitment tree */
52
+ index: number;
53
+ /** Note value */
54
+ value: bigint | string;
55
+ };
56
+ /**
57
+ * Options for note selection algorithm.
58
+ */
59
+ export type SelectionOptions = {
60
+ /** Maximum input notes to select (circuit constraint). Default: 8 */
61
+ maxInputs?: number;
62
+ /** Maximum output notes (circuit constraint). Default: 4 */
63
+ maxOutputs?: number;
64
+ /** Number of recipients (outputs excluding change). Default: 1 */
65
+ recipientCount?: number;
66
+ };
67
+ /**
68
+ * Result of note selection algorithm.
69
+ */
70
+ export type SelectionResult<T> = {
71
+ /** Selected notes, sorted by value ascending */
72
+ selected: SelectableNote<T>[];
73
+ /** Sum of selected note values */
74
+ totalInput: bigint;
75
+ /** Amount needed for transaction */
76
+ totalNeeded: bigint;
77
+ /** Change amount (totalInput - totalNeeded) */
78
+ change: bigint;
79
+ };
80
+ //# sourceMappingURL=planning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planning.d.ts","sourceRoot":"","sources":["../../../transactions/types/planning.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACtC,0EAA0E;IAC1E,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC;IAC5B,uDAAuD;IACvD,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC/B,2BAA2B;IAC3B,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,iDAAiD;IACjD,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,yEAAyE;IACzE,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,qCAAqC;IAErC,OAAO,EAAE,GAAG,CAAC;IACb,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG;IAC5C,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC/B,gDAAgD;IAChD,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9B,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};