diff --git a/Sources/TorusUtils/Convenience/Data+Extension.swift b/Sources/TorusUtils/Convenience/Data+Extension.swift index 4d8acae6..a9feddc6 100755 --- a/Sources/TorusUtils/Convenience/Data+Extension.swift +++ b/Sources/TorusUtils/Convenience/Data+Extension.swift @@ -7,10 +7,11 @@ import Foundation public extension Data { - - init(fromArray values: [T]) { - var values = values - self.init(buffer: UnsafeBufferPointer(start: &values, count: values.count)) + + static func fromArray(values: [T]) -> Data { + return values.withUnsafeBufferPointer{ + return Data(buffer: $0) + } } func toArray(type: T.Type) throws -> [T] { diff --git a/Sources/TorusUtils/Convenience/SECP256k1.swift b/Sources/TorusUtils/Convenience/SECP256k1.swift index 70989184..76432c59 100755 --- a/Sources/TorusUtils/Convenience/SECP256k1.swift +++ b/Sources/TorusUtils/Convenience/SECP256k1.swift @@ -110,7 +110,9 @@ extension SECP256K1 { let result = privateKey.withUnsafeBytes { (pkRawBufferPointer: UnsafeRawBufferPointer) -> Int32? in if let pkRawPointer = pkRawBufferPointer.baseAddress, pkRawBufferPointer.count > 0 { let privateKeyPointer = pkRawPointer.assumingMemoryBound(to: UInt8.self) - let res = secp256k1_ec_pubkey_create(context!, UnsafeMutablePointer(&publicKey), privateKeyPointer) + let res = withUnsafeMutablePointer(to: &publicKey){ + secp256k1_ec_pubkey_create(context!, $0, privateKeyPointer) + } return res } else { return nil @@ -157,7 +159,11 @@ extension SECP256K1 { let result = serializedKey.withUnsafeBytes { (serializedKeyRawBufferPointer: UnsafeRawBufferPointer) -> Int32? in if let serializedKeyRawPointer = serializedKeyRawBufferPointer.baseAddress, serializedKeyRawBufferPointer.count > 0 { let serializedKeyPointer = serializedKeyRawPointer.assumingMemoryBound(to: UInt8.self) - let res = secp256k1_ec_pubkey_parse(context!, UnsafeMutablePointer(&publicKey), serializedKeyPointer, keyLen) + + let res = withUnsafeMutablePointer(to: &publicKey){ + secp256k1_ec_pubkey_parse(context!, $0, serializedKeyPointer, keyLen) + } + return res } else { return nil diff --git a/Sources/TorusUtils/Extensions/TorusUtils+extension.swift b/Sources/TorusUtils/Extensions/TorusUtils+extension.swift index 3d665ead..06e071b7 100644 --- a/Sources/TorusUtils/Extensions/TorusUtils+extension.swift +++ b/Sources/TorusUtils/Extensions/TorusUtils+extension.swift @@ -80,8 +80,9 @@ extension TorusUtils { let result = privateKey.withUnsafeBytes { (a: UnsafeRawBufferPointer) -> Int32? in if let pkRawPointer = a.baseAddress, let ctx = TorusUtils.context, a.count > 0 { let privateKeyPointer = pkRawPointer.assumingMemoryBound(to: UInt8.self) - let res = secp256k1_ec_pubkey_tweak_mul( - ctx, UnsafeMutablePointer(&localPubkey), privateKeyPointer) + let res = withUnsafeMutablePointer(to: &localPubkey){ + secp256k1_ec_pubkey_tweak_mul(ctx, $0, privateKeyPointer) + } return res } else { return nil @@ -105,12 +106,12 @@ extension TorusUtils { return promise } - guard let encoded = encoded else { + guard let encodedUnwrapped = encoded else { seal.reject(TorusError.runtime("Unable to serialize dictionary into JSON.")) return promise } let request = try! self.makeUrlRequest(url: "https://metadata.tor.us/get") - let task = URLSession.shared.uploadTask(.promise, with: request, from: encoded) + let task = URLSession.shared.uploadTask(.promise, with: request, from: encodedUnwrapped) task.compactMap { try JSONSerialization.jsonObject(with: $0.data) as? [String: Any] }.done{ data in diff --git a/Sources/TorusUtils/Helpers/JSONRPCRequest.swift b/Sources/TorusUtils/Helpers/JSONRPCRequest.swift index 7ce1a0ff..0929025d 100644 --- a/Sources/TorusUtils/Helpers/JSONRPCRequest.swift +++ b/Sources/TorusUtils/Helpers/JSONRPCRequest.swift @@ -121,7 +121,7 @@ public struct JSONRPCrequest: Encodable { public struct JSONRPCresponse: Codable{ public var id: Int public var jsonrpc = "2.0" - public var result: Any + public var result: Any? public var error: ErrorMessage? public var message: String?