Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/keefertaylor/tezoskit
Browse files Browse the repository at this point in the history
  • Loading branch information
keefertaylor committed Apr 28, 2019
2 parents 8284a47 + 3b94dd8 commit 69cb5d7
Show file tree
Hide file tree
Showing 37 changed files with 223 additions and 250 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ before_install:
- brew outdated carthage || brew upgrade carthage
- travis_wait 120 carthage bootstrap --platform iOS --no-use-binaries --verbose
before_deploy:
- carthage build --no-skip-current --platform iOS --cache-builds --verbose
- travis_wait 120 carthage build --no-skip-current --platform iOS --cache-builds
- carthage archive $FRAMEWORK_NAME
after_deploy:
- pod trunk push --skip-import-validation --skip-tests --allow-warnings
- travis_wait 120 pod trunk push --skip-import-validation --skip-tests --allow-warnings
script:
- set -o pipefail && xcodebuild test -scheme TezosKit -destination 'platform=iOS Simulator,name=iPhone
XS,OS=12.2' ONLY_ACTIVE_ARCH=YES | xcpretty
Expand Down
3 changes: 1 addition & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
github "attaswift/BigInt" ~> 3.1
github "keefertaylor/MnemonicKit" ~> 1.3.4
github "jedisct1/swift-sodium" ~> 0.8.0
github "keefertaylor/TezosCrypto" ~> 1.2.0
github "keefertaylor/TezosCrypto" ~> 2.0.0
github "mxcl/PromiseKit" ~> 6.8
8 changes: 4 additions & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github "attaswift/BigInt" "v3.1.0"
github "attaswift/SipHash" "v1.2.2"
github "jedisct1/swift-sodium" "0.8.0"
github "keefertaylor/Base58Swift" "1.1.0"
github "keefertaylor/MnemonicKit" "1.3.4"
github "keefertaylor/TezosCrypto" "1.2.1"
github "keefertaylor/Base58Swift" "2.1.0"
github "keefertaylor/MnemonicKit" "1.3.7"
github "keefertaylor/TezosCrypto" "2.0.1"
github "krzyzanowskim/CryptoSwift" "0.14.0"
github "mxcl/PromiseKit" "6.8.3"
github "mxcl/PromiseKit" "6.8.4"
2 changes: 1 addition & 1 deletion Extensions/PromiseKit/ConseilClient+Promises.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import PromiseKit

/// Extension for ConseilClient which provides a Promise/PromiseKit based API.
extension ConseilClient {
public extension ConseilClient {
/// Retrieve originated accounts.
///
/// - Parameters:
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/TezosKit/ConseilClientIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import XCTest
/// *** Configuration must be done before theses tests can be run. Please configure: ***
/// - Conseil URL
/// - Conseil API Key
let apiKey = "your_api_key_here"
let remoteNodeURL = URL(string: "your conseil url here")!
let apiKey = "hooman"
let remoteNodeURL = URL(string: "https://conseil-dev.cryptonomic-infra.tech:443")!

class ConseilClientIntegrationTests: XCTestCase {
public lazy var conseilClient: ConseilClient = {
Expand Down
13 changes: 13 additions & 0 deletions Tests/FakeObjects.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Keefer Taylor, 2019

import Foundation
import TezosKit

public struct FakePublicKey: PublicKey {
public let base58CheckRepresentation: String
}

public struct FakeSecretKey: SecretKey {
public let base58CheckRepresentation: String
}

21 changes: 17 additions & 4 deletions Tests/TezosKit/KeysTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ import XCTest

class KeysTests: XCTestCase {
public func testEquality() {
let keys1 = Keys(publicKey: "a", secretKey: "a")
let keys2 = Keys(publicKey: "a", secretKey: "a")
let fakePublicKey1 = FakePublicKey(base58CheckRepresentation: "a")
let fakeSecretKey1 = FakeSecretKey(base58CheckRepresentation: "b")

let fakePublicKey2 = FakePublicKey(base58CheckRepresentation: "a")
let fakeSecretKey2 = FakeSecretKey(base58CheckRepresentation: "b")

let keys1 = Keys(publicKey: fakePublicKey1, secretKey: fakeSecretKey1)
let keys2 = Keys(publicKey: fakePublicKey2, secretKey: fakeSecretKey2)
XCTAssertEqual(keys1, keys2)

let keys3 = Keys(publicKey: "a", secretKey: "b")
let keys4 = Keys(publicKey: "b", secretKey: "a")
let fakePublicKey3 = FakePublicKey(base58CheckRepresentation: "b")
let fakeSecretKey3 = FakeSecretKey(base58CheckRepresentation: "b")

let keys3 = Keys(publicKey: fakePublicKey3, secretKey: fakeSecretKey3)
XCTAssertNotEqual(keys1, keys3)

let fakePublicKey4 = FakePublicKey(base58CheckRepresentation: "a")
let fakeSecretKey4 = FakeSecretKey(base58CheckRepresentation: "a")

let keys4 = Keys(publicKey: fakePublicKey4, secretKey: fakeSecretKey4)
XCTAssertNotEqual(keys1, keys4)
}
}
6 changes: 3 additions & 3 deletions Tests/TezosKit/RevealOperationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import XCTest
class RevealOperationTest: XCTestCase {
public func testDictionaryRepresentation() {
let source = "tz1abc"
let publicKey = "edpkXYZ"
let publicKey = FakePublicKey(base58CheckRepresentation: "edpkXYZ")

let operation = RevealOperation(from: source, publicKey: publicKey)
let dictionary = operation.dictionaryRepresentation
Expand All @@ -15,7 +15,7 @@ class RevealOperationTest: XCTestCase {
XCTAssertEqual(dictionary["source"] as? String, source)

XCTAssertNotNil(dictionary["public_key"])
XCTAssertEqual(dictionary["public_key"] as? String, publicKey)
XCTAssertEqual(dictionary["public_key"] as? String, publicKey.base58CheckRepresentation)
}

public func testDictionaryRepresentationFromWallet() {
Expand All @@ -31,6 +31,6 @@ class RevealOperationTest: XCTestCase {
XCTAssertEqual(dictionary["source"] as? String, wallet.address)

XCTAssertNotNil(dictionary["public_key"])
XCTAssertEqual(dictionary["public_key"] as? String, wallet.keys.publicKey)
XCTAssertEqual(dictionary["public_key"] as? String, wallet.keys.publicKey.base58CheckRepresentation)
}
}
16 changes: 8 additions & 8 deletions Tests/TezosKit/WalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class WalletTests: XCTestCase {

XCTAssertNotNil(wallet.mnemonic)
XCTAssertEqual(wallet.mnemonic!, mnemonic)
XCTAssertEqual(wallet.keys.publicKey, expectedPublicKeyNoPassphrase)
XCTAssertEqual(wallet.keys.secretKey, expectedSecretKeyNoPassphrase)
XCTAssertEqual(wallet.keys.publicKey.base58CheckRepresentation, expectedPublicKeyNoPassphrase)
XCTAssertEqual(wallet.keys.secretKey.base58CheckRepresentation, expectedSecretKeyNoPassphrase)
XCTAssertEqual(wallet.address, expectedPublicKeyHashNoPassphrase)
}

Expand All @@ -53,8 +53,8 @@ class WalletTests: XCTestCase {
// A wallet with an empty passphrase should be the same as a wallet with no passphrase.
XCTAssertNotNil(wallet.mnemonic)
XCTAssertEqual(wallet.mnemonic!, mnemonic)
XCTAssertEqual(wallet.keys.publicKey, expectedPublicKeyNoPassphrase)
XCTAssertEqual(wallet.keys.secretKey, expectedSecretKeyNoPassphrase)
XCTAssertEqual(wallet.keys.publicKey.base58CheckRepresentation, expectedPublicKeyNoPassphrase)
XCTAssertEqual(wallet.keys.secretKey.base58CheckRepresentation, expectedSecretKeyNoPassphrase)
XCTAssertEqual(wallet.address, expectedPublicKeyHashNoPassphrase)
}

Expand All @@ -67,8 +67,8 @@ class WalletTests: XCTestCase {
// A wallet with an empty passphrase should be the same as a wallet with no passphrase.
XCTAssertNotNil(wallet.mnemonic)
XCTAssertEqual(wallet.mnemonic!, mnemonic)
XCTAssertEqual(wallet.keys.publicKey, expectedPublicKeyPassphrase)
XCTAssertEqual(wallet.keys.secretKey, expectedSecretKeyPassphrase)
XCTAssertEqual(wallet.keys.publicKey.base58CheckRepresentation, expectedPublicKeyPassphrase)
XCTAssertEqual(wallet.keys.secretKey.base58CheckRepresentation, expectedSecretKeyPassphrase)
XCTAssertEqual(wallet.address, expectedPublicKeyHashPassphrase)
}

Expand All @@ -80,8 +80,8 @@ class WalletTests: XCTestCase {

XCTAssertNil(wallet.mnemonic)
XCTAssertEqual(wallet.address, expectedPublicKeyHashNoPassphrase)
XCTAssertEqual(wallet.keys.publicKey, expectedPublicKeyNoPassphrase)
XCTAssertEqual(wallet.keys.secretKey, expectedSecretKeyNoPassphrase)
XCTAssertEqual(wallet.keys.publicKey.base58CheckRepresentation, expectedPublicKeyNoPassphrase)
XCTAssertEqual(wallet.keys.secretKey.base58CheckRepresentation, expectedSecretKeyNoPassphrase)
}

public func testGenerateWalletFromInvalidSecretKey() {
Expand Down
14 changes: 10 additions & 4 deletions TezosKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
7774780B2222281B0010BA4D /* TezosKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77CE359621F7DC76006ADABA /* TezosKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
7774780C222228590010BA4D /* PromiseKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77F4D26B221F899800D34B01 /* PromiseKit.framework */; };
7774780F222228E50010BA4D /* PromiseKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7774780E222228E50010BA4D /* PromiseKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
7776493B227616B200451DD5 /* FakeObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7776493A227616B200451DD5 /* FakeObjects.swift */; };
7794E97B224C2518000D9F1E /* Header.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7794E97A224C2518000D9F1E /* Header.swift */; };
77B1EADE222496B500EA4FCE /* TezosNodeClient+Promises.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B1EADD222496B500EA4FCE /* TezosNodeClient+Promises.swift */; };
77B1EAEA222730D600EA4FCE /* TezosNodeIntegrationTests+Promises.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B1EAE9222730D600EA4FCE /* TezosNodeIntegrationTests+Promises.swift */; };
Expand Down Expand Up @@ -202,6 +203,7 @@
77633D522247EFE20011106A /* TezosNodeClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TezosNodeClientTests.swift; sourceTree = "<group>"; };
7774780422221DE50010BA4D /* AbstractClientTest+Promises.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AbstractClientTest+Promises.swift"; sourceTree = "<group>"; };
7774780E222228E50010BA4D /* PromiseKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PromiseKit.framework; path = Carthage/Build/iOS/PromiseKit.framework; sourceTree = "<group>"; };
7776493A227616B200451DD5 /* FakeObjects.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeObjects.swift; sourceTree = "<group>"; };
7791E60F21FE862600957650 /* TezosKitExample.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; name = TezosKitExample.playground; path = Examples/TezosKitExample.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
7794E97A224C2518000D9F1E /* Header.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Header.swift; sourceTree = "<group>"; };
77B1EADD222496B500EA4FCE /* TezosNodeClient+Promises.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TezosNodeClient+Promises.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -465,6 +467,7 @@
isa = PBXGroup;
children = (
77B1EAFB2228C03400EA4FCE /* TestObjects.swift */,
7776493A227616B200451DD5 /* FakeObjects.swift */,
77F4D27422221CDD00D34B01 /* Extensions */,
77F4D27322221CCE00D34B01 /* TezosKit */,
);
Expand Down Expand Up @@ -772,9 +775,11 @@
TargetAttributes = {
772F48A42224894E00DF0F9D = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1020;
};
77CE359521F7DC76006ADABA = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1020;
};
77CE359E21F7DC76006ADABA = {
CreatedOnToolsVersion = 10.1;
Expand Down Expand Up @@ -1006,6 +1011,7 @@
77CE36F721F7F49F006ADABA /* WalletTests.swift in Sources */,
77B69EC522510D5400DB4319 /* ConseilEntityTest.swift in Sources */,
77F4D268221CD44100D34B01 /* AbstractClientTest.swift in Sources */,
7776493B227616B200451DD5 /* FakeObjects.swift in Sources */,
77CE36E721F7F49F006ADABA /* OriginateAccountOperation.swift in Sources */,
77CE36E521F7F49F006ADABA /* RPCTest.swift in Sources */,
77CE36E821F7F49F006ADABA /* KeysTests.swift in Sources */,
Expand Down Expand Up @@ -1060,7 +1066,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.keefertaylor.IntegrationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1082,7 +1088,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.keefertaylor.IntegrationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down Expand Up @@ -1234,7 +1240,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.keefertaylor.TezosKit;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -1264,7 +1270,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.keefertaylor.TezosKit;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
63 changes: 29 additions & 34 deletions TezosKit/Client/RPCResponseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import Foundation

/**
* A response handler handles responses that are received when network requests are completed.
*/
/// A response handler handles responses that are received when network requests are completed.
public class RPCResponseHandler {
/**
* Handle a response from the network.
* - Parameter response: The URLResponse associated with the request, if it exists.
* - Parameter data: Raw data returned from the network, if it exists.
* - Parameter error: An error in the request, if one occurred.
* - Parameter responseAdapterClass: A response adapter class that will adapt the raw data to a first class object.
* - Returns: A tuple containing the result of the parsing operation if successful, otherwise an error.
*/
/// Handle a response from the network.
///
/// - Parameters:
/// - response: The URLResponse associated with the request, if it exists.
/// - data: Raw data returned from the network, if it exists.
/// - error: An error in the request, if one occurred.
/// - responseAdapterClass: A response adapter class that will adapt the raw data to a first class object.
/// - Returns: A tuple containing the result of the parsing operation if successful, otherwise an error.
public func handleResponse<T>(
response: URLResponse?,
data: Data?,
Expand Down Expand Up @@ -46,15 +44,14 @@ public class RPCResponseHandler {

// MARK: - Helpers

/**
* Parse an error from a given HTTPURLResponse.
*
* - Note: This method assumes that the HTTPResponse contained an error.
*
* - Parameter httpResponse: The HTTPURLResponse to parse.
* - Parameter data: Optional data that may have been returned with the response.
* - Returns: An appropriate error based on the inputs.
*/
/// Parse an error from a given HTTPURLResponse.
///
/// - Note: This method assumes that the HTTPResponse contained an error.
///
/// - Parameters:
/// - httpResponse: The HTTPURLResponse to parse.
/// -data: Optional data that may have been returned with the response.
/// - Returns: An appropriate error based on the inputs.
private func parseError(from httpResponse: HTTPURLResponse, with data: Data?) -> TezosKitError {
// Decode the server's response to a string in order to bundle it with the error if it is in
// a readable format.
Expand All @@ -71,14 +68,12 @@ public class RPCResponseHandler {
return error
}

/**
* Parse an error kind from a given HTTPURLResponse.
*
* - Note: This method assumes that the HTTPResponse contained an error.
*
* - Parameter httpResponse: The HTTPURLResponse to parse.
* - Returns: An appropriate error kind based on the response.
*/
/// Parse an error kind from a given HTTPURLResponse.
///
/// - Note: This method assumes that the HTTPResponse contained an error.
///
/// - Parameter httpResponse: The HTTPURLResponse to parse.
/// - Returns: An appropriate error kind based on the response.
private func parseErrorKind(from httpResponse: HTTPURLResponse) -> TezosKitError.ErrorKind {
// Default to unknown error and try to give a more specific error code if it can be narrowed
// down based on HTTP response code.
Expand All @@ -93,12 +88,12 @@ public class RPCResponseHandler {
return errorKind
}

/**
* Parse the given data to an object with the given response adapter.
* - Parameter data: Data to parse.
* - Paramater responseAdapterClass: A response adapter class to use for parsing the data.
* - Returns: The parsed type if the data was was valid, otherwise nil.
*/
/// Parse the given data to an object with the given response adapter.
///
/// - Parameters:
/// - data: Data to parse.
/// -responseAdapterClass: A response adapter class to use for parsing the data.
/// - Returns: The parsed type if the data was was valid, otherwise nil.
private func parse<T>(_ data: Data, with responseAdapterClass: AbstractResponseAdapter<T>.Type) -> T? {
guard let result = responseAdapterClass.parse(input: data) else {
return nil
Expand Down
26 changes: 13 additions & 13 deletions TezosKit/Client/TezosNodeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,29 +517,29 @@ public class TezosNodeClient: AbstractClient {
forgedPayload: String,
keys: Keys
) -> (signedBytes: String, signedOperationPayload: SignedOperationPayload)? {
guard let signingResult = TezosCrypto.signForgedOperation(operation: forgedPayload, secretKey: keys.secretKey),
let jsonSignedBytes = JSONUtils.jsonString(for: signingResult.sbytes) else {
guard let secretKey = keys.secretKey as? TezosCrypto.SecretKey,
let signingResult = TezosCryptoUtils.sign(hex: forgedPayload, secretKey: secretKey),
let jsonSignedBytes = JSONUtils.jsonString(for: signingResult.injectableHexBytes) else {
return nil
}

let signedForgeablePayload = SignedOperationPayload(
operationPayload: operationPayload,
signature: signingResult.edsig
signature: signingResult.base58Representation
)

return (jsonSignedBytes, signedForgeablePayload)
}

/**
* Sign the result of a forged operation, preapply and inject it if successful.
*
* - Parameter operationPayload: The operation payload which was used to forge the operation.
* - Parameter operationMetadata: Metadata related to the operation.
* - Parameter forgeResult: The result of forging the operation payload.
* - Parameter source: The address performing the operation.
* - Parameter keys: The keys to use to sign the operation for the address.
* - Parameter completion: A completion block that will be called with the results of the operation.
*/
/// Sign the result of a forged operation, preapply and inject it if successful.
///
/// - Parameters:
/// - operationPayload: The operation payload which was used to forge the operation.
/// - operationMetadata: Metadata related to the operation.
/// - forgeResult: The result of forging the operation payload.
/// - source: The address performing the operation.
/// - keys: The keys to use to sign the operation for the address.
/// - completion: A completion block that will be called with the results of the operation.
private func signPreapplyAndInjectOperation(
operationPayload: OperationPayload,
operationMetadata: OperationMetadata,
Expand Down
Loading

0 comments on commit 69cb5d7

Please sign in to comment.