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
It is crucial to understand what is Whisper Notification Service is designed for:
SubscriptionKey
), which is used to control subscription (say, querying for server id or generating chat keys).SubscriptionKey
, new chat sessions can be initiated (yielding yet another SymKey - ChatKey
). By sharing that key with others, you will have a common secret that can be used to trigger notifications.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:
Device A
starts the protocol by sending encrypted message using Discovery Protocol PubKey (Status test cluster will have a single PubKey installed on all the nodes, allowing any of them to respond on discovery requests).Subscription SymKey
and Chat SymKey
you rely on symmetric encryption.DeviceA
you send encrypted message to DeviceB
(so, only DeviceB
can open envelope)Chat SymKey
Chat SymKey
)n-1
requests for group of n
chats - that's we do not notify ourselves)wnode
⭐️ ⭐️ ⭐️ 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")
}
};