From 2a155d371993826ddd077436b1345c8dd8424549 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 11 Feb 2023 18:22:30 +0200 Subject: [PATCH] chore: hashECRecover and personalECRecover are identical except 1 line --- Sources/Web3Core/Utility/Utilities.swift | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Sources/Web3Core/Utility/Utilities.swift b/Sources/Web3Core/Utility/Utilities.swift index 4524bcd98..310a8e26e 100644 --- a/Sources/Web3Core/Utility/Utilities.swift +++ b/Sources/Web3Core/Utility/Utilities.swift @@ -206,22 +206,8 @@ public struct Utilities { /// /// Input parameters should be Data objects. public static func personalECRecover(_ personalMessage: Data, signature: Data) -> EthereumAddress? { - if signature.count != 65 { return nil} - let rData = signature[0..<32].bytes - let sData = signature[32..<64].bytes - var vData = signature[64] - if vData >= 27 && vData <= 30 { - vData -= 27 - } else if vData >= 31 && vData <= 34 { - vData -= 31 - } else if vData >= 35 && vData <= 38 { - vData -= 35 - } - - guard let signatureData = SECP256K1.marshalSignature(v: vData, r: rData, s: sData) else { return nil } guard let hash = Utilities.hashPersonalMessage(personalMessage) else { return nil } - guard let publicKey = SECP256K1.recoverPublicKey(hash: hash, signature: signatureData) else { return nil } - return Utilities.publicToAddress(publicKey) + return hashECRecover(hash: hash, signature: signature) } /// Recover the Ethereum address from recoverable secp256k1 signature.