Skip to content

zkmopro/SemaphoreSwift

Repository files navigation

Semaphore Swift Package

This is a Swift package for Semaphore protocol.

How to Import the Package

Option 1: Using Xcode

  1. Open your project in Xcode.

  2. Go to File > Add package dependencies.

  3. In Search or Enter Package URL, enter the URL: https://github.com/zkmopro/SemaphoreSwift

  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/SemaphoreSwift") // Or change to your own URL
    ],
    // ...
    targets: [
        .target(name: "YourSwiftProject", dependencies: ["Semaphore"])
    ]
)

Option 3: Using CocoaPods

  1. Add the following to your Podfile:
pod 'Semaphore', :git => 'https://github.com/zkmopro/SemaphoreSwift'
  1. Run the installation command:
pod install
  1. Import the package in your Swift code:
import Semaphore

How to Use the Package

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

Import the package:

import Semaphore

Identity

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()

Group

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)

Proof

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)

How to Build the Package

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

Community

  • X account:
  • Telegram group:

Acknowledgements

This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published