Skip to content

Commit

Permalink
fix: update TorusNetwork to Web3AuthNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Apr 8, 2024
1 parent 30d9764 commit 6b6d405
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
24 changes: 24 additions & 0 deletions Sources/mpc-core-kit-swift/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
3 changes: 2 additions & 1 deletion Sources/mpc-core-kit-swift/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions Sources/mpc-core-kit-swift/mpcCoreKitSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6b6d405

Please sign in to comment.