Skip to content

Commit 2ce089a

Browse files
committed
re-align torus-utils-swift
Re-align the current implementation of torus-utils-swift to that of the web implementation of torus.js. This will reduce the overhead of differences a developer would need to remember between the two and provide an overall better experience. This will also provide better long term maintainability and make feature parity simpler to implement between the two. The are also numerous bug fixes implemented in this PR as well, one of which allowed the package AnyCodable as a dependency to be removed. Should be feature-complete up until tag v12.3.5 on torus.js
1 parent 06ec8f9 commit 2ce089a

File tree

90 files changed

+3856
-4696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3856
-4696
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
platform:
2626
- iOS
2727
steps:
28-
- uses: actions/checkout@v2.3.4
29-
- uses: mxcl/xcodebuild@v1
28+
- uses: actions/checkout@v4
29+
- uses: mxcl/xcodebuild@v3.0.0
3030
with:
3131
platform: ${{ matrix.platform }}
3232
action: test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ playground.xcworkspace
4949
#
5050
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
5151
# hence it is not needed unless you have added a package configuration file to your project
52-
.swiftpm/
5352

5453
.build/
5554

.periphery.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
retain_public: true
2+
targets:
3+
- TorusUtils

.swiftpm/TorusUtils.xctestplan

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "9F2D8848-AB66-4789-A38F-C7E010657904",
5+
"name" : "Test Scheme Action",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"testRepetitionMode" : "retryOnFailure"
13+
},
14+
"testTargets" : [
15+
{
16+
"target" : {
17+
"containerPath" : "container:",
18+
"identifier" : "TorusUtilsTests",
19+
"name" : "TorusUtilsTests"
20+
}
21+
}
22+
],
23+
"version" : 1
24+
}

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1540"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "TorusUtils"
19+
BuildableName = "TorusUtils"
20+
BlueprintName = "TorusUtils"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES">
31+
<TestPlans>
32+
<TestPlanReference
33+
reference = "container:.swiftpm/TorusUtils.xctestplan"
34+
default = "YES">
35+
</TestPlanReference>
36+
</TestPlans>
37+
<Testables>
38+
<TestableReference
39+
skipped = "NO">
40+
<BuildableReference
41+
BuildableIdentifier = "primary"
42+
BlueprintIdentifier = "TorusUtilsTests"
43+
BuildableName = "TorusUtilsTests"
44+
BlueprintName = "TorusUtilsTests"
45+
ReferencedContainer = "container:">
46+
</BuildableReference>
47+
</TestableReference>
48+
</Testables>
49+
</TestAction>
50+
<LaunchAction
51+
buildConfiguration = "Debug"
52+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
53+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
54+
launchStyle = "0"
55+
useCustomWorkingDirectory = "NO"
56+
ignoresPersistentStateOnLaunch = "NO"
57+
debugDocumentVersioning = "YES"
58+
debugServiceExtension = "internal"
59+
allowLocationSimulation = "YES">
60+
</LaunchAction>
61+
<ProfileAction
62+
buildConfiguration = "Release"
63+
shouldUseLaunchSchemeArgsEnv = "YES"
64+
savedToolIdentifier = ""
65+
useCustomWorkingDirectory = "NO"
66+
debugDocumentVersioning = "YES">
67+
<MacroExpansion>
68+
<BuildableReference
69+
BuildableIdentifier = "primary"
70+
BlueprintIdentifier = "TorusUtils"
71+
BuildableName = "TorusUtils"
72+
BlueprintName = "TorusUtils"
73+
ReferencedContainer = "container:">
74+
</BuildableReference>
75+
</MacroExpansion>
76+
</ProfileAction>
77+
<AnalyzeAction
78+
buildConfiguration = "Debug">
79+
</AnalyzeAction>
80+
<ArchiveAction
81+
buildConfiguration = "Release"
82+
revealArchiveInOrganizer = "YES">
83+
</ArchiveAction>
84+
</Scheme>

Package.resolved

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"pins" : [
3-
{
4-
"identity" : "anycodable",
5-
"kind" : "remoteSourceControl",
6-
"location" : "https://github.com/Flight-School/AnyCodable",
7-
"state" : {
8-
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
9-
"version" : "0.6.7"
10-
}
11-
},
123
{
134
"identity" : "bigint",
145
"kind" : "remoteSourceControl",
@@ -32,8 +23,8 @@
3223
"kind" : "remoteSourceControl",
3324
"location" : "https://github.com/torusresearch/fetch-node-details-swift.git",
3425
"state" : {
35-
"revision" : "f085d3d85a4f36b57cfef8f0871ac8df1dd4f6f1",
36-
"version" : "6.0.1"
26+
"revision" : "22bfadf7491d77a0bc1953af002cadbd61383e7d",
27+
"version" : "6.0.2"
3728
}
3829
},
3930
{

Package.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ let package = Package(
1212
],
1313
dependencies: [
1414
.package(url: "https://github.com/tkey/curvelib.swift", from: "1.0.1"),
15-
.package(url: "https://github.com/torusresearch/fetch-node-details-swift", from: "6.0.1"),
16-
.package(url: "https://github.com/vapor/jwt-kit", from: "4.0.0"),
17-
.package(
18-
url: "https://github.com/Flight-School/AnyCodable",
19-
from: "0.6.0"
20-
),
15+
.package(url: "https://github.com/torusresearch/fetch-node-details-swift", from: "6.0.2"),
16+
// NB: jwt-kit may only be a dependency in tests or it will break cocoapod support
17+
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
2118
],
2219
targets: [
2320
.target(
2421
name: "TorusUtils",
25-
dependencies: ["AnyCodable",
22+
dependencies: [
2623
.product(name: "FetchNodeDetails", package: "fetch-node-details-swift"),
2724
.product(name: "curveSecp256k1", package: "curvelib.swift"),
2825
]),

README.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ This utility library allows for early exits in optimistic scenarios, while handl
88
The general approach is to evaluate predicates against a list of (potentially incomplete) results, and exit when the predicate passes.
99

1010
## 🔗 Installation
11-
You can install the SingleFactorAuth Swift using Swift Package Manager.
11+
You can install the TorusUtils using Swift Package Manager:
1212

1313
```
1414
...
1515
dependencies: [
1616
...
17-
.package(url: "https://github.com/torusresearch/torus-utils-swift", from: "8.1")
17+
.package(url: "https://github.com/torusresearch/torus-utils-swift", from: "9.0.0")
1818
],
1919
targets: [
20-
.target( name: "",
20+
.target( name: "<INSERT_TARGET_NAME>",
2121
dependencies: [
2222
.product(name: "TorusUtils", package: "torus-utils-swift")
2323
]
@@ -26,15 +26,19 @@ targets: [
2626
...
2727
```
2828

29+
Or CocoaPods:
30+
31+
```
32+
...
33+
pod 'Torus-utils', '~> 9.0.0'
34+
...
35+
```
36+
2937
## Getting Started
30-
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.
38+
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.
3139

3240
```swift
33-
let torus = TorusUtils(
34-
enableOneKey: true,
35-
network: .sapphire(.SAPPHIRE_DEVNET),
36-
clientId: "YOUR_CLIENT_ID"
37-
)
41+
let torusUtils = TorusUtils(params: TorusOptions(clientId: "YOUR_CLIENT_ID", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true))
3842
```
3943

4044

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

49-
let nodeDetails = try await fnd.getNodeDetails(verifier: verifer, verifierID: veriferID)
53+
let nodeDetails = try await fnd.getNodeDetails(verifier: verifier, verifierID: verifierID)
5054

51-
let publicAddressResponse = try await torus.getPublicAddress(
52-
endpoints: nodeDetails.getTorusNodeEndpoints(),
53-
torusNodePubs: nodeDetails.torusNodePub,
54-
verifier: TORUS_TEST_VERIFIER,
55-
verifierId: TORUS_TEST_EMAIL
56-
)
57-
58-
print(publicAddressResponse.oAuthKeyData!.evmAddress)
55+
let publicDetails = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: verifier, verifierId: verifierID)
56+
57+
print(publicDetails.oAuthKeyData!.evmAddress)
5958
} catch let error {
6059
// Handle error
6160
}
6261
```
6362

64-
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).
63+
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).
6564

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

7069
do {
7170
// Use nodeDetails from above step
72-
let data = try await torus.retrieveShares(
73-
endpoints: nodeDetails.getTorusNodeEndpoints(),
74-
torusNodePubs: nodeDetails.getTorusNodePub(),
75-
indexes: nodeDetails.getTorusIndexes(),
76-
verifier: TORUS_TEST_VERIFIER,
77-
verifierParams: verifierParams,
78-
idToken: token
79-
)
80-
81-
let privateKey = data.finalKeyData!.privKey
71+
72+
let verifierParams = VerifierParams(verifier_id: verifierID)
73+
74+
let data = try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeSSSEndpoints(), indexes: nodeDetails.getTorusIndexes(), verifier: verifier, verifierParams: verifierParams, idToken: token)
75+
8276
let evmAddress = data.finalKeyData!.evmAddress
8377
} catch let error {
8478
// Handle error

Sources/TorusUtils/AbstractTorusUtils.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

Sources/TorusUtils/Constants.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
enum JRPC_METHODS {
22
static let GET_OR_SET_KEY = "GetPubKeyOrKeyAssign"
33
static let COMMITMENT_REQUEST = "CommitmentRequest"
4-
static let IMPORT_SHARE = "ImportShare"
4+
static let IMPORT_SHARES = "ImportShares"
55
static let GET_SHARE_OR_KEY_ASSIGN = "GetShareOrKeyAssign"
6-
static let LEGACY_VERIFIER_LOOKUP_REQUEST = "VerifierLookupRequest"
7-
static let LEGACY_KEY_ASSIGN = "KeyAssign"
8-
static let LEGACY_SHARE_REQUEST = "ShareRequest"
96
}
107

118
let CURVE_N: String = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
12-
13-
let LEGACY_METADATA_HOST = "https://metadata.tor.us"

0 commit comments

Comments
 (0)