Skip to main content

Choose Your Platform

The ZK ElGamal Proof SDK is available for both Rust and JavaScript/TypeScript development. Choose the installation method that matches your project.
cargo add solana-zk-sdk

Rust Installation

Prerequisites

1

Install Rust

Ensure you have Rust 1.75 or later installed. The project uses Rust edition 2021.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2

Add to Cargo.toml

Add the SDK to your project’s dependencies:
Cargo.toml
[dependencies]
solana-zk-sdk = "5.0.1"
For Solana program development, you may need additional dependencies:
Cargo.toml
[dependencies]
solana-zk-sdk = "5.0.1"
solana-instruction = "3.2.0"
solana-address = "2.2.0"
3

Import in Your Code

Start using the encryption primitives:
use solana_zk_sdk::encryption::{
    elgamal::{ElGamalKeypair, ElGamalPubkey, ElGamalSecretKey},
    pedersen::Pedersen,
};

Platform-Specific Features

The SDK automatically enables platform-specific features:
When targeting target_os = "solana", certain dependencies like encryption and proof generation are disabled to optimize program size. Full functionality is available for all other platforms.

JavaScript Installation

Prerequisites

1

Node.js Version

Ensure you have Node.js 16 or later installed:
node --version
2

Install Package

Install the WebAssembly package:
npm install @solana/zk-sdk
The package includes pre-compiled WASM binaries for all target environments.
3

Choose Your Import

The package provides different entry points for various environments:
const { ElGamalKeypair, PubkeyValidityProofData } = require('@solana/zk-sdk/node');

Environment-Specific Setup

For Node.js applications, use the CommonJS entry point:
const {
  ElGamalKeypair,
  ElGamalSecretKey,
  ElGamalPubkey,
  PubkeyValidityProofData,
} = require('@solana/zk-sdk/node');

// No initialization needed - ready to use
const keypair = new ElGamalKeypair();
Package Path: ./dist/node/index.cjs

TypeScript Support

The package includes TypeScript definitions for all environments:
import type { ElGamalKeypair, PubkeyValidityProofData } from '@solana/zk-sdk/bundler';

// Type declarations are located at:
// - Node: ./dist/node/index.d.ts
// - Web: ./dist/web/index.d.ts
// - Bundler: ./dist/bundler/index.d.ts

Verify Installation

Create a simple test to verify the installation:
src/main.rs
use solana_zk_sdk::encryption::elgamal::ElGamalKeypair;

fn main() {
    let keypair = ElGamalKeypair::new_rand();
    println!("ElGamal keypair generated successfully!");
}
Run with:
cargo run

Next Steps

Quickstart Guide

Learn how to generate keypairs, encrypt data, and create zero-knowledge proofs.

Core Concepts

Understand the cryptographic foundations of ElGamal encryption and zero-knowledge proofs.

Troubleshooting

The SDK uses curve25519-dalek v4.1.3 with SIMD optimizations. If you encounter performance issues in development builds, the workspace configuration automatically sets opt-level = 3 for this crate.This is already configured in the workspace Cargo.toml and should not require manual intervention.
For web environments, ensure you call await init() before using any SDK functions:
import init, { ElGamalKeypair } from '@solana/zk-sdk/web';

await init(); // Required for web target
const keypair = new ElGamalKeypair();
Node.js and bundler targets do not require initialization.
Some bundlers require enabling WebAssembly support:Webpack 5:
experiments: {
  asyncWebAssembly: true,
}
Vite: No special configuration needed, but exclude from optimization:
optimizeDeps: {
  exclude: ['@solana/zk-sdk'],
}

Build docs developers (and LLMs) love