Skip to content

Commit 7bf7425

Browse files
committed
Please refer to the 1.1 update notes
1 parent b56210b commit 7bf7425

File tree

168 files changed

+21331
-704
lines changed

Some content is hidden

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

168 files changed

+21331
-704
lines changed

Examples/iOS_Example/iOS_Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Package.resolved

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

Package.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "SuiKit",
7-
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
7+
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
88
products: [
99
.library(
1010
name: "SuiKit",
@@ -17,7 +17,8 @@ let package = Package(
1717
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.1.0"),
1818
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1919
.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")
20+
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
21+
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
2122
],
2223
targets: [
2324
.target(
@@ -29,7 +30,8 @@ let package = Package(
2930
.product(name: "Blake2", package: "Blake2.swift"),
3031
.product(name: "AnyCodable", package: "AnyCodable"),
3132
.product(name: "Bip39", package: "Bip39.swift"),
32-
.product(name: "web3swift", package: "web3swift")
33+
.product(name: "web3swift", package: "web3swift"),
34+
.product(name: "JWTDecode", package: "JWTDecode.swift")
3335
],
3436
path: "Sources"
3537
),

Package@swift-5.5.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "SuiKit",
7-
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
7+
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
88
products: [
99
.library(
1010
name: "SuiKit",
@@ -17,7 +17,8 @@ let package = Package(
1717
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.1.0"),
1818
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1919
.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")
20+
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
21+
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
2122
],
2223
targets: [
2324
.target(
@@ -29,7 +30,8 @@ let package = Package(
2930
.product(name: "Blake2", package: "Blake2.swift"),
3031
.product(name: "AnyCodable", package: "AnyCodable"),
3132
.product(name: "Bip39", package: "Bip39.swift"),
32-
.product(name: "web3swift", package: "web3swift")
33+
.product(name: "web3swift", package: "web3swift"),
34+
.product(name: "JWTDecode", package: "JWTDecode.swift")
3335
],
3436
path: "Sources"
3537
),

Package@swift-5.6.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "SuiKit",
7-
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
7+
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
88
products: [
99
.library(
1010
name: "SuiKit",
@@ -17,7 +17,8 @@ let package = Package(
1717
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.1.0"),
1818
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1919
.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")
20+
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
21+
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
2122
],
2223
targets: [
2324
.target(
@@ -29,7 +30,8 @@ let package = Package(
2930
.product(name: "Blake2", package: "Blake2.swift"),
3031
.product(name: "AnyCodable", package: "AnyCodable"),
3132
.product(name: "Bip39", package: "Bip39.swift"),
32-
.product(name: "web3swift", package: "web3swift")
33+
.product(name: "web3swift", package: "web3swift"),
34+
.product(name: "JWTDecode", package: "JWTDecode.swift")
3335
],
3436
path: "Sources"
3537
),

Package@swift-5.7.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "SuiKit",
7-
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
7+
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
88
products: [
99
.library(
1010
name: "SuiKit",
@@ -17,7 +17,8 @@ let package = Package(
1717
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.1.0"),
1818
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1919
.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")
20+
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
21+
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
2122
],
2223
targets: [
2324
.target(
@@ -29,7 +30,8 @@ let package = Package(
2930
.product(name: "Blake2", package: "Blake2.swift"),
3031
.product(name: "AnyCodable", package: "AnyCodable"),
3132
.product(name: "Bip39", package: "Bip39.swift"),
32-
.product(name: "web3swift", package: "web3swift")
33+
.product(name: "web3swift", package: "web3swift"),
34+
.product(name: "JWTDecode", package: "JWTDecode.swift")
3335
],
3436
path: "Sources"
3537
),

Package@swift-5.8.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "SuiKit",
7-
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
7+
platforms: [.iOS(.v13), .macOS(.v11), .watchOS(.v6), .tvOS(.v13), .custom("xros", versionString: "1.0")],
88
products: [
99
.library(
1010
name: "SuiKit",
@@ -17,7 +17,8 @@ let package = Package(
1717
.package(url: "https://github.com/tesseract-one/Blake2.swift.git", from: "0.1.0"),
1818
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
1919
.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")
20+
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
21+
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
2122
],
2223
targets: [
2324
.target(
@@ -29,7 +30,8 @@ let package = Package(
2930
.product(name: "Blake2", package: "Blake2.swift"),
3031
.product(name: "AnyCodable", package: "AnyCodable"),
3132
.product(name: "Bip39", package: "Bip39.swift"),
32-
.product(name: "web3swift", package: "web3swift")
33+
.product(name: "web3swift", package: "web3swift"),
34+
.product(name: "JWTDecode", package: "JWTDecode.swift")
3335
],
3436
path: "Sources"
3537
),

README.md

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,28 @@ SuiKit is a Swift SDK natively designed to make developing for the Sui Blockchai
2121

2222
## Features
2323

24-
- [x] Submitting transactions
25-
- [x] Transferring objects
26-
- [x] Transfer Sui
27-
- [x] Air drop Sui tokens
28-
- [x] Merge and Split coins
29-
- [x] Publish modules
30-
- [x] Transfer objects
31-
- [x] Execute move calls
32-
- [x] Retrieving objects, transactions, checkpoints, coins, and events
33-
- [x] Executing transactions
34-
- [x] Local, custom, dev, test, and main net compatiblity
35-
- [x] ED25519 and SECP256K1 Key and HD Wallet generation
36-
- [x] Native Swift BCS Implementation
24+
- [x] Submitting transactions.
25+
- [x] Transferring objects.
26+
- [x] Transfer Sui.
27+
- [x] Air drop Sui tokens.
28+
- [x] Merge and Split coins.
29+
- [x] Publish modules.
30+
- [x] Transfer objects.
31+
- [x] Execute move calls.
32+
- [x] Retrieving objects, transactions, checkpoints, coins, and events.
33+
- [x] Local Transaction Building.
34+
- [x] Local, custom, dev, test, and main net compatiblity.
35+
- [x] ED25519, SECP256K1, SECP256R1, and zkLogin Key and HD Wallet generation.
36+
- [x] SuiNS support.
37+
- [x] Kiosk Support.
38+
- [x] Native Swift BCS Implementation.
3739
- [x] Swift Concurrency Support back to iOS 13, macOS 10.15, tvOS 13, and watchOS 6.
3840
- [x] Comprehensive Unit and End To End Test coverage.
3941

4042
## ToDo
4143

4244
- [ ] Complete documentation of SuiKit.
4345
- [ ] Implement Resolve Name Service Names.
44-
- [ ] Implement SECP256R1 Enclaves.
4546

4647
## Requirements
4748

@@ -148,6 +149,42 @@ catch {
148149
}
149150
```
150151

152+
Also the developer is able to call functions with multiple return values
153+
154+
```swift
155+
import SuiKit
156+
do {
157+
// Create new wallet
158+
let newWallet = try Wallet()
159+
160+
// Create Signer and Provider
161+
let provider = SuiProvider()
162+
let signer = RawSigner(account: newWallet.accounts[0], provider: provider)
163+
164+
// Create transaction block
165+
var tx = try TransactionBlock()
166+
167+
// Prepare merge coin
168+
let result = try tx.moveCall(
169+
target: "OxB0B::nft::mint_multiple",
170+
arguments: [
171+
.input(try tx.pure(value: .string("Example NFT"))),
172+
.input(try tx.pure(value: .number(2)))
173+
]
174+
)
175+
176+
// Utilizing the multiple return values
177+
try tx.transferObjects([result[0], result[1]], try newWallet.accounts[0].address())
178+
179+
// Execute transaction
180+
var result = try await signer.signAndExecuteTransaction(transactionBlock: &tx)
181+
result = try await provider.waitForTransaction(tx: result.digest)
182+
print (result)
183+
catch {
184+
print ("Error: (error)")
185+
}
186+
```
187+
151188
And this is how to publish a package. (Note: it is recommended for this to be used in a CLI / MacOS enviornment)
152189

153190
```swift
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Marcus Arnett on 11/29/23.
6+
//
7+
8+
import Foundation
9+
10+
extension Double {
11+
public func percentageToBasisPoints() throws -> Int {
12+
guard self >= 0 && self <= 100 else { throw SuiError.notImplemented }
13+
return Int(ceil(self * 100))
14+
}
15+
}

Sources/SuiKit/Extensions/String.swift

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

2828
extension String {
29+
func extractDomainAndTLD() -> (domain: String?, topLevelDomain: String?) {
30+
let regex = try! NSRegularExpression(pattern: "^(.+)\\.([^.]+)$", options: [])
31+
let nsrange = NSRange(self.startIndex..<self.endIndex, in: self)
32+
33+
var domain: String?
34+
var topLevelDomain: String?
35+
36+
if let match = regex.firstMatch(in: self, options: [], range: nsrange) {
37+
if let domainRange = Range(match.range(at: 1), in: self) {
38+
domain = String(self[domainRange])
39+
}
40+
if let tldRange = Range(match.range(at: 2), in: self) {
41+
topLevelDomain = String(self[tldRange])
42+
}
43+
}
44+
45+
return (domain, topLevelDomain)
46+
}
47+
48+
func capitalizingFirstLetter() -> String {
49+
return prefix(1).uppercased() + self.lowercased().dropFirst()
50+
}
51+
2952
var urlEncoded: String {
3053
return self.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? self
3154
}
@@ -82,6 +105,12 @@ extension String {
82105
return (self.isHex()) && (self.getHexByteLength() == 32)
83106
}
84107

108+
public func leftPad(toLength: Int, withPad: String) -> String {
109+
guard toLength > self.count else { return self }
110+
let padding = String(repeating: withPad, count: toLength - self.count)
111+
return padding + self
112+
}
113+
85114
private func isHex() -> Bool {
86115
let regex = try! NSRegularExpression(pattern: "^(0x|0X)?[a-fA-F0-9]+$")
87116
let range = NSRange(location: 0, length: self.utf16.count)

Sources/SuiKit/Protocols/Cryptography/KeyValueProtocol.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//
2525

2626
import Foundation
27+
import CryptoKit
2728

2829
/// Represents what type of type the key's data is going to be,
2930
public protocol KeyValueProtocol {
@@ -37,7 +38,28 @@ extension Data: KeyValueProtocol {
3738
public func getType() -> DataType { return .data }
3839
}
3940

40-
/// Represents a security key.
41-
extension SecKey: KeyValueProtocol {
42-
public func getType() -> DataType { return .secKey }
41+
/// Represents a `P256`public key.
42+
extension P256.Signing.PublicKey: KeyValueProtocol, Hashable {
43+
public static func == (lhs: P256.Signing.PublicKey, rhs: P256.Signing.PublicKey) -> Bool {
44+
return lhs.rawRepresentation == rhs.rawRepresentation
45+
}
46+
47+
public func hash(into hasher: inout Hasher) {
48+
hasher.combine(self.rawRepresentation)
49+
}
50+
51+
public func getType() -> DataType { return .p256 }
52+
}
53+
54+
/// Represents a `P256`private key.
55+
extension SecureEnclave.P256.Signing.PrivateKey: KeyValueProtocol, Hashable {
56+
public static func == (lhs: SecureEnclave.P256.Signing.PrivateKey, rhs: SecureEnclave.P256.Signing.PrivateKey) -> Bool {
57+
return lhs.dataRepresentation == rhs.dataRepresentation
58+
}
59+
60+
public func hash(into hasher: inout Hasher) {
61+
hasher.combine(self.hashValue)
62+
}
63+
64+
public func getType() -> DataType { return .p256 }
4365
}

Sources/SuiKit/Protocols/Cryptography/PublicKeyProtocol.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public protocol PublicKeyProtocol: KeyProtocol, CustomStringConvertible, Hashabl
5757
/// - Throws: If any error occurs during conversion.
5858
/// - Returns: A string representing the Sui address.
5959
func toSuiAddress() throws -> String
60-
60+
6161
/// Serializes the signature along with the public key.
6262
/// - Parameter signature: The signature to serialize.
6363
/// - Throws: If any error occurs during serialization.
@@ -88,4 +88,6 @@ public protocol PublicKeyProtocol: KeyProtocol, CustomStringConvertible, Hashabl
8888
/// - Throws: If any error occurs during verification.
8989
/// - Returns: `true` if the verification is successful, otherwise `false`.
9090
func verifyPersonalMessage(_ message: [UInt8], _ signature: Signature) throws -> Bool
91+
92+
func toSuiBytes() throws -> [UInt8]
9193
}

0 commit comments

Comments
 (0)