@veilo/sdk-core 0.3.3 → 0.5.0

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 (251) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +289 -1262
  3. package/dist/cjs/accounts/admin.d.ts +84 -0
  4. package/dist/cjs/accounts/admin.js +208 -0
  5. package/dist/cjs/accounts/errors.d.ts +6 -0
  6. package/dist/cjs/accounts/errors.js +98 -0
  7. package/dist/cjs/accounts/index.d.ts +4 -0
  8. package/dist/cjs/accounts/index.js +20 -0
  9. package/dist/cjs/accounts/pdas.d.ts +23 -0
  10. package/dist/cjs/accounts/pdas.js +44 -0
  11. package/dist/cjs/accounts/queries.d.ts +41 -0
  12. package/dist/cjs/accounts/queries.js +95 -0
  13. package/dist/cjs/client.d.ts +2 -407
  14. package/dist/cjs/client.js +17 -912
  15. package/dist/cjs/cloak/client.d.ts +28 -0
  16. package/dist/cjs/cloak/client.js +68 -0
  17. package/dist/cjs/cloak/errors.d.ts +13 -0
  18. package/dist/cjs/cloak/errors.js +25 -0
  19. package/dist/cjs/cloak/helpers.d.ts +6 -0
  20. package/dist/cjs/cloak/helpers.js +35 -0
  21. package/dist/cjs/cloak/index.d.ts +6 -0
  22. package/dist/cjs/cloak/index.js +24 -0
  23. package/dist/cjs/cloak/polling.d.ts +7 -0
  24. package/dist/cjs/cloak/polling.js +66 -0
  25. package/dist/cjs/cloak/transport.d.ts +15 -0
  26. package/dist/cjs/cloak/transport.js +119 -0
  27. package/dist/cjs/cloak/types.d.ts +188 -0
  28. package/dist/cjs/cloak/types.js +5 -0
  29. package/dist/cjs/cloak.d.ts +1 -0
  30. package/dist/cjs/cloak.js +18 -0
  31. package/dist/cjs/compactNote.d.ts +128 -0
  32. package/dist/cjs/compactNote.js +191 -0
  33. package/dist/cjs/events.d.ts +1 -1
  34. package/dist/cjs/events.js +2 -2
  35. package/dist/cjs/idl/privacy_pool.d.ts +5 -0
  36. package/dist/cjs/idl/privacy_pool.js +15218 -0
  37. package/dist/cjs/index.d.ts +17 -13
  38. package/dist/cjs/index.js +43 -30
  39. package/dist/cjs/merkle.d.ts +13 -0
  40. package/dist/cjs/merkle.js +31 -8
  41. package/dist/cjs/notes/encryption.d.ts +41 -0
  42. package/dist/cjs/notes/encryption.js +75 -0
  43. package/dist/cjs/notes/index.d.ts +5 -0
  44. package/dist/cjs/notes/index.js +21 -0
  45. package/dist/cjs/notes/mailbox.d.ts +70 -0
  46. package/dist/cjs/notes/mailbox.js +164 -0
  47. package/dist/cjs/notes/model.d.ts +91 -0
  48. package/dist/cjs/notes/model.js +109 -0
  49. package/dist/cjs/notes/nullifier.d.ts +27 -0
  50. package/dist/cjs/notes/nullifier.js +45 -0
  51. package/dist/cjs/notes/recovery.d.ts +10 -0
  52. package/dist/cjs/notes/recovery.js +31 -0
  53. package/dist/cjs/program.d.ts +11 -0
  54. package/dist/cjs/program.js +26 -3
  55. package/dist/cjs/proof.d.ts +1 -183
  56. package/dist/cjs/proof.js +16 -290
  57. package/dist/cjs/proofs/encoding.d.ts +17 -0
  58. package/dist/cjs/proofs/encoding.js +72 -0
  59. package/dist/cjs/proofs/formatting.d.ts +6 -0
  60. package/dist/cjs/proofs/formatting.js +34 -0
  61. package/dist/cjs/proofs/index.d.ts +5 -0
  62. package/dist/cjs/proofs/index.js +21 -0
  63. package/dist/cjs/proofs/swap.d.ts +87 -0
  64. package/dist/cjs/proofs/swap.js +144 -0
  65. package/dist/cjs/proofs/transaction.d.ts +28 -0
  66. package/dist/cjs/proofs/transaction.js +110 -0
  67. package/dist/cjs/proofs/types.d.ts +70 -0
  68. package/dist/cjs/proofs/types.js +2 -0
  69. package/dist/cjs/prover.d.ts +4 -1
  70. package/dist/cjs/prover.js +12 -2
  71. package/dist/cjs/random.d.ts +16 -0
  72. package/dist/cjs/random.js +28 -0
  73. package/dist/cjs/relayer/client.d.ts +61 -0
  74. package/dist/cjs/relayer/client.js +151 -0
  75. package/dist/cjs/relayer/crypto.d.ts +5 -0
  76. package/dist/cjs/relayer/crypto.js +26 -0
  77. package/dist/cjs/relayer/encoding.d.ts +2 -0
  78. package/dist/cjs/relayer/encoding.js +23 -0
  79. package/dist/cjs/relayer/errors.d.ts +7 -0
  80. package/dist/cjs/relayer/errors.js +17 -0
  81. package/dist/cjs/relayer/index.d.ts +3 -0
  82. package/dist/cjs/relayer/index.js +19 -0
  83. package/dist/cjs/relayer/transport.d.ts +17 -0
  84. package/dist/cjs/relayer/transport.js +63 -0
  85. package/dist/cjs/relayer/types.d.ts +276 -0
  86. package/dist/cjs/relayer/types.js +5 -0
  87. package/dist/cjs/relayer.d.ts +1 -295
  88. package/dist/cjs/relayer.js +15 -243
  89. package/dist/cjs/shield/alt.d.ts +87 -0
  90. package/dist/cjs/shield/alt.js +194 -0
  91. package/dist/cjs/shield/computeBudget.d.ts +61 -0
  92. package/dist/cjs/shield/computeBudget.js +64 -0
  93. package/dist/cjs/shield/errors.d.ts +58 -0
  94. package/dist/cjs/shield/errors.js +121 -0
  95. package/dist/cjs/shield/finalize.d.ts +45 -0
  96. package/dist/cjs/shield/finalize.js +119 -0
  97. package/dist/cjs/shield/index.d.ts +35 -0
  98. package/dist/cjs/shield/index.js +68 -0
  99. package/dist/cjs/shield/ix.d.ts +54 -0
  100. package/dist/cjs/shield/ix.js +119 -0
  101. package/dist/cjs/shield/owner.d.ts +36 -0
  102. package/dist/cjs/shield/owner.js +127 -0
  103. package/dist/cjs/shield/ports.d.ts +43 -0
  104. package/dist/cjs/shield/ports.js +153 -0
  105. package/dist/cjs/shield/preflight.d.ts +30 -0
  106. package/dist/cjs/shield/preflight.js +154 -0
  107. package/dist/cjs/shield/shield.d.ts +68 -0
  108. package/dist/cjs/shield/shield.js +500 -0
  109. package/dist/cjs/shield/types.d.ts +202 -0
  110. package/dist/cjs/shield/types.js +2 -0
  111. package/dist/cjs/transactions/deposit.d.ts +94 -0
  112. package/dist/cjs/transactions/deposit.js +234 -0
  113. package/dist/cjs/transactions/index.d.ts +7 -0
  114. package/dist/cjs/transactions/index.js +26 -0
  115. package/dist/cjs/transactions/swap.d.ts +71 -0
  116. package/dist/cjs/transactions/swap.js +184 -0
  117. package/dist/cjs/transactions/transact.d.ts +34 -0
  118. package/dist/cjs/transactions/transact.js +146 -0
  119. package/dist/cjs/transactions/transfer.d.ts +51 -0
  120. package/dist/cjs/transactions/transfer.js +106 -0
  121. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  122. package/dist/cjs/transactions/withdraw.js +104 -0
  123. package/dist/cjs/utxo.d.ts +1 -215
  124. package/dist/cjs/utxo.js +15 -391
  125. package/dist/esm/accounts/admin.d.ts +84 -0
  126. package/dist/esm/accounts/admin.js +165 -0
  127. package/dist/esm/accounts/errors.d.ts +6 -0
  128. package/dist/esm/accounts/errors.js +95 -0
  129. package/dist/esm/accounts/index.d.ts +4 -0
  130. package/dist/esm/accounts/index.js +4 -0
  131. package/dist/esm/accounts/pdas.d.ts +23 -0
  132. package/dist/esm/accounts/pdas.js +38 -0
  133. package/dist/esm/accounts/queries.d.ts +41 -0
  134. package/dist/esm/accounts/queries.js +88 -0
  135. package/dist/esm/client.d.ts +2 -0
  136. package/dist/esm/client.js +3 -887
  137. package/dist/esm/cloak/client.d.ts +28 -0
  138. package/dist/esm/cloak/client.js +64 -0
  139. package/dist/esm/cloak/errors.d.ts +13 -0
  140. package/dist/esm/cloak/errors.js +21 -0
  141. package/dist/esm/cloak/helpers.d.ts +6 -0
  142. package/dist/esm/cloak/helpers.js +31 -0
  143. package/dist/esm/cloak/index.d.ts +6 -0
  144. package/dist/esm/cloak/index.js +6 -0
  145. package/dist/esm/cloak/polling.d.ts +7 -0
  146. package/dist/esm/cloak/polling.js +63 -0
  147. package/dist/esm/cloak/transport.d.ts +15 -0
  148. package/dist/esm/cloak/transport.js +115 -0
  149. package/dist/esm/cloak/types.d.ts +188 -0
  150. package/dist/esm/cloak/types.js +4 -0
  151. package/dist/esm/cloak.d.ts +1 -0
  152. package/dist/esm/cloak.js +2 -0
  153. package/dist/esm/compactNote.d.ts +128 -0
  154. package/dist/esm/compactNote.js +179 -0
  155. package/dist/esm/config.d.ts +82 -0
  156. package/dist/esm/events.d.ts +77 -0
  157. package/dist/esm/events.js +1 -1
  158. package/dist/esm/idl/privacy_pool.d.ts +5 -0
  159. package/dist/esm/idl/privacy_pool.js +15216 -0
  160. package/dist/esm/index.d.ts +17 -0
  161. package/dist/esm/index.js +20 -11
  162. package/dist/esm/merkle.d.ts +77 -0
  163. package/dist/esm/merkle.js +23 -1
  164. package/dist/esm/notes/encryption.d.ts +41 -0
  165. package/dist/esm/notes/encryption.js +67 -0
  166. package/dist/esm/notes/index.d.ts +5 -0
  167. package/dist/esm/notes/index.js +5 -0
  168. package/dist/esm/notes/mailbox.d.ts +70 -0
  169. package/dist/esm/notes/mailbox.js +154 -0
  170. package/dist/esm/notes/model.d.ts +91 -0
  171. package/dist/esm/notes/model.js +99 -0
  172. package/dist/esm/notes/nullifier.d.ts +27 -0
  173. package/dist/esm/notes/nullifier.js +40 -0
  174. package/dist/esm/notes/recovery.d.ts +10 -0
  175. package/dist/esm/notes/recovery.js +28 -0
  176. package/dist/esm/package.json +1 -0
  177. package/dist/esm/poseidon.d.ts +29 -0
  178. package/dist/esm/program.d.ts +37 -0
  179. package/dist/esm/program.js +23 -1
  180. package/dist/esm/proof.d.ts +1 -0
  181. package/dist/esm/proof.js +2 -281
  182. package/dist/esm/proofs/encoding.d.ts +17 -0
  183. package/dist/esm/proofs/encoding.js +68 -0
  184. package/dist/esm/proofs/formatting.d.ts +6 -0
  185. package/dist/esm/proofs/formatting.js +31 -0
  186. package/dist/esm/proofs/index.d.ts +5 -0
  187. package/dist/esm/proofs/index.js +5 -0
  188. package/dist/esm/proofs/swap.d.ts +87 -0
  189. package/dist/esm/proofs/swap.js +138 -0
  190. package/dist/esm/proofs/transaction.d.ts +28 -0
  191. package/dist/esm/proofs/transaction.js +105 -0
  192. package/dist/esm/proofs/types.d.ts +70 -0
  193. package/dist/esm/proofs/types.js +1 -0
  194. package/dist/esm/prover.d.ts +57 -0
  195. package/dist/esm/prover.js +10 -1
  196. package/dist/esm/random.d.ts +16 -0
  197. package/dist/esm/random.js +21 -0
  198. package/dist/esm/relayer/client.d.ts +61 -0
  199. package/dist/esm/relayer/client.js +144 -0
  200. package/dist/esm/relayer/crypto.d.ts +5 -0
  201. package/dist/esm/relayer/crypto.js +20 -0
  202. package/dist/esm/relayer/encoding.d.ts +2 -0
  203. package/dist/esm/relayer/encoding.js +19 -0
  204. package/dist/esm/relayer/errors.d.ts +7 -0
  205. package/dist/esm/relayer/errors.js +13 -0
  206. package/dist/esm/relayer/index.d.ts +3 -0
  207. package/dist/esm/relayer/index.js +3 -0
  208. package/dist/esm/relayer/transport.d.ts +17 -0
  209. package/dist/esm/relayer/transport.js +59 -0
  210. package/dist/esm/relayer/types.d.ts +276 -0
  211. package/dist/esm/relayer/types.js +4 -0
  212. package/dist/esm/relayer.d.ts +1 -0
  213. package/dist/esm/relayer.js +2 -238
  214. package/dist/esm/retry.d.ts +32 -0
  215. package/dist/esm/shield/alt.d.ts +87 -0
  216. package/dist/esm/shield/alt.js +186 -0
  217. package/dist/esm/shield/computeBudget.d.ts +61 -0
  218. package/dist/esm/shield/computeBudget.js +61 -0
  219. package/dist/esm/shield/errors.d.ts +58 -0
  220. package/dist/esm/shield/errors.js +115 -0
  221. package/dist/esm/shield/finalize.d.ts +45 -0
  222. package/dist/esm/shield/finalize.js +83 -0
  223. package/dist/esm/shield/index.d.ts +35 -0
  224. package/dist/esm/shield/index.js +32 -0
  225. package/dist/esm/shield/ix.d.ts +54 -0
  226. package/dist/esm/shield/ix.js +82 -0
  227. package/dist/esm/shield/owner.d.ts +36 -0
  228. package/dist/esm/shield/owner.js +123 -0
  229. package/dist/esm/shield/ports.d.ts +43 -0
  230. package/dist/esm/shield/ports.js +147 -0
  231. package/dist/esm/shield/preflight.d.ts +30 -0
  232. package/dist/esm/shield/preflight.js +151 -0
  233. package/dist/esm/shield/shield.d.ts +68 -0
  234. package/dist/esm/shield/shield.js +493 -0
  235. package/dist/esm/shield/types.d.ts +202 -0
  236. package/dist/esm/shield/types.js +1 -0
  237. package/dist/esm/transactions/deposit.d.ts +94 -0
  238. package/dist/esm/transactions/deposit.js +198 -0
  239. package/dist/esm/transactions/index.d.ts +7 -0
  240. package/dist/esm/transactions/index.js +7 -0
  241. package/dist/esm/transactions/swap.d.ts +71 -0
  242. package/dist/esm/transactions/swap.js +144 -0
  243. package/dist/esm/transactions/transact.d.ts +34 -0
  244. package/dist/esm/transactions/transact.js +110 -0
  245. package/dist/esm/transactions/transfer.d.ts +51 -0
  246. package/dist/esm/transactions/transfer.js +103 -0
  247. package/dist/esm/transactions/withdraw.d.ts +52 -0
  248. package/dist/esm/transactions/withdraw.js +101 -0
  249. package/dist/esm/utxo.d.ts +1 -0
  250. package/dist/esm/utxo.js +2 -372
  251. package/package.json +111 -15
@@ -0,0 +1,202 @@
1
+ import { AddressLookupTableAccount, Connection, PublicKey, VersionedTransaction } from "@solana/web3.js";
2
+ import type { TransactionProofBuilder, TransactionProofStruct } from "../proofs/types.js";
3
+ import type { CompactNoteCipher } from "../compactNote.js";
4
+ /**
5
+ * Who owns the resulting note. Both halves are required and neither is derived
6
+ * from the other:
7
+ *
8
+ * - `veiloPublicKey` is the Poseidon field element bound into the output
9
+ * commitment. It is the **spending** authority.
10
+ * - `noteViewingKey` is the Ed25519 wallet key the compact cipher is encrypted
11
+ * to. It is the **detection** authority.
12
+ *
13
+ * If these two belong to different people, the note is *spendable but
14
+ * invisible*: the owner can never find it, so the funds are effectively gone.
15
+ * Nothing on-chain and nothing in this type can detect that — which is why
16
+ * `resolveShieldOwner()` exists and why hand-constructing this requires an
17
+ * explicit acknowledgement.
18
+ *
19
+ * See veilo-browser-extension/.../privateStealthWallet.ts:403-415 for the
20
+ * production comment describing this failure mode.
21
+ */
22
+ export type ShieldOwner = {
23
+ veiloPublicKey: bigint;
24
+ noteViewingKey: PublicKey;
25
+ /**
26
+ * Set automatically by {@link resolveShieldOwner}, which fetches both halves
27
+ * from a single relayer response and can therefore guarantee they match.
28
+ *
29
+ * Hand-built owners must set this explicitly — it is the only mechanism
30
+ * standing between an integration mistake and silent fund loss.
31
+ */
32
+ acknowledgeOwnerInvariant?: true;
33
+ };
34
+ /**
35
+ * Who signs and pays. Public key only — the SDK never receives a secret key.
36
+ *
37
+ * The signer is unavoidably the fee payer, the funding source, and the payer of
38
+ * ~0.00192 SOL of nullifier-marker rent (the program hardcodes
39
+ * `payer = relayer` on both marker accounts). A wallet with no SOL cannot
40
+ * shield through this path regardless of who submits the transaction.
41
+ */
42
+ export type ShieldSigner = {
43
+ publicKey: PublicKey;
44
+ /**
45
+ * Source token account for SPL shields. Defaults to the signer's canonical
46
+ * ATA. Must be owned by `publicKey` with no delegate set.
47
+ */
48
+ tokenAccount?: PublicKey;
49
+ };
50
+ /** Where the target tree and its root come from. */
51
+ export interface TreeSource {
52
+ getDepositTarget(mint: PublicKey): Promise<DepositTarget>;
53
+ }
54
+ export type DepositTarget = {
55
+ /** Always 0 — the tree whose root the dummy inputs nominally prove against. */
56
+ inputTreeId: number;
57
+ /** 32-byte root, read from that tree's on-chain root history. */
58
+ inputRoot: Uint8Array;
59
+ /** Tree the new commitments are appended to. */
60
+ outputTreeId: number;
61
+ /** `nextIndex` at build time. A prediction — see `predictedLeafIndex`. */
62
+ outputNextIndex: number;
63
+ };
64
+ /** Where the address lookup table comes from. */
65
+ export interface AltSource {
66
+ resolve(ctx: {
67
+ connection: Connection;
68
+ mint: PublicKey;
69
+ outputTreeId: number;
70
+ programId: PublicKey;
71
+ }): Promise<AddressLookupTableAccount>;
72
+ }
73
+ /**
74
+ * Caching for values that are stable across builds (the ALT account, rent
75
+ * exemption minimums, pool config).
76
+ *
77
+ * Deliberately an interface: the three production deposit implementations
78
+ * differ on exactly this axis — `localStorage`, `chrome.storage`, and
79
+ * `AsyncStorage` — and none of them belongs in a published SDK.
80
+ */
81
+ export interface ShieldCachePort {
82
+ get<T>(key: string): Promise<T | undefined>;
83
+ set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
84
+ }
85
+ export type PreflightOptions = {
86
+ /** Skip the SPL token-account inspection (owner, delegate, balance). */
87
+ skipTokenAccount?: boolean;
88
+ /** Skip the signer balance check. */
89
+ skipBalance?: boolean;
90
+ /** Skip pool state checks (paused, min/max, tree capacity). */
91
+ skipPoolState?: boolean;
92
+ };
93
+ export type ShieldParams = {
94
+ connection: Connection;
95
+ /** Net amount to shield, in base units. No fee is taken on deposits. */
96
+ amount: bigint;
97
+ /** Defaults to native SOL. */
98
+ mint?: PublicKey;
99
+ owner: ShieldOwner;
100
+ signer: ShieldSigner;
101
+ /** Proof generation. `createTransactionProver(artifacts)` satisfies this. */
102
+ prover: TransactionProofBuilder;
103
+ treeSource?: TreeSource;
104
+ alt?: AltSource;
105
+ cache?: ShieldCachePort;
106
+ programId?: PublicKey;
107
+ computeUnitLimit?: number;
108
+ /** Set to 0 to omit the priority-fee instruction entirely. */
109
+ computeUnitPriceMicroLamports?: number;
110
+ deadlineSeconds?: number;
111
+ /** Supply to avoid an RPC round-trip; otherwise fetched just before compiling. */
112
+ blockhash?: {
113
+ blockhash: string;
114
+ lastValidBlockHeight: number;
115
+ };
116
+ preflight?: boolean | PreflightOptions;
117
+ };
118
+ /**
119
+ * The recoverable secret material for the note this shield creates.
120
+ *
121
+ * SECRET. Anyone holding this can locate the note. It must never be persisted
122
+ * server-side in the clear or transmitted alongside {@link ShieldProofCache},
123
+ * which is deliberately public.
124
+ */
125
+ export type ShieldNote = {
126
+ commitment: Uint8Array;
127
+ blinding: bigint;
128
+ amount: bigint;
129
+ ownerVeiloPublicKey: bigint;
130
+ mint: PublicKey;
131
+ treeId: number;
132
+ compact: CompactNoteCipher;
133
+ };
134
+ /**
135
+ * Everything needed to re-assemble the transaction with a fresh blockhash.
136
+ *
137
+ * PUBLIC and JSON-serializable by construction: it carries no blinding, no
138
+ * private key, and no note plaintext. A platform can build server-side, ship
139
+ * this to a client for signature, and rebuild in a different process without
140
+ * ever moving a secret.
141
+ */
142
+ export type ShieldProofCache = {
143
+ version: 1;
144
+ programId: string;
145
+ mint: string;
146
+ signer: string;
147
+ altAddress: string;
148
+ inputTreeId: number;
149
+ outputTreeId: number;
150
+ root: string;
151
+ publicAmount: string;
152
+ extData: {
153
+ recipient: string;
154
+ relayer: string;
155
+ fee: string;
156
+ refund: string;
157
+ claimant: string;
158
+ };
159
+ extDataHash: string;
160
+ inputNullifiers: [string, string];
161
+ outputCommitments: [string, string];
162
+ proof: TransactionProofStruct;
163
+ noteCiphers: {
164
+ note0EphemeralKey: string;
165
+ note0Encrypted: string;
166
+ note0ViewTag: number;
167
+ note1EphemeralKey: string;
168
+ note1Encrypted: string;
169
+ note1ViewTag: number;
170
+ };
171
+ /** Resolved instruction accounts, keyed by IDL account name. */
172
+ accounts: Record<string, string>;
173
+ computeUnitLimit: number;
174
+ };
175
+ export type ShieldQuote = {
176
+ /** Serialized size including the signature. Must be <= 1232. */
177
+ serializedSize: number;
178
+ computeUnitLimit: number;
179
+ computeUnitPriceMicroLamports: number;
180
+ estimatedFeeLamports: bigint;
181
+ /** Nullifier-marker rent, permanently burned by the signer. */
182
+ estimatedRentLamports: bigint;
183
+ };
184
+ export type ShieldResult = {
185
+ /** UNSIGNED. The caller signs and submits — this SDK never broadcasts. */
186
+ transaction: VersionedTransaction;
187
+ blockhash: string;
188
+ lastValidBlockHeight: number;
189
+ deadline: bigint;
190
+ note: ShieldNote;
191
+ /**
192
+ * Leaf index the output commitment is *expected* to land at.
193
+ *
194
+ * A prediction, read before submission. Under concurrent deposits into the
195
+ * same tree it will be wrong. Use `finalizeShield()` to read the authoritative
196
+ * index from the confirmed transaction's `CommitmentEvent` before persisting
197
+ * anything that depends on it.
198
+ */
199
+ predictedLeafIndex: number;
200
+ quote: ShieldQuote;
201
+ proofCache: ShieldProofCache;
202
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,94 @@
1
+ import type { Program, Idl } from "@coral-xyz/anchor";
2
+ import { PublicKey, Transaction } from "@solana/web3.js";
3
+ import type { ExtData, TransactionProofBuilder } from "../proofs/types.js";
4
+ import type { SerializedUTXO } from "../notes/model.js";
5
+ import { MerkleTree } from "../merkle.js";
6
+ import { type NoteCiphers } from "../compactNote.js";
7
+ /**
8
+ * Result of a deposit operation, produced by `DepositBuild.commit()` after the
9
+ * caller has successfully submitted the deposit transaction on-chain.
10
+ */
11
+ export type DepositResult = {
12
+ /** The output UTXOs created by the deposit */
13
+ outputUTXOs: [SerializedUTXO, SerializedUTXO];
14
+ /** The leaf indices where the UTXOs were inserted */
15
+ leafIndices: [number, number];
16
+ /** The new Merkle root after insertion */
17
+ root: Uint8Array;
18
+ };
19
+ /**
20
+ * The return of `deposit()`. Instead of submitting the transaction itself,
21
+ * `deposit()` hands back an unsigned {@link Transaction} so the caller can
22
+ * sign it with whatever wallet they control (Solana wallet-adapter, Ledger,
23
+ * anchor NodeWallet, etc.) and submit it on their own terms.
24
+ *
25
+ * Usage pattern (browser / wallet-adapter):
26
+ *
27
+ * const { transaction, commit } = await deposit({ ... });
28
+ * const signed = await wallet.signTransaction(transaction);
29
+ * const sig = await connection.sendRawTransaction(signed.serialize());
30
+ * await connection.confirmTransaction(sig, "confirmed");
31
+ * const result = commit(); // updates the local tree, returns DepositResult
32
+ */
33
+ export type DepositBuild = {
34
+ /**
35
+ * Unsigned {@link Transaction} for the deposit. `feePayer` and
36
+ * `recentBlockhash` are already populated, so the caller only needs to sign
37
+ * and send.
38
+ */
39
+ transaction: Transaction;
40
+ /**
41
+ * Output UTXOs created by this deposit. Safe to read before submission —
42
+ * the commitment values are deterministic from the circuit inputs and do
43
+ * not depend on the on-chain result.
44
+ */
45
+ outputUTXOs: [SerializedUTXO, SerializedUTXO];
46
+ /**
47
+ * Inserts the two output commitments into the local {@link MerkleTree} and
48
+ * returns the receipt. Call this **only after** the on-chain transaction
49
+ * has been confirmed — deferring the insert keeps the local tree
50
+ * consistent with chain state if the submission fails.
51
+ *
52
+ * Calling `commit()` more than once is unsupported and will corrupt the
53
+ * local tree.
54
+ */
55
+ commit: () => DepositResult;
56
+ };
57
+ /**
58
+ * Build an unsigned deposit {@link Transaction} for the privacy pool.
59
+ *
60
+ * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs
61
+ * with the deposit amount. `publicAmount` is positive. The caller is
62
+ * responsible for signing and submitting the returned transaction, and then
63
+ * calling `commit()` once it confirms.
64
+ *
65
+ * @param amount - Amount to deposit in lamports/token units
66
+ * @param recipientPubkey - UTXO public key that will own the deposited funds
67
+ * @param treeId - The tree ID to deposit into (defaults to 0)
68
+ */
69
+ export declare function deposit<T extends Idl>(params: {
70
+ program: Program<T>;
71
+ /**
72
+ * Account that will pay for and sign the deposit transaction. Only
73
+ * `publicKey` is read — `deposit()` never touches a secret key. A browser
74
+ * wallet-adapter wallet, a Node `anchor.Wallet`, or a raw `Keypair` are all
75
+ * structurally acceptable.
76
+ */
77
+ depositor: {
78
+ publicKey: PublicKey;
79
+ };
80
+ amount: bigint;
81
+ mintAddress: PublicKey;
82
+ recipientPubkey: bigint;
83
+ tree: MerkleTree;
84
+ proofBuilder: TransactionProofBuilder;
85
+ treeId?: number;
86
+ extData?: Partial<ExtData>;
87
+ /** Solana wallet key used to make output note 0 recoverable from chain events. */
88
+ noteRecipientWallet?: PublicKey | Uint8Array;
89
+ /** Prebuilt recovery payload. Takes precedence over noteRecipientWallet. */
90
+ noteCiphers?: NoteCiphers | null;
91
+ }): Promise<DepositBuild>;
92
+ /**
93
+ * Result of a withdrawal operation.
94
+ */
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.deposit = deposit;
37
+ const anchor = __importStar(require("@coral-xyz/anchor"));
38
+ const web3_js_1 = require("@solana/web3.js");
39
+ const spl_token_1 = require("@solana/spl-token");
40
+ const transaction_js_1 = require("../proofs/transaction.js");
41
+ const encoding_js_1 = require("../proofs/encoding.js");
42
+ const model_js_1 = require("../notes/model.js");
43
+ const config_js_1 = require("../config.js");
44
+ const poseidon_js_1 = require("../poseidon.js");
45
+ const compactNote_js_1 = require("../compactNote.js");
46
+ const pdas_js_1 = require("../accounts/pdas.js");
47
+ // Anchor is CJS and does not expose BN as a detectable Node ESM named export.
48
+ const { BN } = anchor;
49
+ /**
50
+ * Build an unsigned deposit {@link Transaction} for the privacy pool.
51
+ *
52
+ * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs
53
+ * with the deposit amount. `publicAmount` is positive. The caller is
54
+ * responsible for signing and submitting the returned transaction, and then
55
+ * calling `commit()` once it confirms.
56
+ *
57
+ * @param amount - Amount to deposit in lamports/token units
58
+ * @param recipientPubkey - UTXO public key that will own the deposited funds
59
+ * @param treeId - The tree ID to deposit into (defaults to 0)
60
+ */
61
+ async function deposit(params) {
62
+ const { program, depositor, amount, mintAddress, recipientPubkey, tree, proofBuilder, treeId = 0, extData: partialExtData, noteRecipientWallet, noteCiphers, } = params;
63
+ if (amount <= 0n) {
64
+ throw new Error("Deposit amount must be positive");
65
+ }
66
+ // Create zero input UTXOs (for deposits, we don't spend any existing UTXOs)
67
+ const zeroKeypair0 = (0, model_js_1.generateKeypair)();
68
+ const zeroKeypair1 = (0, model_js_1.generateKeypair)();
69
+ const zeroInput0 = (0, model_js_1.createOwnedZeroUTXO)(zeroKeypair0.privateKey, mintAddress);
70
+ const zeroInput1 = (0, model_js_1.createOwnedZeroUTXO)(zeroKeypair1.privateKey, mintAddress);
71
+ // The circuit skips the Merkle proof check for zero-amount inputs (amount == 0
72
+ // causes `enabled = 0` in MerkleProofIfEnabled). So we provide a dummy path using
73
+ // the tree's pre-computed zero chain without inserting anything into the tree.
74
+ const dummyPath = tree.zeroes.slice(0, tree.depth);
75
+ const currentRoot = tree.root;
76
+ const inputUTXOs = [
77
+ {
78
+ ...zeroInput0,
79
+ pathIndex: 0,
80
+ pathElements: dummyPath,
81
+ privateKey: zeroKeypair0.privateKey,
82
+ },
83
+ {
84
+ ...zeroInput1,
85
+ pathIndex: 0,
86
+ pathElements: dummyPath,
87
+ privateKey: zeroKeypair1.privateKey,
88
+ },
89
+ ];
90
+ const outputUTXO0 = (0, model_js_1.createUTXO)({
91
+ amount: amount,
92
+ pubkey: recipientPubkey,
93
+ mintAddress,
94
+ });
95
+ const outputUTXO1 = (0, model_js_1.createUTXO)({
96
+ amount: 0n,
97
+ pubkey: (0, model_js_1.generateKeypair)().publicKey,
98
+ mintAddress,
99
+ });
100
+ const outputUTXOs = [
101
+ outputUTXO0,
102
+ outputUTXO1,
103
+ ];
104
+ const depositorPubkey = depositor.publicKey;
105
+ const extData = {
106
+ recipient: partialExtData?.recipient ?? depositorPubkey,
107
+ relayer: partialExtData?.relayer ?? depositorPubkey,
108
+ fee: partialExtData?.fee ?? 0n,
109
+ refund: partialExtData?.refund ?? 0n,
110
+ claimant: partialExtData?.claimant ?? web3_js_1.SystemProgram.programId,
111
+ };
112
+ if (!extData.relayer.equals(depositorPubkey)) {
113
+ throw new Error("Deposit extData.relayer must be the signing depositor");
114
+ }
115
+ if (extData.fee !== 0n || extData.refund !== 0n) {
116
+ throw new Error("Deposits require extData fee and refund to be zero");
117
+ }
118
+ const circuitInputs = (0, transaction_js_1.prepareTransactionInputs)({
119
+ inputUTXOs,
120
+ outputUTXOs,
121
+ root: currentRoot,
122
+ publicAmount: amount, // Positive for deposits
123
+ extData,
124
+ mintAddress,
125
+ });
126
+ const rawProof = await proofBuilder(circuitInputs);
127
+ const proof = (0, encoding_js_1.encodeSnarkjsProofToTransactionProof)(rawProof);
128
+ const depositNoteCiphers = noteCiphers !== undefined
129
+ ? noteCiphers
130
+ : noteRecipientWallet
131
+ ? (0, compactNote_js_1.createNoteCiphers)({
132
+ recipientWalletPubkey: noteRecipientWallet instanceof web3_js_1.PublicKey
133
+ ? noteRecipientWallet.toBytes()
134
+ : noteRecipientWallet,
135
+ blinding: (0, poseidon_js_1.bigIntToBytesBE)(outputUTXO0.blinding),
136
+ amount: outputUTXO0.amount,
137
+ }, null)
138
+ : null;
139
+ // -----------------------------------------------------------------------
140
+ // Build the transact instruction inline because deposits return an unsigned
141
+ // wallet-signable transaction while `transact()` submits with a Keypair.
142
+ //
143
+ // We intentionally don't reuse the `transact()` helper: it submits via
144
+ // anchor's `.rpc()` with `.signers([relayer])`, which assumes the caller
145
+ // holds a real Keypair. For deposit, we want to return an unsigned
146
+ // Transaction so the caller (typically a browser wallet) can sign it.
147
+ // -----------------------------------------------------------------------
148
+ const { config, vault, nullifiers } = (0, pdas_js_1.getPoolPdas)(program.programId, mintAddress);
149
+ const globalConfig = (0, pdas_js_1.getGlobalConfigPda)(program.programId);
150
+ const inputTree = (0, pdas_js_1.getNoteTreePda)(program.programId, mintAddress, treeId);
151
+ const outputTree = (0, pdas_js_1.getNoteTreePda)(program.programId, mintAddress, treeId);
152
+ const nullifierMarker0 = (0, pdas_js_1.getNullifierMarkerPda)(program.programId, mintAddress, circuitInputs.inputNullifiers[0]);
153
+ const nullifierMarker1 = (0, pdas_js_1.getNullifierMarkerPda)(program.programId, mintAddress, circuitInputs.inputNullifiers[1]);
154
+ const extDataHash = (0, transaction_js_1.computeExtDataHash)(extData);
155
+ const isNativeSol = mintAddress.equals(config_js_1.NATIVE_SOL_MINT);
156
+ let vaultTA;
157
+ let userTA;
158
+ let recipientTA;
159
+ let relayerTA;
160
+ if (!isNativeSol) {
161
+ vaultTA = await (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, vault, true);
162
+ userTA = await (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, depositorPubkey);
163
+ recipientTA = await (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, extData.recipient);
164
+ relayerTA = await (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, depositorPubkey);
165
+ }
166
+ const builtTx = await program.methods
167
+ .transact(Array.from(currentRoot), treeId, treeId, new BN(amount.toString()), Array.from(extDataHash), mintAddress, Array.from(circuitInputs.inputNullifiers[0]), Array.from(circuitInputs.inputNullifiers[1]), Array.from(circuitInputs.outputCommitments[0]), Array.from(circuitInputs.outputCommitments[1]), new BN(Math.floor(Date.now() / 1000) + 3600), // 1-hour window from build time
168
+ {
169
+ recipient: extData.recipient,
170
+ relayer: extData.relayer,
171
+ fee: new BN(extData.fee.toString()),
172
+ refund: new BN(extData.refund.toString()),
173
+ claimant: extData.claimant,
174
+ }, {
175
+ proofA: proof.proofA,
176
+ proofB: proof.proofB,
177
+ proofC: proof.proofC,
178
+ }, depositNoteCiphers
179
+ ? {
180
+ note0EphemeralKey: Array.from(depositNoteCiphers.note0EphemeralKey),
181
+ note0Encrypted: Array.from(depositNoteCiphers.note0Encrypted),
182
+ note0ViewTag: depositNoteCiphers.note0ViewTag,
183
+ note1EphemeralKey: Array.from(depositNoteCiphers.note1EphemeralKey),
184
+ note1Encrypted: Array.from(depositNoteCiphers.note1Encrypted),
185
+ note1ViewTag: depositNoteCiphers.note1ViewTag,
186
+ }
187
+ : null)
188
+ .accountsStrict({
189
+ config,
190
+ globalConfig,
191
+ vault,
192
+ inputTree,
193
+ outputTree,
194
+ nullifiers,
195
+ nullifierMarker0,
196
+ nullifierMarker1,
197
+ relayer: depositorPubkey,
198
+ recipient: extData.recipient,
199
+ vaultTokenAccount: vaultTA ?? depositorPubkey,
200
+ userTokenAccount: userTA ?? depositorPubkey,
201
+ recipientTokenAccount: recipientTA ?? extData.recipient,
202
+ relayerTokenAccount: relayerTA ?? depositorPubkey,
203
+ tokenProgram: isNativeSol ? web3_js_1.SystemProgram.programId : spl_token_1.TOKEN_PROGRAM_ID,
204
+ systemProgram: web3_js_1.SystemProgram.programId,
205
+ })
206
+ .transaction();
207
+ // Add compute budget instruction for higher CU limit
208
+ const computeBudgetIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
209
+ units: 1000000,
210
+ });
211
+ builtTx.instructions.unshift(computeBudgetIx);
212
+ // Populate feePayer + recentBlockhash so the wallet only has to sign.
213
+ const provider = program.provider;
214
+ builtTx.feePayer = depositorPubkey;
215
+ const { blockhash } = await provider.connection.getLatestBlockhash();
216
+ builtTx.recentBlockhash = blockhash;
217
+ const commit = () => {
218
+ const { index: outIdx0 } = tree.insert(outputUTXOs[0].commitment);
219
+ const { index: outIdx1, root: newRoot } = tree.insert(outputUTXOs[1].commitment);
220
+ return {
221
+ outputUTXOs,
222
+ leafIndices: [outIdx0, outIdx1],
223
+ root: newRoot,
224
+ };
225
+ };
226
+ return {
227
+ transaction: builtTx,
228
+ outputUTXOs,
229
+ commit,
230
+ };
231
+ }
232
+ /**
233
+ * Result of a withdrawal operation.
234
+ */
@@ -0,0 +1,7 @@
1
+ export * from "./transact.js";
2
+ export * from "./deposit.js";
3
+ export * from "./withdraw.js";
4
+ export * from "./transfer.js";
5
+ export * from "./swap.js";
6
+ export { buildTransactInstruction as buildRawTransactInstruction, TRANSACT_ACCOUNT_NAMES, } from "../shield/ix.js";
7
+ export type { TransactAccounts as RawTransactAccounts, TransactArgs as RawTransactArgs, } from "../shield/ix.js";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TRANSACT_ACCOUNT_NAMES = exports.buildRawTransactInstruction = void 0;
18
+ __exportStar(require("./transact.js"), exports);
19
+ __exportStar(require("./deposit.js"), exports);
20
+ __exportStar(require("./withdraw.js"), exports);
21
+ __exportStar(require("./transfer.js"), exports);
22
+ __exportStar(require("./swap.js"), exports);
23
+ // Raw IDL-correct builder for custom v0/ALT transaction composition.
24
+ var ix_js_1 = require("../shield/ix.js");
25
+ Object.defineProperty(exports, "buildRawTransactInstruction", { enumerable: true, get: function () { return ix_js_1.buildTransactInstruction; } });
26
+ Object.defineProperty(exports, "TRANSACT_ACCOUNT_NAMES", { enumerable: true, get: function () { return ix_js_1.TRANSACT_ACCOUNT_NAMES; } });
@@ -0,0 +1,71 @@
1
+ import type { Idl, Program } from "@coral-xyz/anchor";
2
+ import { Keypair, PublicKey, type AccountMeta, type TransactionInstruction } from "@solana/web3.js";
3
+ import type { ExtData, TransactionProofStruct } from "../proofs/types.js";
4
+ import type { NoteCiphers } from "../compactNote.js";
5
+ /** Seeds: ["swap_executor", source_mint, dest_mint, nullifier_0, relayer]. */
6
+ export declare function getSwapExecutorPda(programId: PublicKey, sourceMint: PublicKey, destMint: PublicKey, inputNullifier0: Uint8Array, relayer: PublicKey): PublicKey;
7
+ /** Build `fund_native_source`. It must immediately precede `transact_swap`. */
8
+ export declare function fundNativeSource<T extends Idl>(params: {
9
+ program: Program<T>;
10
+ relayer: {
11
+ publicKey: PublicKey;
12
+ };
13
+ sourceMint: PublicKey;
14
+ destMint: PublicKey;
15
+ inputNullifier0: Uint8Array;
16
+ swapAmount: bigint;
17
+ /** Wrapped-native mint used by the DEX. Defaults to canonical WSOL. */
18
+ sourceMintAccount?: PublicKey;
19
+ }): Promise<TransactionInstruction>;
20
+ export type SwapProofStruct = TransactionProofStruct;
21
+ /** Fields in the current IDL's `SwapParams` struct. */
22
+ export type SwapParams = {
23
+ minAmountOut: bigint;
24
+ deadline: bigint;
25
+ destAmount: bigint;
26
+ /** SHA-256 of the exact DEX instruction bytes passed as `swapData`. */
27
+ swapDataHash: Uint8Array;
28
+ };
29
+ export type TransactSwapParams<T extends Idl = Idl> = {
30
+ program: Program<T>;
31
+ relayer: {
32
+ publicKey: PublicKey;
33
+ };
34
+ sourceMint: PublicKey;
35
+ destMint: PublicKey;
36
+ sourceRoot: Uint8Array;
37
+ sourceTreeId: number;
38
+ destTreeId: number;
39
+ inputNullifiers: [Uint8Array, Uint8Array];
40
+ /** Output 0 is source-mint change; output 1 is the destination note. */
41
+ outputCommitments: [Uint8Array, Uint8Array];
42
+ proof: SwapProofStruct;
43
+ swapParams: SwapParams;
44
+ swapAmount: bigint;
45
+ /** Exact raw data from the DEX/Jupiter instruction. */
46
+ swapData: Uint8Array | Buffer;
47
+ extData: ExtData;
48
+ noteCiphers?: NoteCiphers | null;
49
+ sourceVaultTokenAccount: PublicKey;
50
+ /** Actual DEX source mint (WSOL for the native-SOL pool sentinel). */
51
+ sourceMintAccount: PublicKey;
52
+ destVaultTokenAccount: PublicKey;
53
+ /** Actual DEX destination mint (WSOL for the native-SOL pool sentinel). */
54
+ destMintAccount: PublicKey;
55
+ relayerTokenAccount: PublicKey;
56
+ swapProgram: PublicKey;
57
+ jupiterEventAuthority: PublicKey;
58
+ /** Preserve the DEX instruction's account order and duplicates exactly. */
59
+ remainingAccounts?: AccountMeta[];
60
+ };
61
+ /** Build the current IDL's `transact_swap` instruction without submitting it. */
62
+ export declare function buildTransactSwapInstruction<T extends Idl>(params: TransactSwapParams<T>): Promise<TransactionInstruction>;
63
+ /** Build the atomic instruction sequence, including native-source funding. */
64
+ export declare function buildPrivateSwapInstructions<T extends Idl>(params: TransactSwapParams<T>): Promise<TransactionInstruction[]>;
65
+ /**
66
+ * Submit the parity-correct instructions as a legacy transaction. For Jupiter
67
+ * routes, prefer `buildPrivateSwapInstructions` and compile v0 with route ALTs.
68
+ */
69
+ export declare function transactSwap<T extends Idl>(params: TransactSwapParams<T> & {
70
+ relayer: Keypair;
71
+ }): Promise<string>;