This is a Swift package for Semaphore protocol.
-
Open your project in Xcode.
-
Go to File > Add package dependencies.
-
In Search or Enter Package URL, enter the URL:
https://github.com/zkmopro/SemaphoreSwift
-
Choose the version and add the package to your project.
Add the following to your Package.swift
dependencies:
let package = Package(
name: "YourSwiftProject",
// ...
dependencies: [
.package(url: "https://github.com/zkmopro/SemaphoreSwift") // Or change to your own URL
],
// ...
targets: [
.target(name: "YourSwiftProject", dependencies: ["Semaphore"])
]
)
- Add the following to your
Podfile
:
pod 'Semaphore', :git => 'https://github.com/zkmopro/SemaphoreSwift'
- Run the installation command:
pod install
- Import the package in your Swift code:
import Semaphore
Here is an example of how to integrate and use this package
Import the package:
import Semaphore
let privateKey = "secret".data(using: .utf8)!
// generate an identity from privateKey
let identity = Identity(privateKey: privateKey)
// get the identity commitment
identity.commitment()
// get private key
identity.privateKey()
// get secret scalar
identity.secretScalar()
// convert the type to Element to be used in Group
identity.toElement()
let group = Group(members: [
identity.toElement(),
identity2.toElement()
])
// get root
group.root()
// get depth (TODO: need to be tested)
// get members (TODO: need to be tested)
// index of (TODO: need to be tested)
// add member (TODO: need to be tested)
// add members (TODO: need to be tested)
// update member (TODO: need to be tested)
// remove member (TODO: need to be tested)
let message = "message"
let scope = "scope"
// generate semaphore proof
// It will output a JSON string
// You can parse it with swift JSON parser
let proof = try generateSemaphoreProof(
identity: identity,
group: group,
message: message,
scope: scope,
merkleTreeDepth: 16
)
// verify semaphore proof
let valid = try verifySemaphoreProof(proof: proof)
This package relies on bindings generated by the Mopro CLI. To learn how to build Mopro bindings, refer to the Getting Started section. If you'd like to generate custom bindings for your own circuits or proving schemes, check out the guide on how to use the Mopro CLI: Rust Setup for Android/iOS Bindings.
The bindings' source is from here semaphore-bindings
Then, replace the entire bindings directory with your generated files in the following location: Sources/MoproiOSBindings
Alternatively, you can run the following commands to copy your generated bindings into the correct location:
cp -r ../path/to/your/bindings/MoproiOSBindings ./Sources
This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.