Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: full refactor to align torus-utils-swift to torus.js #97

Merged
merged 19 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
platform:
- iOS
steps:
- uses: actions/checkout@v2.3.4
- uses: mxcl/xcodebuild@v1
- uses: actions/checkout@v4
- uses: mxcl/xcodebuild@v3.0.0
with:
platform: ${{ matrix.platform }}
action: test
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ playground.xcworkspace
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
.swiftpm/

.build/

Expand Down
3 changes: 3 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
retain_public: true
targets:
- TorusUtils
24 changes: 24 additions & 0 deletions .swiftpm/TorusUtils.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "9F2D8848-AB66-4789-A38F-C7E010657904",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {
"testRepetitionMode" : "retryOnFailure"
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:",
"identifier" : "TorusUtilsTests",
"name" : "TorusUtilsTests"
}
}
],
"version" : 1
}
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

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

84 changes: 84 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/TorusUtils.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TorusUtils"
BuildableName = "TorusUtils"
BlueprintName = "TorusUtils"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:.swiftpm/TorusUtils.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TorusUtilsTests"
BuildableName = "TorusUtilsTests"
BlueprintName = "TorusUtilsTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TorusUtils"
BuildableName = "TorusUtils"
BlueprintName = "TorusUtils"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
13 changes: 2 additions & 11 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 All @@ -32,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/fetch-node-details-swift.git",
"state" : {
"revision" : "f085d3d85a4f36b57cfef8f0871ac8df1dd4f6f1",
"version" : "6.0.1"
"revision" : "22bfadf7491d77a0bc1953af002cadbd61383e7d",
"version" : "6.0.2"
}
},
{
Expand Down
11 changes: 4 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/tkey/curvelib.swift", from: "1.0.1"),
.package(url: "https://github.com/torusresearch/fetch-node-details-swift", from: "6.0.1"),
.package(url: "https://github.com/vapor/jwt-kit", from: "4.0.0"),
.package(
url: "https://github.com/Flight-School/AnyCodable",
from: "0.6.0"
),
.package(url: "https://github.com/torusresearch/fetch-node-details-swift", from: "6.0.2"),
metalurgical marked this conversation as resolved.
Show resolved Hide resolved
// NB: jwt-kit may only be a dependency in tests or it will break cocoapod support
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
],
targets: [
.target(
name: "TorusUtils",
dependencies: ["AnyCodable",
dependencies: [
.product(name: "FetchNodeDetails", package: "fetch-node-details-swift"),
.product(name: "curveSecp256k1", package: "curvelib.swift"),
]),
Expand Down
59 changes: 30 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@ This utility library allows for early exits in optimistic scenarios, while handl
The general approach is to evaluate predicates against a list of (potentially incomplete) results, and exit when the predicate passes.

## 🔗 Installation
You can install the SingleFactorAuth Swift using Swift Package Manager.
You can install the TorusUtils using Swift Package Manager:

```
...
dependencies: [
...
.package(url: "https://github.com/torusresearch/torus-utils-swift", from: "8.0.1")
.package(url: "https://github.com/torusresearch/torus-utils-swift", from: "9.0.0")
],
targets: [
.target( name: "<INSERT_TARGET_NAME>",
dependencies: [
.product(name: "TorusUtils", package: "torus-utils-swift")
]
) ],
]
...
```

Or CocoaPods:

```
...
pod 'Torus-utils', '~> 9.0.0'
...
```

## Getting Started
Initialize the `TorusUtils` class by passing `TorusNetwork`, `enableOneKey`, and your `clientId`. `enableOneKey` if true, adds the nonce value to the key, to make it compaitible with v2 users. The package supports both legacy and sapphire networks.
Initialize the `TorusUtils` class by passing `TorusOptions` as params. Params includes `TorusNetwork`, `enableOneKey`, and your `clientId`. `enableOneKey` if true, adds the nonce value to the key, to make it compatible with v2 users. The package supports both legacy and sapphire networks.

```swift
let torus = TorusUtils(
enableOneKey: true,
network: .sapphire(.SAPPHIRE_DEVNET),
clientId: "YOUR_CLIENT_ID"
)
let torusUtils = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true))
```


Expand All @@ -39,39 +50,29 @@ Use the `getNodeDetails` function to retrive the node details for specific `veri
do {
let fnd = NodeDetailManager(network: .sapphire(.SAPPHIRE_DEVNET))

let nodeDetails = try await fnd.getNodeDetails(verifier: verifer, verifierID: veriferID)
let nodeDetails = try await fnd.getNodeDetails(verifier: verifier, verifierID: verifierID)

let publicAddressResponse = try await torus.getPublicAddress(
endpoints: nodeDetails.getTorusNodeEndpoints(),
torusNodePubs: nodeDetails.torusNodePub,
verifier: TORUS_TEST_VERIFIER,
verifierId: TORUS_TEST_EMAIL
)

print(publicAddressResponse.oAuthKeyData!.evmAddress)
let publicDetails = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: verifier, verifierId: verifierID)

print(publicDetails.oAuthKeyData!.evmAddress)
} catch let error {
// Handle error
}
```

Use `retriveShares` function to login a user, and get the login data such as `sessionData`, `privKey`, `evmAddress`, `metaData` for user. Along with node detals, it also takes verifier, `verifierParams`, and `idToken`(JWT token).
Use `retrieveShares` function to login a user, and get the login data such as `sessionData`, `privKey`, `evmAddress`, `metaData` for user. Along with node details, it also takes `verifier`, `verifierParams`, and `idToken`(JWT token).

```swift
// verifier_id takes the value, for instance email, sub, or custom.
let verifierParams = VerifierParams(verifier_id: "verifier_id_value")

do {
// Use nodeDetails from above step
let data = try await torus.retrieveShares(
endpoints: nodeDetails.getTorusNodeEndpoints(),
torusNodePubs: nodeDetails.getTorusNodePub(),
indexes: nodeDetails.getTorusIndexes(),
verifier: TORUS_TEST_VERIFIER,
verifierParams: verifierParams,
idToken: token
)

let privateKey = data.finalKeyData!.privKey

let verifierParams = VerifierParams(verifier_id: verifierID)

let data = try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: token)

let evmAddress = data.finalKeyData!.evmAddress
} catch let error {
// Handle error
Expand All @@ -85,4 +86,4 @@ do {

- Have a look at our [Community Portal](https://community.web3auth.io/) to see if anyone has any questions or issues you might be having. Feel free to reate new topics and we'll help you out as soon as possible.
- Checkout our [Troubleshooting Documentation Page](https://web3auth.io/docs/troubleshooting) to know the common issues and solutions.
- For Priority Support, please have a look at our [Pricing Page](https://web3auth.io/pricing.html) for the plan that suits your needs.
- For Priority Support, please have a look at our [Pricing Page](https://web3auth.io/pricing.html) for the plan that suits your needs.
9 changes: 0 additions & 9 deletions Sources/TorusUtils/AbstractTorusUtils.swift

This file was deleted.

7 changes: 1 addition & 6 deletions Sources/TorusUtils/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
enum JRPC_METHODS {
static let GET_OR_SET_KEY = "GetPubKeyOrKeyAssign"
static let COMMITMENT_REQUEST = "CommitmentRequest"
static let IMPORT_SHARE = "ImportShare"
static let IMPORT_SHARES = "ImportShares"
static let GET_SHARE_OR_KEY_ASSIGN = "GetShareOrKeyAssign"
static let LEGACY_VERIFIER_LOOKUP_REQUEST = "VerifierLookupRequest"
static let LEGACY_KEY_ASSIGN = "KeyAssign"
static let LEGACY_SHARE_REQUEST = "ShareRequest"
}

let CURVE_N: String = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"

let LEGACY_METADATA_HOST = "https://metadata.tor.us"
Loading