From 59122b76052fccab44e013a12ba19504ae0910ea Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 14:45:41 +0800 Subject: [PATCH 1/6] feat: make multiple products --- Package.swift | 8 ++++---- Tests/curvelibTests/curvelibErrorTests.swift | 2 +- Tests/curvelibTests/curvelibTests.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 26a613b..ce13cb7 100644 --- a/Package.swift +++ b/Package.swift @@ -11,8 +11,8 @@ let package = Package( products: [ // Products define the executables and libraries a package produces, making them visible to other packages. .library( - name: "curvelib.swift", - targets: ["curvelib.swift"]), + name: "secp256k1.swift", + targets: ["secp256k1.swift"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -30,12 +30,12 @@ let package = Package( // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. .target( - name: "curvelib.swift", + name: "secp256k1.swift", dependencies: ["curvelib"], path: "Sources/curvelib" ), .testTarget( name: "curvelibTests", - dependencies: ["curvelib.swift"]), + dependencies: ["secp256k1.swift"]), ] ) diff --git a/Tests/curvelibTests/curvelibErrorTests.swift b/Tests/curvelibTests/curvelibErrorTests.swift index 4ded360..57051cc 100644 --- a/Tests/curvelibTests/curvelibErrorTests.swift +++ b/Tests/curvelibTests/curvelibErrorTests.swift @@ -1,5 +1,5 @@ import XCTest -@testable import curvelib_swift +@testable import secp256k1_swift final class curvelibErrorTests: XCTestCase { func testCurveError() { diff --git a/Tests/curvelibTests/curvelibTests.swift b/Tests/curvelibTests/curvelibTests.swift index bf55b7d..08a9186 100644 --- a/Tests/curvelibTests/curvelibTests.swift +++ b/Tests/curvelibTests/curvelibTests.swift @@ -1,5 +1,5 @@ import XCTest -import curvelib_swift +import secp256k1_swift final class curvelibTests: XCTestCase { func testSecretKey() throws { From 783fece367eb9e2942052dc2b82ae8cb84f8d5f6 Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 15:22:59 +0800 Subject: [PATCH 2/6] feat: make encryption separate product --- Package.swift | 14 ++++++++++++-- .../EncryptedMessage.swift | 1 + .../{secp256k1 => encryption}/Encryption.swift | 1 + Sources/curvelib/secp256k1/CurveError.swift | 4 ++-- Sources/curvelib/secp256k1/PublicKey.swift | 4 ++-- Sources/curvelib/secp256k1/SecretKey.swift | 2 +- Tests/curvelibTests/curvelibTests.swift | 1 + 7 files changed, 20 insertions(+), 7 deletions(-) rename Sources/curvelib/{secp256k1 => encryption}/EncryptedMessage.swift (99%) rename Sources/curvelib/{secp256k1 => encryption}/Encryption.swift (98%) diff --git a/Package.swift b/Package.swift index ce13cb7..0597395 100644 --- a/Package.swift +++ b/Package.swift @@ -13,6 +13,10 @@ let package = Package( .library( name: "secp256k1.swift", targets: ["secp256k1.swift"]), + + .library( + name: "encryption_aes_cbc_sha512.swift", + targets: ["encryption_aes_cbc_sha512.swift"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -32,10 +36,16 @@ let package = Package( .target( name: "secp256k1.swift", dependencies: ["curvelib"], - path: "Sources/curvelib" + path: "Sources/curvelib/secp256k1" ), + .target( + name: "encryption_aes_cbc_sha512.swift", + dependencies: ["curvelib", "secp256k1.swift"], + path: "Sources/curvelib/encryption" + ), + .testTarget( name: "curvelibTests", - dependencies: ["secp256k1.swift"]), + dependencies: ["secp256k1.swift", "encryption_aes_cbc_sha512.swift"]), ] ) diff --git a/Sources/curvelib/secp256k1/EncryptedMessage.swift b/Sources/curvelib/encryption/EncryptedMessage.swift similarity index 99% rename from Sources/curvelib/secp256k1/EncryptedMessage.swift rename to Sources/curvelib/encryption/EncryptedMessage.swift index 56db35f..0c23f1f 100644 --- a/Sources/curvelib/secp256k1/EncryptedMessage.swift +++ b/Sources/curvelib/encryption/EncryptedMessage.swift @@ -3,6 +3,7 @@ import Foundation #if canImport(curvelib) import curvelib #endif +import secp256k1_swift public final class EncryptedMessage { private(set) var pointer: OpaquePointer? diff --git a/Sources/curvelib/secp256k1/Encryption.swift b/Sources/curvelib/encryption/Encryption.swift similarity index 98% rename from Sources/curvelib/secp256k1/Encryption.swift rename to Sources/curvelib/encryption/Encryption.swift index 24b0367..d974beb 100644 --- a/Sources/curvelib/secp256k1/Encryption.swift +++ b/Sources/curvelib/encryption/Encryption.swift @@ -3,6 +3,7 @@ import Foundation #if canImport(curvelib) import curvelib #endif +import secp256k1_swift public final class Encryption { public static func encrypt(pk: PublicKey, plainText: String) throws -> EncryptedMessage { diff --git a/Sources/curvelib/secp256k1/CurveError.swift b/Sources/curvelib/secp256k1/CurveError.swift index 2adea06..145536c 100644 --- a/Sources/curvelib/secp256k1/CurveError.swift +++ b/Sources/curvelib/secp256k1/CurveError.swift @@ -1,7 +1,7 @@ import Foundation public struct CurveError: Error, LocalizedError { - enum ErrorType { + public enum ErrorType { case null case convert case parse @@ -17,7 +17,7 @@ public struct CurveError: Error, LocalizedError { private(set) var type: ErrorType - init(code: Int32) { + public init(code: Int32) { switch code { case 1: type = .null case 2: type = .convert diff --git a/Sources/curvelib/secp256k1/PublicKey.swift b/Sources/curvelib/secp256k1/PublicKey.swift index 68c6da6..7ba0e2b 100644 --- a/Sources/curvelib/secp256k1/PublicKey.swift +++ b/Sources/curvelib/secp256k1/PublicKey.swift @@ -5,9 +5,9 @@ import Foundation #endif public final class PublicKey { - private(set) var pointer: OpaquePointer? + private(set) public var pointer: OpaquePointer? - internal init(ptr: OpaquePointer) { + public init(ptr: OpaquePointer) { pointer = ptr } diff --git a/Sources/curvelib/secp256k1/SecretKey.swift b/Sources/curvelib/secp256k1/SecretKey.swift index f3222d0..251e694 100644 --- a/Sources/curvelib/secp256k1/SecretKey.swift +++ b/Sources/curvelib/secp256k1/SecretKey.swift @@ -5,7 +5,7 @@ import Foundation #endif public final class SecretKey { - private(set) var pointer: OpaquePointer? + private(set) public var pointer: OpaquePointer? public init() { pointer = curve_secp256k1_private_key_generate() diff --git a/Tests/curvelibTests/curvelibTests.swift b/Tests/curvelibTests/curvelibTests.swift index 08a9186..3372f54 100644 --- a/Tests/curvelibTests/curvelibTests.swift +++ b/Tests/curvelibTests/curvelibTests.swift @@ -1,5 +1,6 @@ import XCTest import secp256k1_swift +import encryption_aes_cbc_sha512_swift final class curvelibTests: XCTestCase { func testSecretKey() throws { From 068e36f52223c66f6b13ef57ce2326570470c4e0 Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 15:47:23 +0800 Subject: [PATCH 3/6] fix: update name --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 0597395..d2cd6bf 100644 --- a/Package.swift +++ b/Package.swift @@ -11,11 +11,11 @@ let package = Package( products: [ // Products define the executables and libraries a package produces, making them visible to other packages. .library( - name: "secp256k1.swift", + name: "curveSecp256k1", targets: ["secp256k1.swift"]), .library( - name: "encryption_aes_cbc_sha512.swift", + name: "encryption_aes_cbc_sha512", targets: ["encryption_aes_cbc_sha512.swift"]), ], dependencies: [ From 5a9bc3015851575d07e25d62c4d32f46825860f8 Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 15:56:41 +0800 Subject: [PATCH 4/6] fix: rename product and target name --- Package.swift | 12 ++++++------ Sources/curvelib/encryption/EncryptedMessage.swift | 2 +- Sources/curvelib/encryption/Encryption.swift | 2 +- Tests/curvelibTests/curvelibErrorTests.swift | 2 +- Tests/curvelibTests/curvelibTests.swift | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Package.swift b/Package.swift index d2cd6bf..5db3842 100644 --- a/Package.swift +++ b/Package.swift @@ -12,11 +12,11 @@ let package = Package( // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "curveSecp256k1", - targets: ["secp256k1.swift"]), + targets: ["curveSecp256k1"]), .library( name: "encryption_aes_cbc_sha512", - targets: ["encryption_aes_cbc_sha512.swift"]), + targets: ["encryption_aes_cbc_sha512"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -34,18 +34,18 @@ let package = Package( // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. .target( - name: "secp256k1.swift", + name: "curveSecp256k1", dependencies: ["curvelib"], path: "Sources/curvelib/secp256k1" ), .target( - name: "encryption_aes_cbc_sha512.swift", - dependencies: ["curvelib", "secp256k1.swift"], + name: "encryption_aes_cbc_sha512", + dependencies: ["curvelib", "curveSecp256k1"], path: "Sources/curvelib/encryption" ), .testTarget( name: "curvelibTests", - dependencies: ["secp256k1.swift", "encryption_aes_cbc_sha512.swift"]), + dependencies: ["curveSecp256k1", "encryption_aes_cbc_sha512"]), ] ) diff --git a/Sources/curvelib/encryption/EncryptedMessage.swift b/Sources/curvelib/encryption/EncryptedMessage.swift index 0c23f1f..f98065a 100644 --- a/Sources/curvelib/encryption/EncryptedMessage.swift +++ b/Sources/curvelib/encryption/EncryptedMessage.swift @@ -3,7 +3,7 @@ import Foundation #if canImport(curvelib) import curvelib #endif -import secp256k1_swift +import curveSecp256k1 public final class EncryptedMessage { private(set) var pointer: OpaquePointer? diff --git a/Sources/curvelib/encryption/Encryption.swift b/Sources/curvelib/encryption/Encryption.swift index d974beb..fbceb42 100644 --- a/Sources/curvelib/encryption/Encryption.swift +++ b/Sources/curvelib/encryption/Encryption.swift @@ -3,7 +3,7 @@ import Foundation #if canImport(curvelib) import curvelib #endif -import secp256k1_swift +import curveSecp256k1 public final class Encryption { public static func encrypt(pk: PublicKey, plainText: String) throws -> EncryptedMessage { diff --git a/Tests/curvelibTests/curvelibErrorTests.swift b/Tests/curvelibTests/curvelibErrorTests.swift index 57051cc..a65af8c 100644 --- a/Tests/curvelibTests/curvelibErrorTests.swift +++ b/Tests/curvelibTests/curvelibErrorTests.swift @@ -1,5 +1,5 @@ import XCTest -@testable import secp256k1_swift +@testable import curveSecp256k1 final class curvelibErrorTests: XCTestCase { func testCurveError() { diff --git a/Tests/curvelibTests/curvelibTests.swift b/Tests/curvelibTests/curvelibTests.swift index 3372f54..1857c74 100644 --- a/Tests/curvelibTests/curvelibTests.swift +++ b/Tests/curvelibTests/curvelibTests.swift @@ -1,6 +1,6 @@ import XCTest -import secp256k1_swift -import encryption_aes_cbc_sha512_swift +import curveSecp256k1 +import encryption_aes_cbc_sha512 final class curvelibTests: XCTestCase { func testSecretKey() throws { From 7d4a27bc16b171c77c18cb1f143292b94a8027b4 Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 16:04:26 +0800 Subject: [PATCH 5/6] fix: ci --- .github/workflows/ci.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2fab322..ed519fa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,6 +21,13 @@ jobs: with: platform: ${{ matrix.platform }} action: test - scheme: curvelib.swift + scheme: curveSecp256k1 + code-coverage: true + upload-logs: always + - uses: mxcl/xcodebuild@v1 + with: + platform: ${{ matrix.platform }} + action: test + scheme: encryption_aes_cbc_sha512 code-coverage: true upload-logs: always From 20cdc9837be888c1772d7575cd811bbe9d98d12d Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 23 Jan 2024 16:14:42 +0800 Subject: [PATCH 6/6] fix: add scheme fix ci --- .github/workflows/ci.yaml | 9 +- .../xcschemes/curveSecp256k1.xcscheme | 66 +++++++++++ .../xcschemes/curvelib.swift-Package.xcscheme | 106 ++++++++++++++++++ .../encryption_aes_cbc_sha512.xcscheme | 66 +++++++++++ Tests/curvelibTests/curvelibTests.swift | 4 +- 5 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/curveSecp256k1.xcscheme create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/curvelib.swift-Package.xcscheme create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/encryption_aes_cbc_sha512.xcscheme diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ed519fa..39a3f5a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,13 +21,6 @@ jobs: with: platform: ${{ matrix.platform }} action: test - scheme: curveSecp256k1 - code-coverage: true - upload-logs: always - - uses: mxcl/xcodebuild@v1 - with: - platform: ${{ matrix.platform }} - action: test - scheme: encryption_aes_cbc_sha512 + scheme: curvelib.swift-Package code-coverage: true upload-logs: always diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/curveSecp256k1.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/curveSecp256k1.xcscheme new file mode 100644 index 0000000..dce03d7 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/curveSecp256k1.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/curvelib.swift-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/curvelib.swift-Package.xcscheme new file mode 100644 index 0000000..865b394 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/curvelib.swift-Package.xcscheme @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/encryption_aes_cbc_sha512.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/encryption_aes_cbc_sha512.xcscheme new file mode 100644 index 0000000..8bdb642 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/encryption_aes_cbc_sha512.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/curvelibTests/curvelibTests.swift b/Tests/curvelibTests/curvelibTests.swift index 1857c74..5b91282 100644 --- a/Tests/curvelibTests/curvelibTests.swift +++ b/Tests/curvelibTests/curvelibTests.swift @@ -1,6 +1,6 @@ import XCTest -import curveSecp256k1 -import encryption_aes_cbc_sha512 +@testable import curveSecp256k1 +@testable import encryption_aes_cbc_sha512 final class curvelibTests: XCTestCase { func testSecretKey() throws {