Giter VIP home page Giter VIP logo

diwakarthapa / iroha-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyperledger/iroha-ios

0.0 1.0 0.0 115.01 MB

iOS Swift library for Iroha, a simple distributed ledger

Home Page: http://iroha.tech

License: Apache License 2.0

Ruby 0.01% Swift 0.44% Objective-C 0.02% Objective-C++ 0.02% C++ 99.31% C 0.19% CMake 0.01% Perl 0.01% HTML 0.01% M4 0.01% Batchfile 0.01% Shell 0.01%

iroha-ios's Introduction

Hyperledger Iroha iOS library

Please pay attention! Master branch of this library works with develop branch of Hyperledger Iroha project! Commands listed in this README.md file depends on Hyperledger Iroha branch!

This library was implemented in order to provide key generation and signing logic for queries and transactions passed to Hyperledger Iroha. In example application you can see the way of how to use this library with grpc generated services.

For establishing connection with Hyperledger Iroha by this library you need to import the following modules into your swift project:

How to start with example project

In this repository you can find an example project called SwiftyIrohaExample.xcodeproj. This project can help you to see how to establish connection with Hyperledger Iroha by using this library

Preparing example project

Before starting you need to install the following software on you mac:

Instruction:

  1. Go into folder you want to download example project:
    $cd path/to/your/folder/for/example/iroha-ios/project/
  1. Clone iroha-ios repository:
    $git clone https://github.com/hyperledger/iroha-ios.git
  1. Go inside project folder:
    $cd iroha-ios
  1. Install all dependencies:
    $pod install
  1. Open project in Xcode:
    $open SwiftyIroha.xcworkspace
  1. Run target SwiftyIrohaExample

  2. DONE.

Preparing Hyperledger Iroha instance launched in Docker

Before starting you need to install the following software on you mac:

Instruction:

  1. You can find a detail instruction of how to launch Hyperledger Iroha instance here. Also you can follow the instruction in this readme file.

  2. Create a Docker Network:

    $docker network create iroha-network
  1. Start PostgreSQL Container:
    $docker run --name some-postgres \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_PASSWORD=mysecretpassword \
    -p 5432:5432 \
    --network=iroha-network \
    -d postgres:9.5
  1. Create Blockstore:
    $docker volume create blockstore
  1. Download Hyperledger Iroha (develop branch):
    $git clone -b develop https://github.com/hyperledger/iroha --depth=1
  1. Start Hyperledger Iroha (develop branch):
    $docker run -it --name iroha \
    -p 50051:50051 \
    -v $(pwd)/iroha/example:/opt/iroha_data \
    -v blockstore:/tmp/block_store \
    --network=iroha-network \
    --entrypoint=/bin/bash \
    hyperledger/iroha:develop
  1. Launch Iroha Daemon:
    $irohad --config config.docker --genesis_block genesis.block --keypair_name node0
  1. DONE.

How to import this library into your project

Install manually

    Please import generated framework from this repository manually (SwiftyIroha targer) into your project
    or start modyfying this project (SwiftyIrohaExample target) which is already working with library

Install via Carthage

    Currently not available, please inport framework manually

Install via CocoaPods

    Currently not available, please inport framework manually

How to use this library

Keypair

Generating new keypair

    let modelCrypto = IrohaModelCrypto()

    // Generating new keypair object
    let newKeypair = modelCrypto.generateKeypair()

Generating new keypair from existing one

    // Setting keypair
    let publicKey = IrohaPublicKey(value: "407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83")
    let privateKey = IrohaPrivateKey(value: "1d7e0a32ee0affeb4d22acd73c2c6fb6bd58e266c8c2ce4fa0ffe3dd6a253ffb")

    // Initializing keypair object
    let existingKeypair = IrohaKeypair(publicKey: publicKey, privateKey: privateKey)

    let modelCrypto = IrohaModelCrypto()

    // Generating keypair object from excisting keypair object
    let newKeypair = modelCrypto.generateNewKeypair(from: existingKeypair)

Transactions

Creating transaction object

    let irohaTransactionBuilder = IrohaTransactionBuilder()

    // Creating transaction object for Iroha
    let unsignedTransaction =
        try irohaTransactionBuilder
            .creatorAccountId("admin@test")
            .createdTime(Date())
            .transactionCounter(1)
            .createDomain(withDomainId: "ru", withDefaultRole: "user")
            .createAssets(withAssetName: "dollar", domainId: "ru", percision: 0.1)
            .build()

Signing transaction object

    // Creating helper class for signing unsigned transaction object
    let irohaTransactionPreparation = IrohaTransactionPreparation()

    // Signing transaction and getting object which is ready for converting to GRPC object
    let irohaSignedTransactionReadyForConvertingToGRPC =
            irohaTransactionPreparation.sign(unsignedTransaction, with: keypair)

Creating GRPC transaction object

    // Creating GRPC transaction object from signed transaction
    var irohaGRPCTransaction = Iroha_Protocol_Transaction()

    do {
        try irohaGRPCTransaction.merge(serializedData: irohaSignedTransactionReadyForConvertingToGRPC)

        // Checking that transaction is excactly transaction that was created
        print("Transaction to Iroha: \n")
        print("\(try irohaGRPCTransaction.payload.jsonString()) \n")
    } catch {
        let nsError = error as NSError
        print("\(nsError.localizedDescription) \n")
    }

Sending transaction object to Hyperledger Iroha

    let serviceForSendingTransaction = Iroha_Protocol_CommandServiceService(address: "127.0.0.1:50051")

    do {
        try serviceForSendingTransaction.torii(irohaGRPCTransaction)
    } catch {
        let nsError = error as NSError
        print("\(nsError.localizedDescription) \n")
    }

Queries

Creating query object

    // Creating unsigned query object
    let queryBuilder = IrohaQueryBuilder()

    let unsignedQuery =
        try queryBuilder
            .creatorAccountId("admin@test")
            .createdTime(Date())
            .queryCounter(1)
            .getAssetInfo(byAssetsId: "dollar#ru")
            .build()

Signing query object

    // Creating helper class for signing unsigned query
    let irohaQueryPreparation = IrohaQueryPreparation()

    let irohaSignedQueryReadyForConvertingToGRPC =
        irohaQueryPreparation.sign(unsignedQuery, with: keypair)

Creating GRPC query object

    var irohaGRPCQuery = Iroha_Protocol_Query()

    do {
        try irohaGRPCQuery.merge(serializedData: irohaSignedQueryReadyForConvertingToGRPC)

        // Checking that query is excactly query that was created
        print("Query to Iroha: \n")
        print("\(try irohaGRPCQuery.payload.jsonString()) \n")
    } catch {
        let nsError = error as NSError
        print("\(nsError.localizedDescription) \n")
    }

Sending query object to Hyperledger Iroha

    let serviceForSendingQuery = Iroha_Protocol_QueryServiceService(address: "127.0.0.1:50051")

    do {
        let result = try serviceForSendingQuery.find(irohaGRPCQuery)
    } catch {
        let nsError = error as NSError
        print("\(nsError.localizedDescription) \n")
    }

Having build problems?

This library was build with the following dependencies:

  • BoringSSL 10.0.3
  • SwiftGRPC 0.4.3
  • SwiftProtobuf 1.0.3
  • gRPC-Core 1.11.0
  • nanopb 0.3.8

Author

AlexeyMukhin

License

Copyright 2018 Soramitsu Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

iroha-ios's People

Contributors

mukhinalexey avatar takemiyamakoto avatar satoshi-kaji avatar dendoronin avatar

Watchers

James Cloos avatar

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.