diff --git a/EosioSwift.xcodeproj/project.pbxproj b/EosioSwift.xcodeproj/project.pbxproj index 8f588cc0..21748664 100644 --- a/EosioSwift.xcodeproj/project.pbxproj +++ b/EosioSwift.xcodeproj/project.pbxproj @@ -440,10 +440,11 @@ TargetAttributes = { 6B80D25E21FA6DDF00716A7B = { CreatedOnToolsVersion = 10.1; - LastSwiftMigration = 1010; + LastSwiftMigration = 1110; }; 6B80D26721FA6DDF00716A7B = { CreatedOnToolsVersion = 10.1; + LastSwiftMigration = 1110; }; }; }; @@ -789,7 +790,7 @@ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -817,7 +818,7 @@ PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwift; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -838,7 +839,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwiftTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -859,7 +860,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwiftTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/EosioSwift/Crypto/Base58String.swift b/EosioSwift/Crypto/Base58String.swift index ebd694fc..7aad8908 100644 --- a/EosioSwift/Crypto/Base58String.swift +++ b/EosioSwift/Crypto/Base58String.swift @@ -46,7 +46,7 @@ public extension Data { let byteString = [UInt8](string.utf8) for ch in byteString.reversed() { - if let index = alphabet.index(of: ch) { + if let index = alphabet.firstIndex(of: ch) { answer = answer + (j * BigUInt(index)) j *= radix } else { diff --git a/EosioSwift/Crypto/RIPEMD160.swift b/EosioSwift/Crypto/RIPEMD160.swift index d76e4cfe..e66d82be 100755 --- a/EosioSwift/Crypto/RIPEMD160.swift +++ b/EosioSwift/Crypto/RIPEMD160.swift @@ -306,8 +306,9 @@ public struct RIPEMD160 { } public mutating func update(data: Data) { - data.withUnsafeBytes { (ptr: UnsafePointer) in - var ptr = ptr + data.withUnsafeBytes { ptr in + let typedPtr = ptr.bindMemory(to: UInt8.self) + guard var ptr = typedPtr.baseAddress else { return } var length = data.count var X = [UInt32](repeating: 0, count: 16) @@ -315,7 +316,10 @@ public struct RIPEMD160 { if buffer.count > 0 && buffer.count + length >= 64 { let amount = 64 - buffer.count buffer.append(ptr, count: amount) - buffer.withUnsafeBytes { _ = memcpy(&X, $0, 64) } + buffer.withUnsafeBytes { ptr in + guard let baseAddress = ptr.baseAddress else { return } + _ = memcpy(&X, baseAddress, 64) + } compress(X) ptr += amount length -= amount @@ -329,15 +333,18 @@ public struct RIPEMD160 { } // Save remaining unprocessed bytes: buffer = Data(bytes: ptr, count: length) + count += Int64(data.count) } - count += Int64(data.count) } public mutating func finalize() -> Data { var X = [UInt32](repeating: 0, count: 16) /* append the bit m_n == 1 */ buffer.append(0x80) - buffer.withUnsafeBytes { _ = memcpy(&X, $0, buffer.count) } + buffer.withUnsafeBytes { ptr in + guard let baseAddress = ptr.baseAddress else { return } + _ = memcpy(&X, baseAddress, buffer.count) + } if (count & 63) > 55 { /* length goes to next block */ @@ -353,12 +360,14 @@ public struct RIPEMD160 { compress(X) var data = Data(count: 20) - data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer) in - ptr[0] = MDbuf.0 - ptr[1] = MDbuf.1 - ptr[2] = MDbuf.2 - ptr[3] = MDbuf.3 - ptr[4] = MDbuf.4 + data.withUnsafeMutableBytes { ptr in + let typedPtr = ptr.bindMemory(to: UInt32.self) + guard let baseAddress = typedPtr.baseAddress else { return } + baseAddress[0] = MDbuf.0 + baseAddress[1] = MDbuf.1 + baseAddress[2] = MDbuf.2 + baseAddress[3] = MDbuf.3 + baseAddress[4] = MDbuf.4 } buffer = Data() @@ -386,8 +395,8 @@ public extension RIPEMD160 { var key = key key.count = 64 // Truncate to 64 bytes or fill-up with zeros. - let outerKeyPad = Data(bytes: key.map { $0 ^ 0x5c }) - let innerKeyPad = Data(bytes: key.map { $0 ^ 0x36 }) + let outerKeyPad = Data(key.map { $0 ^ 0x5c }) + let innerKeyPad = Data(key.map { $0 ^ 0x36 }) var innerMd = RIPEMD160() innerMd.update(data: innerKeyPad) diff --git a/EosioSwift/Extensions/DataExtensions.swift b/EosioSwift/Extensions/DataExtensions.swift index 5569a319..f6506c86 100644 --- a/EosioSwift/Extensions/DataExtensions.swift +++ b/EosioSwift/Extensions/DataExtensions.swift @@ -75,10 +75,11 @@ public extension Data { /// Returns the SHA256 hash of the data. var sha256: Data { var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) - self.withUnsafeBytes { - _ = CC_SHA256($0, CC_LONG(self.count), &hash) + self.withUnsafeBytes { ptr in + guard let baseAddress = ptr.baseAddress else { return } + _ = CC_SHA256(baseAddress, CC_LONG(self.count), &hash) } - return Data(bytes: hash) + return Data(hash) } /// Returns the current Data as a base58 encoded String. diff --git a/EosioSwift/Extensions/EosioKeySignatureExtensions.swift b/EosioSwift/Extensions/EosioKeySignatureExtensions.swift index 6bcf7a92..fcc6705e 100644 --- a/EosioSwift/Extensions/EosioKeySignatureExtensions.swift +++ b/EosioSwift/Extensions/EosioKeySignatureExtensions.swift @@ -56,7 +56,7 @@ public extension Data { let x = uncompressedKey[1...32] // swiftlint:disable:this identifier_name let yLastByte = uncompressedKey[64] let flag: UInt8 = 2 + (yLastByte % 2) - let compressedKey = Data(bytes: [flag]) + x + let compressedKey = Data([flag]) + x return compressedKey } @@ -229,7 +229,7 @@ public extension Data { } if key.count == 33 { - guard key.prefix(1) == Data(bytes: [0x80]) else { + guard key.prefix(1) == Data([0x80]) else { throw EosioError(.signatureProviderError, reason: "33 byte private key: \(key.hex) does not begin with 80") } key = key.suffix(key.count-1) diff --git a/EosioSwift/Extensions/StringExtensions.swift b/EosioSwift/Extensions/StringExtensions.swift index c9dec8b0..2f04381d 100644 --- a/EosioSwift/Extensions/StringExtensions.swift +++ b/EosioSwift/Extensions/StringExtensions.swift @@ -60,14 +60,14 @@ public extension String { /// Converts the string to a dictionary if it is convertible to a dictionary (i.e., it is a JSON string.) and returns the dictionary. Otherwise, returns `nil`. var toJsonDictionary: [String: Any]? { guard let data = self.data(using: .utf8) else { return nil } - let dict = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [String: Any]) ?? nil + let dict = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments)) as? [String: Any] return dict } /// Converts the string to a array if it is convertible to a array (i.e., it is a JSON string.) and returns the array. Otherwise, returns `nil`. var toJsonArray: [Any]? { guard let data = self.data(using: .utf8) else { return nil } - let array = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [Any]) ?? nil + let array = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments)) as? [Any] return array } diff --git a/Podfile b/Podfile index db1c046e..f84247c9 100644 --- a/Podfile +++ b/Podfile @@ -6,11 +6,11 @@ target 'EosioSwift' do target 'EosioSwiftTests' do inherit! :search_paths pod 'OHHTTPStubs/Swift' - pod 'BigInt', '~> 3.1', :inhibit_warnings => true + pod 'BigInt', '~> 5.0' pod 'PromiseKit', '~> 6.8' end - pod 'BigInt', '~> 3.1', :inhibit_warnings => true + pod 'BigInt', '~> 5.0' pod 'SwiftLint' pod 'PromiseKit', '~> 6.8' end diff --git a/Podfile.lock b/Podfile.lock index dc3281f8..f4383db3 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,5 @@ PODS: - - BigInt (3.1.0): - - SipHash (~> 1.2) + - BigInt (5.0.0) - OHHTTPStubs/Core (8.0.0) - OHHTTPStubs/Default (8.0.0): - OHHTTPStubs/Core @@ -23,11 +22,10 @@ PODS: - PromiseKit/CorePromise - PromiseKit/UIKit (6.8.4): - PromiseKit/CorePromise - - SipHash (1.2.2) - SwiftLint (0.32.0) DEPENDENCIES: - - BigInt (~> 3.1) + - BigInt (~> 5.0) - OHHTTPStubs/Swift - PromiseKit (~> 6.8) - SwiftLint @@ -37,16 +35,14 @@ SPEC REPOS: - BigInt - OHHTTPStubs - PromiseKit - - SipHash - SwiftLint SPEC CHECKSUMS: - BigInt: 76b5dfdfa3e2e478d4ffdf161aeede5502e2742f + BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 OHHTTPStubs: 9cbce6364bec557cc3439aa6bb7514670d780881 PromiseKit: 51794a832647e7b819336dc2279039ce9f1cc49b - SipHash: fad90a4683e420c52ef28063063dbbce248ea6d4 SwiftLint: 009a898ef2a1c851f45e1b59349bf6ff2ddc990d -PODFILE CHECKSUM: 1d10bec70f8d2560be35e67e47b034772bba25f7 +PODFILE CHECKSUM: c2e188f1ae1612a01b8b39f8a779631954878ead COCOAPODS: 1.8.3