Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions Sources/Web3Core/Utility/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,8 @@ public struct Utilities {
/// Recover the Ethereum address from recoverable secp256k1 signature. Message is first hashed using the "personal hash" protocol.
/// BE WARNED - changing a message will result in different Ethereum address, but not in an error.
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.
Expand Down