Skip to content

Commit a5697ec

Browse files
committed
Merge branch 'main' into refactor-internal-processing
Signed-off-by: Rob Walworth <[email protected]>
2 parents 5d08203 + 62da63d commit a5697ec

File tree

187 files changed

+4712
-726
lines changed

Some content is hidden

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

187 files changed

+4712
-726
lines changed

.github/workflows/swift-ci.yml

Lines changed: 87 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Swift CI
22
on:
33
pull_request:
4-
push:
4+
push:
55
branches: ['main']
66

77
defaults:
@@ -13,7 +13,8 @@ permissions:
1313

1414
jobs:
1515
format:
16-
runs-on: macos-latest
16+
name: Format (lint)
17+
runs-on: hiero-client-sdk-linux-large
1718
steps:
1819
- name: Harden Runner
1920
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
@@ -23,73 +24,110 @@ jobs:
2324
- name: Checkout Code
2425
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2526

26-
- name: Install swift-format
27-
run: brew install swift-format
28-
29-
- name: Format
30-
run: swift format lint --strict --configuration .swift-format.json --recursive --parallel Sources/ Tests/ Examples/ Package.swift
31-
32-
build:
33-
strategy:
34-
matrix:
35-
swift: ["5.9", "5.10"]
36-
os: [macos-13, macos-14]
37-
38-
runs-on: ${{ matrix.os }}
39-
steps:
40-
- name: Harden Runner
41-
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
42-
with:
43-
egress-policy: audit
44-
45-
- name: Setup Swift
46-
uses: swift-actions/setup-swift@3aed395c5397f62deb91d8fe7af1418a9ae4d16f # v2.1.0
27+
- name: Install system deps for Swift
28+
run: |
29+
set -euxo pipefail
30+
sudo apt-get update
31+
sudo apt-get install -y \
32+
git curl unzip xz-utils ca-certificates pkg-config \
33+
clang libicu-dev libxml2-dev libsqlite3-dev zlib1g-dev \
34+
libcurl4-openssl-dev libssl-dev
35+
36+
- name: Setup Swift (toolchain)
37+
uses: SwiftyLab/setup-swift@4bbb093f8c68d1dee1caa8b67c681a3f8fe70a91 # v1.12.0
4738
with:
48-
swift-version: ${{ matrix.swift }}
49-
50-
- name: Checkout Code
51-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
52-
53-
- name: Cache
54-
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
55-
with:
56-
path: sdk/swift/.build
57-
key: ${{ runner.os }}-${{ matrix.swift }}-spm-${{ github.job }}-${{ hashFiles('**/Package.resolved') }}
58-
restore-keys: |
59-
${{ runner.os }}-${{ matrix.swift }}-spm-
60-
61-
- name: Build
62-
run: swift build
39+
swift-version: '5.9'
40+
41+
- name: Build swift-format
42+
run: |
43+
set -euxo pipefail
44+
git clone --depth=1 https://github.com/apple/swift-format.git .swift-format-src
45+
pushd .swift-format-src
46+
swift build -c release
47+
echo "$PWD/.build/release" >> $GITHUB_PATH
48+
popd
49+
swift-format --version || true
50+
51+
- name: Format (lint)
52+
run: |
53+
swift-format lint --strict --configuration .swift-format.json --recursive --parallel Sources/ Tests/ Examples/ Package.swift
6354
6455
test:
56+
name: Build and Test SDK
6557
strategy:
6658
matrix:
6759
swift: ["5.9", "5.10"]
68-
os: [macos-13, macos-14]
60+
runs-on: hiero-client-sdk-linux-large
61+
env:
62+
SOLO_CLUSTER_NAME: solo
63+
SOLO_NAMESPACE: solo
64+
SOLO_CLUSTER_SETUP_NAMESPACE: solo-cluster
65+
SOLO_DEPLOYMENT: solo-deployment
66+
KIND_IMAGE: kindest/node:v1.32.2 # pin to a stable image
6967

70-
needs: [build]
71-
runs-on: ${{ matrix.os }}
7268
steps:
7369
- name: Harden Runner
74-
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
70+
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f
7571
with:
7672
egress-policy: audit
7773

7874
- name: Setup Swift
79-
uses: swift-actions/setup-swift@3aed395c5397f62deb91d8fe7af1418a9ae4d16f # v2.1.0
75+
uses: SwiftyLab/setup-swift@4bbb093f8c68d1dee1caa8b67c681a3f8fe70a91 # v1.12.0
8076
with:
8177
swift-version: ${{ matrix.swift }}
8278

8379
- name: Checkout Code
84-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
80+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
8581

86-
- name: Cache Code
87-
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
82+
- name: Cache SPM build dir
83+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
8884
with:
89-
path: sdk/swift/.build
85+
path: .build
9086
key: ${{ runner.os }}-${{ matrix.swift }}-spm-${{ github.job }}-${{ hashFiles('**/Package.resolved') }}
9187
restore-keys: |
9288
${{ runner.os }}-${{ matrix.swift }}-spm-
9389
94-
- name: Test
95-
run: swift test
90+
- name: Install system dependencies for Swift/gRPC
91+
run: |
92+
set -euxo pipefail
93+
sudo apt-get update
94+
sudo apt-get install -y \
95+
git curl jq coreutils ca-certificates \
96+
clang libicu-dev libxml2-dev libsqlite3-dev zlib1g-dev \
97+
libcurl4-openssl-dev libssl-dev pkg-config \
98+
protobuf-compiler
99+
100+
- name: Verify Swift installation
101+
run: |
102+
swift --version
103+
which swift
104+
swift package --version
105+
106+
- name: Build SDK and TCK
107+
run: |
108+
swift build
109+
110+
- name: Run unit tests (HieroTests)
111+
run: swift test --filter HieroTests
112+
113+
- name: Prepare Hiero Solo
114+
id: solo
115+
uses: hiero-ledger/hiero-solo-action@6a1a77601cf3e69661fb6880530a4edf656b40d5 # v0.14.0
116+
with:
117+
installMirrorNode: true
118+
mirrorNodeVersion: v0.142.0
119+
hieroVersion: v0.68.0
120+
121+
- name: Write .env for tests
122+
run: |
123+
umask 077
124+
{
125+
echo "TEST_NETWORK_NAME=localhost"
126+
echo "TEST_RUN_NONFREE=1"
127+
echo "TEST_OPERATOR_ID=0.0.2"
128+
echo "TEST_OPERATOR_KEY=302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"
129+
} > .env
130+
cat .env
131+
132+
- name: Run integration tests (HieroE2ETests)
133+
run: swift test --filter HieroE2ETests

Examples/CreateUpdateDeleteNode/main.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import Foundation
44
import Hiero
55
import HieroExampleUtilities
6-
import Network
76
import SwiftDotenv
87

98
// Set the paths **HERE** for the json files provided by solo.

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ let package = Package(
109109
.package(url: "https://github.com/attaswift/BigInt.git", .upToNextMajor(from: "5.2.0")),
110110
// Currently, only used for keccak256
111111
.package(url: "https://github.com/krzyzanowskim/OpenSSL-Package.git", .upToNextMajor(from: "3.3.2000")),
112+
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.8.0"),
113+
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMajor(from: "3.0.0")),
112114
],
113115
targets: [
114116
.target(
@@ -140,6 +142,8 @@ let package = Package(
140142
.product(name: "secp256k1", package: "secp256k1.swift"),
141143
.product(name: "BigInt", package: "BigInt"),
142144
.product(name: "OpenSSL", package: "OpenSSL-Package"),
145+
.product(name: "CryptoSwift", package: "CryptoSwift"),
146+
.product(name: "Crypto", package: "swift-crypto"),
143147
]
144148
// todo: find some way to enable these locally.
145149
// swiftSettings: [

Sources/Hiero/AnyTransaction.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ internal enum ServicesTransactionDataList {
6363
case hintsPartialSignature([Com_Hedera_Hapi_Services_Auxiliary_Hints_HintsPartialSignatureTransactionBody])
6464
case crsPublication([Com_Hedera_Hapi_Services_Auxiliary_Hints_CrsPublicationTransactionBody])
6565
case atomicBatch([Proto_AtomicBatchTransactionBody])
66+
case lambdaSstore([Com_Hedera_Hapi_Node_Hooks_LambdaSStoreTransactionBody])
67+
case hookDispatch([Com_Hedera_Hapi_Node_Hooks_HookDispatchTransactionBody])
6668

6769
internal mutating func append(_ transaction: Proto_TransactionBody.OneOf_Data) throws {
6870
switch (self, transaction) {
@@ -298,6 +300,14 @@ internal enum ServicesTransactionDataList {
298300
array.append(data)
299301
self = .atomicBatch(array)
300302

303+
case (.lambdaSstore(var array), .lambdaSstore(let data)):
304+
array.append(data)
305+
self = .lambdaSstore(array)
306+
307+
case (.hookDispatch(var array), .hookDispatch(let data)):
308+
array.append(data)
309+
self = .hookDispatch(array)
310+
301311
default:
302312
throw HError.fromProtobuf("mismatched transaction types")
303313
}
@@ -370,6 +380,8 @@ extension ServicesTransactionDataList: TryFromProtobuf {
370380
case .tokenCancelAirdrop(let data): value = .tokenCancelAirdrop([data])
371381
case .tokenClaimAirdrop(let data): value = .tokenClaimAirdrop([data])
372382
case .atomicBatch(let data): value = .atomicBatch([data])
383+
case .lambdaSstore(let data): value = .lambdaSstore([data])
384+
case .hookDispatch(let data): value = .hookDispatch([data])
373385
case .stateSignatureTransaction:
374386
throw HError.fromProtobuf("Unsupported transaction `StateSignatureTransaction`")
375387
case .hintsPreprocessingVote:

Sources/Hiero/Contract/ContractFunctionSelector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private struct KeccakHasher {
261261
}
262262

263263
mutating func finalize() -> Data {
264-
let output = Crypto.Sha3.keccak256(buffer!)
264+
let output = CryptoNamespace.Sha3.keccak256(buffer!)
265265
buffer = nil
266266

267267
return output

Sources/Hiero/Contract/MirrorNodeContractQuery.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import Foundation
44
import GRPC
55
import HieroProtobufs
66

7+
#if canImport(FoundationNetworking)
8+
import FoundationNetworking
9+
#endif
10+
711
/// MirrorNodeContractQuery returns a result from EVM execution such as cost-free execution of read-only smart
812
/// contract queries, gas estimation, and transient simulations of read-write operations.
913
public class MirrorNodeContractQuery: ValidateChecksums {
@@ -107,7 +111,25 @@ public class MirrorNodeContractQuery: ValidateChecksums {
107111
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
108112

109113
/// Send the request.
110-
let (data, response) = try await URLSession.shared.data(for: request)
114+
#if canImport(FoundationNetworking)
115+
// Linux: Use callback-based API wrapped in continuation
116+
let (data, response): (Data, URLResponse) = try await withCheckedThrowingContinuation { continuation in
117+
URLSession.shared.dataTask(with: request) { data, response, error in
118+
if let error = error {
119+
continuation.resume(throwing: error)
120+
return
121+
}
122+
guard let data = data, let response = response else {
123+
continuation.resume(throwing: URLError(.badServerResponse))
124+
return
125+
}
126+
continuation.resume(returning: (data, response))
127+
}.resume()
128+
}
129+
#else
130+
// macOS/iOS: Use modern async/await API
131+
let (data, response) = try await URLSession.shared.data(for: request)
132+
#endif
111133

112134
/// Make sure a good response was returned.
113135
guard let httpResponse = response as? HTTPURLResponse,

Sources/Hiero/Crypto/Crypto+k256Digest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
import secp256k1
44

5-
extension Crypto {
5+
extension CryptoNamespace {
66
internal typealias SecpDigest = Digest
77
}

Sources/Hiero/Crypto/Crypto.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
// used as a namespace
4-
internal enum Crypto {}
3+
// MARK: - Crypto Namespace
4+
//
5+
// This file defines the `CryptoNamespace` enum, which serves as a namespace
6+
// for organizing cryptographic functionality used throughout the Hiero SDK.
7+
//
8+
// The namespace pattern avoids polluting the global namespace with generic names
9+
// like "Aes" or "Hmac", and provides a clear organizational structure for
10+
// crypto-related code.
11+
//
12+
// Extensions in other files add functionality to this namespace:
13+
// - CryptoAes.swift: AES encryption/decryption
14+
// - CryptoSha2.swift: SHA-256, SHA-384, SHA-512
15+
// - CryptoSha3.swift: Keccak-256
16+
// - Crypto+k256Digest.swift: secp256k1 digest types
517

6-
extension Crypto {
18+
/// Namespace for cryptographic primitives used by the Hiero SDK.
19+
///
20+
/// This enum is never instantiated - it exists solely as a namespace to
21+
/// organize cryptographic functionality.
22+
internal enum CryptoNamespace {}
23+
24+
// MARK: - HMAC Algorithm Selection
25+
26+
extension CryptoNamespace {
27+
/// HMAC (Hash-based Message Authentication Code) algorithm variants.
28+
///
29+
/// Specifies which hash function to use with HMAC for key derivation
30+
/// and message authentication.
731
internal enum Hmac {
8-
// case sha1
9-
case sha2(Crypto.Sha2)
32+
/// HMAC using a SHA-2 family hash function.
33+
case sha2(CryptoNamespace.Sha2)
1034
}
1135
}

0 commit comments

Comments
 (0)