Skip to content

Commit

Permalink
Merge pull request #7 from tkey/feat/bump-torusUtils
Browse files Browse the repository at this point in the history
feat: bump torusUtils
  • Loading branch information
himanshuchawla009 authored Apr 8, 2024
2 parents 4731b8a + 6b6d405 commit 7f3b7ef
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/session-manager-swift.git",
"state" : {
"revision" : "290e36cd0646f7fb3be737b65bdfc9f5428dfd5c",
"version" : "3.1.0"
"revision" : "c89d9205a1ce38cd6c6374b906a9039d9cc03f05",
"version" : "3.1.1"
}
},
{
"identity" : "single-factor-auth-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/single-factor-auth-swift",
"state" : {
"revision" : "f2f56e8b7002a84ac4f4d2028570c51343a3e49f",
"revision" : "8baa2b8cf55b0a38cb98c412bea1c6597adb78ba",
"version" : "4.0.0"
}
},
Expand Down Expand Up @@ -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"
}
},
{
Expand Down
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 7f3b7ef

Please sign in to comment.