Latest 1.0.0
Homepage https://github.com/OpenZesame/Zesame
License MIT
Platforms ios 11.3
Dependencies EllipticCurveKit, CryptoSwift, RxSwift, SwiftProtobuf, Alamofire
Authors

Zesame is an unofficial Swift SDK for Zilliqa. It is written in Swift 5.0. This SDK contains cryptographic methods allowing you to create and restore a wallet, sign and broadcast transactions. The cryptographic methods are implemented in EllipticCurveKit. This SDK uses Zilliqas JSON-RPC API

Getting started

  • Install Brew
  • Install Carthage
  • Build Carthage projects
    carthage bootstrap --platform iOS,macOS --cache-builds --no-use-binaries

Protobuf

Zesame uses the JSON-RPC API and not the protobuf API, however, for the packaging of the transaction we need to use protobuf. Please not that protocolbuffers is only used for the packaging of the transaction, it is not used at all for any communication with the API. All data is sent as JSON to the JSON-RPC API.

We use the apple/swift-protobuf project for protocol buffers, and it is important to note the two different programs associated with swift protobuf:

Install protobuf

protoc-gen-swift

This program is used only for generating our swift files from our .proto files and we install this program using brew (it can also be manually downloaded and built).

Follow installation instructions using brew here.

brew install swift-protobuf

After this is done we can generate .pb.swift files using

$ protoc --swift_out=. my.proto

SwiftProtobuf library

In order to make use of our generated .pb.swift files we need to include the SwiftProtobuf library, which we can do using cocoapods or carhage.

Use protobuf

Stand in the root of the project and run:

protoc --swift_opt=Visibility=Public --swift_out=. Source/Models/Protobuf/messages.proto

Add the generated file messages.pb.swift to corresponding Xcode group.

Dependencies

You will find all dependencies inside the Cartfile, but to mention the most important:

EllipticCurveKit

Zesame is dependent on the Elliptic Curve Cryptography of EllipticCurveKit, for the generation of new wallets, restoration of existing ones, the encryption of your private keys into keystores and the signing of your transactions using Schnorr Signatures.

Other

  • RxSwift: The library uses RxSwift for async programming.

  • JSONRPCKit: For consuming the Zilliqa JSON-RPC API.

API

Closure or Rx

This SDK contains two implementations for each method, one that uses Closures(a.k.a. "Callbacks") and one implementation using RxSwift Observables.

Rx

DefaultZilliqaService.shared.rx.getBalance(for: address).subscribe(
    onNext: { print("Balance: ($0.balance)") },
    onError: { print("Failed to get balance, error: ($0)") }
).disposed(by: bag)

Closure

DefaultZilliqaService.shared.getBalalance(for: address) {
    switch $0 {
    case .success(let balanceResponse): print("Balance: (balanceResponse.balance)") 
    case .failure(let error): print("Failed to get balance, error: (error)")
    }
}

Functions

Have a look at ZilliqaService.swift for an overview of the functions, here is a snapshot of the current functions of the reactive API (each function having a closure counterpart):

public protocol ZilliqaServiceReactive {
    func createNewWallet() -> Observable<Wallet>
    func exportKeystore(from wallet: Wallet, encryptWalletBy passphrase: String) -> Observable<Keystore>
    func importWalletFrom(keyStore: Keystore, encryptedBy passphrase: String) -> Observable<Wallet>

    func getBalance(for address: Address) -> Observable<BalanceResponse>
    func sendTransaction(for payment: Payment, signWith keyPair: KeyPair) -> Observable<TransactionIdentifier>
}

Explorer

While developing it might be useful for you to use the Zilliqa explorer

Donate

This SDK and the foundation EllipticCurveKit its built upon has been developed by the single author Alexander Cyon without paid salary in his free time – approximatly a thousand hours of work since May 2018 (see initial commit).

Any donation would be much appreciated:

  • BTC: 3GarsdAzLpEYbhkryYz1WiZxhtTLLaNJwo
  • ETH: 0xAB8F0137295BFE37f50b581F76418518a91ab8DB
  • NEO: AbbnnCLP26ccSnLooDDcwPLDnfXbVL5skH

License

Zhip is released under the MIT License.

Latest podspec

{
    "name": "Zesame",
    "version": "1.0.0",
    "swift_versions": "5.0",
    "platforms": {
        "ios": "11.3"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "Zilliqa SDK in pure Swift",
    "homepage": "https://github.com/OpenZesame/Zesame",
    "authors": {
        "Alex Cyon": "[email protected]"
    },
    "source": {
        "git": "https://github.com/OpenZesame/Zesame.git",
        "tag": "1.0.0"
    },
    "source_files": "Source/**/*.swift",
    "social_media_url": "https://twitter.com/alexcyon",
    "dependencies": {
        "EllipticCurveKit": [
            "~> 1.0.0"
        ],
        "CryptoSwift": [
            "~> 1.0.0"
        ],
        "RxSwift": [],
        "SwiftProtobuf": [],
        "Alamofire": [
            "~> 5.0.0-beta.3"
        ]
    }
}

Pin It on Pinterest

Share This