diff --git a/EthereumKit.xcodeproj/project.pbxproj b/EthereumKit.xcodeproj/project.pbxproj index 613a245..8def2c8 100644 --- a/EthereumKit.xcodeproj/project.pbxproj +++ b/EthereumKit.xcodeproj/project.pbxproj @@ -771,7 +771,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 9T7JPNQ2UD; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -792,7 +792,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 9T7JPNQ2UD; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", diff --git a/EthereumKit/Helper/Network.swift b/EthereumKit/Helper/Network.swift index 41cef3a..54b5134 100644 --- a/EthereumKit/Helper/Network.swift +++ b/EthereumKit/Helper/Network.swift @@ -2,8 +2,9 @@ public enum Network { case mainnet case ropsten case kovan + case rinkeby case `private`(chainID: Int, testUse: Bool) - + public init?(name: String, chainID: Int = 0, testUse: Bool = false) { switch name { case "main": @@ -12,56 +13,58 @@ public enum Network { self = .ropsten case "kovan": self = .kovan + case "rinkeby": + self = .rinkeby case "private": self = .private(chainID: chainID, testUse: testUse) default: return nil } } - + // https://github.com/satoshilabs/slips/blob/master/slip-0044.md public var coinType: UInt32 { let mainnetCoinType = UInt32(60) let testnetCoinType = UInt32(1) - + switch self { case .mainnet: return mainnetCoinType - case .ropsten, .kovan: + case .ropsten, .kovan, .rinkeby: return testnetCoinType case .private(_, let testUse): return testUse ? testnetCoinType : mainnetCoinType } } - + public var privateKeyPrefix: UInt32 { let mainnetPrefix: UInt32 = 0x0488ade4 let testnetPrefix: UInt32 = 0x04358394 - + switch self { case .mainnet: return mainnetPrefix - case .ropsten, .kovan: + case .ropsten, .kovan, .rinkeby: return testnetPrefix case .private(_, let testUse): return testUse ? testnetPrefix : mainnetPrefix } } - + public var publicKeyPrefix: UInt32 { let mainnetPrefix: UInt32 = 0x0488b21e let testnetPrefix: UInt32 = 0x043587cf - + switch self { case .mainnet: return mainnetPrefix - case .ropsten, .kovan: + case .ropsten, .kovan, .rinkeby: return testnetPrefix case .private(_, let testUse): return testUse ? testnetPrefix : mainnetPrefix } } - + public var name: String { switch self { case .mainnet: @@ -70,11 +73,13 @@ public enum Network { return "Ropsten" case .kovan: return "Kovan" - case .private(_, _): + case .rinkeby: + return "Rinkeby" + case .private: return "Privatenet" } } - + public var chainID: Int { switch self { case .mainnet: @@ -83,6 +88,8 @@ public enum Network { return 3 case .kovan: return 42 + case .rinkeby: + return 4 case .private(let chainID, _): return chainID } @@ -92,7 +99,7 @@ public enum Network { extension Network: Equatable { public static func == (lhs: Network, rhs: Network) -> Bool { switch (lhs, rhs) { - case (.mainnet, .mainnet), (.ropsten, .ropsten), (.kovan, .kovan): + case (.mainnet, .mainnet), (.ropsten, .ropsten), (.kovan, .kovan), (.rinkeby, .rinkeby): return true case (.private(let firstChainID, let firstTestUse), .private(let secondChainID, let secondTestUse)): return firstChainID == secondChainID && firstTestUse == secondTestUse diff --git a/EthereumKit/Mnemonic/Mnemonic.swift b/EthereumKit/Mnemonic/Mnemonic.swift index 21fcc2b..f70554a 100644 --- a/EthereumKit/Mnemonic/Mnemonic.swift +++ b/EthereumKit/Mnemonic/Mnemonic.swift @@ -4,24 +4,24 @@ import Foundation public final class Mnemonic { public enum Strength: Int { case normal = 128 - case hight = 256 + case high = 256 } - + public static func create(strength: Strength = .normal, language: WordList = .english) -> [String] { let byteCount = strength.rawValue / 8 var bytes = Data(count: byteCount) _ = bytes.withUnsafeMutableBytes { SecRandomCopyBytes(kSecRandomDefault, byteCount, $0) } return create(entropy: bytes, language: language) } - + public static func create(entropy: Data, language: WordList = .english) -> [String] { let entropybits = String(entropy.flatMap { ("00000000" + String($0, radix: 2)).suffix(8) }) let hashBits = String(entropy.sha256().flatMap { ("00000000" + String($0, radix: 2)).suffix(8) }) let checkSum = String(hashBits.prefix((entropy.count * 8) / 32)) - + let words = language.words let concatenatedBits = entropybits + checkSum - + var mnemonic: [String] = [] for index in 0..<(concatenatedBits.count / 11) { let startIndex = concatenatedBits.index(concatenatedBits.startIndex, offsetBy: index * 11) @@ -29,10 +29,10 @@ public final class Mnemonic { let wordIndex = Int(strtoul(String(concatenatedBits[startIndex.. Data { let words = WordList.english.words + WordList.japanese.words guard !mnemonic.map({ words.contains($0) }).contains(false) else { diff --git a/EthereumKit/Networking/HTTPClient/Configuration.swift b/EthereumKit/Networking/HTTPClient/Configuration.swift index 52b8fcc..40e1757 100644 --- a/EthereumKit/Networking/HTTPClient/Configuration.swift +++ b/EthereumKit/Networking/HTTPClient/Configuration.swift @@ -1,37 +1,40 @@ /// Configuration has necessary information to use in Geth network public struct Configuration { - + /// represents which network to use public let network: Network - + /// represents an endpoint of ethereum node to connect to public let nodeEndpoint: String - + /// represents an etherscan api key public let etherscanAPIKey: String - + /// represents whether to print debug logs in console public let debugPrints: Bool - + public init(network: Network, nodeEndpoint: String, etherscanAPIKey: String, debugPrints: Bool) { self.network = network self.nodeEndpoint = nodeEndpoint self.etherscanAPIKey = etherscanAPIKey self.debugPrints = debugPrints } - + /// reprensets an etherscan url based on which network to use public var etherscanURL: URL { switch network { case .mainnet: return URL(string: "https://api.etherscan.io")! - + case .ropsten: return URL(string: "https://ropsten.etherscan.io")! - + case .kovan: return URL(string: "https://kovan.etherscan.io")! - + + case .rinkeby: + return URL(string: "https://rinkeby.etherscan.io/")! + case .private: // NOTE: does not get any transactions because of private network. return URL(string: "https://ropsten.etherscan.io")! diff --git a/EthereumKitTests/NetworkTests.swift b/EthereumKitTests/NetworkTests.swift index f0f2a90..46c830f 100644 --- a/EthereumKitTests/NetworkTests.swift +++ b/EthereumKitTests/NetworkTests.swift @@ -2,7 +2,7 @@ import XCTest @testable import EthereumKit final class NetworkTests: XCTestCase { - + func testMainnet() { let network = Network.mainnet XCTAssert(network.chainID == 1) @@ -10,7 +10,7 @@ final class NetworkTests: XCTestCase { XCTAssert(network.privateKeyPrefix == 0x0488ade4) XCTAssert(network.publicKeyPrefix == 0x0488b21e) } - + func testRopsten() { let network = Network.ropsten XCTAssert(network.chainID == 3) @@ -18,7 +18,7 @@ final class NetworkTests: XCTestCase { XCTAssert(network.privateKeyPrefix == 0x04358394) XCTAssert(network.publicKeyPrefix == 0x043587cf) } - + func testKovan() { let network = Network.kovan XCTAssert(network.chainID == 42) @@ -26,7 +26,15 @@ final class NetworkTests: XCTestCase { XCTAssert(network.privateKeyPrefix == 0x04358394) XCTAssert(network.publicKeyPrefix == 0x043587cf) } - + + func testRinkeby() { + let network = Network.rinkeby + XCTAssert(network.chainID == 4) + XCTAssert(network.coinType == 1) + XCTAssert(network.privateKeyPrefix == 0x04358394) + XCTAssert(network.publicKeyPrefix == 0x043587cf) + } + func testPrivateNetTestUse() { let network = Network.private(chainID: 100, testUse: true) XCTAssert(network.chainID == 100) @@ -34,7 +42,7 @@ final class NetworkTests: XCTestCase { XCTAssert(network.privateKeyPrefix == 0x04358394) XCTAssert(network.publicKeyPrefix == 0x043587cf) } - + func testPrivateNet() { let network = Network.private(chainID: 100, testUse: false) XCTAssert(network.chainID == 100) @@ -42,20 +50,24 @@ final class NetworkTests: XCTestCase { XCTAssert(network.privateKeyPrefix == 0x0488ade4) XCTAssert(network.publicKeyPrefix == 0x0488b21e) } - + func testNetworkInitializer() { let mainNetwork = Network(name: "main") XCTAssertNotNil(mainNetwork) XCTAssertEqual(mainNetwork, Network.mainnet) - + let ropstenNetwork = Network(name: "ropsten") XCTAssertNotNil(ropstenNetwork) XCTAssertEqual(ropstenNetwork, Network.ropsten) - + let kovanNetwork = Network(name: "kovan") XCTAssertNotNil(kovanNetwork) XCTAssertEqual(kovanNetwork, Network.kovan) - + + let rinkebyNetwork = Network(name: "rinkeby") + XCTAssertNotNil(rinkebyNetwork) + XCTAssertEqual(rinkebyNetwork, Network.rinkeby) + let privateNetwork = Network(name: "private", chainID: 1, testUse: false) XCTAssertNotNil(privateNetwork) XCTAssertEqual(privateNetwork, Network.private(chainID: 1, testUse: false))