Skip to content

Commit fad9241

Browse files
committed
Update whisper docs for geth / parity
1 parent 6c54808 commit fad9241

File tree

9 files changed

+503
-328
lines changed

9 files changed

+503
-328
lines changed

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Contents
2828
web3.eth
2929
web3.eth.account
3030
web3.pm
31-
web3.shh
3231
web3.net
3332
web3.miner
3433
web3.geth

docs/web3.geth.rst

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,273 @@ The following methods are available on the ``web3.geth.txpool`` namespace.
447447
}
448448
}
449449
}
450+
451+
GethShh
452+
~~~~~~~
453+
454+
The ``web3.geth.shh`` object exposes methods to interact with the RPC APIs under the
455+
``shh_`` namespace.
456+
457+
Full documentation for Geth-supported endpoints can be found `here <https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API>`_.
458+
459+
.. warning:: The Whisper protocol is in flux, with incompatible versions supported
460+
by different major clients.
461+
462+
.. py:method:: Shh.version()
463+
464+
Returns the Whisper version this node offers.
465+
466+
.. code-block:: python
467+
468+
>>>web3.geth.shh.version()
469+
6.0
470+
471+
.. py:method:: Shh.info()
472+
473+
Returns the Whisper statistics for diagnostics.
474+
475+
.. code-block:: python
476+
477+
>>>web3.geth.shh.info()
478+
{'maxMessageSize': 1024, 'memory': 240, 'messages': 0, 'minPow': 0.2}
479+
480+
.. py:method:: Shh.post(self, message)
481+
482+
* Creates a whisper message and injects it into the network for distribution.
483+
484+
* Parameters:
485+
* ``symKeyID``: When using symmetric key encryption, holds the symmetric key ID.
486+
* ``pubKey``: When using asymmetric key encryption, holds the public key.
487+
* ``ttl``: Time-to-live in seconds.
488+
* ``sig (optional)``: ID of the signing key.
489+
* ``topic``: Message topic (four bytes of arbitrary data).
490+
* ``payload``: Payload to be encrypted.
491+
* ``padding (optional)``: Padding (byte array of arbitrary length).
492+
* ``powTime``: Maximal time in seconds to be spent on prrof of work.
493+
* ``powTarget``: Minimal PoW target required for this message.
494+
* ``targetPeer (optional)``: Peer ID (for peer-to-peer message only).
495+
496+
* Returns ``True`` if the message was succesfully sent, otherwise ``False``
497+
498+
.. code-block:: python
499+
500+
>>>web3.geth.shh.post({'payload': web3.toHex(text="test_payload"), 'pubKey': recipient_public, 'topic': '0x12340000', 'powTarget': 2.5, 'powTime': 2})
501+
True
502+
503+
.. py:method:: Shh.newMessageFilter(self, criteria)
504+
505+
* Create a new filter id. This filter id can be used with ``ShhFilter`` to poll for new messages that match the set of criteria.
506+
507+
* Parameters:
508+
* ``symKeyID``: When using symmetric key encryption, holds the symmetric key ID.
509+
* ``privateKeyID``: When using asymmetric key encryption, holds the private key ID.
510+
* ``sig``: Public key of the signature.
511+
* ``minPoW``: Minimal PoW requirement for incoming messages.
512+
* ``topics``: Array of possible topics (or partial topics).
513+
* ``allowP2P``: Indicates if this filter allows processing of direct peer-to-peer messages.
514+
515+
516+
.. code-block:: python
517+
518+
>>>web3.geth.shh.newMessageFilter({'topic': '0x12340000', 'privateKeyID': recipient_private})
519+
'b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554'
520+
521+
.. py:method:: Shh.deleteMessageFilter(self, filter_id)
522+
523+
* Deletes a message filter in the node.
524+
525+
* Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False``
526+
527+
.. code-block:: python
528+
529+
>>>web3.geth.shh.deleteMessageFilter('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554')
530+
True
531+
532+
.. py:method:: Shh.getMessages(self, filter_id)
533+
534+
* Retrieve messages that match the filter criteria and are received between the last time this function was called and now.
535+
536+
* Returns all new messages since the last invocation
537+
538+
.. code-block:: python
539+
540+
>>>web3.geth.shh.getMessages('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554')
541+
[{
542+
'ttl': 50,
543+
'timestamp': 1524497850,
544+
'topic': HexBytes('0x13370000'),
545+
'payload': HexBytes('0x74657374206d657373616765203a29'),
546+
'padding': HexBytes('0x50ab643f1b23bc6df1b1532bb6704ad947c2453366754aade3e3597553eeb96119f4f4299834d9989dc4ecc67e6b6470317bb3f7396ace0417fc0d6d2023900d3'),
547+
'pow': 6.73892030848329,
548+
'hash': HexBytes('0x7418f8f0989655ed2f4f9b496e6b1d9be51ef9f0f5ad89f6f750b0eee268b02f'),
549+
'recipientPublicKey': HexBytes('0x047d36c9e45fa82fcd27d35bc7d2fd41a2e41e512feec9e4b90ee4293ab12dc2cfc98250a6f5689b07650f8a5ca3a6e0fa8808cd0ce1a1962f2551354487a8fc79')
550+
}]
551+
552+
.. py:method:: Shh.setMaxMessageSize(self, size)
553+
554+
* 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).
555+
556+
* Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False``
557+
558+
.. code-block:: python
559+
560+
>>>web3.geth.shh.setMaxMessageSize(1024)
561+
True
562+
563+
.. py:method:: Shh.setMinPoW(self, min_pow)
564+
565+
* Sets the minimal PoW required by this node.
566+
567+
* Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False``
568+
569+
.. code-block:: python
570+
571+
>>>web3.geth.shh.setMinPoW(0.4)
572+
True
573+
574+
.. py:method:: Shh.markTrustedPeer(self, enode)
575+
576+
* Marks specific peer trusted, which will allow it to send historic (expired) messages.
577+
578+
* Returns ``True`` if the filter was sucesfully uninstalled, otherwise ``False``
579+
580+
.. code-block:: python
581+
582+
>>>web3.geth.shh.markTrustedPeer('enode://d25474361659861e9e651bc728a17e807a3359ca0d344afd544ed0f11a31faecaf4d74b55db53c6670fd624f08d5c79adfc8da5dd4a11b9213db49a3b750845e@52.178.209.125:30379')
583+
True
584+
585+
---------------
586+
Asymmetric Keys
587+
---------------
588+
589+
.. py:method:: Shh.newKeyPair(self)
590+
591+
* Generates a new cryptographic identity for the client, and injects it into the known identities for message decryption
592+
593+
* Returns the new key pair's identity
594+
595+
.. code-block:: python
596+
597+
>>>web3.geth.shh.newKeyPair()
598+
'86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb'
599+
600+
.. py:method:: Shh.addPrivateKey(self, key)
601+
602+
* Stores a key pair derived from a private key, and returns its ID.
603+
604+
* Returns the added key pair's ID
605+
606+
.. code-block:: python
607+
608+
>>>web3.geth.shh.addPrivateKey('0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0')
609+
'86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb'
610+
611+
.. py:method:: Shh.deleteKeyPair(self, id)
612+
613+
* Deletes the specifies key if it exists.
614+
615+
* Returns ``True`` if the key pair was deleted, otherwise ``False``
616+
617+
.. code-block:: python
618+
619+
>>>web3.geth.shh.deleteKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb')
620+
True
621+
622+
.. py:method:: Shh.hasKeyPair(self, id)
623+
624+
* Checks if the whisper node has a private key of a key pair matching the given ID.
625+
626+
* Returns ``True`` if the key pair exists, otherwise ``False``
627+
628+
.. code-block:: python
629+
630+
>>>web3.geth.shh.hasKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb')
631+
False
632+
633+
.. py:method:: Shh.getPublicKey(self, id)
634+
635+
* Returns the public key associated with the key pair.
636+
637+
.. code-block:: python
638+
639+
>>>web3.geth.shh.getPublicKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb')
640+
'0x041b0777ceb8cf8748fe0bba5e55039d650a03eb0239a909f9ee345bbbad249f2aa236a4b8f41f51bd0a97d87c08e69e67c51f154d634ba51a224195212fc31e4e'
641+
642+
.. py:method:: Shh.getPrivateKey(self, id)
643+
644+
* Returns the private key associated with the key pair.
645+
646+
.. code-block:: python
647+
648+
>>>web3.geth.shh.getPrivateKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb')
649+
'0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0'
650+
651+
---------------
652+
Symmetric Keys
653+
---------------
654+
655+
.. py:method:: Shh.newSymKey(self)
656+
657+
* Generates a random symmetric key and stores it under id, which is then returned. Will be used in the future for session key exchange
658+
659+
* Returns the new key pair's identity
660+
661+
.. code-block:: python
662+
663+
>>>web3.geth.shh.newSymKey()
664+
'6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c'
665+
666+
.. py:method:: Shh.addSymKey(self, key)
667+
668+
* Stores the key, and returns its ID.
669+
670+
* Returns the new key pair's identity
671+
672+
.. code-block:: python
673+
674+
>>>web3.geth.shh.addSymKey('0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2')
675+
'6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c'
676+
677+
.. py:method:: Shh.generateSymKeyFromPassword(self)
678+
679+
* Generates the key from password, stores it, and returns its ID.
680+
681+
* Returns the new key pair's identity
682+
683+
.. code-block:: python
684+
685+
>>>web3.geth.shh.generateSymKeyFromPassword('shh secret pwd')
686+
'6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c'
687+
688+
.. py:method:: Shh.hasSymKey(self, id)
689+
690+
* Checks if there is a symmetric key stored with the given ID.
691+
692+
* Returns ``True`` if the key exists, otherwise ``False``
693+
694+
.. code-block:: python
695+
696+
>>>web3.geth.shh.hasSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c')
697+
False
698+
699+
.. py:method:: Shh.getSymKey(self, id)
700+
701+
* Returns the symmetric key associated with the given ID.
702+
703+
* Returns the public key associated with the key pair
704+
705+
.. code-block:: python
706+
707+
>>>web3.geth.shh.getSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c')
708+
'0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2'
709+
710+
.. py:method:: Shh.deleteSymKey(self, id)
711+
712+
* Deletes the symmetric key associated with the given ID.
713+
714+
* Returns ``True`` if the key pair was deleted, otherwise ``False``
715+
716+
.. code-block:: python
717+
718+
>>>web3.geth.shh.deleteSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c')
719+
True

docs/web3.main.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ Each ``web3`` instance also exposes these namespaced APIs.
8080
8181
See :doc:`./web3.eth`
8282

83-
.. py:attribute:: Web3.shh
84-
85-
See :doc:`./web3.shh`
86-
8783
.. py:attribute:: Web3.miner
8884
8985
See :doc:`./web3.miner`

0 commit comments

Comments
 (0)