veilix-sdk 0.0.9 → 0.2.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.
@@ -1,386 +0,0 @@
1
- import { PublicKey, Keypair, Connection, TransactionInstruction, Transaction } from '@solana/web3.js';
2
- import { OracleJob } from '@switchboard-xyz/common';
3
- import { Program } from '@coral-xyz/anchor';
4
- import { Wallet } from '@coral-xyz/anchor/dist/cjs/provider';
5
- import { C as CircuitPaths } from './constants-sO9UKB9l.cjs';
6
-
7
- type IndexerAsset = string | {
8
- mint?: string;
9
- asset?: string;
10
- } | null;
11
-
12
- /** Frontend wallet adapter or backend {@link Keypair}. */
13
- type EncryptKeyWallet = Keypair | {
14
- signMessage: (message: Uint8Array) => Promise<Uint8Array> | Uint8Array;
15
- };
16
- type BuildDepositTxParams = {
17
- senderPublicKey: PublicKey | string;
18
- /** Pre-generated secret note from {@link generateDepositParams}. */
19
- note: string;
20
- onChainBackup?: boolean;
21
- computeUnitPrice?: number;
22
- tempSigner?: PublicKey | string;
23
- };
24
- type FetchWalletBalanceOptions = {
25
- includeDeposits?: boolean;
26
- indexerAsset?: IndexerAsset;
27
- };
28
- type BuildRelayPayloadParams = {
29
- args: unknown[];
30
- proofHex: string;
31
- denomination: number | bigint | string;
32
- withdrawAddress: unknown;
33
- relayerPubkey: unknown;
34
- mint?: unknown;
35
- };
36
- type RelayPayload = Record<string, unknown>;
37
-
38
- type DepositParams = {
39
- nullifier: string;
40
- secret: string;
41
- amount: string;
42
- commitment: string;
43
- nullifierHash: string;
44
- mint: string | null;
45
- };
46
- type GenerateDepositParamsResult = {
47
- params: DepositParams;
48
- note: string;
49
- };
50
- type PreparedCircuitArtifacts = {
51
- wasmPath: string;
52
- zkeyPath: string;
53
- /** Revokes the browser object URLs. `null` outside the browser. */
54
- cleanup: (() => void) | null;
55
- };
56
- type GenerateWithdrawProofOptions = {
57
- /** Override WASM path/URL (for bundled frontends, use a Vite `?url` import). */
58
- circuitWasmPath?: string;
59
- /** Override zkey path/URL (for bundled frontends, use a Vite `?url` import). */
60
- circuitZkeyPath?: string;
61
- /**
62
- * Artifacts already fetched and verified by {@link prepareCircuitArtifacts}.
63
- * Skips the download and takes precedence over the path overrides; the caller
64
- * stays responsible for calling `cleanup`.
65
- */
66
- circuitArtifacts?: PreparedCircuitArtifacts;
67
- };
68
- /**
69
- * Fetch and integrity-check the withdraw circuit artifacts once so that several
70
- * proofs can share them. Call `cleanup` after the last proof has settled.
71
- */
72
- declare const prepareCircuitArtifacts: (circuitWasmPath?: string, circuitZkeyPath?: string) => Promise<PreparedCircuitArtifacts>;
73
-
74
- type Network = "mainnet" | "devnet";
75
- declare const MAINNET_TOKEN_MINTS: {
76
- readonly Veilix: "GAFN64LvtCBoc5BHncVn3JEJGpq42rUzQjPmvMK2UhZH";
77
- readonly Bitcoin: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh";
78
- readonly Ethereum: "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs";
79
- readonly USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
80
- };
81
- type TokenSymbol = keyof typeof MAINNET_TOKEN_MINTS;
82
- declare const TOKEN_DECIMALS: {
83
- readonly Solana: 9;
84
- readonly Veilix: 9;
85
- readonly Ethereum: 8;
86
- readonly Bitcoin: 8;
87
- readonly USDC: 6;
88
- };
89
- type TokenDecimalsSymbol = keyof typeof TOKEN_DECIMALS;
90
- /** Supported deposit denominations per token (same on mainnet and devnet). */
91
- declare const DEPOSIT_AMOUNTS: {
92
- readonly Solana: readonly [0.1, 1, 5, 10, 50, 100, 500];
93
- readonly Veilix: readonly [10000, 50000, 100000, 500000, 1000000, 10000000];
94
- readonly Bitcoin: readonly [0.01, 0.05, 0.1, 0.5, 1, 5];
95
- readonly Ethereum: readonly [0.1, 1, 10, 50, 100, 500];
96
- readonly USDC: readonly [1, 10, 50, 100, 1000, 10000, 100000, 1000000];
97
- };
98
- type DepositTokenSymbol = keyof typeof DEPOSIT_AMOUNTS;
99
-
100
- type Relayer = {
101
- isValid: true;
102
- label: string;
103
- url: string;
104
- key: number;
105
- value: string;
106
- fee: unknown;
107
- recentActivities: unknown;
108
- userPubkey: unknown;
109
- workers: unknown;
110
- totalFeeEarningsSol: unknown;
111
- totalWithdrawCount: unknown;
112
- stakedAmount: unknown;
113
- volume24hSol: unknown;
114
- volume7dSol: unknown;
115
- };
116
-
117
- interface VeilixSdkInitOptions {
118
- /** Wallet for Anchor provider transactions. */
119
- wallet: Wallet;
120
- /**
121
- * Solana JSON-RPC endpoint (Node/scripts). Omit when passing {@link connection}
122
- * from `@solana/wallet-adapter-react` (`useConnection()`).
123
- */
124
- rpcEndpoint?: string;
125
- /** Existing connection (e.g. `useConnection()` in React). */
126
- connection?: Connection;
127
- /**
128
- * Cluster override when the RPC URL does not contain `devnet` / `mainnet` hints
129
- * (common with private RPC providers).
130
- */
131
- network: Network;
132
- /**
133
- * Base URL/path for withdraw circuit artifacts in the browser.
134
- * Defaults to `/node_modules/<pkg>/dist/circuits/` on localhost and the
135
- * pinned, SHA-256-verified jsDelivr CDN in production (domain-independent).
136
- * Set this to self-host instead, e.g. `"/circuits/"` (verified, with CDN fallback)
137
- * or `"https://cdn.example.com/veilix/circuits/"`.
138
- */
139
- circuitPathsBase?: string;
140
- }
141
- interface VeilixSdkRuntimeConfig {
142
- rpcEndpoint: string;
143
- /** Cluster inferred from {@link rpcEndpoint}. */
144
- network: Network;
145
- programId: string;
146
- /** Active relayers for {@link network}, loaded at SDK initialization. */
147
- relayers: Relayer[];
148
- connection: Connection;
149
- wallet: Wallet;
150
- program: Program;
151
- /** Set by {@link VeilixSDK.getEncryptionKey}; required for on-chain note backup. */
152
- encryptKey?: Uint8Array;
153
- /** Resolved withdraw circuit wasm/zkey URLs for browser proof generation. */
154
- circuitPaths?: CircuitPaths;
155
- }
156
-
157
- type WithdrawParams = {
158
- /** Secret note from the original deposit. */
159
- note: string;
160
- /** Withdrawal recipient public key. */
161
- recipient: PublicKey | string;
162
- /** Mode for normal withdraw or veilix transfer. */
163
- veilixTransferMode?: boolean;
164
- };
165
- type WithdrawStatus = "success" | "failed";
166
- type WithdrawResult = {
167
- txHash: string;
168
- status: WithdrawStatus;
169
- };
170
-
171
- type QuoteRelayer = {
172
- url: string;
173
- [key: string]: unknown;
174
- };
175
- type QuoteTransaction = Record<string, unknown>;
176
- type QuoteSplit = {
177
- denomination: number;
178
- totalRelayerFee: number;
179
- relayer: QuoteRelayer;
180
- transaction: QuoteTransaction;
181
- };
182
- type Quote = {
183
- amount: number;
184
- transactionCount: number;
185
- recipientAmount: number;
186
- totalRelayerFee: number;
187
- etaSeconds: number;
188
- splits: QuoteSplit[];
189
- platformFee?: number;
190
- };
191
- type GetQuoteResponse = {
192
- success: boolean;
193
- quote: Quote;
194
- };
195
- type GetQuoteParams = {
196
- amount: number | string;
197
- amountLamports: number | string | bigint;
198
- recipient: PublicKey | string;
199
- /** Indexer asset label (default `SOL`). */
200
- asset?: string;
201
- /** Cluster for the quote (default active SDK network). */
202
- network?: Network;
203
- };
204
- /** Fetch a withdraw quote from the indexer. Requires SDK init or an active instance context. */
205
- declare function getQuote(params: GetQuoteParams): Promise<GetQuoteResponse>;
206
-
207
- type ResolvedNoteAsset = {
208
- key: string;
209
- tokenName: TokenDecimalsSymbol;
210
- unit: string;
211
- multiplier: bigint;
212
- mint: string | null;
213
- poolAmounts: readonly number[];
214
- decimals: number;
215
- };
216
-
217
- type VeilixTransferItem = {
218
- mint: PublicKey;
219
- /** Human-readable token amount (e.g. `"1.5"` SOL). */
220
- amount: string;
221
- recipient: PublicKey;
222
- };
223
- type VeilixTransferDepositFailure = {
224
- amount: string;
225
- mint: string;
226
- recipient: string;
227
- };
228
- type VeilixTransferWithdrawFailure = {
229
- note: string;
230
- recipient: string;
231
- };
232
- type VeilixTransferResult = {
233
- error: boolean;
234
- depositFailed: VeilixTransferDepositFailure[];
235
- withdrawFailed: VeilixTransferWithdrawFailure[];
236
- depositSuccess: string[];
237
- };
238
- type VeilixTransferOptions = {
239
- /** When true, all withdraws use the same randomly selected relayer. */
240
- uniqueRelayer?: boolean;
241
- };
242
-
243
- /**
244
- * Veilix SDK client. Create one instance per configuration (network, RPC, wallet).
245
- *
246
- * @example
247
- * ```js
248
- * const { VeilixSDK } = require('veilix-sdk');
249
- * const sdk = await VeilixSDK.create({
250
- * rpcEndpoint: 'https://api.devnet.solana.com',
251
- * wallet,
252
- * network: 'devnet',
253
- * });
254
- * console.log(sdk.config.relayers);
255
- * ```
256
- *
257
- * @example React (wallet-adapter)
258
- * ```tsx
259
- * import { useVeilixSdk } from 'veilix-sdk/react';
260
- *
261
- * function MyComponent() {
262
- * const sdk = useVeilixSdk({ network: 'mainnet' });
263
- * if (!sdk) return null;
264
- * // ...
265
- * }
266
- * ```
267
- *
268
- * @example
269
- * ```ts
270
- * import { VeilixSDK } from 'veilix-sdk';
271
- * const sdk = await VeilixSDK.create({ rpcEndpoint, wallet, network: 'mainnet' });
272
- * await sdk.getEncryptionKey(wallet);
273
- * const { note } = sdk.generateDepositParams(1_000_000_000n, null);
274
- * await sdk.buildDepositTx({ senderPublicKey: wallet.publicKey, note, onChainBackup: true });
275
- * ```
276
- */
277
- declare class VeilixSDK {
278
- static readonly VERSION = "0.0.1";
279
- readonly config: VeilixSdkRuntimeConfig;
280
- private constructor();
281
- /** Create an SDK instance (loads relayers for the inferred network). */
282
- static create(options: VeilixSdkInitOptions): Promise<VeilixSDK>;
283
- private run;
284
- private runAsync;
285
- getConfig(): VeilixSdkRuntimeConfig;
286
- getRpcEndpoint(): string;
287
- getNetwork(): Network;
288
- getProgramIdString(): string;
289
- /** Encryption key derived by {@link getEncryptionKey}; undefined until set. */
290
- get encryptKey(): Uint8Array | undefined;
291
- /** Relayers loaded at initialization; use {@link fetchRelayers} to refresh. */
292
- get relayers(): Relayer[];
293
- getIndexerUrl(): string;
294
- getRiskApiUrl(): string;
295
- getTokenMints(): {
296
- Solana: string;
297
- Veilix: "GAFN64LvtCBoc5BHncVn3JEJGpq42rUzQjPmvMK2UhZH";
298
- Bitcoin: "" | "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh";
299
- Ethereum: "" | "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs";
300
- USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" | "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
301
- };
302
- getVeilixTokenMint(): string;
303
- getTokenMint(symbol: TokenSymbol): string;
304
- getDepositAmounts(symbol: DepositTokenSymbol): readonly number[];
305
- getTokenDecimals(symbol: TokenDecimalsSymbol): number;
306
- resolveCircuitPaths(base?: string): Promise<CircuitPaths>;
307
- getRangeRiskScoreJob(address: string): OracleJob;
308
- getOracleQuote(payer: Keypair | PublicKey, addressToCheck: string): Promise<{
309
- queueAccount: PublicKey;
310
- sigVerifyIx: TransactionInstruction;
311
- }>;
312
- getProgramId(): PublicKey;
313
- getPoolPDA(denominationLamports: number | bigint): [PublicKey, number];
314
- getTokenPoolPDA(mint: PublicKey | string, denominationSmallestUnits: number | bigint): [PublicKey, number];
315
- getTreasuryPDA(): [PublicKey, number];
316
- getCommitmentPDA(commitmentBigInt: bigint | number | string): [PublicKey, number];
317
- getNullifierPDA(nullifierHashBigInt: bigint | number | string): [PublicKey, number];
318
- getNetworkStatePDA(): [PublicKey, number];
319
- buildDepositTx(params: BuildDepositTxParams): Promise<{
320
- tx: Transaction;
321
- note: string;
322
- }>;
323
- /**
324
- * Withdraw to `recipient` using a secret `note`.
325
- * Relayer is chosen at random from {@link config.relayers}, or by {@link WithdrawParams.relayerIdx}.
326
- */
327
- withdraw(params: WithdrawParams, relayerIdx?: number): Promise<WithdrawResult>;
328
- /**
329
- * Private transfer: deposit into the pool (split by supported denominations),
330
- * then withdraw each successful note to the recipient.
331
- *
332
- * Requires {@link getEncryptionKey} before calling (deposits use on-chain backup).
333
- *
334
- * @param tempKeypair Ephemeral keypair co-signed on deposit instructions.
335
- */
336
- veilixTransfer(items: VeilixTransferItem[], tempKeypair: Keypair): Promise<VeilixTransferResult>;
337
- /** Validate a withdraw recipient against the risk API. */
338
- assertWithdrawRecipientAllowed(address: string): Promise<void>;
339
- /** Resolve the token asset encoded in a secret note. */
340
- resolveNoteAsset(amount: string, mint?: string | null, tokenNameHint?: TokenDecimalsSymbol): ResolvedNoteAsset;
341
- fetchPlatformFee(): Promise<string>;
342
- /** Fetch a withdraw quote from the indexer. */
343
- getQuote(params: GetQuoteParams): Promise<GetQuoteResponse>;
344
- fetchCommitments(denomination: number | bigint | string, indexerAsset?: IndexerAsset): Promise<unknown>;
345
- validateNullifier(nullifierHash: string, indexerAsset?: IndexerAsset): Promise<unknown>;
346
- fetchTxStatus(commitmentHex: string, nullifierHashHex: string, indexerAsset?: IndexerAsset): Promise<unknown>;
347
- fetchDepositCountByCommitment(commitment: string, denomination: number | bigint | string, indexerAsset?: IndexerAsset): Promise<unknown>;
348
- fetchWalletBalance(wallet: string, options?: FetchWalletBalanceOptions): Promise<unknown>;
349
- /** Re-fetch relayers from the indexer and update {@link config.relayers}. */
350
- fetchRelayers(): Promise<Relayer[]>;
351
- fetchLatestTransactions(type?: string, indexerAsset?: IndexerAsset): Promise<unknown>;
352
- fetchTxCounts(type?: string, indexerAsset?: IndexerAsset): Promise<unknown>;
353
- normalizePubkeyString(value: unknown): string;
354
- buildRelayPayload(params: BuildRelayPayloadParams): RelayPayload;
355
- submitToRelayer(relayerUrl: string, payload: RelayPayload): Promise<unknown>;
356
- pollRelayerJob(relayerUrl: string, jobId: string, maxWaitMs?: number): Promise<unknown>;
357
- /**
358
- * Derives the note encryption key from a wallet signature and stores it on
359
- * {@link config.encryptKey}. Required before {@link buildDepositTx} with
360
- * `onChainBackup: true`.
361
- *
362
- * Accepts a frontend wallet adapter (`signMessage`) or a backend {@link Keypair}.
363
- */
364
- getEncryptionKey(wallet: EncryptKeyWallet): Promise<Uint8Array>;
365
- encryptData(key: Uint8Array, plaintext: string): Uint8Array<ArrayBufferLike>;
366
- decryptData(key: Uint8Array, combined: Uint8Array): string;
367
- generateRandomFieldElement(): bigint;
368
- createCommitment(nullifier: bigint | number | string, secret: bigint | number | string): bigint;
369
- createNullifierHash(nullifier: bigint | number | string): bigint;
370
- generateDepositParams(amountLamports: bigint | number | string, mint?: string | null): GenerateDepositParamsResult;
371
- parseSecretNote(note: string): Record<string, string>;
372
- publicKeyToFieldElement(publicKeyBytes: Uint8Array | number[]): bigint;
373
- amountToFieldElement(amount: bigint | number | string): bigint;
374
- generateMerkleProof(depositParams: Record<string, unknown>, leaves: unknown[]): unknown;
375
- generateWithdrawProof(depositParams: Record<string, unknown>, leaves: unknown[], recipient: PublicKey | string, relayer: PublicKey | string, fee: bigint | number | string, refund: bigint | number | string, options?: GenerateWithdrawProofOptions): Promise<unknown>;
376
- convertProofToBytes(proof: unknown): Promise<number[] | Uint8Array<ArrayBufferLike>>;
377
- to32ByteBuffer(bigInt: bigint | number | string): Uint8Array<ArrayBufferLike>;
378
- toFixedHex(value: bigint | number | string, length?: number): string;
379
- toFieldElementHex(value: bigint | number | string): string;
380
- formatNoteForDisplay(note: string, segmentLen?: number): string;
381
- appendIndexerAsset(params: URLSearchParams, indexerAsset?: IndexerAsset): void;
382
- /** Program ID for a cluster without an SDK instance. */
383
- static getProgramIdForNetwork(network: Network): string;
384
- }
385
-
386
- export { type BuildDepositTxParams as B, type DepositTokenSymbol as D, type EncryptKeyWallet as E, type FetchWalletBalanceOptions as F, type GenerateDepositParamsResult as G, type IndexerAsset as I, type Network as N, type PreparedCircuitArtifacts as P, type Quote as Q, type RelayPayload as R, type TokenDecimalsSymbol as T, VeilixSDK as V, type WithdrawParams as W, type BuildRelayPayloadParams as a, type GenerateWithdrawProofOptions as b, type GetQuoteParams as c, type GetQuoteResponse as d, type QuoteRelayer as e, type QuoteSplit as f, type QuoteTransaction as g, type Relayer as h, type ResolvedNoteAsset as i, type TokenSymbol as j, type VeilixSdkInitOptions as k, type VeilixSdkRuntimeConfig as l, type VeilixTransferDepositFailure as m, type VeilixTransferItem as n, type VeilixTransferOptions as o, type VeilixTransferResult as p, type VeilixTransferWithdrawFailure as q, type WithdrawResult as r, type WithdrawStatus as s, getQuote as t, prepareCircuitArtifacts as u };