Skip to content

Commit

Permalink
Merge pull request #32 from soramitsu/1.0.0a5
Browse files Browse the repository at this point in the history
1.0.0a5
  • Loading branch information
Satoshi Kaji authored Oct 22, 2016
2 parents 8eefc84 + f5d9fb5 commit 594ff0b
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 461 deletions.
2 changes: 1 addition & 1 deletion IrohaSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "IrohaSwift"
s.version = "1.0.0a4"
s.version = "1.0.0a5"
s.summary = "Easy create signature of Iroha Blockchain"
s.homepage = "http://www.soramitsu.co.jp/"
s.license = "Apache License Version 2.0"
Expand Down
12 changes: 0 additions & 12 deletions IrohaSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
/* Begin PBXBuildFile section */
7413F4221D8FD6D500F4929A /* Ed25519.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7413F4211D8FD6D500F4929A /* Ed25519.swift */; };
74298A001D9AC5330074F91D /* Sha3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 742989FF1D9AC5330074F91D /* Sha3.swift */; };
7458D11E1D903E89003C3D1D /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7458D11D1D903E89003C3D1D /* ColorExtension.swift */; };
7471C86F1D8D942300C151E8 /* IrohaSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7471C8641D8D942300C151E8 /* IrohaSwift.framework */; };
7471C8741D8D942300C151E8 /* IrohaSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7471C8731D8D942300C151E8 /* IrohaSwiftTests.swift */; };
7471C8A71D8D9AC200C151E8 /* IrohaSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7471C8A61D8D9AC200C151E8 /* IrohaSwift.swift */; };
747237A01D8ECB5600D22133 /* HttpRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472379F1D8ECB5600D22133 /* HttpRequest.swift */; };
747816E51D9FA5AD00394583 /* IrohaDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747816E41D9FA5AD00394583 /* IrohaDataManager.swift */; };
7494E09D1D8F961300F311DA /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7494E09C1D8F961300F311DA /* Security.framework */; };
74A8F08E1D9819DF008CCF51 /* add_scalar.c in Sources */ = {isa = PBXBuildFile; fileRef = 74A8F07A1D9819DF008CCF51 /* add_scalar.c */; };
74A8F08F1D9819DF008CCF51 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = 74A8F07B1D9819DF008CCF51 /* base64.c */; };
Expand Down Expand Up @@ -50,16 +47,13 @@
/* Begin PBXFileReference section */
7413F4211D8FD6D500F4929A /* Ed25519.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Ed25519.swift; sourceTree = "<group>"; };
742989FF1D9AC5330074F91D /* Sha3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sha3.swift; sourceTree = "<group>"; };
7458D11D1D903E89003C3D1D /* ColorExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = "<group>"; };
7471C8641D8D942300C151E8 /* IrohaSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = IrohaSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7471C8671D8D942300C151E8 /* IrohaSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IrohaSwift.h; sourceTree = "<group>"; };
7471C8691D8D942300C151E8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7471C86E1D8D942300C151E8 /* IrohaSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IrohaSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7471C8731D8D942300C151E8 /* IrohaSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IrohaSwiftTests.swift; sourceTree = "<group>"; };
7471C8751D8D942300C151E8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7471C8A61D8D9AC200C151E8 /* IrohaSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IrohaSwift.swift; sourceTree = "<group>"; };
7472379F1D8ECB5600D22133 /* HttpRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpRequest.swift; sourceTree = "<group>"; };
747816E41D9FA5AD00394583 /* IrohaDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IrohaDataManager.swift; path = IrohaSwift/IrohaDataManager.swift; sourceTree = SOURCE_ROOT; };
7494E09C1D8F961300F311DA /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
74A8F07A1D9819DF008CCF51 /* add_scalar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = add_scalar.c; sourceTree = "<group>"; };
74A8F07B1D9819DF008CCF51 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = base64.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,10 +123,7 @@
7471C8671D8D942300C151E8 /* IrohaSwift.h */,
7471C8691D8D942300C151E8 /* Info.plist */,
7471C8A61D8D9AC200C151E8 /* IrohaSwift.swift */,
7472379F1D8ECB5600D22133 /* HttpRequest.swift */,
7413F4211D8FD6D500F4929A /* Ed25519.swift */,
747816E41D9FA5AD00394583 /* IrohaDataManager.swift */,
7458D11D1D903E89003C3D1D /* ColorExtension.swift */,
742989FF1D9AC5330074F91D /* Sha3.swift */,
);
path = IrohaSwift;
Expand Down Expand Up @@ -302,17 +293,14 @@
74A8F09D1D9819DF008CCF51 /* sha3.c in Sources */,
74A8F0921D9819DF008CCF51 /* fe.c in Sources */,
74A8F0951D9819DF008CCF51 /* ge.c in Sources */,
7458D11E1D903E89003C3D1D /* ColorExtension.swift in Sources */,
74298A001D9AC5330074F91D /* Sha3.swift in Sources */,
747237A01D8ECB5600D22133 /* HttpRequest.swift in Sources */,
74A8F09C1D9819DF008CCF51 /* seed.c in Sources */,
7471C8A71D8D9AC200C151E8 /* IrohaSwift.swift in Sources */,
74A8F0981D9819DF008CCF51 /* keypair.c in Sources */,
74A8F09F1D9819DF008CCF51 /* sign.c in Sources */,
74A8F08E1D9819DF008CCF51 /* add_scalar.c in Sources */,
74A8F0A01D9819DF008CCF51 /* verify.c in Sources */,
74A8F08F1D9819DF008CCF51 /* base64.c in Sources */,
747816E51D9FA5AD00394583 /* IrohaDataManager.swift in Sources */,
74A8F09A1D9819DF008CCF51 /* sc.c in Sources */,
7413F4221D8FD6D500F4929A /* Ed25519.swift in Sources */,
74A8F0971D9819DF008CCF51 /* key_exchange.c in Sources */,
Expand Down
22 changes: 0 additions & 22 deletions IrohaSwift/ColorExtension.swift

This file was deleted.

12 changes: 8 additions & 4 deletions IrohaSwift/Ed25519.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public func createKeyPair() -> (publicKey:String, privateKey:String){

return (base64Pub, base64Pri)
}
func sign(publicKey:String,privateKey:String, message:String) -> String{
public func sign(publicKey:String,privateKey:String, message:String) -> String{
var sig: Array<UInt8> = Array(repeating: 0, count: 64)
var sigMsg: Array<UInt8> = Array(repeating: 0, count: 32)
sha3_256(Array<UInt8>(message.utf8), Array<UInt8>(message.utf8).count, &sigMsg)
Expand All @@ -47,13 +47,17 @@ func sign(publicKey:String,privateKey:String, message:String) -> String{
return base64Sig
}

func verify(publicKey:String, signature:String, message:String) -> Int{
public func verify(publicKey:String, signature:String, message:String) -> Bool{
var sigMsg: Array<UInt8> = Array(repeating: 0, count: 32)
sha3_256(Array<UInt8>(message.utf8), Array<UInt8>(message.utf8).count, &sigMsg)
let decPubArr = base64toArr(base64str: publicKey, count: 32)
let decSigArr = base64toArr(base64str: signature, count: 64)

return Int(ed25519_verify(decSigArr, sigMsg, sigMsg.count, decPubArr))
let valid = Int(ed25519_verify(decSigArr, sigMsg, sigMsg.count, decPubArr))
if valid == 1 {
return true
}else{
return false
}
}

func base64toArr(base64str:String, count:Int) -> Array<UInt8>{
Expand Down
106 changes: 0 additions & 106 deletions IrohaSwift/HttpRequest.swift

This file was deleted.

18 changes: 0 additions & 18 deletions IrohaSwift/IrohaDataManager.swift

This file was deleted.

111 changes: 0 additions & 111 deletions IrohaSwift/IrohaSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,114 +13,3 @@
//limitations under the License.

import Foundation
import libs

public func setDatas(uuid:String){
IrohaDataManager.sharedManager.uuid = uuid
}

public func setDatas(accessPoint:String, publicKey:String){
IrohaDataManager.sharedManager.accessPoint = accessPoint
IrohaDataManager.sharedManager.publicKey = publicKey
}

public func setDatas(accessPoint:String, publicKey:String, uuid:String){
IrohaDataManager.sharedManager.accessPoint = accessPoint
IrohaDataManager.sharedManager.publicKey = publicKey
IrohaDataManager.sharedManager.uuid = uuid
}

public func register(name:String) -> [String:Any]{
let manager = IrohaDataManager.sharedManager
let req = HttpRequest()
let parameter: [String : Any] = [
"publicKey": manager.publicKey,
"screen_name": name,
"timestamp": Date().timeIntervalSince1970
]
let res = req.postRequest(accessPoint: manager.accessPoint, endpoint: "/account/register", parameters: parameter)

return res
}

public func getAccountInfo() -> [String:Any]{
let manager = IrohaDataManager.sharedManager
let req = HttpRequest()
return req.getRequest(accessPoint: manager.accessPoint, endpoint: "/account",parameters: ["uuid":manager.uuid])
}

public func domainRegister(domain:String, privateKey:String) -> [String:Any]{
let manager = IrohaDataManager.sharedManager
let req = HttpRequest()
let timestamp = Int(Date().timeIntervalSince1970)
let message = "timestamp:\(timestamp),owner:\(manager.publicKey),name:\(domain)"
let signature = sign(publicKey: manager.publicKey, privateKey: privateKey, message: sha3_256(message: message))
let parameter: [String : Any] = [
"name" : domain,
"owner" : manager.publicKey,
"signature" : signature,
"timestamp": timestamp
]

return req.postRequest(accessPoint: manager.accessPoint, endpoint: "/domain/register", parameters:parameter)
}

public func createAsset(domain:String, privateKey:String, name:String)-> [String:Any]{
let manager = IrohaDataManager.sharedManager
let req = HttpRequest()
let timestamp = Int(Date().timeIntervalSince1970)
let message = "timestamp:\(timestamp),name:\(name),domain:\(domain),creator:\(manager.publicKey)"
let signature = sign(publicKey: manager.publicKey, privateKey: privateKey, message: sha3_256(message: message))
let parameter: [String : Any] = [
"name" : name,
"domain" : domain,
"creator" : manager.publicKey,
"signature" : signature,
"timestamp" : timestamp
]

return req.postRequest(accessPoint: manager.accessPoint, endpoint: "/asset/create", parameters:parameter)
}

public func getDomainList() -> [String:Any]{
let req = HttpRequest()
return req.getRequest(accessPoint: IrohaDataManager.sharedManager.accessPoint, endpoint: "/domain/list")
}

public func getAssetsList(domain:String) -> [String:Any]{
let req = HttpRequest()
return req.getRequest(accessPoint: IrohaDataManager.sharedManager.accessPoint, endpoint: "/assets/list/\(domain)")
}


public func assetOperation(command:String, assetUuid:String, amount:String, privateKey:String, reciever:String) -> [String:Any]{
let manager = IrohaDataManager.sharedManager
let req = HttpRequest()
let timestamp = Int(Date().timeIntervalSince1970)
let message = "timestamp:\(timestamp),sender:\(manager.publicKey),reciever:\(reciever),command:\(command),amount:\(amount),asset-uuid:\(assetUuid)"
let signature = sign(publicKey: manager.publicKey, privateKey: privateKey, message: sha3_256(message: message))
let parameter: [String : Any] = [
"asset-uuid": assetUuid,
"params" : [
"command": command,
"amount": Int(amount),
"sender" : manager.publicKey,
"receiver" : reciever
],
"signature" : signature,
"timestamp" : timestamp
]
return req.postRequest(accessPoint: manager.accessPoint, endpoint: "/asset/operation", parameters:parameter)
}


public func getTransaction() -> [String:Any]{
let manager = IrohaDataManager.sharedManager
let req = HttpRequest()
return req.getRequest(accessPoint: manager.accessPoint, endpoint: "/history/transaction/\(manager.uuid)")
}

public func getTransactionWithAssetName(asset:String, domain:String) -> [String:Any]{
let req = HttpRequest()
return req.getRequest(accessPoint: IrohaDataManager.sharedManager.accessPoint, endpoint: "/history/transaction/\(domain).\(asset)")
}
22 changes: 0 additions & 22 deletions IrohaSwift/Keychain.swift

This file was deleted.

Loading

0 comments on commit 594ff0b

Please sign in to comment.