Skip to content

Commit a94d5bb

Browse files
author
Paul Robinson
authored
add personal_sign and personal_ec_recover docs (#2511)
1 parent 31f7ab9 commit a94d5bb

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

docs/web3.geth.rst

+46-19
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,33 @@ GethPersonal API
185185

186186
The following methods are available on the ``web3.geth.personal`` namespace.
187187

188+
.. py:method:: ec_recover(message, signature)
189+
190+
* Delegates to ``personal_ecRecover`` RPC Method
191+
192+
Returns the address associated with a signature created with ``personal.sign``.
193+
194+
.. code-block:: python
195+
196+
>>> web3.geth.personal.sign('snakesnax', '0x9ad3c920dce5cea9a31d69467bb8d7c954e5acff', '')
197+
'0x8eb502165dec388af1c45c4bc835fd1852eaf358316ae5d248a40af8cd8dd7dc6373a6e606d8b411f788718b8b09a6cf87d980639731f530e4481148f14abfdf1b'
198+
>>> web3.geth.personal.ec_recover('snakesnax', '0x8eb502165dec388af1c45c4bc835fd1852eaf358316ae5d248a40af8cd8dd7dc6373a6e606d8b411f788718b8b09a6cf87d980639731f530e4481148f14abfdf1b')
199+
'0x9ad3c920dce5cea9a31d69467bb8d7c954e5acff'
200+
201+
202+
.. py:method:: import_raw_key(private_key, passphrase)
203+
204+
* Delegates to ``personal_importRawKey`` RPC Method
205+
206+
Adds the given ``private_key`` to the node's keychain, encrypted with the
207+
given ``passphrase``. Returns the address of the imported account.
208+
209+
.. code-block:: python
210+
211+
>>> web3.geth.personal.import_raw_key(some_private_key, 'the-passphrase')
212+
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
213+
214+
188215
.. py:method:: list_accounts()
189216
190217
* Delegates to ``personal_listAccounts`` RPC Method
@@ -216,20 +243,19 @@ The following methods are available on the ``web3.geth.personal`` namespace.
216243
}]
217244
218245
219-
.. py:method:: import_raw_key(self, private_key, passphrase)
246+
.. py:method:: lock_account(account)
220247
221-
* Delegates to ``personal_importRawKey`` RPC Method
248+
* Delegates to ``personal_lockAccount`` RPC Method
222249

223-
Adds the given ``private_key`` to the node's keychain, encrypted with the
224-
given ``passphrase``. Returns the address of the imported account.
250+
Locks the given ``account``.
225251

226252
.. code-block:: python
227253
228-
>>> web3.geth.personal.import_raw_key(some_private_key, 'the-passphrase')
229-
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
254+
>>> web3.geth.personal.lock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
255+
True
230256
231257
232-
.. py:method:: new_account(self, passphrase)
258+
.. py:method:: new_account(passphrase)
233259
234260
* Delegates to ``personal_newAccount`` RPC Method
235261

@@ -242,18 +268,26 @@ The following methods are available on the ``web3.geth.personal`` namespace.
242268
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
243269
244270
245-
.. py:method:: lock_account(self, account)
271+
.. py:method:: send_transaction(transaction, passphrase)
246272
247-
* Delegates to ``personal_lockAccount`` RPC Method
273+
* Delegates to ``personal_sendTransaction`` RPC Method
248274

249-
Locks the given ``account``.
275+
Sends the transaction.
250276

277+
278+
.. py:method:: sign(message, account, passphrase)
279+
280+
* Delegates to ``personal_sign`` RPC Method
281+
282+
Generates an Ethereum-specific signature for ``keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))``
283+
251284
.. code-block:: python
252285
253-
>>> web3.geth.personal.lock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
286+
>>> web3.geth.personal.sign('snakesnax', '0x9ad3c920dce5cea9a31d69467bb8d7c954e5acff', '')
287+
'0x8eb502165dec388af1c45c4bc835fd1852eaf358316ae5d248a40af8cd8dd7dc6373a6e606d8b411f788718b8b09a6cf87d980639731f530e4481148f14abfdf1b'
254288
255289
256-
.. py:method:: unlock_account(self, account, passphrase, duration=None)
290+
.. py:method:: unlock_account(account, passphrase, duration=None)
257291
258292
* Delegates to ``personal_unlockAccount`` RPC Method
259293

@@ -271,13 +305,6 @@ The following methods are available on the ``web3.geth.personal`` namespace.
271305
True
272306
273307
274-
.. py:method:: send_transaction(self, transaction, passphrase)
275-
276-
* Delegates to ``personal_sendTransaction`` RPC Method
277-
278-
Sends the transaction.
279-
280-
281308
.. py:module:: web3.geth.txpool
282309
283310
GethTxPool API

newsfragments/2511.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
removed `Optional` type hints for `passphrase` arguments that aren't actually optional

newsfragments/2511.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
added geth personal_sign and personal_ec_recover documentation

web3/geth.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def new_account(self, passphrase: str) -> ChecksumAddress:
113113
def send_transaction(self, transaction: TxParams, passphrase: str) -> HexBytes:
114114
return self._send_transaction(transaction, passphrase)
115115

116-
def sign(self, message: str, account: ChecksumAddress, password: Optional[str]) -> HexStr:
117-
return self._sign(message, account, password)
116+
def sign(self, message: str, account: ChecksumAddress, passphrase: str) -> HexStr:
117+
return self._sign(message, account, passphrase)
118118

119119
def sign_typed_data(self,
120120
message: Dict[str, Any],
121121
account: ChecksumAddress,
122-
password: Optional[str]) -> HexStr:
123-
return self._sign_typed_data(message, account, password)
122+
passphrase: str) -> HexStr:
123+
return self._sign_typed_data(message, account, passphrase)
124124

125125
def unlock_account(self,
126126
account: ChecksumAddress,
@@ -156,14 +156,14 @@ async def send_transaction(self, transaction: TxParams, passphrase: str) -> Awai
156156
async def sign(self,
157157
message: str,
158158
account: ChecksumAddress,
159-
password: Optional[str]) -> Awaitable[HexStr]:
160-
return await self._sign(message, account, password) # type: ignore
159+
passphrase: str) -> Awaitable[HexStr]:
160+
return await self._sign(message, account, passphrase) # type: ignore
161161

162162
async def sign_typed_data(self,
163163
message: Dict[str, Any],
164164
account: ChecksumAddress,
165-
password: Optional[str]) -> Awaitable[HexStr]:
166-
return await self._sign_typed_data(message, account, password) # type: ignore
165+
passphrase: str) -> Awaitable[HexStr]:
166+
return await self._sign_typed_data(message, account, passphrase) # type: ignore
167167

168168
async def unlock_account(self,
169169
account: ChecksumAddress,

0 commit comments

Comments
 (0)