Skip to content

Commit

Permalink
update: use latest torus-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Jul 30, 2024
1 parent 4caaaa8 commit 633a194
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 46 deletions.
15 changes: 3 additions & 12 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
Expand Down
6 changes: 3 additions & 3 deletions SingleFactorAuth.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
11 changes: 11 additions & 0 deletions Sources/SingleFactorAuth/Data+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

internal extension Data {
var bytes: Array<UInt8> {
Array(self)
}

func toHexString() -> String {
bytes.toHexString()
}
}
36 changes: 10 additions & 26 deletions Sources/SingleFactorAuth/SingleFactorAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/SingleFactorAuthTests/AquaTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SingleFactorAuthTests/CyanTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 633a194

Please sign in to comment.