From 633a194ff9b49e18acf505f658a59bf5d2db3fe6 Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:56:33 +0200 Subject: [PATCH] update: use latest torus-utils --- Package.resolved | 15 ++------ Package.swift | 4 +-- SingleFactorAuth.podspec | 6 ++-- Sources/SingleFactorAuth/Data+Extension.swift | 11 ++++++ .../SingleFactorAuth/SingleFactorAuth.swift | 36 ++++++------------- Tests/SingleFactorAuthTests/AquaTest.swift | 2 +- Tests/SingleFactorAuthTests/CyanTest.swift | 2 +- .../SingleFactorAuthTests.swift | 2 +- 8 files changed, 32 insertions(+), 46 deletions(-) create mode 100644 Sources/SingleFactorAuth/Data+Extension.swift diff --git a/Package.resolved b/Package.resolved index bee738a..6000c4e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,14 +1,5 @@ { "pins" : [ - { - "identity" : "anycodable", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Flight-School/AnyCodable", - "state" : { - "revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05", - "version" : "0.6.7" - } - }, { "identity" : "bigint", "kind" : "remoteSourceControl", @@ -75,10 +66,10 @@ { "identity" : "torus-utils-swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/torusresearch/torus-utils-swift", + "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "revision" : "608c28404c506983bfec7bbd957632fc0544db8c", - "version" : "8.1.2" + "revision" : "ecf4a77f1eb387d0fd048f1431f5f3189e793977", + "version" : "9.0.0" } } ], diff --git a/Package.swift b/Package.swift index 24e9291..0d8a593 100644 --- a/Package.swift +++ b/Package.swift @@ -15,8 +15,8 @@ let package = Package( targets: ["SingleFactorAuth"]) ], dependencies: [ - .package(url: "https://github.com/torusresearch/fetch-node-details-swift.git", from: "6.0.1"), - .package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "8.1.0"), + .package(url: "https://github.com/torusresearch/fetch-node-details-swift.git", from: "6.0.3"), + .package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "9.0.0"), .package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"), .package(url: "https://github.com/Web3Auth/session-manager-swift.git", from: "4.0.2"), ], diff --git a/SingleFactorAuth.podspec b/SingleFactorAuth.podspec index 2c5d6f8..3473b9e 100644 --- a/SingleFactorAuth.podspec +++ b/SingleFactorAuth.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "SingleFactorAuth" - spec.version = "6.0.0" + spec.version = "7.0.0" spec.ios.deployment_target = "14.0" spec.summary = "Enable one key flow for Web3Auth" spec.homepage = "https://github.com/Web3Auth/single-factor-auth-swift" @@ -10,8 +10,8 @@ Pod::Spec.new do |spec| spec.module_name = "SingleFactorAuth" spec.source = { :git => "https://github.com/web3Auth/single-factor-auth-swift", :tag => spec.version } spec.source_files = "Sources/SingleFactorAuth/*.{swift,json}","Sources/SingleFactorAuth/**/*.{swift,json}" - spec.dependency 'Torus-fetchNodeDetails', '~> 6.0.1' + spec.dependency 'Torus-fetchNodeDetails', '~> 6.0.3' spec.dependency 'curvelib.swift', '~> 1.0.1' - spec.dependency 'Torus-utils', '~> 8.1.0' + spec.dependency 'Torus-utils', '~> 9.0.0' spec.dependency 'TorusSessionManager', '~> 4.0.2' end diff --git a/Sources/SingleFactorAuth/Data+Extension.swift b/Sources/SingleFactorAuth/Data+Extension.swift new file mode 100644 index 0000000..55a59bb --- /dev/null +++ b/Sources/SingleFactorAuth/Data+Extension.swift @@ -0,0 +1,11 @@ +import Foundation + +internal extension Data { + var bytes: Array { + Array(self) + } + + func toHexString() -> String { + bytes.toHexString() + } +} diff --git a/Sources/SingleFactorAuth/SingleFactorAuth.swift b/Sources/SingleFactorAuth/SingleFactorAuth.swift index cf0c130..599d57c 100644 --- a/Sources/SingleFactorAuth/SingleFactorAuth.swift +++ b/Sources/SingleFactorAuth/SingleFactorAuth.swift @@ -11,14 +11,11 @@ public class SingleFactorAuth { let torusUtils: TorusUtils private var sessionManager: SessionManager - public init(singleFactorAuthArgs: SingleFactorAuthArgs) { + public init(singleFactorAuthArgs: SingleFactorAuthArgs) throws { sessionManager = .init() nodeDetailManager = NodeDetailManager(network: singleFactorAuthArgs.getNetwork().network) - torusUtils = TorusUtils( - enableOneKey: true, - network: singleFactorAuthArgs.getNetwork().network, - clientId: singleFactorAuthArgs.getWeb3AuthClientId() - ) + let torusOptions = TorusOptions(clientId: singleFactorAuthArgs.getWeb3AuthClientId(), network: singleFactorAuthArgs.getNetwork().network, enableOneKey: true) + try torusUtils = TorusUtils( params: torusOptions) } public func initialize() async throws -> TorusSFAKey { @@ -33,7 +30,7 @@ public class SingleFactorAuth { let details = try await nodeDetailManager.getNodeDetails(verifier: loginParams.verifier, verifierID: loginParams.verifierId) - let userDetails = try await torusUtils.getUserTypeAndAddress(endpoints: details.getTorusNodeEndpoints(), torusNodePubs: details.getTorusNodePub(), verifier: loginParams.verifier, verifierId: loginParams.verifierId) + let userDetails = try await torusUtils.getUserTypeAndAddress(endpoints: details.getTorusNodeEndpoints(), verifier: loginParams.verifier, verifierId: loginParams.verifierId) if userDetails.metadata?.upgraded == true { throw "User already has enabled MFA" @@ -42,45 +39,32 @@ public class SingleFactorAuth { if let subVerifierInfoArray = loginParams.subVerifierInfoArray, !subVerifierInfoArray.isEmpty { var aggregateIdTokenSeeds = [String]() var subVerifierIds = [String]() - var verifyParams = [[String: String]]() + var verifyParams = [VerifyParams]() for value in subVerifierInfoArray { aggregateIdTokenSeeds.append(value.idToken) - var verifyParam: [String: String] = [:] - verifyParam["verifier_id"] = loginParams.verifierId - verifyParam["idtoken"] = value.idToken + let verifyParam = VerifyParams(verifier_id: loginParams.verifierId, idtoken: value.idToken) verifyParams.append(verifyParam) subVerifierIds.append(value.verifier) } aggregateIdTokenSeeds.sort() - let extraParams = [ - "verifier_id": loginParams.verifierId, - "sub_verifier_ids": subVerifierIds, - "verify_params": verifyParams, - ] as [String: Codable] - - let verifierParams = VerifierParams(verifier_id: loginParams.verifierId) + let verifierParams = VerifierParams(verifier_id: loginParams.verifierId, sub_verifier_ids: subVerifierIds, verify_params: verifyParams) let aggregateIdToken = try curveSecp256k1.keccak256(data: Data(aggregateIdTokenSeeds.joined(separator: "\u{001d}").utf8)).toHexString() retrieveSharesResponse = try await torusUtils.retrieveShares( endpoints: details.getTorusNodeEndpoints(), - torusNodePubs: details.getTorusNodePub(), - indexes: details.getTorusIndexes(), verifier: loginParams.verifier, verifierParams: verifierParams, - idToken: aggregateIdToken, - extraParams: extraParams + idToken: aggregateIdToken ) } else { let verifierParams = VerifierParams(verifier_id: loginParams.verifierId) retrieveSharesResponse = try await torusUtils.retrieveShares( endpoints: details.getTorusNodeEndpoints(), - torusNodePubs: details.getTorusNodePub(), - indexes: details.getTorusIndexes(), verifier: loginParams.verifier, verifierParams: verifierParams, idToken: loginParams.idToken @@ -93,8 +77,8 @@ public class SingleFactorAuth { public func getKey(loginParams: LoginParams) async throws -> TorusSFAKey { let torusKey = try await self.getTorusKey(loginParams: loginParams) - let publicAddress = torusKey.finalKeyData?.evmAddress ?? "" - let privateKey = torusKey.finalKeyData?.privKey ?? "" + let publicAddress = torusKey.finalKeyData.evmAddress + let privateKey = torusKey.finalKeyData.privKey let torusSfaKey = TorusSFAKey(privateKey: privateKey, publicAddress: publicAddress) _ = try await sessionManager.createSession(data: torusSfaKey) diff --git a/Tests/SingleFactorAuthTests/AquaTest.swift b/Tests/SingleFactorAuthTests/AquaTest.swift index f5d5c8f..ed70cbc 100644 --- a/Tests/SingleFactorAuthTests/AquaTest.swift +++ b/Tests/SingleFactorAuthTests/AquaTest.swift @@ -14,7 +14,7 @@ final class AquaTest: XCTestCase { override func setUp() { singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.AQUA) - singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) + singleFactoreAuth = try! SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } func testGetTorusKey() async throws { diff --git a/Tests/SingleFactorAuthTests/CyanTest.swift b/Tests/SingleFactorAuthTests/CyanTest.swift index 910a8d1..db6728c 100644 --- a/Tests/SingleFactorAuthTests/CyanTest.swift +++ b/Tests/SingleFactorAuthTests/CyanTest.swift @@ -14,7 +14,7 @@ final class CyanTest: XCTestCase { override func setUp() { singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.CYAN) - singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) + singleFactoreAuth = try! SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } func testGetTorusKey() async throws { diff --git a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift index 9f10ab4..6af503d 100644 --- a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift +++ b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift @@ -14,7 +14,7 @@ final class SingleFactorAuthTests: XCTestCase { override func setUp() { singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: Web3AuthNetwork.TESTNET) - singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) + singleFactoreAuth = try! SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs) } func testGetTorusKey() async throws {