Skip to main content
Version: 0.2.0

Swift SDK

In this section, you'll learn how to build a Swift SDK using Mopro's native bindings. The process includes the following steps:

  1. Generate the binding using the Mopro CLI
  2. Integrate the binding into a Swift Package
  3. How to install the Swift SDK in Xcode
  4. How to use the package
  5. How to publish the package

Generate the bindings using the Mopro CLI

To get started with building Mopro bindings, refer to the Getting Started section. If you’d like to generate custom bindings for your own circuits or proving schemes, see the guide: Rust Setup for Android/iOS Bindings.

Then you will have a MoproiOSBindings in the project directory.

Integrate the bindings into a Swift Package

  1. Clone the SDK template repository:
git clone https://github.com/zkmopro/mopro-swift-package
  1. Replace the generated bindings:

Replace the contents of the Sources/MoproiOSBindings directory with your own generated bindings. Or, copy your bindings using the following command:

cp -r ..<PATH/TO/YOUR/BINDINGS>/MoproiOSBindings ./Sources

How to install the Swift SDK in Xcode

Option 1. Using Xcode

  1. Open your project in Xcode.
  2. Go to File > Add package dependencies.
  3. In Search or Enter Package URL (e.g. enter the URL: https://github.com/zkmopro/mopro-swift-package)
  4. Choose the version and add the package to your project.

Option 2: Using Package.swift

Add the following to your Package.swift dependencies:

let package = Package(
name: "YourSwiftProject",
// ...
dependencies: [
.package(url: "https://github.com/zkmopro/mopro-swift-package") // Or change to your own URL
],
// ...
targets: [
.target(name: "YourSwiftProject", dependencies: ["MoproFFI"])
]
)

Option 3: Using CocoaPods

  1. Add the following to your Podfile:
pod 'MoproFFI', :git => 'https://github.com/zkmopro/mopro-swift-package'
  1. Run the installation command:
pod install

How to use the package

Here is an example of how to integrate and use this example package

import MoproFFI // Name of the package

// ...
let generateProofResult = try generateCircomProof(zkeyPath: zkeyPath, circuitInputs: input_str, proofLib: ProofLib.arkworks)

Or checkout the test-e2e app.

How to publish the package

If you want to publish a package that can be used by React Native or Flutter, you can distribute it via CocoaPods.

To do this, you'll need to update the .podspec file accordingly.

Here is an example script to help you release your package on CocoaPods: release.yml

Acknowledgement

This project is heavily inspired by ezkl-swift-package and follows a similar approach for integrating native cryptographic libraries into Swift via a Swift Package.