Javascript Client Library
JavaScript Client Library
Intent Signing + Proof Generation • Relayer Sync + Witness Resolver
The SnarkSide JavaScript Client Library provides a high-level interface for dApp developers, trading bots, and relayer nodes to interact with the protocol’s encrypted intent layer. While the ZK Wallet SDK handles full account abstraction and stealth vault workflows, the JS Client Library is purpose-built for real-time, headless systems that need to:
Sign and blind intents
Generate or request ZK proofs
Resolve Merkle witnesses
Sync with the off-chain relayer mesh
This client does not expose raw transaction mechanics—it interfaces with SnarkSide’s encrypted execution architecture at the intent and proof level.
1. Intent Signing Workflow
Each trade begins with an off-chain Intent object. The client library signs this using a Poseidon-compatible keypair and serializes the result for relayer ingestion.
import { Intent, Signer } from '@snarkside/client';
const keypair = Signer.generateKeyPair(seed);
const intent = Intent.create({
action: 'open',
market: 'SOL-PERP',
size: 50000,
leverage: 8,
expiry: Date.now() + 30 * 60 * 1000,
});
const signedIntent = Signer.sign(intent, keypair.privateKey);The output is a fully blinded, tamper-proof payload that can be transmitted across a trustless matching layer.
2. Proof Generation (Local or Remote)
The JS client can either:
Generate proofs locally (via Circom + SnarkJS)
Delegate to a prover node (using secure RPC)
import { ProofGenerator } from '@snarkside/client';
const witness = await ProofGenerator.calculateWitness({
circuitName: 'intent',
inputs: {
intentHash: signedIntent.hash(),
vaultRoot: localVaultRoot,
oracleCommitment,
},
});
const proof = await ProofGenerator.generateProof({
circuitName: 'intent',
witness,
});All circuits follow a strict spec and use Groth16-compatible keys. The client auto-selects optimized parameters for browser, Node, or edge runtimes.
3. Relayer Sync & Batching
To maintain relayer compatibility, the client library includes lightweight sync modules:
import { RelayerClient } from '@snarkside/client';
const relayer = new RelayerClient('https://relay.snarkside.app');
await relayer.sendIntent(signedIntent);
await relayer.confirmBatch({
proof: zkProof,
batchRoot: calculatedMerkleRoot,
});Relayers respond with:
Batch inclusion receipts
Nullifier confirmations
Rejection proofs (if circuit constraints fail)
4. Witness Resolver
The witness resolver module handles:
Merkle proof path generation
Nullifier set updates
Vault state tracking via Merkle frontiers
import { WitnessResolver } from '@snarkside/client';
const witness = await WitnessResolver.resolveVault({
vaultHash: userVaultCommitment,
epoch: 'latest',
});This allows intents to be constructed with minimal latency while preserving circuit validity.
5. Example: Bot Execution
const market = 'ETH-PERP';
const userSeed = '...';
const intent = Intent.createLongETH({ size: 10_000, leverage: 10 });
const keypair = Signer.derive(userSeed);
const signed = Signer.sign(intent, keypair.privateKey);
const proof = await ProofGenerator.generateFromIntent(signed);
await RelayerClient.submit({ signedIntent: signed, proof });This flow can be run statelessly from CLI scripts, cloud workers, or hosted matching bots.
6. Planned Features
Intent DSL
Write trade strategies in a scripting format
Fee Bidding API
Dynamically adjust $SNSD tips via volatility
L2 Bridge Hooks
Trigger cross-chain matching logic
Encrypted Oracle Adapter
Use client-verified oracle streams
Conclusion
The SnarkSide JavaScript Client Library offers:
Lightweight encrypted intent signing
Local or delegated proof generation
Real-time relayer sync
Vault and nullifier witness resolution
Built to support automated trading, dark matching networks, and trustless settlement infrastructure, this library forms the execution backbone of a fully private, fully verifiable DeFi future.
Last updated

