Skip to content

Commit

Permalink
- remove watermark from verify
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed May 15, 2023
1 parent d86d4e4 commit cda79d3
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions Sources/KukaiCryptoSwift/PublicKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@ public struct PublicKey: Codable {
- Returns: True if the public key and signature match the given bytes.
*/
public func verify(signature: [UInt8], bytes: [UInt8]) -> Bool {
guard let bytesToVerify = prepareBytesForVerification(bytes) else {
return false
}

switch signingCurve {
case .ed25519:
return Sodium.shared.sign.verify(message: bytesToVerify, publicKey: self.bytes, signature: signature)
return Sodium.shared.sign.verify(message: signature, publicKey: self.bytes, signature: signature)

case .secp256k1:
let context = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_VERIFY))
Expand All @@ -118,15 +114,9 @@ public struct PublicKey: Codable {
secp256k1_ecdsa_signature_parse_compact(context!, &cSignature, signature)
_ = secp256k1_ec_pubkey_parse(context!, &publicKey, self.bytes, self.bytes.count)

return secp256k1_ecdsa_verify(context!, &cSignature, bytesToVerify, &publicKey) == 1
return secp256k1_ecdsa_verify(context!, &cSignature, signature, &publicKey) == 1
}
}

/// Prepare bytes for verification by applying a watermark and hashing.
private func prepareBytesForVerification(_ bytes: [UInt8]) -> [UInt8]? {
let watermarkedOperation = Prefix.Watermark.operation + bytes
return Sodium.shared.genericHash.hash(message: watermarkedOperation, outputLength: 32)
}
}

extension PublicKey: CustomStringConvertible {
Expand Down

0 comments on commit cda79d3

Please sign in to comment.