diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/TorusUtils.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/TorusUtils.xcscheme index ec373689..d7cb3177 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/TorusUtils.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/TorusUtils.xcscheme @@ -51,6 +51,17 @@ BlueprintName = "torus-utils-swiftTests" ReferencedContainer = "container:"> + + + + + + + + diff --git a/Sources/TorusUtils/Extensions/torus+extension.swift b/Sources/TorusUtils/Extensions/torus+extension.swift index 8734ed88..8e199946 100644 --- a/Sources/TorusUtils/Extensions/torus+extension.swift +++ b/Sources/TorusUtils/Extensions/torus+extension.swift @@ -71,7 +71,7 @@ extension TorusUtils { "timestamp": timestamp] )) - // print( String(data: rpcdata, encoding: .utf8)!) + print( String(data: rpcdata, encoding: .utf8)!) promisesArray.append(URLSession.shared.uploadTask(.promise, with: rq, from: rpcdata)) } @@ -110,7 +110,7 @@ extension TorusUtils { } - func retreiveIndividualNodeShare(endpoints : Array, verifier: String, verifierParams: [String: String], idToken:String, nodeSignatures: [[String:String]]) -> Promise<[Int:[String:String]]>{ + func retreiveIndividualNodeShare(endpoints : Array, verifier: String, verifierParams: [[String: String]], tokenCommitment:String, nodeSignatures: [[String:String]], subVerifierId: [String], verifierId: String) -> Promise<[Int:[String:String]]>{ let (tempPromise, seal) = Promise<[Int:[String:String]]>.pending() var promisesArrayReq = Array >() @@ -122,9 +122,9 @@ extension TorusUtils { "id":10, "method": "ShareRequest", "params": ["encrypted": "yes", - "item": [["verifieridentifier":verifier, "verifier_id": verifierParams["verifier_id"]!, "idtoken": idToken, "nodesignatures": nodeSignatures]]]] as [String : Any] - + "item": [["verify_params": verifierParams, "sub_verifier_ids": subVerifierId, "verifieridentifier":verifier, "verifier_id": verifierId, "nodesignatures": nodeSignatures, "idtoken": tokenCommitment]]]] as [String : Any] let rpcdata = try! JSONSerialization.data(withJSONObject: dataForRequest) + print( String(data: rpcdata, encoding: .utf8)!) promisesArrayReq.append(URLSession.shared.uploadTask(.promise, with: rq, from: rpcdata)) } @@ -134,6 +134,7 @@ extension TorusUtils { var receivedRequiredShares = false for (i, pr) in promisesArrayReq.enumerated(){ pr.done{ data, response in + print(try! JSONSerialization.jsonObject(with: data, options: [])) let decoded = try JSONDecoder().decode(JSONRPCresponse.self, from: data) print("share responses", decoded) if(decoded.error != nil) {throw TorusError.decodingError} diff --git a/Sources/TorusUtils/TorusUtils.swift b/Sources/TorusUtils/TorusUtils.swift index 6deefaae..dccf945b 100644 --- a/Sources/TorusUtils/TorusUtils.swift +++ b/Sources/TorusUtils/TorusUtils.swift @@ -63,7 +63,7 @@ public class TorusUtils{ - public func retreiveShares(endpoints : Array, verifier: String, verifierParams: [String: String], idToken:String) -> Promise{ + public func retreiveShares(endpoints : Array, verifierIdentifier: String, verifierParams: [[String: String]], subVerifierIds: [String], verifierId: String) -> Promise{ // Generate privatekey let privateKey = SECP256K1.generatePrivateKey() @@ -75,7 +75,8 @@ public class TorusUtils{ let pubKeyY = publicKey?.suffix(publicKey!.count/2).toHexString() // Hash the token from OAuth login - let tokenCommitment = idToken.sha3(.keccak256) + let tempIDToken = verifierParams.map{$0["idtoken"]!}.joined(separator: "\u{001d}") + let tokenCommitment = tempIDToken.sha3(.keccak256) let timestamp = String(Int(Date().timeIntervalSince1970)) var nodeReturnedPubKeyX:String = "" @@ -84,17 +85,16 @@ public class TorusUtils{ print(privateKey?.toHexString() as Any, publicKeyHex as Any, pubKeyX as Any, pubKeyY as Any, tokenCommitment) return Promise{ seal in - commitmentRequest(endpoints: endpoints, verifier: verifier, pubKeyX: pubKeyX!, pubKeyY: pubKeyY!, timestamp: timestamp, tokenCommitment: tokenCommitment) + commitmentRequest(endpoints: endpoints, verifier: verifierIdentifier, pubKeyX: pubKeyX!, pubKeyY: pubKeyY!, timestamp: timestamp, tokenCommitment: tokenCommitment.sha3(.keccak256)) .then{ data -> Promise<[Int:[String:String]]> in - print("data after commitment requrest", data) - return self.retreiveIndividualNodeShare(endpoints: endpoints, verifier: verifier, verifierParams: verifierParams, idToken: idToken, nodeSignatures: data) + print("data after commitment requrest", data) + return self.retreiveIndividualNodeShare(endpoints: endpoints, verifier: verifierIdentifier, verifierParams: verifierParams, tokenCommitment: tokenCommitment, nodeSignatures: data, subVerifierId: subVerifierIds, verifierId: verifierId) }.then{ data -> Promise<[Int:String]> in print("data after retrieve shares", data) if let temp = data.first{ nodeReturnedPubKeyX = temp.value["pubKeyX"]! nodeReturnedPubKeyY = temp.value["pubKeyY"]! } - return self.decryptIndividualShares(shares: data, privateKey: privateKey!.toHexString()) }.then{ data -> Promise in //print("individual shares array", data) diff --git a/Tests/torus-utils-swiftTests/unit_test.swift b/Tests/torus-utils-swiftTests/unit_test.swift index 8654f3ff..ef8c7955 100644 --- a/Tests/torus-utils-swiftTests/unit_test.swift +++ b/Tests/torus-utils-swiftTests/unit_test.swift @@ -23,8 +23,11 @@ final class torus_utils_swiftTests: XCTestCase { let nodeList = ["https://lrc-test-13-a.torusnode.com/jrpc", "https://lrc-test-13-b.torusnode.com/jrpc", "https://lrc-test-13-c.torusnode.com/jrpc", "https://lrc-test-13-d.torusnode.com/jrpc", "https://lrc-test-13-e.torusnode.com/jrpc"] let nodePubKeys : Array = [TorusNodePub(_X: "4086d123bd8b370db29e84604cd54fa9f1aeb544dba1cc9ff7c856f41b5bf269", _Y: "fde2ac475d8d2796aab2dea7426bc57571c26acad4f141463c036c9df3a8b8e8"),TorusNodePub(_X: "1d6ae1e674fdc1849e8d6dacf193daa97c5d484251aa9f82ff740f8277ee8b7d", _Y: "43095ae6101b2e04fa187e3a3eb7fbe1de706062157f9561b1ff07fe924a9528"),TorusNodePub(_X: "fd2af691fe4289ffbcb30885737a34d8f3f1113cbf71d48968da84cab7d0c262", _Y: "c37097edc6d6323142e0f310f0c2fb33766dbe10d07693d73d5d490c1891b8dc"),TorusNodePub(_X: "e078195f5fd6f58977531135317a0f8d3af6d3b893be9762f433686f782bec58", _Y: "843f87df076c26bf5d4d66120770a0aecf0f5667d38aa1ec518383d50fa0fb88"),TorusNodePub(_X: "a127de58df2e7a612fd256c42b57bb311ce41fd5d0ab58e6426fbf82c72e742f", _Y: "388842e57a4df814daef7dceb2065543dd5727f0ee7b40d527f36f905013fa96")] let verifierId = "shubham@tor.us" - let verifier = "google-shubs" - let token = "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc0YmQ4NmZjNjFlNGM2Y2I0NTAxMjZmZjRlMzhiMDY5YjhmOGYzNWMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiIyMzg5NDE3NDY3MTMtcXFlNGE3cmR1dWsyNTZkOG9pNWwwcTM0cXR1OWdwZmcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIyMzg5NDE3NDY3MTMtcXFlNGE3cmR1dWsyNTZkOG9pNWwwcTM0cXR1OWdwZmcuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDk1ODQzNTA5MTA3Mjc0NzAzNDkiLCJoZCI6InRvci51cyIsImVtYWlsIjoic2h1YmhhbUB0b3IudXMiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXRfaGFzaCI6IjY2bXVLVS1NTzNmTjFNbV9LdnhJWHciLCJub25jZSI6IjEyMyIsIm5hbWUiOiJTaHViaGFtIFJhdGhpIiwicGljdHVyZSI6Imh0dHBzOi8vbGg0Lmdvb2dsZXVzZXJjb250ZW50LmNvbS8tT19SUi1aYlQwZVUvQUFBQUFBQUFBQUkvQUFBQUFBQUFBQUEvQUFLV0pKTmVleHhiRHozcjFVVnBrWjVGbzdsYTNhMXZRZy9zOTYtYy9waG90by5qcGciLCJnaXZlbl9uYW1lIjoiU2h1YmhhbSIsImZhbWlseV9uYW1lIjoiUmF0aGkiLCJsb2NhbGUiOiJlbiIsImlhdCI6MTU4ODY2ODUzOSwiZXhwIj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sZXVzZXJjb250ZW50LmNvbS8tT19SUi1aYlQwZVUvQUFBQUFBQUFBQUkvQUFBQUFBQUFBQUEvQU1adXVjazdCR2hkRkhZdEtfQVN6T01wZlpTSWVHU2NmZy9zOTYtYy9waG90by5qcGciLCJnaXZlbl9uYW1lIjoiU2h1YmhhbSIsImZhbWlseV9uYW1lIjoiUmF0aGkiLCJsb2NhbGUiOiJlbiIsImlhdCI6MTU4OTc5NDI2NywiZXhwIjoxNTg5Nzk3ODY3LCJqdGkiOiIxNzIyNmYwMWMxMGNjNTIyZjMwNjkwMDFhZmI1NWVlYjhkNjNmNTBhIn0.sJ3VBXnqBvRUOwKIwuvV8tt9Eh8I8OZtWMGljuz8SGg83f90Bf-llVNfsnxTBbdntIpVP75sTcSpSKEm35T407QrCPcbAsnawHTFtDvwdqkMSW2Y5FaOkJsrI9iFcRFpOmqqloB4k-OD64vdkw-rInDrrRmgS8f6nui5QQmhk8GS8Mgm6BGNa6isWXPcHCZZgg2R6r03rjfqFM_LNtEb-Zg0h8KbnlmOwo1wKD_iWWszHaWOgWC4iXZRVO-ORz_IAY6g-QXEFSSjju9fAZe4Sr0vjVEE48PZuvTFslU9FrrYi2lW2V5NEJMi5KEj6wc75b55zIbIxqPH6WJXSUm5HA" + let verifyParams = [["GOOGLE_CLIENT_ID": "238941746713-qqe4a7rduuk256d8oi5l0q34qtu9gpfg.apps.googleusercontent.com", + "typeOfLogin": "google", + "verifier": "google-shubs",]] override class func setUp() { super.setUp() @@ -98,7 +101,7 @@ final class torus_utils_swiftTests: XCTestCase { func testRetreiveShares(){ let exp1 = XCTestExpectation(description: "reterive privatekey") let obj = TorusUtils() - let key = obj.retreiveShares(endpoints: self.nodeList, verifier: verifier, verifierParams: ["verifier_id": verifierId], idToken: token) + let key = obj.retreiveShares(endpoints: self.nodeList, verifierIdentifier: verifier, verifierParams: [["verifier_id": verifierId, "idtoken": token]], subVerifierIds: ["google-shubs"], verifierId: verifierId) key.done{ data in print("data", data) XCTAssertEqual(64, data.count)