Skip to content

Commit 9062543

Browse files
authored
Merge pull request #77 from OpenDive/marcus-swift-6x-concurrency
(Release) Swift 6x concurrency
2 parents 43a590e + 5dff8c7 commit 9062543

49 files changed

Lines changed: 1038 additions & 299 deletions

Some content is hidden

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

Package.resolved

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

Package.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ let package = Package(
1515
.package(url: "https://github.com/pebble8888/ed25519swift.git", from: "1.2.7"),
1616
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "4.0.0"),
1717
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.2.0"),
18-
.package(url: "https://github.com/MarcoDotIO/AnyCodable", from: "1.0.0"),
19-
.package(url: "https://github.com/tesseract-one/Bip39.swift.git", from: "0.1.1"),
2018
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0"),
2119
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
22-
.package(url: "https://github.com/apollographql/apollo-ios.git", exact: "1.17.0")
20+
.package(url: "https://github.com/apollographql/apollo-ios.git", exact: "1.17.0"),
21+
.package(url: "https://github.com/tesseract-one/UncommonCrypto.swift.git", .upToNextMinor(from: "0.2.0"))
2322
],
2423
targets: [
2524
.target(
@@ -33,10 +32,9 @@ let package = Package(
3332
.product(name: "ed25519swift", package: "ed25519swift"),
3433
.product(name: "SwiftyJSON", package: "swiftyjson"),
3534
.product(name: "Blake2", package: "Blake2.swift"),
36-
.product(name: "AnyCodable", package: "AnyCodable"),
37-
.product(name: "Bip39", package: "Bip39.swift"),
3835
.product(name: "JWTDecode", package: "JWTDecode.swift"),
3936
.product(name: "Apollo", package: "apollo-ios"),
37+
.product(name: "UncommonCrypto", package: "UncommonCrypto.swift"),
4038
"secp256k1sui"
4139
]
4240
),

Sources/SuiKit/Protocols/BCS/EncodingProtocol.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
import Foundation
2727
import UInt256
28-
@preconcurrency import AnyCodable
2928

30-
public protocol EncodingProtocol: EncodingContainer { }
29+
public protocol EncodingProtocol: EncodingContainer, Sendable { }
3130

3231
extension UInt8: EncodingProtocol { }
3332
extension UInt16: EncodingProtocol { }

Sources/SuiKit/Protocols/BCS/KeyProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import Foundation
2727

28-
public protocol KeyProtocol: EncodingProtocol {
28+
public protocol KeyProtocol: EncodingProtocol, Sendable {
2929
/// Serializes an output instance using the given Serializer.
3030
///
3131
/// - Parameter serializer: The Serializer instance used to serialize the data.

Sources/SuiKit/Protocols/Cryptography/KeyValueProtocol.swift

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,6 @@ extension P256.Signing.PublicKey: KeyValueProtocol, @retroactive Hashable {
5555

5656
public func getType() -> DataType { return .p256 }
5757
}
58-
59-
/// Represents a `P256`private key.
60-
extension SecureEnclave.P256.Signing.PrivateKey: @retroactive Equatable {}
61-
extension SecureEnclave.P256.Signing.PrivateKey: KeyValueProtocol, @retroactive Hashable {
62-
public static func == (lhs: SecureEnclave.P256.Signing.PrivateKey, rhs: SecureEnclave.P256.Signing.PrivateKey) -> Bool {
63-
return lhs.dataRepresentation == rhs.dataRepresentation
64-
}
65-
66-
public func hash(into hasher: inout Hasher) {
67-
hasher.combine(self.hashValue)
68-
}
69-
70-
public func getType() -> DataType { return .p256 }
71-
}
7258
#else
7359
/// Represents a `P256`public key.
7460
extension P256.Signing.PublicKey: Equatable {}
@@ -83,18 +69,41 @@ extension P256.Signing.PublicKey: KeyValueProtocol, Hashable {
8369

8470
public func getType() -> DataType { return .p256 }
8571
}
72+
#endif
73+
74+
/// Support two types of private key storage:
75+
/// - `secureEnclave`: Keys stored securely in the device's Secure Enclave (hardware-backed).
76+
/// - `software`: Keys stored in software, using CryptoKit's P256 implementation.
77+
///
78+
/// Secure Enclave keys cannot be initialized from arbitrary raw private key bytes,
79+
/// so when initializing from raw data, the software implementation is used.
80+
public enum P256PrivateKeyStorage: Sendable {
81+
case secureEnclave(SecureEnclave.P256.Signing.PrivateKey)
82+
case software(CryptoKit.P256.Signing.PrivateKey)
83+
}
84+
85+
extension P256PrivateKeyStorage: Equatable {
86+
public static func == (lhs: Self, rhs: Self) -> Bool {
87+
switch (lhs, rhs) {
88+
case let (.secureEnclave(a), .secureEnclave(b)):
89+
return a.dataRepresentation == b.dataRepresentation
90+
91+
case let (.software(a), .software(b)):
92+
return a.rawRepresentation == b.rawRepresentation
93+
94+
// Different storage backends are not considered equal
95+
default:
96+
return false
97+
}
98+
}
99+
}
86100

87-
/// Represents a `P256`private key.
88-
extension SecureEnclave.P256.Signing.PrivateKey: Equatable {}
89-
extension SecureEnclave.P256.Signing.PrivateKey: KeyValueProtocol, Hashable {
90-
public static func == (lhs: SecureEnclave.P256.Signing.PrivateKey, rhs: SecureEnclave.P256.Signing.PrivateKey) -> Bool {
91-
return lhs.dataRepresentation == rhs.dataRepresentation
101+
extension P256PrivateKeyStorage: KeyValueProtocol, Hashable {
102+
public func getType() -> DataType {
103+
return .p256
92104
}
93105

94106
public func hash(into hasher: inout Hasher) {
95107
hasher.combine(self.hashValue)
96108
}
97-
98-
public func getType() -> DataType { return .p256 }
99109
}
100-
#endif

Sources/SuiKit/Protocols/Cryptography/PrivateKeyProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import Foundation
2727

2828
/// Protocol defining the requirements for a private key type.
29-
public protocol PrivateKeyProtocol: KeyProtocol, CustomStringConvertible, Hashable {
29+
public protocol PrivateKeyProtocol: KeyProtocol, CustomStringConvertible, Hashable, Sendable {
3030
/// The type of the public key that corresponds to this private key.
3131
associatedtype PublicKeyType: PublicKeyProtocol
3232

Sources/SuiKit/Protocols/Cryptography/PublicKeyProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import Foundation
2727

2828
/// Protocol defining the requirements for a public key type.
29-
public protocol PublicKeyProtocol: KeyProtocol, CustomStringConvertible, Hashable {
29+
public protocol PublicKeyProtocol: KeyProtocol, CustomStringConvertible, Hashable, Sendable {
3030
/// The type of data value that represents the key.
3131
associatedtype DataValue: KeyValueProtocol
3232

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1+
////
2+
//// SecKeyConvertible.swift
3+
//// SuiKit
4+
////
5+
//// Copyright (c) 2024-2025 OpenDive
6+
////
7+
//// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
//// of this software and associated documentation files (the "Software"), to deal
9+
//// in the Software without restriction, including without limitation the rights
10+
//// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
//// copies of the Software, and to permit persons to whom the Software is
12+
//// furnished to do so, subject to the following conditions:
13+
////
14+
//// The above copyright notice and this permission notice shall be included in
15+
//// all copies or substantial portions of the Software.
16+
////
17+
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
//// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
//// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
//// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
//// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
//// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
//// THE SOFTWARE.
24+
////
125
//
2-
// SecKeyConvertible.swift
3-
// SuiKit
26+
//import Foundation
27+
//import CryptoKit
428
//
5-
// Copyright (c) 2024-2025 OpenDive
29+
//public protocol GenericPasswordConvertible: CustomStringConvertible {
30+
// /// Creates a key from a raw representation.
31+
// init(rawRepresentation data: Data) throws
632
//
7-
// Permission is hereby granted, free of charge, to any person obtaining a copy
8-
// of this software and associated documentation files (the "Software"), to deal
9-
// in the Software without restriction, including without limitation the rights
10-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
// copies of the Software, and to permit persons to whom the Software is
12-
// furnished to do so, subject to the following conditions:
33+
// /// A raw representation of the key.
34+
// var rawRepresentation: Data { get }
35+
//}
1336
//
14-
// The above copyright notice and this permission notice shall be included in
15-
// all copies or substantial portions of the Software.
37+
//#if swift(>=5.9)
38+
//extension SecureEnclave.P256.Signing.PrivateKey: @retroactive CustomStringConvertible {}
39+
//extension SecureEnclave.P256.Signing.PrivateKey: GenericPasswordConvertible {
40+
// public var description: String {
41+
// "\(self.hashValue)"
42+
// }
1643
//
17-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
// THE SOFTWARE.
44+
// public init(rawRepresentation data: Data) throws {
45+
// try self.init(dataRepresentation: data)
46+
// }
2447
//
25-
26-
import Foundation
27-
import CryptoKit
28-
29-
public protocol GenericPasswordConvertible: CustomStringConvertible {
30-
/// Creates a key from a raw representation.
31-
init(rawRepresentation data: Data) throws
32-
33-
/// A raw representation of the key.
34-
var rawRepresentation: Data { get }
35-
}
36-
37-
#if swift(>=5.9)
38-
extension SecureEnclave.P256.Signing.PrivateKey: @retroactive CustomStringConvertible {}
39-
extension SecureEnclave.P256.Signing.PrivateKey: GenericPasswordConvertible {
40-
public var description: String {
41-
"\(self.hashValue)"
42-
}
43-
44-
public init(rawRepresentation data: Data) throws {
45-
try self.init(dataRepresentation: data)
46-
}
47-
48-
public var rawRepresentation: Data {
49-
return dataRepresentation
50-
}
51-
}
52-
#else
53-
extension SecureEnclave.P256.Signing.PrivateKey: CustomStringConvertible {}
54-
extension SecureEnclave.P256.Signing.PrivateKey: GenericPasswordConvertible {
55-
public var description: String {
56-
"\(self.hashValue)"
57-
}
58-
59-
public init(rawRepresentation data: Data) throws {
60-
try self.init(dataRepresentation: data)
61-
}
62-
63-
public var rawRepresentation: Data {
64-
return dataRepresentation
65-
}
66-
}
67-
#endif
48+
// public var rawRepresentation: Data {
49+
// return dataRepresentation
50+
// }
51+
//}
52+
//#else
53+
//extension SecureEnclave.P256.Signing.PrivateKey: CustomStringConvertible {}
54+
//extension SecureEnclave.P256.Signing.PrivateKey: GenericPasswordConvertible {
55+
// public var description: String {
56+
// "\(self.hashValue)"
57+
// }
58+
//
59+
// public init(rawRepresentation data: Data) throws {
60+
// try self.init(dataRepresentation: data)
61+
// }
62+
//
63+
// public var rawRepresentation: Data {
64+
// return dataRepresentation
65+
// }
66+
//}
67+
//#endif

Sources/SuiKit/Protocols/Sui/ConnectionProtocol.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,9 @@
2424
//
2525

2626
import Foundation
27-
#if swift(>=6.0)
28-
/// Protocol defining the requirements for a connection configuration.
29-
public protocol ConnectionProtocol: Sendable {
30-
/// The URL or IP address of the full node to connect to.
31-
var fullNode: String { get }
32-
33-
/// Optional URL for a faucet service to obtain tokens.
34-
/// Default is nil, meaning no faucet is configured.
35-
var faucet: String? { get }
3627

37-
var graphql: String? { get }
38-
39-
/// Optional URL for a WebSocket connection.
40-
/// Default is nil, meaning no WebSocket is configured.
41-
var websocket: String? { get }
42-
}
43-
#elseif swift(<6.0)
4428
/// Protocol defining the requirements for a connection configuration.
45-
public protocol ConnectionProtocol {
29+
public protocol ConnectionProtocol: Sendable {
4630
/// The URL or IP address of the full node to connect to.
4731
var fullNode: String { get }
4832

@@ -56,7 +40,6 @@ public protocol ConnectionProtocol {
5640
/// Default is nil, meaning no WebSocket is configured.
5741
var websocket: String? { get }
5842
}
59-
#endif
6043

6144
// MARK: - Default Implementations
6245
public extension ConnectionProtocol {

Sources/SuiKit/Protocols/Sui/GraphQLClientProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Marcus Arnett on 5/21/25.
66
//
77

8-
public protocol GraphQLClientProtocol {
8+
public protocol GraphQLClientProtocol: Sendable {
99
/// Verify a zkLogin signature using GraphQL
1010
/// - Parameters:
1111
/// - bytes: The message bytes (transaction data or personal message) as Base64

0 commit comments

Comments
 (0)