I am trying to sign signature as well as verify using Sawtooth SDK from Sawtooth SDK. Looking at the documentation, i followed through but it didnt work.
import SawtoothSigning
public class Secp256k1 {
private var signer: Signer
private var privateKey: PrivateKey
private var context = Secp256k1Context() //Here it crashed with error Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeda61ff8)
public func sign(message: [UInt8]) -> String {
var result = ""
do {
result = try signer.sign(data: message)
} catch {
print("Error signing")
}
return result
}
public func getPrivateKey() -> PrivateKey {
if let privateKey = UserDefaults.standard.string(forKey: "privateKey") {
return Secp256k1PrivateKey.fromHex(hexPrivKey: privateKey)
} else {
let privateKey = context.newRandomPrivateKey()
UserDefaults.standard.set(privateKey.hex(), forKey: "privateKey" )
do {
let pubKey = try context.getPublicKey(privateKey: privateKey)
UserDefaults.standard.set(pubKey.hex(), forKey: "publicKey" )
} catch {
if #available(iOS 10.0, *) {
print("Error creating public key")
}
}
return privateKey
}
}
public init() {
self.privateKey = Secp256k1().getPrivateKey()
self.signer = Signer(context: context, privateKey: self.privateKey)
}
}
Have anyone worked with this SDK and knows why is it crashing? Or is there any simpler SDK?