veilix-sdk
TypeScript SDK for interacting with the Veilix privacy protocol on Solana — deposits, withdrawals, private transfers, and fee quotes.
Veilix uses a UTXO note model: a deposit can be any amount (up to the pool's per-deposit cap), and a withdrawal can take the whole note or only part of it — the remainder comes back as a new change note.
Third-party partners integrating Private Send into their own website or app (quote → wallet sign → deposit → /submit): see docs/partner-private-send.md.
Installation
npm install veilix-sdk
Peer dependencies (optional, for React):
npm install @solana/wallet-adapter-react react
Prerequisites
- A Solana wallet (
Keypair for backend/scripts, or a wallet adapter with signMessage / signTransaction / signAllTransactions for frontend)
- An RPC endpoint or existing
@solana/web3.js Connection
Supported networks: mainnet and devnet (set via network).
Creating a VeilixSDK instance
Create one SDK instance per configuration (network, RPC, wallet). Initialization loads active relayers for the target network.
import { VeilixSDK } from "veilix-sdk";
const sdk = await VeilixSDK.create({
rpcEndpoint: RPC_URL, // or `connection`
wallet,
network: "mainnet",
});
Init options
| Option |
Required |
Description |
wallet |
yes |
Anchor-compatible wallet (Keypair wrapper or wallet adapter) |
rpcEndpoint / connection |
one of |
Solana JSON-RPC URL, or an existing Connection |
network |
yes |
"mainnet" or "devnet" |
circuitPathsBase |
no |
Self-hosted location of withdraw.wasm / withdraw.zkey |
indexerUrl |
no |
Indexer override (defaults to the Veilix indexer of network) |
relayerUrls |
no |
Use these relayers instead of the indexer's list (self-hosted or local relayers) |
governanceProgramId |
no |
DAO governance program override, for a local validator (defaults to the network's; none on mainnet yet) |
After creation, inspect runtime config via sdk.config or helpers like sdk.getNetwork(), sdk.relayers, and sdk.getTokenMints().
Notes
A note is the secret needed to spend deposited funds:
vx2-<amountHex>-<privateKeyHex>-<blindingHex>[-<mint>]
The mint suffix is omitted for SOL. Anyone holding the note can withdraw it, so store it safely. Notes from the previous (fixed-denomination) pool are not compatible; sdk.isLegacyNote(note) detects them.
const parsed = sdk.parseSecretNote(note); // { amount, mint, commitment, commitmentHex, ... }
const status = await sdk.getNoteStatus(note); // { deposited, index, spent, ... }
Note lookups don't reveal which notes you hold. The SDK downloads the full leaf list of each tree from the indexer (/commitments, cached and updated incrementally) and the full list of spent-note markers from the RPC (the program's nullifier accounts), and matches your notes locally. getNoteStatus / getNotesStatus, scanOwnedNotes, countLeavesAfterCommitment and the checks before a withdraw, swap or bridge all work this way.
Only { includeHistory: true } asks the indexer about specific notes, to return the deposit and spending transactions (signature, spentIn). Use it only when the user chooses to share a note, for example for a compliance report. The per-note indexer helpers (validateCommitment, validateNullifier(s), fetchTxStatus, fetchDepositCountByCommitment) are kept for compatibility and have the same effect.
getEncryptionKey
Derives the note-encryption key from a wallet signature and stores it on the SDK instance (sdk.encryptKey). Accepts a backend Keypair or a frontend wallet adapter with publicKey and signMessage.
The wallet signs a Sign In With Solana message bound to the network's official site, devnet.veilixprotocol.com or veilixprotocol.com (notesKeyMessage). Wallets that check these messages, such as Phantom, warn when another site asks for it. That matters: anyone with this signature can open and spend the notes sealed for the account. To bind the key to another site, set notesKeyDomain in VeilixSDK.create; that site's users then get a different key.
await sdk.getEncryptionKey(wallet);
Notes sealed before this version used the unbound message veilix:notes:v1. sdk.getLegacyEncryptionKey(wallet) derives that key as well, so scanOwnedNotes also finds those notes; nothing new is sealed with it. A Keypair gets it automatically with getEncryptionKey. A wallet adapter asks for one more signature.
await sdk.getLegacyEncryptionKey(wallet); // only to find notes from before v2
The key is used to:
- seal a deposit's note into its on-chain encrypted output (
onChainBackup: true), and
- seal the change note of a partial withdrawal,
so that sdk.scanOwnedNotes() can recover every unspent note of the wallet later.
Deposit
1. Generate a note
// 1.5 SOL (lamports)
const { note } = sdk.generateDepositParams(1_500_000_000n, null);
// SPL token — pass the token mint and base units
const usdcMint = sdk.getTokenMint("USDC");
const { note: usdcNote } = sdk.generateDepositParams(
sdk.parseAmountToBaseUnits("25.5", 6),
usdcMint
);
2. Build, sign and send
await sdk.getEncryptionKey(wallet); // required when onChainBackup is true
const tx = await sdk.buildDepositTx({
senderPublicKey: wallet.publicKey,
note,
onChainBackup: true, // recover the note later with scanOwnedNotes (recommended)
computeUnitPrice: 50_000, // optional priority fee (micro-lamports / CU)
});
const signed = await wallet.signTransaction(tx); // VersionedTransaction
const signature = await connection.sendRawTransaction(signed.serialize());
buildDepositTx generates the deposit ZK proof (a few seconds) and returns an unsigned VersionedTransaction. Save the note before sending — it is required to withdraw.
| Parameter |
Description |
senderPublicKey |
Depositor's public key |
note |
Secret note from generateDepositParams |
onChainBackup |
Seal the note into the deposit's encrypted output (requires getEncryptionKey) |
computeUnitPrice |
Priority fee in micro-lamports (default 5000) |
computeUnitLimit |
Compute unit limit override |
The pool's per-deposit cap is available via (await sdk.fetchTreeAccount(mint)).maxDepositAmount.
withdraw
Withdraws a note (or part of it) to a recipient through a relayer. The SDK:
- Validates the recipient against the risk API
- Locates the note in the indexer and checks it is unspent
- Rebuilds the Merkle tree and generates the ZK proof
- Submits the proof to a relayer (random, by index, or by URL)
- Polls until the relayer confirms the on-chain transaction
// Full note
const result = await sdk.withdraw({ note, recipient: "RecipientPubkey..." });
// Partial: withdraw 0.4 SOL, keep the rest as a change note
const partial = await sdk.withdraw({
note,
recipient: "RecipientPubkey...",
amount: 400_000_000n,
});
console.log(partial.changeNote); // save it — it holds the remaining funds
console.log(result.status); // "success" | "failed"
console.log(result.txHash); // withdraw transaction signature
console.log(result.fee); // total fee in base units (protocol + relayer + network)
| Parameter |
Description |
note |
Secret note to spend |
recipient |
Recipient public key (PublicKey or base58 string) |
amount |
Optional base-unit amount before fees; defaults to the full note |
relayerUrl |
Optional relayer URL (otherwise relayerIdx or random, weighted by stake) |
maxFee |
Optional highest total fee accepted (the fee of the quote you showed) |
second argument relayerIdx |
Optional index into sdk.relayers |
The recipient receives amount - fee. When sdk.encryptKey is set, the change note is also sealed on-chain so scanOwnedNotes can find it.
Fees and getWithdrawQuote
A withdrawal pays the protocol wallets' share, the relayer's rate and, with relayers whose /v1/status reports networkFee: true, a network fee: the SOL the withdrawal costs the relayer for good (two spent-note accounts, the signature and, for a token sent to a wallet without that token, its token account), charged in the note's asset. Swaps pay it too, inside the swap quote's fee (quote.networkFee).
Show the quote before the user confirms, then withdraw with the same relayer and maxFee:
const quote = await sdk.getWithdrawQuote({ mint, amount, recipient });
// { relayerUrl, fee, protocolFee, relayerFee, networkFee, newAccount, received } (bigints)
await sdk.withdraw({ note, recipient, amount, relayerUrl: quote.relayerUrl, maxFee: quote.fee });
The recipient is only used locally, to check whether it already has a token account; it is not sent to the relayer. For SOL the SDK refuses a network fee above the actual cost.
scanOwnedNotes
Recovers the wallet's notes by trial-decrypting the pool's encrypted outputs with sdk.encryptKey:
await sdk.getEncryptionKey(wallet);
const notes = await sdk.scanOwnedNotes(); // unspent notes, SOL + configured tokens
// options: { mints: [null, usdcMint], includeSpent: true }
Each entry is a NoteStatus with the re-encoded note, amount, mint, index and spend state. The scan also finds private payments to the wallet's private address and the change of its own payments (see below).
Private payments: getPrivateAddress and sendPrivatePayment
A private payment moves value from your notes to someone else's notes without leaving the pool. A relayer submits it and only its flat fee leaves the pool, so nothing on chain shows who paid, who was paid, or how much.
Every wallet has a private address (vxp1…): two public keys derived from its note encryption key, so the same wallet always gets the same address and finds its payments again on any device. Share it to be paid; it never appears on chain.
await sdk.getEncryptionKey(wallet);
const myAddress = sdk.getPrivateAddress(); // "vxp1…", share it to be paid
// Pay from your notes of one asset (SOL here). The SDK picks one or two of them.
const notes = (await sdk.scanOwnedNotes({ mints: [null] })).map((status) => status.note);
const quote = await sdk.getPayQuote(); // { fee, relayerUrl, ... }: a flat fee, whatever the amount
const result = await sdk.sendPrivatePayment({
to: "vxp1…",
amount: 250_000_000n, // what the recipient gets, in base units
notes,
relayerUrl: quote.relayerUrl,
maxFee: quote.fee, // refused before proving if the fee went up since it was shown
});
// result: { status, txHash, fee, changeNote, spentNotes }. The recipient's scanOwnedNotes finds the payment.
- Fee: flat, never a share of the amount (a share would reveal it): the relayer's SOL costs plus at most the payment margin set on chain (0.001 SOL until the DAO changes it;
sdk.getRelayerLimits() reads it), paid in the payment's asset. The 0.15% protocol fee is charged when money leaves the pool, as before.
- Notes: one payment spends at most two notes. When more are needed,
sendPrivatePayment throws CombineNotesFirstError (with payableNow); sdk.combineNotes({ notes: [a, b] }) combines two notes into one (a payment to yourself) for one fee.
- Addresses:
sdk.parsePrivateAddress(text) / sdk.isPrivateAddress(text) check one; a checksum catches typos. A Solana address is not a private address: to pay one, withdraw.
- What stays public: that a payment happened, when, its relayer and its fee. Deposits and withdrawals stay public as always, so a recipient should withdraw later and a different amount.
- Lower level:
buildPrivatePayPayload / submitPrivatePayPayload, and derivePrivateAddressKeys, encryptPayNote, decryptPayNote, payExtDataHash.
veilixTransfer
End-to-end private transfer: deposits one note per item, then withdraws each note to its recipient via the indexer /submit queue. Handles proving, signing, sending, and settlement.
Keep the window open until it resolves.
import { PublicKey } from "@solana/web3.js";
const result = await sdk.veilixTransfer(
[
{ mint: new PublicKey(sdk.getTokenMint("USDC")), amount: "25", recipient: new PublicKey("Recipient...") },
{ mint: new PublicKey(sdk.getTokenMints().Solana), amount: "1.5", recipient: new PublicKey("Another...") },
],
{ uniqueRelayer: false, onChainBackup: true, downloadNotes: true }
);
if (result.error) {
console.log("Deposit failures:", result.depositFailed);
console.log("Withdraw failures:", result.withdrawFailed); // include the note, still spendable
}
| Option |
Default |
Description |
uniqueRelayer |
false |
Use one random relayer for every withdraw |
onChainBackup |
true when encryptKey is set |
Seal each note into its deposit |
downloadNotes |
true |
Download the notes as CSV (browser) before sending |
depositTransactionVersion |
"auto" |
"auto": up to 5 deposits per v1 transaction when the wallet signs v1, else one per v0 transaction. 0: always v0 |
Partial failures are reported without throwing; result.notes lists every note created.