Skip to content

Commit 65f767d

Browse files
committed
ACT download section
1 parent d85284d commit 65f767d

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

docs/documentation/act.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,51 @@ You can choose which `History Reference` to share depending on which set of publ
277277

278278
## Download With ACT
279279

280-
:::
281-
🚧 Under Construction 🚧
282-
ACT download with bee-js is not currently functioning, however you can still download directly using a curl command for the Bee API and the corresponding headers.
283-
:::
284280

285-
Below are curl commands for downloading the file we uploaded with ACT. Each command is for the same file, but uploaded using a different grantees list. Therefore if we try downloading the file from the node with the public key of `03636056d1e08f100c5acaf14d10070102de9444c97b2e8215305ab3e97254ede6`, it will only work with the second command, since that one was uploaded using the grantees list which contained the public key, while the first one was uploaded using a list that does not contain it:
281+
In order to download using ACT, we must pass in the public key from the grantee list creator along with the file reference and history reference returned from the file upload operation:
286282

287-
```bash
288-
curl -X GET "http://localhost:1633/bzz/14bc3765a893f7bac1d179f2606997ece06389b20cedc4b7f707f98e8e3dca5f/" -H "swarm-act-publisher: 0295562f9c1013d1db29f7aaa0c997c4bb3f1fc053bd0ed49a3d98584490cc8f96" -H "swarm-act-history-address: 8e74e7dc0c94786b576b55d32c238ebcb4da633ee36ae9beae11aaa98defbb3d" --output downloaded_file.txt
283+
284+
```js
285+
import { Bee, Reference, PublicKey } from '@ethersphere/bee-js'
286+
287+
// Initialize Bee instance
288+
const bee = new Bee('http://localhost:1633')
289+
290+
291+
// Publisher public key used during upload
292+
const publisherPublicKey = new PublicKey('0295562f9c1013d1db29f7aaa0c997c4bb3f1fc053bd0ed49a3d98584490cc8f96');
293+
294+
// File reference and history reference returned from upload operation
295+
const fileRef_01 = new Reference('14bc3765a893f7bac1d179f2606997ece06389b20cedc4b7f707f98e8e3dca5f');
296+
const historyRef_01 = new Reference('8e74e7dc0c94786b576b55d32c238ebcb4da633ee36ae9beae11aaa98defbb3d');
297+
298+
299+
// Function to download ACT-protected content
300+
async function downloadWithACT(fileRef, historyRef, publisherPubKey) {
301+
try {
302+
const result = await bee.downloadFile(fileRef, './', {
303+
actPublisher: publisherPubKey,
304+
actHistoryAddress: historyRef
305+
})
306+
307+
console.log('Content:', result.data.toUtf8())
308+
} catch (error) {
309+
console.error(`Error downloading from reference ${fileRef}:`, error)
310+
}
311+
}
312+
313+
// Download using two sets of file + history references
314+
downloadWithACT(
315+
fileRef_01,
316+
historyRef_01,
317+
publisherPublicKey
318+
)
289319
```
290320

321+
Example terminal output:
322+
291323
```bash
292-
curl -X GET "http://localhost:1633/bzz/14bc3765a893f7bac1d179f2606997ece06389b20cedc4b7f707f98e8e3dca5f/" -H "swarm-act-publisher: 0295562f9c1013d1db29f7aaa0c997c4bb3f1fc053bd0ed49a3d98584490cc8f96" -H "swarm-act-history-address: 7fd72a4d7a175c6d709c799b990adc8b200ec3e0f413c2ae48026a316bb4810c" --output downloaded_file.txt
293-
```
324+
Content: This is a sample string that will be uploaded securely using ACT. 01.
325+
```
326+
327+
In the example above, we used the history reference from the file uploaded using the grantees list with only one public key included (`027d0c4759f689ea3dd3eb79222870671c492cb99f3fade275bcbf0ea39cd0ef6e`), and so it will only be able to be retrieved and decrypted by the node with that public key.

0 commit comments

Comments
 (0)