Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed May 16, 2024
1 parent e1e5f66 commit 0f561e7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/TorusUtils/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enum JRPC_METHODS {
static let GET_OR_SET_KEY = "GetPubKeyOrKeyAssign"
static let COMMITMENT_REQUEST = "CommitmentRequest"
static let IMPORT_SHARE = "ImportShare"
static let IMPORT_SHARE = "ImportShares"
static let GET_SHARE_OR_KEY_ASSIGN = "GetShareOrKeyAssign"
static let VERIFIER_LOOKUP_REQUEST = "VerifierLookupRequest"
static let KEY_ASSIGN = "KeyAssign"
Expand Down
13 changes: 13 additions & 0 deletions Sources/TorusUtils/Helpers/NodeUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ internal class NodeUtils {
if received >= minRequired {
group.cancelAll()
}
} else {
if value == nil || value?.error != nil {
// cannot continue, all must pass for import
group.cancelAll()
}
}
}
return collected
Expand All @@ -222,6 +227,7 @@ internal class NodeUtils {
group -> [JRPCResponse<ShareRequestResult>?] in
let isImport = isImportShareReq // Local copy for parellel code
var received = 0

for i in 0 ..< endpoints.count {
if !nodeSigs.indices.contains(i) {
continue
Expand Down Expand Up @@ -266,6 +272,8 @@ internal class NodeUtils {
let rpcdata = try encoder.encode(jsonRPCRequest)
var request = try MetadataUtils.makeUrlRequest(url: endpoints[i])
request.httpBody = rpcdata
// let readable = String(data: rpcdata, encoding: .utf8)!
// debugPrint(readable)
let val = try await URLSession(configuration: .default).data(for: request)
let decoded = try JSONDecoder().decode(JRPCResponse<ShareRequestResult>.self, from: val.0)
return decoded
Expand Down Expand Up @@ -316,6 +324,11 @@ internal class NodeUtils {
if received >= minRequired {
group.cancelAll()
}
} else {
if value == nil || value?.error != nil {
// cannot continue, all must pass for import
group.cancelAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal struct ShareRequestParams: Codable {
public var key_type: String?
public var nonce_data: String?
public var nonce_signature: String?
// [key: string]: unknown; ?? Needs to be strongly typed in javascript
// [key: string]; This should be strongly typed
public var sub_verifier_ids: [String]?
public var session_token_exp_second: Int?
public var verify_params: [VerifyParams?]?
Expand Down
1 change: 0 additions & 1 deletion Sources/TorusUtils/TorusUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public class TorusUtils {
idToken: String
) async throws -> TorusKey {
// This has to be done here as retrieveOrImport share does not have a reference to self
// Moving this in javascript library will allow it to be done directly in the function
var params: [String: Codable] = [:]
params.updateValue(sessionTime, forKey: "session_token_exp_second")

Expand Down
2 changes: 1 addition & 1 deletion Sources/TorusUtils/VerifierParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class VerifyParams: Codable {
}

public class VerifierParams {
// [key: string]: unknown; ?? Needs to be strongly typed in javascript
// [key: string]: unknown; This should be strongly typed
public let verifier_id: String
public let extended_verifier_id: String?
public let sub_verifier_ids: [String]?
Expand Down
2 changes: 1 addition & 1 deletion Tests/TorusUtilsTests/AquaTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class AquaTest: XCTestCase {
let verifierID: String = fakeEmail
let nodeDetails = try await fnd.getNodeDetails(verifier: verifier, verifierID: verifierID)
let data = try await torus.getPublicAddress(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: verifier, verifierId: verifierID)
// note: duplicated checks on next two lines in javascript

XCTAssertNotNil(data.finalKeyData?.evmAddress)
XCTAssertNotNil(data.oAuthKeyData?.evmAddress)
XCTAssertEqual(data.metadata?.typeOfUser, .v1)
Expand Down

0 comments on commit 0f561e7

Please sign in to comment.