diff --git a/Package.resolved b/Package.resolved index 0c785ed..0cbc1b0 100644 --- a/Package.resolved +++ b/Package.resolved @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Web3Auth/session-manager-swift.git", "state" : { - "revision" : "290e36cd0646f7fb3be737b65bdfc9f5428dfd5c", - "version" : "3.1.0" + "revision" : "c89d9205a1ce38cd6c6374b906a9039d9cc03f05", + "version" : "3.1.1" } }, { @@ -95,7 +95,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Web3Auth/single-factor-auth-swift", "state" : { - "revision" : "f2f56e8b7002a84ac4f4d2028570c51343a3e49f", + "revision" : "8baa2b8cf55b0a38cb98c412bea1c6597adb78ba", "version" : "4.0.0" } }, @@ -140,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "revision" : "04c62fd5f73f21bd01b7c07e08f6135db26c5940", - "version" : "8.0.0" + "revision" : "4c17ef5166c162455d0a37115c033eeff8cb282d", + "version" : "8.0.1" } }, { diff --git a/Sources/mpc-core-kit-swift/Helper.swift b/Sources/mpc-core-kit-swift/Helper.swift index 1c95fc1..61982ea 100644 --- a/Sources/mpc-core-kit-swift/Helper.swift +++ b/Sources/mpc-core-kit-swift/Helper.swift @@ -11,6 +11,10 @@ import tkey_mpc_swift import BigInt import curveSecp256k1 +import SingleFactorAuth + +import CommonSources + func convertPublicKeyFormat ( publicKey: String, outFormat: PublicKeyEncoding ) throws -> String { let point = try KeyPoint(address: publicKey) let result = try point.getPublicKey(format: outFormat) @@ -60,3 +64,23 @@ public class MemoryStorage : ILocalStorage { memory.updateValue(payload, forKey: key) } } + + +func convertWeb3AuthNetworkToTorusNetWork ( network: Web3AuthNetwork ) -> TorusNetwork { + switch network { + case Web3AuthNetwork.SAPPHIRE_DEVNET : return .sapphire(.SAPPHIRE_DEVNET); + case Web3AuthNetwork.SAPPHIRE_MAINNET : return .sapphire(.SAPPHIRE_MAINNET); + case Web3AuthNetwork.MAINNET : return .legacy(.MAINNET); + case Web3AuthNetwork.TESTNET: return .legacy(.TESTNET); + case Web3AuthNetwork.CYAN: return .legacy(.CYAN); + case Web3AuthNetwork.AQUA: return .legacy(.AQUA); + case Web3AuthNetwork.CELESTE: return .legacy(.CELESTE); + case Web3AuthNetwork.CUSTOM(_): return .sapphire(.SAPPHIRE_MAINNET); + } +} + +public extension Web3AuthNetwork { + func toTorusNetwork () -> TorusNetwork{ + return convertWeb3AuthNetworkToTorusNetWork(network: self) + } +} diff --git a/Sources/mpc-core-kit-swift/Interface.swift b/Sources/mpc-core-kit-swift/Interface.swift index 04cd36b..5e28c65 100644 --- a/Sources/mpc-core-kit-swift/Interface.swift +++ b/Sources/mpc-core-kit-swift/Interface.swift @@ -8,6 +8,7 @@ import Foundation import CommonSources import tkey_mpc_swift +import SingleFactorAuth public protocol ILocalStorage { func set(key:String, payload: Data ) async throws -> Void @@ -23,7 +24,7 @@ public protocol IFactorStorage { public struct CoreKitOptions { public var disableHashFactor : Bool public var Web3AuthClientId : String - public var network : TorusNetwork + public var network : Web3AuthNetwork } public struct CoreKitAppState :Codable, Equatable { diff --git a/Sources/mpc-core-kit-swift/mpcCoreKitSwift.swift b/Sources/mpc-core-kit-swift/mpcCoreKitSwift.swift index 4abfad5..7ba0bb7 100644 --- a/Sources/mpc-core-kit-swift/mpcCoreKitSwift.swift +++ b/Sources/mpc-core-kit-swift/mpcCoreKitSwift.swift @@ -24,7 +24,7 @@ public struct MpcCoreKit { internal var factorKey: String?; internal var oauthKey: String?; - internal var network: TorusNetwork; + internal var network: Web3AuthNetwork; internal var option: CoreKitOptions; internal var appState : CoreKitAppState; @@ -54,16 +54,16 @@ public struct MpcCoreKit { // init - public init( web3AuthClientId : String , web3AuthNetwork: TorusNetwork, disableHashFactor : Bool = false, localStorage: ILocalStorage ) { + public init( web3AuthClientId : String , web3AuthNetwork: Web3AuthNetwork, disableHashFactor : Bool = false, localStorage: ILocalStorage ) { self.option = .init(disableHashFactor: disableHashFactor , Web3AuthClientId: web3AuthClientId, network: web3AuthNetwork) self.appState = CoreKitAppState.init() self.network = web3AuthNetwork self.torusUtils = TorusUtils( enableOneKey: true, - network: self.network, clientId: web3AuthClientId ) + network: self.network.toTorusNetwork(), clientId: web3AuthClientId ) - self.nodeDetailsManager = NodeDetailManager(network: self.network) + self.nodeDetailsManager = NodeDetailManager(network: self.network.toTorusNetwork()) self.coreKitStorage = .init(storeKey: self.storeKey, storage: localStorage) @@ -109,7 +109,7 @@ public struct MpcCoreKit { browserRedirectURL: browserRedirectURL, jwtParams: jwtParams ) - let customAuth = CustomAuth(web3AuthClientId: option.Web3AuthClientId, aggregateVerifierType: .singleLogin, aggregateVerifier: verifier, subVerifierDetails: [sub], network: self.network, enableOneKey: true) + let customAuth = CustomAuth(web3AuthClientId: option.Web3AuthClientId, aggregateVerifierType: .singleLogin, aggregateVerifier: verifier, subVerifierDetails: [sub], network: self.network.toTorusNetwork(), enableOneKey: true) let userData = try await customAuth.triggerLogin() return try await self.login(userData: userData) diff --git a/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift b/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift index 1a0d7f5..461042c 100644 --- a/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift +++ b/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift @@ -2,6 +2,7 @@ import XCTest @testable import mpc_core_kit_swift import JWTKit import curveSecp256k1 +import SingleFactorAuth // JWT payload structure. struct TestPayload: JWTPayload, Equatable { @@ -100,7 +101,7 @@ final class mpc_kit_swiftTests: XCTestCase { // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods let memoryStorage = MemoryStorage() - var coreKitInstance = MpcCoreKit( web3AuthClientId: "torus-test-health", web3AuthNetwork: .sapphire(.SAPPHIRE_DEVNET), disableHashFactor: false, localStorage: memoryStorage) + var coreKitInstance = MpcCoreKit( web3AuthClientId: "torus-test-health", web3AuthNetwork: Web3AuthNetwork.SAPPHIRE_DEVNET, disableHashFactor: false, localStorage: memoryStorage) let email = "testiosEmail004" let verifier = "torus-test-health" let data = try mockLogin2(email: email)