Skip to content

Commit cfd206e

Browse files
committed
clarify private key generation and usage for signing and publishing
1 parent 74da60a commit cfd206e

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

docs/documentation/soc-and-feeds.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,39 @@ Feeds are a unique feature of Swarm which simulate the publishing of mutable con
1616

1717
## Requirements
1818

19-
Interactions with SOC and feeds requires the following:
19+
Interactions with SOC and feeds require the following:
2020

21-
* A fully initialized Bee light node running with fully synced postage batch data. (Running at `http://localhost:1633` by default)
21+
* A fully initialized Bee light node running with fully synced postage batch data (running at `http://localhost:1633` by default).
2222
* A valid postage batch ID.
23-
* An Ethereum-compatible private key to sign updates. Using your node or blockchain account wallet's private key is strongly discouraged. Using a dedicated key for SOC / feeds is recommended.
23+
* A dedicated Ethereum-compatible publisher private key to sign updates. Do **not** use the private key of your Bee node or any wallet that holds funds.
24+
25+
:::tip
26+
You can use the `PrivateKey` class to generate a dedicated publisher key for signing SOC and feed updates:
27+
28+
```js
29+
const crypto = require('crypto');
30+
const { PrivateKey } = require('@ethersphere/bee-js');
31+
32+
// Generate 32 random bytes and construct a private key
33+
const hexKey = '0x' + crypto.randomBytes(32).toString('hex');
34+
const privateKey = new PrivateKey(hexKey);
35+
36+
console.log('Private key:', privateKey.toHex());
37+
console.log('Public address:', privateKey.publicKey().address().toHex());
38+
````
39+
40+
Example output:
41+
42+
```bash
43+
Private key: 634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd
44+
Public address: 8d3766440f0d7b949a5e32995d09619a7f86e632
45+
```
46+
47+
Store this key securely.
48+
Anyone with access to it can publish to your feed or SOC.
49+
50+
*It is recommended to use a separate publishing key for each feed or SOC. This limits the damage if a key is ever exposed — a compromised key should only allow publishing to one resource, not all of them.*
51+
:::
2452

2553
## Single Owner Chunks
2654

@@ -107,7 +135,7 @@ Reference (Hex): 9d453ebb73b2fedaaf44ceddcf7a0aa37f3e3d6453fea5841c31f0ea6d61dc8
107135

108136

109137
In this example:
110-
- `privateKey` is used to initialize the writer as `socWriter` which is used to sign the SOC.
138+
- `privateKey` (initialized using our [previously generated](#requirements) publisher key) is used to initialize the writer as `socWriter` which is used to sign the SOC.
111139
- `NULL_IDENTIFIER` is the 32-byte value used as the identifier (can be replaced with any user-defined value).
112140
- `socWriter.upload()` signs and uploads the data, returning a `reference` as confirmation.
113141

@@ -155,7 +183,7 @@ readSOC()
155183
```
156184

157185
In this example:
158-
- The `owner` is the Ethereum address used to sign the SOC.
186+
- The `owner` is the Ethereum address used to retrieve the SOC (derived from the private key [previously generated](#requirements)).
159187
- `NULL_IDENTIFIER` is the same default identifier used in the earlier upload example.
160188
- The returned payload is a `Bytes` object, and `.toUtf8()` converts it to a human-readable string.
161189

@@ -171,7 +199,7 @@ Feeds are an abstraction built on top of Single Owner Chunks (SOCs) that **simul
171199

172200
Similar to how an SOC is defined by an `owner` and `identifier`, a feed is defined by:
173201

174-
* `owner`: an Ethereum-compatible address
202+
* `owner`: an Ethereum-compatible address
175203
* `topic`: a unique 32-byte identifier
176204

177205
### Concepts
@@ -199,7 +227,7 @@ Although it is possible to update feeds with an arbitrary data payload using `up
199227

200228
The script below performs the following steps:
201229

202-
1. Initializes the Bee client and derives the feed owner address from a private key.
230+
1. Initializes the Bee client and derives the feed owner address from a private key (which we have [previously generated](#requirements)).
203231
2. Uses the `uploadPayload()` method to upload a plain text string as a **payload update** to the feed with topic `"payload-update"`.
204232
3. Uploads the same string as a file to Swarm and obtains a reference.
205233
4. Uses the `upload()` method to upload the obtained reference as a **reference update** to the feed with topic `"reference-update"`.

0 commit comments

Comments
 (0)