How etospheres-labs/etopay-sdk works
Project Type and Purpose
• This is ETOPay SDK: a multi‐language, decentralized payment SDK written in Rust.
• It exposes core payment, wallet and transaction functionality via a central Rust “sdk” crate and several support crates (api_types, etopay-wallet), and then generates bindings for Android (JNI), iOS/Swift (FFI), and WebAssembly/JavaScript.
File‐Structure Analysis
• Top‐level Rust crates:
• api_types/ – definitions of all API types (networks, transactions, KYC, viviswap, etc.)
• crates/etopay-wallet/ – low‐level on‐chain wallet client, RPC wrappers, crypto primitives
• sdk/ – high‐level orchestration: configuration, core business logic, backend modules (DLT, KYC, transactions, postident, viviswap), user & wallet management, types, error handling, examples, and tests
• bindings/ – subfolders for android, swift, wasm, each containing build scripts, FFI glue (JNI, module maps, wasm-pack), and examples
• testing/ – end-to-end test harness connecting to Keycloak, cleanup, auth flows
• Supplementary: docs/ (MkDocs site), CI/CD pipelines under .github/workflows, Makefile, devcontainer, sonar, linters, etc.
Key Insights from README
• Core SDK crates published on crates.io
• Quickstart repos in four languages, demonstrating platform integration
• Comprehensive docs site for architecture, examples, modules
Diagramming the Architecture
1. API Types Crate (“api_types”)
2. Wallet Client Crate (“etopay-wallet”)
3. Core SDK Crate (“sdk”)
4. Language/Platform Bindings:
– Android (JNI layer, Java wrappers)
– Swift (FFI layer, Swift package)
– WebAssembly (wasm-pack, JS/TS wrappers)
5. Example Apps & Tests (Rust examples, Android tests, Swift examples, wasm examples)
6. External Services:
– Decentralized Ledger (DLT RPC endpoints)
– KYC/Postident services
– Viviswap exchange API
c. Architectural Patterns & Principles
• Modular micro-crate architecture: separation of concerns (types vs. wallet vs. orchestrator)
• Adapter/FFI pattern for multi-platform support (JNI for Android, module maps for Swift, wasm-pack for JS)
• Clear layering: Core logic → FFI bindings → Consumer apps
• Dependency inversion: core logic depends on traits, wiring occurs in backend modules
d. Technologies & Frameworks
• Rust + Cargo workspaces
• JNI (Android bindings, Gradle wrapper)
• Swift Package Manager + bridging headers
• wasm-pack + webpack + TypeScript examples
• CI/CD: GitHub Actions for Rust, Android, Swift, wasm, GitHub Pages for docs