@veilo/sdk-core 0.4.0 → 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 (296) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +286 -1298
  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 +6 -938
  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 +21 -0
  32. package/dist/cjs/compactNote.js +31 -7
  33. package/dist/cjs/index.d.ts +2 -1
  34. package/dist/cjs/index.js +4 -1
  35. package/dist/cjs/notes/encryption.d.ts +41 -0
  36. package/dist/cjs/notes/encryption.js +75 -0
  37. package/dist/cjs/notes/index.d.ts +5 -0
  38. package/dist/cjs/notes/index.js +21 -0
  39. package/dist/cjs/notes/mailbox.d.ts +70 -0
  40. package/dist/cjs/notes/mailbox.js +164 -0
  41. package/dist/cjs/notes/model.d.ts +91 -0
  42. package/dist/cjs/notes/model.js +109 -0
  43. package/dist/cjs/notes/nullifier.d.ts +27 -0
  44. package/dist/cjs/notes/nullifier.js +45 -0
  45. package/dist/cjs/notes/recovery.d.ts +10 -0
  46. package/dist/cjs/notes/recovery.js +31 -0
  47. package/dist/cjs/proof.d.ts +1 -183
  48. package/dist/cjs/proof.js +16 -290
  49. package/dist/cjs/proofs/encoding.d.ts +17 -0
  50. package/dist/cjs/proofs/encoding.js +72 -0
  51. package/dist/cjs/proofs/formatting.d.ts +6 -0
  52. package/dist/cjs/proofs/formatting.js +34 -0
  53. package/dist/cjs/proofs/index.d.ts +5 -0
  54. package/dist/cjs/proofs/index.js +21 -0
  55. package/dist/cjs/proofs/swap.d.ts +87 -0
  56. package/dist/cjs/proofs/swap.js +144 -0
  57. package/dist/cjs/proofs/transaction.d.ts +28 -0
  58. package/dist/cjs/proofs/transaction.js +110 -0
  59. package/dist/cjs/proofs/types.d.ts +70 -0
  60. package/dist/cjs/prover.d.ts +4 -1
  61. package/dist/cjs/prover.js +12 -2
  62. package/dist/cjs/relayer/client.d.ts +61 -0
  63. package/dist/cjs/relayer/client.js +151 -0
  64. package/dist/cjs/relayer/crypto.d.ts +5 -0
  65. package/dist/cjs/relayer/crypto.js +26 -0
  66. package/dist/cjs/relayer/encoding.d.ts +2 -0
  67. package/dist/cjs/relayer/encoding.js +23 -0
  68. package/dist/cjs/relayer/errors.d.ts +7 -0
  69. package/dist/cjs/relayer/errors.js +17 -0
  70. package/dist/cjs/relayer/index.d.ts +3 -0
  71. package/dist/cjs/relayer/index.js +19 -0
  72. package/dist/cjs/relayer/transport.d.ts +17 -0
  73. package/dist/cjs/relayer/transport.js +63 -0
  74. package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +44 -86
  75. package/dist/cjs/relayer/types.js +5 -0
  76. package/dist/cjs/relayer.d.ts +1 -318
  77. package/dist/cjs/relayer.js +15 -254
  78. package/dist/cjs/shield/alt.js +8 -8
  79. package/dist/cjs/shield/errors.js +2 -2
  80. package/dist/cjs/shield/finalize.js +2 -2
  81. package/dist/cjs/shield/ix.d.ts +1 -1
  82. package/dist/cjs/shield/owner.js +9 -8
  83. package/dist/cjs/shield/ports.js +3 -3
  84. package/dist/cjs/shield/preflight.js +3 -3
  85. package/dist/cjs/shield/shield.js +20 -19
  86. package/dist/cjs/shield/types.d.ts +1 -1
  87. package/dist/cjs/transactions/deposit.d.ts +94 -0
  88. package/dist/cjs/transactions/deposit.js +234 -0
  89. package/dist/cjs/transactions/index.d.ts +7 -0
  90. package/dist/cjs/transactions/index.js +26 -0
  91. package/dist/cjs/transactions/swap.d.ts +71 -0
  92. package/dist/cjs/transactions/swap.js +184 -0
  93. package/dist/cjs/transactions/transact.d.ts +34 -0
  94. package/dist/cjs/transactions/transact.js +146 -0
  95. package/dist/cjs/transactions/transfer.d.ts +51 -0
  96. package/dist/cjs/transactions/transfer.js +106 -0
  97. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  98. package/dist/cjs/transactions/withdraw.js +104 -0
  99. package/dist/cjs/utxo.d.ts +1 -235
  100. package/dist/cjs/utxo.js +15 -404
  101. package/dist/esm/accounts/admin.d.ts +84 -0
  102. package/dist/esm/accounts/admin.js +165 -0
  103. package/dist/esm/accounts/errors.d.ts +6 -0
  104. package/dist/esm/accounts/errors.js +95 -0
  105. package/dist/esm/accounts/index.d.ts +4 -0
  106. package/dist/esm/accounts/index.js +4 -0
  107. package/dist/esm/accounts/pdas.d.ts +23 -0
  108. package/dist/esm/accounts/pdas.js +38 -0
  109. package/dist/esm/accounts/queries.d.ts +41 -0
  110. package/dist/esm/accounts/queries.js +88 -0
  111. package/dist/esm/client.d.ts +2 -407
  112. package/dist/esm/client.js +3 -891
  113. package/dist/esm/cloak/client.d.ts +28 -0
  114. package/dist/esm/cloak/client.js +64 -0
  115. package/dist/esm/cloak/errors.d.ts +13 -0
  116. package/dist/esm/cloak/errors.js +21 -0
  117. package/dist/esm/cloak/helpers.d.ts +6 -0
  118. package/dist/esm/cloak/helpers.js +31 -0
  119. package/dist/esm/cloak/index.d.ts +6 -0
  120. package/dist/esm/cloak/index.js +6 -0
  121. package/dist/esm/cloak/polling.d.ts +7 -0
  122. package/dist/esm/cloak/polling.js +63 -0
  123. package/dist/esm/cloak/transport.d.ts +15 -0
  124. package/dist/esm/cloak/transport.js +115 -0
  125. package/dist/esm/cloak/types.d.ts +188 -0
  126. package/dist/esm/cloak/types.js +4 -0
  127. package/dist/esm/cloak.d.ts +1 -0
  128. package/dist/esm/cloak.js +2 -0
  129. package/dist/esm/compactNote.d.ts +21 -0
  130. package/dist/esm/compactNote.js +24 -1
  131. package/dist/esm/index.d.ts +2 -1
  132. package/dist/esm/index.js +3 -1
  133. package/dist/esm/notes/encryption.d.ts +41 -0
  134. package/dist/esm/notes/encryption.js +67 -0
  135. package/dist/esm/notes/index.d.ts +5 -0
  136. package/dist/esm/notes/index.js +5 -0
  137. package/dist/esm/notes/mailbox.d.ts +70 -0
  138. package/dist/esm/notes/mailbox.js +154 -0
  139. package/dist/esm/notes/model.d.ts +91 -0
  140. package/dist/esm/notes/model.js +99 -0
  141. package/dist/esm/notes/nullifier.d.ts +27 -0
  142. package/dist/esm/notes/nullifier.js +40 -0
  143. package/dist/esm/notes/recovery.d.ts +10 -0
  144. package/dist/esm/notes/recovery.js +28 -0
  145. package/dist/esm/proof.d.ts +1 -183
  146. package/dist/esm/proof.js +2 -281
  147. package/dist/esm/proofs/encoding.d.ts +17 -0
  148. package/dist/esm/proofs/encoding.js +68 -0
  149. package/dist/esm/proofs/formatting.d.ts +6 -0
  150. package/dist/esm/proofs/formatting.js +31 -0
  151. package/dist/esm/proofs/index.d.ts +5 -0
  152. package/dist/esm/proofs/index.js +5 -0
  153. package/dist/esm/proofs/swap.d.ts +87 -0
  154. package/dist/esm/proofs/swap.js +138 -0
  155. package/dist/esm/proofs/transaction.d.ts +28 -0
  156. package/dist/esm/proofs/transaction.js +105 -0
  157. package/dist/esm/proofs/types.d.ts +70 -0
  158. package/dist/esm/proofs/types.js +1 -0
  159. package/dist/esm/prover.d.ts +4 -1
  160. package/dist/esm/prover.js +10 -1
  161. package/dist/esm/relayer/client.d.ts +61 -0
  162. package/dist/esm/relayer/client.js +144 -0
  163. package/dist/esm/relayer/crypto.d.ts +5 -0
  164. package/dist/esm/relayer/crypto.js +20 -0
  165. package/dist/esm/relayer/encoding.d.ts +2 -0
  166. package/dist/esm/relayer/encoding.js +19 -0
  167. package/dist/esm/relayer/errors.d.ts +7 -0
  168. package/dist/esm/relayer/errors.js +13 -0
  169. package/dist/esm/relayer/index.d.ts +3 -0
  170. package/dist/esm/relayer/index.js +3 -0
  171. package/dist/esm/relayer/transport.d.ts +17 -0
  172. package/dist/esm/relayer/transport.js +59 -0
  173. package/dist/esm/relayer/types.d.ts +276 -0
  174. package/dist/esm/relayer/types.js +4 -0
  175. package/dist/esm/relayer.d.ts +1 -318
  176. package/dist/esm/relayer.js +2 -249
  177. package/dist/esm/shield/alt.js +1 -1
  178. package/dist/esm/shield/errors.js +1 -1
  179. package/dist/esm/shield/finalize.js +1 -1
  180. package/dist/esm/shield/ix.d.ts +1 -1
  181. package/dist/esm/shield/owner.js +2 -1
  182. package/dist/esm/shield/ports.js +1 -1
  183. package/dist/esm/shield/preflight.js +1 -1
  184. package/dist/esm/shield/shield.js +4 -3
  185. package/dist/esm/shield/types.d.ts +1 -1
  186. package/dist/esm/transactions/deposit.d.ts +94 -0
  187. package/dist/esm/transactions/deposit.js +198 -0
  188. package/dist/esm/transactions/index.d.ts +7 -0
  189. package/dist/esm/transactions/index.js +7 -0
  190. package/dist/esm/transactions/swap.d.ts +71 -0
  191. package/dist/esm/transactions/swap.js +144 -0
  192. package/dist/esm/transactions/transact.d.ts +34 -0
  193. package/dist/esm/transactions/transact.js +110 -0
  194. package/dist/esm/transactions/transfer.d.ts +51 -0
  195. package/dist/esm/transactions/transfer.js +103 -0
  196. package/dist/esm/transactions/withdraw.d.ts +52 -0
  197. package/dist/esm/transactions/withdraw.js +101 -0
  198. package/dist/esm/utxo.d.ts +1 -235
  199. package/dist/esm/utxo.js +2 -382
  200. package/package.json +54 -16
  201. package/SHIELD_INTEGRATION.md +0 -143
  202. package/config.d.ts +0 -2
  203. package/config.js +0 -4
  204. package/dist/src/client.d.ts +0 -407
  205. package/dist/src/client.js +0 -951
  206. package/dist/src/compactNote.d.ts +0 -107
  207. package/dist/src/compactNote.js +0 -167
  208. package/dist/src/config.d.ts +0 -82
  209. package/dist/src/config.js +0 -57
  210. package/dist/src/events.d.ts +0 -77
  211. package/dist/src/events.js +0 -167
  212. package/dist/src/idl/privacy_pool.d.ts +0 -5
  213. package/dist/src/idl/privacy_pool.js +0 -15218
  214. package/dist/src/index.d.ts +0 -16
  215. package/dist/src/index.js +0 -67
  216. package/dist/src/merkle.d.ts +0 -77
  217. package/dist/src/merkle.js +0 -156
  218. package/dist/src/poseidon.d.ts +0 -29
  219. package/dist/src/poseidon.js +0 -100
  220. package/dist/src/program.d.ts +0 -37
  221. package/dist/src/program.js +0 -61
  222. package/dist/src/proof.d.ts +0 -183
  223. package/dist/src/proof.js +0 -292
  224. package/dist/src/prover.d.ts +0 -54
  225. package/dist/src/prover.js +0 -112
  226. package/dist/src/random.d.ts +0 -16
  227. package/dist/src/random.js +0 -28
  228. package/dist/src/relayer.js +0 -257
  229. package/dist/src/retry.d.ts +0 -32
  230. package/dist/src/retry.js +0 -75
  231. package/dist/src/shield/alt.d.ts +0 -87
  232. package/dist/src/shield/alt.js +0 -194
  233. package/dist/src/shield/computeBudget.d.ts +0 -61
  234. package/dist/src/shield/computeBudget.js +0 -64
  235. package/dist/src/shield/errors.d.ts +0 -58
  236. package/dist/src/shield/errors.js +0 -121
  237. package/dist/src/shield/finalize.d.ts +0 -45
  238. package/dist/src/shield/finalize.js +0 -119
  239. package/dist/src/shield/index.d.ts +0 -35
  240. package/dist/src/shield/index.js +0 -68
  241. package/dist/src/shield/ix.d.ts +0 -54
  242. package/dist/src/shield/ix.js +0 -119
  243. package/dist/src/shield/owner.d.ts +0 -36
  244. package/dist/src/shield/owner.js +0 -126
  245. package/dist/src/shield/ports.d.ts +0 -43
  246. package/dist/src/shield/ports.js +0 -153
  247. package/dist/src/shield/preflight.d.ts +0 -30
  248. package/dist/src/shield/preflight.js +0 -154
  249. package/dist/src/shield/shield.d.ts +0 -68
  250. package/dist/src/shield/shield.js +0 -499
  251. package/dist/src/shield/types.d.ts +0 -202
  252. package/dist/src/utxo.d.ts +0 -235
  253. package/dist/src/utxo.js +0 -407
  254. package/dist/tests/compact-note.test.d.ts +0 -1
  255. package/dist/tests/compact-note.test.js +0 -173
  256. package/dist/tests/config.test.d.ts +0 -1
  257. package/dist/tests/config.test.js +0 -102
  258. package/dist/tests/edge-cases.test.d.ts +0 -1
  259. package/dist/tests/edge-cases.test.js +0 -220
  260. package/dist/tests/encryption.test.d.ts +0 -1
  261. package/dist/tests/encryption.test.js +0 -215
  262. package/dist/tests/events.test.d.ts +0 -1
  263. package/dist/tests/events.test.js +0 -78
  264. package/dist/tests/multi-tree.test.d.ts +0 -1
  265. package/dist/tests/multi-tree.test.js +0 -405
  266. package/dist/tests/pda.test.d.ts +0 -1
  267. package/dist/tests/pda.test.js +0 -229
  268. package/dist/tests/poseidon-builder-parity.test.d.ts +0 -1
  269. package/dist/tests/poseidon-builder-parity.test.js +0 -72
  270. package/dist/tests/poseidon.test.d.ts +0 -1
  271. package/dist/tests/poseidon.test.js +0 -142
  272. package/dist/tests/proof.test.d.ts +0 -1
  273. package/dist/tests/proof.test.js +0 -296
  274. package/dist/tests/relayer.test.d.ts +0 -1
  275. package/dist/tests/relayer.test.js +0 -271
  276. package/dist/tests/sdk.integration.test.d.ts +0 -1
  277. package/dist/tests/sdk.integration.test.js +0 -330
  278. package/dist/tests/shield-owner.test.d.ts +0 -1
  279. package/dist/tests/shield-owner.test.js +0 -89
  280. package/dist/tests/shield-preflight.test.d.ts +0 -1
  281. package/dist/tests/shield-preflight.test.js +0 -87
  282. package/dist/tests/shield-realproof.test.d.ts +0 -1
  283. package/dist/tests/shield-realproof.test.js +0 -272
  284. package/dist/tests/shield.test.d.ts +0 -1
  285. package/dist/tests/shield.test.js +0 -403
  286. package/dist/tests/utxo.test.d.ts +0 -1
  287. package/dist/tests/utxo.test.js +0 -140
  288. package/poseidon.d.ts +0 -2
  289. package/poseidon.js +0 -4
  290. package/proof.d.ts +0 -2
  291. package/proof.js +0 -4
  292. package/prover.d.ts +0 -2
  293. package/prover.js +0 -4
  294. package/shield.d.ts +0 -2
  295. package/shield.js +0 -4
  296. /package/dist/{src/shield → cjs/proofs}/types.js +0 -0
@@ -1,318 +1 @@
1
- export interface VeiloRelayerConfig {
2
- /** Base URL of the relayer. Defaults to Veilo's production service. */
3
- relayerUrl?: string;
4
- /** API key sent as x-api-key header */
5
- apiKey: string;
6
- /** Relayer's NaCl box public key (base64-encoded, 32 bytes) */
7
- relayerPublicKey: string;
8
- /** Optional JWT auth token for authenticated endpoints */
9
- authToken?: string;
10
- }
11
- /** Structured error thrown by VeiloRelayerClient on API failures. */
12
- export declare class VeiloApiError extends Error {
13
- code: string;
14
- status: number;
15
- details?: unknown;
16
- constructor(code: string, message: string, status: number, details?: unknown);
17
- }
18
- /** Retry configuration for the relayer HTTP client. */
19
- export interface RetryPolicy {
20
- /** Max number of retry attempts (default: 3) */
21
- maxRetries: number;
22
- /** Base delay in ms for exponential backoff (default: 1000) */
23
- baseDelayMs: number;
24
- /** HTTP status codes that trigger a retry (default: [429, 502, 503, 504]) */
25
- retryableStatuses: number[];
26
- }
27
- export interface RelayerEncryptedNote {
28
- noteId: string;
29
- commitment: string;
30
- ephemeralPublicKey: string;
31
- encryptedBlob: string;
32
- timestamp: number;
33
- blockHeight?: number;
34
- txSignature?: string;
35
- spent?: boolean;
36
- onchainId?: string;
37
- spentTx?: string;
38
- spentAt?: number;
39
- compactEphemeralKey?: string | null;
40
- compactBlob?: string | null;
41
- viewTag?: number | null;
42
- leafIndex?: number | null;
43
- mintAddress?: string | null;
44
- treeId?: number | null;
45
- }
46
- export interface QueryNotesRequest {
47
- lastCheckedTimestamp?: number;
48
- limit?: number;
49
- offset?: number;
50
- walletPublicKey?: string;
51
- }
52
- export interface QueryNotesResponse {
53
- success: boolean;
54
- notes: RelayerEncryptedNote[];
55
- total: number;
56
- limit: number;
57
- offset: number;
58
- }
59
- export interface SaveEncryptedNoteRequest {
60
- commitment: string;
61
- ephemeralPublicKey: string;
62
- encryptedBlob: string;
63
- timestamp: number;
64
- blockHeight?: number;
65
- txSignature?: string;
66
- recipientWalletPublicKey?: string;
67
- compactEphemeralKey?: string | null;
68
- compactBlob?: string | null;
69
- viewTag?: number | null;
70
- leafIndex?: number;
71
- newRoot?: string;
72
- mintAddress?: string;
73
- treeId?: number;
74
- amountRaw?: string;
75
- }
76
- export interface SaveEncryptedNoteResponse {
77
- success: boolean;
78
- noteId?: string;
79
- message?: string;
80
- error?: string;
81
- }
82
- export interface MerkleRootResponse {
83
- success: boolean;
84
- data: {
85
- root: string;
86
- nextIndex: number;
87
- treeId: number;
88
- onChainTreeId: number;
89
- mintAddress: string;
90
- };
91
- }
92
- export interface MerkleTreeResponse {
93
- success: boolean;
94
- data: {
95
- treeId: number;
96
- onChainTreeId: number;
97
- mintAddress: string;
98
- height: number;
99
- nextIndex: number;
100
- root: string;
101
- totalCommitments: number;
102
- leaves: Array<{
103
- commitment: string;
104
- index: number;
105
- txSignature: string;
106
- slot: number;
107
- timestamp: string;
108
- }>;
109
- reconstructionInfo: {
110
- instructions: string;
111
- treeHeight: number;
112
- hashFunction?: string;
113
- };
114
- };
115
- }
116
- export interface TransactNote {
117
- commitment: string;
118
- privateKey: string;
119
- publicKey: string;
120
- blinding: string;
121
- amount: string;
122
- nullifier: string;
123
- leafIndex?: number;
124
- noteId?: string;
125
- }
126
- export interface WithdrawRequest {
127
- notes: TransactNote[];
128
- recipient: string;
129
- amount: string;
130
- userPublicKey: string;
131
- mintAddress: string;
132
- }
133
- export interface WithdrawResponse {
134
- success: boolean;
135
- message: string;
136
- data?: {
137
- withdrawRecipient: string;
138
- withdrawAmount: number;
139
- changeAmount: number;
140
- changeNote: {
141
- commitment: string;
142
- privateKey: string;
143
- publicKey: string;
144
- blinding: string;
145
- amount: string;
146
- nullifier: string;
147
- };
148
- spentNoteIds?: string[];
149
- txSignature?: string;
150
- };
151
- }
152
- export interface PrivateTransferRequest {
153
- notes: TransactNote[];
154
- amount: string;
155
- recipientUsername: string;
156
- userPublicKey?: string;
157
- mintAddress?: string;
158
- }
159
- export interface PrivateTransferResponse {
160
- success: boolean;
161
- message: string;
162
- data?: {
163
- recipient: string;
164
- transferAmount: number;
165
- senderChangeAmount: number;
166
- txSignature: string;
167
- recipientNote: {
168
- commitment: string;
169
- amount: string;
170
- leafIndex: number;
171
- savedNoteId: string;
172
- };
173
- senderChangeNote: {
174
- commitment: string;
175
- privateKey: string;
176
- publicKey: string;
177
- blinding: string;
178
- amount: string;
179
- leafIndex: number;
180
- savedNoteId: string;
181
- } | null;
182
- };
183
- }
184
- export interface PrivateSwapRequest {
185
- notes: TransactNote[];
186
- sourceMintAddress: string;
187
- destMintAddress: string;
188
- sourceJupiterMint?: string;
189
- destJupiterMint?: string;
190
- swapAmountRaw: string;
191
- minAmountOut: string;
192
- slippageBps: number;
193
- userPublicKey: string;
194
- veiloPublicKey: string;
195
- }
196
- export interface PrivateSwapResponse {
197
- success: boolean;
198
- message: string;
199
- data?: {
200
- txSignature: string;
201
- swapAmountRaw: string;
202
- outputAmount: string;
203
- minAmountOut: string;
204
- changeAmount: string;
205
- };
206
- }
207
- export interface ChallengeResponse {
208
- success: boolean;
209
- challenge: string;
210
- expiresAt: number;
211
- }
212
- export interface RegisterRequest {
213
- username: string;
214
- walletPublicKey: string;
215
- signature: string;
216
- challenge: string;
217
- veiloPublicKey: string;
218
- }
219
- export interface RegisterResponse {
220
- success: boolean;
221
- token: string;
222
- message?: string;
223
- }
224
- export interface RestoreRequest {
225
- walletPublicKey: string;
226
- signature: string;
227
- challenge: string;
228
- }
229
- export interface RestoreResponse {
230
- success: boolean;
231
- token: string;
232
- username: string;
233
- veiloPublicKey: string;
234
- }
235
- export interface CheckUsernameResponse {
236
- success: boolean;
237
- available: boolean;
238
- }
239
- export interface VeiloPublicKeyResponse {
240
- success: boolean;
241
- username: string;
242
- pubK: string;
243
- veiloPublicKey: string;
244
- }
245
- export interface PreRegisterKeyResponse {
246
- success: boolean;
247
- veiloPublicKey: string;
248
- }
249
- export interface DeleteUserDataResponse {
250
- success: boolean;
251
- message: string;
252
- deletedCount?: number;
253
- }
254
- /**
255
- * HTTP client for the Veilo relayer API.
256
- *
257
- * Handles auth, notes, merkle, and encrypted transact endpoints with
258
- * automatic retry on transient failures and NaCl box payload encryption.
259
- *
260
- * @example
261
- * ```ts
262
- * const client = new VeiloRelayerClient({
263
- * apiKey: "your-api-key",
264
- * relayerPublicKey: "<base64 NaCl public key>",
265
- * });
266
- * const root = await client.getMerkleRoot("So111...");
267
- * ```
268
- */
269
- export declare class VeiloRelayerClient {
270
- private readonly baseUrl;
271
- private readonly apiKey;
272
- private readonly relayerPubKey;
273
- private authToken;
274
- private readonly retry;
275
- constructor(config: VeiloRelayerConfig, retry?: Partial<RetryPolicy>);
276
- /** Update the auth token (e.g. after register/restore). */
277
- setAuthToken(token: string): void;
278
- private headers;
279
- private request;
280
- private encrypt;
281
- /** Request a signature challenge for wallet authentication. */
282
- getChallenge(walletPublicKey: string): Promise<ChallengeResponse>;
283
- /** Register a new account with a signed challenge. Returns a JWT auth token. */
284
- register(data: RegisterRequest): Promise<RegisterResponse>;
285
- /** Restore an existing account using a signed challenge. Returns a JWT auth token. */
286
- restore(data: RestoreRequest): Promise<RestoreResponse>;
287
- /** Check whether a username is available for registration. */
288
- checkUsername(username: string): Promise<CheckUsernameResponse>;
289
- /** Look up a user's Veilo public key by username or wallet public key. */
290
- getVeiloPublicKey(params: {
291
- username: string;
292
- publicKey?: never;
293
- } | {
294
- publicKey: string;
295
- username?: never;
296
- }): Promise<VeiloPublicKeyResponse>;
297
- /**
298
- * Provision (or retrieve) the Veilo spend key paired with a Solana address.
299
- * Public and idempotent; the response contains public key material only.
300
- */
301
- preRegisterKey(solanaAddress: string): Promise<PreRegisterKeyResponse>;
302
- /** Save an encrypted note to the relayer's database. */
303
- saveEncryptedNote(data: SaveEncryptedNoteRequest): Promise<SaveEncryptedNoteResponse>;
304
- /** Query encrypted notes for the authenticated user. Requires auth token. */
305
- queryEncryptedNotes(params?: QueryNotesRequest): Promise<QueryNotesResponse>;
306
- /** Delete all stored data for the authenticated user. Requires auth token. */
307
- deleteUserData(): Promise<DeleteUserDataResponse>;
308
- /** Fetch the current Merkle root for a pool, optionally filtered by mint and tree ID. */
309
- getMerkleRoot(mintAddress?: string, treeId?: number): Promise<MerkleRootResponse>;
310
- /** Fetch the full Merkle tree (all leaves) for a pool. */
311
- getMerkleTree(mintAddress?: string, treeId?: number): Promise<MerkleTreeResponse>;
312
- /** Submit an encrypted withdrawal request to the relayer. Not retried on failure. */
313
- submitWithdraw(data: WithdrawRequest): Promise<WithdrawResponse>;
314
- /** Submit an encrypted private transfer request. Not retried on failure. */
315
- submitPrivateTransfer(data: PrivateTransferRequest): Promise<PrivateTransferResponse>;
316
- /** Submit an encrypted private swap request. Not retried on failure. */
317
- submitPrivateSwap(data: PrivateSwapRequest): Promise<PrivateSwapResponse>;
318
- }
1
+ export * from "./relayer/index.js";
@@ -1,249 +1,2 @@
1
- import nacl from "tweetnacl";
2
- const DEFAULT_RELAYER_URL = "https://relayer-server.onrender.com";
3
- // =============================================================================
4
- // Structured Error
5
- // =============================================================================
6
- /** Structured error thrown by VeiloRelayerClient on API failures. */
7
- export class VeiloApiError extends Error {
8
- constructor(code, message, status, details) {
9
- super(message);
10
- this.name = "VeiloApiError";
11
- this.code = code;
12
- this.status = status;
13
- this.details = details;
14
- }
15
- }
16
- const DEFAULT_RETRY = {
17
- maxRetries: 3,
18
- baseDelayMs: 1000,
19
- retryableStatuses: [429, 502, 503, 504],
20
- };
21
- // =============================================================================
22
- // Base64 helpers (no dependency on tweetnacl-util)
23
- // =============================================================================
24
- function toBase64(bytes) {
25
- if (typeof Buffer !== "undefined") {
26
- return Buffer.from(bytes).toString("base64");
27
- }
28
- return btoa(String.fromCharCode(...bytes));
29
- }
30
- function fromBase64(str) {
31
- if (typeof Buffer !== "undefined") {
32
- return new Uint8Array(Buffer.from(str, "base64"));
33
- }
34
- const binary = atob(str);
35
- const bytes = new Uint8Array(binary.length);
36
- for (let i = 0; i < binary.length; i++)
37
- bytes[i] = binary.charCodeAt(i);
38
- return bytes;
39
- }
40
- // =============================================================================
41
- // Encryption
42
- // =============================================================================
43
- /**
44
- * Encrypt a JSON-serializable payload for the relayer using NaCl box.
45
- * Layout: [ephemeralPubKey (32)] [nonce (24)] [ciphertext (...)]
46
- */
47
- function encryptForRelayer(data, relayerPublicKey) {
48
- const ephemeral = nacl.box.keyPair();
49
- const message = new TextEncoder().encode(JSON.stringify(data));
50
- const nonce = nacl.randomBytes(nacl.box.nonceLength);
51
- const ciphertext = nacl.box(message, nonce, relayerPublicKey, ephemeral.secretKey);
52
- const payload = new Uint8Array(ephemeral.publicKey.length + nonce.length + ciphertext.length);
53
- payload.set(ephemeral.publicKey, 0);
54
- payload.set(nonce, ephemeral.publicKey.length);
55
- payload.set(ciphertext, ephemeral.publicKey.length + nonce.length);
56
- return toBase64(payload);
57
- }
58
- // =============================================================================
59
- // Relayer Client
60
- // =============================================================================
61
- /**
62
- * HTTP client for the Veilo relayer API.
63
- *
64
- * Handles auth, notes, merkle, and encrypted transact endpoints with
65
- * automatic retry on transient failures and NaCl box payload encryption.
66
- *
67
- * @example
68
- * ```ts
69
- * const client = new VeiloRelayerClient({
70
- * apiKey: "your-api-key",
71
- * relayerPublicKey: "<base64 NaCl public key>",
72
- * });
73
- * const root = await client.getMerkleRoot("So111...");
74
- * ```
75
- */
76
- export class VeiloRelayerClient {
77
- constructor(config, retry) {
78
- this.baseUrl = (config.relayerUrl?.trim() || DEFAULT_RELAYER_URL).replace(/\/+$/, "");
79
- this.apiKey = config.apiKey;
80
- this.relayerPubKey = fromBase64(config.relayerPublicKey);
81
- this.authToken = config.authToken;
82
- this.retry = { ...DEFAULT_RETRY, ...retry };
83
- }
84
- /** Update the auth token (e.g. after register/restore). */
85
- setAuthToken(token) {
86
- this.authToken = token;
87
- }
88
- // ---------------------------------------------------------------------------
89
- // Internal helpers
90
- // ---------------------------------------------------------------------------
91
- headers(authenticated) {
92
- const h = {
93
- "Content-Type": "application/json",
94
- };
95
- if (this.apiKey)
96
- h["x-api-key"] = this.apiKey;
97
- if (authenticated && this.authToken) {
98
- h["Authorization"] = `Bearer ${this.authToken}`;
99
- }
100
- return h;
101
- }
102
- async request(method, path, opts = {}) {
103
- const url = `${this.baseUrl}/api${path}`;
104
- const { body, authenticated = false, retryable = true } = opts;
105
- const maxAttempts = retryable ? this.retry.maxRetries + 1 : 1;
106
- let lastError;
107
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
108
- if (attempt > 0) {
109
- const delay = this.retry.baseDelayMs * Math.pow(2, attempt - 1) +
110
- Math.random() * 200;
111
- await new Promise((r) => setTimeout(r, delay));
112
- }
113
- let res;
114
- try {
115
- res = await fetch(url, {
116
- method,
117
- headers: this.headers(authenticated),
118
- body: body != null ? JSON.stringify(body) : undefined,
119
- });
120
- }
121
- catch (err) {
122
- lastError = new VeiloApiError("NETWORK_ERROR", err.message || "Network request failed", 0);
123
- continue;
124
- }
125
- const data = await res.json().catch(() => ({}));
126
- if (res.ok && data.success !== false) {
127
- return data;
128
- }
129
- lastError = new VeiloApiError(data.error || "UNKNOWN", data.message || data.error || `Request failed: ${res.status}`, res.status, data);
130
- // Only retry on transient statuses
131
- if (!this.retry.retryableStatuses.includes(res.status)) {
132
- throw lastError;
133
- }
134
- }
135
- throw lastError;
136
- }
137
- encrypt(data) {
138
- return encryptForRelayer({
139
- ...data,
140
- timestamp: Date.now(),
141
- nonce: toBase64(nacl.randomBytes(32)),
142
- }, this.relayerPubKey);
143
- }
144
- // ---------------------------------------------------------------------------
145
- // Auth
146
- // ---------------------------------------------------------------------------
147
- /** Request a signature challenge for wallet authentication. */
148
- async getChallenge(walletPublicKey) {
149
- return this.request("POST", "/auth/challenge", {
150
- body: { walletPublicKey },
151
- });
152
- }
153
- /** Register a new account with a signed challenge. Returns a JWT auth token. */
154
- async register(data) {
155
- return this.request("POST", "/auth/register", { body: data });
156
- }
157
- /** Restore an existing account using a signed challenge. Returns a JWT auth token. */
158
- async restore(data) {
159
- return this.request("POST", "/auth/restore", { body: data });
160
- }
161
- /** Check whether a username is available for registration. */
162
- async checkUsername(username) {
163
- return this.request("GET", `/auth/checkUsername?username=${encodeURIComponent(username)}`);
164
- }
165
- /** Look up a user's Veilo public key by username or wallet public key. */
166
- async getVeiloPublicKey(params) {
167
- const query = "username" in params && params.username
168
- ? `username=${encodeURIComponent(params.username)}`
169
- : `publicKey=${encodeURIComponent(params.publicKey)}`;
170
- return this.request("GET", `/auth/veiloPublicKey?${query}`);
171
- }
172
- /**
173
- * Provision (or retrieve) the Veilo spend key paired with a Solana address.
174
- * Public and idempotent; the response contains public key material only.
175
- */
176
- async preRegisterKey(solanaAddress) {
177
- return this.request("POST", "/auth/pre-register-key", {
178
- body: { solanaAddress },
179
- });
180
- }
181
- // ---------------------------------------------------------------------------
182
- // Notes
183
- // ---------------------------------------------------------------------------
184
- /** Save an encrypted note to the relayer's database. */
185
- async saveEncryptedNote(data) {
186
- return this.request("POST", "/notes/save", { body: data });
187
- }
188
- /** Query encrypted notes for the authenticated user. Requires auth token. */
189
- async queryEncryptedNotes(params = {}) {
190
- return this.request("POST", "/notes/query", {
191
- body: params,
192
- authenticated: true,
193
- });
194
- }
195
- /** Delete all stored data for the authenticated user. Requires auth token. */
196
- async deleteUserData() {
197
- return this.request("POST", "/notes/delete", { authenticated: true });
198
- }
199
- // ---------------------------------------------------------------------------
200
- // Merkle
201
- // ---------------------------------------------------------------------------
202
- /** Fetch the current Merkle root for a pool, optionally filtered by mint and tree ID. */
203
- async getMerkleRoot(mintAddress, treeId) {
204
- const params = new URLSearchParams();
205
- if (mintAddress)
206
- params.append("mintAddress", mintAddress);
207
- if (treeId !== undefined)
208
- params.append("treeId", treeId.toString());
209
- const qs = params.toString();
210
- return this.request("GET", `/merkle/root${qs ? `?${qs}` : ""}`);
211
- }
212
- /** Fetch the full Merkle tree (all leaves) for a pool. */
213
- async getMerkleTree(mintAddress, treeId) {
214
- const params = new URLSearchParams();
215
- if (mintAddress)
216
- params.append("mintAddress", mintAddress);
217
- if (treeId !== undefined)
218
- params.append("treeId", treeId.toString());
219
- const qs = params.toString();
220
- return this.request("GET", `/merkle/tree${qs ? `?${qs}` : ""}`);
221
- }
222
- // ---------------------------------------------------------------------------
223
- // Transact (encrypted payloads)
224
- // ---------------------------------------------------------------------------
225
- /** Submit an encrypted withdrawal request to the relayer. Not retried on failure. */
226
- async submitWithdraw(data) {
227
- const encryptedPayload = this.encrypt(data);
228
- return this.request("POST", "/transact/withdra", {
229
- body: { encryptedPayload },
230
- retryable: false,
231
- });
232
- }
233
- /** Submit an encrypted private transfer request. Not retried on failure. */
234
- async submitPrivateTransfer(data) {
235
- const encryptedPayload = this.encrypt(data);
236
- return this.request("POST", "/transact/private-transfer", {
237
- body: { encryptedPayload },
238
- retryable: false,
239
- });
240
- }
241
- /** Submit an encrypted private swap request. Not retried on failure. */
242
- async submitPrivateSwap(data) {
243
- const encryptedPayload = this.encrypt(data);
244
- return this.request("POST", "/transact/private-swap", {
245
- body: { encryptedPayload },
246
- retryable: false,
247
- });
248
- }
249
- }
1
+ // Backward-compatible entry point. Relayer responsibilities live in src/relayer.
2
+ export * from "./relayer/index.js";
@@ -1,6 +1,6 @@
1
1
  import { ComputeBudgetProgram, PublicKey, SystemProgram, } from "@solana/web3.js";
2
2
  import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress, getAssociatedTokenAddressSync, } from "@solana/spl-token";
3
- import { getGlobalConfigPda, getNoteTreePda, getPoolPdas, } from "../client.js";
3
+ import { getGlobalConfigPda, getNoteTreePda, getPoolPdas, } from "../accounts/pdas.js";
4
4
  import { PRIVACY_POOL_PROGRAM_ID } from "../program.js";
5
5
  import { NATIVE_SOL_MINT } from "../config.js";
6
6
  import { ShieldError } from "./errors.js";
@@ -1,4 +1,4 @@
1
- import { parseOnChainError } from "../client.js";
1
+ import { parseOnChainError } from "../accounts/errors.js";
2
2
  export class ShieldError extends Error {
3
3
  constructor(code, message, opts = {}) {
4
4
  super(message);
@@ -1,6 +1,6 @@
1
1
  import * as anchor from "@coral-xyz/anchor";
2
2
  import { PRIVACY_POOL_IDL, PRIVACY_POOL_PROGRAM_ID } from "../program.js";
3
- import { encryptBlindMailboxNote } from "../utxo.js";
3
+ import { encryptBlindMailboxNote } from "../notes/mailbox.js";
4
4
  import { bigIntToBytesBE } from "../poseidon.js";
5
5
  import { ShieldError } from "./errors.js";
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
- import type { TransactionProofStruct } from "../proof.js";
2
+ import type { TransactionProofStruct } from "../proofs/types.js";
3
3
  /**
4
4
  * `transact` instruction assembly, driven by the IDL rather than by a
5
5
  * hand-written account list.
@@ -1,5 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { VeiloApiError, VeiloRelayerClient } from "../relayer.js";
2
+ import { VeiloRelayerClient } from "../relayer/client.js";
3
+ import { VeiloApiError } from "../relayer/errors.js";
3
4
  import { ShieldError } from "./errors.js";
4
5
  /**
5
6
  * Owner resolution is a Veilo protocol service, not an integrator-selected
@@ -1,5 +1,5 @@
1
1
  import { createReadonlyVeiloProgram, PRIVACY_POOL_PROGRAM_ID } from "../program.js";
2
- import { getNoteTreePda, getPoolPdas } from "../client.js";
2
+ import { getNoteTreePda, getPoolPdas } from "../accounts/pdas.js";
3
3
  import { MERKLE_TREE_DEPTH } from "../config.js";
4
4
  import { ShieldError } from "./errors.js";
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { createRevokeInstruction, getAccount, getAssociatedTokenAddress, TokenAccountNotFoundError, } from "@solana/spl-token";
2
- import { getPoolPdas } from "../client.js";
2
+ import { getPoolPdas } from "../accounts/pdas.js";
3
3
  import { createReadonlyVeiloProgram, PRIVACY_POOL_PROGRAM_ID } from "../program.js";
4
4
  import { NATIVE_SOL_MINT } from "../config.js";
5
5
  import { ShieldError } from "./errors.js";
@@ -1,12 +1,13 @@
1
1
  import { ComputeBudgetProgram, PublicKey, SystemProgram, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
2
2
  import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token";
3
3
  import { PRIVACY_POOL_PROGRAM_ID } from "../program.js";
4
- import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../client.js";
4
+ import { getGlobalConfigPda, getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "../accounts/pdas.js";
5
5
  import { MERKLE_TREE_DEPTH, NATIVE_SOL_MINT } from "../config.js";
6
6
  import { bigIntToBytesBE, bytesToBigIntBE, BN254_FR_MODULUS, } from "../poseidon.js";
7
7
  import { poseidonZeroChain } from "../merkle.js";
8
- import { createUTXO, createOwnedZeroUTXO, generateKeypair, } from "../utxo.js";
9
- import { computeExtDataHash, encodeSnarkjsProofToTransactionProof, prepareTransactionInputs, } from "../proof.js";
8
+ import { createUTXO, createOwnedZeroUTXO, generateKeypair, } from "../notes/model.js";
9
+ import { computeExtDataHash, prepareTransactionInputs, } from "../proofs/transaction.js";
10
+ import { encodeSnarkjsProofToTransactionProof } from "../proofs/encoding.js";
10
11
  import { createCompactNoteCipher, emptyNoteCipher } from "../compactNote.js";
11
12
  import { buildTransactInstruction } from "./ix.js";
12
13
  import { sharedDepositAlt } from "./alt.js";
@@ -1,5 +1,5 @@
1
1
  import { AddressLookupTableAccount, Connection, PublicKey, VersionedTransaction } from "@solana/web3.js";
2
- import type { TransactionProofBuilder, TransactionProofStruct } from "../proof.js";
2
+ import type { TransactionProofBuilder, TransactionProofStruct } from "../proofs/types.js";
3
3
  import type { CompactNoteCipher } from "../compactNote.js";
4
4
  /**
5
5
  * Who owns the resulting note. Both halves are required and neither is derived