Skip to content

Commit

Permalink
Merge pull request #24 from Web3Auth/encapsulate_torusnetwork
Browse files Browse the repository at this point in the history
refactor: use latest version of torusutils and update features
  • Loading branch information
chaitanyapotti authored Oct 24, 2024
2 parents 44e222e + f58e2cd commit 95e1ea4
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 154 deletions.
27 changes: 18 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tkey/curvelib.swift",
"state" : {
"revision" : "9f88bd5e56d1df443a908f7a7e81ae4f4d9170ea",
"version" : "1.0.1"
"revision" : "432bf1abe7ff505fc2ac9fcf697341ff5b2dc6d0",
"version" : "2.0.0"
}
},
{
"identity" : "fetch-node-details-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/fetch-node-details-swift.git",
"location" : "https://github.com/torusresearch/fetch-node-details-swift",
"state" : {
"revision" : "4bd96c33ba8d02d9e27190c5c7cedf09cfdfd656",
"version" : "6.0.3"
"revision" : "52fb5efaa94e0fe3775913ab00964bcb51601c2a",
"version" : "8.0.0"
}
},
{
Expand All @@ -36,6 +36,15 @@
"version" : "4.13.2"
}
},
{
"identity" : "jwtdecode.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/auth0/JWTDecode.swift",
"state" : {
"revision" : "1e153ef009969543191970c66b7c60163c0b4a65",
"version" : "3.2.0"
}
},
{
"identity" : "keychain-swift",
"kind" : "remoteSourceControl",
Expand All @@ -50,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/session-manager-swift.git",
"state" : {
"revision" : "67d5f7db655d02778861057fb280ecf47c923b09",
"version" : "5.0.0"
"revision" : "90afccc0e5e2ea8d671cdacb26899f60740b4e0b",
"version" : "6.0.0"
}
},
{
Expand All @@ -68,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/torus-utils-swift.git",
"state" : {
"revision" : "eda55b8537a600e657d19d4c452c0a36f217883c",
"version" : "9.0.1"
"revision" : "baa822fc67bdb208ed1a2dc5b3c10485cfca15df",
"version" : "10.0.0"
}
}
],
Expand Down
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ let package = Package(
targets: ["SingleFactorAuth"])
],
dependencies: [
.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.1"),
.package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "10.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: "5.0.0"),
.package(url: "https://github.com/Web3Auth/session-manager-swift.git", from: "6.0.0"),
.package(url: "https://github.com/auth0/JWTDecode.swift.git", from: "3.2.0")
],
targets: [
.target(
name: "SingleFactorAuth",
dependencies: [
.product(name: "FetchNodeDetails", package: "fetch-node-details-swift"),
.product(name: "TorusUtils", package: "torus-utils-swift"),
.product(name: "SessionManager", package: "session-manager-swift")
.product(name: "SessionManager", package: "session-manager-swift"),
.product(name: "JWTDecode", package: "JWTDecode.swift")
]),
.testTarget(
name: "SingleFactorAuthTests",
Expand Down
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ You can install the SingleFactorAuth Swift using Swift Package Manager.
...
dependencies: [
...
.package(url: "https://github.com/Web3Auth/single-factor-auth-swift/", from: "8.0.0")
.package(url: "https://github.com/Web3Auth/single-factor-auth-swift/", from: "9.0.0")
],
...
```


## Getting Started
Initialize the `SingleFactAuth` class by passing `SFAParams`
Initialize the `SingleFactAuth` class by passing `Web3AuthOptions`

```swift
let singleFactorAuthArgs = SingleFactorAuthArgs(
web3AuthClientId: "<Your Client Id>",
clientId: "<Your Client Id>",
network: Web3AuthNetwork.SAPPHIRE_MAINNET
)
let singleFactoreAuth = SingleFactorAuth(params: SFAParams)
let singleFactoreAuth = SingleFactorAuth(params: Web3AuthOptions)
```

Use the `getKey` function to login the user and get the privateKey and public address for the given user.
Expand All @@ -51,14 +51,6 @@ let loginParams = LoginParams(
let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams)
```

We also have included Session Management in this SDK so call initialize function to get TorusKey value without relogging in the user if a user has an active session it will return the TorusKey struct otherwise it will return nil.

```swift
if let savedKey = try await singleFactoreAuth.initialize() {
print(savedKey.getPrivateKey())
print(savedKey.getPublicAddress())
}
```

## Requirements
- iOS 14 or above is required
Expand Down
9 changes: 4 additions & 5 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 = "8.0.0"
spec.version = "9.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,7 @@ 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.3'
spec.dependency 'curvelib.swift', '~> 1.0.1'
spec.dependency 'Torus-utils', '~> 9.0.1'
spec.dependency 'TorusSessionManager', '~> 5.0.0'
spec.dependency 'Torus-utils', '~> 10.0.0'
spec.dependency 'TorusSessionManager', '~> 6.0.0'
spec.dependency 'JWTDecode', '~> 3.2'
end
14 changes: 14 additions & 0 deletions Sources/SingleFactorAuth/Error.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

public enum SFAError: Error, Equatable {
case MFAAlreadyEnabled
}

extension SFAError: LocalizedError {
public var errorDescription: String? {
switch self {
case .MFAAlreadyEnabled:
return "User has already enabled MFA"
}
}
}
13 changes: 5 additions & 8 deletions Sources/SingleFactorAuth/LoginParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ public class LoginParams {
public let verifierId: String
public let idToken: String
public let subVerifierInfoArray: [TorusSubVerifierInfo]?
public let serverTimeOffset: Int?
public let fallbackUserInfo: UserInfo?

public init(verifier: String, verifierId: String, idToken: String) {
self.verifier = verifier
self.verifierId = verifierId
self.idToken = idToken
subVerifierInfoArray = nil
}

public init(verifier: String, verifierId: String, idToken: String, subVerifierInfoArray: [TorusSubVerifierInfo]) {
public init(verifier: String, verifierId: String, idToken: String, subVerifierInfoArray: [TorusSubVerifierInfo]? = nil, serverTimeOffset: Int? = nil, fallbackUserInfo: UserInfo? = nil) {
self.verifier = verifier
self.verifierId = verifierId
self.idToken = idToken
self.subVerifierInfoArray = subVerifierInfoArray
self.serverTimeOffset = serverTimeOffset
self.fallbackUserInfo = fallbackUserInfo
}
}

Expand Down
24 changes: 0 additions & 24 deletions Sources/SingleFactorAuth/SFAKey.swift

This file was deleted.

37 changes: 0 additions & 37 deletions Sources/SingleFactorAuth/SFAParams.swift

This file was deleted.

33 changes: 33 additions & 0 deletions Sources/SingleFactorAuth/SessionData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import BigInt
import Foundation
import TorusUtils

public class SessionData: Codable {
let privateKey: String
let publicAddress: String
let signatures: TorusKey.SessionData?
let userInfo: UserInfo?

init(privateKey: String, publicAddress: String, signatures: TorusKey.SessionData? = nil, userInfo: UserInfo? = nil) {
self.privateKey = privateKey
self.publicAddress = publicAddress
self.signatures = signatures
self.userInfo = userInfo
}

public func getPrivateKey() -> String {
return privateKey
}

public func getPublicAddress() -> String {
return publicAddress
}

public func getUserInfo() -> UserInfo? {
return userInfo
}

public func getSignatures() -> TorusKey.SessionData? {
return self.signatures
}
}
Loading

0 comments on commit 95e1ea4

Please sign in to comment.