Skip to content

Commit

Permalink
Fix version build issues for other platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Arnett committed Feb 21, 2024
1 parent 16290fd commit 62a3307
Show file tree
Hide file tree
Showing 75 changed files with 13,320 additions and 150 deletions.
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@
"revision" : "e089407582e1f2d81dc11ba167362742422b8979",
"version" : "0.1.3"
}
},
{
"identity" : "web3swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/web3swift-team/web3swift.git",
"state" : {
"revision" : "74c24f4d3d5f1816616e9ebd16741ca5f7a57eb0",
"version" : "3.2.0"
}
}
],
"version" : 2
Expand Down
20 changes: 12 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// swift-tools-version: 5.9
// swift-tools-version: 5.5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SuiKit",
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v7), .tvOS(.v13)],
products: [
.library(
name: "SuiKit",
Expand All @@ -17,25 +18,28 @@ let package = Package(
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.2.0"),
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
.package(url: "https://github.com/tesseract-one/Bip39.swift.git", from: "0.1.1"),
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0"),
.package(url: "https://github.com/apollographql/apollo-ios.git", .upToNextMajor(from: "1.0.0"))
.package(url: "https://github.com/apollographql/apollo-ios.git", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0")
],
targets: [
.target(
name: "secp256k1"
),
.target(
name: "SuiKit",
dependencies: [
.product(name: "BigInt", package: "BigInt"),
.product(name: "UInt256", package: "UInt256"),
.product(name: "ed25519swift", package: "ed25519swift"),
.product(name: "SwiftyJSON", package: "swiftyjson"),
.product(name: "Blake2", package: "Blake2.swift"),
.product(name: "AnyCodable", package: "AnyCodable"),
.product(name: "Bip39", package: "Bip39.swift"),
.product(name: "web3swift", package: "web3swift"),
.product(name: "Apollo", package: "apollo-ios"),
.product(name: "JWTDecode", package: "JWTDecode.swift"),
.product(name: "Apollo", package: "apollo-ios")
],
path: "Sources"
"secp256k1"
]
),
.testTarget(
name: "SuiKitTests",
Expand Down
46 changes: 0 additions & 46 deletions [email protected]

This file was deleted.

46 changes: 0 additions & 46 deletions [email protected]

This file was deleted.

50 changes: 50 additions & 0 deletions Sources/SuiKit/Extensions/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,56 @@
import CommonCrypto
import Foundation

extension Data {
/// Converts hexadecimal string representation of some bytes into actual bytes.
/// Notes:
/// - empty string will return `nil`;
/// - empty hex string, meaning it's equal to `"0x"`, will return empty `Data` object.
/// - Parameter hex: bytes represented as string.
/// - Returns: optional raw bytes.
public static func fromHex(_ hex: String) -> Data? {
let hex = hex.lowercased().trim()
guard !hex.isEmpty else { return nil }
guard hex != "0x" else { return Data() }
let bytes = [UInt8](hex: hex.stripHexPrefix())
return bytes.isEmpty ? nil : Data(bytes)
}

func setLengthLeft(_ toBytes: UInt64, isNegative: Bool = false) -> Data? {
let existingLength = UInt64(self.count)
if existingLength == toBytes {
return Data(self)
} else if existingLength > toBytes {
return nil
}
var data: Data
if isNegative {
data = Data(repeating: UInt8(255), count: Int(toBytes - existingLength))
} else {
data = Data(repeating: UInt8(0), count: Int(toBytes - existingLength))
}
data.append(self)
return data
}

func setLengthRight(_ toBytes: UInt64, isNegative: Bool = false) -> Data? {
let existingLength = UInt64(self.count)
if existingLength == toBytes {
return Data(self)
} else if existingLength > toBytes {
return nil
}
var data: Data = Data()
data.append(self)
if isNegative {
data.append(Data(repeating: UInt8(255), count: Int(toBytes - existingLength)))
} else {
data.append(Data(repeating: UInt8(0), count: Int(toBytes - existingLength)))
}
return data
}
}

public extension Data {
/// Two octet checksum as defined in RFC-4880. Sum of all octets, mod 65536
func checksum() -> UInt16 {
Expand Down
13 changes: 13 additions & 0 deletions Sources/SuiKit/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ extension String {
return self.count / 2
}
}

/// Strips whitespaces and newlines on both ends.
func trim() -> String {
trimmingCharacters(in: .whitespacesAndNewlines)
}

public func stripHexPrefix() -> String {
if self.hasPrefix("0x") {
let indexStart = self.index(self.startIndex, offsetBy: 2)
return String(self[indexStart...])
}
return self
}
}

fileprivate func convertHex(_ s: String.UnicodeScalarView, i: String.UnicodeScalarIndex, appendTo d: [UInt8]) -> [UInt8] {
Expand Down
3 changes: 3 additions & 0 deletions Sources/SuiKit/Types/Enums/Errors/SuiError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,7 @@ public enum SuiError: Error, Equatable {

/// The result for the GraphQL query is missing
case missingGraphQLData

/// There was an error with parsing data for RIPEMD160 functions
case DataError
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TransactionBlock {
private var isPreparred: Bool = false

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

// Unwrap protocolConfig's attributes for the given key.
Expand Down Expand Up @@ -550,7 +550,7 @@ public class TransactionBlock {
}
}

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

// Fetch objects in chunks asynchronously and append them to the objects array
Expand Down Expand Up @@ -844,7 +844,7 @@ public class TransactionBlock {
throw SuiError.failedDryRun
}

let safeOverhead = TransactionConstants.GAS_SAFE_OVERHEAD * (
let safeOverhead = Int(TransactionConstants.GAS_SAFE_OVERHEAD) * (
Int(blockData.builder.gasConfig.price ?? "1")!
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import Foundation

public struct TransactionConstants {
public static let MAX_GAS_OBJECTS = 256
public static let MAX_GAS = 50_000_000_000
public static let GAS_SAFE_OVERHEAD = 1_000
public static let MAX_OBJECTS_PER_FETCH = 50
public static let MAX_GAS_OBJECTS: UInt64 = 256
public static let MAX_GAS: UInt64 = 50_000_000_000
public static let GAS_SAFE_OVERHEAD: UInt64 = 1_000
public static let MAX_OBJECTS_PER_FETCH: UInt64 = 50
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import Foundation
import BigInt
import CryptoKit
import Web3Core
import Blake2

public struct TransactionBlockDataBuilder: KeyProtocol {
Expand Down
10 changes: 5 additions & 5 deletions Sources/SuiKit/Types/Structs/Cryptography/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct Account: Equatable, Hashable {
let privateKey = try SECP256K1PrivateKey()
try self.init(privateKey: privateKey, accountType: accountType)
case .secp256r1:
if #available(macOS 13.0, iOS 16.0, *) {
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
let privateKey = try SECP256R1PrivateKey(hasBiometrics: hasBiometrics)
try self.init(privateKey: privateKey, accountType: accountType)
} else {
Expand All @@ -80,7 +80,7 @@ public struct Account: Equatable, Hashable {
let privateKey = try SECP256K1PrivateKey(key: privateKey)
try self.init(privateKey: privateKey, accountType: accountType)
case .secp256r1:
if #available(macOS 13.0, iOS 16.0, *) {
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
let privateKey = try SECP256R1PrivateKey(key: privateKey)
try self.init(privateKey: privateKey, accountType: accountType)
} else {
Expand Down Expand Up @@ -142,7 +142,7 @@ public struct Account: Equatable, Hashable {
self.publicKey = try privateKey.publicKey()
self.accountType = keyType
case .secp256r1:
if #available(macOS 13.0, iOS 16.0, *) {
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
let privateKey = try SECP256R1PrivateKey(hexString: hexString)
self.privateKey = privateKey
self.publicKey = try privateKey.publicKey()
Expand Down Expand Up @@ -198,7 +198,7 @@ public struct Account: Equatable, Hashable {
self.privateKey = privateKey
self.publicKey = try privateKey.publicKey()
case .secp256r1:
if #available(macOS 13.0, iOS 16.0, *) {
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
let privateKey = try SECP256R1PrivateKey(mnemonic)
self.privateKey = privateKey
self.publicKey = try privateKey.publicKey()
Expand Down Expand Up @@ -227,7 +227,7 @@ public struct Account: Equatable, Hashable {
self.privateKey = privateKey
self.publicKey = try privateKey.publicKey()
case .secp256r1:
if #available(macOS 13.0, iOS 16.0, *) {
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
let privateKey = try SECP256R1PrivateKey(value: value)
self.privateKey = privateKey
self.publicKey = try privateKey.publicKey()
Expand Down
4 changes: 1 addition & 3 deletions Sources/SuiKit/Types/Structs/Cryptography/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
//

import Foundation
import secp256k1
import Web3Core

/// Represents a cryptographic signature.
public struct Signature: Equatable, KeyProtocol {
Expand Down Expand Up @@ -101,7 +99,7 @@ public struct Signature: Equatable, KeyProtocol {
let pubKey = try SECP256K1PublicKey(data: Data(pubKeyBytes))
return Signature(signature: Data(signature), publickey: pubKey.key, signatureScheme: .SECP256K1)
} else if signatureScheme == "SECP256R1" {
if #available(macOS 13.0, iOS 16.0, *) {
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) {
let signature = Array(bytes[1...(bytes.count - SECP256R1PublicKey.LENGTH)])
let pubKeyBytes = Array(bytes[(1 + signature.count)...])
let pubKey = try SECP256R1PublicKey(data: Data(pubKeyBytes))
Expand Down
2 changes: 1 addition & 1 deletion Sources/SuiKit/Types/Structs/Kiosk/KioskUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public struct KioskUtilities {

/// Normalizes the packageId part of a rule's type.
public static func getNormalizedRuleType(rule: String) throws -> String {
if #available(macOS 13.0, *) {
if #available(macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
var normalizedRuleAddress = rule.split(separator: "::").map { String($0) }
normalizedRuleAddress[0] = try Inputs.normalizeSuiAddress(value: normalizedRuleAddress[0])
return normalizedRuleAddress.joined(separator: "::")
Expand Down
1 change: 0 additions & 1 deletion Sources/SuiKit/Types/Structs/Objects/SuiObjectRef.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
//

import Foundation
import Web3Core
import SwiftyJSON

/// Represents a reference to a Sui Object and conforms to `KeyProtocol`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Foundation
import SwiftyJSON
import AnyCodable
import Blake2
import Web3Core
import Apollo
import ApolloAPI
import BigInt
Expand Down
Loading

0 comments on commit 62a3307

Please sign in to comment.