Privacy SDK for Solana with optional x402 payment support - Python interface with Rust cryptographic backbone
Project description
Mirage SDK
Privacy SDK infrastructure for Solana - Python interface with Rust cryptographic backbone
Mirage provides production-ready privacy primitives for Solana applications with optional x402 payment integration for chain-agnostic micropayments.
๐ Features
- Privacy-Preserving Transactions: zkSNARK-based private transfers on Solana
- Multi-Asset Support: Native SOL and SPL tokens
- x402 Payment Integration: Pay for privacy services using any supported blockchain
- Production Ready: Battle-tested cryptography with comprehensive test coverage
- Developer Friendly: Clean Python API with Rust performance
๐ฆ Package Structure
Mirage is a unified Python package with embedded Rust cryptographic backend:
- Rust Core: High-performance cryptography (Poseidon, Groth16, Merkle trees) via PyO3
- Python SDK: Clean API for Solana privacy operations with optional x402 support
- On-chain Program: Separate Solana program (Anchor) in
packages/mirage-solana/
๐ Quick Start
Installation
pip install mirage-solana
Basic Usage
from mirage import PrivacyClient
from solders.keypair import Keypair
# Initialize client
client = PrivacyClient(rpc_url="https://api.mainnet-beta.solana.com")
user_keypair = Keypair()
# Shield assets (deposit into privacy pool)
secret, commitment = client.shield_assets(
amount=1_000_000_000, # 1 SOL
token="SOL",
keypair=user_keypair
)
# Private transfer (requires proof generation)
tx = await client.private_transfer_async(
recipient=recipient_address,
amount=500_000_000, # 0.5 SOL
sender_secret=secret,
sender_commitment=commitment
)
# Unshield assets (withdraw from privacy pool)
tx = client.unshield_assets(
commitment=commitment,
secret=secret,
recipient=user_keypair.pubkey()
)
x402 Payment Integration
from mirage.x402 import X402Client
# Pay for privacy services using Base USDC
async with X402Client(network="base", wallet_address="0x...") as x402:
payment = await x402.pay_for_access(
resource_url="https://mirage-api.network/privacy/shield",
price_usd=0.01,
merchant_address="0xMERCHANT..."
)
# Use privacy features with access token
tx = await privacy.shield_assets_async(
amount=1_000_000_000,
access_token=payment.access_token
)
๐ง Development
Prerequisites
- Python 3.12+
- Rust 1.70+
- Solana CLI tools
- Anchor Framework (for Solana program)
Building from Source
# Clone the repository
git clone https://github.com/miragesolana/mirage-sdk.git
cd mirage-sdk
# Install all packages in development mode
make install-dev
# Run tests
make test
# Build all packages
make build
๐บ๏ธ Roadmap
Phase 1: Foundation & Cryptographic Core โ (Q3 2025)
Status: COMPLETED
Cryptographic Primitives
- โ BN254 Elliptic Curve: G1/G2 group operations, pairing-based cryptography
- โ Poseidon Hash Function: Optimized for zkSNARKs (t=3, RF=8, RP=57, ~200 constraints/hash)
- โ
Pedersen Commitments: Perfectly hiding, computationally binding with domain separator
MIRAGE_PROTOCOL_PEDERSEN_H_V1 - โ Nothing-Up-My-Sleeve: H generator derived via domain separation (no trusted setup for commitments)
Merkle Tree Implementation
- โ Depth-20 Poseidon Tree: Supports ~1,048,576 leaves for privacy pool
- โ Filled Subtrees Optimization: O(log n) insertion performance
- โ Zero-Hash Precomputation: Efficient empty node handling
- โ Incremental Updates: On-chain state synchronization
Core Infrastructure
- โ Rust Core Library: High-performance cryptography with arkworks-rs ecosystem
- โ PyO3 Bindings: Seamless Python-Rust interop for SDK
- โ Testing Framework: Comprehensive unit tests for all crypto primitives
Phase 2: Privacy Protocol & zkSNARKs โ (Q3-Q4 2025)
Status: COMPLETED
Groth16 zkSNARK Circuit
- โ Transfer Circuit: ~7,000 R1CS constraints for private transfers
- โ Public Inputs: merkle_root (32 bytes), nullifier (32 bytes), new_commitment (32 bytes)
- โ Private Inputs: secret, amounts, blinding factors, Merkle path (20 siblings)
- โ
Constraint Breakdown:
- Spending key derivation: ~400 constraints
- Input commitment verification: ~500 constraints
- Merkle membership proof: ~4,000 constraints (20 Poseidon hashes)
- Nullifier derivation: ~400 constraints
- Output commitment: ~500 constraints
- Range checks: ~1,200 constraints
Circuit-Safe Nullifier System
- โ Two-Step Derivation: Prevents secret leakage in constraint system
- โ
Step 1:
spending_key = Poseidon(secret || "MIRAGE_SPENDING_KEY") - โ
Step 2:
nullifier = Poseidon(spending_key || Hash(leaf_index || "MIRAGE_NULLIFIER")) - โ Unlinkability: Nullifiers cannot be linked to commitments without secret
ECDH Note Encryption
- โ Key Exchange: Elliptic Curve Diffie-Hellman on BN254 G1
- โ Symmetric Encryption: ChaCha20-Poly1305 AEAD (authenticated encryption)
- โ Encrypted Note Format: 32 bytes ephemeral key + 48 bytes data + 16 bytes MAC = 96 bytes
- โ Forward Secrecy: Ephemeral keys provide forward secrecy
- โ Recipient Discovery: Trial decryption for note scanning
Privacy Operations
- โ Shield: Convert public SOL to private commitments
- โ Private Transfer: Zero-knowledge transfer between notes (2-5s proof generation)
- โ Unshield: Withdraw to public Solana addresses
- โ Note Management: Local storage, scanning, and tracking
Phase 3: Production Launch & Mainnet โ (Q4 2025)
Status: COMPLETED โข LIVE ON MAINNET ๐
Solana On-Chain Program
- โ Anchor Framework: Production-grade smart contract (v0.29.0)
- โ
Program ID:
6p1tzefXSST8j72qcj5EU3pAcY5qSc3HnCfFqc2gWxjM - โ
PDA-Based Nullifiers: Double-spend prevention via Anchor
initconstraint - โ 30-Root History Buffer: Front-running protection (~1 minute validity window)
- โ
Groth16 Verification:
200k CU ($0.0002 per proof at $100 SOL) - โ Mainnet Deployment: Audited and battle-tested on production
Production SDK
- โ
Unified Python Package:
pip install mirage-solana(single command) - โ Embedded Rust Backend: PyO3 + maturin for native performance
- โ Async/Sync APIs: Full support for both async and sync operations
- โ Type Safety: Comprehensive type hints and Pydantic models
- โ Test Coverage: 80+ unit and integration tests passing
- โ Documentation: API reference, quickstart guides, examples
x402 Payment Integration
- โ Chain-Agnostic Payments: HTTP 402 Payment Required protocol
- โ 15+ Supported Networks: Base, Polygon, Avalanche, Solana, IoTeX, Peaq, Sei, XLayer
- โ EIP-712 Signatures: Secure payment authentication for EVM chains
- โ Gas Abstraction: Pay Solana fees using other blockchain tokens
- โ Facilitator Network: Payment verification and settlement infrastructure
Security Hardening
- โ Front-Running Protection: 30-root history prevents proof invalidation
- โ Constant-Time Operations: Timing attack resistance in cryptographic code
- โ Circuit Safety: Two-step nullifier prevents secret exposure
- โ PDA Constraints: Solana program uses init constraints for safety
- โ Secure Randomness: OsRng for cryptographically secure random generation
Infrastructure
- โ Relayer Protocol: IP privacy layer with transaction submission service
- โ Fee Structure: Default 0.3% (30 basis points), max 5% cap
- โ Self-Hostable: Open-source relayer software for censorship resistance
- โ Build System: Maturin-based build for Python + Rust distribution
- โ CI/CD: Automated testing and deployment pipelines
Phase 4: Multi-Asset Privacy & Ecosystem ๐ฅ (Q1 2026)
Status: IN PROGRESS โข Priority: SPL Token Support
Core Protocol
- โณ SPL Token Privacy: Private transfers for USDC, USDT, BONK, and all SPL tokens
- โณ Multi-Asset Pools: Separate privacy pools per token with unified commitment scheme
- โณ Batch Operations: Aggregate multiple shields/transfers for 40-50% gas savings
- โณ Relayer Network v1: Public relayer marketplace with reputation scoring
Ecosystem Integration
- ๐ Jupiter Integration: Private swaps through Jupiter aggregator with MEV protection
- ๐ Orca Whirlpools: Concentrated liquidity positions with hidden amounts
- ๐ Marginfi Lending: Private collateral deposits and anonymous borrowing
- ๐ Developer SDK v2: GraphQL indexer, TypeScript bindings, REST API
Tooling & Infrastructure
- ๐ Block Explorer: Privacy-preserving transaction viewer with encrypted note tracking
- ๐ Mobile SDK Preview: React Native proof-of-concept for iOS/Android
- ๐ Monitoring Dashboard: Real-time anonymity set size, pool TVL, relayer health
Phase 5: AI Agent Privacy & x402 Expansion ๐ค (Q1-Q2 2026)
Status: PLANNED โข Focus: Autonomous Privacy
AI Agent Infrastructure
- ๐ Agent Privacy SDK: Pre-built modules for autonomous trading with hidden positions
- ๐ Multi-Agent Coordination: Encrypted state sharing between AI agents via x402 payments
- ๐ Agent Wallet System: Hierarchical deterministic wallets with view-only scanning keys
- ๐ Private Order Flow: Submit trades through encrypted channels to prevent front-running
x402 Deep Integration
- ๐ Cross-Chain Privacy Payments: Pay Solana relayer fees using Base USDC, Polygon USDC, etc.
- ๐ Service Marketplace: x402-enabled privacy services (mixing, relaying, compliance)
- ๐ Agent-to-Agent Payments: Private micropayments between autonomous agents
- ๐ Gas Abstraction Layer: Let agents operate without holding SOL for fees
MEV Protection Suite
- ๐ Private Limit Orders: Hidden order books with zero-knowledge matching
- ๐ Encrypted Mempool: Submit transactions through relayers with delayed reveal
- ๐ JIT Protection: Just-in-time liquidity shielding for large trades
- ๐ Sandwich Attack Prevention: Circuit-level guarantees against MEV exploitation
Phase 6: Institutional Privacy & Compliance ๐๏ธ (Q2 2026)
Status: PLANNED โข Focus: Enterprise Adoption
Advanced Privacy Features
- ๐ Stealth Addresses: One-time addresses for recipient unlinkability (BIP47-style)
- ๐ Viewing Keys: Separate scan/spend keys for auditing without spending permission
- ๐ Multi-Sig Shielded Wallets: Threshold signatures for institutional custody
- ๐ Time-Locked Reveals: Commitments that auto-disclose after time period
Compliance & Regulatory
- ๐ Zero-Knowledge Compliance: Prove transaction legitimacy without revealing details
- ๐ Selective Disclosure: Share specific transaction data with auditors/regulators
- ๐ Range Proofs: Prove amount > threshold without revealing exact value
- ๐ Whitelisted Recipients: Circuit constraints for approved counterparties
DeFi Composability
- ๐ Drift Protocol: Private perpetual positions with hidden leverage
- ๐ Kamino Vaults: Anonymous yield farming strategies
- ๐ Phoenix DEX: Private order book trading
- ๐ Sanctum LST: Private liquid staking positions
Developer Experience
- ๐ WebAssembly Proofs: Browser-based proof generation (no backend needed)
- ๐ Rust SDK: Native Rust API for Solana programs
- ๐ Privacy-as-a-Service API: Hosted proving service for mobile/web apps
- ๐ Testing Framework: Local privacy pool for development
Beyond Q2 2026: Vision ๐
Cross-Chain Privacy Bridges
- Wormhole integration for Ethereum/Polygon private bridging
- Unified privacy layer across Solana, EVM chains, and Cosmos
Advanced Cryptography
- Recursive SNARKs for unlimited transaction batching
- Halo2 migration for trustless setup
- Post-quantum secure privacy primitives
Decentralized Infrastructure
- DHT-based relayer discovery (no central directory)
- Slashing mechanism for malicious relayers
- Community-run trusted setup ceremonies
Legend: โ Completed โข โณ In Progress โข ๐ Planned (Next 1-6 months) โข ๐ Live โข ๐ฅ Priority Focus
๐ Documentation
- Getting Started: miragesdk.com/docs/getting-started/overview
- API Reference: miragesdk.com/docs/api
- Architecture: docs/ARCHITECTURE.md
- Migration Guide: MIGRATION.md (from Veil 0.1.x)
๐ Supported Networks (x402)
Mirage x402 integration supports payments on 15+ blockchains:
Mainnets: Base, Polygon, Avalanche, Solana, IoTeX, Peaq, Sei, XLayer Testnets: Base Sepolia, Polygon Amoy, Avalanche Fuji, Solana Devnet, and more
See x402 networks documentation for full list.
๐ก๏ธ Security
- Audit Status: Internal review complete
- Bug Bounty: Coming soon
- Security Contact: security@mirage-sdk.com
โ ๏ธ Important: Mirage 0.1.0 (formerly Veil) uses incompatible cryptographic domain separators. See MIGRATION.md for details.
๐ License
MIT License - see LICENSE for details
๐ค Contributing
Contributions welcome! Please see our contributing guidelines.
Mirage - Privacy by design โข Built with โค๏ธ using Rust and Python
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mirage_solana-0.1.0.tar.gz.
File metadata
- Download URL: mirage_solana-0.1.0.tar.gz
- Upload date:
- Size: 214.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9395ade3d81dc5c19212ca29b8678704287fab55b3fed993b4c5f193d6ae7520
|
|
| MD5 |
613eadf7322b359487f5601ec0659226
|
|
| BLAKE2b-256 |
900616c2ff4040cf20904f8c6e56c624b5a798b5abfe5d6dce74380d77c31f7c
|
File details
Details for the file mirage_solana-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: mirage_solana-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 332.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9796880125d52b15594577806e45ca423e540603f72f348b798da41eda5366d
|
|
| MD5 |
f8f545fa9909130b6f78232bd8f22eb2
|
|
| BLAKE2b-256 |
855365921443942ad06fe1b76a5c6d02eddb44eba6da26797ab623e033e4d711
|
File details
Details for the file mirage_solana-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: mirage_solana-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 333.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
660f02877a8e545e171d0985060a981de9455a7be5d21712cc7becb6a132d625
|
|
| MD5 |
7cf3e7a26fb3043476246597f383ee90
|
|
| BLAKE2b-256 |
89a49c6d3d237349ae39b7477ade48f86adf01dd52294e074ec8cfb3c03cce55
|
File details
Details for the file mirage_solana-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: mirage_solana-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 333.1 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
386fce56133d15d64ee5f74b4244af81d2da797aa4133256c1d2294da1dee770
|
|
| MD5 |
f4416629d160587bfd9d856ea143a755
|
|
| BLAKE2b-256 |
8347ee3a37952c3bbe9c3230dcc1555f7de1cc95c3eae6d1ef60d82e3e0bfea6
|
File details
Details for the file mirage_solana-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: mirage_solana-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 333.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c485f71d5fc68fbe2b24d99d38f794f269c89ebfa7c3aadbf6f6581e1526f0fa
|
|
| MD5 |
ca4677aac8d6c3f9103ff34a7d7bd4f2
|
|
| BLAKE2b-256 |
63bea4acf2406c354fa7b84473fd9c034ba8ce88e7a13f58d3a827c7f18f0682
|