@@ -19,6 +19,7 @@ This section is still being worked on. Check back soon for updates!
1919
2020
2121## Create Grantees List
22+ First we create a grantees list with the public keys of anyone we want to grant access to:
2223
2324``` js
2425import { Bee , PublicKey , BatchId } from ' @ethersphere/bee-js' ;
@@ -28,11 +29,11 @@ const bee = new Bee('http://localhost:1643');
2829
2930// Grantee's public key (replace with the actual key)
3031const grantees = [
31- new PublicKey (' 027d0c4759f689ea3dd3eb79222870671c492cb99f3fade275bcbf0ea39cd0ef6e' )
32+ new PublicKey (' 027d0c4759f689ea3dd3eb79222870671c492cb99f3fade275bcbf0ea39cd0ef6e' ),
3233];
3334
3435// Your postage batch ID (replace with a valid one)
35- const postageBatchId = new BatchId (' 955e22d95ca6793db4d22cb1aac1c59f64469293811bb969ac33f0c23f3b1f31 ' );
36+ const postageBatchId = new BatchId (' f2949db4cfa4f5140ed3ef29f651d189175a8cb9534c992d3c3212b17f0b67f7 ' );
3637
3738// Function to create grantees list
3839async function createGranteeList () {
@@ -57,11 +58,30 @@ Example output:
5758
5859``` bash
5960Grantee List Created Successfully:
60- Reference: ac35c416cae0a5481e483b70a55950c0d0ed63f61ead4edc20d6fc70d065fc3792223d08752fa6ea9b6bdf66d55def4fdceb3a2f9d8672aacde209717bfbf8fd
61- History Reference: 980969082877ba5577e01fd2bfe9941d151a1ca2a58aa8c114a97807e8e94e54
61+ Reference: 98bc4076efe5736aa682649c1928cbc9e0ac11d395f7ed0e67126ff660f5410a238e14f8b1d74f7df6121b8450d79ca789a257eeb84c5ca7dda3ed08a6859934
62+ History Reference: 06ee838e1f9b26c6d44077a2e63ad5ba9ecc143f278f9301f477eb99391f5796
6263```
6364
64- ## Update Grantees List
65+ The first reference ` Reference ` is used on its own for reviewing the list contents and updating the list. It is encrypted so only the list creator can view the list contents.
66+
67+ The seconde reference ` History Reference ` is used along with the first ` Reference ` for creating a new grantee list based on the list referred to by the ` Reference ` .
68+
69+ ## Update Grantees
70+
71+ In order to update grantees we pass an object in this format to the ` bee.patchGrantees ` method containing the public keys we wish to add or remove from the list along with the ` History Reference ` and the grantee list ` Reference ` and a valid postage stamp:
72+
73+ ``` js
74+ bee .patchGrantees (postageBatchId, granteeListRef, granteeHistoryRef, {
75+ add: [grantee1, grantee2], // Add the new grantee
76+ revoke: [],
77+ });
78+ ```
79+
80+ Calling this method will create an entirely new grantees list based on our first list and will return the ` Reference ` and ` History Reference ` for the new list.
81+
82+ This *** WILL NOT*** update which users had access to content uploaded using the first grantees list, it is simply creating a new list with a different set of grantees which can be used for uploading content accessible to the new set.
83+
84+ Full example script:
6585
6686``` js
6787import { Bee , PublicKey , BatchId , Reference } from ' @ethersphere/bee-js' ;
@@ -70,21 +90,22 @@ import { Bee, PublicKey, BatchId, Reference } from '@ethersphere/bee-js';
7090const bee = new Bee (' http://localhost:1643' ); // Correct port is 1643
7191
7292// Grantee's public key to be added (replace with the actual key)
73- const newGrantee = new PublicKey (' 03636056d1e08f100c5acaf14d10070102de9444c97b2e8215305ab3e97254ede6' );
93+ const grantee = new PublicKey (' 03636056d1e08f100c5acaf14d10070102de9444c97b2e8215305ab3e97254ede6' );
7494
7595// Grantee list reference and history reference (replace with actual references from `createGrantees`)
76- const granteeListRef = new Reference (' ac35c416cae0a5481e483b70a55950c0d0ed63f61ead4edc20d6fc70d065fc3792223d08752fa6ea9b6bdf66d55def4fdceb3a2f9d8672aacde209717bfbf8fd ' )
77- const granteeHistoryRef = new Reference (' 980969082877ba5577e01fd2bfe9941d151a1ca2a58aa8c114a97807e8e94e54 ' )
96+ const granteeListRef = new Reference (' 98bc4076efe5736aa682649c1928cbc9e0ac11d395f7ed0e67126ff660f5410a238e14f8b1d74f7df6121b8450d79ca789a257eeb84c5ca7dda3ed08a6859934 ' )
97+ const granteeHistoryRef = new Reference (' 06ee838e1f9b26c6d44077a2e63ad5ba9ecc143f278f9301f477eb99391f5796 ' )
7898
7999// Your postage batch ID (replace with a valid one)
80- const postageBatchId = new BatchId (' 955e22d95ca6793db4d22cb1aac1c59f64469293811bb969ac33f0c23f3b1f31 ' );
100+ const postageBatchId = new BatchId (' f2949db4cfa4f5140ed3ef29f651d189175a8cb9534c992d3c3212b17f0b67f7 ' );
81101
82102// Function to update the grantee list by adding the new public key
83103async function updateGranteeList () {
84104 try {
85105 // Call the patchGrantees function to add the new public key
86106 const response = await bee .patchGrantees (postageBatchId, granteeListRef, granteeHistoryRef, {
87- add: [newGrantee], // Add the new grantee
107+ add: [grantee], // Add the new grantee
108+ revoke: [],
88109 });
89110
90111 // Log the updated grantee list references
@@ -109,23 +130,27 @@ Example output:
109130
110131``` bash
111132Grantee List Updated Successfully:
112- Updated Reference: 4cad43d435bceca6925b3ed750d415a9f78566bb2b7dac90886f9305cd8f2267818cfaf6b0cd00a593a94719ec1cbc0270c76f0c57840c1210667b7b6aa48080
113- Updated History Reference: ffa62ebf1c0f8f9c756743add487d0e5f0c938309333e283729bdb9ad962da14
133+ Updated Reference: 363430f8c500e7ea7d23eff1f14674cf6d46ce1640684edad7cc2e5631c37bbaf9dc5b0f5ea42f919191c77187a7f1f40adfd1ab60bc84f1ae4f2d7bf42b98bd
134+ Updated History Reference: c2a43bea8abaae8ef31141ef8ec953097c76f48c2a14c1a6119bb110675e5378
114135```
115136
116137## Get Grantees List
117138
139+ In order to view the members of our grantees list we need to use the ` Reference ` returned when we create or update a list. We will view both our original list and the updated list based on the original list using the respective ` Reference ` from each list:
140+
118141``` js
119142import { Bee , Reference } from ' @ethersphere/bee-js' ;
120143
121144// Initialize Bee instance with the correct port (1643)
122145const bee = new Bee (' http://localhost:1643' );
123146
124- // Grantee list reference (the reference returned from the `createGrantees` function)
125- const granteeListRef = new Reference (' 55c3b293cd15956f4c40f2fe1b58e4fea4cf55a1c95b61a419120b39d545f9592c58ea761147122685ff940409a57047d04cb2ae914b5ecf2a0083267eded8ab' );
147+
148+ // Grantee list references (the reference returned from the `createGrantees` function)
149+ const granteeListRef_01 = new Reference (' 98bc4076efe5736aa682649c1928cbc9e0ac11d395f7ed0e67126ff660f5410a238e14f8b1d74f7df6121b8450d79ca789a257eeb84c5ca7dda3ed08a6859934' );
150+ const granteeListRef_02 = new Reference (' 363430f8c500e7ea7d23eff1f14674cf6d46ce1640684edad7cc2e5631c37bbaf9dc5b0f5ea42f919191c77187a7f1f40adfd1ab60bc84f1ae4f2d7bf42b98bd' );
126151
127152// Function to get the grantee list
128- async function getGranteeList () {
153+ async function getGranteeList (granteeListRef ) {
129154 try {
130155 // Call the getGrantees function with the reference
131156 const result = await bee .getGrantees (granteeListRef);
@@ -135,21 +160,104 @@ async function getGranteeList() {
135160 console .log (' Status:' , result .status );
136161 console .log (' Status Text:' , result .statusText );
137162
138- // Log the grantees as an array of their string representations (compressed hex values)
163+ // Log the as an array of their string representations (compressed hex values)
139164 console .log (' Grantees:' , result .grantees .map (grantee => grantee .toCompressedHex ()));
140165
141- // Check if ref and historyref exist before trying to call toHex()
142- if (result .ref && result .historyref ) {
143- console .log (' Reference:' , result .ref .toHex ());
144- console .log (' History Reference:' , result .historyref .toHex ());
145- } else {
146- console .log (' Reference or History Reference not found.' );
147- }
148166 } catch (error) {
149167 console .error (' Error retrieving grantee list:' , error);
150168 }
151169}
152170
153171// Call the function to fetch the grantee list
154- getGranteeList ();
172+ getGranteeList (granteeListRef_01);
173+ getGranteeList (granteeListRef_02);
174+ ```
175+
176+ Example output:
177+
178+ ``` bash
179+ Grantee List Retrieved:
180+ Status: 200
181+ Status Text: OK
182+ Grantees: [
183+ ' 027d0c4759f689ea3dd3eb79222870671c492cb99f3fade275bcbf0ea39cd0ef6e'
184+ ]
185+ Grantee List Retrieved:
186+ Status: 200
187+ Status Text: OK
188+ Grantees: [
189+ ' 027d0c4759f689ea3dd3eb79222870671c492cb99f3fade275bcbf0ea39cd0ef6e' ,
190+ ' 03636056d1e08f100c5acaf14d10070102de9444c97b2e8215305ab3e97254ede6'
191+ ]
192+ ```
193+
194+ The first list of grantees contains the first public key we gave access to when we created the list, while the second one contains both the first and the second one we added when we created our second list based on the first one.
195+
196+ ## Upload With ACT
197+
198+ We can upload our content with either of the two lists we created depending on which set of users we wish to give access too. In the example below, we use both lists.
199+
200+ ``` js
201+ import { Bee , BatchId , Reference } from ' @ethersphere/bee-js' ;
202+
203+ // Initialize Bee instance with the correct port (1643)
204+ const bee = new Bee (' http://localhost:1643' );
205+
206+ // Your postage batch ID (replace with a valid one)
207+ const postageBatchId = new BatchId (' f2949db4cfa4f5140ed3ef29f651d189175a8cb9534c992d3c3212b17f0b67f7' );
208+
209+ // Grantee history reference (the reference returned from the `createGrantees` function)
210+ const granteeHistoryRef1 = new Reference (' 06ee838e1f9b26c6d44077a2e63ad5ba9ecc143f278f9301f477eb99391f5796' );
211+ const granteeHistoryRef2 = new Reference (' c2a43bea8abaae8ef31141ef8ec953097c76f48c2a14c1a6119bb110675e5378' );
212+
213+ // Sample data to upload
214+ const fileData = ' This is a sample string that will be uploaded securely using ACT. ABCDE.' ;
215+
216+ // Function to upload the data with ACT
217+ async function uploadWithACT (historyRef ) {
218+ try {
219+ // Upload the string with ACT enabled
220+ const result = await bee .uploadFile (postageBatchId, fileData, ' samplefile.txt' , {
221+ act: true , // Enable ACT for the uploaded data
222+ actHistoryAddress: historyRef, // Provide the grantee list reference for ACT
223+ contentType: ' text/plain' ,
224+ });
225+
226+ console .log (' File uploaded successfully with ACT:' );
227+ console .log (' Reference:' , result .reference .toHex ());
228+ console .log (" History reference" )
229+ console .log (result .historyAddress .value .toHex ())
230+ } catch (error) {
231+ console .error (' Error uploading file with ACT:' , error);
232+ }
233+ }
234+
235+ // Call the function to upload the file
236+ uploadWithACT (granteeHistoryRef1);
237+ uploadWithACT (granteeHistoryRef2);
238+ ```
239+
240+ Example output:
241+
242+ ``` bash
243+ File uploaded successfully with ACT:
244+ Reference: d3d4485efcc22acdf4d20a31d79edc3220655151bd15cec0df9111e0c0f89e86
245+ History reference
246+ 06ee838e1f9b26c6d44077a2e63ad5ba9ecc143f278f9301f477eb99391f5796
247+ File uploaded successfully with ACT:
248+ Reference: d3d4485efcc22acdf4d20a31d79edc3220655151bd15cec0df9111e0c0f89e86
249+ History reference
250+ c2a43bea8abaae8ef31141ef8ec953097c76f48c2a14c1a6119bb110675e5378
251+ ```
252+
253+ The reference hash is the same for each upload since the content is the same. The reference hash along with a ` History Reference ` and the uploader's public key are required in order to access the content uploaded with ACT.
254+
255+ You can choose which ` History Reference ` to share depending on which set of public keys you wish to authorize to download the content.
256+
257+ ## Download With ACT
258+
259+ The example below uses the first ` History Reference ` , and so can only gives access to the single public key in the grantees list it refers to. If we wish to give both public keys access then we could share the other key.
260+
261+ ``` bash
262+ curl -X GET " http://localhost:1633/bzz/d3d4485efcc22acdf4d20a31d79edc3220655151bd15cec0df9111e0c0f89e86/" -H " swarm-act-publisher: 0295562f9c1013d1db29f7aaa0c997c4bb3f1fc053bd0ed49a3d98584490cc8f96" -H " swarm-act-history-address: 06ee838e1f9b26c6d44077a2e63ad5ba9ecc143f278f9301f477eb99391f5796" --output downloaded_file.txt
155263```
0 commit comments