diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 65f78f6..e6901d4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,20 +16,16 @@ on: workflow_dispatch: # Checkout the code, and run mxcl's xcodebuild action to run the unit tests + jobs: - build: - runs-on: macOS-latest - strategy: - matrix: - platform: - - iOS + test: + runs-on: macos-latest steps: - - uses: actions/checkout@v2.3.4 - - uses: mxcl/xcodebuild@v1 + - name: checkout + uses: actions/checkout@v3 + - name: xcode + uses: maxim-lobanov/setup-xcode@v1 with: - platform: ${{ matrix.platform }} - action: test - scheme: SingleFactorAuth - code-coverage: true - upload-logs: always - + xcode-version: latest-stable + - name: package + run: xcodebuild test -scheme SingleFactorAuth -destination "platform=iOS Simulator,OS=16.2,name=iPhone 14" COMPILER_INDEX_STORE_ENABLE=NO diff --git a/Package.resolved b/Package.resolved index 1fe50ca..a6ceeca 100644 --- a/Package.resolved +++ b/Package.resolved @@ -23,26 +23,26 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", "state" : { - "revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e", - "version" : "1.8.0" + "revision" : "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c", + "version" : "1.8.1" } }, { - "identity" : "fetch-node-details-swift", + "identity" : "curvelib.swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/torusresearch/fetch-node-details-swift.git", + "location" : "https://github.com/tkey/curvelib.swift", "state" : { - "revision" : "d591af500f32ce3c88d04af9bb74d746585acfea", - "version" : "5.1.0" + "revision" : "7dad3bf1793de263f83406c08c18c9316abf082f", + "version" : "0.1.2" } }, { - "identity" : "generic-json-swift", + "identity" : "fetch-node-details-swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/iwill/generic-json-swift", + "location" : "https://github.com/torusresearch/fetch-node-details-swift.git", "state" : { - "revision" : "0a06575f4038b504e78ac330913d920f1630f510", - "version" : "2.0.2" + "revision" : "d591af500f32ce3c88d04af9bb74d746585acfea", + "version" : "5.1.0" } }, { @@ -50,8 +50,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/jwt-kit.git", "state" : { - "revision" : "ef12bdfa557cd9d9f0c53396e0a9908f773bcd7b", - "version" : "4.9.0" + "revision" : "e05513b5aec24f88012b6e3034115b6bc915356a", + "version" : "4.13.2" } }, { @@ -63,40 +63,13 @@ "version" : "20.0.0" } }, - { - "identity" : "secp256k1.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/GigaBitcoin/secp256k1.swift", - "state" : { - "revision" : "1a14e189def5eaa92f839afdd2faad8e43b61a6e", - "version" : "0.12.2" - } - }, { "identity" : "session-manager-swift", "kind" : "remoteSourceControl", "location" : "https://github.com/Web3Auth/session-manager-swift.git", "state" : { - "revision" : "f4e6f24dfe0bac88eb9a7aeda1cd73caad69a9ce", - "version" : "3.0.1" - } - }, - { - "identity" : "swift-atomics", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-atomics.git", - "state" : { - "revision" : "cd142fd2f64be2100422d658e7411e39489da985", - "version" : "1.2.0" - } - }, - { - "identity" : "swift-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-collections.git", - "state" : { - "revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307", - "version" : "1.0.5" + "revision" : "290e36cd0646f7fb3be737b65bdfc9f5428dfd5c", + "version" : "3.1.0" } }, { @@ -104,71 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-crypto.git", "state" : { - "revision" : "6d9c36b4beda0dae88feab6dc36206434bae713c", - "version" : "2.4.1" - } - }, - { - "identity" : "swift-http-types", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-http-types", - "state" : { - "revision" : "99d066e29effa8845e4761dd3f2f831edfdf8925", - "version" : "1.0.0" - } - }, - { - "identity" : "swift-log", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", - "state" : { - "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", - "version" : "1.5.3" - } - }, - { - "identity" : "swift-nio", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio.git", - "state" : { - "revision" : "853522d90871b4b63262843196685795b5008c46", - "version" : "2.61.1" - } - }, - { - "identity" : "swift-nio-extras", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-extras.git", - "state" : { - "revision" : "798c962495593a23fdea0c0c63fd55571d8dff51", - "version" : "1.20.0" - } - }, - { - "identity" : "swift-nio-http2", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-http2.git", - "state" : { - "revision" : "3bd9004b9d685ed6b629760fc84903e48efec806", - "version" : "1.29.0" - } - }, - { - "identity" : "swift-nio-ssl", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-ssl.git", - "state" : { - "revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9", - "version" : "2.25.0" - } - }, - { - "identity" : "swift-nio-transport-services", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-transport-services.git", - "state" : { - "revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e", - "version" : "1.20.0" + "revision" : "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb", + "version" : "3.3.0" } }, { @@ -176,26 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift", "state" : { - "revision" : "b7e4eff3bf1a135cd408f6679952ae7b476ba833", - "version" : "6.1.0" - } - }, - { - "identity" : "web3.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/argentlabs/web3.swift", - "state" : { - "revision" : "8ca33e700ed8de6137a0e1471017aa3b3c8de0db", - "version" : "1.6.0" - } - }, - { - "identity" : "websocket-kit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/vapor/websocket-kit.git", - "state" : { - "revision" : "53fe0639a98903858d0196b699720decb42aee7b", - "version" : "2.14.0" + "revision" : "04c62fd5f73f21bd01b7c07e08f6135db26c5940", + "version" : "8.0.0" } } ], diff --git a/Package.swift b/Package.swift index 2dfcefb..2a50e46 100644 --- a/Package.swift +++ b/Package.swift @@ -16,9 +16,9 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/torusresearch/fetch-node-details-swift.git", from: "5.1.0"), - .package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "6.1.0"), + .package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "8.0.0"), .package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"), - .package(url: "https://github.com/Web3Auth/session-manager-swift.git", from: "3.0.1") + .package(url: "https://github.com/Web3Auth/session-manager-swift.git", from: "3.1.0") ], targets: [ .target( diff --git a/Sources/SingleFactorAuth/SingleFactorAuth.swift b/Sources/SingleFactorAuth/SingleFactorAuth.swift index 595ae75..0d784c6 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuth.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuth.swift @@ -18,7 +18,8 @@ public class SingleFactorAuth { enableOneKey: true, signerHost: singleFactorAuthArgs.getSignerUrl()! + "/api/sign", allowHost: singleFactorAuthArgs.getSignerUrl()! + "/api/allow", - network: singleFactorAuthArgs.getNetwork() + network: singleFactorAuthArgs.getNetwork(), + clientId: singleFactorAuthArgs.getWeb3AuthClientId() ) } @@ -29,7 +30,7 @@ public class SingleFactorAuth { return .init(privateKey: privKey, publicAddress: publicAddress) } - public func getKey(loginParams: LoginParams) async throws -> TorusSFAKey { + public func getTorusKey(loginParams: LoginParams) async throws -> TorusKey { var retrieveSharesResponse: TorusKey let details = try await nodeDetailManager.getNodeDetails(verifier: loginParams.verifier, verifierID: loginParams.verifierId) @@ -63,8 +64,8 @@ public class SingleFactorAuth { ] as [String: Codable] let verifierParams = VerifierParams(verifier_id: loginParams.verifierId) - - let aggregateIdToken = String(String(bytes: aggregateIdTokenSeeds.joined(separator: "\u{001d}").bytes.sha3(.keccak256)).dropFirst(2)) // drop 0x + + let aggregateIdToken = aggregateIdTokenSeeds.joined(separator: "\u{001d}").bytes.sha3(.keccak256).toHexString() // drop 0x retrieveSharesResponse = try await torusUtils.retrieveShares( endpoints: details.getTorusNodeEndpoints(), @@ -88,11 +89,17 @@ public class SingleFactorAuth { ) } - let publicAddress = (retrieveSharesResponse.finalKeyData?.X ?? "") + (retrieveSharesResponse.finalKeyData?.Y ?? "") - let privateKey = retrieveSharesResponse.finalKeyData?.privKey ?? "" - - let torusKey = TorusSFAKey(privateKey: privateKey, publicAddress: publicAddress) - _ = try await sessionManager.createSession(data: torusKey) - return torusKey + return retrieveSharesResponse + } + + public func getKey(loginParams: LoginParams) async throws -> TorusSFAKey { + let torusKey = try await self.getTorusKey(loginParams: loginParams) + + let publicAddress = (torusKey.finalKeyData?.X ?? "") + (torusKey.finalKeyData?.Y ?? "") + let privateKey = torusKey.finalKeyData?.privKey ?? "" + + let torusSfaKey = TorusSFAKey(privateKey: privateKey, publicAddress: publicAddress) + _ = try await sessionManager.createSession(data: torusSfaKey) + return torusSfaKey } } diff --git a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift index f40cc26..2c787ca 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuthArgs.swift @@ -14,10 +14,16 @@ public class SingleFactorAuthArgs { private var network: TorusNetwork private var networkUrl: String + private var web3AuthClientId: String - public init(network: TorusNetwork, networkUrl: String = "") { + public init(web3AuthClientId: String, network: TorusNetwork, networkUrl: String = "") { self.network = network self.networkUrl = networkUrl + self.web3AuthClientId = web3AuthClientId + } + + public func getWeb3AuthClientId() -> String { + return web3AuthClientId } public func getNetwork() -> TorusNetwork { diff --git a/Tests/SingleFactorAuthTests/AquaTest.swift b/Tests/SingleFactorAuthTests/AquaTest.swift index 0ae26f3..bf597ae 100644 --- a/Tests/SingleFactorAuthTests/AquaTest.swift +++ b/Tests/SingleFactorAuthTests/AquaTest.swift @@ -14,7 +14,7 @@ final class AquaTest: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.legacy(.AQUA)) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.AQUA)) singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } diff --git a/Tests/SingleFactorAuthTests/CyanTest.swift b/Tests/SingleFactorAuthTests/CyanTest.swift index c7636de..138b499 100644 --- a/Tests/SingleFactorAuthTests/CyanTest.swift +++ b/Tests/SingleFactorAuthTests/CyanTest.swift @@ -14,7 +14,7 @@ final class CyanTest: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.legacy(.CYAN)) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.CYAN)) singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } diff --git a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift index 80d3ceb..ec9f955 100644 --- a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift +++ b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift @@ -14,7 +14,7 @@ final class SingleFactorAuthTests: XCTestCase { let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" override func setUp() { - singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.legacy(.TESTNET)) + singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.TESTNET)) singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) }