Skip to content
Merged
Show file tree
Hide file tree
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
65 changes: 46 additions & 19 deletions docs/web3.geth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,33 @@ GethPersonal API

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

.. py:method:: ec_recover(message, signature)

* Delegates to ``personal_ecRecover`` RPC Method

Returns the address associated with a signature created with ``personal.sign``.

.. code-block:: python

>>> web3.geth.personal.sign('snakesnax', '0x9ad3c920dce5cea9a31d69467bb8d7c954e5acff', '')
'0x8eb502165dec388af1c45c4bc835fd1852eaf358316ae5d248a40af8cd8dd7dc6373a6e606d8b411f788718b8b09a6cf87d980639731f530e4481148f14abfdf1b'
>>> web3.geth.personal.ec_recover('snakesnax', '0x8eb502165dec388af1c45c4bc835fd1852eaf358316ae5d248a40af8cd8dd7dc6373a6e606d8b411f788718b8b09a6cf87d980639731f530e4481148f14abfdf1b')
'0x9ad3c920dce5cea9a31d69467bb8d7c954e5acff'


.. py:method:: import_raw_key(private_key, passphrase)

* Delegates to ``personal_importRawKey`` RPC Method

Adds the given ``private_key`` to the node's keychain, encrypted with the
given ``passphrase``. Returns the address of the imported account.

.. code-block:: python

>>> web3.geth.personal.import_raw_key(some_private_key, 'the-passphrase')
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'


.. py:method:: list_accounts()

* Delegates to ``personal_listAccounts`` RPC Method
Expand Down Expand Up @@ -216,20 +243,19 @@ The following methods are available on the ``web3.geth.personal`` namespace.
}]


.. py:method:: import_raw_key(self, private_key, passphrase)
.. py:method:: lock_account(account)

* Delegates to ``personal_importRawKey`` RPC Method
* Delegates to ``personal_lockAccount`` RPC Method

Adds the given ``private_key`` to the node's keychain, encrypted with the
given ``passphrase``. Returns the address of the imported account.
Locks the given ``account``.

.. code-block:: python

>>> web3.geth.personal.import_raw_key(some_private_key, 'the-passphrase')
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
>>> web3.geth.personal.lock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
True


.. py:method:: new_account(self, passphrase)
.. py:method:: new_account(passphrase)

* Delegates to ``personal_newAccount`` RPC Method

Expand All @@ -242,18 +268,26 @@ The following methods are available on the ``web3.geth.personal`` namespace.
'0xd3CdA913deB6f67967B99D67aCDFa1712C293601'


.. py:method:: lock_account(self, account)
.. py:method:: send_transaction(transaction, passphrase)

* Delegates to ``personal_lockAccount`` RPC Method
* Delegates to ``personal_sendTransaction`` RPC Method

Locks the given ``account``.
Sends the transaction.


.. py:method:: sign(message, account, passphrase)

* Delegates to ``personal_sign`` RPC Method

Generates an Ethereum-specific signature for ``keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))``

.. code-block:: python

>>> web3.geth.personal.lock_account('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
>>> web3.geth.personal.sign('snakesnax', '0x9ad3c920dce5cea9a31d69467bb8d7c954e5acff', '')
'0x8eb502165dec388af1c45c4bc835fd1852eaf358316ae5d248a40af8cd8dd7dc6373a6e606d8b411f788718b8b09a6cf87d980639731f530e4481148f14abfdf1b'


.. py:method:: unlock_account(self, account, passphrase, duration=None)
.. py:method:: unlock_account(account, passphrase, duration=None)

* Delegates to ``personal_unlockAccount`` RPC Method

Expand All @@ -271,13 +305,6 @@ The following methods are available on the ``web3.geth.personal`` namespace.
True


.. py:method:: send_transaction(self, transaction, passphrase)

* Delegates to ``personal_sendTransaction`` RPC Method

Sends the transaction.


.. py:module:: web3.geth.txpool

GethTxPool API
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2511.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
removed `Optional` type hints for `passphrase` arguments that aren't actually optional
1 change: 1 addition & 0 deletions newsfragments/2511.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
added geth personal_sign and personal_ec_recover documentation
16 changes: 8 additions & 8 deletions web3/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def new_account(self, passphrase: str) -> ChecksumAddress:
def send_transaction(self, transaction: TxParams, passphrase: str) -> HexBytes:
return self._send_transaction(transaction, passphrase)

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

def sign_typed_data(self,
message: Dict[str, Any],
account: ChecksumAddress,
password: Optional[str]) -> HexStr:
return self._sign_typed_data(message, account, password)
passphrase: str) -> HexStr:
return self._sign_typed_data(message, account, passphrase)

def unlock_account(self,
account: ChecksumAddress,
Expand Down Expand Up @@ -156,14 +156,14 @@ async def send_transaction(self, transaction: TxParams, passphrase: str) -> Awai
async def sign(self,
message: str,
account: ChecksumAddress,
password: Optional[str]) -> Awaitable[HexStr]:
return await self._sign(message, account, password) # type: ignore
passphrase: str) -> Awaitable[HexStr]:
return await self._sign(message, account, passphrase) # type: ignore

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

async def unlock_account(self,
account: ChecksumAddress,
Expand Down