Skip to content

Commit dab2667

Browse files
Merge pull request #824 from JuyeonYu/noHashInSign
feat: sign without hash
2 parents 4833b1c + c9e0edd commit dab2667

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/web3swift/Web3/Web3+Signing.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ public struct Web3Signer {
2323
keystore: T,
2424
account: EthereumAddress,
2525
password: String,
26+
useHash: Bool = true,
2627
useExtraEntropy: Bool = false) throws -> Data? {
2728
var privateKey = try keystore.UNSAFE_getPrivateKeyData(password: password, account: account)
2829
defer { Data.zero(&privateKey) }
29-
guard let hash = Utilities.hashPersonalMessage(personalMessage) else { return nil }
30-
let (compressedSignature, _) = SECP256K1.signForRecovery(hash: hash,
30+
var data: Data
31+
if useHash {
32+
guard let hash = Utilities.hashPersonalMessage(personalMessage) else { return nil }
33+
data = hash
34+
} else {
35+
data = personalMessage
36+
}
37+
let (compressedSignature, _) = SECP256K1.signForRecovery(hash: data,
3138
privateKey: privateKey,
3239
useExtraEntropy: useExtraEntropy)
3340
return compressedSignature

0 commit comments

Comments
 (0)