4

From Whisper wiki:

Low-latency, 1-1 or 1-N signalling messages.

Shh.post(self, message:) and Whisper Usage / shh.post

Creates a whisper message and injects it into the network for distribution.

Example usage of web3.shh.post, for more details please see this answer:

web3.shh.post({
  pubKey: 'PUBLIC_KEY_OF_THE_RECEIVER',
  ttl: 3600,
  topic: '0x07678231',
  powTarget: 2.01,
  powTime: 2,
  payload: web3.fromAscii("Hello there!")
  });

When I remove pubKey from web3.shh.post as arguments; it says: Error: specify either a symmetric or an asymmetric key.

shh.post({ "topic": t, "payload": p }); No signature, no encryption: Anonymous broadcast; a bit like an anonymous subject-filtered twitter feed.

[Q] Since web3.shh.post()requires us to provide single public key of the receiver; is it possible to send 1-N or broadcast message using whisper protocol? If yes, how?

alper
  • 8,395
  • 11
  • 63
  • 152

2 Answers2

3

I would recommended to use this documentation : https://github.com/ethereum/go-ethereum/wiki/Whisper

Whisper usage

your posted links are outdated and moreover are for Whisper v 2.0

Answer: It's possible 1:N message if you provide identical symKey for all recipients.

P.S. My posted links are for Whisper 5.0 , current version of Whisper is 6.0 but but the API for v6 is almost identical to v5 anyway.


On node-1's geth-client:

generatedSymKey=shh.generateSymKeyFromPassword("hello");    
symKey=shh.getSymKey(generatedSymKey)    
symKeyID=shh.addSymKey(symKey) //ex: "d5212e736703afbb21246e8acd192e4345ea910398544d765ed6b49f0ec524b5"
filter = web3.shh.newMessageFilter(
        {symKeyID:symKeyID, topic: '0x07678231'}, 
        function(err, res) {console.log(web3.toUtf8(res.payload))});

On node-2's geth-client:

generatedSymKey=shh.generateSymKeyFromPassword("hello")    
symKey=shh.getSymKey(generatedSymKey)    
symKeyID=shh.addSymKey(symKey) //ex: "c4c4cecf6ad9499c2386b8ce6416f44684e042e491726b38315646c0b4afadc6"
filter = web3.shh.newMessageFilter(
        {symKeyID:symKeyID, topic: '0x07678231'}, 
        function(err, res) {console.log(web3.toUtf8(res.payload))});

Than, sending message on another node and both messages show up on node-1 and node-2 even if symKeyID is either node-1's or node-2's on shh.post() function.

Following code is run on node-1's geth-client:

node-1's symKeyID is given:

web3.shh.post({
  symKeyID: 'd5212e736703afbb21246e8acd192e4345ea910398544d765ed6b49f0ec524b5', //symKeyID of the node-1
  ttl: 10,
  topic: '0x07678231',
  powTarget: 2.01,
  powTime: 2,
  payload: web3.fromAscii("Hello there!")
  });

OR


Following code is run on node-2's geth-client:

node-2's symKeyID is given:

web3.shh.post({
  symKeyID: 'c4c4cecf6ad9499c2386b8ce6416f44684e042e491726b38315646c0b4afadc6', //symKeyID of the node-2
  ttl: 10,
  topic: '0x07678231',
  powTarget: 2.01,
  powTime: 2,
  payload: web3.fromAscii("Hello there!")
  });
alper
  • 8,395
  • 11
  • 63
  • 152
Archi
  • 379
  • 1
  • 6
  • Thanks for the updated links. But how could recipients have identical symKey or publicKey since they are unique for each recipient? @Baracuda – alper Jul 08 '18 at 17:29
  • I have just pushed working ssh demo: https://github.com/achiko/whisper-v6-test I used shh.generateSymKeyFromPassword('....' ) method with one password. – Archi Jul 08 '18 at 17:37
  • 1
    I am pretty sure each receipt should have a unique symKey. What do you get symKey with following: shh.generateSymKeyFromPassword("hello") which I get : a0ce4c9103be09614d59103ca5aeee0bda8e59e9f6112f6c0b40f439ab0b4ab9 for receipt-1 and for another receipt I get different one. 4a6c15f288bfa9949702aa9a5e5bd305b6f48681513a266e8a3c42e58433f859 . – alper Jul 08 '18 at 17:43
  • generateSymKeyFromPassword Generates the key from password, stores it, and returns its id.
    https://github.com/ethereum/go-ethereum/wiki/Whisper-Usage#generatesymkeyfrompassword Its just ID stored locally.
    – Archi Jul 09 '18 at 09:55
  • This is not my solution omg ... this method generateSymKeyFromPassword is from official documentation and I would like to say that the official API is wrong ? or Go ethereum client works wrongly ? – Archi Jul 09 '18 at 11:16
  • This is not possible: "if you provide identical symKey for all recipients". Each recipient has a unique symKey since each has different private key. – alper Jul 09 '18 at 11:17
  • Please run this code and test : do not downvote before it please .... https://gist.github.com/achiko/b4b58bb1bde29ab40a3782a0d9bc5c01 – Archi Jul 09 '18 at 11:24
  • SymkeyID its just only id returned when you generating symKey. you can get get symKey by using symkeyID ... so symkeyId is different for different nodes but symKey is identical for one password string. – Archi Jul 09 '18 at 12:03
  • you can run code code in different nodes and you will get identical symKey. – Archi Jul 09 '18 at 12:04
  • I have just tested in 2 different nodes, which comment ? – Archi Jul 09 '18 at 12:06
  • if you run shh.generateSymKeyFromPassword("hello") it will return different symKeyId on every run.
  • but if you run shh.getSymKey() you will always get identical symkey for identical password on every node.
  • – Archi Jul 09 '18 at 12:10
  • 1
    I got your point, I added your answer with a tutorial code. @Baracuda – alper Jul 09 '18 at 12:51