From 0f561e7fc42ae7585982b371fbac4d85c2652aac Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Thu, 16 May 2024 08:28:40 +0200 Subject: [PATCH] update --- Sources/TorusUtils/Constants.swift | 2 +- Sources/TorusUtils/Helpers/NodeUtils.swift | 13 +++++++++++++ .../jsonRPC/Requests/ShareRequestParams.swift | 2 +- Sources/TorusUtils/TorusUtils.swift | 1 - Sources/TorusUtils/VerifierParams.swift | 2 +- Tests/TorusUtilsTests/AquaTest.swift | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Sources/TorusUtils/Constants.swift b/Sources/TorusUtils/Constants.swift index adcc6eb1..09c51953 100644 --- a/Sources/TorusUtils/Constants.swift +++ b/Sources/TorusUtils/Constants.swift @@ -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" diff --git a/Sources/TorusUtils/Helpers/NodeUtils.swift b/Sources/TorusUtils/Helpers/NodeUtils.swift index 33021891..499561b8 100644 --- a/Sources/TorusUtils/Helpers/NodeUtils.swift +++ b/Sources/TorusUtils/Helpers/NodeUtils.swift @@ -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 @@ -222,6 +227,7 @@ internal class NodeUtils { group -> [JRPCResponse?] in let isImport = isImportShareReq // Local copy for parellel code var received = 0 + for i in 0 ..< endpoints.count { if !nodeSigs.indices.contains(i) { continue @@ -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.self, from: val.0) return decoded @@ -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() + } } } diff --git a/Sources/TorusUtils/Helpers/jsonRPC/Requests/ShareRequestParams.swift b/Sources/TorusUtils/Helpers/jsonRPC/Requests/ShareRequestParams.swift index c3f64847..2c86ec99 100644 --- a/Sources/TorusUtils/Helpers/jsonRPC/Requests/ShareRequestParams.swift +++ b/Sources/TorusUtils/Helpers/jsonRPC/Requests/ShareRequestParams.swift @@ -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?]? diff --git a/Sources/TorusUtils/TorusUtils.swift b/Sources/TorusUtils/TorusUtils.swift index d590f690..58f7547e 100644 --- a/Sources/TorusUtils/TorusUtils.swift +++ b/Sources/TorusUtils/TorusUtils.swift @@ -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") diff --git a/Sources/TorusUtils/VerifierParams.swift b/Sources/TorusUtils/VerifierParams.swift index 21ecd5f3..7c335043 100644 --- a/Sources/TorusUtils/VerifierParams.swift +++ b/Sources/TorusUtils/VerifierParams.swift @@ -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]? diff --git a/Tests/TorusUtilsTests/AquaTest.swift b/Tests/TorusUtilsTests/AquaTest.swift index 9ead7485..43f46cdb 100644 --- a/Tests/TorusUtilsTests/AquaTest.swift +++ b/Tests/TorusUtilsTests/AquaTest.swift @@ -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)