Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let package = Package(
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
.package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "10.0.1"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
.package(url: "https://github.com/auth0/JWTDecode.swift.git", from: "3.2.0")
.package(url: "https://github.com/auth0/JWTDecode.swift.git", from: "3.2.0"),
.package(url: "https://github.com/segmentio/analytics-swift.git", from: "1.8.0")
],
targets: [
.target(
Expand All @@ -30,7 +31,8 @@ let package = Package(
"SessionManager",
"BigInt",
.product(name: "TorusUtils", package: "torus-utils-swift"),
.product(name: "JWTDecode", package: "JWTDecode.swift")
.product(name: "JWTDecode", package: "JWTDecode.swift"),
.product(name: "Segment", package: "analytics-swift")
]),
.testTarget(
name: "Web3AuthTests",
Expand Down
42 changes: 41 additions & 1 deletion Sources/Web3Auth/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ public struct AuthConnectionConfig: Codable {
}

public struct Web3AuthOptions: Codable {

public var isFlutterAnalytics: Bool = false
public var sdkVersion: String? = nil

public mutating func setFlutterAnalytics(_ isFlutter: Bool?, sdkVersion: String? = nil) {
self.isFlutterAnalytics = isFlutter ?? false
self.sdkVersion = sdkVersion
}

public func getSdkName() -> String {
return isFlutterAnalytics ? AnalyticsSdkType.flutter : AnalyticsSdkType.ios
}

public func getSdkVersion() -> String {
if let version = sdkVersion, !version.isEmpty {
return version // Flutter SDK version
}
return AnalyticsEvents.iosSdkVersion // Default iOS SDK version
}

public init(clientId: String, redirectUrl: String, originData: [String: String]? = nil, authBuildEnv: BuildEnv? = .production, sdkUrl: String? = nil,
storageServerUrl: String? = nil,sessionSocketUrl: String? = nil, authConnectionConfig: [AuthConnectionConfig]? = nil,
whiteLabel: WhiteLabelData? = nil, dashboardUrl: String? = nil, accountAbstractionConfig: String? = nil, walletSdkUrl: String? = nil,
Expand Down Expand Up @@ -248,7 +268,7 @@ public struct Web3AuthOptions: Codable {
var web3AuthNetwork: Web3AuthNetwork
var useSFAKey: Bool?
var walletServicesConfig: WalletServicesConfig?
let mfaSettings: MfaSettings?
var mfaSettings: MfaSettings?


enum CodingKeys: String, CodingKey {
Expand Down Expand Up @@ -731,6 +751,8 @@ public struct ProjectConfigResponse: Codable {
public var walletConnectEnabled: Bool? = nil
public var walletConnectProjectId: String? = nil
public var whitelabel: WhiteLabelData? = nil
public var teamId: Int? = nil
public var mfaSettings: MfaSettings?

enum CodingKeys: String, CodingKey {
case userDataInIdToken
Expand All @@ -745,6 +767,8 @@ public struct ProjectConfigResponse: Codable {
case walletConnectEnabled = "wallet_connect_enabled"
case walletConnectProjectId
case whitelabel
case teamId
case mfaSettings
}

public init(from decoder: Decoder) throws {
Expand All @@ -761,6 +785,8 @@ public struct ProjectConfigResponse: Codable {
self.walletConnectEnabled = try container.decodeIfPresent(Bool.self, forKey: .walletConnectEnabled) ?? false
self.walletConnectProjectId = try container.decodeIfPresent(String.self, forKey: .walletConnectProjectId)
self.whitelabel = try container.decodeIfPresent(WhiteLabelData.self, forKey: .whitelabel)
self.teamId = try container.decodeIfPresent(Int.self, forKey: .teamId)
self.mfaSettings = try container.decodeIfPresent(MfaSettings.self, forKey: .mfaSettings)
}
}

Expand Down Expand Up @@ -810,3 +836,17 @@ public struct Web3AuthSubVerifierInfo: Codable {
var idToken: String
}

extension MfaSettings {
func merge(with other: MfaSettings?) -> MfaSettings {
guard let other = other else { return self }
return MfaSettings(
deviceShareFactor: other.deviceShareFactor ?? self.deviceShareFactor,
backUpShareFactor: other.backUpShareFactor ?? self.backUpShareFactor,
socialBackupFactor: other.socialBackupFactor ?? self.socialBackupFactor,
passwordFactor: other.passwordFactor ?? self.passwordFactor,
passkeysFactor: other.passkeysFactor ?? self.passkeysFactor,
authenticatorFactor: other.authenticatorFactor ?? self.authenticatorFactor
)
}
}

Loading