From e1e5f66f28496666b754d784401d8815210630f7 Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Thu, 16 May 2024 07:29:24 +0200 Subject: [PATCH] implement getOrSetSapphireMetadataNonce --- .../TorusUtils/Helpers/MetadataUtils.swift | 8 ++ Sources/TorusUtils/Helpers/NodeUtils.swift | 83 +++++++++++-------- .../TorusUtils/Interfaces/TorusOptions.swift | 2 +- Sources/TorusUtils/TorusUtils.swift | 23 +++-- Tests/TorusUtilsTests/AquaTest.swift | 2 +- Tests/TorusUtilsTests/Celeste.swift | 2 +- Tests/TorusUtilsTests/CyanTest.swift | 2 +- Tests/TorusUtilsTests/MainnetTest.swift | 2 +- .../TorusUtilsTests/SapphireDevnetTest.swift | 2 +- .../SapphireMainnetTests.swift | 5 +- Tests/TorusUtilsTests/TestnetTest.swift | 2 +- Tests/TorusUtilsTests/oneKeyTest.swift | 2 +- 12 files changed, 84 insertions(+), 51 deletions(-) diff --git a/Sources/TorusUtils/Helpers/MetadataUtils.swift b/Sources/TorusUtils/Helpers/MetadataUtils.swift index 437a08bb..ea14449e 100644 --- a/Sources/TorusUtils/Helpers/MetadataUtils.swift +++ b/Sources/TorusUtils/Helpers/MetadataUtils.swift @@ -122,4 +122,12 @@ internal class MetadataUtils { public static func getNonce(legacyMetadataHost: String, serverTimeOffset: Int, X: String, Y: String, privateKey: String? = nil, getOnly: Bool = false) async throws -> GetOrSetNonceResult { return try await getOrSetNonce(legacyMetadataHost: legacyMetadataHost, serverTimeOffset: serverTimeOffset, X: X, Y: Y, privateKey: privateKey, getOnly: true) } + + public static func getOrSetSapphireMetadataNonce(legacyMetadataHost: String, network: TorusNetwork, X: String, Y: String, serverTimeOffset: Int, privateKey: String? = nil, getOnly: Bool = false) async throws -> GetOrSetNonceResult { + if case .sapphire = network { + return try await getOrSetNonce(legacyMetadataHost: legacyMetadataHost, serverTimeOffset: serverTimeOffset, X: X, Y: Y) + } else { + throw TorusUtilError.metadataNonceMissing + } + } } diff --git a/Sources/TorusUtils/Helpers/NodeUtils.swift b/Sources/TorusUtils/Helpers/NodeUtils.swift index eb81dc28..33021891 100644 --- a/Sources/TorusUtils/Helpers/NodeUtils.swift +++ b/Sources/TorusUtils/Helpers/NodeUtils.swift @@ -12,6 +12,7 @@ internal class NodeUtils { network: TorusNetwork, verifier: String, verifierId: String, + legacyMetadataHost: String, extendedVerifierId: String? = nil) async throws -> KeyLookupResult { let threshold = Int(trunc(Double((endpoints.count / 2) + 1))) @@ -27,8 +28,8 @@ internal class NodeUtils { var nonceResult: GetOrSetNonceResult? var nodeIndexes: [Int] = [] - let minRequired = Int(trunc(Double((endpoints.count * 3 / 4))+1)) - + let minRequired = Int(trunc(Double(endpoints.count * 3 / 4) + 1)) + let lookupResults: [JRPCResponse?] = try await withThrowingTaskGroup(of: JRPCResponse?.self, returning: [JRPCResponse?].self) { group -> [JRPCResponse?] in var received: Int = 0 for endpoint in endpoints { @@ -65,15 +66,14 @@ internal class NodeUtils { let keyResult = try thresholdSame(arr: normalizedKeyResults, threshold: threshold) - // Note: The condition for nonceResult will always pass as it was never assigned if keyResult != nil && nonceResult == nil && extendedVerifierId == nil && !TorusUtils.isLegacyNetworkRouteMap(network: network) { for i in 0 ..< lookupResults.count { let x1 = lookupResults[i] if x1 != nil && x1?.error == nil { - let currentNodePubKey = x1!.result!.keys[0].pub_key_X.lowercased() - let thresholdPubKey = keyResult!.keys[0].pub_key_X.lowercased() - let pubNonceX: String? = x1!.result!.keys[0].nonce_data?.pubNonce?.x - if pubNonceX != nil && currentNodePubKey == thresholdPubKey { + let currentNodePubKeyX = x1!.result!.keys[0].pub_key_X.addLeading0sForLength64().lowercased() + let thresholdPubKeyX = keyResult!.keys[0].pub_key_X.addLeading0sForLength64().lowercased() + let pubNonce: PubNonce? = x1!.result!.keys[0].nonce_data?.pubNonce + if pubNonce != nil && currentNodePubKeyX == thresholdPubKeyX { nonceResult = x1?.result?.keys[0].nonce_data break } @@ -101,6 +101,16 @@ internal class NodeUtils { } let serverTimeOffset = (keyResult != nil) ? calculateMedian(arr: serverTimeOffsets) : 0 + + if case .sapphire = network { + let X: BigInt = BigInt(nonceResult?.pubNonce?.x ?? "0", radix: 16) ?? BigInt(0) + let Y: BigInt = BigInt(nonceResult?.pubNonce?.x ?? "0", radix: 16) ?? BigInt(0) + if nonceResult == nil || (X == BigInt(0) && Y == BigInt(0)) { + let metadataNonce = try await MetadataUtils.getOrSetSapphireMetadataNonce(legacyMetadataHost: legacyMetadataHost, network: network, X: keyResult!.keys[0].pub_key_X, Y: keyResult!.keys[0].pub_key_Y, serverTimeOffset: serverTimeOffset, getOnly: false) + nonceResult = metadataNonce + } + } + return KeyLookupResult( keyResult: keyResult, nodeIndexes: nodeIndexes, @@ -168,8 +178,8 @@ internal class NodeUtils { encoder.outputFormatting = .sortedKeys let rpcdata = try encoder.encode(jsonRPCRequest) - let minRequired = Int(trunc(Double((endpoints.count * 3 / 4))+1)) - + let minRequired = Int(trunc(Double(endpoints.count * 3 / 4) + 1)) + let commitmentRequestResults: [JRPCResponse?] = try await withThrowingTaskGroup(of: JRPCResponse?.self, returning: [JRPCResponse?].self) { group -> [JRPCResponse?] in var received: Int = 0 for endpoint in endpoints { @@ -200,10 +210,6 @@ internal class NodeUtils { let completedCommitmentRequests = commitmentRequestResults.filter({ $0 != nil && $0?.error == nil }) - // Invert first comparision in corresponding javascript to return error case early - // Comment: Refactor javascript to not chain and embed promises within promises - // as extensively as it has been currently implemented - if importedShareCount > 0 && !(commitmentRequestResults.count == endpoints.count) { throw TorusUtilError.commitmentRequestFailed } @@ -327,18 +333,34 @@ internal class NodeUtils { } for item in shareResponses { - // first check will always pass as it is never assigned if thresholdNonceData == nil && verifierParams.extended_verifier_id == nil { - let currentPubKey = item.keys[0].publicKey - let pubNonce = item.keys[0].nonceData?.pubNonce?.x - if pubNonce != nil && currentPubKey.X == thresholdPublicKey!.X { + let currentPubKeyX = item.keys[0].publicKey.X.addLeading0sForLength64().lowercased() + let thesholdPubKeyX = thresholdPublicKey!.X.addLeading0sForLength64().lowercased() + let pubNonce: PubNonce? = item.keys[0].nonceData?.pubNonce + if pubNonce != nil && currentPubKeyX == thesholdPubKeyX { thresholdNonceData = item.keys[0].nonceData } } } + + var serverTimeOffsets: [String] = [] + for item in shareResponses { + serverTimeOffsets.append(item.serverTimeOffset) + } + let serverOffsetTimes = serverTimeOffsets.map({ Int($0) ?? 0 }) - if thresholdNonceData == nil && verifierParams.extended_verifier_id == nil && !TorusUtils.isLegacyNetworkRouteMap(network: network) { - throw TorusUtilError.runtime("invalid metadata result from nodes, nonce metadata is empty") + let serverTimeOffsetResponse: Int = serverTimeOffset ?? calculateMedian(arr: serverOffsetTimes) + + let nX: BigInt = BigInt(thresholdNonceData?.pubNonce?.x ?? "0", radix: 16) ?? BigInt(0) + let nY: BigInt = BigInt(thresholdNonceData?.pubNonce?.x ?? "0", radix: 16) ?? BigInt(0) + + if (thresholdNonceData == nil || (nX == BigInt(0) && nY == BigInt(0))) && verifierParams.extended_verifier_id == nil && !TorusUtils.isLegacyNetworkRouteMap(network: network) { + if case .sapphire = network { + let metadataNonce = try await MetadataUtils.getOrSetSapphireMetadataNonce(legacyMetadataHost: legacyMetadataHost, network: network, X: thresholdPublicKey!.X, Y: thresholdPublicKey!.Y, serverTimeOffset: serverTimeOffsetResponse, getOnly: false) + thresholdNonceData = metadataNonce + } else { + throw TorusUtilError.runtime("invalid metadata result from nodes, nonce metadata is empty") + } } let thresholdReqCount = (importedShares != nil && importedShares!.count > 0) ? endpoints.count : threshold @@ -354,11 +376,9 @@ internal class NodeUtils { var nodeIndexes: [Int?] = [] var sessionTokenDatas: [SessionToken?] = [] var isNewKeys: [String] = [] - var serverTimeOffsets: [String] = [] for item in shareResponses { isNewKeys.append(item.isNewKey) - serverTimeOffsets.append(item.serverTimeOffset) if !item.sessionTokenSigs.isEmpty { if !item.sessionTokenSigMetadata.isEmpty { @@ -457,14 +477,10 @@ internal class NodeUtils { let thresholdIsNewKey = try thresholdSame(arr: isNewKeys, threshold: threshold) - let serverOffsetTimes = serverTimeOffsets.map({ Int($0) ?? 0 }) - - let serverTimeOffsetResponse: Int = serverTimeOffset ?? calculateMedian(arr: serverOffsetTimes) - let oAuthKey = privateKey!.addLeading0sForLength64() let oAuthPublicKey = try SecretKey(hex: oAuthKey).toPublic().serialize(compressed: false) let (oAuthPublicKeyX, oAuthPublicKeyY) = try KeyUtils.getPublicKeyCoords(pubKey: oAuthPublicKey) - var metadataNonce = BigInt(thresholdNonceData?.nonce?.addLeading0sForLength64() ?? "0", radix: 16) + var metadataNonce = BigInt(thresholdNonceData?.nonce?.addLeading0sForLength64() ?? "0", radix: 16) ?? BigInt(0) var finalPubKey: String? var pubNonce: PubNonce? var typeOfUser: UserType = .v1 @@ -474,7 +490,7 @@ internal class NodeUtils { } else if TorusUtils.isLegacyNetworkRouteMap(network: network) { if enableOneKey { let nonce = try await MetadataUtils.getOrSetNonce(legacyMetadataHost: legacyMetadataHost, serverTimeOffset: serverTimeOffsetResponse, X: oAuthPublicKeyX, Y: oAuthPublicKeyY, getOnly: !(Bool(thresholdIsNewKey ?? "true")!)) - metadataNonce = BigInt(nonce.nonce?.addLeading0sForLength64() ?? "0", radix: 16) + metadataNonce = BigInt(nonce.nonce?.addLeading0sForLength64() ?? "0", radix: 16) ?? BigInt(0) typeOfUser = UserType(rawValue: nonce.typeOfUser?.lowercased() ?? "v1")! if typeOfUser == .v2 { pubNonce = nonce.pubNonce @@ -483,17 +499,16 @@ internal class NodeUtils { } else { typeOfUser = .v1 metadataNonce = BigInt(try await MetadataUtils.getMetadata(legacyMetadataHost: legacyMetadataHost, dictionary: ["pub_key_X": oAuthPublicKeyX, "pub_key_Y": oAuthPublicKeyY])) - let privateKeyWithNonce = (BigInt(oAuthKey, radix: 16)! + BigInt(metadataNonce!)).modulus(KeyUtils.getOrderOfCurve()) + let privateKeyWithNonce = (BigInt(oAuthKey, radix: 16)! + BigInt(metadataNonce)).modulus(KeyUtils.getOrderOfCurve()) finalPubKey = try SecretKey(hex: privateKeyWithNonce.magnitude.serialize().hexString.addLeading0sForLength64()).toPublic().serialize(compressed: false) } } else { typeOfUser = .v1 metadataNonce = BigInt(try await MetadataUtils.getMetadata(legacyMetadataHost: legacyMetadataHost, dictionary: ["pub_key_X": oAuthPublicKeyX, "pub_key_Y": oAuthPublicKeyY])) - let privateKeyWithNonce = (BigInt(oAuthKey, radix: 16)! + BigInt(metadataNonce!)).modulus(KeyUtils.getOrderOfCurve()) + let privateKeyWithNonce = (BigInt(oAuthKey, radix: 16)! + BigInt(metadataNonce)).modulus(KeyUtils.getOrderOfCurve()) finalPubKey = try SecretKey(hex: privateKeyWithNonce.magnitude.serialize().hexString.addLeading0sForLength64()).toPublic().serialize(compressed: false) } } else { - // TODO: BUG: Nonce is returned as (x=0,y=0) sometimes, this is invalid investigate further typeOfUser = .v2 let publicNonce = KeyUtils.getPublicKeyFromCoords(pubKeyX: thresholdNonceData!.pubNonce!.x, pubKeyY: thresholdNonceData!.pubNonce!.y) let oAuthPubKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: oAuthPublicKeyX, pubKeyY: oAuthPublicKeyY) @@ -511,14 +526,14 @@ internal class NodeUtils { let finalEvmAddress = try KeyUtils.generateAddressFromPubKey(publicKeyX: finalPubX, publicKeyY: finalPubY) var finalPrivKey = "" - if typeOfUser == .v1 || (typeOfUser == .v2 && metadataNonce! > BigInt(0)) { - let privateKeyWithNonce = ((BigInt(oAuthKey, radix: 16) ?? BigInt(0)) + metadataNonce!).modulus(KeyUtils.getOrderOfCurve()) + if typeOfUser == .v1 || (typeOfUser == .v2 && metadataNonce > BigInt(0)) { + let privateKeyWithNonce = ((BigInt(oAuthKey, radix: 16) ?? BigInt(0)) + metadataNonce).modulus(KeyUtils.getOrderOfCurve()) finalPrivKey = privateKeyWithNonce.magnitude.serialize().hexString.addLeading0sForLength64() } var isUpgraded: Bool? if typeOfUser == .v2 { - isUpgraded = metadataNonce! == BigInt(0) + isUpgraded = metadataNonce == BigInt(0) } return TorusKey( @@ -537,7 +552,7 @@ internal class NodeUtils { sessionAuthKey: sessionAuthKeySerialized), metadata: TorusPublicKey.Metadata( pubNonce: pubNonce, - nonce: metadataNonce?.magnitude, + nonce: metadataNonce.magnitude, typeOfUser: typeOfUser, upgraded: isUpgraded, serverTimeOffset: serverTimeOffsetResponse), diff --git a/Sources/TorusUtils/Interfaces/TorusOptions.swift b/Sources/TorusUtils/Interfaces/TorusOptions.swift index 7566de97..2dd1795e 100644 --- a/Sources/TorusUtils/Interfaces/TorusOptions.swift +++ b/Sources/TorusUtils/Interfaces/TorusOptions.swift @@ -19,7 +19,7 @@ public class TorusOptions { /// - enableOneKey: Use the oneKey flow. /// /// - Returns: `TorusOptions` - public init(clientId: String, network: TorusNetwork, legacyMetadataHost: String = "https://metadata.tor.us", serverTimeOffset: Int = 0, enableOneKey: Bool = false) { + public init(clientId: String, network: TorusNetwork, legacyMetadataHost: String? = nil, serverTimeOffset: Int = 0, enableOneKey: Bool = false) { self.clientId = clientId self.enableOneKey = enableOneKey self.network = network diff --git a/Sources/TorusUtils/TorusUtils.swift b/Sources/TorusUtils/TorusUtils.swift index 0a76dee1..d590f690 100644 --- a/Sources/TorusUtils/TorusUtils.swift +++ b/Sources/TorusUtils/TorusUtils.swift @@ -38,13 +38,24 @@ public class TorusUtils { /// - logLevel: `OSLogType`, only needs to be provided if the default logging level should be changed /// /// - Returns: `TorusUtils` - public init(params: TorusOptions, loglevel: OSLogType = .default) { + /// + /// - Throws: `TorusUtilError.invalidInput` + public init(params: TorusOptions, loglevel: OSLogType = .default) throws { var defaultHost = "" if params.legacyMetadataHost == nil { if case let .legacy(urlHost) = params.network { defaultHost = urlHost.metadataMap } else { - defaultHost = (LegacyNetwork.MAINNET.metadataMap) + // TODO: Move this into fetchNodeDetails metadataMap + if case let .sapphire(sapphireNetwork) = params.network { + if sapphireNetwork == .SAPPHIRE_MAINNET { + defaultHost = "https://node-1.node.web3auth.io/metadata" + } else { + defaultHost = "https://node-1.dev-node.web3auth.io/metadata" + } + } else { + throw TorusUtilError.invalidInput + } } } else { defaultHost = params.legacyMetadataHost! @@ -208,7 +219,8 @@ public class TorusUtils { throw TorusUtilError.runtime("Missing node pub key for node index") } let shareJson = try encoder.encode(share) - enc.append(try MetadataUtils.encrypt(publicKey: KeyUtils.getPublicKeyFromCoords(pubKeyX: nodePubs[i].X, pubKeyY: nodePubs[i].Y), msg: share!.share.magnitude.serialize().hexString.addLeading0sForLength64())) + let encPubKey = try PublicKey(hex: KeyUtils.getPublicKeyFromCoords(pubKeyX: nodePubs[i].X, pubKeyY: nodePubs[i].Y)) + enc.append(try MetadataUtils.encrypt(publicKey: encPubKey.serialize(compressed: true), msg: share!.share.magnitude.serialize().hexString.addLeading0sForLength64())) jsonShares.append(shareJson) } @@ -276,7 +288,7 @@ public class TorusUtils { } private func getNewPublicAddress(endpoints: [String], verifier: String, verifierId: String, extendedVerifierId: String? = nil, enableOneKey: Bool) async throws -> TorusPublicKey { - let keyAssignResult = try await NodeUtils.getPubKeyOrKeyAssign(endpoints: endpoints, network: network, verifier: verifier, verifierId: verifierId, extendedVerifierId: extendedVerifierId) + let keyAssignResult = try await NodeUtils.getPubKeyOrKeyAssign(endpoints: endpoints, network: network, verifier: verifier, verifierId: verifierId, legacyMetadataHost: legacyMetadataHost, extendedVerifierId: extendedVerifierId) if keyAssignResult.errorResult != nil { let error = keyAssignResult.errorResult!.message @@ -298,7 +310,7 @@ public class TorusUtils { let pubKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: keyAssignResult.keyResult!.keys[0].pub_key_X, pubKeyY: keyAssignResult.keyResult!.keys[0].pub_key_Y) var pubNonce: PubNonce? - let nonce: BigUInt = BigUInt(keyAssignResult.nonceResult?.nonce ?? "0", radix: 16)! + let nonce: BigUInt = BigUInt(keyAssignResult.nonceResult?.nonce ?? "0", radix: 16) ?? BigUInt(0) var oAuthPubKey: String? var finalPubKey: String? @@ -315,7 +327,6 @@ public class TorusUtils { let legacyResult = LegacyVerifierLookupResponse(keys: legacyKeysResult, serverTimeOffset: String(finalServerTimeOffset)) return try await formatLegacyPublicKeyData(finalKeyResult: legacyResult, enableOneKey: enableOneKey, isNewKey: keyAssignResult.keyResult!.is_new_key, serverTimeOffset: finalServerTimeOffset) } else { - // TODO: BUG: Nonce is returned as (x=0,y=0) sometimes, this is invalid investigate further let pubNonceResult = keyAssignResult.nonceResult!.pubNonce! oAuthPubKey = pubKey let pubNonceKey = KeyUtils.getPublicKeyFromCoords(pubKeyX: pubNonceResult.x, pubKeyY: pubNonceResult.y) diff --git a/Tests/TorusUtilsTests/AquaTest.swift b/Tests/TorusUtilsTests/AquaTest.swift index 265ddda9..9ead7485 100644 --- a/Tests/TorusUtilsTests/AquaTest.swift +++ b/Tests/TorusUtilsTests/AquaTest.swift @@ -14,7 +14,7 @@ class AquaTest: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .legacy(.AQUA)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.AQUA))) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.AQUA))) } func test_should_fetch_public_address() async throws { diff --git a/Tests/TorusUtilsTests/Celeste.swift b/Tests/TorusUtilsTests/Celeste.swift index fb2e4bce..7ad380cc 100644 --- a/Tests/TorusUtilsTests/Celeste.swift +++ b/Tests/TorusUtilsTests/Celeste.swift @@ -14,7 +14,7 @@ class CelesteTest: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .legacy(.CELESTE)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.CELESTE))) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.CELESTE))) } func test_should_fetch_public_address() async throws { diff --git a/Tests/TorusUtilsTests/CyanTest.swift b/Tests/TorusUtilsTests/CyanTest.swift index 2f72c820..e4cadb5c 100644 --- a/Tests/TorusUtilsTests/CyanTest.swift +++ b/Tests/TorusUtilsTests/CyanTest.swift @@ -14,7 +14,7 @@ class CyanTest: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .legacy(.CYAN)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.CYAN))) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.CYAN))) } func test_should_fetch_public_address() async throws { diff --git a/Tests/TorusUtilsTests/MainnetTest.swift b/Tests/TorusUtilsTests/MainnetTest.swift index 203e1ba7..09fa1628 100644 --- a/Tests/TorusUtilsTests/MainnetTest.swift +++ b/Tests/TorusUtilsTests/MainnetTest.swift @@ -21,7 +21,7 @@ class MainnetTests: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .legacy(.MAINNET)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.MAINNET))) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.MAINNET))) } func test_should_fetch_public_address() async throws { diff --git a/Tests/TorusUtilsTests/SapphireDevnetTest.swift b/Tests/TorusUtilsTests/SapphireDevnetTest.swift index 07434397..7e4756ee 100644 --- a/Tests/TorusUtilsTests/SapphireDevnetTest.swift +++ b/Tests/TorusUtilsTests/SapphireDevnetTest.swift @@ -21,7 +21,7 @@ final class SapphireDevnetTest: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .sapphire(.SAPPHIRE_DEVNET)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .sapphire(.SAPPHIRE_DEVNET))) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .sapphire(.SAPPHIRE_DEVNET))) } func test_should_fetch_public_address() async throws { diff --git a/Tests/TorusUtilsTests/SapphireMainnetTests.swift b/Tests/TorusUtilsTests/SapphireMainnetTests.swift index 1baf6c66..d1048429 100644 --- a/Tests/TorusUtilsTests/SapphireMainnetTests.swift +++ b/Tests/TorusUtilsTests/SapphireMainnetTests.swift @@ -24,7 +24,7 @@ class SapphireMainnetTests: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .sapphire(.SAPPHIRE_MAINNET)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true)) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true)) } func test_should_fetch_public_address() async throws { @@ -49,7 +49,6 @@ class SapphireMainnetTests: XCTestCase { XCTAssertNotNil(val.nodesData) } - // TODO: fix import share code, further debugging /* func test_should_be_able_to_import_key_for_a_new_user() async throws { let fakeEmail = generateRandomEmail(of: 6) @@ -67,7 +66,7 @@ class SapphireMainnetTests: XCTestCase { XCTAssertEqual(val.finalKeyData.privKey, privateKey) } - */ + */ func test_should_be_able_to_key_assign() async throws { let fakeEmail = generateRandomEmail(of: 6) diff --git a/Tests/TorusUtilsTests/TestnetTest.swift b/Tests/TorusUtilsTests/TestnetTest.swift index 54874849..c73b26fb 100644 --- a/Tests/TorusUtilsTests/TestnetTest.swift +++ b/Tests/TorusUtilsTests/TestnetTest.swift @@ -14,7 +14,7 @@ class TestnetTest: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .legacy(.TESTNET)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.TESTNET))) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.TESTNET))) } func test_should_fetch_public_address() async throws { diff --git a/Tests/TorusUtilsTests/oneKeyTest.swift b/Tests/TorusUtilsTests/oneKeyTest.swift index feb950ec..1b02624e 100644 --- a/Tests/TorusUtilsTests/oneKeyTest.swift +++ b/Tests/TorusUtilsTests/oneKeyTest.swift @@ -14,7 +14,7 @@ class OneKeyTest: XCTestCase { override func setUp() { super.setUp() fnd = NodeDetailManager(network: .legacy(.TESTNET)) - torus = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.TESTNET), enableOneKey: true)) + torus = try! TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .legacy(.TESTNET), enableOneKey: true)) } func test_should_still_fetch_v1_address_correctly() async throws {