SDK Architecture

SDK Architecture - Technical Deep Dive

This document provides a comprehensive technical overview of the Roru SDK architecture, including detailed component descriptions, data flows, and implementation details.

Architecture Overview

SDK Structure

The Roru SDK is organized into four distinct layers, each with specific responsibilities:

┌─────────────────────────────────────────┐
│         Application Layer                 │
│  (Your Application Code)                  │
└──────────────┬────────────────────────────┘

┌──────────────▼────────────────────────────┐
│           API Layer                        │
│  - TransactionBuilder                     │
│  - Wallet API                              │
│  - ProofGenerator                          │
│  - StateSync                               │
│  - OfflineTransfer                         │
└──────────────┬────────────────────────────┘

┌──────────────▼────────────────────────────┐
│           Core Layer                       │
│  - Note Management                         │
│  - Commitment Operations                   │
│  - Nullifier Generation                    │
│  - Merkle Tree Operations                  │
│  - Key Management                          │
└──────────────┬────────────────────────────┘

┌──────────────▼────────────────────────────┐
│        Protocol Layer                      │
│  - Shielded State Tree                     │
│  - ZK Circuit Execution                    │
│  - Proof Generation/Verification            │
│  - Transaction Validation                 │
└──────────────┬────────────────────────────┘

┌──────────────▼────────────────────────────┐
│         Network Layer                      │
│  - Encrypted RPC Client                    │
│  - WebSocket Connections                   │
│  - State Synchronization                  │
│  - Transaction Broadcasting               │
└────────────────────────────────────────────┘

Layer Responsibilities

API Layer:

  • Provides high-level, developer-friendly interfaces

  • Handles input validation and error formatting

  • Manages async operations and callbacks

  • Abstracts protocol complexity

Core Layer:

  • Implements cryptographic primitives

  • Manages local state and caching

  • Handles key derivation and storage

  • Performs note selection and management

Protocol Layer:

  • Executes zero-knowledge circuits

  • Generates and verifies proofs

  • Manages shielded state tree

  • Validates transactions

Network Layer:

  • Handles all network communication

  • Manages connection pooling and retries

  • Implements encryption and authentication

  • Synchronizes state with infrastructure

Core Components

RoruClient

The RoruClient is the main entry point for SDK operations. It manages connections, configuration, and provides access to all SDK functionality.

Rust Implementation:

TypeScript Implementation:

Wallet

The Wallet component manages user funds, transactions, and state synchronization.

Rust Implementation:

Module Structure

Transaction Module

Purpose: Build and manage private transactions

Key Types:

Proof Module

Purpose: Generate and verify zero-knowledge proofs

Key Types:

State Module

Purpose: Manage and synchronize shielded state

Key Types:

Network Module

Purpose: Handle network communication

Key Types:

Data Flow

Transaction Creation Flow

State Synchronization Flow

Configuration

ClientConfig

Rust:

TypeScript:

Error Handling

Error Types

Performance Considerations

Caching

  • State cache: Reduces network calls

  • Proof cache: Reuses proofs when possible

  • Address cache: Fast address lookups

Optimization

  • Batch operations: Multiple transactions at once

  • Parallel proof generation: Multiple proofs concurrently

  • Incremental sync: Only download changes

Conclusion

The SDK architecture provides:

  • Modularity: Clear separation of concerns

  • Extensibility: Easy to add new features

  • Performance: Optimized for production use

  • Developer Experience: Clean, intuitive APIs

  • Security: Secure key management and operations

Understanding the SDK architecture is essential for effective development with Roru Labs.

Last updated