Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Added signTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
DantePuglisi committed Jul 13, 2022
1 parent 0107fcd commit d978df3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion SolanaWrapperDemo/SolanaWrapperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class ViewController: UIViewController {
} failure: { error in
print(error)
}*/
solana.getAddress(path: self.DERIVATION_PATH_SOL) { response in
/*solana.getAddress(path: self.DERIVATION_PATH_SOL) { response in
print("Response received: \(response)")
} failure: { error in
print(error)
}*/
solana.signTransaction(path: self.DERIVATION_PATH_SOL, txBuffer: [1, 2, 3]) { response in
print("Response received: \(response)")
} failure: { error in
print(error)
Expand Down
5 changes: 4 additions & 1 deletion Sources/SolanaWrapper/JavaScript/bundle.js

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion Sources/SolanaWrapper/SolanaWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class SolanaWrapper: Wrapper {
return jsContext
}()

var transportInstance: JSValue?
var solanaInstance: JSValue?

public override init() {
Expand All @@ -54,7 +55,8 @@ public class SolanaWrapper: Wrapper {
fileprivate func loadInstance() {
guard let module = jsContext.objectForKeyedSubscript("TransportModule") else { return }
guard let transportModule = module.objectForKeyedSubscript("TransportBLEiOS") else { return }
guard let transportInstance = transportModule.construct(withArguments: []) else { return }
transportInstance = transportModule.construct(withArguments: [])
guard let transportInstance = transportInstance else { return }
guard let solanaModule = module.objectForKeyedSubscript("Solana") else { return }
solanaInstance = solanaModule.construct(withArguments: [transportInstance])
}
Expand Down Expand Up @@ -96,6 +98,25 @@ public class SolanaWrapper: Wrapper {
}
}
}

public func signTransaction(path: String, txBuffer: [UInt8], success: @escaping ((String)->()), failure: @escaping ((String)->())) {
guard let solanaInstance = solanaInstance else { return }
guard let transportInstance = transportInstance else { return }
guard let buffer = transportInstance.invokeMethod("arrayToBuffer", withArguments: [txBuffer]) else { failure("Couldn't create buffer"); return }
solanaInstance.invokeMethodAsync("signTransaction", withArguments: [path, buffer]) { resolve, reject in
if let resolve = resolve {
if let dict = resolve.toDictionary() as? [String: Any], let addressDict = dict["signature"] as? [String: AnyObject] {
let data = self.parseBuffer(dict: addressDict)
let base58 = Base58.base58Encode(data)
success(base58)
} else {
failure("Resolved but couldn't parse")
}
} else if let reject = reject {
failure("REJECTED. Value: \(reject)")
}
}
}
}

enum PubKeyDisplayMode: Int {
Expand Down

0 comments on commit d978df3

Please sign in to comment.