From 30505b8b33c67827267fbcf72db0eafc542c48c2 Mon Sep 17 00:00:00 2001 From: Chaitanya Potti Date: Mon, 22 Apr 2024 14:06:51 +0800 Subject: [PATCH] mid commit gating error --- Package.resolved | 4 ++-- Package.swift | 2 +- Sources/TorusUtils/Helpers/Error.swift | 3 +++ Sources/TorusUtils/TorusUtils.swift | 15 ++++++--------- Tests/TorusUtilsTests/AquaTest.swift | 4 +--- Tests/TorusUtilsTests/CyanTest.swift | 4 +--- Tests/TorusUtilsTests/IntegrationTest.swift | 2 -- Tests/TorusUtilsTests/SapphireTest.swift | 5 +---- Tests/TorusUtilsTests/TestnetTest.swift | 4 +--- Torus-utils.podspec | 2 +- 10 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Package.resolved b/Package.resolved index 5987e702..0bf696a3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/fetch-node-details-swift.git", "state" : { - "revision" : "6d9b100321cbca8abf70d378236d4e3c45e3f2cb", - "version" : "6.0.0" + "revision" : "f085d3d85a4f36b57cfef8f0871ac8df1dd4f6f1", + "version" : "6.0.1" } }, { diff --git a/Package.swift b/Package.swift index f373520b..57771d76 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/tkey/curvelib.swift", from: "1.0.1"), - .package(url: "https://github.com/torusresearch/fetch-node-details-swift", from: "6.0.0"), + .package(url: "https://github.com/torusresearch/fetch-node-details-swift", from: "6.0.1"), .package(url: "https://github.com/vapor/jwt-kit", from: "4.0.0"), .package( url: "https://github.com/Flight-School/AnyCodable", diff --git a/Sources/TorusUtils/Helpers/Error.swift b/Sources/TorusUtils/Helpers/Error.swift index 3ffce30c..f0615e79 100644 --- a/Sources/TorusUtils/Helpers/Error.swift +++ b/Sources/TorusUtils/Helpers/Error.swift @@ -21,6 +21,7 @@ public enum TorusUtilError: Error, Equatable { case runtime(_ msg: String) case retrieveOrImportShareError case metadataNonceMissing + case gatingError(_ msg: String? = nil) case empty } @@ -69,6 +70,8 @@ extension TorusUtilError: CustomDebugStringConvertible { return "retrieve or import share failed" case .metadataNonceMissing: return "Unable to fetch metadata nonce" + case let .gatingError(msg): + return "could not process request \(msg ?? "")" } } diff --git a/Sources/TorusUtils/TorusUtils.swift b/Sources/TorusUtils/TorusUtils.swift index 03c5f5c6..b431e2d7 100644 --- a/Sources/TorusUtils/TorusUtils.swift +++ b/Sources/TorusUtils/TorusUtils.swift @@ -25,17 +25,15 @@ open class TorusUtils: AbstractTorusUtils { urlSession: URLSession = URLSession(configuration: .default), enableOneKey: Bool = false, serverTimeOffset: TimeInterval = 0, - signerHost: String = "https://signer.tor.us/api/sign", - allowHost: String = "https://signer.tor.us/api/allow", - network: TorusNetwork = TorusNetwork.legacy(.MAINNET), + network: TorusNetwork, clientId: String, legacyMetadataHost: String = "https://metadata.tor.us" ) { self.urlSession = urlSession utilsLogType = loglevel self.enableOneKey = enableOneKey - self.signerHost = signerHost // TODO: remove signer host read it from fetch node details same as web sdk. - self.allowHost = allowHost + self.allowHost = network.signerMap + "/api/allow" + self.signerHost = network.signerMap + "/api/sign" self.network = network self.serverTimeOffset = serverTimeOffset self.clientId = clientId @@ -66,8 +64,7 @@ open class TorusUtils: AbstractTorusUtils { allowHostRequest.addValue("torus-default", forHTTPHeaderField: "x-api-key") allowHostRequest.addValue(verifier, forHTTPHeaderField: "origin") allowHostRequest.addValue(verifier, forHTTPHeaderField: "verifier") - allowHostRequest.addValue(verifierParams.verifier_id, forHTTPHeaderField: "verifier_id") - allowHostRequest.addValue(verifierParams.verifier_id, forHTTPHeaderField: "verifierId") + allowHostRequest.addValue(verifierParams.verifier_id, forHTTPHeaderField: "verifierid") allowHostRequest.addValue(clientId, forHTTPHeaderField: "clientid") allowHostRequest.addValue(network.name, forHTTPHeaderField: "network") allowHostRequest.addValue("true", forHTTPHeaderField: "enablegating") @@ -75,8 +72,8 @@ open class TorusUtils: AbstractTorusUtils { let result = try await session.data(for: allowHostRequest) let responseData = try JSONDecoder().decode(AllowSuccess.self, from: result.0) if (responseData.success == false ) { - let _ = try JSONDecoder().decode(AllowRejected.self, from: result.0) - // throw "code: \(errorData.code), error: \(errorData.error)" + let errorData = try JSONDecoder().decode(AllowRejected.self, from: result.0) + throw TorusUtilError.gatingError("code: \(errorData.code), error: \(errorData.error)") } } catch { os_log("retrieveShares: signer allow: %@", log: getTorusLogger(log: TorusUtilsLogger.core, type: .error), type: .error, error.localizedDescription) diff --git a/Tests/TorusUtilsTests/AquaTest.swift b/Tests/TorusUtilsTests/AquaTest.swift index bd61e8ff..90ec485f 100644 --- a/Tests/TorusUtilsTests/AquaTest.swift +++ b/Tests/TorusUtilsTests/AquaTest.swift @@ -12,8 +12,6 @@ class AquaTest: XCTestCase { var TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate" var fnd: NodeDetailManager! var tu: TorusUtils! - var signerHost = "https://signer-polygon.tor.us/api/sign" - var allowHost = "https://signer-polygon.tor.us/api/allow" override func setUp() { super.setUp() @@ -22,7 +20,7 @@ class AquaTest: XCTestCase { func getFNDAndTUData(verifer: String, veriferID: String, enableOneKey: Bool = false) async throws -> AllNodeDetailsModel { let nodeDetails = try await fnd.getNodeDetails(verifier: verifer, verifierID: veriferID) - tu = TorusUtils(enableOneKey: enableOneKey, signerHost: signerHost, allowHost: allowHost, network: .legacy(.AQUA), clientId: "YOUR_CLIENT_ID") + tu = TorusUtils(enableOneKey: enableOneKey, network: .legacy(.AQUA), clientId: "YOUR_CLIENT_ID") return nodeDetails } diff --git a/Tests/TorusUtilsTests/CyanTest.swift b/Tests/TorusUtilsTests/CyanTest.swift index 0c90aae4..f1b9982b 100644 --- a/Tests/TorusUtilsTests/CyanTest.swift +++ b/Tests/TorusUtilsTests/CyanTest.swift @@ -12,8 +12,6 @@ class CyanTest: XCTestCase { var TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate" var fnd: NodeDetailManager! var tu: TorusUtils! - var signerHost = "https://signer-polygon.tor.us/api/sign" - var allowHost = "https://signer-polygon.tor.us/api/allow" override func setUp() { super.setUp() @@ -22,7 +20,7 @@ class CyanTest: XCTestCase { func getFNDAndTUData(verifer: String, veriferID: String, enableOneKey: Bool = false) async throws -> AllNodeDetailsModel { let nodeDetails = try await fnd.getNodeDetails(verifier: verifer, verifierID: veriferID) - tu = TorusUtils(enableOneKey: enableOneKey, signerHost: signerHost, allowHost: allowHost, network: .legacy(.CYAN), clientId: "YOUR_CLIENT_ID") + tu = TorusUtils(enableOneKey: enableOneKey, network: .legacy(.CYAN), clientId: "YOUR_CLIENT_ID") return nodeDetails } diff --git a/Tests/TorusUtilsTests/IntegrationTest.swift b/Tests/TorusUtilsTests/IntegrationTest.swift index d8ed3f3e..8617d165 100644 --- a/Tests/TorusUtilsTests/IntegrationTest.swift +++ b/Tests/TorusUtilsTests/IntegrationTest.swift @@ -16,8 +16,6 @@ class IntegrationTests: XCTestCase { let TORUS_TEST_VERIFIER = "torus-test-health" let TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate" let TORUS_TEST_EMAIL = "hello@tor.us" - var signerHost = "https://signer.tor.us/api/sign" - var allowHost = "https://signer.tor.us/api/allow" // Fake data let TORUS_TEST_VERIFIER_FAKE = "google-lrc-fakes" diff --git a/Tests/TorusUtilsTests/SapphireTest.swift b/Tests/TorusUtilsTests/SapphireTest.swift index 2095b628..fa8de2e3 100644 --- a/Tests/TorusUtilsTests/SapphireTest.swift +++ b/Tests/TorusUtilsTests/SapphireTest.swift @@ -22,9 +22,6 @@ final class SapphireTest: XCTestCase { let TORUS_EXTENDED_VERIFIER_EMAIL = "testextenderverifierid@example.com" let HashEnabledVerifier = "torus-test-verifierid-hash" - var signerHost = "https://signer.tor.us/api/sign" - var allowHost = "https://signer.tor.us/api/allow" - var fnd: NodeDetailManager! var torus: TorusUtils! @@ -349,7 +346,7 @@ final class SapphireTest: XCTestCase { ) XCTAssert(false, "Should not pass") }catch { - if (!error.localizedDescription.contains("code: 1001")) { + if (error != gatingError("code: 1001, error: Invalid client id")) { XCTAssert(false, "Should fail with signer allow gating error") } } diff --git a/Tests/TorusUtilsTests/TestnetTest.swift b/Tests/TorusUtilsTests/TestnetTest.swift index 4d03ddbf..003b5a88 100644 --- a/Tests/TorusUtilsTests/TestnetTest.swift +++ b/Tests/TorusUtilsTests/TestnetTest.swift @@ -12,8 +12,6 @@ class TestnetTest: XCTestCase { var TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate" var fnd: NodeDetailManager! var tu: TorusUtils! - var signerHost = "https://signer-polygon.tor.us/api/sign" - var allowHost = "https://signer-polygon.tor.us/api/allow" override func setUp() { super.setUp() @@ -22,7 +20,7 @@ class TestnetTest: XCTestCase { func getFNDAndTUData(verifer: String, veriferID: String, enableOneKey: Bool = false) async throws -> AllNodeDetailsModel { let nodeDetails = try await fnd.getNodeDetails(verifier: verifer, verifierID: veriferID) - tu = TorusUtils(enableOneKey: enableOneKey, signerHost: signerHost, allowHost: allowHost, network: .legacy(.TESTNET), clientId: "YOUR_CLIENT_ID") + tu = TorusUtils(enableOneKey: enableOneKey, network: .legacy(.TESTNET), clientId: "YOUR_CLIENT_ID") return nodeDetails } diff --git a/Torus-utils.podspec b/Torus-utils.podspec index 3383a42b..36583bf6 100644 --- a/Torus-utils.podspec +++ b/Torus-utils.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| spec.module_name = "TorusUtils" spec.source = { :git => "https://github.com/torusresearch/torus-utils-swift.git", :tag => spec.version } spec.source_files = "Sources/TorusUtils/*.{swift,json}","Sources/TorusUtils/**/*.{swift,json}" - spec.dependency 'Torus-fetchNodeDetails', '~> 6.0.0' + spec.dependency 'Torus-fetchNodeDetails', '~> 6.0.1' spec.dependency 'curvelib.swift', '~> 1.0.1' spec.dependency 'AnyCodable-FlightSchool', '~> 0.6.0' end