@@ -44,7 +44,6 @@ public struct K256Operations {
4444 /// - Throws: An error if signature verification fails.
4545 public static func verifySignature( publicKey: [ UInt8 ] , data: [ UInt8 ] , signature: [ UInt8 ] , options: VerifyOptions ? = nil ) async throws -> Bool {
4646 let allowMalleable = options? . areMalleableSignaturesAllowed ?? false
47- let hashedData = await SHA256Hasher . sha256 ( data)
4847
4948 guard let publicKey = try ? secp256k1. Signing. PublicKey ( dataRepresentation: publicKey, format: . compressed) else {
5049 throw EllipticalCurveOperationsError . invalidPublicKey
@@ -57,15 +56,15 @@ public struct K256Operations {
5756 throw EllipticalCurveOperationsError . invalidSignatureFormat
5857 }
5958
60- guard let parsedSignature = try ? secp256k1. Signing. ECDSASignature ( dataRepresentation : signatureData) else {
59+ guard let parsedSignature = try ? secp256k1. Signing. ECDSASignature ( compactRepresentation : signatureData) else {
6160 return false
6261 }
6362
6463 guard let correctedSignature = parsedSignature. normalizedForK256 ( ) else {
6564 return false
6665 }
6766
68- return publicKey. isValidSignature ( correctedSignature, for: Data ( hashedData ) )
67+ return publicKey. isValidSignature ( correctedSignature, for: Data ( data ) )
6968 }
7069
7170 /// Checks if a signature is in compact format.
@@ -75,11 +74,9 @@ public struct K256Operations {
7574 public static func isCompactFormat( _ signature: [ UInt8 ] ) -> Bool {
7675 // ECDSA k256 signatures should be exactly 64 bytes in compact form.
7776 do {
78- // Attempt to initialize a P-256 signature from compact representation.
79- let ecdsaSignature = try secp256k1. Signing. ECDSASignature ( dataRepresentation: signature)
80-
81- // Convert back to raw representation and compare with input
82- return ecdsaSignature. dataRepresentation == signature. toData ( )
77+ // Attempt to parse as a compact representation.
78+ _ = try secp256k1. Signing. ECDSASignature ( compactRepresentation: signature)
79+ return true
8380 } catch {
8481 return false
8582 }
0 commit comments