Skip to main content

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.

Documentation License: MIT Python 3.12+ Rust

๐ŸŒŸ 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 init constraint
  • โœ… 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

๐ŸŒ 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

โš ๏ธ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mirage_solana-0.1.0.tar.gz (214.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mirage_solana-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl (332.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

mirage_solana-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (333.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

mirage_solana-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (333.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

mirage_solana-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (333.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

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

Hashes for mirage_solana-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9395ade3d81dc5c19212ca29b8678704287fab55b3fed993b4c5f193d6ae7520
MD5 613eadf7322b359487f5601ec0659226
BLAKE2b-256 900616c2ff4040cf20904f8c6e56c624b5a798b5abfe5d6dce74380d77c31f7c

See more details on using hashes here.

File details

Details for the file mirage_solana-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mirage_solana-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c9796880125d52b15594577806e45ca423e540603f72f348b798da41eda5366d
MD5 f8f545fa9909130b6f78232bd8f22eb2
BLAKE2b-256 855365921443942ad06fe1b76a5c6d02eddb44eba6da26797ab623e033e4d711

See more details on using hashes here.

File details

Details for the file mirage_solana-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mirage_solana-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 660f02877a8e545e171d0985060a981de9455a7be5d21712cc7becb6a132d625
MD5 7cf3e7a26fb3043476246597f383ee90
BLAKE2b-256 89a49c6d3d237349ae39b7477ade48f86adf01dd52294e074ec8cfb3c03cce55

See more details on using hashes here.

File details

Details for the file mirage_solana-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mirage_solana-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 386fce56133d15d64ee5f74b4244af81d2da797aa4133256c1d2294da1dee770
MD5 f4416629d160587bfd9d856ea143a755
BLAKE2b-256 8347ee3a37952c3bbe9c3230dcc1555f7de1cc95c3eae6d1ef60d82e3e0bfea6

See more details on using hashes here.

File details

Details for the file mirage_solana-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for mirage_solana-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c485f71d5fc68fbe2b24d99d38f794f269c89ebfa7c3aadbf6f6581e1526f0fa
MD5 ca4677aac8d6c3f9103ff34a7d7bd4f2
BLAKE2b-256 63bea4acf2406c354fa7b84473fd9c034ba8ce88e7a13f58d3a827c7f18f0682

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page