Skip to content

Commit

Permalink
Merge pull request #14 from Web3Auth/feat/update-torusUtils
Browse files Browse the repository at this point in the history
feat: update torus-Utils
  • Loading branch information
himanshuchawla009 authored Apr 3, 2024
2 parents 30f6a26 + 7a5caa3 commit f2f56e8
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 156 deletions.
24 changes: 10 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ on:
workflow_dispatch:

# Checkout the code, and run mxcl's xcodebuild action to run the unit tests

jobs:
build:
runs-on: macOS-latest
strategy:
matrix:
platform:
- iOS
test:
runs-on: macos-latest
steps:
- uses: actions/[email protected]
- uses: mxcl/xcodebuild@v1
- name: checkout
uses: actions/checkout@v3
- name: xcode
uses: maxim-lobanov/setup-xcode@v1
with:
platform: ${{ matrix.platform }}
action: test
scheme: SingleFactorAuth
code-coverage: true
upload-logs: always

xcode-version: latest-stable
- name: package
run: xcodebuild test -scheme SingleFactorAuth -destination "platform=iOS Simulator,OS=16.2,name=iPhone 14" COMPILER_INDEX_STORE_ENABLE=NO
144 changes: 18 additions & 126 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
"state" : {
"revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e",
"version" : "1.8.0"
"revision" : "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c",
"version" : "1.8.1"
}
},
{
"identity" : "fetch-node-details-swift",
"identity" : "curvelib.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/fetch-node-details-swift.git",
"location" : "https://github.com/tkey/curvelib.swift",
"state" : {
"revision" : "d591af500f32ce3c88d04af9bb74d746585acfea",
"version" : "5.1.0"
"revision" : "7dad3bf1793de263f83406c08c18c9316abf082f",
"version" : "0.1.2"
}
},
{
"identity" : "generic-json-swift",
"identity" : "fetch-node-details-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/iwill/generic-json-swift",
"location" : "https://github.com/torusresearch/fetch-node-details-swift.git",
"state" : {
"revision" : "0a06575f4038b504e78ac330913d920f1630f510",
"version" : "2.0.2"
"revision" : "d591af500f32ce3c88d04af9bb74d746585acfea",
"version" : "5.1.0"
}
},
{
"identity" : "jwt-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"state" : {
"revision" : "ef12bdfa557cd9d9f0c53396e0a9908f773bcd7b",
"version" : "4.9.0"
"revision" : "e05513b5aec24f88012b6e3034115b6bc915356a",
"version" : "4.13.2"
}
},
{
Expand All @@ -63,139 +63,31 @@
"version" : "20.0.0"
}
},
{
"identity" : "secp256k1.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/GigaBitcoin/secp256k1.swift",
"state" : {
"revision" : "1a14e189def5eaa92f839afdd2faad8e43b61a6e",
"version" : "0.12.2"
}
},
{
"identity" : "session-manager-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/session-manager-swift.git",
"state" : {
"revision" : "f4e6f24dfe0bac88eb9a7aeda1cd73caad69a9ce",
"version" : "3.0.1"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
"revision" : "290e36cd0646f7fb3be737b65bdfc9f5428dfd5c",
"version" : "3.1.0"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "6d9c36b4beda0dae88feab6dc36206434bae713c",
"version" : "2.4.1"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "99d066e29effa8845e4761dd3f2f831edfdf8925",
"version" : "1.0.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "853522d90871b4b63262843196685795b5008c46",
"version" : "2.61.1"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "798c962495593a23fdea0c0c63fd55571d8dff51",
"version" : "1.20.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "3bd9004b9d685ed6b629760fc84903e48efec806",
"version" : "1.29.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e",
"version" : "1.20.0"
"revision" : "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb",
"version" : "3.3.0"
}
},
{
"identity" : "torus-utils-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/torus-utils-swift",
"state" : {
"revision" : "b7e4eff3bf1a135cd408f6679952ae7b476ba833",
"version" : "6.1.0"
}
},
{
"identity" : "web3.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/argentlabs/web3.swift",
"state" : {
"revision" : "8ca33e700ed8de6137a0e1471017aa3b3c8de0db",
"version" : "1.6.0"
}
},
{
"identity" : "websocket-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
"version" : "2.14.0"
"revision" : "04c62fd5f73f21bd01b7c07e08f6135db26c5940",
"version" : "8.0.0"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/torusresearch/fetch-node-details-swift.git", from: "5.1.0"),
.package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "6.1.0"),
.package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "8.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: "3.0.1")
.package(url: "https://github.com/Web3Auth/session-manager-swift.git", from: "3.1.0")
],
targets: [
.target(
Expand Down
27 changes: 17 additions & 10 deletions Sources/SingleFactorAuth/SingleFactorAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class SingleFactorAuth {
enableOneKey: true,
signerHost: singleFactorAuthArgs.getSignerUrl()! + "/api/sign",
allowHost: singleFactorAuthArgs.getSignerUrl()! + "/api/allow",
network: singleFactorAuthArgs.getNetwork()
network: singleFactorAuthArgs.getNetwork(),
clientId: singleFactorAuthArgs.getWeb3AuthClientId()
)
}

Expand All @@ -29,7 +30,7 @@ public class SingleFactorAuth {
return .init(privateKey: privKey, publicAddress: publicAddress)
}

public func getKey(loginParams: LoginParams) async throws -> TorusSFAKey {
public func getTorusKey(loginParams: LoginParams) async throws -> TorusKey {
var retrieveSharesResponse: TorusKey

let details = try await nodeDetailManager.getNodeDetails(verifier: loginParams.verifier, verifierID: loginParams.verifierId)
Expand Down Expand Up @@ -63,8 +64,8 @@ public class SingleFactorAuth {
] as [String: Codable]

let verifierParams = VerifierParams(verifier_id: loginParams.verifierId)

let aggregateIdToken = String(String(bytes: aggregateIdTokenSeeds.joined(separator: "\u{001d}").bytes.sha3(.keccak256)).dropFirst(2)) // drop 0x
let aggregateIdToken = aggregateIdTokenSeeds.joined(separator: "\u{001d}").bytes.sha3(.keccak256).toHexString() // drop 0x

retrieveSharesResponse = try await torusUtils.retrieveShares(
endpoints: details.getTorusNodeEndpoints(),
Expand All @@ -88,11 +89,17 @@ public class SingleFactorAuth {
)
}

let publicAddress = (retrieveSharesResponse.finalKeyData?.X ?? "") + (retrieveSharesResponse.finalKeyData?.Y ?? "")
let privateKey = retrieveSharesResponse.finalKeyData?.privKey ?? ""

let torusKey = TorusSFAKey(privateKey: privateKey, publicAddress: publicAddress)
_ = try await sessionManager.createSession(data: torusKey)
return torusKey
return retrieveSharesResponse
}

public func getKey(loginParams: LoginParams) async throws -> TorusSFAKey {
let torusKey = try await self.getTorusKey(loginParams: loginParams)

let publicAddress = (torusKey.finalKeyData?.X ?? "") + (torusKey.finalKeyData?.Y ?? "")
let privateKey = torusKey.finalKeyData?.privKey ?? ""

let torusSfaKey = TorusSFAKey(privateKey: privateKey, publicAddress: publicAddress)
_ = try await sessionManager.createSession(data: torusSfaKey)
return torusSfaKey
}
}
8 changes: 7 additions & 1 deletion Sources/SingleFactorAuth/SingleFactorAuthArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ public class SingleFactorAuthArgs {

private var network: TorusNetwork
private var networkUrl: String
private var web3AuthClientId: String

public init(network: TorusNetwork, networkUrl: String = "") {
public init(web3AuthClientId: String, network: TorusNetwork, networkUrl: String = "") {
self.network = network
self.networkUrl = networkUrl
self.web3AuthClientId = web3AuthClientId
}

public func getWeb3AuthClientId() -> String {
return web3AuthClientId
}

public func getNetwork() -> TorusNetwork {
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 {
let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate"

override func setUp() {
singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.legacy(.AQUA))
singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.AQUA))
singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs)
}

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 {
let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate"

override func setUp() {
singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.legacy(.CYAN))
singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.CYAN))
singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs)
}

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 {
let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate"

override func setUp() {
singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.legacy(.TESTNET))
singleFactorAuthArgs = SingleFactorAuthArgs(web3AuthClientId: "CLIENT ID", network: TorusNetwork.legacy(.TESTNET))
singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs)
}

Expand Down

0 comments on commit f2f56e8

Please sign in to comment.