From a489f61462026048c489c3b2f3b3340d383f3d16 Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Thu, 4 Apr 2019 13:46:04 +0200 Subject: [PATCH] Update whisper docs for geth / parity --- docs/index.rst | 1 - docs/web3.geth.rst | 270 +++++++++++++++++++++ docs/web3.main.rst | 4 - docs/web3.parity.rst | 208 ++++++++++++++++ docs/web3.shh.rst | 290 ----------------------- tests/integration/parity/common.py | 2 + web3/_utils/filters.py | 5 +- web3/_utils/module_testing/shh_module.py | 1 + web3/parity.py | 50 ++-- 9 files changed, 503 insertions(+), 328 deletions(-) delete mode 100644 docs/web3.shh.rst diff --git a/docs/index.rst b/docs/index.rst index 0f9007fde3..d9ae9f2972 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -28,7 +28,6 @@ Contents web3.eth web3.eth.account web3.pm - web3.shh web3.net web3.miner web3.geth diff --git a/docs/web3.geth.rst b/docs/web3.geth.rst index 445f3ea4c7..181a66c718 100644 --- a/docs/web3.geth.rst +++ b/docs/web3.geth.rst @@ -447,3 +447,273 @@ The following methods are available on the ``web3.geth.txpool`` namespace. } } } + +GethShh +~~~~~~~ + +The ``web3.geth.shh`` object exposes methods to interact with the RPC APIs under the +``shh_`` namespace. + +Full documentation for Geth-supported endpoints can be found `here `_. + +.. warning:: The Whisper protocol is in flux, with incompatible versions supported + by different major clients. + +.. py:method:: Shh.version() + + Returns the Whisper version this node offers. + + .. code-block:: python + + >>>web3.geth.shh.version() + 6.0 + +.. py:method:: Shh.info() + + Returns the Whisper statistics for diagnostics. + + .. code-block:: python + + >>>web3.geth.shh.info() + {'maxMessageSize': 1024, 'memory': 240, 'messages': 0, 'minPow': 0.2} + +.. py:method:: Shh.post(self, message) + + * Creates a whisper message and injects it into the network for distribution. + + * Parameters: + * ``symKeyID``: When using symmetric key encryption, holds the symmetric key ID. + * ``pubKey``: When using asymmetric key encryption, holds the public key. + * ``ttl``: Time-to-live in seconds. + * ``sig (optional)``: ID of the signing key. + * ``topic``: Message topic (four bytes of arbitrary data). + * ``payload``: Payload to be encrypted. + * ``padding (optional)``: Padding (byte array of arbitrary length). + * ``powTime``: Maximal time in seconds to be spent on prrof of work. + * ``powTarget``: Minimal PoW target required for this message. + * ``targetPeer (optional)``: Peer ID (for peer-to-peer message only). + + * Returns ``True`` if the message was succesfully sent, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.post({'payload': web3.toHex(text="test_payload"), 'pubKey': recipient_public, 'topic': '0x12340000', 'powTarget': 2.5, 'powTime': 2}) + True + +.. py:method:: Shh.newMessageFilter(self, criteria) + + * Create a new filter id. This filter id can be used with ``ShhFilter`` to poll for new messages that match the set of criteria. + + * Parameters: + * ``symKeyID``: When using symmetric key encryption, holds the symmetric key ID. + * ``privateKeyID``: When using asymmetric key encryption, holds the private key ID. + * ``sig``: Public key of the signature. + * ``minPoW``: Minimal PoW requirement for incoming messages. + * ``topics``: Array of possible topics (or partial topics). + * ``allowP2P``: Indicates if this filter allows processing of direct peer-to-peer messages. + + + .. code-block:: python + + >>>web3.geth.shh.newMessageFilter({'topic': '0x12340000', 'privateKeyID': recipient_private}) + 'b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554' + +.. py:method:: Shh.deleteMessageFilter(self, filter_id) + + * Deletes a message filter in the node. + + * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.deleteMessageFilter('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') + True + +.. py:method:: Shh.getMessages(self, filter_id) + + * Retrieve messages that match the filter criteria and are received between the last time this function was called and now. + + * Returns all new messages since the last invocation + + .. code-block:: python + + >>>web3.geth.shh.getMessages('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') + [{ + 'ttl': 50, + 'timestamp': 1524497850, + 'topic': HexBytes('0x13370000'), + 'payload': HexBytes('0x74657374206d657373616765203a29'), + 'padding': HexBytes('0x50ab643f1b23bc6df1b1532bb6704ad947c2453366754aade3e3597553eeb96119f4f4299834d9989dc4ecc67e6b6470317bb3f7396ace0417fc0d6d2023900d3'), + 'pow': 6.73892030848329, + 'hash': HexBytes('0x7418f8f0989655ed2f4f9b496e6b1d9be51ef9f0f5ad89f6f750b0eee268b02f'), + 'recipientPublicKey': HexBytes('0x047d36c9e45fa82fcd27d35bc7d2fd41a2e41e512feec9e4b90ee4293ab12dc2cfc98250a6f5689b07650f8a5ca3a6e0fa8808cd0ce1a1962f2551354487a8fc79') + }] + +.. py:method:: Shh.setMaxMessageSize(self, size) + + * Sets the maximal message size allowed by this node. Incoming and outgoing messages with a larger size will be rejected. Whisper message size can never exceed the limit imposed by the underlying P2P protocol (10 Mb). + + * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.setMaxMessageSize(1024) + True + +.. py:method:: Shh.setMinPoW(self, min_pow) + + * Sets the minimal PoW required by this node. + + * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.setMinPoW(0.4) + True + +.. py:method:: Shh.markTrustedPeer(self, enode) + + * Marks specific peer trusted, which will allow it to send historic (expired) messages. + + * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.markTrustedPeer('enode://d25474361659861e9e651bc728a17e807a3359ca0d344afd544ed0f11a31faecaf4d74b55db53c6670fd624f08d5c79adfc8da5dd4a11b9213db49a3b750845e@52.178.209.125:30379') + True + +--------------- +Asymmetric Keys +--------------- + +.. py:method:: Shh.newKeyPair(self) + + * Generates a new cryptographic identity for the client, and injects it into the known identities for message decryption + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.geth.shh.newKeyPair() + '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' + +.. py:method:: Shh.addPrivateKey(self, key) + + * Stores a key pair derived from a private key, and returns its ID. + + * Returns the added key pair's ID + + .. code-block:: python + + >>>web3.geth.shh.addPrivateKey('0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0') + '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' + +.. py:method:: Shh.deleteKeyPair(self, id) + + * Deletes the specified key if it exists. + + * Returns ``True`` if the key pair was deleted, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.deleteKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + True + +.. py:method:: Shh.hasKeyPair(self, id) + + * Checks if the whisper node has a private key of a key pair matching the given ID. + + * Returns ``True`` if the key pair exists, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.hasKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + False + +.. py:method:: Shh.getPublicKey(self, id) + + * Returns the public key associated with the key pair. + + .. code-block:: python + + >>>web3.geth.shh.getPublicKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + '0x041b0777ceb8cf8748fe0bba5e55039d650a03eb0239a909f9ee345bbbad249f2aa236a4b8f41f51bd0a97d87c08e69e67c51f154d634ba51a224195212fc31e4e' + +.. py:method:: Shh.getPrivateKey(self, id) + + * Returns the private key associated with the key pair. + + .. code-block:: python + + >>>web3.geth.shh.getPrivateKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + '0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0' + +--------------- +Symmetric Keys +--------------- + +.. py:method:: Shh.newSymKey(self) + + * Generates a random symmetric key and stores it under id, which is then returned. Will be used in the future for session key exchange + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.geth.shh.newSymKey() + '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' + +.. py:method:: Shh.addSymKey(self, key) + + * Stores the key, and returns its ID. + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.geth.shh.addSymKey('0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2') + '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' + +.. py:method:: Shh.generateSymKeyFromPassword(self) + + * Generates the key from password, stores it, and returns its ID. + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.geth.shh.generateSymKeyFromPassword('shh secret pwd') + '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' + +.. py:method:: Shh.hasSymKey(self, id) + + * Checks if there is a symmetric key stored with the given ID. + + * Returns ``True`` if the key exists, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.hasSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + False + +.. py:method:: Shh.getSymKey(self, id) + + * Returns the symmetric key associated with the given ID. + + * Returns the public key associated with the key pair + + .. code-block:: python + + >>>web3.geth.shh.getSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + '0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2' + +.. py:method:: Shh.deleteSymKey(self, id) + + * Deletes the symmetric key associated with the given ID. + + * Returns ``True`` if the key pair was deleted, otherwise ``False`` + + .. code-block:: python + + >>>web3.geth.shh.deleteSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + True diff --git a/docs/web3.main.rst b/docs/web3.main.rst index 6ba6e792fc..92c5fd1a30 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -80,10 +80,6 @@ Each ``web3`` instance also exposes these namespaced APIs. See :doc:`./web3.eth` -.. py:attribute:: Web3.shh - - See :doc:`./web3.shh` - .. py:attribute:: Web3.miner See :doc:`./web3.miner` diff --git a/docs/web3.parity.rst b/docs/web3.parity.rst index d11b9b1b0c..46b0f0592b 100644 --- a/docs/web3.parity.rst +++ b/docs/web3.parity.rst @@ -69,3 +69,211 @@ The following methods are available on the ``web3.parity.personal`` namespace. * Delegates to ``personal_sendTransaction`` RPC Method Sends the transaction. + + +ParityShh +--------- + +The ``web3.parity.shh`` object exposes methods to interact with the RPC APIs under the `shh_`` namespace. + +Full documentation for Parity-supported endpoints can be found `here `_. + +.. warning:: The Whisper protocol is in flux, with incompatible versions supported + by different major clients. + + +.. py:method:: Shh.info() + + Returns the Whisper statistics for diagnostics. + + .. code-block:: python + + >>> web3.parity.shh.info() + {'memory': 240, 'messages': 0, 'targetMemory': 102485760} + +.. py:method:: Shh.post(self, message) + + * Creates a whisper message and injects it into the network for distribution. + + * Parameters: + * ``to``: The receiver of the message. Can be omitted for a broadcast message. Use one of the following two fields. + * ``public``: The public key of the recipient. + * ``identity``: The identity of the recipient key on your local node. + * ``from``: Asymmetric identity to sign the message with, or null. + * ``topics``: Array of topics for the message. Should be non-empty. + * ``payload``: Payload to be encrypted. + * ``padding``: Optional padding. Up to 2^24 -1 bytes. + * ``priority``: How many milliseconds to spend doing POW. + * ``ttl``: Time-to-live (in seconds) of the message before expiry. + + * Returns ``True`` if the message was succesfully sent, otherwise ``False`` + + .. code-block:: python + + >>> web3.parity.shh.post({ + "from":"0x193f71c502feb0c181ed0b97352fdcebcb621c733cd80637b2154a2a2b867a12", + "topics":["0x12270000"], + "payload":"0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6", + "priority":40, + "ttl":400 + }) + True + +.. py:method:: Shh.newMessageFilter(self, criteria) + + * Return the filter ID that can be used with ``ShhFilter`` to poll for new messages that match the set of criteria. + + * Parameters: + * ``decryptWith``: 32 bytes - Identity of key used for description. Null if listening for broadcasts. + * ``from``: 64 bytes - If present, only accept messages signed by this key. + * ``topics``: Array of possible topics (or partial topics). Should be non-empty. + + * Returns the newly created filter id. + + .. code-block:: python + + >>>web3.parity.shh.newMessageFilter({'topic': '0x12340000', 'privateKeyID': recipient_private}) + 0xea7120c5408c72cfd7e0e1d2ff62df8e208d9a1f85d2ed54a4a3e1ad6daeb6f9 + +.. py:method:: Shh.deleteMessageFilter(self, filter_id) + + * Deletes a message filter in the node. + + * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` + + .. code-block:: python + + >>>web3.parity.shh.deleteMessageFilter('0xea7120c5408c72cfd7e0e1d2ff62df8e208d9a1f85d2ed54a4a3e1ad6daeb6f9') + True + +.. py:method:: Shh.getMessages(self, filter_id) + + * Retrieve messages that match the filter criteria and are received between the last time this function was called and now. + + * Returns all new messages since the last invocation + + .. code-block:: python + + >>>web3.parity.shh.getMessages('0xea7120c5408c72cfd7e0e1d2ff62df8e208d9a1f85d2ed54a4a3e1ad6daeb6f9') + [{ + 'ttl': 50, + 'timestamp': 1524497850, + 'topics': HexBytes('0x13370000'), + 'payload': HexBytes('0x74657374206d657373616765203a29'), + 'padding': HexBytes('0x50ab643f1b23bc6df1b1532bb6704ad947c2453366754aade3e3597553eeb96119f4f4299834d9989dc4ecc67e6b6470317bb3f7396ace0417fc0d6d2023900d3'), + 'recipient': HexBytes('0x047d36c9e45fa82fcd27d35bc7d2fd41a2e41e512feec9e4b90ee4293ab12dcac'), + }] + +.. py:method:: Shh.subscribe(self, filter_id) + + * Open a subscription to a filter. Subscription calls are only supported on the websocket transport. + + * Returns ``True`` if the filter was sucesfully subscribed to, otherwise ``False`` + + .. code-block:: python + + >>>web3.parity.shh.subscribe('0xea7120c5408c72cfd7e0e1d2ff62df8e208d9a1f85d2ed54a4a3e1ad6daeb6f9') + True + +.. py:method:: Shh.unsubscribe(self, filter_id) + + * Close a subscribed filter. + + * Returns ``True`` if the filter subscription was sucesfully closed, otherwise ``False`` + + .. code-block:: python + + >>>web3.parity.shh.unsubscribe('0xea7120c5408c72cfd7e0e1d2ff62df8e208d9a1f85d2ed54a4a3e1ad6daeb6f9') + True + +--------------- +Asymmetric Keys +--------------- + +.. py:method:: Shh.newKeyPair(self) + + * Generates a new cryptographic identity for the client, and injects it into the known identities for message decryption + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.parity.shh.newKeyPair() + '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' + +.. py:method:: Shh.addPrivateKey(self, key) + + * Stores a key pair derived from a private key, and returns its ID. + + * Returns the added key pair's ID + + .. code-block:: python + + >>>web3.parity.shh.addPrivateKey('0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0') + '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' + +.. py:method:: Shh.getPublicKey(self, id) + + * Returns the public key associated with the key pair. + + .. code-block:: python + + >>>web3.parity.shh.getPublicKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + '0x041b0777ceb8cf8748fe0bba5e55039d650a03eb0239a909f9ee345bbbad249f2aa236a4b8f41f51bd0a97d87c08e69e67c51f154d634ba51a224195212fc31e4e' + +.. py:method:: Shh.getPrivateKey(self, id) + + * Returns the private key associated with the key pair. + + .. code-block:: python + + >>>web3.parity.shh.getPrivateKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + '0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0' + +--------------- +Symmetric Keys +--------------- + +.. py:method:: Shh.newSymKey(self) + + * Generates a random symmetric key and stores it under id, which is then returned. Will be used in the future for session key exchange + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.parity.shh.newSymKey() + '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' + +.. py:method:: Shh.addSymKey(self, key) + + * Stores the key, and returns its ID. + + * Returns the new key pair's identity + + .. code-block:: python + + >>>web3.parity.shh.addSymKey('0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2') + '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' + +.. py:method:: Shh.getSymKey(self, id) + + * Returns the symmetric key associated with the given ID. + + * Returns the public key associated with the key pair + + .. code-block:: python + + >>>web3.parity.shh.getSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + '0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2' + +.. py:method:: Shh.deleteKey(self, id) + + * Deletes the symmetric key associated with the given ID. + + * Returns ``True`` if the key pair was deleted, otherwise ``False`` + + .. code-block:: python + + >>>web3.parity.shh.deleteKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + True diff --git a/docs/web3.shh.rst b/docs/web3.shh.rst deleted file mode 100644 index b956b30bfb..0000000000 --- a/docs/web3.shh.rst +++ /dev/null @@ -1,290 +0,0 @@ -SHH API -======= - -.. py:module:: web3.shh -.. py:class:: Shh - -The ``web3.shh`` object exposes methods to interact with the RPC APIs under the -``shh_`` namespace. - -Web3.py exposes select Whisper methods under the ``web3.geth`` and ``web3.parity`` -namespaces to interact with the Whisper RPC API based on which endpoints are -supported by each respective client. - - -.. warning:: The Whisper protocol is in flux, with incompatible versions supported - by different major clients. - - -Properties ----------- - -The following properties are available on the ``web.shh`` namespace. - -.. py:attribute:: Shh.version - - Returns the Whisper version this node offers. - - .. code-block:: python - - >>>web3.shh.version - 6.0 - -.. py:attribute:: Shh.info - - Returns the Whisper statistics for diagnostics. - - .. code-block:: python - - >>>web3.shh.info - {'maxMessageSize': 1024, 'memory': 240, 'messages': 0, 'minPow': 0.2} - -Methods -------- - -The following methods are available on the ``web3.shh`` namespace. - - -.. py:method:: Shh.post(self, message) - - * Creates a whisper message and injects it into the network for distribution. - - * Parameters: - * ``symKeyID``: When using symmetric key encryption, holds the symmetric key ID. - * ``pubKey``: When using asymmetric key encryption, holds the public key. - * ``ttl``: Time-to-live in seconds. - * ``sig (optional)``: ID of the signing key. - * ``topic``: Message topic (four bytes of arbitrary data). - * ``payload``: Payload to be encrypted. - * ``padding (optional)``: Padding (byte array of arbitrary length). - * ``powTime``: Maximal time in seconds to be spent on prrof of work. - * ``powTarget``: Minimal PoW target required for this message. - * ``targetPeer (optional)``: Peer ID (for peer-to-peer message only). - - * Returns ``True`` if the message was succesfully sent, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.post({'payload': web3.toHex(text="test_payload"), 'pubKey': recipient_public, 'topic': '0x12340000', 'powTarget': 2.5, 'powTime': 2}) - True - -.. py:method:: Shh.newMessageFilter(self, criteria, poll_interval=None) - - * Create a new filter within the node. This filter can be used to poll for new messages that match the set of criteria. - - * If a ``poll_interval`` is specified, the client will asynchronously poll for new messages. - - * Parameters: - * ``symKeyID``: When using symmetric key encryption, holds the symmetric key ID. - * ``privateKeyID``: When using asymmetric key encryption, holds the private key ID. - * ``sig``: Public key of the signature. - * ``minPoW``: Minimal PoW requirement for incoming messages. - * ``topics``: Array of possible topics (or partial topics). - * ``allowP2P``: Indicates if this filter allows processing of direct peer-to-peer messages. - - * Returns ``ShhFilter`` which you can either ``watch(callback)`` or request ``get_new_entries()`` - - .. code-block:: python - - >>>web3.shh.newMessageFilter({'topic': '0x12340000', 'privateKeyID': recipient_private}) - ShhFilter({'filter_id': 'b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554'}) - -.. py:method:: Shh.deleteMessageFilter(self, filter_id) - - * Deletes a message filter in the node. - - * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.deleteMessageFilter('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') - True - -.. py:method:: Shh.getMessages(self, filter_id) - - * Retrieve messages that match the filter criteria and are received between the last time this function was called and now. - - * Returns all new messages since the last invocation - - .. code-block:: python - - >>>web3.shh.getMessages('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') - [{ - 'ttl': 50, - 'timestamp': 1524497850, - 'topic': HexBytes('0x13370000'), - 'payload': HexBytes('0x74657374206d657373616765203a29'), - 'padding': HexBytes('0x50ab643f1b23bc6df1b1532bb6704ad947c2453366754aade3e3597553eeb96119f4f4299834d9989dc4ecc67e6b6470317bb3f7396ace0417fc0d6d2023900d3'), - 'pow': 6.73892030848329, - 'hash': HexBytes('0x7418f8f0989655ed2f4f9b496e6b1d9be51ef9f0f5ad89f6f750b0eee268b02f'), - 'recipientPublicKey': HexBytes('0x047d36c9e45fa82fcd27d35bc7d2fd41a2e41e512feec9e4b90ee4293ab12dc2cfc98250a6f5689b07650f8a5ca3a6e0fa8808cd0ce1a1962f2551354487a8fc79') - }] - -.. py:method:: Shh.setMaxMessageSize(self, size) - - * Sets the maximal message size allowed by this node. Incoming and outgoing messages with a larger size will be rejected. Whisper message size can never exceed the limit imposed by the underlying P2P protocol (10 Mb). - - * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.setMaxMessageSize(1024) - True - -.. py:method:: Shh.setMinPoW(self, min_pow) - - * Sets the minimal PoW required by this node. - - * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.setMinPoW(0.4) - True - -.. py:method:: Shh.markTrustedPeer(self, enode) - - * Marks specific peer trusted, which will allow it to send historic (expired) messages. - - * Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.markTrustedPeer('enode://d25474361659861e9e651bc728a17e807a3359ca0d344afd544ed0f11a31faecaf4d74b55db53c6670fd624f08d5c79adfc8da5dd4a11b9213db49a3b750845e@52.178.209.125:30379') - True - ---------------- -Asymmetric Keys ---------------- - -.. py:method:: Shh.newKeyPair(self) - - * Generates a new cryptographic identity for the client, and injects it into the known identities for message decryption - - * Returns the new key pair's identity - - .. code-block:: python - - >>>web3.shh.newKeyPair() - '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' - -.. py:method:: Shh.addPrivateKey(self, key) - - * Stores a key pair derived from a private key, and returns its ID. - - * Returns the added key pair's ID - - .. code-block:: python - - >>>web3.shh.addPrivateKey('0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0') - '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' - -.. py:method:: Shh.deleteKeyPair(self, id) - - * Deletes the specifies key if it exists. - - * Returns ``True`` if the key pair was deleted, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.deleteKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') - True - -.. py:method:: Shh.hasKeyPair(self, id) - - * Checks if the whisper node has a private key of a key pair matching the given ID. - - * Returns ``True`` if the key pair exists, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.hasKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') - False - -.. py:method:: Shh.getPublicKey(self, id) - - * Returns the public key associated with the key pair. - - .. code-block:: python - - >>>web3.shh.getPublicKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') - '0x041b0777ceb8cf8748fe0bba5e55039d650a03eb0239a909f9ee345bbbad249f2aa236a4b8f41f51bd0a97d87c08e69e67c51f154d634ba51a224195212fc31e4e' - -.. py:method:: Shh.getPrivateKey(self, id) - - * Returns the private key associated with the key pair. - - .. code-block:: python - - >>>web3.shh.getPrivateKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') - '0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0' - ---------------- -Symmetric Keys ---------------- - -.. py:method:: Shh.newSymKey(self) - - * Generates a random symmetric key and stores it under id, which is then returned. Will be used in the future for session key exchange - - * Returns the new key pair's identity - - .. code-block:: python - - >>>web3.shh.newSymKey() - '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' - -.. py:method:: Shh.addSymKey(self, key) - - * Stores the key, and returns its ID. - - * Returns the new key pair's identity - - .. code-block:: python - - >>>web3.shh.addSymKey('0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2') - '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' - -.. py:method:: Shh.generateSymKeyFromPassword(self) - - * Generates the key from password, stores it, and returns its ID. - - * Returns the new key pair's identity - - .. code-block:: python - - >>>web3.shh.generateSymKeyFromPassword('shh secret pwd') - '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' - -.. py:method:: Shh.hasSymKey(self, id) - - * Checks if there is a symmetric key stored with the given ID. - - * Returns ``True`` if the key exists, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.hasSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') - False - -.. py:method:: Shh.getSymKey(self, id) - - * Returns the symmetric key associated with the given ID. - - * Returns the public key associated with the key pair - - .. code-block:: python - - >>>web3.shh.getSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') - '0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2' - -.. py:method:: Shh.deleteSymKey(self, id) - - * Deletes the symmetric key associated with the given ID. - - * Returns ``True`` if the key pair was deleted, otherwise ``False`` - - .. code-block:: python - - >>>web3.shh.deleteSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') - True diff --git a/tests/integration/parity/common.py b/tests/integration/parity/common.py index 7194cdc611..167f2bfb87 100644 --- a/tests/integration/parity/common.py +++ b/tests/integration/parity/common.py @@ -175,9 +175,11 @@ class ParityTraceModuleTest(TraceModuleTest): class CommonParityShhModuleTest(ParityShhModuleTest): def test_shh_sync_filter(self, web3): + # https://github.com/paritytech/parity-ethereum/issues/10565 pytest.xfail("Skip until parity filter bug is resolved") super().test_shh_sync_filter(web3) def test_shh_async_filter(self, web3): + # https://github.com/paritytech/parity-ethereum/issues/10565 pytest.xfail("Skip until parity filter bug is resolved") super().test_shh_async_filter(web3) diff --git a/web3/_utils/filters.py b/web3/_utils/filters.py index afa784d4af..e41dc1cc7f 100644 --- a/web3/_utils/filters.py +++ b/web3/_utils/filters.py @@ -239,7 +239,10 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def get_new_entries(self): - all_messages = self.web3.parity.shh.getFilterMessages(self.filter_id) + all_messages = self.web3.manager.request_blocking( + "shh_getFilterMessages", + [self.filter_id] + ) log_entries = self._filter_valid_entries(all_messages) return self._format_log_entries(log_entries) diff --git a/web3/_utils/module_testing/shh_module.py b/web3/_utils/module_testing/shh_module.py index 9a8ef41448..e38b2dfc00 100644 --- a/web3/_utils/module_testing/shh_module.py +++ b/web3/_utils/module_testing/shh_module.py @@ -330,6 +330,7 @@ def test_shh_remove_filter(self, web3): time.sleep(1) # Commented out until parity filter bug is resolved + # https://github.com/paritytech/parity-ethereum/issues/10565 # message = ShhFilter(web3, shh_filter).get_new_entries() # assert message["payload"] == HexBytes(payload) diff --git a/web3/parity.py b/web3/parity.py index b73a240845..6ff23cd09c 100644 --- a/web3/parity.py +++ b/web3/parity.py @@ -2,6 +2,9 @@ is_checksum_address, ) +from web3._utils import ( + shh, +) from web3._utils.personal import ( ecRecover, importRawKey, @@ -11,23 +14,6 @@ sign, unlockAccount, ) -from web3._utils.shh import ( - addPrivateKey, - addSymKey, - deleteKey, - deleteMessageFilter, - getFilterMessages, - getPrivateKey, - getPublicKey, - getSymKey, - info, - newKeyPair, - newMessageFilter, - newSymKey, - post, - subscribe, - unsubscribe, -) from web3._utils.toolz import ( assoc, ) @@ -41,21 +27,21 @@ class ParityShh(ModuleV2): """ https://wiki.parity.io/JSONRPC-shh-module """ - info = info - newKeyPair = newKeyPair - addPrivateKey = addPrivateKey - newSymKey = newSymKey - addSymKey = addSymKey - getPublicKey = getPublicKey - getPrivateKey = getPrivateKey - getSymKey = getSymKey - post = post - newMessageFilter = newMessageFilter - deleteMessageFilter = deleteMessageFilter - getFilterMessages = getFilterMessages - deleteKey = deleteKey - subscribe = subscribe - unsubscribe = unsubscribe + info = shh.info + newKeyPair = shh.newKeyPair + addPrivateKey = shh.addPrivateKey + newSymKey = shh.newSymKey + addSymKey = shh.addSymKey + getPublicKey = shh.getPublicKey + getPrivateKey = shh.getPrivateKey + getSymKey = shh.getSymKey + post = shh.post + newMessageFilter = shh.newMessageFilter + deleteMessageFilter = shh.deleteMessageFilter + getFilterMessages = shh.getFilterMessages + deleteKey = shh.deleteKey + subscribe = shh.subscribe + unsubscribe = shh.unsubscribe class ParityPersonal(ModuleV2):