Skip to content

Commit 1c0f2f7

Browse files
fix: docs fix in Web3.Personal
1 parent bce743e commit 1c0f2f7

File tree

1 file changed

+33
-62
lines changed

1 file changed

+33
-62
lines changed

Sources/web3swift/Web3/Web3+Personal.swift

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,48 @@ import Web3Core
99

1010
extension Web3.Personal {
1111

12-
/**
13-
*Locally or remotely sign a message (arbitrary data) with the private key. To avoid potential signing of a transaction the message is first prepended by a special header and then hashed.*
14-
15-
- parameters:
16-
- message: Message Data
17-
- from: Use a private key that corresponds to this account
18-
- password: Password for account if signing locally
19-
20-
- returns:
21-
- Result object
22-
23-
- important: This call is synchronous
24-
25-
*/
12+
/// Locally or remotely sign a message (arbitrary data) with the private key.
13+
/// To avoid potential signing of a transaction the message is first prepended by a special header and then hashed.
14+
/// - Parameters:
15+
/// - message: raw message as bytes (e.g. UTF-8 bytes of a string);
16+
/// - from: an account whose private key will be used;
17+
/// - password: password to extract private key;
18+
/// - Returns: signed personal message
2619
public func signPersonalMessage(message: Data, from: EthereumAddress, password: String) async throws -> Data {
27-
let result = try await self.signPersonal(message: message, from: from, password: password)
20+
let result = try await signPersonal(message: message, from: from, password: password)
2821
return result
2922
}
3023

31-
/**
32-
*Unlock an account on the remote node to be able to send transactions and sign messages.*
33-
34-
- parameters:
35-
- account: EthereumAddress of the account to unlock
36-
- password: Password to use for the account
37-
- seconds: Time interval before automatic account lock by Ethereum node
38-
39-
- returns:
40-
- Result object
41-
42-
- important: This call is synchronous. Does nothing if private keys are stored locally.
43-
44-
*/
24+
/// Unlock an account on the remote node to be able to send transactions and sign messages.
25+
/// - Parameters:
26+
/// - account: EthereumAddress of the account to unlock
27+
/// - password: Password for the account
28+
/// - seconds: Time interval before automatic account lock by Ethereum node. Default 300
29+
/// - Returns: `true` if account was unlocked.
4530
public func unlockAccount(account: EthereumAddress, password: String, seconds: UInt = 300) async throws -> Bool {
46-
let result = try await self.unlock(account: account, password: password)
31+
let result = try await unlock(account: account, password: password)
4732
return result
4833
}
4934

50-
/**
51-
*Recovers a signer of some message. Message is first prepended by special prefix (check the "signPersonalMessage" method description) and then hashed.*
52-
53-
- parameters:
54-
- personalMessage: Message Data
55-
- signature: Serialized signature, 65 bytes
56-
57-
- returns:
58-
- Result object
59-
60-
*/
61-
public func ecrecover(personalMessage: Data, signature: Data) throws -> EthereumAddress {
62-
guard let recovered = Utilities.personalECRecover(personalMessage, signature: signature) else {
63-
throw Web3Error.dataError
64-
}
65-
return recovered
35+
/// Recovers a signer of some personal message. Message will be first prepended by special prefix
36+
/// (check the "signPersonalMessage" method description) and then hashed before the recovery attempt.
37+
///
38+
/// If you have a hash instead of a message use ``Web3/Personal/ecrecover(hash:signature:)``
39+
///
40+
/// - Parameters:
41+
/// - personalMessage: raw message as bytes (e.g. UTF-8 bytes of a string);
42+
/// - signature: signature that is the result of signing the `personalMessage`;
43+
/// - Returns: address of the signer or `nil`.
44+
public func ecrecover(personalMessage: Data, signature: Data) -> EthereumAddress? {
45+
Utilities.personalECRecover(personalMessage, signature: signature)
6646
}
6747

68-
/**
69-
*Recovers a signer of some hash. Checking what is under this hash is on behalf of the user.*
70-
71-
- parameters:
72-
- hash: Signed hash
73-
- signature: Serialized signature, 65 bytes
74-
75-
- returns:
76-
- Result object
77-
78-
*/
79-
public func ecrecover(hash: Data, signature: Data) throws -> EthereumAddress {
80-
guard let recovered = Utilities.hashECRecover(hash: hash, signature: signature) else {
81-
throw Web3Error.dataError
82-
}
83-
return recovered
48+
/// Recovers a signer of some hash.
49+
/// - Parameters:
50+
/// - hash: some hash, e.g. hashed personal message;
51+
/// - signature: 65 bytes serialized signature;
52+
/// - Returns: address of the signer or `nil`.
53+
public func ecrecover(hash: Data, signature: Data) -> EthereumAddress {
54+
Utilities.hashECRecover(hash: hash, signature: signature)
8455
}
8556
}

0 commit comments

Comments
 (0)