Skip to content

Commit

Permalink
feat(ios): download arkzkey and wasm from server and generate proof
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianjeng authored and oskarth committed Feb 23, 2024
1 parent 92e9e5e commit 7a7c467
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 168 deletions.
6 changes: 6 additions & 0 deletions mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
2A5149C82B87616600B57A44 /* multiplier2_final.arkzkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A5149C62B87616600B57A44 /* multiplier2_final.arkzkey */; };
2A5149CA2B87618000B57A44 /* main_final.arkzkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A5149C92B87618000B57A44 /* main_final.arkzkey */; };
2A5149CB2B87618000B57A44 /* main_final.arkzkey in Resources */ = {isa = PBXBuildFile; fileRef = 2A5149C92B87618000B57A44 /* main_final.arkzkey */; };
2A5149CD2B8766DA00B57A44 /* FileDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */; };
2A5149CE2B8766DA00B57A44 /* FileDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */; };
2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6E5BAE2AF499460052A601 /* CircomTests.swift */; };
4384FD09A96F702A375841EE /* Pods_MoproKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0F9CBE5DD22576996A993 /* Pods_MoproKit_Tests.framework */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -58,6 +60,7 @@
2A5149C32B87615900B57A44 /* keccak256_256_test_final.arkzkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = keccak256_256_test_final.arkzkey; path = "../../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.arkzkey"; sourceTree = "<group>"; };
2A5149C62B87616600B57A44 /* multiplier2_final.arkzkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = multiplier2_final.arkzkey; path = "../../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_final.arkzkey"; sourceTree = "<group>"; };
2A5149C92B87618000B57A44 /* main_final.arkzkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = main_final.arkzkey; path = "../../../../../mopro-core/examples/circom/rsa/target/main_final.arkzkey"; sourceTree = "<group>"; };
2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileDownloader.swift; sourceTree = "<group>"; };
2A6E5BAE2AF499460052A601 /* CircomTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircomTests.swift; sourceTree = "<group>"; };
47F8ADB0AC4168C6E874818D /* MoproKit.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = MoproKit.podspec; path = ../MoproKit.podspec; sourceTree = "<group>"; };
5DAF212A114DFA0C9F4282B2 /* Pods-MoproKit_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Tests.debug.xcconfig"; path = "Target Support Files/Pods-MoproKit_Tests/Pods-MoproKit_Tests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -146,6 +149,7 @@
CEB804572AFF81BF0063F091 /* RSAViewController.swift */,
E6E6F42D2B5860F7002F5F18 /* AnonAadhaarViewControllerNew.swift */,
E69338632AFFDB1A00B80312 /* AnonAadhaarViewController.swift */,
2A5149CC2B8766DA00B57A44 /* FileDownloader.swift */,
CEB804552AFF81AF0063F091 /* KeccakZkeyViewController.swift */,
E6D848582B766C8C00DBAF30 /* ComplexZkeyViewController.swift */,
CEB8044F2AFF81960063F091 /* KeccakSetupViewController.swift */,
Expand Down Expand Up @@ -441,6 +445,7 @@
CEB804502AFF81960063F091 /* KeccakSetupViewController.swift in Sources */,
E6D848592B766C8C00DBAF30 /* ComplexZkeyViewController.swift in Sources */,
E6E6F42E2B5860F7002F5F18 /* AnonAadhaarViewControllerNew.swift in Sources */,
2A5149CD2B8766DA00B57A44 /* FileDownloader.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
E69338642AFFDB1A00B80312 /* AnonAadhaarViewController.swift in Sources */,
);
Expand All @@ -450,6 +455,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2A5149CE2B8766DA00B57A44 /* FileDownloader.swift in Sources */,
2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */,
2A418AB02AF4B1200004B747 /* CircomUITests.swift in Sources */,
);
Expand Down
95 changes: 95 additions & 0 deletions mopro-ios/MoproKit/Example/MoproKit/FileDownloader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// FileDownloader.swift
// MoproKit
//
// Copyright © 2024 CocoaPods. All rights reserved.
//

import Foundation

class FileDownloader {

static func loadFileSync(url: URL, completion: @escaping (String?, Error?) -> Void)
{
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let destinationUrl = documentsUrl.appendingPathComponent(url.lastPathComponent)

if FileManager().fileExists(atPath: destinationUrl.path)
{
print("File already exists [\(destinationUrl.path)]")
completion(destinationUrl.path, nil)
}
else if let dataFromURL = NSData(contentsOf: url)
{
if dataFromURL.write(to: destinationUrl, atomically: true)
{
print("file saved [\(destinationUrl.path)]")
completion(destinationUrl.path, nil)
}
else
{
print("error saving file")
let error = NSError(domain:"Error saving file", code:1001, userInfo:nil)
completion(destinationUrl.path, error)
}
}
else
{
let error = NSError(domain:"Error downloading file", code:1002, userInfo:nil)
completion(destinationUrl.path, error)
}
}

static func loadFileAsync(url: URL, completion: @escaping (String?, Error?) -> Void)
{
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let destinationUrl = documentsUrl.appendingPathComponent(url.lastPathComponent)

if FileManager().fileExists(atPath: destinationUrl.path)
{
print("File already exists [\(destinationUrl.path)]")
completion(destinationUrl.path, nil)
}
else
{
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: nil, delegateQueue: nil)
var request = URLRequest(url: url)
request.httpMethod = "GET"
let task = session.dataTask(with: request, completionHandler:
{
data, response, error in
if error == nil
{
if let response = response as? HTTPURLResponse
{
if response.statusCode == 200
{
if let data = data
{
if let _ = try? data.write(to: destinationUrl, options: Data.WritingOptions.atomic)
{
completion(destinationUrl.path, error)
}
else
{
completion(destinationUrl.path, error)
}
}
else
{
completion(destinationUrl.path, error)
}
}
}
}
else
{
completion(destinationUrl.path, error)
}
})
task.resume()
}
}
}
Loading

0 comments on commit 7a7c467

Please sign in to comment.