From 7f8f4b0b967fc42422bbd08d8427bd46c29b871b Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:14:03 +0200 Subject: [PATCH] update dependencies --- Package.resolved | 63 ++++++------------- Package.swift | 10 ++- Sources/mpc-core-kit-swift/CoreKitError.swift | 3 + .../DeviceFactorStorage.swift | 2 +- Sources/mpc-core-kit-swift/Helper.swift | 1 - Sources/mpc-core-kit-swift/Interface.swift | 1 - .../mpc-core-kit-swift/MpcCoreKitSwift.swift | 16 ++--- Sources/mpc-core-kit-swift/Tss.swift | 8 +-- .../core/Web3AuthOptions.swift | 4 +- .../mpc_kit_swiftTests.swift | 11 ++-- 10 files changed, 45 insertions(+), 74 deletions(-) diff --git a/Package.resolved b/Package.resolved index f93d197..ff8db62 100644 --- a/Package.resolved +++ b/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tkey/curvelib.swift", "state" : { - "revision" : "9f88bd5e56d1df443a908f7a7e81ae4f4d9170ea", - "version" : "1.0.1" + "revision" : "432bf1abe7ff505fc2ac9fcf697341ff5b2dc6d0", + "version" : "2.0.0" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/customauth-swift-sdk", "state" : { - "branch" : "features_update", - "revision" : "72a83f30942b1f87cbed7eac5b1c5a164e91d1d4" + "revision" : "b3d0079bb1683d9daba95c349a072e60c8390328", + "version" : "11.0.1" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/fetch-node-details-swift.git", "state" : { - "revision" : "4bd96c33ba8d02d9e27190c5c7cedf09cfdfd656", - "version" : "6.0.3" + "revision" : "52fb5efaa94e0fe3775913ab00964bcb51601c2a", + "version" : "8.0.0" } }, { @@ -50,35 +50,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/auth0/JWTDecode.swift.git", "state" : { - "revision" : "58af7278797871e460d79496621b3e5366b865b2", - "version" : "3.1.0" - } - }, - { - "identity" : "keychain-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/evgenyneu/keychain-swift.git", - "state" : { - "revision" : "d108a1fa6189e661f91560548ef48651ed8d93b9", - "version" : "20.0.0" - } - }, - { - "identity" : "session-manager-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Web3Auth/session-manager-swift.git", - "state" : { - "revision" : "20cc7bff065d7fe53164d17e7714a3f17d4cea2a", - "version" : "4.0.2" - } - }, - { - "identity" : "single-factor-auth-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Web3Auth/single-factor-auth-swift", - "state" : { - "branch" : "7.0.0", - "revision" : "d9a8fd7885e37e74e61010f8fb240cbbafd1e577" + "revision" : "1e153ef009969543191970c66b7c60163c0b4a65", + "version" : "3.2.0" } }, { @@ -86,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/socketio/socket.io-client-swift", "state" : { - "revision" : "175da8b5156f6b132436f0676cc84c2f6a766b6e", - "version" : "16.1.0" + "revision" : "42da871d9369f290d6ec4930636c40672143905b", + "version" : "16.1.1" } }, { @@ -95,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/daltoniam/Starscream", "state" : { - "revision" : "ac6c0fc9da221873e01bd1a0d4818498a71eef33", - "version" : "4.0.6" + "revision" : "c6bfd1af48efcc9a9ad203665db12375ba6b145a", + "version" : "4.0.8" } }, { @@ -113,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tkey/tkey-mpc-swift", "state" : { - "branch" : "update_features", - "revision" : "00ed189447df83681092aabd5c64e65671ccd0d1" + "branch" : "encapsulate_torusnetwork", + "revision" : "73158e73e109e59ec7e7a9f9fdd9c70759a04d7b" } }, { @@ -122,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "revision" : "303dc2cf41db7c10f769855edad0e717ced2d554", - "version" : "9.0.0" + "revision" : "baa822fc67bdb208ed1a2dc5b3c10485cfca15df", + "version" : "10.0.0" } }, { @@ -131,8 +104,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/tss-client-swift.git", "state" : { - "revision" : "40246d5e3ff1d2c97d41846576f7a81d58858981", - "version" : "4.0.0" + "revision" : "4eadb32baed827d5e0600ee4f5c099259c45631c", + "version" : "5.0.0" } } ], diff --git a/Package.swift b/Package.swift index f94c03a..0a8c513 100644 --- a/Package.swift +++ b/Package.swift @@ -14,11 +14,10 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"), - .package(url: "https://github.com/torusresearch/tss-client-swift.git", from: "4.0.0"), - .package(url: "https://github.com/tkey/tkey-mpc-swift", branch : "update_features" ), - .package(url: "https://github.com/torusresearch/customauth-swift-sdk", branch : "features_update"), - .package(url: "https://github.com/Web3Auth/single-factor-auth-swift", branch :"7.0.0"), - .package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0") + .package(url: "https://github.com/torusresearch/tss-client-swift.git", from: "5.0.0"), + .package(url: "https://github.com/tkey/tkey-mpc-swift", branch : "encapsulate_torusnetwork" ), // 4.0.0 + .package(url: "https://github.com/torusresearch/customauth-swift-sdk", from: "11.0.1"), + .package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.2.0") ], targets: [ @@ -28,7 +27,6 @@ let package = Package( name: "mpc-core-kit-swift", dependencies: [ .product(name: "CustomAuth", package: "customauth-swift-sdk"), - .product(name: "SingleFactorAuth", package: "single-factor-auth-swift"), .product(name: "tkey", package: "tkey-mpc-swift" ), .product(name: "tssClientSwift", package: "tss-client-swift" ), .product(name: "JWTDecode", package: "JWTDecode.swift") diff --git a/Sources/mpc-core-kit-swift/CoreKitError.swift b/Sources/mpc-core-kit-swift/CoreKitError.swift index eed6220..94e6e31 100644 --- a/Sources/mpc-core-kit-swift/CoreKitError.swift +++ b/Sources/mpc-core-kit-swift/CoreKitError.swift @@ -29,6 +29,7 @@ public enum CoreKitError: Error { case invalidStore case noTssTags case invalidDeviceFactorKey + case invalidTssPubKey case runtime(_ msg: String) public var errorDescription: String { @@ -91,6 +92,8 @@ public enum CoreKitError: Error { return "Device factor key not found" case .runtime(msg: let msg): return msg + case .invalidTssPubKey: + return "Invalid tss public key" } } } diff --git a/Sources/mpc-core-kit-swift/DeviceFactorStorage.swift b/Sources/mpc-core-kit-swift/DeviceFactorStorage.swift index 14afabb..ef0fd0f 100644 --- a/Sources/mpc-core-kit-swift/DeviceFactorStorage.swift +++ b/Sources/mpc-core-kit-swift/DeviceFactorStorage.swift @@ -9,7 +9,7 @@ public class DeviceFactorStorage: IFactorStorage { public func setFactor(metadataPubKey: String, factorKey: String) async throws { guard let factorKeyData = Data(hexString: factorKey) else { - throw "invalid factorKey" + throw CoreKitError.invalidFactorKey } try await storage.set(key: metadataPubKey, payload: factorKeyData) } diff --git a/Sources/mpc-core-kit-swift/Helper.swift b/Sources/mpc-core-kit-swift/Helper.swift index 9b9804d..da86e85 100644 --- a/Sources/mpc-core-kit-swift/Helper.swift +++ b/Sources/mpc-core-kit-swift/Helper.swift @@ -1,7 +1,6 @@ import BigInt import FetchNodeDetails import Foundation -import SingleFactorAuth #if canImport(tkey) import tkey diff --git a/Sources/mpc-core-kit-swift/Interface.swift b/Sources/mpc-core-kit-swift/Interface.swift index 6dff03b..d303df4 100644 --- a/Sources/mpc-core-kit-swift/Interface.swift +++ b/Sources/mpc-core-kit-swift/Interface.swift @@ -1,5 +1,4 @@ import Foundation -import SingleFactorAuth #if canImport(tkey) import tkey diff --git a/Sources/mpc-core-kit-swift/MpcCoreKitSwift.swift b/Sources/mpc-core-kit-swift/MpcCoreKitSwift.swift index 4136c1e..66ff555 100644 --- a/Sources/mpc-core-kit-swift/MpcCoreKitSwift.swift +++ b/Sources/mpc-core-kit-swift/MpcCoreKitSwift.swift @@ -1,7 +1,6 @@ import CustomAuth import FetchNodeDetails import Foundation -import SingleFactorAuth import TorusUtils #if canImport(tkey) @@ -21,7 +20,7 @@ public class MpcCoreKit { internal var tssPubKey: String? internal var userInfo: [String:Any] - internal var option: Web3AuthOptions + internal var option: CoreKitWeb3AuthOptions // internal var state: CoreKitstate @@ -49,7 +48,7 @@ public class MpcCoreKit { private let customAuth: CustomAuth - public init(options: Web3AuthOptions) throws { + public init(options: CoreKitWeb3AuthOptions) throws { if options.web3AuthClientId.isEmpty { throw CoreKitError.invalidInput } @@ -111,9 +110,10 @@ public class MpcCoreKit { return mnemonic } + public func loginWithJwt(verifier: String, verifierId: String, idToken: String) async throws -> MpcKeyDetails { - let singleFactor = try SingleFactorAuth(singleFactorAuthArgs: SingleFactorAuthArgs(web3AuthClientId: option.web3AuthClientId, network: option.web3AuthNetwork)) - let torusKey = try await singleFactor.getTorusKey(loginParams: LoginParams(verifier: verifier, verifierId: verifierId, idToken: idToken)) + + let torusKey = try await customAuth.getTorusKey(verifier: verifier, verifier_id: verifierId, verifierParams: VerifierParams(verifier_id: verifierId), idToken: idToken) let result = try await login(keyDetails: torusKey, verifier: verifier, verifierId: verifierId) @@ -183,7 +183,7 @@ public class MpcCoreKit { self.nodeDetails = nodeDetails - tssEndpoints = nodeDetails.torusNodeTSSEndpoints + tssEndpoints = nodeDetails.getTorusNodeTSSEndpoints() guard let postboxkey = self.oAuthKey else { throw CoreKitError.invalidPostboxKey @@ -201,7 +201,7 @@ public class MpcCoreKit { authSigs = sigs guard let metadataEndpoint = metadataHostUrl else { - throw "Invalid metadata url endpoint" + throw CoreKitError.invalidInput } // initialize tkey @@ -360,7 +360,7 @@ public class MpcCoreKit { let allFactorPubs = try await self.getAllFactorPubs() let factorPub = try SecretKey(hex: factorKey).toPublic().serialize(compressed: true) if (!allFactorPubs.contains(factorPub)) { - throw "Invalid factor \(factorKey)" + throw CoreKitError.invalidFactorKey } // input factor diff --git a/Sources/mpc-core-kit-swift/Tss.swift b/Sources/mpc-core-kit-swift/Tss.swift index 16e71c1..99926e5 100644 --- a/Sources/mpc-core-kit-swift/Tss.swift +++ b/Sources/mpc-core-kit-swift/Tss.swift @@ -15,16 +15,16 @@ import tssClientSwift extension MpcCoreKit { public func getTssPubKey() throws -> Data { - guard let thresholdKey = tkey else { + guard tkey != nil else { throw CoreKitError.invalidTKey } guard let tssPubKey = self.tssPubKey else { - throw "invalid Tss Pub Key" + throw CoreKitError.invalidTssPubKey } guard let res = Data(hexString: tssPubKey) else { - throw "invalid Tss Pub Key" + throw CoreKitError.invalidTssPubKey } return res } @@ -40,7 +40,7 @@ extension MpcCoreKit { } if factorKey == nil { - throw "Invalid factor Key" + throw CoreKitError.invalidFactorKey } let selectedTag = try TssModule.get_tss_tag(threshold_key: tkey) diff --git a/Sources/mpc-core-kit-swift/core/Web3AuthOptions.swift b/Sources/mpc-core-kit-swift/core/Web3AuthOptions.swift index 85076c2..56396c8 100644 --- a/Sources/mpc-core-kit-swift/core/Web3AuthOptions.swift +++ b/Sources/mpc-core-kit-swift/core/Web3AuthOptions.swift @@ -1,7 +1,7 @@ import Foundation -import SingleFactorAuth +import FetchNodeDetails -public class Web3AuthOptions { +public class CoreKitWeb3AuthOptions { public let web3AuthClientId: String public let manualSync: Bool public let web3AuthNetwork: Web3AuthNetwork diff --git a/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift b/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift index 8cb6e8e..0ab05fa 100644 --- a/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift +++ b/Tests/mpc-kit-swiftTests/mpc_kit_swiftTests.swift @@ -2,7 +2,6 @@ import curveSecp256k1 import JWTKit import FetchNodeDetails import mpc_core_kit_swift -import SingleFactorAuth import XCTest // JWT payload structure. @@ -91,7 +90,7 @@ func mockLogin2(email: String) throws -> String { final class mpc_kit_swiftTests: XCTestCase { func resetMPC(email: String, verifier: String, clientId: String) async throws { - let coreKitInstance = try MpcCoreKit(options: Web3AuthOptions(web3AuthClientId: clientId, manualSync: true, web3AuthNetwork: .sapphire(.SAPPHIRE_DEVNET), localStorage: MemoryStorage(), disableHashFactor: false)) + let coreKitInstance = try MpcCoreKit(options: CoreKitWeb3AuthOptions(web3AuthClientId: clientId, manualSync: true, web3AuthNetwork: .SAPPHIRE_DEVNET, localStorage: MemoryStorage(), disableHashFactor: false)) let data = try mockLogin2(email: email) let token = data @@ -109,14 +108,14 @@ final class mpc_kit_swiftTests: XCTestCase { let memoryStorage = MemoryStorage() - let coreKitInstance = try MpcCoreKit(options: Web3AuthOptions(web3AuthClientId: clientId, manualSync: true, web3AuthNetwork: .sapphire(.SAPPHIRE_DEVNET), localStorage: memoryStorage, disableHashFactor: false)) + let coreKitInstance = try MpcCoreKit(options: CoreKitWeb3AuthOptions(web3AuthClientId: clientId, manualSync: true, web3AuthNetwork: .SAPPHIRE_DEVNET, localStorage: memoryStorage, disableHashFactor: false)) let data = try mockLogin2(email: email) let token = data let _ = try await coreKitInstance.loginWithJwt(verifier: verifier, verifierId: email, idToken: token) let hash = try keccak256(data: Data(hexString: "010203040506")!) - let signatures = try coreKitInstance.tssSign(message: hash) + _ = try coreKitInstance.tssSign(message: hash) let newFactor = try await coreKitInstance.createFactor(tssShareIndex: .device, factorKey: nil, factorDescription: .DeviceShare, additionalMetadata: ["my": "mymy"]) @@ -132,7 +131,7 @@ final class mpc_kit_swiftTests: XCTestCase { // reset Account try await resetMPC(email: email, verifier: verifier, clientId: clientId) let memoryStorage = MemoryStorage() - let coreKitInstance = try MpcCoreKit(options: Web3AuthOptions(web3AuthClientId: clientId, manualSync: false, web3AuthNetwork: .sapphire(.SAPPHIRE_DEVNET), localStorage: memoryStorage, disableHashFactor: false)) + let coreKitInstance = try MpcCoreKit(options: CoreKitWeb3AuthOptions(web3AuthClientId: clientId, manualSync: false, web3AuthNetwork: .SAPPHIRE_DEVNET, localStorage: memoryStorage, disableHashFactor: false)) let data = try mockLogin2(email: email) let token = data @@ -141,7 +140,7 @@ final class mpc_kit_swiftTests: XCTestCase { let recoveryFactor = try await coreKitInstance.enableMFAWithRecoveryFactor() let memoryStorage2 = MemoryStorage() - let coreKitInstance2 = try MpcCoreKit(options: Web3AuthOptions(web3AuthClientId: clientId, manualSync: false, web3AuthNetwork: .sapphire(.SAPPHIRE_DEVNET), localStorage: memoryStorage2, disableHashFactor: false)) + let coreKitInstance2 = try MpcCoreKit(options: CoreKitWeb3AuthOptions(web3AuthClientId: clientId, manualSync: false, web3AuthNetwork: .SAPPHIRE_DEVNET, localStorage: memoryStorage2, disableHashFactor: false)) let data2 = try mockLogin2(email: email) let token2 = data2