Skip to content

Commit

Permalink
fix: ci build issues (#20)
Browse files Browse the repository at this point in the history
* fix: swift error

* fix: kukai ci issues
  • Loading branch information
michaellee8 authored Oct 26, 2021
1 parent 4ad891b commit 79d4682
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions Sources/TorusUtils/Convenience/Data+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import Foundation

public extension Data {

init<T>(fromArray values: [T]) {
var values = values
self.init(buffer: UnsafeBufferPointer(start: &values, count: values.count))

static func fromArray<T>(values: [T]) -> Data {
return values.withUnsafeBufferPointer{
return Data(buffer: $0)
}
}

func toArray<T>(type: T.Type) throws -> [T] {
Expand Down
10 changes: 8 additions & 2 deletions Sources/TorusUtils/Convenience/SECP256k1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<secp256k1_pubkey>(&publicKey), privateKeyPointer)
let res = withUnsafeMutablePointer(to: &publicKey){
secp256k1_ec_pubkey_create(context!, $0, privateKeyPointer)
}
return res
} else {
return nil
Expand Down Expand Up @@ -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<secp256k1_pubkey>(&publicKey), serializedKeyPointer, keyLen)

let res = withUnsafeMutablePointer(to: &publicKey){
secp256k1_ec_pubkey_parse(context!, $0, serializedKeyPointer, keyLen)
}

return res
} else {
return nil
Expand Down
9 changes: 5 additions & 4 deletions Sources/TorusUtils/Extensions/TorusUtils+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<secp256k1_pubkey>(&localPubkey), privateKeyPointer)
let res = withUnsafeMutablePointer(to: &localPubkey){
secp256k1_ec_pubkey_tweak_mul(ctx, $0, privateKeyPointer)
}
return res
} else {
return nil
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/TorusUtils/Helpers/JSONRPCRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit 79d4682

Please sign in to comment.