From de5bfc71fbdfa0ce3267eb8cdd171a9fc0607961 Mon Sep 17 00:00:00 2001
From: metalurgical <97008724+metalurgical@users.noreply.github.com>
Date: Tue, 17 Dec 2024 07:58:35 +0200
Subject: [PATCH 1/2] fix: use multipart request for bulk_set_stream

---
 Sources/ThresholdKey/StorageLayer.swift | 34 ++++++++++---------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/Sources/ThresholdKey/StorageLayer.swift b/Sources/ThresholdKey/StorageLayer.swift
index 92ce5ee..ebb34c8 100644
--- a/Sources/ThresholdKey/StorageLayer.swift
+++ b/Sources/ThresholdKey/StorageLayer.swift
@@ -51,29 +51,23 @@ public final class StorageLayer {
             request.addValue("Content-Type", forHTTPHeaderField: "Access-Control-Allow-Headers")
 
             if urlString.split(separator: "/").last == "bulk_set_stream" {
-                // let boundary = UUID().uuidString;
-                // request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
-                request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
+                let boundary = "Boundary-\(UUID().uuidString)"
+                request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
 
                 let json = try! JSONSerialization.jsonObject(with: dataString.data(using: String.Encoding.utf8)!, options: .allowFragments) as! [[String: Any]]
-
-                // for item in json {
-                    // let dataItem = try! JSONSerialization.data(withJSONObject: item, options: .prettyPrinted)
-                    // requestData.append(StorageLayer.createMultipartBody(data: dataItem, boundary: boundary, file: "multipartData"))
-                // }
-
-                var form_data: [String] = []
-
-                // urlencoded item format: "(key)=(self.percentEscapeString(value))"
-                for (index, element) in json.enumerated() {
-                    let json_elem = try! JSONSerialization.data(withJSONObject: element, options: .withoutEscapingSlashes)
-                    let json_escaped_string = StorageLayer.percentEscapeString(string: String(data: json_elem, encoding: .utf8)!)
-                    let final_string = String(index) + "=" + json_escaped_string
-                    form_data.append(final_string)
+                
+                var body_data = Data()
+                
+                for (index, item) in json.enumerated() {
+                    body_data.append("--\(boundary)\r\n".data(using: .utf8)!)
+                    body_data.append("Content-Disposition: form-data; name=\"\(index)\"\r\n\r\n".data(using: .utf8)!)
+                     
+                    let dataItem = String(data: try! JSONSerialization.data(withJSONObject: item), encoding: .utf8)!
+                    body_data.append("\(dataItem)\r\n".data(using: .utf8)!)
                 }
-                let body_data = form_data.joined(separator: "&")
-
-                request.httpBody = body_data.data(using: String.Encoding.utf8)
+                body_data.append("--\(boundary)--\r\n".data(using: .utf8)!)
+                
+                request.httpBody = body_data
             } else {
                 request.addValue("application/json", forHTTPHeaderField: "Content-Type")
                 request.httpBody = dataString.data(using: String.Encoding.utf8)

From 2c801af48a64cab6fe754596d3c1c8f3345102dd Mon Sep 17 00:00:00 2001
From: metalurgical <97008724+metalurgical@users.noreply.github.com>
Date: Fri, 3 Jan 2025 07:48:23 +0200
Subject: [PATCH 2/2] update podspec

---
 tkey-mpc-swift.podspec | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tkey-mpc-swift.podspec b/tkey-mpc-swift.podspec
index 67b0a30..67f15c9 100644
--- a/tkey-mpc-swift.podspec
+++ b/tkey-mpc-swift.podspec
@@ -1,6 +1,6 @@
 Pod::Spec.new do |spec|
   spec.name         = "tkey-mpc-swift"
-  spec.version      = "4.0.0"
+  spec.version      = "4.0.1"
   spec.platform = :ios, "14.0"
   spec.summary      = "SDK allows you to create threshold key setup natively with multiparty computation support"
   spec.homepage     = "https://web3auth.io/"