Swift

Swift Package for integrating Colibri Stateless Client into iOS and macOS applications. These bindings provide a native Swift API for secure, verified blockchain interactions without trusting centralized infrastructure.

Overview

The Colibri Swift Bindings enable you to verify Ethereum RPC calls with cryptographic proofs, directly in Swift applications. This provides Web3 functionality without dependency on centralized RPC providers.

Core Features

  • πŸ” Cryptographic Verification - All RPC responses are validated with Merkle proofs

  • πŸ“± iOS + macOS Support - Native Swift Package for all Apple platforms

  • πŸ—„οΈ Flexible Storage System - Customizable storage implementations for different use cases

  • ⚑ Performance - Optimized C libraries with Swift interface

  • πŸ§ͺ Comprehensive Testing - Complete integration tests with mock data

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Swift Application Layer                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                     Colibri.swift API                           β”‚
β”‚  β€’ Colibri class (main interface)                               β”‚
β”‚  β€’ RequestHandler protocol                                      β”‚
β”‚  β€’ ColibriStorage protocol                                      β”‚
β”‚  β€’ Error handling & type conversion                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                  Swift-C Bridge Layer                           β”‚
β”‚  β€’ swift_storage_bridge.c                                       β”‚
β”‚  β€’ Function pointer callbacks                                   β”‚
β”‚  β€’ Memory management                                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                   Core C Libraries                              β”‚
β”‚  β€’ Prover (proof generation)                                   β”‚
β”‚  β€’ Verifier (proof verification)                                β”‚
β”‚  β€’ Storage plugin system                                        β”‚
β”‚  β€’ Cryptographic libraries (blst, ed25519)                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

iOS Integration

For iOS applications, use the pre-built XCFramework:

iOS Example App

The CI-Pipeline contains a minimalistic Example and TestApp for iOS, which is used to test the integration. You can look at the code as an example on how to use certain features.

The code can be found in the bindings/swift/test_ios_apparrow-up-right.

macOS Development

For macOS development with local static libraries:

Development Workflow

Local macOS Build

What happens during build:

  1. Compile C Libraries - All core libraries (Prover, Verifier, Crypto)

  2. Swift Storage Bridge - C-Swift interop for storage system

  3. Generate Integration Tests - Automatic generation of test functions from test/data

  4. Prepare Package - Swift Package with all dependencies

iOS XCFramework Build

XCFramework Structure:

Test System

Unit Tests

  • Initialization Tests - Colibri setup and configuration

  • Method Support Tests - RPC method availability

  • Storage Tests - Custom storage implementations

  • Error Handling Tests - Error handling and edge cases

Integration Tests

  • 23 automatically generated tests from test/data/*/test.json

  • Mock HTTP Requests - Offline tests with real blockchain data

  • Sequential Execution - Storage is global, tests run sequentially

  • Result Verification - Structural and string-based comparison

iOS Test App

The iOS test app serves as:

  • CI Integration Test - Verifies package integration in CI

  • Developer Example - Reference implementation for iOS developers

  • API Demonstration - Shows all important Colibri APIs

API Reference

Colibri Class

Storage System

Error Handling

Storage Implementations

Default File Storage

UserDefaults Storage (iOS)

Core Data Storage

Chain Configurations

Supported Chains

Multi-Chain Setup

Performance Optimization

Storage Performance

Memory Management

Testing

Mock Request Handler

Test Utils

CI/CD Integration

GitHub Actions

The Swift bindings are fully integrated into the CI/CD pipeline:

Automatic Distribution

On every release, a distribution package is automatically created:

  1. iOS XCFramework for Device + Simulator

  2. Swift Package with binaryTarget

  3. Upload to separate distribution repository

  4. Release on GitHub with versioning

Troubleshooting

Common Issues

"No such module 'Colibri'"

iOS Simulator Crashes

RPC Calls Fail

Storage Permissions

Debug Tips

Storage Debug

Network Debug

Platform Specifics

iOS Considerations

  • App Transport Security: HTTPS required for all prover URLs

  • Background Tasks: RPC calls in background apps may be terminated

  • Memory Limits: Adjust storage cache size to iOS memory limits

  • Network Reachability: Offline capabilities through local proof generation

macOS Considerations

  • Sandboxing: Configure file system access for storage

  • Code Signing: All C libraries must be signed

  • Rosetta: Intel Mac compatibility through Universal Binaries

Further Information

Last updated