Skip to content

Commit 7f8230e

Browse files
Merge pull request #776 from JeneaVranceanu/chore/ec-recover-message-and-hash
chore: hashECRecover and personalECRecover are identical except 1 line
2 parents 58219ae + f8bf43f commit 7f8230e

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

Sources/Web3Core/Utility/Utilities.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,8 @@ public struct Utilities {
231231
/// Recover the Ethereum address from recoverable secp256k1 signature. Message is first hashed using the "personal hash" protocol.
232232
/// BE WARNED - changing a message will result in different Ethereum address, but not in an error.
233233
public static func personalECRecover(_ personalMessage: Data, signature: Data) -> EthereumAddress? {
234-
if signature.count != 65 { return nil }
235-
let rData = signature[0..<32].bytes
236-
let sData = signature[32..<64].bytes
237-
var vData = signature[64]
238-
if vData >= 27 && vData <= 30 {
239-
vData -= 27
240-
} else if vData >= 31 && vData <= 34 {
241-
vData -= 31
242-
} else if vData >= 35 && vData <= 38 {
243-
vData -= 35
244-
}
245-
246-
guard let signatureData = SECP256K1.marshalSignature(v: vData, r: rData, s: sData) else { return nil }
247234
guard let hash = Utilities.hashPersonalMessage(personalMessage) else { return nil }
248-
guard let publicKey = SECP256K1.recoverPublicKey(hash: hash, signature: signatureData) else { return nil }
249-
return Utilities.publicToAddress(publicKey)
235+
return hashECRecover(hash: hash, signature: signature)
250236
}
251237

252238
/// Recover the Ethereum address from recoverable secp256k1 signature.

0 commit comments

Comments
 (0)