-
Notifications
You must be signed in to change notification settings - Fork 5
feat: documentation for PSS #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
649e484
feat: documentation for PSS
vojtechsimetka 989ea87
Merge branch 'master' into feat/pss
vojtechsimetka 21a7480
chore: grammar suggestion by @significance
vojtechsimetka 31f2fea
chore: apply language suggestions from code review but @agazso
vojtechsimetka f600a2d
chore: added warning about privacy for unencrypted PSS communication
vojtechsimetka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,184 @@ | ||
| --- | ||
| title: Postal Service over Swarm | ||
| hide_title: true | ||
| id: pss | ||
| slug: /pss | ||
| sidebar_label: Postal Service over Swarm | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs' | ||
| import TabItem from '@theme/TabItem' | ||
|
|
||
| Swarm provides the ability to send messages that appear to be normal Swarm traffic, but are in fact messages that may be received and decrypted to reveal their content only to specific nodes that were intended to receive them. | ||
|
|
||
| PSS provides a pub-sub facility that can be used for a variety of tasks. Nodes are able to listen to messages received for a specific topic in their nearest neighbourhood and create messages destined for another neighbourhood which are sent over the network using Swarm's usual data dissemination protocols. | ||
|
|
||
| The intended use of PSS is to communicate privately with a publicly known identity (to for example initiate further communication directly). Due to the cost of mining the trojan chunks, it is not recommended to use as an instant messaging system. | ||
|
|
||
| ## Getting the relevant data | ||
| When you start `bee`, you may find all the necessary information in the log: | ||
| ```sh | ||
| INFO using existing swarm network address: 9e2ebf266369090091620db013aab164afb1574aedb3fcc08ce8dc6e6f28ef54 | ||
| INFO swarm public key 03e0cee7e979fa99350fc2e2f8c81d857b525b710380f238742af269bb794dfd3c | ||
| INFO pss public key 02fa24cac43531176d21678900b37bd800c93da3b02c5e11572fb6a96ec49527fa | ||
| INFO using ethereum address 5f5505033e3b985b88e20616d95201596b463c9a | ||
| ``` | ||
| Let's break it down: | ||
| - **Ethereum address** is the public address of your node wallet. Together with the corresponding private key, it is used for things such as making Ethereum transactions (receiving and sending ETH and BZZ); receiving, claiming and singing cheques and the Swarm network address is also derived from it. | ||
| - The **Swarm network address** defines your location in the kademlia and within the context of PSS is used for addressing the trojan chunks to you. In other words, others may use it to send you a message. | ||
| - **PSS public key** can be used by others to encrypt their messages for you. | ||
|
|
||
| <!--- | ||
| ### Deriving swarm address from ethereum address | ||
| This section will need a lot of love and testing, probably should be in some advanced page but leaving it here as comment since we want to write it at some point. | ||
| --> | ||
|
|
||
| ## Sending message | ||
|
|
||
| To send data simply define a topic, prefix of the recipient's swarm network address (we recommend 4-6 character prefix length) and the data to be send. | ||
| :::caution Your communication privacy may be at risk | ||
| When sending PSS messages without encryption key, any Bee node through which the trojan chunk passes would be able to read the message. | ||
| ::: | ||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| /** | ||
| * @param {string} topic | ||
| * @param {string} targetPrefix | ||
| * @param {string|Uint8Array} data | ||
| * @param {string} encryptionKey | ||
| */ | ||
| bee.pssSend('topic', '9e2e', 'Hello!') | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| /** | ||
| * @param {string} topic | ||
| * @param {string} targetPrefix | ||
| * @param {string|Uint8Array} data | ||
| * @param {string} encryptionKey | ||
| */ | ||
| bee.pssSend('topic', '9e2e', 'Hello!') | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| If you want to encrypt the message, you may provide the recipient's PSS public key. | ||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| bee.pssSend( | ||
| 'topic', | ||
| '9e2e', | ||
| 'Encrypted Hello!', | ||
| '02fa24cac43531176d21678900b37bd800c93da3b02c5e11572fb6a96ec49527fa', | ||
| ) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| bee.pssSend( | ||
| 'topic', | ||
| '9e2e', | ||
| 'Encrypted Hello!', | ||
| '02fa24cac43531176d21678900b37bd800c93da3b02c5e11572fb6a96ec49527fa', | ||
| ) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Retrieving message | ||
| As a recipient, you have two ways how to receive the message. If you are expecting one off message (which is the intended PSS use case to exchange credentials for further direct communication), you can use the `pssReceive` method. | ||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| const message = await bee.pssReceive('topic') | ||
|
|
||
| console.log(new TextDecoder("utf-8").decode(message)) // prints the received message | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| const message = await bee.pssReceive('topic') | ||
|
|
||
| console.log(new TextDecoder("utf-8").decode(message)) // prints the received message | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| If you want to subscribe to multiple messagees, use the `pssSubscribe` method. | ||
|
|
||
|
|
||
| <Tabs | ||
| groupId="lang_preferrence" | ||
| defaultValue="ts" | ||
| values={[ | ||
| {label: 'TypeScript', value: 'ts'}, | ||
| {label: 'JavaScript', value: 'js'}, | ||
| ]}> | ||
| <TabItem value="ts"> | ||
|
|
||
| ```ts | ||
| const handler = { | ||
| onMessage: (message: Uint8Array) => {console.log(new TextDecoder("utf-8").decode(message))}, | ||
| onError: (error: BeeError) => {console.log(error)} | ||
| } | ||
|
|
||
| // Subscribe | ||
| const subscription = bee.pssSubscribe('topic', handler) | ||
|
|
||
| // Terminate the subscription | ||
| subscription.cancel() | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="js"> | ||
|
|
||
| ```js | ||
| const handler = { | ||
| onMessage: (message: Uint8Array) => {console.log(new TextDecoder("utf-8").decode(message))}, | ||
| onError: (error: BeeError) => {console.log(error)} | ||
| } | ||
|
|
||
| // Subscribe | ||
| const subscription = bee.pssSubscribe('topic', handler) | ||
|
|
||
| // Terminate the subscription | ||
| subscription.cancel() | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.