Name: iroha-ios
Owner: Hyperledger
Description: iOS Swift library for Iroha, a simple distributed ledger
Created: 2016-09-17 15:12:44.0
Updated: 2018-05-24 09:26:07.0
Pushed: 2018-05-12 20:53:09.0
Homepage: http://iroha.tech
Size: 82102
Language: C++
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This library was implemented in order to provide key generation and signing logic for queries and transactions passed to Hyperledger Iroha
For establishing connection with Hyperledger Iroha by this library you need to import the following modules into your swift 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
Before starting you need to install the following software on you mac:
path/to/your/folder/for/example/iroha-ios/project/
clone https://github.com/hyperledger/iroha-ios.git
iroha-ios
install
SwiftyIroha.xcworkspace
Before starting you need to install the following software on you mac:
Please import generated framework form this project (SwiftyIroha targer) into your project
or start modyfying this project (SwiftyIrohaExample target) it is already working with library
Currently not available, please inport framework manually
Currently not available, please inport framework manually
modelCrypto = IrohaModelCrypto()
enerating new keypair object
newKeypair = modelCrypto.generateKeypair()
etting keypair
publicKey = IrohaPublicKey(value: "407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83")
privateKey = IrohaPrivateKey(value: "1d7e0a32ee0affeb4d22acd73c2c6fb6bd58e266c8c2ce4fa0ffe3dd6a253ffb")
nitializing keypair object
existingKeypair = IrohaKeypair(publicKey: publicKey,
privateKey: privateKey)
modelCrypto = IrohaModelCrypto()
enerating keypair object from excisting keypair object
newKeypair = modelCrypto.generateNewKeypair(from: existingKeypair)
irohaTransactionBuilder = IrohaTransactionBuilder()
reating transaction object for Iroha
unsignedTransaction = try irohaTransactionBuilder
.creatorAccountId("admin@test")
.createdTime(Date())
.transactionCounter(1)
.createDomain(withDomainId: "ru", withDefaultRole: "user")
.createAssets(withAssetName: "dollar", domainId: "ru", percision: 0.1)
.build()
reating helper class for signing unsigned transaction object
irohaTransactionPreparation = IrohaTransactionPreparation()
igning transaction and getting object which is ready for converting to GRPC object
irohaSignedTransactionReadyForConvertingToGRPC =
irohaTransactionPreparation.sign(unsignedTransaction, with: keypair)
reating GRPC transaction object from signed transaction
irohaGRPCTransaction = Iroha_Protocol_Transaction()
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")
tch {
let nsError = error as NSError
print("\(nsError.localizedDescription) \n")
serviceForSendingTransaction = Iroha_Protocol_CommandServiceService(address: "127.0.0.1:50051")
try serviceForSendingTransaction.torii(irohaGRPCTransaction)
tch {
let nsError = error as NSError
print("\(nsError.localizedDescription) \n")
reating unsigned query object
queryBuilder = IrohaQueryBuilder()
unsignedQuery = try queryBuilder
.creatorAccountId("admin@test")
.createdTime(Date())
.queryCounter(1)
.getAssetInfo(byAssetsId: "dollar#ru")
.build()
reating helper class for signing unsigned query
irohaQueryPreparation = IrohaQueryPreparation()
irohaSignedQueryReadyForConvertingToGRPC = irohaQueryPreparation.sign(unsignedQuery, with: keypair)
irohaGRPCQuery = Iroha_Protocol_Query()
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")
tch {
let nsError = error as NSError
print("\(nsError.localizedDescription) \n")
serviceForSendingQuery = Iroha_Protocol_QueryServiceService(address: "127.0.0.1:50051")
let result = try serviceForSendingQuery.find(irohaGRPCQuery)
tch {
let nsError = error as NSError
print("\(nsError.localizedDescription) \n")
AlexeyMukhin
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.