Open Sajjon opened 5 years ago
I think the signature and verify works if I take the sha256 hash of the data of the message first.
So changing:
let message = "Hello BitcoinKit".data(using: .utf8)!
to:
Crypto.sha256("Hello BitcoinKit".data(using: .utf8)!)
But this was not documented. Also it might be a good idea to change:
public static func sign(_ data: Data, privateKey: BitcoinKit.PrivateKey) throws -> Data
to
public static func sign(hashedData: Data, privateKey: PrivateKey) throws -> Data {
guard hashedData.count == 32 else {
throw Error.dataShouldHaveLengthOf32
}
....
}
and add a method:
public static func sign(message: String, encoding: String.Encoding = .utf8, privateKey: PrivateKey) throws -> Data {
guard let encoded = message.data(using: encoding) else {
throw Error.failedToEncodeMessage
}
return sign(hashedData: Crypto.sha256(encoded), privateKey: privateKey)
}
Current behavior
BitcoinKit built using Carthage:
verifySignature
fails ~ 10% of the times. This seems troublesome.Expected behavior
I expect a signature to always validate.
Steps to reproduce
Just create a Xcode project, and create a Unit Test file and paste this code. I'm using this in a Cocoa Touch Framework.
Environment