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:
- Generate the binding using the Mopro CLI
- Integrate the binding into a Swift Package
- How to install the Swift SDK in Xcode
- How to use the package
- 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
- Clone the SDK template repository:
git clone https://github.com/zkmopro/mopro-swift-package
- 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
- Open your project in Xcode.
- Go to File > Add package dependencies.
- In Search or Enter Package URL (e.g. enter the URL: https://github.com/zkmopro/mopro-swift-package)
- 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
- Add the following to your
Podfile
:
pod 'MoproFFI', :git => 'https://github.com/zkmopro/mopro-swift-package'
- 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.