Coder Social home page Coder Social logo

zesame's Introduction

Zesame

Zesame is an unofficial Swift SDK for Zilliqa. It is written in Swift 5.3. 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

SPM will install all dependencies, either when run from terminal, or when Xcode gets opened. To run tests it is recommended to use optimisation flag, otherwise it takes quite a bit of time to run them:

swift test -Xswiftc -O

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 note that protocol buffers 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 is installed through SPM.

Use protobuf

Stand in the root of the project and run:

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

Add the generated file messages.pb.swift to Models folder.

Dependencies

You will find all dependencies inside the Package.swift, 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.getBalance(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 - approximately a thousand hours of work since May 2018 (see initial commit).

Any donation would be much appreciated:

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

License

Zesame is released under the MIT License.

zesame's People

Contributors

sajjon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

zesame's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.