Skip to main content

iOS

Getting started with a new project

  1. Install mopro-cli. See Getting Started.
  2. Create a new project
mopro init --platforms ios \
cd mopro-example-app
  1. Prepare circuits
mopro prepare
  1. Build the project
mopro build --platforms ios
  1. Open the project in xcode
open ios/ExampleApp/ExampleApp.xcworkspace

Getting started with exported bindings

  1. Install mopro-cli. See Getting Started.
  2. Prepare circuits
mopro prepare
  1. Build the project
mopro build --platforms ios
  1. Export bindings
mopro export-bindings --platforms ios --destination out
  1. Create an xcframework with xcodebuild

e.g. for simulator

xcodebuild -create-xcframework \
-library out/ios/aarch64-apple-ios-sim/release/libmopro_ffi.a \
-headers out/ios/Bindings \
-output "out/ios/Mopro.xcframework"

e.g. for both simulator and device
Please specify ios_device_type in mopro-config.toml to build for both device and simulator.

xcodebuild -create-xcframework \
-library out/ios/aarch64-apple-ios-sim/release/libmopro_ffi.a \
-headers out/ios/Bindings \
-library out/ios/aarch64-apple-ios/release/libmopro_ffi.a \
-headers out/ios/Bindings \
-output "out/ios/Mopro.xcframework"
  1. Import both the XCFramework Mopro.xcframework and the Swift file bindings Bindings/mopro.swift files into your project (drag and drop should work).
  2. Use moproFFI in swift like
import moproFFI

...
try initializeMopro()
...

Swift API

MoproCircom

Initialize a MoproCircom object.

Usage:

let moproCircom = MoproCircom()

initialize

Initializes the instance with the given zkeyPath and wasmPath.

func initialize(zkeyPath: String, wasmPath: String)  throws

Usage:

try moproCircom.initialize(zkeyPath: zkeyPath, wasmPath: wasmPath)

generateProof

Generates a proof based on the provided circuit inputs.

func generateProof(circuitInputs: [String: [String]])  throws -> GenerateProofResult

Usage:

var inputs = [String: [String]]()
let a = 3
let b = 5
inputs["a"] = [String(a)]
inputs["b"] = [String(b)]
let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs)

verifyProof

Verifies the provided proof against the given inputs.

func verifyProof(proof: Data, publicInput: Data)  throws -> Bool

Usage:

let isValid = try moproCircom.verifyProof(
proof: generateProofResult.proof,
publicInput: generateProofResult.inputs
)

generateProofStatic

Generates a proof based on the provided circuit inputs.

warning

Note: The function is different from generateProof.
In this function, the zkey and wasm are precompiled during cargo build.
You can specify the mopro-config.toml to build the default circuits.

func generateProofStatic(circuitInputs: [String: [String]]) throws -> GenerateProofResult

verifyProofStatic

Verifies the provided proof against the given inputs.

warning

Note: The function is different from verifyProof.
In this function, the zkey and wasm are precompiled during cargo build.
You can specify the mopro-config.toml to build the default circuits.

func verifyProofStatic(proof: Data, publicInput: Data) throws -> Bool

toEthereumInputs

Convert public inputs data to a string array.

func toEthereumInputs(inputs: Data)  -> [String]

toEthereumProof

Convert proof data to a proof structure which can be submitted to a verifier contract.

func toEthereumProof(proof: Data)  -> ProofCalldata