diff --git a/mopro-ios/MoproKit/Bindings/mopro.swift b/mopro-ios/MoproKit/Bindings/mopro.swift index 31ba96b4..b604ae2b 100644 --- a/mopro-ios/MoproKit/Bindings/mopro.swift +++ b/mopro-ios/MoproKit/Bindings/mopro.swift @@ -721,14 +721,13 @@ public func `generateProof2`(`circuitInputs`: [String: [String]]) throws -> Gene ) } -public func verifyProof2(proof: Data, publicInput: Data) throws -> Bool { - return try FfiConverterBool.lift( - rustCallWithError(FfiConverterTypeMoproError.lift) { - uniffi_mopro_fn_func_verify_proof2( - FfiConverterData.lower(proof), - FfiConverterData.lower(publicInput), $0 - ) - } +public func `verifyProof2`(`proof`: Data, `publicInput`: Data) throws -> Bool { + return try FfiConverterBool.lift( + try rustCallWithError(FfiConverterTypeMoproError.lift) { + uniffi_mopro_fn_func_verify_proof2( + FfiConverterData.lower(`proof`), + FfiConverterData.lower(`publicInput`),$0) +} ) } @@ -759,10 +758,10 @@ private var initializationResult: InitializationResult { if (uniffi_mopro_checksum_func_generate_proof2() != 6969) { return InitializationResult.apiChecksumMismatch } - if uniffi_mopro_checksum_func_verify_proof2() != 6153 { + if (uniffi_mopro_checksum_func_verify_proof2() != 6153) { return InitializationResult.apiChecksumMismatch } - if uniffi_mopro_checksum_method_moprocircom_setup() != 40345 { + if (uniffi_mopro_checksum_method_moprocircom_setup() != 40345) { return InitializationResult.apiChecksumMismatch } if (uniffi_mopro_checksum_method_moprocircom_generate_proof() != 30646) { diff --git a/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift b/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift index 31af5808..63604141 100644 --- a/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift +++ b/mopro-ios/MoproKit/Example/MoproKit/AnonAadhaarViewController.swift @@ -16,9 +16,13 @@ class AnonAadhaarViewController: UIViewController, WKScriptMessageHandler, WKNav //var setupResult: SetupResult? var generatedProof: Data? var publicInputs: Data? + let containerView = UIView() + var textView = UITextView() override func viewDidLoad() { super.viewDidLoad() + runInitAction() + setupUI() let contentController = WKUserContentController() contentController.add(self, name: "startProvingHandler") @@ -31,39 +35,67 @@ class AnonAadhaarViewController: UIViewController, WKScriptMessageHandler, WKNav // Assign the configuration to the WKWebView let webView = WKWebView(frame: view.bounds, configuration: configuration) webView.navigationDelegate = self - + view.addSubview(webView) + view.addSubview(textView) guard let url = URL(string: "https://webview-anon-adhaar.vercel.app/") else { return } webView.load(URLRequest(url: url)) } + func setupUI() { + textView.isEditable = false + + textView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(textView) + + // Make text view visible + textView.heightAnchor.constraint(equalToConstant: 200).isActive = true + + NSLayoutConstraint.activate([ + textView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), + textView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), + textView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20) + ]) + } + @objc func runInitAction() { - // Logic for init - do { - //textView.text += "Initializing library\n" + // Update the textView on the main thread + DispatchQueue.main.async { + self.textView.text += "Initializing library\n" + } + + // Execute long-running tasks in the background + DispatchQueue.global(qos: .userInitiated).async { // Record start time let start = CFAbsoluteTimeGetCurrent() - try initializeMopro() + do { + try initializeMopro() - // Record end time and compute duration - let end = CFAbsoluteTimeGetCurrent() - let timeTaken = end - start + // Record end time and compute duration + let end = CFAbsoluteTimeGetCurrent() + let timeTaken = end - start - //textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" - } catch let error as MoproError { - print("MoproError: \(error)") - } catch { - print("Unexpected error: \(error)") + // Again, update the UI on the main thread + DispatchQueue.main.async { + self.textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n" + } + } catch { + // Handle errors - update UI on main thread + DispatchQueue.main.async { + self.textView.text += "An error occurred during initialization: \(error)\n" + } + } } } @objc func runProveAction(inputs: [String: [String]]) { // Logic for prove (generate_proof2) do { + textView.text += "Starts proving...\n" // Record start time let start = CFAbsoluteTimeGetCurrent() @@ -82,10 +114,10 @@ class AnonAadhaarViewController: UIViewController, WKScriptMessageHandler, WKNav print("Proof generation took \(timeTaken) seconds.\n") - //textView.text += "Proof generation took \(timeTaken) seconds.\n" - // TODO: Enable verify - //verifyButton.isEnabled = false - //verifyButton.isEnabled = true // Enable the Verify button once proof has been generated + textView.text += "Proof generated!!! \n" + textView.text += "Proof generation took \(timeTaken) seconds.\n" + textView.text += "---\n" + runVerifyAction() } catch let error as MoproError { print("MoproError: \(error)") } catch { @@ -137,4 +169,24 @@ class AnonAadhaarViewController: UIViewController, WKScriptMessageHandler, WKNav } } } + + @objc func runVerifyAction() { + // Logic for verify + guard let proof = generatedProof, + let publicInputs = publicInputs else { + print("Proof has not been generated yet.") + return + } + do { + // Verify Proof + let isValid = try verifyProof2(proof: proof, publicInput: publicInputs) + assert(isValid, "Proof verification should succeed") + + textView.text += "Proof verification succeeded.\n" + } catch let error as MoproError { + print("MoproError: \(error)") + } catch { + print("Unexpected error: \(error)") + } + } }