Skip to content

Commit

Permalink
mid commit gating error
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Apr 22, 2024
1 parent dd51e56 commit 30505b8
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions Sources/TorusUtils/Helpers/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum TorusUtilError: Error, Equatable {
case runtime(_ msg: String)
case retrieveOrImportShareError
case metadataNonceMissing
case gatingError(_ msg: String? = nil)
case empty
}

Expand Down Expand Up @@ -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 ?? "")"
}
}

Expand Down
15 changes: 6 additions & 9 deletions Sources/TorusUtils/TorusUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,17 +64,16 @@ 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")
do {
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)
Expand Down
4 changes: 1 addition & 3 deletions Tests/TorusUtilsTests/AquaTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

Expand Down
4 changes: 1 addition & 3 deletions Tests/TorusUtilsTests/CyanTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions Tests/TorusUtilsTests/IntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
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"
Expand Down
5 changes: 1 addition & 4 deletions Tests/TorusUtilsTests/SapphireTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ final class SapphireTest: XCTestCase {
let TORUS_EXTENDED_VERIFIER_EMAIL = "[email protected]"
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!

Expand Down Expand Up @@ -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")
}
}
Expand Down
4 changes: 1 addition & 3 deletions Tests/TorusUtilsTests/TestnetTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion Torus-utils.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 30505b8

Please sign in to comment.