diff --git a/Tests/TorusUtilsTests/IntegrationTest.swift b/Tests/TorusUtilsTests/IntegrationTest.swift index fd517b50..3aa7a9e9 100644 --- a/Tests/TorusUtilsTests/IntegrationTest.swift +++ b/Tests/TorusUtilsTests/IntegrationTest.swift @@ -44,77 +44,48 @@ class IntegrationTests: XCTestCase { return nodeDetails } - func test_getPublicAddress() async { - let exp1 = XCTestExpectation(description: "Should be able to getPublicAddress") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: "google-lrc", veriferID: TORUS_TEST_EMAIL) - let data = try await tu.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: "google-lrc", verifierId: "hello@tor.us") - XCTAssertEqual(data.finalKeyData?.evmAddress, "0x872eEfa7495599A6983d396fE8dcf542457CF33f") - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + func test_getPublicAddress() async throws { + var nodeDetails = try await get_fnd_and_tu_data(verifer: "google-lrc", veriferID: TORUS_TEST_EMAIL) + let data = try await tu.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: "google-lrc", verifierId: "hello@tor.us") + XCTAssertEqual(data.finalKeyData?.evmAddress, "0x872eEfa7495599A6983d396fE8dcf542457CF33f") - let exp2 = XCTestExpectation(description: "Should throw if verifier not supported") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER_FAKE, veriferID: TORUS_TEST_EMAIL) - _ = try await tu.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER_FAKE, verifierId: TORUS_TEST_EMAIL) - XCTFail() - } catch _ { - exp2.fulfill() - } + nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER_FAKE, veriferID: TORUS_TEST_EMAIL) + _ = try await tu.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER_FAKE, verifierId: TORUS_TEST_EMAIL) } - func test_getUserTypeAndAddress() async { - let exp1 = XCTestExpectation(description: "Should be able to getPublicAddress") + func test_getUserTypeAndAddress() async throws { let verifier: String = "tkey-google-lrc" let verifierID: String = "somev2user@gmail.com" - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier, verifierId: verifierID) + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier, verifierId: verifierID) - XCTAssertEqual(val.finalKeyData?.evmAddress, "0xE91200d82029603d73d6E307DbCbd9A7D0129d8D") - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + XCTAssertEqual(val.finalKeyData?.evmAddress, "0xE91200d82029603d73d6E307DbCbd9A7D0129d8D") } - func test_keyAssign() async { + func test_keyAssign() async throws { let email = generateRandomEmail(of: 6) - let exp1 = XCTestExpectation(description: "Should be able to do a keyAssign") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: "google-lrc", veriferID: email) - let val = try await tu.keyAssign(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: email, signerHost: tu.signerHost, network: .legacy(.TESTNET)) - let result = val.result as! [String: Any] - let keys = result["keys"] as! [[String: String]] - let address = keys[0]["address"] + let nodeDetails = try await get_fnd_and_tu_data(verifer: "google-lrc", veriferID: email) + let val = try await tu.keyAssign(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: email, signerHost: tu.signerHost, network: .legacy(.TESTNET)) + let result = val.result as! [String: Any] + let keys = result["keys"] as! [[String: String]] + _ = keys[0]["address"] - // Add more check to see if address is valid - XCTAssertNotNil(address) - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + // Add more check to see if address is valid } func test_keyLookup() async throws { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let val = try await tu.keyLookup(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: "google-lrc", verifierId: TORUS_TEST_EMAIL) - XCTAssertEqual(val.address, "0x872eEfa7495599A6983d396fE8dcf542457CF33f") - + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let val = try await tu.keyLookup(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: "google-lrc", verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(val.address, "0x872eEfa7495599A6983d396fE8dcf542457CF33f") + do { let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) _ = try await tu.keyLookup(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: "google-lrc-fake", verifierId: TORUS_TEST_EMAIL) - XCTFail() + XCTFail() } catch let error { if let keylookupError = error as? KeyLookupError { XCTAssertEqual(keylookupError, KeyLookupError.verifierNotSupported) - } } } @@ -138,50 +109,28 @@ class IntegrationTests: XCTestCase { // MARK: Aggregate tests - func test_getPublicAddressAggregateLogin() async { - let exp1 = XCTestExpectation(description: "Should be able to getPublicAddress") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let val = try await tu.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL) - XCTAssertEqual(val.finalKeyData?.evmAddress, "0x5a165d2Ed4976BD104caDE1b2948a93B72FA91D2") - exp1.fulfill() - } catch let error { - XCTFail(error.localizedDescription) - exp1.fulfill() - } + func test_getPublicAddressAggregateLogin() async throws { + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let val = try await tu.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(val.finalKeyData?.evmAddress, "0x5a165d2Ed4976BD104caDE1b2948a93B72FA91D2") } - func test_keyAssignAggregateLogin() async { + func test_keyAssignAggregateLogin() async throws { let email = generateRandomEmail(of: 6) - let exp1 = XCTestExpectation(description: "Should be able to do a keyAssign") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let val = try await tu.keyAssign(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email, signerHost: signerHost, network: .legacy(.TESTNET)) - let result = val.result as! [String: Any] - let keys = result["keys"] as! [[String: String]] - let address = keys[0]["address"] + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let val = try await tu.keyAssign(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email, signerHost: signerHost, network: .legacy(.TESTNET)) + let result = val.result as! [String: Any] + let keys = result["keys"] as! [[String: String]] + _ = keys[0]["address"] - // Add more check to see if address is valid - XCTAssertNotNil(address) - exp1.fulfill() - } catch let error { - XCTFail(error.localizedDescription) - exp1.fulfill() - } + // Add more check to see if address is valid } - func test_keyLookupAggregateLogin() async { - let exp1 = XCTestExpectation(description: "Should be able to do a keyLookupAggregateLogin") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let val = try await tu.keyLookup(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL) - XCTAssertEqual(val.address, "0x5a165d2Ed4976BD104caDE1b2948a93B72FA91D2") - exp1.fulfill() - } catch let error { - XCTFail(error.localizedDescription) - exp1.fulfill() - } + func test_keyLookupAggregateLogin() async throws { + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let val = try await tu.keyLookup(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(val.address, "0x5a165d2Ed4976BD104caDE1b2948a93B72FA91D2") } // func test_shouldAggregateLogin() async { @@ -206,7 +155,6 @@ class IntegrationTests: XCTestCase { } extension IntegrationTests { - // func test_retrieveShares_timeout() async { // // change the timeout variable in TorusUtil to 0 the test should fail // let exp1 = XCTestExpectation(description: "Should be able to do a Login") @@ -268,29 +216,20 @@ extension IntegrationTests { // } // } - func test_keyLookup_some_nodes_waiting() async { + func test_keyLookup_some_nodes_waiting() async throws { + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + var endpoints = nodeDetails.getTorusNodeEndpoints() - let exp1 = XCTestExpectation(description: "Should be able to do a keyLookup") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - var endpoints = nodeDetails.getTorusNodeEndpoints() - - // should fail if un-commented threshold 3/5 in case of key lookup - - endpoints = ["https://node-1.torus-cluster-1.com/jrpc", - "https://node-2.torus-cluster-1.com/jrpc", - "https://node-3.torus-cluster-1.com/jrpc", - "https://node-4.torus-cluster-1.com/jrpc", - "https://node-5.torus-cluster-1.com/jrpc"] - let val = try await tu.keyLookup(endpoints: endpoints, verifier: "torus-test-health", verifierId: TORUS_TEST_EMAIL) - XCTAssertEqual(val.address, "0x8AA6C8ddCD868873120aA265Fc63E3a2180375BA") - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } - } + // should fail if un-commented threshold 3/5 in case of key lookup + endpoints = ["https://node-1.torus-cluster-1.com/jrpc", + "https://node-2.torus-cluster-1.com/jrpc", + "https://node-3.torus-cluster-1.com/jrpc", + "https://node-4.torus-cluster-1.com/jrpc", + "https://node-5.torus-cluster-1.com/jrpc"] + let val = try await tu.keyLookup(endpoints: endpoints, verifier: "torus-test-health", verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(val.address, "0x8AA6C8ddCD868873120aA265Fc63E3a2180375BA") + } } struct ROPSTEN_CONSTANTS { diff --git a/Tests/TorusUtilsTests/MainnetTest.swift b/Tests/TorusUtilsTests/MainnetTest.swift index f34aa13c..475baadf 100644 --- a/Tests/TorusUtilsTests/MainnetTest.swift +++ b/Tests/TorusUtilsTests/MainnetTest.swift @@ -46,202 +46,144 @@ class MainnetTests: XCTestCase { return nodeDetails } - func test_getPublicAddress() async { - let exp1 = XCTestExpectation(description: "Should be able to getPublicAddress") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: "google", veriferID: TORUS_TEST_EMAIL) - let val = try await tu.getPublicAddress(endpoints: nodeDetails.torusNodeEndpoints, torusNodePubs: nodeDetails.torusNodePub , verifier: "google", verifierId: TORUS_TEST_EMAIL ) - XCTAssertEqual(val.finalKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") - XCTAssertEqual(val.finalKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") - XCTAssertEqual(val.finalKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") - XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") - XCTAssertEqual(val.oAuthKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") - XCTAssertEqual(val.oAuthKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") - XCTAssertNil(val.metadata?.pubNonce) - XCTAssertEqual(val.metadata?.nonce, 0) - XCTAssertEqual(val.metadata?.upgraded, false) - XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v1")) - XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + func test_getPublicAddress() async throws { + let nodeDetails = try await get_fnd_and_tu_data(verifer: "google", veriferID: TORUS_TEST_EMAIL) + let val = try await tu.getPublicAddress(endpoints: nodeDetails.torusNodeEndpoints, torusNodePubs: nodeDetails.torusNodePub, verifier: "google", verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(val.finalKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") + XCTAssertEqual(val.finalKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") + XCTAssertEqual(val.finalKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") + XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") + XCTAssertEqual(val.oAuthKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") + XCTAssertEqual(val.oAuthKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") + XCTAssertNil(val.metadata?.pubNonce) + XCTAssertEqual(val.metadata?.nonce, 0) + XCTAssertEqual(val.metadata?.upgraded, false) + XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v1")) + XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) } - func test_getUserTypeAndAddress() async { - let exp1 = XCTestExpectation(description: "should fetch user type and public address") + func test_getUserTypeAndAddress() async throws { let verifier1: String = "google" let verifierID1: String = TORUS_TEST_EMAIL - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier1, verifierId: verifierID1) - - XCTAssertEqual(val.finalKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") - XCTAssertEqual(val.finalKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") - XCTAssertEqual(val.finalKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") - XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") - XCTAssertEqual(val.oAuthKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") - XCTAssertEqual(val.oAuthKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") - XCTAssertNil(val.metadata?.pubNonce) - XCTAssertEqual(val.metadata?.nonce, 0) - XCTAssertEqual(val.metadata?.upgraded, false) - XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v1")) - XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } - - let exp2 = XCTestExpectation(description: "should fetch user type and public address") + var nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + var val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier1, verifierId: verifierID1) + + XCTAssertEqual(val.finalKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") + XCTAssertEqual(val.finalKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") + XCTAssertEqual(val.finalKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") + XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A") + XCTAssertEqual(val.oAuthKeyData!.X, "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4") + XCTAssertEqual(val.oAuthKeyData!.Y, "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1") + XCTAssertNil(val.metadata?.pubNonce) + XCTAssertEqual(val.metadata?.nonce, 0) + XCTAssertEqual(val.metadata?.upgraded, false) + XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v1")) + XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) let verifier2: String = "tkey-google" let verifierID2: String = "somev2user@gmail.com" - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier2, veriferID: verifierID2) - let val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier2, verifierId: verifierID2) - - XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0xA9c6829e4899b6D630130ebf59D046CA868D7f83") - XCTAssertEqual(val.oAuthKeyData!.X, "5566cd940ea540ba1a3ba2ff0f5fd3d9a3a74350ac3baf47b811592ae6ea1c30") - XCTAssertEqual(val.oAuthKeyData!.Y, "07a302e87e8d9eb5d143f570c248657288c13c09ecbe1e3a8720449daf9315b0") - XCTAssertEqual(val.finalKeyData!.evmAddress, "0xFf669A15bFFcf32D3C5B40bE9E5d409d60D43526") - XCTAssertEqual(val.finalKeyData!.X, "bbfd26b1e61572c4e991a21b64f12b313cb6fce6b443be92d4d5fd8f311e8f33") - XCTAssertEqual(val.finalKeyData!.Y, "df2c905356ec94faaa111a886be56ed6fa215b7facc1d1598486558355123c25") - XCTAssertEqual(val.metadata?.pubNonce?.x, "96f4b7d3c8c8c69cabdea46ae1eedda346b03cad8ba1a454871b0ec6a69861f3") - XCTAssertEqual(val.metadata?.pubNonce?.y, "da3aed7f7e9d612052beb1d92ec68a8dcf60faf356985435b424af2423f66672") - XCTAssertEqual(val.metadata?.nonce, 0) - XCTAssertEqual(val.metadata?.upgraded, false) - XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v2")) - XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) - exp2.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp2.fulfill() - } - - let exp3 = XCTestExpectation(description: "should fetch user type and public address") + nodeDetails = try await get_fnd_and_tu_data(verifer: verifier2, veriferID: verifierID2) + val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier2, verifierId: verifierID2) + + XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0xA9c6829e4899b6D630130ebf59D046CA868D7f83") + XCTAssertEqual(val.oAuthKeyData!.X, "5566cd940ea540ba1a3ba2ff0f5fd3d9a3a74350ac3baf47b811592ae6ea1c30") + XCTAssertEqual(val.oAuthKeyData!.Y, "07a302e87e8d9eb5d143f570c248657288c13c09ecbe1e3a8720449daf9315b0") + XCTAssertEqual(val.finalKeyData!.evmAddress, "0xFf669A15bFFcf32D3C5B40bE9E5d409d60D43526") + XCTAssertEqual(val.finalKeyData!.X, "bbfd26b1e61572c4e991a21b64f12b313cb6fce6b443be92d4d5fd8f311e8f33") + XCTAssertEqual(val.finalKeyData!.Y, "df2c905356ec94faaa111a886be56ed6fa215b7facc1d1598486558355123c25") + XCTAssertEqual(val.metadata?.pubNonce?.x, "96f4b7d3c8c8c69cabdea46ae1eedda346b03cad8ba1a454871b0ec6a69861f3") + XCTAssertEqual(val.metadata?.pubNonce?.y, "da3aed7f7e9d612052beb1d92ec68a8dcf60faf356985435b424af2423f66672") + XCTAssertEqual(val.metadata?.nonce, 0) + XCTAssertEqual(val.metadata?.upgraded, false) + XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v2")) + XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) let verifier3: String = "tkey-google" let verifierID3: String = "caspertorus@gmail.com" - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier3, veriferID: verifierID3) - let val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier3, verifierId: verifierID3) - - XCTAssertEqual(val.finalKeyData!.evmAddress, "0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53") - XCTAssertEqual(val.finalKeyData!.X, "c01282dd68d2341031a1cff06f70d821cad45140f425f1c25055a8aa64959df8") - XCTAssertEqual(val.finalKeyData!.Y, "cb3937773bb819d60b780b6d4c2edcf27c0f7090ba1fc2ff42504a8138a8e2d7") - XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53") - XCTAssertEqual(val.oAuthKeyData!.X, "c01282dd68d2341031a1cff06f70d821cad45140f425f1c25055a8aa64959df8") - XCTAssertEqual(val.oAuthKeyData!.Y, "cb3937773bb819d60b780b6d4c2edcf27c0f7090ba1fc2ff42504a8138a8e2d7") - XCTAssertEqual(val.metadata?.pubNonce?.x, nil) - XCTAssertEqual(val.metadata?.pubNonce?.y, nil) - XCTAssertEqual(val.metadata?.nonce, 0) - XCTAssertEqual(val.metadata?.upgraded, false) - XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v1")) - XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) - exp3.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp3.fulfill() - } + nodeDetails = try await get_fnd_and_tu_data(verifer: verifier3, veriferID: verifierID3) + val = try await tu.getUserTypeAndAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier3, verifierId: verifierID3) + + XCTAssertEqual(val.finalKeyData!.evmAddress, "0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53") + XCTAssertEqual(val.finalKeyData!.X, "c01282dd68d2341031a1cff06f70d821cad45140f425f1c25055a8aa64959df8") + XCTAssertEqual(val.finalKeyData!.Y, "cb3937773bb819d60b780b6d4c2edcf27c0f7090ba1fc2ff42504a8138a8e2d7") + XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53") + XCTAssertEqual(val.oAuthKeyData!.X, "c01282dd68d2341031a1cff06f70d821cad45140f425f1c25055a8aa64959df8") + XCTAssertEqual(val.oAuthKeyData!.Y, "cb3937773bb819d60b780b6d4c2edcf27c0f7090ba1fc2ff42504a8138a8e2d7") + XCTAssertEqual(val.metadata?.pubNonce?.x, nil) + XCTAssertEqual(val.metadata?.pubNonce?.y, nil) + XCTAssertEqual(val.metadata?.nonce, 0) + XCTAssertEqual(val.metadata?.upgraded, false) + XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v1")) + XCTAssertEqual(val.nodesData?.nodeIndexes.count, 0) } - func test_keyAssign() async { + func test_keyAssign() async throws { let email = generateRandomEmail(of: 6) + let nodeDetails = try await get_fnd_and_tu_data(verifer: "google", veriferID: email) + let val = try await tu.keyAssign(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: email, signerHost: tu.signerHost, network: .legacy(.MAINNET)) + let result = val.result as! [String: Any] + let keys = result["keys"] as! [[String: String]] + _ = keys[0]["address"] - let exp1 = XCTestExpectation(description: "Should be able to do a keyAssign") - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: "google", veriferID: email) - let val = try await tu.keyAssign(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: email, signerHost: tu.signerHost, network: .legacy(.MAINNET)) - let result = val.result as! [String: Any] - let keys = result["keys"] as! [[String: String]] - let address = keys[0]["address"] - - // Add more check to see if address is valid - XCTAssertNotNil(address) - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + // Add more check to see if address is valid } - func test_shouldLogin() async { - let exp1 = XCTestExpectation(description: "Should be able to do a Login") + func test_shouldLogin() async throws { let jwt = try! generateIdToken(email: TORUS_TEST_EMAIL) let verifierParams = VerifierParams(verifier_id: TORUS_TEST_EMAIL) let extraParams = ["verifieridentifier": TORUS_TEST_VERIFIER, "verifier_id": TORUS_TEST_EMAIL] as [String: Codable] -// let buffer: Data = try! NSKeyedArchiver.archivedData(withRootObject: extraParams, requiringSecureCoding: false) - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - let data = try await tu.retrieveShares( - endpoints: nodeDetails.getTorusNodeEndpoints(), - torusNodePubs: nodeDetails.getTorusNodePub(), - indexes: nodeDetails.getTorusIndexes(), - verifier: TORUS_TEST_VERIFIER, - verifierParams: verifierParams, - idToken: jwt, - extraParams: extraParams) - - XCTAssertEqual(data.finalKeyData?.evmAddress, "0x90A926b698047b4A87265ba1E9D8b512E8489067") - XCTAssertEqual(data.finalKeyData?.X, "a92d8bf1f01ad62e189a5cb0f606b89aa6df1b867128438c38e3209f3b9fc34f") - XCTAssertEqual(data.finalKeyData?.Y, "0ad1ffaecb2178b02a37c455975368be9b967ead1b281202cc8d48c77618bff1") - XCTAssertEqual(data.finalKeyData?.privKey, "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44") - XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0x90A926b698047b4A87265ba1E9D8b512E8489067") - XCTAssertEqual(data.oAuthKeyData?.X, "a92d8bf1f01ad62e189a5cb0f606b89aa6df1b867128438c38e3209f3b9fc34f") - XCTAssertEqual(data.oAuthKeyData?.Y, "0ad1ffaecb2178b02a37c455975368be9b967ead1b281202cc8d48c77618bff1") - XCTAssertEqual(data.oAuthKeyData?.privKey, "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44") - XCTAssertEqual(data.sessionData?.sessionTokenData.count, 0) - XCTAssertEqual(data.sessionData?.sessionAuthKey, "") - XCTAssertEqual(data.metadata?.pubNonce, nil) - XCTAssertEqual(data.metadata?.nonce, BigUInt(0)) - XCTAssertEqual(data.metadata?.typeOfUser, .v1) - XCTAssertEqual(data.metadata?.upgraded, nil) - XCTAssertEqual(data.nodesData?.nodeIndexes.count, 0) - - exp1.fulfill() - } catch let error { - XCTFail(error.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let data = try await tu.retrieveShares( + endpoints: nodeDetails.getTorusNodeEndpoints(), + torusNodePubs: nodeDetails.getTorusNodePub(), + indexes: nodeDetails.getTorusIndexes(), + verifier: TORUS_TEST_VERIFIER, + verifierParams: verifierParams, + idToken: jwt, + extraParams: extraParams) + + XCTAssertEqual(data.finalKeyData?.evmAddress, "0x90A926b698047b4A87265ba1E9D8b512E8489067") + XCTAssertEqual(data.finalKeyData?.X, "a92d8bf1f01ad62e189a5cb0f606b89aa6df1b867128438c38e3209f3b9fc34f") + XCTAssertEqual(data.finalKeyData?.Y, "0ad1ffaecb2178b02a37c455975368be9b967ead1b281202cc8d48c77618bff1") + XCTAssertEqual(data.finalKeyData?.privKey, "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44") + XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0x90A926b698047b4A87265ba1E9D8b512E8489067") + XCTAssertEqual(data.oAuthKeyData?.X, "a92d8bf1f01ad62e189a5cb0f606b89aa6df1b867128438c38e3209f3b9fc34f") + XCTAssertEqual(data.oAuthKeyData?.Y, "0ad1ffaecb2178b02a37c455975368be9b967ead1b281202cc8d48c77618bff1") + XCTAssertEqual(data.oAuthKeyData?.privKey, "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44") + XCTAssertEqual(data.sessionData?.sessionTokenData.count, 0) + XCTAssertEqual(data.sessionData?.sessionAuthKey, "") + XCTAssertEqual(data.metadata?.pubNonce, nil) + XCTAssertEqual(data.metadata?.nonce, BigUInt(0)) + XCTAssertEqual(data.metadata?.typeOfUser, .v1) + XCTAssertEqual(data.metadata?.upgraded, nil) + XCTAssertEqual(data.nodesData?.nodeIndexes.count, 0) } - func test_shouldAggregateLogin() async { - let exp1 = XCTestExpectation(description: "Should be able to getPublicAddress") + func test_shouldAggregateLogin() async throws { let verifier: String = TORUS_TEST_AGGREGATE_VERIFIER let verifierID: String = TORUS_TEST_EMAIL let jwt = try! generateIdToken(email: TORUS_TEST_EMAIL) let hashedIDToken = jwt.sha3(.keccak256) let extraParams = ["verifier_id": TORUS_TEST_EMAIL, "sub_verifier_ids": [TORUS_TEST_VERIFIER], "verify_params": [["verifier_id": TORUS_TEST_EMAIL, "idtoken": jwt]]] as [String: Codable] -// let buffer: Data = try! NSKeyedArchiver.archivedData(withRootObject: extraParams, requiringSecureCoding: false) let verifierParams = VerifierParams(verifier_id: verifierID) - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier, veriferID: verifierID) - - let data = try await tu.retrieveShares(endpoints: nodeDetails.torusNodeEndpoints, torusNodePubs: nodeDetails.torusNodePub, indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: hashedIDToken, extraParams: extraParams) - - XCTAssertEqual(data.finalKeyData?.evmAddress, "0x621a4d458cFd345dAE831D9E756F10cC40A50381") - XCTAssertEqual(data.finalKeyData?.X, "52abc69ebec21deacd273dbdcb4d40066b701177bba906a187676e3292e1e236") - XCTAssertEqual(data.finalKeyData?.Y, "5e57e251db2c95c874f7ec852439302a62ef9592c8c50024e3d48018a6f77c7e") - XCTAssertEqual(data.finalKeyData?.privKey, "f55d89088a0c491d797c00da5b2ed6dc9c269c960ff121e45f255d06a91c6534") - XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0x621a4d458cFd345dAE831D9E756F10cC40A50381") - XCTAssertEqual(data.oAuthKeyData?.X, "52abc69ebec21deacd273dbdcb4d40066b701177bba906a187676e3292e1e236") - XCTAssertEqual(data.oAuthKeyData?.Y, "5e57e251db2c95c874f7ec852439302a62ef9592c8c50024e3d48018a6f77c7e") - XCTAssertEqual(data.oAuthKeyData?.privKey, "f55d89088a0c491d797c00da5b2ed6dc9c269c960ff121e45f255d06a91c6534") - XCTAssertEqual(data.sessionData?.sessionTokenData.count, 0) - XCTAssertEqual(data.sessionData?.sessionAuthKey, "") - XCTAssertEqual(data.metadata?.pubNonce, nil) - XCTAssertEqual(data.metadata?.nonce, BigUInt(0)) - XCTAssertEqual(data.metadata?.typeOfUser, .v1) - XCTAssertEqual(data.metadata?.upgraded, nil) - XCTAssertEqual(data.nodesData?.nodeIndexes.count, 0) - - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier, veriferID: verifierID) + + let data = try await tu.retrieveShares(endpoints: nodeDetails.torusNodeEndpoints, torusNodePubs: nodeDetails.torusNodePub, indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: hashedIDToken, extraParams: extraParams) + + XCTAssertEqual(data.finalKeyData?.evmAddress, "0x621a4d458cFd345dAE831D9E756F10cC40A50381") + XCTAssertEqual(data.finalKeyData?.X, "52abc69ebec21deacd273dbdcb4d40066b701177bba906a187676e3292e1e236") + XCTAssertEqual(data.finalKeyData?.Y, "5e57e251db2c95c874f7ec852439302a62ef9592c8c50024e3d48018a6f77c7e") + XCTAssertEqual(data.finalKeyData?.privKey, "f55d89088a0c491d797c00da5b2ed6dc9c269c960ff121e45f255d06a91c6534") + XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0x621a4d458cFd345dAE831D9E756F10cC40A50381") + XCTAssertEqual(data.oAuthKeyData?.X, "52abc69ebec21deacd273dbdcb4d40066b701177bba906a187676e3292e1e236") + XCTAssertEqual(data.oAuthKeyData?.Y, "5e57e251db2c95c874f7ec852439302a62ef9592c8c50024e3d48018a6f77c7e") + XCTAssertEqual(data.oAuthKeyData?.privKey, "f55d89088a0c491d797c00da5b2ed6dc9c269c960ff121e45f255d06a91c6534") + XCTAssertEqual(data.sessionData?.sessionTokenData.count, 0) + XCTAssertEqual(data.sessionData?.sessionAuthKey, "") + XCTAssertEqual(data.metadata?.pubNonce, nil) + XCTAssertEqual(data.metadata?.nonce, BigUInt(0)) + XCTAssertEqual(data.metadata?.typeOfUser, .v1) + XCTAssertEqual(data.metadata?.upgraded, nil) + XCTAssertEqual(data.nodesData?.nodeIndexes.count, 0) } - } diff --git a/Tests/TorusUtilsTests/SapphireTest.swift b/Tests/TorusUtilsTests/SapphireTest.swift index b81b913b..c7d3c86d 100644 --- a/Tests/TorusUtilsTests/SapphireTest.swift +++ b/Tests/TorusUtilsTests/SapphireTest.swift @@ -10,7 +10,6 @@ import CommonSources @available(iOS 13.0, *) final class SapphireTest: XCTestCase { - static var fetchNodeDetails: AllNodeDetailsModel? // static var nodeDetails: NodeDetails? static var utils: TorusUtils? @@ -41,382 +40,268 @@ final class SapphireTest: XCTestCase { torus = TorusUtils(enableOneKey: enableOneKey, network: .sapphire(.SAPPHIRE_DEVNET)) return nodeDetails } - + func testFetchPublicAddress() async throws { - let exp1 = XCTestExpectation(description: "Should be able to fetch public address") - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - - let val = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.torusNodePub, verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) - XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0xac997dE675Fb69FCb0F4115A23c0061A892A2772") - XCTAssertEqual(val.oAuthKeyData!.X, "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528") - XCTAssertEqual(val.oAuthKeyData!.Y, "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe") - XCTAssertEqual(val.finalKeyData!.evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F") - XCTAssertEqual(val.finalKeyData!.X, "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff") - XCTAssertEqual(val.finalKeyData!.Y, "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd") - XCTAssertEqual(val.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") - XCTAssertEqual(val.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") - XCTAssertEqual(val.metadata?.nonce, BigUInt("376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e", radix: 16)) - XCTAssertEqual(val.metadata?.upgraded, false) - XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v2")) - XCTAssertEqual(val.nodesData?.nodeIndexes.count, 3) - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } - + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + + let val = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.torusNodePub, verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(val.oAuthKeyData!.evmAddress, "0xac997dE675Fb69FCb0F4115A23c0061A892A2772") + XCTAssertEqual(val.oAuthKeyData!.X, "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528") + XCTAssertEqual(val.oAuthKeyData!.Y, "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe") + XCTAssertEqual(val.finalKeyData!.evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F") + XCTAssertEqual(val.finalKeyData!.X, "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff") + XCTAssertEqual(val.finalKeyData!.Y, "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd") + XCTAssertEqual(val.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") + XCTAssertEqual(val.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") + XCTAssertEqual(val.metadata?.nonce, BigUInt("376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e", radix: 16)) + XCTAssertEqual(val.metadata?.upgraded, false) + XCTAssertEqual(val.metadata?.typeOfUser, UserType(rawValue: "v2")) + XCTAssertEqual(val.nodesData?.nodeIndexes.count, 3) } - + func testKeepPublicAddressSame() async throws { - let exp1 = XCTestExpectation(description: "should keep public address same") - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - - let publicAddress = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) - let publicAddress2 = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(),torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) - - XCTAssertEqual(publicAddress.finalKeyData?.evmAddress, publicAddress2.finalKeyData?.evmAddress) - XCTAssertNotEqual(publicAddress.finalKeyData?.evmAddress, nil) - XCTAssertNotEqual(publicAddress2.finalKeyData?.evmAddress, "") - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + let publicAddress = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) + let publicAddress2 = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) + + XCTAssertEqual(publicAddress.finalKeyData?.evmAddress, publicAddress2.finalKeyData?.evmAddress) + XCTAssertNotEqual(publicAddress.finalKeyData?.evmAddress, nil) + XCTAssertNotEqual(publicAddress2.finalKeyData?.evmAddress, "") } - + func testFetchPublicAddressAndUserType() async throws { - - let exp1 = XCTestExpectation(description: "should fetch user type and public address") - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - - let result = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(),verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) - - XCTAssertEqual(result.finalKeyData?.evmAddress.lowercased(), "0x4924F91F5d6701dDd41042D94832bB17B76F316F".lowercased()) - - XCTAssertEqual(result.metadata?.typeOfUser, .v2) - - XCTAssertEqual(result.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") - - XCTAssertEqual(result.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } - + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + + let result = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL) + + XCTAssertEqual(result.finalKeyData?.evmAddress.lowercased(), "0x4924F91F5d6701dDd41042D94832bB17B76F316F".lowercased()) + + XCTAssertEqual(result.metadata?.typeOfUser, .v2) + + XCTAssertEqual(result.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") + + XCTAssertEqual(result.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") } - func testKeyAssignSapphireDevnet() async { - let exp1 = XCTestExpectation(description: "should be able to key assign") + func testKeyAssignSapphireDevnet() async throws { let fakeEmail = generateRandomEmail(of: 6) let verifier: String = TORUS_TEST_VERIFIER let verifierID: String = fakeEmail - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier, veriferID: verifierID) - let data = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier, verifierId: verifierID) - XCTAssertNotNil(data.finalKeyData) - XCTAssertNotEqual(data.finalKeyData?.evmAddress, "") - XCTAssertEqual(data.metadata?.typeOfUser, .v2) - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier, veriferID: verifierID) + let data = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: verifier, verifierId: verifierID) + XCTAssertNotNil(data.finalKeyData) + XCTAssertNotEqual(data.finalKeyData?.evmAddress, "") + XCTAssertEqual(data.metadata?.typeOfUser, .v2) } - - func testAbleToLogin() async throws { - let exp1 = XCTestExpectation(description: "Should be able to do a Login") + func testAbleToLogin() async throws { let token = try generateIdToken(email: TORUS_TEST_EMAIL) let verifierParams = VerifierParams(verifier_id: TORUS_TEST_EMAIL) - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - - let data = try await torus.retrieveShares( - endpoints: nodeDetails.getTorusNodeEndpoints(), - torusNodePubs: nodeDetails.getTorusNodePub(), - indexes: nodeDetails.getTorusIndexes(), - verifier: TORUS_TEST_VERIFIER, - verifierParams: verifierParams, - idToken: token - ) - - XCTAssertEqual(data.finalKeyData?.evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F") - XCTAssertEqual(data.finalKeyData?.X, "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff") - XCTAssertEqual(data.finalKeyData?.Y, "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd") - XCTAssertEqual(data.finalKeyData?.privKey, "04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c") - XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0xac997dE675Fb69FCb0F4115A23c0061A892A2772") - XCTAssertEqual(data.oAuthKeyData?.X, "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528") - XCTAssertEqual(data.oAuthKeyData?.Y, "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe") - XCTAssertEqual(data.oAuthKeyData?.privKey, "cd7d1dc7aec71fd2ee284890d56ac34d375bbc15ff41a1d87d088170580b9b0f") - XCTAssertNotEqual(data.sessionData?.sessionTokenData.count, 0) - XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "") - XCTAssertEqual(data.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") - XCTAssertEqual(data.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") - XCTAssertEqual(data.metadata?.nonce, BigUInt(hex: "376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e")) - XCTAssertEqual(data.metadata?.typeOfUser, .v2) - XCTAssertEqual(data.metadata?.upgraded, false) - XCTAssertNotEqual(data.nodesData?.nodeIndexes.count, 0) - - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } - - + + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + + let data = try await torus.retrieveShares( + endpoints: nodeDetails.getTorusNodeEndpoints(), + torusNodePubs: nodeDetails.getTorusNodePub(), + indexes: nodeDetails.getTorusIndexes(), + verifier: TORUS_TEST_VERIFIER, + verifierParams: verifierParams, + idToken: token + ) + + XCTAssertEqual(data.finalKeyData?.evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F") + XCTAssertEqual(data.finalKeyData?.X, "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff") + XCTAssertEqual(data.finalKeyData?.Y, "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd") + XCTAssertEqual(data.finalKeyData?.privKey, "04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c") + XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0xac997dE675Fb69FCb0F4115A23c0061A892A2772") + XCTAssertEqual(data.oAuthKeyData?.X, "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528") + XCTAssertEqual(data.oAuthKeyData?.Y, "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe") + XCTAssertEqual(data.oAuthKeyData?.privKey, "cd7d1dc7aec71fd2ee284890d56ac34d375bbc15ff41a1d87d088170580b9b0f") + XCTAssertNotEqual(data.sessionData?.sessionTokenData.count, 0) + XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "") + XCTAssertEqual(data.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") + XCTAssertEqual(data.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") + XCTAssertEqual(data.metadata?.nonce, BigUInt(hex: "376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e")) + XCTAssertEqual(data.metadata?.typeOfUser, .v2) + XCTAssertEqual(data.metadata?.upgraded, false) + XCTAssertNotEqual(data.nodesData?.nodeIndexes.count, 0) } - - - func testNewUserLogin() async throws { - let exp1 = XCTestExpectation(description: "Should be able to do a Login") + func testNewUserLogin() async throws { let fakeEmail = generateRandomEmail(of: 6) - let verifierId = fakeEmail //faker random address + let verifierId = fakeEmail // faker random address let token = try generateIdToken(email: verifierId) let verifierParams = VerifierParams(verifier_id: verifierId) - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: verifierId) - - let data = try await torus.retrieveShares( - endpoints: nodeDetails.getTorusNodeEndpoints(), - torusNodePubs: nodeDetails.getTorusNodePub(), - indexes: nodeDetails.getTorusIndexes(), - verifier: TORUS_TEST_VERIFIER, - verifierParams: verifierParams, - idToken: token - ) - - XCTAssertEqual(data.metadata?.typeOfUser, .v2) - XCTAssertEqual(data.metadata?.upgraded, false) - XCTAssertNotEqual(data.finalKeyData?.evmAddress, "") - XCTAssertNotEqual(data.finalKeyData?.X, "") - XCTAssertNotEqual(data.finalKeyData?.Y, "") - XCTAssertNotEqual(data.finalKeyData?.privKey, "") - XCTAssertNotEqual(data.oAuthKeyData?.evmAddress, "") - XCTAssertNotEqual(data.oAuthKeyData?.X, "") - XCTAssertNotEqual(data.oAuthKeyData?.Y, "") - XCTAssertNotEqual(data.oAuthKeyData?.privKey, "") - XCTAssertNotEqual(data.sessionData?.sessionTokenData.count, 0) - XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "") - XCTAssertNotEqual(data.metadata?.pubNonce?.x, "") - XCTAssertNotEqual(data.metadata?.pubNonce?.y, "") - XCTAssertNotEqual(data.nodesData?.nodeIndexes.count, 0) - - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } - - - } - - func testNodeDownAbleToLogin () async throws { - let exp1 = XCTestExpectation(description: "should be able to login even when node is down") + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: verifierId) + + let data = try await torus.retrieveShares( + endpoints: nodeDetails.getTorusNodeEndpoints(), + torusNodePubs: nodeDetails.getTorusNodePub(), + indexes: nodeDetails.getTorusIndexes(), + verifier: TORUS_TEST_VERIFIER, + verifierParams: verifierParams, + idToken: token + ) + + XCTAssertEqual(data.metadata?.typeOfUser, .v2) + XCTAssertEqual(data.metadata?.upgraded, false) + XCTAssertNotEqual(data.finalKeyData?.evmAddress, "") + XCTAssertNotEqual(data.finalKeyData?.X, "") + XCTAssertNotEqual(data.finalKeyData?.Y, "") + XCTAssertNotEqual(data.finalKeyData?.privKey, "") + XCTAssertNotEqual(data.oAuthKeyData?.evmAddress, "") + XCTAssertNotEqual(data.oAuthKeyData?.X, "") + XCTAssertNotEqual(data.oAuthKeyData?.Y, "") + XCTAssertNotEqual(data.oAuthKeyData?.privKey, "") + XCTAssertNotEqual(data.sessionData?.sessionTokenData.count, 0) + XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "") + XCTAssertNotEqual(data.metadata?.pubNonce?.x, "") + XCTAssertNotEqual(data.metadata?.pubNonce?.y, "") + XCTAssertNotEqual(data.nodesData?.nodeIndexes.count, 0) + } + func testNodeDownAbleToLogin() async throws { let token = try generateIdToken(email: TORUS_TEST_EMAIL) let verifierParams = VerifierParams(verifier_id: TORUS_TEST_EMAIL) - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) - - var torusNodeEndpoints = nodeDetails.getTorusNodeSSSEndpoints() - torusNodeEndpoints[1] = "https://example.com" - - let data = try await torus.retrieveShares(endpoints: torusNodeEndpoints, - torusNodePubs: nodeDetails.getTorusNodePub(),indexes: nodeDetails.getTorusIndexes(), - verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: token) - - XCTAssertEqual(data.finalKeyData?.evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F") - XCTAssertEqual(data.finalKeyData?.X, "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff") - XCTAssertEqual(data.finalKeyData?.Y, "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd") - XCTAssertEqual(data.finalKeyData?.privKey, "04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c") - XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0xac997dE675Fb69FCb0F4115A23c0061A892A2772") - XCTAssertEqual(data.oAuthKeyData?.X, "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528") - XCTAssertEqual(data.oAuthKeyData?.Y, "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe") - XCTAssertEqual(data.oAuthKeyData?.privKey, "cd7d1dc7aec71fd2ee284890d56ac34d375bbc15ff41a1d87d088170580b9b0f") - XCTAssertNotEqual(data.sessionData?.sessionTokenData.count, 0) - XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "") - XCTAssertEqual(data.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") - XCTAssertEqual(data.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") - XCTAssertEqual(data.metadata?.nonce, BigUInt(hex:"376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e")) - XCTAssertEqual(data.metadata?.typeOfUser, .v2) - XCTAssertEqual(data.metadata?.upgraded, false) - XCTAssertNotEqual(data.nodesData?.nodeIndexes.count, 0) - - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: TORUS_TEST_EMAIL) + + var torusNodeEndpoints = nodeDetails.getTorusNodeSSSEndpoints() + torusNodeEndpoints[1] = "https://example.com" + + let data = try await torus.retrieveShares(endpoints: torusNodeEndpoints, + torusNodePubs: nodeDetails.getTorusNodePub(), indexes: nodeDetails.getTorusIndexes(), + verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: token) + + XCTAssertEqual(data.finalKeyData?.evmAddress, "0x4924F91F5d6701dDd41042D94832bB17B76F316F") + XCTAssertEqual(data.finalKeyData?.X, "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff") + XCTAssertEqual(data.finalKeyData?.Y, "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd") + XCTAssertEqual(data.finalKeyData?.privKey, "04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c") + XCTAssertEqual(data.oAuthKeyData?.evmAddress, "0xac997dE675Fb69FCb0F4115A23c0061A892A2772") + XCTAssertEqual(data.oAuthKeyData?.X, "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528") + XCTAssertEqual(data.oAuthKeyData?.Y, "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe") + XCTAssertEqual(data.oAuthKeyData?.privKey, "cd7d1dc7aec71fd2ee284890d56ac34d375bbc15ff41a1d87d088170580b9b0f") + XCTAssertNotEqual(data.sessionData?.sessionTokenData.count, 0) + XCTAssertNotEqual(data.sessionData?.sessionAuthKey, "") + XCTAssertEqual(data.metadata?.pubNonce?.x, "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c") + XCTAssertEqual(data.metadata?.pubNonce?.y, "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7") + XCTAssertEqual(data.metadata?.nonce, BigUInt(hex: "376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e")) + XCTAssertEqual(data.metadata?.typeOfUser, .v2) + XCTAssertEqual(data.metadata?.upgraded, false) + XCTAssertNotEqual(data.nodesData?.nodeIndexes.count, 0) } func testPubAdderessOfTssVerifierId() async throws { let email = TORUS_EXTENDED_VERIFIER_EMAIL - let exp1 = XCTestExpectation(description: "should fetch pub address of tss verifier id") let nonce = 0 let tssTag = "default" let tssVerifierId = "\(email)\u{0015}\(tssTag)\u{0016}\(nonce)" - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: email) - - let pubAddress = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeSSSEndpoints(),torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, extendedVerifierId: tssVerifierId) - - XCTAssertEqual(pubAddress.oAuthKeyData!.evmAddress, "0xBd6Bc8aDC5f2A0526078Fd2016C4335f64eD3a30") - XCTAssertEqual(pubAddress.oAuthKeyData!.X, "d45d4ad45ec643f9eccd9090c0a2c753b1c991e361388e769c0dfa90c210348c") - XCTAssertEqual(pubAddress.oAuthKeyData!.Y, "fdc151b136aa7df94e97cc7d7007e2b45873c4b0656147ec70aad46e178bce1e") - XCTAssertEqual(pubAddress.finalKeyData!.evmAddress, "0xBd6Bc8aDC5f2A0526078Fd2016C4335f64eD3a30") - XCTAssertEqual(pubAddress.finalKeyData!.X, "d45d4ad45ec643f9eccd9090c0a2c753b1c991e361388e769c0dfa90c210348c") - XCTAssertEqual(pubAddress.finalKeyData!.Y, "fdc151b136aa7df94e97cc7d7007e2b45873c4b0656147ec70aad46e178bce1e") - XCTAssertEqual(pubAddress.metadata?.pubNonce?.x, nil) - XCTAssertEqual(pubAddress.metadata?.pubNonce?.y, nil) - XCTAssertEqual(pubAddress.metadata?.nonce, BigUInt("0")) - XCTAssertEqual(pubAddress.metadata?.upgraded, false) - XCTAssertEqual(pubAddress.metadata?.typeOfUser, UserType(rawValue: "v2")) - XCTAssertEqual(pubAddress.nodesData?.nodeIndexes.count, 3) - - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } - + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: email) + + let pubAddress = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, extendedVerifierId: tssVerifierId) + + XCTAssertEqual(pubAddress.oAuthKeyData!.evmAddress, "0xBd6Bc8aDC5f2A0526078Fd2016C4335f64eD3a30") + XCTAssertEqual(pubAddress.oAuthKeyData!.X, "d45d4ad45ec643f9eccd9090c0a2c753b1c991e361388e769c0dfa90c210348c") + XCTAssertEqual(pubAddress.oAuthKeyData!.Y, "fdc151b136aa7df94e97cc7d7007e2b45873c4b0656147ec70aad46e178bce1e") + XCTAssertEqual(pubAddress.finalKeyData!.evmAddress, "0xBd6Bc8aDC5f2A0526078Fd2016C4335f64eD3a30") + XCTAssertEqual(pubAddress.finalKeyData!.X, "d45d4ad45ec643f9eccd9090c0a2c753b1c991e361388e769c0dfa90c210348c") + XCTAssertEqual(pubAddress.finalKeyData!.Y, "fdc151b136aa7df94e97cc7d7007e2b45873c4b0656147ec70aad46e178bce1e") + XCTAssertEqual(pubAddress.metadata?.pubNonce?.x, nil) + XCTAssertEqual(pubAddress.metadata?.pubNonce?.y, nil) + XCTAssertEqual(pubAddress.metadata?.nonce, BigUInt("0")) + XCTAssertEqual(pubAddress.metadata?.upgraded, false) + XCTAssertEqual(pubAddress.metadata?.typeOfUser, UserType(rawValue: "v2")) + XCTAssertEqual(pubAddress.nodesData?.nodeIndexes.count, 3) } - + func testAssignKeyToTssVerifier() async throws { - - let exp1 = XCTestExpectation(description: "should assign key to tss verifier id") - let fakeEmail = generateRandomEmail(of: 6) - let verifierId = fakeEmail //faker random address + let verifierId = fakeEmail // faker random address let nonce = 0 let tssTag = "default" let tssVerifierId = "\(verifierId)\u{0015}\(tssTag)\u{0016}\(nonce)" - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: verifierId) - let keyData = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeSSSEndpoints(),torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: verifierId, extendedVerifierId: tssVerifierId) - XCTAssertNotEqual(keyData.finalKeyData?.evmAddress, nil) - XCTAssertNotEqual(keyData.finalKeyData?.evmAddress, "") - XCTAssertEqual(keyData.metadata?.typeOfUser, .v2) - XCTAssertEqual(keyData.metadata?.nonce, BigUInt("0")) - XCTAssertEqual(keyData.metadata?.upgraded, false) - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: verifierId) + let keyData = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), torusNodePubs: nodeDetails.getTorusNodePub(), verifier: TORUS_TEST_VERIFIER, verifierId: verifierId, extendedVerifierId: tssVerifierId) + XCTAssertNotEqual(keyData.finalKeyData?.evmAddress, nil) + XCTAssertNotEqual(keyData.finalKeyData?.evmAddress, "") + XCTAssertEqual(keyData.metadata?.typeOfUser, .v2) + XCTAssertEqual(keyData.metadata?.nonce, BigUInt("0")) + XCTAssertEqual(keyData.metadata?.upgraded, false) } - - func testAllowTssVerifierIdFetchShare () async throws { - - let email = generateRandomEmail(of: 6) //faker random address ??? + + func testAllowTssVerifierIdFetchShare() async throws { + let email = generateRandomEmail(of: 6) // faker random address ??? let verifierId = TORUS_TEST_EMAIL let nonce = 0 let tssTag = "default" let tssVerifierId = "\(email)\u{0015}\(tssTag)\u{0016}\(nonce)" - + let token = try generateIdToken(email: email) let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: verifierId) let verifierParams = VerifierParams(verifier_id: verifierId, extended_verifier_id: tssVerifierId) - - + let result = try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeEndpoints(), - torusNodePubs: nodeDetails.getTorusNodePub(),indexes: nodeDetails.getTorusIndexes(), + torusNodePubs: nodeDetails.getTorusNodePub(), indexes: nodeDetails.getTorusIndexes(), verifier: TORUS_TEST_VERIFIER, verifierParams: verifierParams, idToken: token) - + XCTAssertNotEqual(result.finalKeyData?.privKey, nil) XCTAssertNotEqual(result.finalKeyData?.evmAddress, nil) XCTAssertEqual(result.metadata?.typeOfUser, .v2) XCTAssertEqual(result.metadata?.nonce, BigUInt("0")) XCTAssertEqual(result.metadata?.upgraded, true) - } - - func testFetchPubAdderessWhenHashEnabled () async throws { - - let exp1 = XCTestExpectation(description: "should fetch public address when verifierID hash enabled") - - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: HashEnabledVerifier) - let pubAddress = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), - torusNodePubs: nodeDetails.getTorusNodePub(), - verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL) - XCTAssertEqual(pubAddress.oAuthKeyData!.evmAddress, "0x4135ad20D2E9ACF37D64E7A6bD8AC34170d51219") - XCTAssertEqual(pubAddress.oAuthKeyData!.X, "9c591943683c0e5675f99626cea84153a3c5b72c6e7840f8b8b53d0f2bb50c67") - XCTAssertEqual(pubAddress.oAuthKeyData!.Y, "9d9896d82e565a2d5d437745af6e4560f3564c2ac0d0edcb72e0b508b3ac05a0") - XCTAssertEqual(pubAddress.finalKeyData!.evmAddress, "0xF79b5ffA48463eba839ee9C97D61c6063a96DA03") - XCTAssertEqual(pubAddress.finalKeyData!.X, "21cd0ae3168d60402edb8bd65c58ff4b3e0217127d5bb5214f03f84a76f24d8a") - XCTAssertEqual(pubAddress.finalKeyData!.Y, "575b7a4d0ef9921b3b1b84f30d412e87bc69b4eab83f6706e247cceb9e985a1e") - XCTAssertEqual(pubAddress.metadata?.pubNonce?.x, "d6404befc44e3ab77a8387829d77e9c77a9c2fb37ae314c3a59bdc108d70349d") - XCTAssertEqual(pubAddress.metadata?.pubNonce?.y, "1054dfe297f1d977ccc436109cbcce64e95b27f93efc0f1dab739c9146eda2e") - XCTAssertEqual(pubAddress.metadata?.nonce, BigUInt("51eb06f7901d5a8562274d3e53437328ca41ad96926f075122f6bd50e31be52d", radix: 16)) - XCTAssertEqual(pubAddress.metadata?.upgraded, false) - XCTAssertEqual(pubAddress.metadata?.typeOfUser, UserType(rawValue: "v2")) - XCTAssertEqual(pubAddress.nodesData?.nodeIndexes.count, 3) - - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } - + func testFetchPubAdderessWhenHashEnabled() async throws { + let nodeDetails = try await get_fnd_and_tu_data(verifer: TORUS_TEST_VERIFIER, veriferID: HashEnabledVerifier) + let pubAddress = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), + torusNodePubs: nodeDetails.getTorusNodePub(), + verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL) + XCTAssertEqual(pubAddress.oAuthKeyData!.evmAddress, "0x4135ad20D2E9ACF37D64E7A6bD8AC34170d51219") + XCTAssertEqual(pubAddress.oAuthKeyData!.X, "9c591943683c0e5675f99626cea84153a3c5b72c6e7840f8b8b53d0f2bb50c67") + XCTAssertEqual(pubAddress.oAuthKeyData!.Y, "9d9896d82e565a2d5d437745af6e4560f3564c2ac0d0edcb72e0b508b3ac05a0") + XCTAssertEqual(pubAddress.finalKeyData!.evmAddress, "0xF79b5ffA48463eba839ee9C97D61c6063a96DA03") + XCTAssertEqual(pubAddress.finalKeyData!.X, "21cd0ae3168d60402edb8bd65c58ff4b3e0217127d5bb5214f03f84a76f24d8a") + XCTAssertEqual(pubAddress.finalKeyData!.Y, "575b7a4d0ef9921b3b1b84f30d412e87bc69b4eab83f6706e247cceb9e985a1e") + XCTAssertEqual(pubAddress.metadata?.pubNonce?.x, "d6404befc44e3ab77a8387829d77e9c77a9c2fb37ae314c3a59bdc108d70349d") + XCTAssertEqual(pubAddress.metadata?.pubNonce?.y, "1054dfe297f1d977ccc436109cbcce64e95b27f93efc0f1dab739c9146eda2e") + XCTAssertEqual(pubAddress.metadata?.nonce, BigUInt("51eb06f7901d5a8562274d3e53437328ca41ad96926f075122f6bd50e31be52d", radix: 16)) + XCTAssertEqual(pubAddress.metadata?.upgraded, false) + XCTAssertEqual(pubAddress.metadata?.typeOfUser, UserType(rawValue: "v2")) + XCTAssertEqual(pubAddress.nodesData?.nodeIndexes.count, 3) } - func testLoginWhenHashEnabled () async throws { - - let exp1 = XCTestExpectation(description: "should be able to login when verifierID hash enabled") + func testLoginWhenHashEnabled() async throws { let email = TORUS_TEST_EMAIL let token = try generateIdToken(email: email) - let verifierParams = VerifierParams(verifier_id: email ) - - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: HashEnabledVerifier, veriferID: HashEnabledVerifier) - let result = try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), - torusNodePubs: nodeDetails.getTorusNodePub(),indexes: nodeDetails.getTorusIndexes(), - verifier: HashEnabledVerifier, verifierParams: verifierParams, idToken: token ) - XCTAssertEqual(result.finalKeyData?.evmAddress, "0xF79b5ffA48463eba839ee9C97D61c6063a96DA03") - XCTAssertEqual(result.finalKeyData?.X, "21cd0ae3168d60402edb8bd65c58ff4b3e0217127d5bb5214f03f84a76f24d8a") - XCTAssertEqual(result.finalKeyData?.Y, "575b7a4d0ef9921b3b1b84f30d412e87bc69b4eab83f6706e247cceb9e985a1e") - XCTAssertEqual(result.finalKeyData?.privKey, "066270dfa345d3d0415c8223e045f366b238b50870de7e9658e3c6608a7e2d32") - XCTAssertEqual(result.oAuthKeyData?.evmAddress, "0x4135ad20D2E9ACF37D64E7A6bD8AC34170d51219") - XCTAssertEqual(result.oAuthKeyData?.X, "9c591943683c0e5675f99626cea84153a3c5b72c6e7840f8b8b53d0f2bb50c67") - XCTAssertEqual(result.oAuthKeyData?.Y, "9d9896d82e565a2d5d437745af6e4560f3564c2ac0d0edcb72e0b508b3ac05a0") - XCTAssertEqual(result.oAuthKeyData?.privKey, "b47769e81328794adf3534e58d02803ca2a5e4588db81780f5bf679c77988946") - XCTAssertNotEqual(result.sessionData?.sessionTokenData.count, 0) - XCTAssertNotEqual(result.sessionData?.sessionAuthKey, "") - XCTAssertEqual(result.metadata?.pubNonce?.x, "d6404befc44e3ab77a8387829d77e9c77a9c2fb37ae314c3a59bdc108d70349d") - XCTAssertEqual(result.metadata?.pubNonce?.y, "1054dfe297f1d977ccc436109cbcce64e95b27f93efc0f1dab739c9146eda2e") - XCTAssertEqual(result.metadata?.nonce, BigUInt(hex: "51eb06f7901d5a8562274d3e53437328ca41ad96926f075122f6bd50e31be52d")) - XCTAssertEqual(result.metadata?.typeOfUser, .v2) - XCTAssertEqual(result.metadata?.upgraded, false) - XCTAssertNotEqual(result.nodesData?.nodeIndexes.count, 0) - exp1.fulfill() - } catch let error{ - XCTFail(error.localizedDescription) - exp1.fulfill() - } + let verifierParams = VerifierParams(verifier_id: email) + let nodeDetails = try await get_fnd_and_tu_data(verifer: HashEnabledVerifier, veriferID: HashEnabledVerifier) + let result = try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), + torusNodePubs: nodeDetails.getTorusNodePub(), indexes: nodeDetails.getTorusIndexes(), + verifier: HashEnabledVerifier, verifierParams: verifierParams, idToken: token) + XCTAssertEqual(result.finalKeyData?.evmAddress, "0xF79b5ffA48463eba839ee9C97D61c6063a96DA03") + XCTAssertEqual(result.finalKeyData?.X, "21cd0ae3168d60402edb8bd65c58ff4b3e0217127d5bb5214f03f84a76f24d8a") + XCTAssertEqual(result.finalKeyData?.Y, "575b7a4d0ef9921b3b1b84f30d412e87bc69b4eab83f6706e247cceb9e985a1e") + XCTAssertEqual(result.finalKeyData?.privKey, "066270dfa345d3d0415c8223e045f366b238b50870de7e9658e3c6608a7e2d32") + XCTAssertEqual(result.oAuthKeyData?.evmAddress, "0x4135ad20D2E9ACF37D64E7A6bD8AC34170d51219") + XCTAssertEqual(result.oAuthKeyData?.X, "9c591943683c0e5675f99626cea84153a3c5b72c6e7840f8b8b53d0f2bb50c67") + XCTAssertEqual(result.oAuthKeyData?.Y, "9d9896d82e565a2d5d437745af6e4560f3564c2ac0d0edcb72e0b508b3ac05a0") + XCTAssertEqual(result.oAuthKeyData?.privKey, "b47769e81328794adf3534e58d02803ca2a5e4588db81780f5bf679c77988946") + XCTAssertNotEqual(result.sessionData?.sessionTokenData.count, 0) + XCTAssertNotEqual(result.sessionData?.sessionAuthKey, "") + XCTAssertEqual(result.metadata?.pubNonce?.x, "d6404befc44e3ab77a8387829d77e9c77a9c2fb37ae314c3a59bdc108d70349d") + XCTAssertEqual(result.metadata?.pubNonce?.y, "1054dfe297f1d977ccc436109cbcce64e95b27f93efc0f1dab739c9146eda2e") + XCTAssertEqual(result.metadata?.nonce, BigUInt(hex: "51eb06f7901d5a8562274d3e53437328ca41ad96926f075122f6bd50e31be52d")) + XCTAssertEqual(result.metadata?.typeOfUser, .v2) + XCTAssertEqual(result.metadata?.upgraded, false) + XCTAssertNotEqual(result.nodesData?.nodeIndexes.count, 0) } - + func testAggregrateLoginWithEmail(email: String) async throws { - let exp1 = XCTestExpectation(description: "Should be able to aggregate login") - - print("email", email) let verifier: String = TORUS_TEST_AGGREGATE_VERIFIER let verifierID: String = email let jwt = try! generateIdToken(email: email) @@ -427,35 +312,27 @@ final class SapphireTest: XCTestCase { let endpoint = try await nodeManager.getNodeDetails(verifier: HashEnabledVerifier, verifierID: verifierID) let verifierParams = VerifierParams(verifier_id: verifierID) - do { - let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier, veriferID: verifierID) - - let data = try await torus.retrieveShares(endpoints: endpoint.torusNodeEndpoints, torusNodePubs: nodeDetails.getTorusNodePub(),indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: hashedIDToken, extraParams: extraParams) - - XCTAssertNotNil(data.finalKeyData?.evmAddress) - XCTAssertNotEqual(data.finalKeyData?.evmAddress, "") - XCTAssertNotNil(data.oAuthKeyData?.evmAddress) - XCTAssertEqual(data.metadata?.typeOfUser, .v2) - XCTAssertNotNil(data.metadata?.nonce) - XCTAssertEqual(data.metadata?.upgraded, false) - - exp1.fulfill() - } catch let err { - XCTFail(err.localizedDescription) - exp1.fulfill() - } + let nodeDetails = try await get_fnd_and_tu_data(verifer: verifier, veriferID: verifierID) + + let data = try await torus.retrieveShares(endpoints: endpoint.torusNodeEndpoints, torusNodePubs: nodeDetails.getTorusNodePub(), indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: hashedIDToken, extraParams: extraParams) + + XCTAssertNotNil(data.finalKeyData?.evmAddress) + XCTAssertNotEqual(data.finalKeyData?.evmAddress, "") + XCTAssertNotNil(data.oAuthKeyData?.evmAddress) + XCTAssertEqual(data.metadata?.typeOfUser, .v2) + XCTAssertNotNil(data.metadata?.nonce) + XCTAssertEqual(data.metadata?.upgraded, false) } - + func testAggregateLoginWithFixedEmail() async throws { // This fixed email was previously known to trigger an edge case that // revealed a bug in our share decryption implementation. let email = "hEJTRg@gmail.com" try await testAggregrateLoginWithEmail(email: email) } - + func testAggregateLoginWithRandomEmail() async throws { let email = generateRandomEmail(of: 6) try await testAggregrateLoginWithEmail(email: email) } - }