NOTE: Historical document. Doesn't correspond to actual implementation of Push Notifications as of October 26, 2017. Originally wrritten by Victor Spring 2017 (ish). — oskarth

Overview

It is crucial to understand what is Whisper Notification Service is designed for:

High-Level Overview of the process

https://cloud.githubusercontent.com/assets/188194/25035829/b3cf02aa-20f8-11e7-882b-1a4958bcda13.png

The crux here is how to allow DeviceB to trigger notifications on DeviceA, all this w/o knowing much of which wnode is used, or details of DeviceA. And Chat SymKey solves this issue elegantly (the beauty is that it works for both one-on-one and group chats, all you need to ensure is share a secret, namely Chat SymKey, so that newcomers can add their devices to subscribers list).

Important Notes:

Communication Protocol

⭐️ ⭐️ ⭐️ The code below is outdated (it was written for Geth 1.5.9, and with Geth 1.6.0 Whisper API changed drastically). It is still advised to skim over the code and comments, to get better understanding of the idea. And at the end of this document, we include full-fledged test suite (to be run with Mocha).

Suppose, you started service node(s) using statusd --datadir wnode1 wnode --notify --identity ./wnodekey --firebaseauth ./firebaseuathkey, where wnodekey and firebaseauthkey files contain node's private key and FCM authorization key respectively. Now, your server is ready to receive requests encrypted with its PubKey, which for our cluster is 0x040edb0d71a3dbe928e154fcb696ffbda359b153a90efc2b46f0043ce9f5dbe55b77b9328fd841a1db5273758624afadd5b39638d4c35b36b3a96e1a586c1b4c2a.

On client side, we need to use protocol PubKey and pre-defined topic:

var protocolKey = '0x040edb0d71a3dbe928e154fcb696ffbda359b153a90efc2b46f0043ce9f5dbe55b77b9328fd841a1db5273758624afadd5b39638d4c35b36b3a96e1a586c1b4c2a';
var sendDiscoveryRequest = function (identity) {
    // notification server discovery request is a signed (sent from us),
    // encrypted with Notification Protocol Asymmetric (Public) Key
    var err = web3.shh.post({
        from: identity,
        to: protocolKey,
        topics: [discoverServerTopic],
        ttl: 20
    });
    if (err !== null) {
        console.log("message NOT sent")
    } else {
        console.log("message sent OK")
    }
};