Skip to content

Commit 62a3307

Browse files
author
Marcus Arnett
committed
Fix version build issues for other platforms
1 parent 16290fd commit 62a3307

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+13320
-150
lines changed

Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 5.5.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
23

34
import PackageDescription
45

56
let package = Package(
67
name: "SuiKit",
7-
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
8+
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v7), .tvOS(.v13)],
89
products: [
910
.library(
1011
name: "SuiKit",
@@ -17,25 +18,28 @@ let package = Package(
1718
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.2.0"),
1819
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1920
.package(url: "https://github.com/tesseract-one/Bip39.swift.git", from: "0.1.1"),
20-
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
2121
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0"),
22-
.package(url: "https://github.com/apollographql/apollo-ios.git", .upToNextMajor(from: "1.0.0"))
22+
.package(url: "https://github.com/apollographql/apollo-ios.git", .upToNextMajor(from: "1.0.0")),
23+
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0")
2324
],
2425
targets: [
26+
.target(
27+
name: "secp256k1"
28+
),
2529
.target(
2630
name: "SuiKit",
2731
dependencies: [
32+
.product(name: "BigInt", package: "BigInt"),
2833
.product(name: "UInt256", package: "UInt256"),
2934
.product(name: "ed25519swift", package: "ed25519swift"),
3035
.product(name: "SwiftyJSON", package: "swiftyjson"),
3136
.product(name: "Blake2", package: "Blake2.swift"),
3237
.product(name: "AnyCodable", package: "AnyCodable"),
3338
.product(name: "Bip39", package: "Bip39.swift"),
34-
.product(name: "web3swift", package: "web3swift"),
39+
.product(name: "Apollo", package: "apollo-ios"),
3540
.product(name: "JWTDecode", package: "JWTDecode.swift"),
36-
.product(name: "Apollo", package: "apollo-ios")
37-
],
38-
path: "Sources"
41+
"secp256k1"
42+
]
3943
),
4044
.testTarget(
4145
name: "SuiKitTests",

Package@swift-5.7.swift

Lines changed: 0 additions & 46 deletions
This file was deleted.

Package@swift-5.8.swift

Lines changed: 0 additions & 46 deletions
This file was deleted.

Sources/SuiKit/Extensions/Data.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,56 @@
2626
import CommonCrypto
2727
import Foundation
2828

29+
extension Data {
30+
/// Converts hexadecimal string representation of some bytes into actual bytes.
31+
/// Notes:
32+
/// - empty string will return `nil`;
33+
/// - empty hex string, meaning it's equal to `"0x"`, will return empty `Data` object.
34+
/// - Parameter hex: bytes represented as string.
35+
/// - Returns: optional raw bytes.
36+
public static func fromHex(_ hex: String) -> Data? {
37+
let hex = hex.lowercased().trim()
38+
guard !hex.isEmpty else { return nil }
39+
guard hex != "0x" else { return Data() }
40+
let bytes = [UInt8](hex: hex.stripHexPrefix())
41+
return bytes.isEmpty ? nil : Data(bytes)
42+
}
43+
44+
func setLengthLeft(_ toBytes: UInt64, isNegative: Bool = false) -> Data? {
45+
let existingLength = UInt64(self.count)
46+
if existingLength == toBytes {
47+
return Data(self)
48+
} else if existingLength > toBytes {
49+
return nil
50+
}
51+
var data: Data
52+
if isNegative {
53+
data = Data(repeating: UInt8(255), count: Int(toBytes - existingLength))
54+
} else {
55+
data = Data(repeating: UInt8(0), count: Int(toBytes - existingLength))
56+
}
57+
data.append(self)
58+
return data
59+
}
60+
61+
func setLengthRight(_ toBytes: UInt64, isNegative: Bool = false) -> Data? {
62+
let existingLength = UInt64(self.count)
63+
if existingLength == toBytes {
64+
return Data(self)
65+
} else if existingLength > toBytes {
66+
return nil
67+
}
68+
var data: Data = Data()
69+
data.append(self)
70+
if isNegative {
71+
data.append(Data(repeating: UInt8(255), count: Int(toBytes - existingLength)))
72+
} else {
73+
data.append(Data(repeating: UInt8(0), count: Int(toBytes - existingLength)))
74+
}
75+
return data
76+
}
77+
}
78+
2979
public extension Data {
3080
/// Two octet checksum as defined in RFC-4880. Sum of all octets, mod 65536
3181
func checksum() -> UInt16 {

Sources/SuiKit/Extensions/String.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ extension String {
126126
return self.count / 2
127127
}
128128
}
129+
130+
/// Strips whitespaces and newlines on both ends.
131+
func trim() -> String {
132+
trimmingCharacters(in: .whitespacesAndNewlines)
133+
}
134+
135+
public func stripHexPrefix() -> String {
136+
if self.hasPrefix("0x") {
137+
let indexStart = self.index(self.startIndex, offsetBy: 2)
138+
return String(self[indexStart...])
139+
}
140+
return self
141+
}
129142
}
130143

131144
fileprivate func convertHex(_ s: String.UnicodeScalarView, i: String.UnicodeScalarIndex, appendTo d: [UInt8]) -> [UInt8] {

Sources/SuiKit/Types/Enums/Errors/SuiError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@ public enum SuiError: Error, Equatable {
168168

169169
/// The result for the GraphQL query is missing
170170
case missingGraphQLData
171+
172+
/// There was an error with parsing data for RIPEMD160 functions
173+
case DataError
171174
}

Sources/SuiKit/Types/Structs/Builders/Transactions/TransactionBlock/TransactionBlock.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class TransactionBlock {
3737
private var isPreparred: Bool = false
3838

3939
/// A dictionary containing default offline limits with string keys and integer values.
40-
public static let defaultOfflineLimits: [String: Int] = [
40+
public static let defaultOfflineLimits: [String: UInt64] = [
4141
"maxPureArgumentSize": 16 * 1024,
4242
"maxTxGas": 50_000_000_000,
4343
"maxGasObjects": 256,
@@ -463,7 +463,7 @@ public class TransactionBlock {
463463
guard let defaultValue = Self.defaultOfflineLimits[key.rawValue] else {
464464
throw SuiError.cannotFindProtocolConfig
465465
}
466-
return defaultValue
466+
return Int(defaultValue)
467467
}
468468

469469
// Unwrap protocolConfig's attributes for the given key.
@@ -550,7 +550,7 @@ public class TransactionBlock {
550550
}
551551
}
552552

553-
let range = 0..<min(TransactionConstants.MAX_GAS_OBJECTS, filteredCoins.count)
553+
let range = 0..<min(Int(TransactionConstants.MAX_GAS_OBJECTS), filteredCoins.count)
554554
let paymentCoins = filteredCoins[range].map { coin in
555555
SuiObjectRef(
556556
objectId: coin.coinObjectId,
@@ -702,7 +702,7 @@ public class TransactionBlock {
702702
if !(objectsToResolve.isEmpty) {
703703
// Chunk the object IDs to fetch and initialize an array to store the fetched objects
704704
let dedupedIds = objectsToResolve.map { $0.id }
705-
let objectChunks = dedupedIds.chunked(into: TransactionConstants.MAX_OBJECTS_PER_FETCH)
705+
let objectChunks = dedupedIds.chunked(into: Int(TransactionConstants.MAX_OBJECTS_PER_FETCH))
706706
var objects: [SuiObjectResponse] = []
707707

708708
// Fetch objects in chunks asynchronously and append them to the objects array
@@ -844,7 +844,7 @@ public class TransactionBlock {
844844
throw SuiError.failedDryRun
845845
}
846846

847-
let safeOverhead = TransactionConstants.GAS_SAFE_OVERHEAD * (
847+
let safeOverhead = Int(TransactionConstants.GAS_SAFE_OVERHEAD) * (
848848
Int(blockData.builder.gasConfig.price ?? "1")!
849849
)
850850

Sources/SuiKit/Types/Structs/Builders/Transactions/TransactionBlock/TransactionConstants.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import Foundation
2727

2828
public struct TransactionConstants {
29-
public static let MAX_GAS_OBJECTS = 256
30-
public static let MAX_GAS = 50_000_000_000
31-
public static let GAS_SAFE_OVERHEAD = 1_000
32-
public static let MAX_OBJECTS_PER_FETCH = 50
29+
public static let MAX_GAS_OBJECTS: UInt64 = 256
30+
public static let MAX_GAS: UInt64 = 50_000_000_000
31+
public static let GAS_SAFE_OVERHEAD: UInt64 = 1_000
32+
public static let MAX_OBJECTS_PER_FETCH: UInt64 = 50
3333
}

Sources/SuiKit/Types/Structs/Builders/Transactions/TransactionBlockData.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import Foundation
2727
import BigInt
2828
import CryptoKit
29-
import Web3Core
3029
import Blake2
3130

3231
public struct TransactionBlockDataBuilder: KeyProtocol {

Sources/SuiKit/Types/Structs/Cryptography/Account.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public struct Account: Equatable, Hashable {
5353
let privateKey = try SECP256K1PrivateKey()
5454
try self.init(privateKey: privateKey, accountType: accountType)
5555
case .secp256r1:
56-
if #available(macOS 13.0, iOS 16.0, *) {
56+
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
5757
let privateKey = try SECP256R1PrivateKey(hasBiometrics: hasBiometrics)
5858
try self.init(privateKey: privateKey, accountType: accountType)
5959
} else {
@@ -80,7 +80,7 @@ public struct Account: Equatable, Hashable {
8080
let privateKey = try SECP256K1PrivateKey(key: privateKey)
8181
try self.init(privateKey: privateKey, accountType: accountType)
8282
case .secp256r1:
83-
if #available(macOS 13.0, iOS 16.0, *) {
83+
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
8484
let privateKey = try SECP256R1PrivateKey(key: privateKey)
8585
try self.init(privateKey: privateKey, accountType: accountType)
8686
} else {
@@ -142,7 +142,7 @@ public struct Account: Equatable, Hashable {
142142
self.publicKey = try privateKey.publicKey()
143143
self.accountType = keyType
144144
case .secp256r1:
145-
if #available(macOS 13.0, iOS 16.0, *) {
145+
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
146146
let privateKey = try SECP256R1PrivateKey(hexString: hexString)
147147
self.privateKey = privateKey
148148
self.publicKey = try privateKey.publicKey()
@@ -198,7 +198,7 @@ public struct Account: Equatable, Hashable {
198198
self.privateKey = privateKey
199199
self.publicKey = try privateKey.publicKey()
200200
case .secp256r1:
201-
if #available(macOS 13.0, iOS 16.0, *) {
201+
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
202202
let privateKey = try SECP256R1PrivateKey(mnemonic)
203203
self.privateKey = privateKey
204204
self.publicKey = try privateKey.publicKey()
@@ -227,7 +227,7 @@ public struct Account: Equatable, Hashable {
227227
self.privateKey = privateKey
228228
self.publicKey = try privateKey.publicKey()
229229
case .secp256r1:
230-
if #available(macOS 13.0, iOS 16.0, *) {
230+
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
231231
let privateKey = try SECP256R1PrivateKey(value: value)
232232
self.privateKey = privateKey
233233
self.publicKey = try privateKey.publicKey()

Sources/SuiKit/Types/Structs/Cryptography/Signature.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
//
2525

2626
import Foundation
27-
import secp256k1
28-
import Web3Core
2927

3028
/// Represents a cryptographic signature.
3129
public struct Signature: Equatable, KeyProtocol {
@@ -101,7 +99,7 @@ public struct Signature: Equatable, KeyProtocol {
10199
let pubKey = try SECP256K1PublicKey(data: Data(pubKeyBytes))
102100
return Signature(signature: Data(signature), publickey: pubKey.key, signatureScheme: .SECP256K1)
103101
} else if signatureScheme == "SECP256R1" {
104-
if #available(macOS 13.0, iOS 16.0, *) {
102+
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
105103
let signature = Array(bytes[1...(bytes.count - SECP256R1PublicKey.LENGTH)])
106104
let pubKeyBytes = Array(bytes[(1 + signature.count)...])
107105
let pubKey = try SECP256R1PublicKey(data: Data(pubKeyBytes))

Sources/SuiKit/Types/Structs/Kiosk/KioskUtilities.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public struct KioskUtilities {
290290

291291
/// Normalizes the packageId part of a rule's type.
292292
public static func getNormalizedRuleType(rule: String) throws -> String {
293-
if #available(macOS 13.0, *) {
293+
if #available(macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
294294
var normalizedRuleAddress = rule.split(separator: "::").map { String($0) }
295295
normalizedRuleAddress[0] = try Inputs.normalizeSuiAddress(value: normalizedRuleAddress[0])
296296
return normalizedRuleAddress.joined(separator: "::")

Sources/SuiKit/Types/Structs/Objects/SuiObjectRef.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
//
2525

2626
import Foundation
27-
import Web3Core
2827
import SwiftyJSON
2928

3029
/// Represents a reference to a Sui Object and conforms to `KeyProtocol`.

Sources/SuiKit/Types/Structs/Provider/GraphQLSuiProvider.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import Foundation
2727
import SwiftyJSON
2828
import AnyCodable
2929
import Blake2
30-
import Web3Core
3130
import Apollo
3231
import ApolloAPI
3332
import BigInt

0 commit comments

Comments
 (0)