Skip to content

Commit 2a155d3

Browse files
chore: hashECRecover and personalECRecover are identical except 1 line
1 parent bce743e commit 2a155d3

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
@@ -206,22 +206,8 @@ public struct Utilities {
206206
///
207207
/// Input parameters should be Data objects.
208208
public static func personalECRecover(_ personalMessage: Data, signature: Data) -> EthereumAddress? {
209-
if signature.count != 65 { return nil}
210-
let rData = signature[0..<32].bytes
211-
let sData = signature[32..<64].bytes
212-
var vData = signature[64]
213-
if vData >= 27 && vData <= 30 {
214-
vData -= 27
215-
} else if vData >= 31 && vData <= 34 {
216-
vData -= 31
217-
} else if vData >= 35 && vData <= 38 {
218-
vData -= 35
219-
}
220-
221-
guard let signatureData = SECP256K1.marshalSignature(v: vData, r: rData, s: sData) else { return nil }
222209
guard let hash = Utilities.hashPersonalMessage(personalMessage) else { return nil }
223-
guard let publicKey = SECP256K1.recoverPublicKey(hash: hash, signature: signatureData) else { return nil }
224-
return Utilities.publicToAddress(publicKey)
210+
return hashECRecover(hash: hash, signature: signature)
225211
}
226212

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

0 commit comments

Comments
 (0)