Skip to content

Commit e8c0bca

Browse files
author
Ferenc Sárai
committed
feat: upcoming bee-js
1 parent 6830939 commit e8c0bca

File tree

1 file changed

+64
-56
lines changed

1 file changed

+64
-56
lines changed

docs/user-documentation/act.md

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,38 @@ We also need an instance of Bee to interact with the Bee node.
2121

2222
```ts
2323
import { Bee } from "@ethersphere/bee-js"
24+
```
2425

25-
const bee = new Bee('http://localhost:1633')
26+
```ts
27+
const bee = new Bee('http://localhost:1633') // Use BeeDev if running Bee in dev mode locally
2628
```
2729

2830
### Upload with ACT
2931

30-
When uploading, we can specify that we are using ACT in the optional `requestOptions` of the `bee-js` `uploadData` method.
32+
When uploading, we can specify that we are using ACT in the optional `options: RedundantUploadOptions` of the `bee-js` `uploadData` method.
3133

3234
```ts
33-
const beeRequestOptionsUpload = {
34-
act: true,
35-
}
36-
const uploadResultACT = await bee.uploadData(
37-
postageBatchId,
38-
"Bee is awesome with ACT!",
39-
beeRequestOptionsUpload
40-
)
41-
console.log(uploadResultACT)
35+
const optionsUp = {
36+
act: true,
37+
};
38+
const uploadResultACT: UploadResult = await bee.uploadData(
39+
postageBatchId,
40+
"Bee is awesome with ACT!",
41+
optionsUp);
42+
console.log('uploadResultACT:', {
43+
...uploadResultACT,
44+
reference: uploadResultACT.reference.toString(),
45+
historyAddress: uploadResultACT.historyAddress.getOrThrow().toString()
46+
});
4247
```
4348

4449
The return value provides a `reference` and a `historyAddress`. Both will be needed for the download.
4550

4651
```json title="uploadResultACT"
4752
{
48-
"reference": "97132e8e17831dfa220e73ee083bd82819aaeffce0aaf7e1e0abf8135fcfd2fc",
49-
"tagUid": 14,
50-
"historyAddress": "c6cabe3a3b7879ddb182277f3037c02002d4ce33280007cac580ac9256be20ea"
53+
"reference": "85ae50e61155d4a0c9c4563c96074e16c33e5640bacfde1ce488978d602927fa",
54+
"tagUid": 111,
55+
"historyAddress": "97a1f10b344e79cde136353a61877b417af2c8ecea4a20a362b920aedb240dc7"
5156
}
5257
```
5358

@@ -57,30 +62,25 @@ During the upload process, the node performing the upload acts as the __publishe
5762

5863
### Download with ACT
5964

60-
When downloading, we can specify that we are using __ACT__ in the optional `requestOptions` of the `bee-js` `downloadData` method.
65+
When downloading, we can specify that we are using __ACT__ in the optional `options: DownloadOptions` of the `bee-js` `downloadData` method.
6166

6267
:::warning
6368
Downloading is only possible with the knowledge of the __publisher's__ public key.
6469
:::
6570

6671
```ts
67-
const addr = await bee.getNodeAddresses()
72+
const addr = await bee.getNodeAddresses();
6873

6974
// node public key (publisher public key)
70-
const pubk = addr.publicKey
71-
72-
const beeRequestOptionsDownload = {
73-
baseURL: BEE_API_URL,
74-
timeout: 0, // false converted to number
75-
headers: {
76-
'swarm-act': 'true',
77-
'swarm-act-publisher': pubk, // publisher public key
78-
'swarm-act-history-address': uploadResultACT.historyAddress,
79-
},
80-
}
81-
82-
const retrievedData = await bee.downloadData(uploadResultACT.reference, beeRequestOptionsDownload)
83-
console.log(await retrievedData.text()) // prints 'Bee is awesome with ACT!'
75+
const pubk = addr.publicKey;
76+
const optionsDown: DownloadOptions = {
77+
actPublisher: pubk,
78+
actHistoryAddress: uploadResultACT.historyAddress.getOrThrow(),
79+
actTimestamp: 1
80+
};
81+
82+
const retrievedData: Bytes = await bee.downloadData(uploadResultACT.reference, optionsDown);
83+
console.log('retrievedData:', retrievedData.toUtf8()); // prints 'Bee is awesome with ACT!'
8484
```
8585

8686
### Create Grantees
@@ -89,38 +89,45 @@ To download from another node, we need to create a grantee list for the uploaded
8989

9090
```ts
9191
const granteePublicKeys = [
92-
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e8",
93-
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e9",
94-
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12ee"
95-
]
92+
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e8",
93+
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e9",
94+
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12ee"
95+
];
9696

9797
// Create Grantees
98-
const granteeResult = await bee.createGrantees(postageBatchId, granteePublicKeys)
99-
console.log(granteeResult)
98+
const granteesResult: GranteesResult = await bee.createGrantees(postageBatchId, granteePublicKeys);
99+
console.log('granteesResult:', {
100+
...granteesResult,
101+
ref: granteesResult.ref.toString(),
102+
historyref: granteesResult.historyref.toString(),
103+
})
100104
```
101105

102106
```json title="granteeResult"
103107
{
104108
"status": 201,
105109
"statusText": "Created",
106-
"ref": "810b802516f3f0d1ded180d19fdf27bbc05b95a5b7ec8448b5a2d90819e06bed8fdf0697efad7074e66f52679a3aa51010d1897f4ce00918f8fd938b0ff35c3a",
107-
"historyref": "4feb7fc56dcea1acaa74c1fb980156d6db9667b223809c082d69542545c67faf"
110+
"ref": "30f7ba4fec333227dac0053114f68e70ee64290e095d99470a074fa687f0ad0774370a1e597447fbec7f916c4a2f70d0719150dce3573b290b3fcfe7883ed79d",
111+
"historyref": "81cd33bf01b771ed899cb41f4d5e91b49dc28a42ee28144f8ba1ba59ecc66f09"
108112
}
109113
```
110114

111115
### List Grantees
112116

113117
```ts
114118
// List Grantees
115-
const getGranteesResult = await bee.getGrantees(granteeResult.ref)
116-
console.log(getGranteesResult)
119+
const getGranteesResult: GetGranteesResult = await bee.getGrantees(granteesResult.ref);
120+
console.log('getGranteesResult:', {
121+
...getGranteesResult,
122+
grantees: getGranteesResult.grantees.map(grantee => grantee.toCompressedHex())
123+
});
117124
```
118125

119126
```json title="getGranteesResult"
120127
{
121128
"status": 200,
122129
"statusText": "OK",
123-
"data": [
130+
"grantees": [
124131
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e8",
125132
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e9",
126133
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12ee"
@@ -144,40 +151,41 @@ const patchGrantees = {
144151
]
145152
}
146153
// A short delay is needed if we call it immediately after createGrantees.
147-
await new Promise(resolve => setTimeout(resolve, 1500))
148-
const granteeResultAfterPatch = await bee.patchGrantees(
149-
postageBatchId,
150-
granteeResult.ref,
151-
granteeResult.historyref,
152-
patchGrantees
153-
)
154-
console.log(granteeResultAfterPatch)
154+
await new Promise(resolve => setTimeout(resolve, 1500));
155+
const granteeResultAfterPatch: GranteesResult = await bee.patchGrantees(postageBatchId, granteesResult.ref, granteesResult.historyref, patch_grantees);
156+
console.log('granteeResultAfterPatch:', {
157+
...granteeResultAfterPatch,
158+
ref: granteeResultAfterPatch.ref.toString(),
159+
historyref: granteeResultAfterPatch.historyref.toString(),
160+
})
155161
```
156162

157163
```json title="granteeResultAfterPatch"
158164
{
159165
"status": 200,
160166
"statusText": "OK",
161-
"ref": "ae9fd8e0d9158ab9a433bacfde9109bd0545e31a0d8e4f592a5a558e842de59a86f73e08a594874fe38d6a68cfa636a729dcc73b746083b12a384b6578ac5dce",
162-
"historyref": "0a0f709ed9d5ecd46434b8c62aeefc84bffeed7a80741c453d27ffdf67359fff"
167+
"ref": "694152dd351a701a0090b82bbdbd892f110a589596f6a504833855af91aacbf127e292a8a49119c53ec46c112501eab6933340c59d05576ec45354e990479e5f",
168+
"historyref": "73a62da4ad3a29f1899b548d3dbe1a96baab11ab73b02e36ce9fec728a5b87d3"
163169
}
164170
```
165171

166172
After the patch, the grantee list will have a new reference.
167173

168174
```ts
169-
// List Grantees
170-
const getGranteesResultAfterPatch = await bee.getGrantees(granteeResultAfterPatch.ref)
171-
console.log(getGranteesResultAfterPatch)
175+
const getGranteesResultAfterPatch: GetGranteesResult = await bee.getGrantees(granteeResultAfterPatch.ref);
176+
console.log('getGranteesResultAfterPatch:', {
177+
...getGranteesResultAfterPatch,
178+
grantees: getGranteesResultAfterPatch.grantees.map(grantee => grantee.toCompressedHex())
179+
});
172180
```
173181

174182
```json title="getGranteesResultAfterPatch"
175183
{
176184
"status": 200,
177185
"statusText": "OK",
178-
"data": [
186+
"grantees": [
179187
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e8",
180-
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e7"
188+
"02ceff1422a7026ba54ad89967d81f2805a55eb3d05f64eb5c49ea6024212b12e7"'
181189
]
182190
}
183191
```

0 commit comments

Comments
 (0)