-
Notifications
You must be signed in to change notification settings - Fork 0
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/tss sq rust #18
base: main
Are you sure you want to change the base?
Feat/tss sq rust #18
Conversation
add input_share delete_question add check at set_question
to threshold_key class
fix tests
fix multipart form data
due to 'type' backward compatible
Fixes minimum package support. Rebuilds libraries with mac support included.
func selectedServerToPointer (selectedServers: [UInt32]?) throws -> UnsafeMutablePointer<Int8>? { | ||
guard let selectedServers = selectedServers else { | ||
return nil | ||
} | ||
var serversPointer: UnsafeMutablePointer<Int8>? | ||
|
||
let selected_servers_json = try JSONSerialization.data(withJSONObject: selectedServers as Any) | ||
let selected_servers_str = String(data: selected_servers_json, encoding: .utf8)! | ||
print(selected_servers_str) | ||
serversPointer = UnsafeMutablePointer<Int8>(mutating: (selected_servers_str as NSString).utf8String) | ||
|
||
guard let serversPointer = serversPointer else { | ||
throw RuntimeError("convert error") | ||
} | ||
return serversPointer | ||
} | ||
|
||
func authSignaturesToPointer ( authSignatures : [String]?) throws -> UnsafeMutablePointer<Int8>? { | ||
guard let authSignatures = authSignatures else { | ||
return nil | ||
} | ||
let auth_signatures_json = try JSONSerialization.data(withJSONObject: authSignatures) | ||
guard let auth_signatures_str = String(data: auth_signatures_json, encoding: .utf8) else { | ||
throw RuntimeError("auth signatures error") | ||
} | ||
print(authSignatures) | ||
print(auth_signatures_str.count) | ||
|
||
let authSignaturesPointer = UnsafeMutablePointer<Int8>(mutating: (auth_signatures_str as NSString).utf8String) | ||
|
||
|
||
return authSignaturesPointer | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These pointers are probably not valid once the function returns, the memory locations they're assigned are local to this function.
func selectedServerToPointer (selectedServers: [UInt32]?) throws -> UnsafeMutablePointer<Int8>? { | |
guard let selectedServers = selectedServers else { | |
return nil | |
} | |
var serversPointer: UnsafeMutablePointer<Int8>? | |
let selected_servers_json = try JSONSerialization.data(withJSONObject: selectedServers as Any) | |
let selected_servers_str = String(data: selected_servers_json, encoding: .utf8)! | |
print(selected_servers_str) | |
serversPointer = UnsafeMutablePointer<Int8>(mutating: (selected_servers_str as NSString).utf8String) | |
guard let serversPointer = serversPointer else { | |
throw RuntimeError("convert error") | |
} | |
return serversPointer | |
} | |
func authSignaturesToPointer ( authSignatures : [String]?) throws -> UnsafeMutablePointer<Int8>? { | |
guard let authSignatures = authSignatures else { | |
return nil | |
} | |
let auth_signatures_json = try JSONSerialization.data(withJSONObject: authSignatures) | |
guard let auth_signatures_str = String(data: auth_signatures_json, encoding: .utf8) else { | |
throw RuntimeError("auth signatures error") | |
} | |
print(authSignatures) | |
print(auth_signatures_str.count) | |
let authSignaturesPointer = UnsafeMutablePointer<Int8>(mutating: (auth_signatures_str as NSString).utf8String) | |
return authSignaturesPointer | |
} |
// | ||
// // TODO : Fix the deserialization of the Factor cloud metadata | ||
// // ts implemetation break this | ||
// let deviceShareJson : [String: Any] | ||
// if resultJson["deviceShare"] != nil { | ||
// guard var deviceShare = resultJson["deviceShare"] as? [String: Any] else { | ||
// throw "invalid factor json without deviceShare or share indexkey" | ||
// } | ||
// deviceShareJson = deviceShare | ||
// } else { | ||
// guard let deviceShare = resultJson["share"] as? [String:Any] else { | ||
// throw "invalid factor json without deviceShare or share indexkey" | ||
// } | ||
// deviceShareJson = deviceShare | ||
// } | ||
// | ||
// guard let shareJson = deviceShareJson["share"] as? [String: Any] else { | ||
// throw "Invalid factor key" | ||
// } | ||
// guard let shareIndex = shareJson["shareIndex"] as? String else { | ||
// throw "Invalid factor key" | ||
// } | ||
// return shareIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
// | |
// // TODO : Fix the deserialization of the Factor cloud metadata | |
// // ts implemetation break this | |
// let deviceShareJson : [String: Any] | |
// if resultJson["deviceShare"] != nil { | |
// guard var deviceShare = resultJson["deviceShare"] as? [String: Any] else { | |
// throw "invalid factor json without deviceShare or share indexkey" | |
// } | |
// deviceShareJson = deviceShare | |
// } else { | |
// guard let deviceShare = resultJson["share"] as? [String:Any] else { | |
// throw "invalid factor json without deviceShare or share indexkey" | |
// } | |
// deviceShareJson = deviceShare | |
// } | |
// | |
// guard let shareJson = deviceShareJson["share"] as? [String: Any] else { | |
// throw "Invalid factor key" | |
// } | |
// guard let shareIndex = shareJson["shareIndex"] as? String else { | |
// throw "Invalid factor key" | |
// } | |
// return shareIndex |
|
||
public func toString() throws -> String { | ||
let data = try JSONEncoder().encode(self) | ||
// let data = try JSONSerialization.data(withJSONObject: self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// let data = try JSONSerialization.data(withJSONObject: self) |
// private func patch_input_factor_key(factorKey: String, completion: @escaping (Result<Void, Error>) -> Void) { | ||
// tkeyQueue.async { | ||
// do { | ||
// var errorCode: Int32 = -1 | ||
// let cFactorKey = UnsafeMutablePointer<Int8>(mutating: (factorKey as NSString).utf8String) | ||
// let curvePointer = UnsafeMutablePointer<Int8>(mutating: (self.curveN as NSString).utf8String) | ||
// | ||
// withUnsafeMutablePointer(to: &errorCode, { error in | ||
// threshold_key_patch_input_factor_key(self.pointer, cFactorKey, curvePointer, error) | ||
// }) | ||
// guard errorCode == 0 else { | ||
// throw RuntimeError("Error in ThresholdKey input_factor_key \(errorCode)") | ||
// } | ||
// completion(.success(())) | ||
// } catch { | ||
// completion(.failure(error)) | ||
// } | ||
// } | ||
// } | ||
|
||
/// Patch and Inserts a `ShareStore` into `ThresholdKey` using `FactorKey`, useful for insertion before reconstruction to ensure the number of shares meet the minimum threshold. | ||
/// | ||
/// - Parameters: | ||
/// - factorKey : The `factorKey` to be inserted | ||
/// | ||
/// - Throws: `RuntimeError`, indicates invalid parameters or invalid `ThresholdKey`. | ||
// public func patch_input_factor_key(factorKey: String) async throws { | ||
// return try await withCheckedThrowingContinuation { | ||
// continuation in | ||
// self.patch_input_factor_key(factorKey: factorKey) { | ||
// result in | ||
// switch result { | ||
// case let .success(result): | ||
// continuation.resume(returning: result) | ||
// case let .failure(error): | ||
// continuation.resume(throwing: error) | ||
// } | ||
// } | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// private func patch_input_factor_key(factorKey: String, completion: @escaping (Result<Void, Error>) -> Void) { | |
// tkeyQueue.async { | |
// do { | |
// var errorCode: Int32 = -1 | |
// let cFactorKey = UnsafeMutablePointer<Int8>(mutating: (factorKey as NSString).utf8String) | |
// let curvePointer = UnsafeMutablePointer<Int8>(mutating: (self.curveN as NSString).utf8String) | |
// | |
// withUnsafeMutablePointer(to: &errorCode, { error in | |
// threshold_key_patch_input_factor_key(self.pointer, cFactorKey, curvePointer, error) | |
// }) | |
// guard errorCode == 0 else { | |
// throw RuntimeError("Error in ThresholdKey input_factor_key \(errorCode)") | |
// } | |
// completion(.success(())) | |
// } catch { | |
// completion(.failure(error)) | |
// } | |
// } | |
// } | |
/// Patch and Inserts a `ShareStore` into `ThresholdKey` using `FactorKey`, useful for insertion before reconstruction to ensure the number of shares meet the minimum threshold. | |
/// | |
/// - Parameters: | |
/// - factorKey : The `factorKey` to be inserted | |
/// | |
/// - Throws: `RuntimeError`, indicates invalid parameters or invalid `ThresholdKey`. | |
// public func patch_input_factor_key(factorKey: String) async throws { | |
// return try await withCheckedThrowingContinuation { | |
// continuation in | |
// self.patch_input_factor_key(factorKey: factorKey) { | |
// result in | |
// switch result { | |
// case let .success(result): | |
// continuation.resume(returning: result) | |
// case let .failure(error): | |
// continuation.resume(throwing: error) | |
// } | |
// } | |
// } | |
// } |
guard errorCode == 0 else { | ||
throw RuntimeError("Error in ThresholdKey get_domain_store_item") | ||
} | ||
let string = String(cString: result!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused.
let string = String(cString: result!) |
|
||
|
||
|
||
let auth_signatures_json = try JSONSerialization.data(withJSONObject: threshold.authSignatures) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should do a guard on threshold.authSignatures
to resolve the warning here. Same for the places.
guard errorCode == 0 else { | ||
throw RuntimeError("Error in ThresholdKey recover_factor \(errorCode)") | ||
} | ||
let hashOut = String(cString: result!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused. Why not use result instead of having to call compute_hash?
let hashOut = String(cString: result!) |
threshold.setTorusUtils(torusUtils: torusUtils) | ||
// threshold.init | ||
print( try threshold.get_key_details().pub_key.getPublicKey(format: .EllipticCompress)) | ||
let factorKey = "36c1728c47c84dfe855949fa76daf82f8bda801af9374f30aa4c91b7fd7a8e3b" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused.
let factorKey = "36c1728c47c84dfe855949fa76daf82f8bda801af9374f30aa4c91b7fd7a8e3b" |
print( try threshold.get_key_details().pub_key.getPublicKey(format: .EllipticCompress)) | ||
let factorKey = "36c1728c47c84dfe855949fa76daf82f8bda801af9374f30aa4c91b7fd7a8e3b" | ||
let answer = "jsanswer" | ||
let question = "js question" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused.
let question = "js question" |
print(factor) | ||
|
||
try await threshold.input_factor_key(factorKey: factor) | ||
try await threshold.reconstruct() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try await threshold.reconstruct() | |
let _ = try await threshold.reconstruct() |
No description provided.