@upcoming/bee-js 9.9.1 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/bee.js +881 -370
  3. package/dist/cjs/chunk/bmt.js +1 -2
  4. package/dist/cjs/chunk/cac.js +27 -32
  5. package/dist/cjs/chunk/soc.js +39 -31
  6. package/dist/cjs/feed/identifier.js +1 -2
  7. package/dist/cjs/feed/index.js +29 -19
  8. package/dist/cjs/feed/retrievable.js +1 -2
  9. package/dist/cjs/index.js +17 -7
  10. package/dist/cjs/manifest/manifest.js +19 -2
  11. package/dist/cjs/modules/bytes.js +4 -5
  12. package/dist/cjs/modules/bzz.js +4 -5
  13. package/dist/cjs/modules/chunk.js +2 -3
  14. package/dist/cjs/modules/debug/balance.js +4 -5
  15. package/dist/cjs/modules/debug/chequebook.js +9 -10
  16. package/dist/cjs/modules/debug/connectivity.js +7 -8
  17. package/dist/cjs/modules/debug/settlements.js +2 -3
  18. package/dist/cjs/modules/debug/stake.js +6 -7
  19. package/dist/cjs/modules/debug/stamps.js +24 -60
  20. package/dist/cjs/modules/debug/states.js +6 -6
  21. package/dist/cjs/modules/debug/status.js +9 -9
  22. package/dist/cjs/modules/debug/transactions.js +4 -5
  23. package/dist/cjs/modules/envelope.js +1 -2
  24. package/dist/cjs/modules/feed.js +3 -4
  25. package/dist/cjs/modules/grantee.js +3 -4
  26. package/dist/cjs/modules/gsoc.js +2 -3
  27. package/dist/cjs/modules/pinning.js +4 -5
  28. package/dist/cjs/modules/pss.js +2 -3
  29. package/dist/cjs/modules/rchash.js +1 -2
  30. package/dist/cjs/modules/soc.js +1 -2
  31. package/dist/cjs/modules/status.js +2 -3
  32. package/dist/cjs/modules/stewardship.js +2 -3
  33. package/dist/cjs/modules/tag.js +5 -6
  34. package/dist/cjs/types/debug.js +3 -3
  35. package/dist/cjs/types/index.js +11 -6
  36. package/dist/cjs/utils/bytes.js +23 -3
  37. package/dist/cjs/utils/chunk-size.js +1 -2
  38. package/dist/cjs/utils/chunk-stream.browser.js +30 -6
  39. package/dist/cjs/utils/chunk-stream.js +3 -4
  40. package/dist/cjs/utils/cid.js +3 -3
  41. package/dist/cjs/utils/collection.browser.js +2 -3
  42. package/dist/cjs/utils/collection.js +5 -6
  43. package/dist/cjs/utils/collection.node.js +2 -3
  44. package/dist/cjs/utils/data.browser.js +1 -2
  45. package/dist/cjs/utils/data.js +1 -2
  46. package/dist/cjs/utils/duration.js +27 -1
  47. package/dist/cjs/utils/expose.js +4 -1
  48. package/dist/cjs/utils/file.js +2 -3
  49. package/dist/cjs/utils/headers.js +2 -3
  50. package/dist/cjs/utils/http.js +25 -5
  51. package/dist/cjs/utils/pss.js +1 -2
  52. package/dist/cjs/utils/redundancy.js +3 -4
  53. package/dist/cjs/utils/size.js +25 -0
  54. package/dist/cjs/utils/stamps.js +60 -11
  55. package/dist/cjs/utils/tar-uploader.browser.js +1 -2
  56. package/dist/cjs/utils/tar-uploader.js +1 -2
  57. package/dist/cjs/utils/tar-writer.browser.js +1 -2
  58. package/dist/cjs/utils/tar-writer.js +1 -2
  59. package/dist/cjs/utils/type.js +37 -25
  60. package/dist/cjs/utils/url.js +3 -4
  61. package/dist/cjs/utils/workaround.js +7 -5
  62. package/dist/index.browser.min.js +1 -1
  63. package/dist/index.browser.min.js.map +1 -1
  64. package/dist/mjs/bee.js +864 -366
  65. package/dist/mjs/chunk/cac.js +21 -30
  66. package/dist/mjs/chunk/soc.js +16 -17
  67. package/dist/mjs/feed/index.js +7 -6
  68. package/dist/mjs/manifest/manifest.js +19 -2
  69. package/dist/mjs/modules/debug/chequebook.js +2 -2
  70. package/dist/mjs/modules/debug/stamps.js +38 -93
  71. package/dist/mjs/modules/debug/states.js +3 -0
  72. package/dist/mjs/modules/debug/status.js +1 -1
  73. package/dist/mjs/types/index.js +8 -3
  74. package/dist/mjs/utils/bytes.js +19 -2
  75. package/dist/mjs/utils/chunk-stream.browser.js +29 -5
  76. package/dist/mjs/utils/duration.js +27 -1
  77. package/dist/mjs/utils/expose.js +1 -1
  78. package/dist/mjs/utils/http.js +25 -3
  79. package/dist/mjs/utils/size.js +25 -0
  80. package/dist/mjs/utils/stamps.js +48 -0
  81. package/dist/mjs/utils/type.js +8 -1
  82. package/dist/mjs/utils/workaround.js +5 -2
  83. package/dist/types/bee.d.ts +756 -252
  84. package/dist/types/chunk/cac.d.ts +27 -13
  85. package/dist/types/chunk/soc.d.ts +43 -11
  86. package/dist/types/index.d.ts +3 -0
  87. package/dist/types/modules/bzz.d.ts +0 -1
  88. package/dist/types/modules/debug/stamps.d.ts +2 -2
  89. package/dist/types/modules/debug/status.d.ts +1 -1
  90. package/dist/types/modules/gsoc.d.ts +0 -1
  91. package/dist/types/modules/pss.d.ts +0 -1
  92. package/dist/types/types/debug.d.ts +2 -1
  93. package/dist/types/types/index.d.ts +53 -6
  94. package/dist/types/utils/constants.d.ts +3 -3
  95. package/dist/types/utils/duration.d.ts +24 -0
  96. package/dist/types/utils/error.d.ts +2 -2
  97. package/dist/types/utils/expose.d.ts +1 -1
  98. package/dist/types/utils/size.d.ts +23 -0
  99. package/dist/types/utils/stamps.d.ts +15 -1
  100. package/dist/types/utils/tar.browser.d.ts +1 -1
  101. package/dist/types/utils/tar.d.ts +0 -1
  102. package/dist/types/utils/type.d.ts +0 -1
  103. package/package.json +10 -13
package/dist/mjs/bee.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Binary, Objects, System, Types } from 'cafe-utility';
2
- import { makeContentAddressedChunk } from "./chunk/cac.js";
3
- import { downloadSingleOwnerChunk, makeSOCAddress, makeSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
2
+ import { makeContentAddressedChunk, unmarshalContentAddressedChunk } from "./chunk/cac.js";
3
+ import { downloadSingleOwnerChunk, makeSOCAddress, makeSingleOwnerChunk, unmarshalSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
4
4
  import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
5
5
  import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
6
6
  import * as bytes from "./modules/bytes.js";
@@ -37,24 +37,26 @@ import { ResourceLocator } from "./utils/resource-locator.js";
37
37
  import { getAmountForDuration, getDepthForSize, getStampCost } from "./utils/stamps.js";
38
38
  import { BZZ, DAI } from "./utils/tokens.js";
39
39
  import { asNumberString, assertData, assertFileData, makeTagUid, prepareAllTagsOptions, prepareBeeRequestOptions, prepareCollectionUploadOptions, prepareDownloadOptions, prepareFileUploadOptions, prepareGsocMessageHandler, preparePostageBatchOptions, preparePssMessageHandler, prepareRedundantUploadOptions, prepareTransactionOptions, prepareUploadOptions } from "./utils/type.js";
40
- import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
40
+ import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Signature, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
41
41
  import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
42
42
  /**
43
- * The main component that abstracts operations available on the main Bee API.
43
+ * The main component that abstracts operations available on the Bee API.
44
44
  *
45
- * Not all methods are always available as it depends in what mode is Bee node launched in.
46
- * For example gateway mode and light node mode has only limited set of endpoints enabled.
45
+ * Instantiate with `new Bee(url, options)` where `url` is the Bee node URL and `options` are optional parameters.
46
+ *
47
+ * @example
48
+ * const bee = new Bee('http://localhost:1633')
47
49
  */
48
50
  export class Bee {
49
51
  /**
50
52
  * @param url URL on which is the main API of Bee node exposed
51
53
  * @param options
54
+ *
55
+ * @example
56
+ * const bee = new Bee('http://localhost:1633')
52
57
  */
53
58
  constructor(url, options) {
54
59
  assertBeeUrl(url);
55
- // Remove last slash if present, as our endpoint strings starts with `/...`
56
- // which could lead to double slash in URL to which Bee responds with
57
- // unnecessary redirects.
58
60
  this.url = stripLastSlash(url);
59
61
  if (options?.signer) {
60
62
  this.signer = new PrivateKey(options.signer);
@@ -70,15 +72,19 @@ export class Bee {
70
72
  };
71
73
  }
72
74
  /**
73
- * Upload data to a Bee node
75
+ * Uploads raw data to the network (as opposed to uploading chunks or files).
74
76
  *
75
- * @param postageBatchId Postage BatchId to be used to upload the data with
76
- * @param data Data to be uploaded
77
- * @param options Additional options like tag, encryption, pinning, content-type and request options
77
+ * Data uploaded with this method should be retrieved with the {@link downloadData} method.
78
+ *
79
+ * @param postageBatchId Usable Postage Batch ID with sufficient capacity to upload the data.
80
+ * @param data A `string` (text data) or `Uint8Array` (raw data) to be uploaded.
81
+ * @param options Additional options like tag, encryption, pinning, content-type and request options.
82
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
78
83
  *
79
84
  * @returns reference is a content hash of the data
80
- * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
85
+ *
81
86
  * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
87
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
82
88
  */
83
89
  async uploadData(postageBatchId, data, options, requestOptions) {
84
90
  postageBatchId = new BatchId(postageBatchId);
@@ -89,21 +95,32 @@ export class Bee {
89
95
  return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
90
96
  }
91
97
  /**
92
- * Requests content length for a `/bytes` reference
98
+ * Fetches content length for a `/bytes` reference.
99
+ *
100
+ * @param reference
101
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
93
102
  *
94
- * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
103
+ * @see [Bee API reference - `HEAD /bytes/{reference}`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
95
104
  */
96
- async probeData(reference, options) {
105
+ async probeData(reference, requestOptions) {
97
106
  reference = new Reference(reference);
98
- return bytes.head(this.getRequestOptionsForCall(options), reference);
107
+ return bytes.head(this.getRequestOptionsForCall(requestOptions), reference);
99
108
  }
100
109
  /**
101
- * Download data as a byte array
110
+ * Downloads raw data through the `GET /bytes/{reference}` endpoint.
102
111
  *
103
- * @param resource Swarm reference, Swarm CID, or ENS domain
112
+ * This method may be used to download data that was uploaded with the {@link uploadData} method.
113
+ *
114
+ * For downloading files or using the `GET /bzz/{reference}/` endpoint, use the {@link downloadFile} method instead.
115
+ * For downloading chunks or using the `GET /chunks/{reference} endpoint, use the `downloadChunk` method instead.
116
+ *
117
+ * @param resource Swarm reference, Swarm CID, or ENS domain.
104
118
  * @param options Options that affects the request behavior
119
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
120
+ *
105
121
  * @throws TypeError if some of the input parameters is not expected type
106
122
  * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
123
+ *
107
124
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
108
125
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
109
126
  */
@@ -114,12 +131,18 @@ export class Bee {
114
131
  return bytes.download(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
115
132
  }
116
133
  /**
117
- * Download data as a Readable stream
134
+ * Download raw data through the `GET /bytes/{reference}` endpoint.
135
+ *
136
+ * This method may be used to download data that was uploaded with the {@link uploadData} method.
137
+ *
138
+ * Only tested in Node.js environment.
139
+ *
140
+ * @param resource Swarm reference, Swarm CID, or ENS domain.
141
+ * @param options Options that affects the request behavior.
142
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
143
+ *
144
+ * @returns ReadableStream of Uint8Array
118
145
  *
119
- * @param resource Swarm reference, Swarm CID, or ENS domain
120
- * @param options Options that affects the request behavior
121
- * @throws TypeError if some of the input parameters is not expected type
122
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
123
146
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
124
147
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
125
148
  */
@@ -130,17 +153,21 @@ export class Bee {
130
153
  return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
131
154
  }
132
155
  /**
133
- * Upload chunk to a Bee node
156
+ * Uploads a chunk to the network.
157
+ *
158
+ * Chunks uploaded with this method should be retrieved with the {@link downloadChunk} method.
134
159
  *
135
- * @param postageBatchId Postage BatchId to be used to upload the chunk with
136
- * @param data Raw chunk to be uploaded
160
+ * @param stamp Postage Batch ID or an Envelope created with the {@link createEnvelope} method.
161
+ * @param data Raw chunk to be uploaded (Content Addressed Chunk or Single Owner Chunk)
137
162
  * @param options Additional options like tag, encryption, pinning, content-type and request options
163
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
138
164
  *
139
165
  * @returns reference is a content hash of the data
140
166
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
141
167
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
142
168
  */
143
169
  async uploadChunk(stamp, data, options, requestOptions) {
170
+ const isSOC = 'identifier' in data && 'signature' in data && 'owner' in data;
144
171
  data = data instanceof Uint8Array ? data : data.data;
145
172
  if (options) {
146
173
  options = prepareUploadOptions(options);
@@ -148,18 +175,26 @@ export class Bee {
148
175
  if (data.length < Span.LENGTH) {
149
176
  throw new BeeArgumentError(`Chunk has to have size of at least ${Span.LENGTH}.`, data);
150
177
  }
151
- if (data.length > CHUNK_SIZE + Span.LENGTH) {
152
- throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE + Span.LENGTH}.`, data);
178
+ if (!isSOC && data.length > CHUNK_SIZE + Span.LENGTH) {
179
+ throw new BeeArgumentError(`Content Addressed Chunk must not exceed ${CHUNK_SIZE + Span.LENGTH} bytes.`, data);
180
+ }
181
+ if (isSOC && data.length > CHUNK_SIZE + Span.LENGTH + Signature.LENGTH + Identifier.LENGTH) {
182
+ throw new BeeArgumentError(`Single Owner Chunk must not exceed ${CHUNK_SIZE + Span.LENGTH + Signature.LENGTH + Identifier.LENGTH} bytes.`, data);
153
183
  }
154
184
  return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
155
185
  }
156
186
  /**
157
- * Download chunk as a byte array
187
+ * Downloads a chunk as a `Uint8Array`.
188
+ *
189
+ * May be used to download chunks uploaded with the {@link uploadChunk} method.
190
+ *
191
+ * Use {@link downloadData} method to download raw data uploaded with the {@link uploadData} method.
192
+ * Use {@link downloadFile} method to download files uploaded with the {@link uploadFile} method.
158
193
  *
159
194
  * @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
160
195
  * @param options Options that affects the request behavior
161
- * @throws TypeError if some of the input parameters is not expected type
162
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
196
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
197
+ *
163
198
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
164
199
  * @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{address}/get)
165
200
  */
@@ -173,7 +208,7 @@ export class Bee {
173
208
  /**
174
209
  * Create a grantees list from the given array of public keys.
175
210
  *
176
- * The grantees list can be obtained with the `getGrantees` method.
211
+ * The grantees list can be obtained with the {@link getGrantees} method.
177
212
  *
178
213
  * @param postageBatchId - The ID of the postage batch.
179
214
  * @param grantees - An array of public keys representing the grantees.
@@ -203,7 +238,7 @@ export class Bee {
203
238
  * @param history - The history.
204
239
  * @param postageBatchId - The ID of the postage batch.
205
240
  * @param grantees - The grantees.
206
- * @param requestOptions - Optional request options.
241
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
207
242
  * @returns A Promise that resolves to to a `GranteesResult` object.
208
243
  */
209
244
  async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
@@ -217,12 +252,18 @@ export class Bee {
217
252
  return grantee.patchGrantees(postageBatchId, reference, history, publicKeys, this.getRequestOptionsForCall(requestOptions));
218
253
  }
219
254
  /**
220
- * Upload single file to a Bee node.
255
+ * Uploads a single file to a Bee node.
256
+ *
257
+ * To download the file, use the {@link downloadFile} method.
258
+ *
259
+ * Use {@link uploadData} method to upload raw data that can be downloaded with the {@link downloadData} method.
260
+ * Use {@link uploadChunk} method to upload chunks that can be downloaded with the {@link downloadChunk} method.
221
261
  *
222
262
  * @param postageBatchId Postage BatchId to be used to upload the data with
223
263
  * @param data Data or file to be uploaded
224
264
  * @param name Optional name of the uploaded file
225
265
  * @param options Additional options like tag, encryption, pinning, content-type and request options
266
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
226
267
  *
227
268
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
228
269
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
@@ -252,14 +293,13 @@ export class Bee {
252
293
  }
253
294
  }
254
295
  /**
255
- * Download single file.
296
+ * Downloads a single file.
256
297
  *
257
- * @param resource Swarm reference, Swarm CID, or ENS domain
298
+ * @param resource Swarm reference, Swarm CID, or ENS domain.
258
299
  * @param path If reference points to manifest, then this parameter defines path to the file
259
300
  * @param options Options that affects the request behavior
260
- * @throws TypeError if some of the input parameters is not expected type
261
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
262
- * @see Data
301
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
302
+ *
263
303
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
264
304
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
265
305
  */
@@ -275,8 +315,7 @@ export class Bee {
275
315
  * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
276
316
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
277
317
  * @param options Options that affects the request behavior
278
- * @throws TypeError if some of the input parameters is not expected type
279
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
318
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
280
319
  *
281
320
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
282
321
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
@@ -299,6 +338,7 @@ export class Bee {
299
338
  * @param postageBatchId Postage BatchId to be used to upload the data with
300
339
  * @param fileList list of files to be uploaded
301
340
  * @param options Additional options like tag, encryption, pinning and request options
341
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
302
342
  *
303
343
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
304
344
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download#upload-a-directory)
@@ -312,13 +352,57 @@ export class Bee {
312
352
  const data = makeCollectionFromFileList(fileList);
313
353
  return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
314
354
  }
355
+ /**
356
+ * Hashes a directory locally and returns the root hash (Swarm reference).
357
+ *
358
+ * The actual Swarm reference may be different as there is no canonical hashing of directories.
359
+ * For example, metadata may have different casing, or the order of metadata may differ.
360
+ * Such small differences will result in different Swarm references.
361
+ *
362
+ * Different implementations of the Mantaray structure may also result in different Swarm references.
363
+ *
364
+ * @param dir
365
+ * @returns
366
+ */
315
367
  async hashDirectory(dir) {
316
368
  return hashDirectory(dir);
317
369
  }
370
+ /**
371
+ * Uploads a directory to the network. The difference between this method and {@link uploadFilesFromDirectory} is that
372
+ * this method streams the directory contents directly to the Bee node, which supports arbitrary directory sizes,
373
+ * but may be slower due to uploading chunks one by one.
374
+ *
375
+ * Options such as encryption, erasure coding and ACT are not yet available for this method.
376
+ *
377
+ * Only intended for the Node.js environment.
378
+ *
379
+ * @param postageBatchId
380
+ * @param dir
381
+ * @param onUploadProgress
382
+ * @param options
383
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
384
+ * @returns
385
+ */
318
386
  async streamDirectory(postageBatchId, dir, onUploadProgress, options, requestOptions) {
319
387
  postageBatchId = new BatchId(postageBatchId);
320
388
  return streamDirectory(this, dir, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
321
389
  }
390
+ /**
391
+ * Uploads a collection of files to the network. The difference between this method and {@link uploadFiles} is that
392
+ * this method streams the files to the Bee node, which supports arbitrary sizes,
393
+ * but may be slower due to uploading chunks one by one.
394
+ *
395
+ * Options such as encryption, erasure coding and ACT are not yet available for this method.
396
+ *
397
+ * Only intended for the browser environment.
398
+ *
399
+ * @param postageBatchId
400
+ * @param files
401
+ * @param onUploadProgress
402
+ * @param options
403
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
404
+ * @returns
405
+ */
322
406
  async streamFiles(postageBatchId, files, onUploadProgress, options, requestOptions) {
323
407
  postageBatchId = new BatchId(postageBatchId);
324
408
  return streamFiles(this, files, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
@@ -366,23 +450,23 @@ export class Bee {
366
450
  return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
367
451
  }
368
452
  /**
369
- * Create a new Tag which is meant for tracking progres of syncing data across network.
453
+ * Creates a new Tag which is meant for tracking upload and synchronization progress.
454
+ *
455
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
370
456
  *
371
- * @param options Options that affects the request behavior
372
457
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
373
458
  * @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
374
459
  */
375
- async createTag(options) {
376
- return tag.createTag(this.getRequestOptionsForCall(options));
460
+ async createTag(requestOptions) {
461
+ return tag.createTag(this.getRequestOptionsForCall(requestOptions));
377
462
  }
378
463
  /**
379
- * Fetches all tags.
464
+ * Fetches all tags in a paginated manner.
380
465
  *
381
466
  * The listing is limited by options.limit. So you have to iterate using options.offset to get all tags.
382
467
  *
383
- * @param options Options that affects the request behavior
384
- * @throws TypeError if limit or offset are not numbers or undefined
385
- * @throws BeeArgumentError if limit or offset have invalid options
468
+ * @param options Specify `limit` and `offset` to paginate through the tags.
469
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
386
470
  *
387
471
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
388
472
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
@@ -394,34 +478,31 @@ export class Bee {
394
478
  return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
395
479
  }
396
480
  /**
397
- * Retrieve tag information from Bee node
481
+ * Retrieves tag information from Bee node.
398
482
  *
399
483
  * @param tagUid UID or tag object to be retrieved
400
- * @param options Options that affects the request behavior
401
- * @throws TypeError if tagUid is in not correct format
484
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
402
485
  *
403
486
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
404
487
  * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/get)
405
488
  *
406
489
  */
407
- async retrieveTag(tagUid, options) {
490
+ async retrieveTag(tagUid, requestOptions) {
408
491
  tagUid = makeTagUid(tagUid);
409
- return tag.retrieveTag(this.getRequestOptionsForCall(options), tagUid);
492
+ return tag.retrieveTag(this.getRequestOptionsForCall(requestOptions), tagUid);
410
493
  }
411
494
  /**
412
- * Delete Tag
495
+ * Deletes Tag.
413
496
  *
414
497
  * @param tagUid UID or tag object to be retrieved
415
- * @param options Options that affects the request behavior
416
- * @throws TypeError if tagUid is in not correct format
417
- * @throws BeeResponse error if something went wrong on the Bee node side while deleting the tag.
498
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
418
499
  *
419
500
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
420
501
  * @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
421
502
  */
422
- async deleteTag(tagUid, options) {
503
+ async deleteTag(tagUid, requestOptions) {
423
504
  tagUid = makeTagUid(tagUid);
424
- return tag.deleteTag(this.getRequestOptionsForCall(options), tagUid);
505
+ return tag.deleteTag(this.getRequestOptionsForCall(requestOptions), tagUid);
425
506
  }
426
507
  /**
427
508
  * Update tag's total chunks count.
@@ -431,99 +512,90 @@ export class Bee {
431
512
  *
432
513
  * @param tagUid UID or tag object to be retrieved
433
514
  * @param reference The root reference that contains all the chunks to be counted
434
- * @param options Options that affects the request behavior
435
- * @throws TypeError if tagUid is in not correct format
436
- * @throws BeeResponse error if something went wrong on the Bee node side while deleting the tag.
515
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
437
516
  *
438
517
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
439
518
  * @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
440
519
  */
441
- async updateTag(tagUid, reference, options) {
520
+ async updateTag(tagUid, reference, requestOptions) {
442
521
  reference = new Reference(reference);
443
522
  tagUid = makeTagUid(tagUid);
444
- return tag.updateTag(this.getRequestOptionsForCall(options), tagUid, reference);
523
+ return tag.updateTag(this.getRequestOptionsForCall(requestOptions), tagUid, reference);
445
524
  }
446
525
  /**
447
- * Pin local data with given reference
526
+ * Pins local data with given reference.
448
527
  *
449
528
  * @param reference Data reference
450
- * @param options Options that affects the request behavior
451
- * @throws TypeError if reference is in not correct format
529
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
452
530
  *
453
531
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
454
532
  */
455
- async pin(reference, options) {
533
+ async pin(reference, requestOptions) {
456
534
  reference = new Reference(reference);
457
- return pinning.pin(this.getRequestOptionsForCall(options), reference);
535
+ return pinning.pin(this.getRequestOptionsForCall(requestOptions), reference);
458
536
  }
459
537
  /**
460
- * Unpin local data with given reference
538
+ * Unpins local data with given reference.
461
539
  *
462
540
  * @param reference Data reference
463
- * @param options Options that affects the request behavior
464
- * @throws TypeError if reference is in not correct format
541
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
465
542
  *
466
543
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
467
544
  */
468
- async unpin(reference, options) {
545
+ async unpin(reference, requestOptions) {
469
546
  reference = new Reference(reference);
470
- return pinning.unpin(this.getRequestOptionsForCall(options), reference);
547
+ return pinning.unpin(this.getRequestOptionsForCall(requestOptions), reference);
471
548
  }
472
549
  /**
473
- * Get list of all locally pinned references
550
+ * Gets list of all locally pinned references.
551
+ *
552
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
474
553
  *
475
- * @param options Options that affects the request behavior
476
554
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
477
555
  */
478
- async getAllPins(options) {
479
- return pinning.getAllPins(this.getRequestOptionsForCall(options));
556
+ async getAllPins(requestOptions) {
557
+ return pinning.getAllPins(this.getRequestOptionsForCall(requestOptions));
480
558
  }
481
559
  /**
482
560
  * Get pinning status of chunk with given reference
483
561
  *
484
562
  * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
485
- * @param options Options that affects the request behavior
486
- * @throws TypeError if some of the input parameters is not expected type
487
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
563
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
488
564
  *
489
565
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
490
566
  */
491
- async getPin(reference, options) {
567
+ async getPin(reference, requestOptions) {
492
568
  reference = new Reference(reference);
493
- return pinning.getPin(this.getRequestOptionsForCall(options), reference);
569
+ return pinning.getPin(this.getRequestOptionsForCall(requestOptions), reference);
494
570
  }
495
571
  /**
496
572
  * Instructs the Bee node to reupload a locally pinned data into the network.
497
573
  *
574
+ * @param postageBatchId Postage Batch ID that will be used to re-upload the data.
498
575
  * @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
499
- * @param options Options that affects the request behavior
500
- * @throws BeeArgumentError if the reference is not locally pinned
501
- * @throws TypeError if some of the input parameters is not expected type
502
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
576
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
503
577
  *
504
578
  * @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
505
579
  */
506
- async reuploadPinnedData(postageBatchId, reference, options) {
580
+ async reuploadPinnedData(postageBatchId, reference, requestOptions) {
507
581
  postageBatchId = new BatchId(postageBatchId);
508
582
  reference = new Reference(reference);
509
- await stewardship.reupload(this.getRequestOptionsForCall(options), postageBatchId, reference);
583
+ await stewardship.reupload(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
510
584
  }
511
585
  /**
512
586
  * Checks if content specified by reference is retrievable from the network.
513
587
  *
514
588
  * @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
515
- * @param options Options that affects the request behavior
516
- * @throws TypeError if some of the input parameters is not expected type
517
- * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
589
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
518
590
  *
519
591
  * @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
520
592
  */
521
- async isReferenceRetrievable(reference, options) {
593
+ async isReferenceRetrievable(reference, requestOptions) {
522
594
  reference = new Reference(reference);
523
- return stewardship.isRetrievable(this.getRequestOptionsForCall(options), reference);
595
+ return stewardship.isRetrievable(this.getRequestOptionsForCall(requestOptions), reference);
524
596
  }
525
597
  /**
526
- * Functions that validates if feed is retrievable in the network.
598
+ * Functions that validate if feed is retrievable in the network.
527
599
  *
528
600
  * If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
529
601
  * sure what is the "latest" update.
@@ -536,6 +608,7 @@ export class Bee {
536
608
  * @param topic
537
609
  * @param index
538
610
  * @param options
611
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
539
612
  */
540
613
  async isFeedRetrievable(owner, topic, index, options, requestOptions) {
541
614
  owner = new EthAddress(owner);
@@ -565,35 +638,32 @@ export class Bee {
565
638
  * most likely for setting up an encrypted communication
566
639
  * channel by sending an one-off message.
567
640
  *
568
- * **Warning! If the recipient Bee node is a light node, then he will never receive the message!**
569
- * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
641
+ * **Warning! Only full nodes can accept PSS messages.**
570
642
  *
571
643
  * @param postageBatchId Postage BatchId that will be assigned to sent message
572
644
  * @param topic Topic name
573
645
  * @param target Target message address prefix. Has a limit on length. Recommend to use `Utils.Pss.makeMaxTarget()` to get the most specific target that Bee node will accept.
574
646
  * @param data Message to be sent
575
647
  * @param recipient Recipient public key
576
- * @param options Options that affects the request behavior
577
- * @throws TypeError if `data`, `batchId`, `target` or `recipient` are in invalid format
648
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
578
649
  *
579
650
  * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
580
651
  * @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
581
652
  */
582
- async pssSend(postageBatchId, topic, target, data, recipient, options) {
653
+ async pssSend(postageBatchId, topic, target, data, recipient, requestOptions) {
583
654
  postageBatchId = new BatchId(postageBatchId);
584
655
  assertData(data);
585
656
  if (recipient) {
586
657
  recipient = new PublicKey(recipient);
587
- return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId, recipient);
658
+ return pss.send(this.getRequestOptionsForCall(requestOptions), topic, target, data, postageBatchId, recipient);
588
659
  } else {
589
- return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId);
660
+ return pss.send(this.getRequestOptionsForCall(requestOptions), topic, target, data, postageBatchId);
590
661
  }
591
662
  }
592
663
  /**
593
- * Subscribe to messages for given topic with Postal Service for Swarm
664
+ * Subscribes to messages for given topic with the Postal Service for Swarm.
594
665
  *
595
- * **Warning! If connected Bee node is a light node, then he will never receive any message!**
596
- * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
666
+ * **Warning! Only full nodes can accept PSS messages.**
597
667
  *
598
668
  * @param topic Topic name
599
669
  * @param handler Message handler interface
@@ -608,16 +678,13 @@ export class Bee {
608
678
  const ws = pss.subscribe(this.url, topic, this.requestOptions.headers);
609
679
  let cancelled = false;
610
680
  const cancel = () => {
611
- if (cancelled === false) {
681
+ if (!cancelled) {
612
682
  cancelled = true;
613
- // although the WebSocket API offers a `close` function, it seems that
614
- // with the library that we are using (isomorphic-ws) it doesn't close
615
- // the websocket properly, whereas `terminate` does
616
683
  if (ws.terminate) {
617
684
  ws.terminate();
618
685
  } else {
619
686
  ws.close();
620
- } // standard Websocket in browser does not have terminate function
687
+ }
621
688
  }
622
689
  };
623
690
  const subscription = {
@@ -631,28 +698,24 @@ export class Bee {
631
698
  }
632
699
  };
633
700
  ws.onerror = event => {
634
- // ignore errors after subscription was cancelled
635
701
  if (!cancelled) {
636
702
  handler.onError(new BeeError(event.message), subscription);
637
703
  }
638
704
  };
705
+ ws.onclose = () => {
706
+ handler.onClose(subscription);
707
+ };
639
708
  return subscription;
640
709
  }
641
710
  /**
642
- * Receive message with Postal Service for Swarm
643
- *
644
- * Because sending a PSS message is slow and CPU intensive,
645
- * it is not supposed to be used for general messaging but
646
- * most likely for setting up an encrypted communication
647
- * channel by sending an one-off message.
711
+ * Receives message using the Postal Service for Swarm.
648
712
  *
649
713
  * This is a helper function to wait for exactly one message to
650
714
  * arrive and then cancel the subscription. Additionally a
651
715
  * timeout can be provided for the message to arrive or else
652
716
  * an error will be thrown.
653
717
  *
654
- * **Warning! If connected Bee node is a light node, then he will never receive any message!**
655
- * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
718
+ * **Warning! Only full nodes can accept PSS messages.**
656
719
  *
657
720
  * @param topic Topic name
658
721
  * @param timeoutMsec Timeout in milliseconds
@@ -678,6 +741,10 @@ export class Bee {
678
741
  clearTimeout(timeout);
679
742
  subscription.cancel();
680
743
  resolve(message);
744
+ },
745
+ onClose: () => {
746
+ clearTimeout(timeout);
747
+ subscription.cancel();
681
748
  }
682
749
  });
683
750
  if (timeoutMsec > 0) {
@@ -688,6 +755,22 @@ export class Bee {
688
755
  }
689
756
  });
690
757
  }
758
+ /**
759
+ * Mines the signer (a private key) to be used to send GSOC messages to the specific target overlay address.
760
+ *
761
+ * Use {@link gsocSend} to send GSOC messages with the mined signer.
762
+ *
763
+ * Use {@link gsocSubscribe} to subscribe to GSOC messages for the specified owner (of the signer) and identifier.
764
+ *
765
+ * See {@link gsocSend} or {@link gsocSubscribe} for concrete examples of usage.
766
+ *
767
+ * **Warning! Only full nodes can accept GSOC messages.**
768
+ *
769
+ * @param targetOverlay
770
+ * @param identifier
771
+ * @param proximity
772
+ * @returns
773
+ */
691
774
  gsocMine(targetOverlay, identifier, proximity = 12) {
692
775
  targetOverlay = new PeerAddress(targetOverlay);
693
776
  identifier = new Identifier(identifier);
@@ -703,14 +786,68 @@ export class Bee {
703
786
  }
704
787
  throw Error('Could not mine a valid signer');
705
788
  }
789
+ /**
790
+ * Sends a GSOC message with the specified signer and identifier.
791
+ *
792
+ * Use {@link gsocMine} to mine a signer for the target overlay address.
793
+ *
794
+ * Use {@link gsocSubscribe} to subscribe to GSOC messages for the specified owner (of the signer) and identifier.
795
+ *
796
+ * **Warning! Only full nodes can accept GSOC messages.**
797
+ *
798
+ * @param postageBatchId
799
+ * @param signer
800
+ * @param identifier
801
+ * @param data
802
+ * @param options
803
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
804
+ * @returns
805
+ *
806
+ * @example
807
+ * const identifier = NULL_IDENTIFIER
808
+ * const overlay = '0x1234567890123456789012345678901234567890'
809
+ * const signer = bee.gsocMine(overlay, identifier)
810
+ * await bee.gsocSend(postageBatchId, signer, identifier, 'GSOC!')
811
+ */
706
812
  async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
707
813
  postageBatchId = new BatchId(postageBatchId);
708
814
  signer = new PrivateKey(signer);
709
815
  identifier = new Identifier(identifier);
710
816
  const cac = makeContentAddressedChunk(data);
711
- const soc = makeSingleOwnerChunk(cac, identifier, signer);
817
+ const soc = cac.toSingleOwnerChunk(identifier, signer);
712
818
  return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
713
819
  }
820
+ /**
821
+ * Subscribes to GSOC messages for the specified owner (of the signer) and identifier.
822
+ *
823
+ * Use {@link gsocMine} to mine a signer for the target overlay address.
824
+ *
825
+ * Use {@link gsocSend} to send GSOC messages with the mined signer.
826
+ *
827
+ * **Warning! Only full nodes can accept GSOC messages.**
828
+ *
829
+ * @param address
830
+ * @param identifier
831
+ * @param handler
832
+ * @returns
833
+ *
834
+ * @example
835
+ * const identifier = NULL_IDENTIFIER
836
+ * const { overlay } = await bee.getNodeAddresses()
837
+ * const signer = bee.gsocMine(overlay, identifier)
838
+ *
839
+ * const subscription = bee.gsocSubscribe(signer.publicKey().address(), identifier, {
840
+ * onMessage(message) {
841
+ * // handle
842
+ * },
843
+ * onError(error) {
844
+ * // handle
845
+ * },
846
+ * onClose() {
847
+ * // handle
848
+ * }
849
+ * })
850
+ */
714
851
  gsocSubscribe(address, identifier, handler) {
715
852
  address = new EthAddress(address);
716
853
  identifier = new Identifier(identifier);
@@ -719,7 +856,7 @@ export class Bee {
719
856
  const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
720
857
  let cancelled = false;
721
858
  const cancel = () => {
722
- if (cancelled === false) {
859
+ if (!cancelled) {
723
860
  cancelled = true;
724
861
  if (ws.terminate) {
725
862
  ws.terminate();
@@ -743,17 +880,21 @@ export class Bee {
743
880
  handler.onError(new BeeError(event.message), subscription);
744
881
  }
745
882
  };
883
+ ws.onclose = () => {
884
+ handler.onClose(subscription);
885
+ };
746
886
  return subscription;
747
887
  }
748
888
  /**
749
- * Create feed manifest chunk and return the reference to it.
889
+ * Creates a feed manifest chunk and returns the reference to it.
750
890
  *
751
- * Feed manifest chunk allows for a feed to be able to be resolved through `/bzz` endpoint.
891
+ * Feed manifest chunks allow for a feed to be able to be resolved through `/bzz` endpoint.
752
892
  *
753
893
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
754
894
  * @param topic Topic in hex or bytes
755
895
  * @param owner Owner's ethereum address in hex or bytes
756
896
  * @param options Options that affects the request behavior
897
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
757
898
  *
758
899
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
759
900
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
@@ -768,101 +909,191 @@ export class Bee {
768
909
  return createFeedManifest(this.getRequestOptionsForCall(requestOptions), owner, topic, postageBatchId, options);
769
910
  }
770
911
  /**
771
- * Make a new feed reader for downloading feed updates.
912
+ * Makes a new feed reader for downloading feed updates.
772
913
  *
773
914
  * @param topic Topic in hex or bytes
774
915
  * @param owner Owner's ethereum address in hex or bytes
775
- * @param options Options that affects the request behavior
916
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
776
917
  *
777
918
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
778
919
  */
779
- makeFeedReader(topic, owner, options) {
920
+ makeFeedReader(topic, owner, requestOptions) {
780
921
  topic = new Topic(topic);
781
922
  owner = new EthAddress(owner);
782
- return makeFeedReader(this.getRequestOptionsForCall(options), topic, owner);
923
+ return makeFeedReader(this.getRequestOptionsForCall(requestOptions), topic, owner);
783
924
  }
784
925
  /**
785
- * Make a new feed writer for updating feeds
926
+ * Makes a new feed writer for updating feeds
786
927
  *
787
928
  * @param topic Topic in hex or bytes
788
929
  * @param signer The signer's private key or a Signer instance that can sign data
789
- * @param options Options that affects the request behavior
930
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
790
931
  *
791
932
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
792
933
  */
793
- makeFeedWriter(topic, signer, options) {
934
+ makeFeedWriter(topic, signer, requestOptions) {
794
935
  topic = new Topic(topic);
795
936
  signer = signer ? new PrivateKey(signer) : this.signer;
796
937
  if (!signer) {
797
938
  throw Error('No signer provided');
798
939
  }
799
- return makeFeedWriter(this.getRequestOptionsForCall(options), topic, signer);
940
+ return makeFeedWriter(this.getRequestOptionsForCall(requestOptions), topic, signer);
800
941
  }
801
942
  async fetchLatestFeedUpdate(topic, owner, requestOptions) {
802
943
  topic = new Topic(topic);
803
944
  owner = new EthAddress(owner);
804
945
  return fetchLatestFeedUpdate(this.getRequestOptionsForCall(requestOptions), owner, topic);
805
946
  }
947
+ /**
948
+ * Creates a Content Addressed Chunk.
949
+ *
950
+ * To be uploaded with the {@link uploadChunk} method.
951
+ *
952
+ * Payload size must be between 1 and 4096 bytes.
953
+ *
954
+ * @param rawPayload Data to be stored in the chunk. If the data is a string, it will be converted to UTF-8 bytes.
955
+ * @param span Optional span for the chunk. If not provided, it will be set to the length of the payload.
956
+ */
957
+ makeContentAddressedChunk(rawPayload, span) {
958
+ return makeContentAddressedChunk(rawPayload, span);
959
+ }
960
+ /**
961
+ * Attempts to unmarshal arbitrary data into a Content Addressed Chunk.
962
+ * Throws an error if the data is not a valid CAC.
963
+ *
964
+ * @param data The chunk data (`span` and `payload`)
965
+ */
966
+ unmarshalContentAddressedChunk(data) {
967
+ return unmarshalContentAddressedChunk(data);
968
+ }
969
+ /**
970
+ * Creates a Single Owner Chunk.
971
+ *
972
+ * To be uploaded with the {@link uploadChunk} method.
973
+ *
974
+ * Identical to chaining `makeContentAddressedChunk` and `toSingleOwnerChunk`.
975
+ *
976
+ * Payload size must be between 1 and 4096 bytes.
977
+ *
978
+ * @param address Address of the Content Addressed Chunk
979
+ * @param span Span of the Content Addressed Chunk
980
+ * @param payload Payload of the Content Addressed Chunk
981
+ * @param identifier The identifier of the chunk
982
+ * @param signer The signer interface for signing the chunk
983
+ */
984
+ makeSingleOwnerChunk(address, span, payload, identifier, signer) {
985
+ return makeSingleOwnerChunk(address, span, payload, identifier, signer);
986
+ }
987
+ /**
988
+ * Calculates the address of a Single Owner Chunk based on its identifier and owner address.
989
+ *
990
+ * @param identifier
991
+ * @param address
992
+ */
993
+ calculateSingleOwnerChunkAddress(identifier, address) {
994
+ return makeSOCAddress(identifier, address);
995
+ }
996
+ /**
997
+ * Attempts to unmarshal arbitrary data into a Single Owner Chunk.
998
+ * Throws an error if the data is not a valid SOC.
999
+ *
1000
+ * @param data The chunk data
1001
+ * @param address The address of the single owner chunk
1002
+ *
1003
+ * @returns a single owner chunk or throws error
1004
+ */
1005
+ unmarshalSingleOwnerChunk(data, address) {
1006
+ return unmarshalSingleOwnerChunk(data, address);
1007
+ }
806
1008
  /**
807
1009
  * Returns an object for reading single owner chunks
808
1010
  *
809
1011
  * @param ownerAddress The ethereum address of the owner
810
- * @param options Options that affects the request behavior
1012
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
811
1013
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
812
1014
  */
813
- makeSOCReader(ownerAddress, options) {
1015
+ makeSOCReader(ownerAddress, requestOptions) {
814
1016
  ownerAddress = new EthAddress(ownerAddress);
815
1017
  return {
816
1018
  owner: ownerAddress,
817
- download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(options), ownerAddress)
1019
+ download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(requestOptions), ownerAddress)
818
1020
  };
819
1021
  }
820
1022
  /**
821
1023
  * Returns an object for reading and writing single owner chunks
822
1024
  *
823
1025
  * @param signer The signer's private key or a Signer instance that can sign data
824
- * @param options Options that affects the request behavior
1026
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
825
1027
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
826
1028
  */
827
- makeSOCWriter(signer, options) {
1029
+ makeSOCWriter(signer, requestOptions) {
828
1030
  signer = signer ? new PrivateKey(signer) : this.signer;
829
1031
  if (!signer) {
830
1032
  throw Error('No signer provided');
831
1033
  }
832
1034
  return {
833
- ...this.makeSOCReader(signer.publicKey().address(), options),
834
- upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), signer)
1035
+ ...this.makeSOCReader(signer.publicKey().address(), requestOptions),
1036
+ upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(requestOptions), signer)
835
1037
  };
836
1038
  }
837
- async createEnvelope(postageBatchId, reference, options) {
1039
+ /**
1040
+ * Creates the postage batch signature for a specific chunk address.
1041
+ *
1042
+ * This is for advanced usage, where a pre-signed chunk can be uploaded
1043
+ * through a different Bee node.
1044
+ *
1045
+ * @param postageBatchId
1046
+ * @param reference
1047
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1048
+ *
1049
+ * @example
1050
+ * const envelope = await bee.createEnvelope(batchId, chunk.address)
1051
+ * await bee.uploadChunk(envelope, chunk)
1052
+ *
1053
+ * @returns
1054
+ */
1055
+ async createEnvelope(postageBatchId, reference, requestOptions) {
838
1056
  postageBatchId = new BatchId(postageBatchId);
839
1057
  reference = new Reference(reference);
840
- return postEnvelope(this.getRequestOptionsForCall(options), postageBatchId, reference);
1058
+ return postEnvelope(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
841
1059
  }
842
1060
  /**
843
- * Get reserve commitment hash duration seconds
1061
+ * Gets reserve commitment hash duration seconds.
1062
+ *
1063
+ * To be able to participe in the storage incentives and not get frozen, this should
1064
+ * ideally run under 5 minutes.
1065
+ *
1066
+ * This is a CPU intensice operation, as roughly 2^22 chunks are hashed in the process.
1067
+ *
1068
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1069
+ *
1070
+ * @example
1071
+ * const addresses = await bee.getNodeAddresses()
1072
+ * const topology = await bee.getTopology()
1073
+ * const result = await bee.rchash(topology.depth, addresses.overlay.toHex(), addresses.overlay.toHex())
1074
+ * // result is a number of seconds
844
1075
  */
845
- async rchash(depth, anchor1, anchor2, options) {
846
- return rchash(this.getRequestOptionsForCall(options), depth, anchor1, anchor2);
1076
+ async rchash(depth, anchor1, anchor2, requestOptions) {
1077
+ return rchash(this.getRequestOptionsForCall(requestOptions), depth, anchor1, anchor2);
847
1078
  }
848
1079
  /**
849
- * Ping the Bee node to see if there is a live Bee node on the given URL.
1080
+ * Pings the Bee node to see if there is a live Bee node on the given URL.
850
1081
  *
851
- * @param options Options that affects the request behavior
1082
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
852
1083
  * @throws If connection was not successful throw error
853
1084
  */
854
- async checkConnection(options) {
855
- return status.checkConnection(this.getRequestOptionsForCall(options));
1085
+ async checkConnection(requestOptions) {
1086
+ return status.checkConnection(this.getRequestOptionsForCall(requestOptions));
856
1087
  }
857
1088
  /**
858
- * Ping the Bee node to see if there is a live Bee node on the given URL.
1089
+ * Pings the Bee node to see if there is a live Bee node on the given URL.
859
1090
  *
860
- * @param options Options that affects the request behavior
1091
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
861
1092
  * @returns true if successful, false on error
862
1093
  */
863
- async isConnected(options) {
1094
+ async isConnected(requestOptions) {
864
1095
  try {
865
- await status.checkConnection(this.getRequestOptionsForCall(options));
1096
+ await status.checkConnection(this.getRequestOptionsForCall(requestOptions));
866
1097
  } catch (e) {
867
1098
  return false;
868
1099
  }
@@ -874,117 +1105,170 @@ export class Bee {
874
1105
  * Do note that this is not a standard way to check for gateway nodes,
875
1106
  * but some of the gateway tooling expose this endpoint.
876
1107
  *
877
- * @param options
1108
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
878
1109
  */
879
- async isGateway(options) {
880
- return status.isGateway(this.getRequestOptionsForCall(options));
1110
+ async isGateway(requestOptions) {
1111
+ return status.isGateway(this.getRequestOptionsForCall(requestOptions));
881
1112
  }
882
- // Legacy debug API
883
- async getNodeAddresses(options) {
884
- return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
1113
+ /**
1114
+ * Fetches the overlay, underlay, Ethereum, and other addresses of the Bee node.
1115
+ *
1116
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1117
+ * @returns
1118
+ */
1119
+ async getNodeAddresses(requestOptions) {
1120
+ return connectivity.getNodeAddresses(this.getRequestOptionsForCall(requestOptions));
885
1121
  }
886
- async getBlocklist(options) {
887
- return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
1122
+ /**
1123
+ * Fetches the list of blocked peers for this node.
1124
+ *
1125
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1126
+ * @returns
1127
+ */
1128
+ async getBlocklist(requestOptions) {
1129
+ return connectivity.getBlocklist(this.getRequestOptionsForCall(requestOptions));
888
1130
  }
889
1131
  /**
890
- * Get list of peers for this node
1132
+ * Gets list of peers for this node.
1133
+ *
1134
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
891
1135
  */
892
- async getPeers(options) {
893
- return connectivity.getPeers(this.getRequestOptionsForCall(options));
1136
+ async getPeers(requestOptions) {
1137
+ return connectivity.getPeers(this.getRequestOptionsForCall(requestOptions));
894
1138
  }
895
- async removePeer(peer, options) {
1139
+ /**
1140
+ * Disconnects from a specific peer.
1141
+ *
1142
+ * @param peer Overlay address of the peer to be removed.
1143
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1144
+ * @returns
1145
+ */
1146
+ async removePeer(peer, requestOptions) {
896
1147
  peer = new PeerAddress(peer);
897
- return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
1148
+ return connectivity.removePeer(this.getRequestOptionsForCall(requestOptions), peer);
898
1149
  }
899
- async getTopology(options) {
900
- return connectivity.getTopology(this.getRequestOptionsForCall(options));
1150
+ /**
1151
+ * Fetches topology and connectivity information of the Bee node.
1152
+ *
1153
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1154
+ * @returns
1155
+ */
1156
+ async getTopology(requestOptions) {
1157
+ return connectivity.getTopology(this.getRequestOptionsForCall(requestOptions));
901
1158
  }
902
- async pingPeer(peer, options) {
1159
+ /**
1160
+ * Pings a specific peer to check its availability.
1161
+ *
1162
+ * @param peer Overlay address of the peer to be pinged.
1163
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1164
+ * @returns
1165
+ */
1166
+ async pingPeer(peer, requestOptions) {
903
1167
  peer = new PeerAddress(peer);
904
- return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
1168
+ return connectivity.pingPeer(this.getRequestOptionsForCall(requestOptions), peer);
905
1169
  }
906
- /*
907
- * Balance endpoints
908
- */
909
1170
  /**
910
- * Get the balances with all known peers including prepaid services
1171
+ * Gets the SWAP balances with all known peers including prepaid services.
1172
+ *
1173
+ * This is related to the bandwidth incentives and the chequebook.
1174
+ *
1175
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
911
1176
  */
912
- async getAllBalances(options) {
913
- return balance.getAllBalances(this.getRequestOptionsForCall(options));
1177
+ async getAllBalances(requestOptions) {
1178
+ return balance.getAllBalances(this.getRequestOptionsForCall(requestOptions));
914
1179
  }
915
1180
  /**
916
- * Get the balances with a specific peer including prepaid services
1181
+ * Gets the SWAP balances for a specific peer including prepaid services.
917
1182
  *
918
1183
  * @param address Swarm address of peer
1184
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
919
1185
  */
920
- async getPeerBalance(address, options) {
1186
+ async getPeerBalance(address, requestOptions) {
921
1187
  address = new PeerAddress(address);
922
- return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
1188
+ return balance.getPeerBalance(this.getRequestOptionsForCall(requestOptions), address);
923
1189
  }
924
1190
  /**
925
- * Get the past due consumption balances with all known peers
1191
+ * Gets the past due consumption balances for all known peers.
1192
+ *
1193
+ * This is related to the bandwidth incentives and the chequebook.
1194
+ *
1195
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
926
1196
  */
927
- async getPastDueConsumptionBalances(options) {
928
- return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
1197
+ async getPastDueConsumptionBalances(requestOptions) {
1198
+ return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(requestOptions));
929
1199
  }
930
1200
  /**
931
- * Get the past due consumption balance with a specific peer
1201
+ * Gets the past due consumption balance for a specific peer.
1202
+ *
1203
+ * This is related to the bandwidth incentives and the chequebook.
932
1204
  *
933
1205
  * @param address Swarm address of peer
1206
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
934
1207
  */
935
- async getPastDueConsumptionPeerBalance(address, options) {
1208
+ async getPastDueConsumptionPeerBalance(address, requestOptions) {
936
1209
  address = new PeerAddress(address);
937
- return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
1210
+ return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(requestOptions), address);
938
1211
  }
939
- /*
940
- * Chequebook endpoints
941
- */
942
1212
  /**
943
- * Get the address of the chequebook contract used.
1213
+ * Gets the address of the deloyed chequebook.
944
1214
  *
945
- * **Warning:** The address is returned with 0x prefix unlike all other calls.
946
- * https://github.com/ethersphere/bee/issues/1443
1215
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
947
1216
  */
948
- async getChequebookAddress(options) {
949
- return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
1217
+ async getChequebookAddress(requestOptions) {
1218
+ return chequebook.getChequebookAddress(this.getRequestOptionsForCall(requestOptions));
950
1219
  }
951
1220
  /**
952
- * Get the balance of the chequebook
1221
+ * Gets the balance of the chequebook.
1222
+ *
1223
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
953
1224
  */
954
- async getChequebookBalance(options) {
955
- return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
1225
+ async getChequebookBalance(requestOptions) {
1226
+ return chequebook.getChequebookBalance(this.getRequestOptionsForCall(requestOptions));
956
1227
  }
957
1228
  /**
958
- * Get last cheques for all peers
1229
+ * Gets the last cheques for all peers.
1230
+ *
1231
+ * This is related to the bandwidth incentives and the chequebook.
1232
+ *
1233
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
959
1234
  */
960
- async getLastCheques(options) {
961
- return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
1235
+ async getLastCheques(requestOptions) {
1236
+ return chequebook.getLastCheques(this.getRequestOptionsForCall(requestOptions));
962
1237
  }
963
1238
  /**
964
- * Get last cheques for the peer
1239
+ * Gets the last cheques for a specific peer.
965
1240
  *
966
- * @param address Swarm address of peer
1241
+ * This is related to the bandwidth incentives and the chequebook.
1242
+ *
1243
+ * @param address Overlay address of peer.
1244
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
967
1245
  */
968
- async getLastChequesForPeer(address, options) {
1246
+ async getLastChequesForPeer(address, requestOptions) {
969
1247
  address = new PeerAddress(address);
970
- return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
1248
+ return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(requestOptions), address);
971
1249
  }
972
1250
  /**
973
- * Get last cashout action for the peer
1251
+ * Gets the last cashout action for a specific peer.
974
1252
  *
975
- * @param address Swarm address of peer
1253
+ * This is related to the bandwidth incentives and the chequebook.
1254
+ *
1255
+ * @param address Overlay address of peer.
1256
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
976
1257
  */
977
- async getLastCashoutAction(address, options) {
1258
+ async getLastCashoutAction(address, requestOptions) {
978
1259
  address = new PeerAddress(address);
979
- return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
1260
+ return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(requestOptions), address);
980
1261
  }
981
1262
  /**
982
- * Cashout the last cheque for the peer
1263
+ * Cashes out the last cheque for a specific peer.
1264
+ *
1265
+ * This is related to the bandwidth incentives and the chequebook.
983
1266
  *
984
1267
  * @param address Swarm address of peer
985
1268
  * @param options
986
1269
  * @param options.gasPrice Gas price for the cashout transaction in WEI
987
1270
  * @param options.gasLimit Gas limit for the cashout transaction in WEI
1271
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
988
1272
  */
989
1273
  async cashoutLastCheque(address, options, requestOptions) {
990
1274
  address = new PeerAddress(address);
@@ -994,24 +1278,28 @@ export class Bee {
994
1278
  return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
995
1279
  }
996
1280
  /**
997
- * Deposit tokens from node wallet into chequebook
1281
+ * Deposits tokens from the node wallet into the chequebook.
998
1282
  *
999
1283
  * @param amount Amount of tokens to deposit (must be positive integer)
1000
1284
  * @param gasPrice Gas Price in WEI for the transaction call
1285
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1286
+ *
1001
1287
  * @return string Hash of the transaction
1002
1288
  * @deprecated Use `depositBZZToChequebook` instead.
1003
1289
  */
1004
- async depositTokens(amount, gasPrice, options) {
1005
- return this.depositBZZToChequebook(amount, gasPrice, options);
1290
+ async depositTokens(amount, gasPrice, requestOptions) {
1291
+ return this.depositBZZToChequebook(amount, gasPrice, requestOptions);
1006
1292
  }
1007
1293
  /**
1008
- * Deposit tokens from node wallet into chequebook
1294
+ * Deposits tokens from the node wallet into the chequebook.
1009
1295
  *
1010
1296
  * @param amount Amount of tokens to deposit (must be positive integer)
1011
1297
  * @param gasPrice Gas Price in WEI for the transaction call
1298
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1299
+ *
1012
1300
  * @return string Hash of the transaction
1013
1301
  */
1014
- async depositBZZToChequebook(amount, gasPrice, options) {
1302
+ async depositBZZToChequebook(amount, gasPrice, requestOptions) {
1015
1303
  const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
1016
1304
  min: 1n,
1017
1305
  name: 'amount'
@@ -1023,27 +1311,29 @@ export class Bee {
1023
1311
  name: 'gasPrice'
1024
1312
  });
1025
1313
  }
1026
- return chequebook.depositTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
1314
+ return chequebook.depositTokens(this.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
1027
1315
  }
1028
1316
  /**
1029
- * Withdraw tokens from the chequebook to the node wallet
1317
+ * Withdraws tokens from the chequebook to the node wallet.
1030
1318
  *
1031
1319
  * @param amount Amount of tokens to withdraw (must be positive integer)
1032
1320
  * @param gasPrice Gas Price in WEI for the transaction call
1321
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1322
+ *
1033
1323
  * @return string Hash of the transaction
1034
1324
  * @deprecated Use `withdrawBZZFromChequebook` instead.
1035
1325
  */
1036
- async withdrawTokens(amount, gasPrice, options) {
1037
- return this.withdrawBZZFromChequebook(amount, gasPrice, options);
1326
+ async withdrawTokens(amount, gasPrice, requestOptions) {
1327
+ return this.withdrawBZZFromChequebook(amount, gasPrice, requestOptions);
1038
1328
  }
1039
1329
  /**
1040
- * Withdraw tokens from the chequebook to the node wallet
1330
+ * Withdraws tokens from the chequebook to the node wallet.
1041
1331
  *
1042
- * @param amount Amount of tokens to withdraw (must be positive integer)
1043
- * @param gasPrice Gas Price in WEI for the transaction call
1044
- * @return string Hash of the transaction
1332
+ * @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
1333
+ * @param gasPrice Gas Price in WEI for the transaction call.
1334
+ * @return Transaction ID
1045
1335
  */
1046
- async withdrawBZZFromChequebook(amount, gasPrice, options) {
1336
+ async withdrawBZZFromChequebook(amount, gasPrice, requestOptions) {
1047
1337
  // TODO: check BZZ in tests
1048
1338
  const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
1049
1339
  min: 1n,
@@ -1056,67 +1346,95 @@ export class Bee {
1056
1346
  name: 'gasPrice'
1057
1347
  });
1058
1348
  }
1059
- return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
1349
+ return chequebook.withdrawTokens(this.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
1060
1350
  }
1061
- async withdrawBZZToExternalWallet(amount, address, options) {
1351
+ /**
1352
+ * Withdraws BZZ from the node wallet (not chequebook) to a whitelisted external wallet address.
1353
+ *
1354
+ * @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
1355
+ * @param address
1356
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1357
+ * @return Transaction ID
1358
+ */
1359
+ async withdrawBZZToExternalWallet(amount, address, requestOptions) {
1062
1360
  amount = amount instanceof BZZ ? amount : BZZ.fromPLUR(amount);
1063
1361
  address = new EthAddress(address);
1064
- return states.withdrawBZZ(this.getRequestOptionsForCall(options), amount, address);
1362
+ return states.withdrawBZZ(this.getRequestOptionsForCall(requestOptions), amount, address);
1065
1363
  }
1066
- async withdrawDAIToExternalWallet(amount, address, options) {
1364
+ /**
1365
+ * Withdraws DAI from the node wallet (not chequebook) to a whitelisted external wallet address.
1366
+ *
1367
+ * @param amount Amount of DAI tokens to withdraw. If not providing a `DAI` instance, the amount is denoted in wei.
1368
+ * @param address
1369
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1370
+ * @return Transaction ID
1371
+ */
1372
+ async withdrawDAIToExternalWallet(amount, address, requestOptions) {
1067
1373
  amount = amount instanceof DAI ? amount : DAI.fromWei(amount);
1068
1374
  address = new EthAddress(address);
1069
- return states.withdrawDAI(this.getRequestOptionsForCall(options), amount, address);
1375
+ return states.withdrawDAI(this.getRequestOptionsForCall(requestOptions), amount, address);
1070
1376
  }
1071
- /*
1072
- * Settlements endpoint
1073
- */
1074
1377
  /**
1075
- * Get amount of sent and received from settlements with a peer
1378
+ * Gets the amount of sent and received micropayments from settlements with a peer.
1379
+ *
1380
+ * This is related to the bandwidth incentives and the chequebook.
1076
1381
  *
1077
1382
  * @param address Swarm address of peer
1383
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1078
1384
  */
1079
- async getSettlements(address, options) {
1385
+ async getSettlements(address, requestOptions) {
1080
1386
  address = new PeerAddress(address);
1081
- return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
1387
+ return settlements.getSettlements(this.getRequestOptionsForCall(requestOptions), address);
1082
1388
  }
1083
1389
  /**
1084
- * Get settlements with all known peers and total amount sent or received
1390
+ * Gets settlements with all known peers and total amount sent or received.
1391
+ *
1392
+ * This is related to the bandwidth incentives and the chequebook.
1393
+ *
1394
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1085
1395
  */
1086
- async getAllSettlements(options) {
1087
- return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
1396
+ async getAllSettlements(requestOptions) {
1397
+ return settlements.getAllSettlements(this.getRequestOptionsForCall(requestOptions));
1088
1398
  }
1089
1399
  /**
1090
- * Get status of node
1400
+ * Gets the general status of the node.
1401
+ *
1402
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1091
1403
  */
1092
- async getStatus(options) {
1093
- return debugStatus.getDebugStatus(this.getRequestOptionsForCall(options));
1404
+ async getStatus(requestOptions) {
1405
+ return debugStatus.getDebugStatus(this.getRequestOptionsForCall(requestOptions));
1094
1406
  }
1095
1407
  /**
1096
- * Get health of node
1408
+ * Gets the health of the node.
1409
+ *
1410
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1097
1411
  */
1098
- async getHealth(options) {
1099
- return debugStatus.getHealth(this.getRequestOptionsForCall(options));
1412
+ async getHealth(requestOptions) {
1413
+ return debugStatus.getHealth(this.getRequestOptionsForCall(requestOptions));
1100
1414
  }
1101
1415
  /**
1102
- * Get readiness of node
1416
+ * Gets the readiness status of the node.
1417
+ *
1418
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1103
1419
  */
1104
- async getReadiness(options) {
1105
- return debugStatus.getReadiness(this.getRequestOptionsForCall(options));
1420
+ async getReadiness(requestOptions) {
1421
+ return debugStatus.getReadiness(this.getRequestOptionsForCall(requestOptions));
1106
1422
  }
1107
1423
  /**
1108
- * Get mode information of node
1424
+ * Get mode information of node.
1425
+ *
1426
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1109
1427
  */
1110
- async getNodeInfo(options) {
1111
- return debugStatus.getNodeInfo(this.getRequestOptionsForCall(options));
1428
+ async getNodeInfo(requestOptions) {
1429
+ return debugStatus.getNodeInfo(this.getRequestOptionsForCall(requestOptions));
1112
1430
  }
1113
1431
  /**
1114
1432
  * Connects to a node and checks if its version matches with the one that bee-js supports.
1115
1433
  *
1116
- * @param options
1434
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1117
1435
  */
1118
- async isSupportedExactVersion(options) {
1119
- return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(options));
1436
+ async isSupportedExactVersion(requestOptions) {
1437
+ return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(requestOptions));
1120
1438
  }
1121
1439
  /**
1122
1440
  *
@@ -1124,53 +1442,56 @@ export class Bee {
1124
1442
  *
1125
1443
  * This should be the main way how to check compatibility for your app and Bee node.
1126
1444
  *
1127
- * @param options
1445
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1128
1446
  */
1129
- async isSupportedApiVersion(options) {
1130
- return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(options));
1447
+ async isSupportedApiVersion(requestOptions) {
1448
+ return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(requestOptions));
1131
1449
  }
1132
1450
  /**
1133
1451
  * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
1134
1452
  * and versions that bee-js supports (properties prefixed with `supported*`).
1135
1453
  *
1136
- * @param options
1454
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1137
1455
  */
1138
- async getVersions(options) {
1139
- return debugStatus.getVersions(this.getRequestOptionsForCall(options));
1456
+ async getVersions(requestOptions) {
1457
+ return debugStatus.getVersions(this.getRequestOptionsForCall(requestOptions));
1140
1458
  }
1141
1459
  /**
1142
- * Get reserve state
1460
+ * Get reserve state.
1461
+ *
1462
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1143
1463
  */
1144
- async getReserveState(options) {
1145
- return states.getReserveState(this.getRequestOptionsForCall(options));
1464
+ async getReserveState(requestOptions) {
1465
+ return states.getReserveState(this.getRequestOptionsForCall(requestOptions));
1146
1466
  }
1147
1467
  /**
1148
- * Get chain state
1468
+ * Gets chain state.
1469
+ *
1470
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1149
1471
  */
1150
- async getChainState(options) {
1151
- return states.getChainState(this.getRequestOptionsForCall(options));
1472
+ async getChainState(requestOptions) {
1473
+ return states.getChainState(this.getRequestOptionsForCall(requestOptions));
1152
1474
  }
1153
1475
  /**
1154
- * Get wallet balances for DAI and BZZ of the Bee node
1476
+ * Gets DAI and BZZ balances of the Bee node wallet.
1155
1477
  *
1156
- * @param options
1478
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1157
1479
  */
1158
- async getWalletBalance(options) {
1159
- return states.getWalletBalance(this.getRequestOptionsForCall(options));
1480
+ async getWalletBalance(requestOptions) {
1481
+ return states.getWalletBalance(this.getRequestOptionsForCall(requestOptions));
1160
1482
  }
1161
1483
  /**
1162
- * Creates new postage batch from the funds that the node has available in its Ethereum account.
1484
+ * Creates a new postage batch, spending BZZ tokens from the node wallet.
1163
1485
  *
1164
- * For better understanding what each parameter means and what are the optimal values please see
1165
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction#keep-your-data-alive).
1486
+ * Use {@link buyStorage} for a more convenient way to create postage batch.
1166
1487
  *
1167
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
1488
+ * For better understanding what each parameter means and what the optimal values are, see
1489
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction#keep-your-data-alive).
1168
1490
  *
1169
- * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
1170
- * @param depth Logarithm of the number of chunks that can be stamped with the batch.
1491
+ * @param amount TTL parameter - 1 day at the minimum of 24,000 storage price requires an amount of 414,720,000.
1492
+ * @param depth Capacity parameter - 17..255 - depth 17 provides 512MB of theoretical capacity, 18 provides 1GB, 19 provides 2GB, etc.
1171
1493
  * @param options Options for creation of postage batch
1172
- * @throws BeeArgumentError when negative amount or depth is specified
1173
- * @throws TypeError if non-integer value is passed to amount or depth
1494
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1174
1495
  *
1175
1496
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1176
1497
  * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
@@ -1197,6 +1518,23 @@ export class Bee {
1197
1518
  }
1198
1519
  return stamp;
1199
1520
  }
1521
+ /**
1522
+ * A more convenient method to create a postage batch, which is analogous
1523
+ * to buying storage for a certain size and duration on the Swarm network.
1524
+ *
1525
+ * Use {@link getStorageCost} to calculate the cost of creating a postage batch.
1526
+ *
1527
+ * For the low level API, use {@link createPostageBatch}.
1528
+ *
1529
+ * @example const batchId = await bee.buyStorage(Size.fromGigabytes(8), Duration.fromDays(31))
1530
+ * @param size
1531
+ * @param duration
1532
+ * @param options
1533
+ * @param requestOptions
1534
+ * @param encryption
1535
+ * @param erasureCodeLevel
1536
+ * @returns
1537
+ */
1200
1538
  async buyStorage(size, duration, options, requestOptions, encryption, erasureCodeLevel) {
1201
1539
  const chainState = await this.getChainState(requestOptions);
1202
1540
  const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
@@ -1206,61 +1544,159 @@ export class Bee {
1206
1544
  }
1207
1545
  return this.createPostageBatch(amount, depth, options, requestOptions);
1208
1546
  }
1209
- async getStorageCost(size, duration, options, encryption, erasureCodeLevel) {
1210
- const chainState = await this.getChainState(options);
1547
+ /**
1548
+ * Calculates the estimated BZZ cost for creating a postage batch for the given size and duration.
1549
+ *
1550
+ * Use {@link buyStorage} to create a postage batch with the calculated cost.
1551
+ *
1552
+ * @example const bzz = await bee.getStorageCost(Size.fromGigabytes(1), Duration.fromDays(30))
1553
+ *
1554
+ * @param size Size of the data to be stored.
1555
+ * @param duration Duration for which the data should be stored.
1556
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1557
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
1558
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
1559
+ * @returns
1560
+ */
1561
+ async getStorageCost(size, duration, requestOptions, encryption, erasureCodeLevel) {
1562
+ const chainState = await this.getChainState(requestOptions);
1211
1563
  const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1212
1564
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1213
1565
  return getStampCost(depth, amount);
1214
1566
  }
1215
- async extendStorage(postageBatchId, size, duration, options, encryption, erasureCodeLevel) {
1216
- const batch = await this.getPostageBatch(postageBatchId, options);
1567
+ /**
1568
+ * Extends the storage of a postage batch by either increasing its size, duration or both.
1569
+ *
1570
+ * The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
1571
+ *
1572
+ * Use {@link getExtensionCost} to calculate the cost of extending the storage.
1573
+ *
1574
+ * @example
1575
+ * // Increases the size to 8GB (unless it is already at 8GB or higher)
1576
+ * // and extends the duration by 30 days (regardless of the current duration).
1577
+ * await bee.extendStorage(batchId, Size.fromGigabytes(8), Duration.fromDays(30))
1578
+ *
1579
+ * @example
1580
+ * // To increase the duration to a desired date, pass a second parameter to `Duration.fromEndDate`.
1581
+ * // With the second parameter, the duration is set to the difference between the current end date and the desired end date.
1582
+ * const oneMonth = new Date(Date.now() + Dates.days(31))
1583
+ * const batch = await bee.getPostageBatch(batchId)
1584
+ * await bee.extendStorage(batchId, Size.fromGigabytes(8), Duration.fromEndDate(oneMonth, batch.duration.toEndDate()))
1585
+ *
1586
+ * @param postageBatchId Batch ID of the postage batch to extend.
1587
+ * @param size Absolute size to extend the postage batch to.
1588
+ * @param duration Relative duration to extend the postage batch by.
1589
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1590
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
1591
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
1592
+ * @returns
1593
+ */
1594
+ async extendStorage(postageBatchId, size, duration, requestOptions, encryption, erasureCodeLevel) {
1595
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1217
1596
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1218
- const chainState = await this.getChainState(options);
1597
+ const chainState = await this.getChainState(requestOptions);
1219
1598
  const depthDelta = depth - batch.depth;
1220
1599
  const multiplier = depthDelta <= 0 ? 1n : 2n ** BigInt(depthDelta);
1221
1600
  const blockTime = this.network === 'gnosis' ? 5 : 15;
1222
1601
  const additionalAmount = getAmountForDuration(duration, chainState.currentPrice, blockTime);
1223
1602
  const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
1224
- const targetAmount = duration.isZero() ? currentAmount * multiplier : currentAmount + additionalAmount * multiplier;
1603
+ const targetAmount = duration.isZero() ? currentAmount * multiplier : (currentAmount + additionalAmount) * multiplier;
1225
1604
  const amountDelta = targetAmount - currentAmount;
1226
- const transactionId = await this.topUpBatch(batch.batchID, amountDelta, options);
1605
+ const transactionId = await this.topUpBatch(batch.batchID, amountDelta, requestOptions);
1227
1606
  if (depthDelta > 0) {
1228
- return this.diluteBatch(batch.batchID, depth, options);
1607
+ return this.diluteBatch(batch.batchID, depth, requestOptions);
1229
1608
  }
1230
1609
  return transactionId;
1231
1610
  }
1232
- async extendStorageSize(postageBatchId, size, options, encryption, erasureCodeLevel) {
1233
- const chainState = await this.getChainState(options);
1234
- const batch = await this.getPostageBatch(postageBatchId, options);
1611
+ /**
1612
+ * Extends the storage size of a postage batch by increasing its depth.
1613
+ *
1614
+ * Use {@link getSizeExtensionCost} to calculate the cost of extending the size.
1615
+ * Use {@link extendStorage} to extend both size and duration.
1616
+ *
1617
+ * @param postageBatchId
1618
+ * @param size Absolute size to extend the postage batch to.
1619
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1620
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
1621
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
1622
+ * @returns
1623
+ */
1624
+ async extendStorageSize(postageBatchId, size, requestOptions, encryption, erasureCodeLevel) {
1625
+ const chainState = await this.getChainState(requestOptions);
1626
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1235
1627
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1236
1628
  const delta = depth - batch.depth;
1237
1629
  if (delta <= 0) {
1238
1630
  throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
1239
1631
  }
1240
1632
  const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1241
- await this.topUpBatch(batch.batchID, currentAmount * (2n ** BigInt(delta) - 1n) + 1n, options);
1242
- return this.diluteBatch(batch.batchID, depth, options);
1633
+ await this.topUpBatch(batch.batchID, currentAmount * (2n ** BigInt(delta) - 1n) + 1n, requestOptions);
1634
+ return this.diluteBatch(batch.batchID, depth, requestOptions);
1243
1635
  }
1244
- async extendStorageDuration(postageBatchId, duration, options) {
1245
- const batch = await this.getPostageBatch(postageBatchId, options);
1246
- const chainState = await this.getChainState(options);
1636
+ /**
1637
+ * Extends the duration of a postage batch.
1638
+ *
1639
+ * Use {@link getDurationExtensionCost} to calculate the cost of extending the duration.
1640
+ * Use {@link extendStorage} to extend both size and duration.
1641
+ *
1642
+ * @param postageBatchId
1643
+ * @param duration Relative duration to extend the postage batch by.
1644
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1645
+ * @returns
1646
+ */
1647
+ async extendStorageDuration(postageBatchId, duration, requestOptions) {
1648
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1649
+ const chainState = await this.getChainState(requestOptions);
1247
1650
  const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1248
- return this.topUpBatch(batch.batchID, amount, options);
1651
+ return this.topUpBatch(batch.batchID, amount, requestOptions);
1249
1652
  }
1250
- async getExtensionCost(postageBatchId, size, duration, options, encryption, erasureCodeLevel) {
1251
- const batch = await this.getPostageBatch(postageBatchId, options);
1252
- const chainState = await this.getChainState(options);
1653
+ /**
1654
+ * Calculates the cost of extending both the duration and the capacity of a postage batch.
1655
+ *
1656
+ * The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
1657
+ *
1658
+ * Use {@link extendStorage} to extend the the duration and capacity of a postage batch.
1659
+ *
1660
+ * @param postageBatchId
1661
+ * @param size Absolute size to extend the postage batch to.
1662
+ * @param duration Relative duration to extend the postage batch by.
1663
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1664
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
1665
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
1666
+ * @returns
1667
+ */
1668
+ async getExtensionCost(postageBatchId, size, duration, requestOptions, encryption, erasureCodeLevel) {
1669
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1670
+ const chainState = await this.getChainState(requestOptions);
1253
1671
  const blockTime = this.network === 'gnosis' ? 5 : 15;
1254
1672
  const amount = duration.isZero() ? 0n : getAmountForDuration(duration, chainState.currentPrice, blockTime);
1255
1673
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1256
1674
  const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
1257
1675
  const currentCost = getStampCost(batch.depth, currentAmount);
1258
- const newCost = getStampCost(depth, currentAmount + amount);
1676
+ const newCost = getStampCost(Math.max(batch.depth, depth), currentAmount + amount);
1259
1677
  return newCost.minus(currentCost);
1260
1678
  }
1261
- async getSizeExtensionCost(postageBatchId, size, options, encryption, erasureCodeLevel) {
1262
- const batch = await this.getPostageBatch(postageBatchId, options);
1263
- const chainState = await this.getChainState(options);
1679
+ /**
1680
+ * Calculates the cost of extending the size of a postage batch.
1681
+ *
1682
+ * The size is ABSOLUTE, so if the postage batch already equals or is greater than the given size,
1683
+ * the cost will be zero.
1684
+ *
1685
+ * Use {@link extendStorageSize} to extend the size of a postage batch.
1686
+ *
1687
+ * Use {@link getExtensionCost} to get the cost of extending both size and duration.
1688
+ * Use {@link getDurationExtensionCost} to get the cost of extending only the duration.
1689
+ *
1690
+ * @param postageBatchId
1691
+ * @param size
1692
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1693
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
1694
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
1695
+ * @returns
1696
+ */
1697
+ async getSizeExtensionCost(postageBatchId, size, requestOptions, encryption, erasureCodeLevel) {
1698
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1699
+ const chainState = await this.getChainState(requestOptions);
1264
1700
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1265
1701
  const delta = depth - batch.depth;
1266
1702
  if (delta <= 0) {
@@ -1271,142 +1707,201 @@ export class Bee {
1271
1707
  const newCost = getStampCost(depth, currentAmount);
1272
1708
  return newCost.minus(currentCost);
1273
1709
  }
1274
- async getDurationExtensionCost(postageBatchId, duration, options) {
1275
- const batch = await this.getPostageBatch(postageBatchId, options);
1276
- const chainState = await this.getChainState(options);
1710
+ /**
1711
+ * Calculates the cost of extending the duration of a postage batch.
1712
+ *
1713
+ * The duration is RELATIVE to the current duration of the postage batch,
1714
+ * e.g. specifying `Duration.fromDays(30)` will extend the current duration by 30 days,
1715
+ * regardless of the current duration.
1716
+ *
1717
+ * Use {@link extendStorageDuration} to extend the duration of a postage batch.
1718
+ *
1719
+ * Use {@link getExtensionCost} to get the cost of extending both size and duration.
1720
+ * Use {@link getSizeExtensionCost} to get the cost of extending only the size.
1721
+ *
1722
+ * @param postageBatchId
1723
+ * @param duration
1724
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1725
+ * @returns
1726
+ */
1727
+ async getDurationExtensionCost(postageBatchId, duration, requestOptions) {
1728
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1729
+ const chainState = await this.getChainState(requestOptions);
1277
1730
  const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1278
1731
  return getStampCost(batch.depth, amount);
1279
1732
  }
1280
1733
  /**
1281
- * Topup a fresh amount of BZZ to given Postage Batch.
1734
+ * Increases the duration of a postage batch by increasing its amount.
1735
+ *
1736
+ * For a more convenient way to extend the postage batch, refer to the methods below.
1737
+ *
1738
+ * Use {@link getDurationExtensionCost}, {@link getSizeExtensionCost} or {@link getExtensionCost}
1739
+ * to calculate the costs of extending the postage batch properties.
1740
+ *
1741
+ * Use {@link extendStorageDuration}, {@link extendStorageSize} or {@link extendStorage}
1742
+ * to extend the postage batch properties.
1282
1743
  *
1283
1744
  * For better understanding what each parameter means and what are the optimal values please see
1284
1745
  * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
1285
1746
  *
1286
1747
  * @param postageBatchId Batch ID
1287
1748
  * @param amount Amount to be added to the batch
1288
- * @param options Request options
1749
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1289
1750
  *
1290
1751
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1291
1752
  * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{batch_id}~1{amount}/patch)
1292
1753
  */
1293
- async topUpBatch(postageBatchId, amount, options) {
1754
+ async topUpBatch(postageBatchId, amount, requestOptions) {
1294
1755
  postageBatchId = new BatchId(postageBatchId);
1295
1756
  const amountString = asNumberString(amount, {
1296
1757
  min: 1n,
1297
1758
  name: 'amount'
1298
1759
  });
1299
- return stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amountString);
1760
+ return stamps.topUpBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, amountString);
1300
1761
  }
1301
1762
  /**
1302
- * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
1303
- * the Postage Batch to be used for more chunks.
1763
+ * Dilutes a postage batch to extend its capacity by increasing its depth.
1764
+ *
1765
+ * This is a free operation, as for every depth increase, the capacity is doubled,
1766
+ * but the amount (duration) is halved.
1767
+ *
1768
+ * To increase the capacity of the postage batch while retaining the same amount (duration),
1769
+ * you need to top up the postage batch first using {@link topUpBatch}.
1770
+ *
1771
+ * For a more convenient way to extend the postage batch, refer to the methods below.
1772
+ *
1773
+ * Use {@link getDurationExtensionCost}, {@link getSizeExtensionCost} or {@link getExtensionCost}
1774
+ * to calculate the costs of extending the postage batch properties.
1775
+ *
1776
+ * Use {@link extendStorageDuration}, {@link extendStorageSize} or {@link extendStorage}
1777
+ * to extend the postage batch properties.
1304
1778
  *
1305
1779
  * For better understanding what each parameter means and what are the optimal values please see
1306
1780
  * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
1307
1781
  *
1308
1782
  * @param postageBatchId Batch ID
1309
1783
  * @param depth Amount to be added to the batch
1310
- * @param options Request options
1784
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1311
1785
  *
1312
1786
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1313
1787
  * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1dilute~1%7Bbatch_id%7D~1%7Bdepth%7D/patch)
1314
1788
  */
1315
- async diluteBatch(postageBatchId, depth, options) {
1789
+ async diluteBatch(postageBatchId, depth, requestOptions) {
1316
1790
  postageBatchId = new BatchId(postageBatchId);
1317
1791
  depth = Types.asNumber(depth, {
1318
1792
  name: 'depth',
1319
1793
  min: 18,
1320
1794
  max: 255
1321
1795
  });
1322
- return stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
1796
+ return stamps.diluteBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, depth);
1323
1797
  }
1324
1798
  /**
1325
- * Return details for specific postage batch.
1799
+ * Returns details for specific postage batch.
1326
1800
  *
1327
1801
  * @param postageBatchId Batch ID
1802
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1803
+ * @param encryption Assume that uploads with this postage batch are encrypted, which skews the capacity.
1804
+ * @param erasureCodeLevel Assume that uploads with this postage batch are erasure coded, which skews the capacity.
1328
1805
  *
1329
1806
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1330
1807
  * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
1331
1808
  */
1332
- async getPostageBatch(postageBatchId, options) {
1809
+ async getPostageBatch(postageBatchId, requestOptions, encryption, erasureCodeLevel) {
1333
1810
  postageBatchId = new BatchId(postageBatchId);
1334
- return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
1811
+ return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, encryption, erasureCodeLevel);
1335
1812
  }
1336
1813
  /**
1337
1814
  * Return detailed information related to buckets for specific postage batch.
1338
1815
  *
1339
1816
  * @param postageBatchId Batch ID
1817
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1340
1818
  *
1341
1819
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1342
1820
  * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D~1buckets/get)
1343
1821
  */
1344
- async getPostageBatchBuckets(postageBatchId, options) {
1822
+ async getPostageBatchBuckets(postageBatchId, requestOptions) {
1345
1823
  postageBatchId = new BatchId(postageBatchId);
1346
- return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
1824
+ return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(requestOptions), postageBatchId);
1347
1825
  }
1348
1826
  /**
1349
- * Return all postage batches that has the node available.
1827
+ * Returns all postage batches that belongs to the node.
1828
+ *
1829
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1350
1830
  *
1351
1831
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1352
1832
  * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
1353
1833
  * @deprecated Use `getPostageBatches` instead
1354
1834
  */
1355
- async getAllPostageBatch(options) {
1356
- return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
1835
+ async getAllPostageBatch(requestOptions) {
1836
+ return stamps.getAllPostageBatches(this.getRequestOptionsForCall(requestOptions)); // TODO: remove in June 2025
1357
1837
  }
1358
1838
  /**
1359
- * Return all globally available postage batches.
1839
+ * Returns all postage batches that are globally available on the Swarm network.
1840
+ *
1841
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1842
+ *
1360
1843
  * @deprecated Use `getGlobalPostageBatches` instead
1361
1844
  */
1362
- async getAllGlobalPostageBatch(options) {
1363
- return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
1845
+ async getAllGlobalPostageBatch(requestOptions) {
1846
+ return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(requestOptions)); // TODO: remove in June 2025
1364
1847
  }
1365
1848
  /**
1366
- * Return all postage batches that belong to the node.
1849
+ * Returns all postage batches that belong to the node.
1850
+ *
1851
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1367
1852
  *
1368
1853
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1369
1854
  * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
1370
1855
  */
1371
- async getPostageBatches(options) {
1372
- return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
1856
+ async getPostageBatches(requestOptions) {
1857
+ return stamps.getAllPostageBatches(this.getRequestOptionsForCall(requestOptions));
1373
1858
  }
1374
1859
  /**
1375
- * Return all globally available postage batches.
1860
+ * Returns all globally available postage batches.
1861
+ *
1862
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1376
1863
  */
1377
- async getGlobalPostageBatches(options) {
1378
- return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
1864
+ async getGlobalPostageBatches(requestOptions) {
1865
+ return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(requestOptions));
1379
1866
  }
1380
1867
  /**
1381
- * Return lists of all current pending transactions that the Bee made
1868
+ * Fetches the list of all current pending transactions for the Bee node.
1869
+ *
1870
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1382
1871
  */
1383
- async getAllPendingTransactions(options) {
1384
- return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
1872
+ async getAllPendingTransactions(requestOptions) {
1873
+ return transactions.getAllTransactions(this.getRequestOptionsForCall(requestOptions));
1385
1874
  }
1386
1875
  /**
1387
- * Return transaction information for specific transaction
1876
+ * Fetches the transaction information for a specific transaction.
1877
+ *
1388
1878
  * @param transactionHash
1879
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1389
1880
  */
1390
- async getPendingTransaction(transactionHash, options) {
1881
+ async getPendingTransaction(transactionHash, requestOptions) {
1391
1882
  transactionHash = new TransactionId(transactionHash);
1392
- return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
1883
+ return transactions.getTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash);
1393
1884
  }
1394
1885
  /**
1395
- * Rebroadcast already created transaction.
1396
- * This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
1886
+ * Rebroadcasts already created transaction.
1887
+ *
1888
+ * This is mainly needed when the transaction falls off mempool or is not incorporated into any block.
1397
1889
  *
1398
1890
  * @param transactionHash
1891
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1399
1892
  */
1400
- async rebroadcastPendingTransaction(transactionHash, options) {
1893
+ async rebroadcastPendingTransaction(transactionHash, requestOptions) {
1401
1894
  transactionHash = new TransactionId(transactionHash);
1402
- return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
1895
+ return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash);
1403
1896
  }
1404
1897
  /**
1405
- * Cancels a currently pending transaction
1898
+ * Cancels a currently pending transaction.
1899
+ *
1406
1900
  * @param transactionHash
1407
1901
  * @param gasPrice
1902
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1408
1903
  */
1409
- async cancelPendingTransaction(transactionHash, gasPrice, options) {
1904
+ async cancelPendingTransaction(transactionHash, gasPrice, requestOptions) {
1410
1905
  transactionHash = new TransactionId(transactionHash);
1411
1906
  let gasPriceString;
1412
1907
  if (gasPrice) {
@@ -1415,43 +1910,43 @@ export class Bee {
1415
1910
  name: 'gasPrice'
1416
1911
  });
1417
1912
  }
1418
- return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPriceString);
1913
+ return transactions.cancelTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash, gasPriceString);
1419
1914
  }
1420
1915
  /**
1421
- * Gets the amount of staked BZZ
1916
+ * Gets the amount of staked BZZ.
1422
1917
  *
1423
- * @param options HTTP request options, such as `headers` or `timeout`
1918
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1424
1919
  */
1425
- async getStake(options) {
1426
- return stake.getStake(this.getRequestOptionsForCall(options));
1920
+ async getStake(requestOptions) {
1921
+ return stake.getStake(this.getRequestOptionsForCall(requestOptions));
1427
1922
  }
1428
1923
  /**
1429
1924
  * Gets the amount of withdrawable staked BZZ.
1430
1925
  *
1431
- * @param options HTTP request options, such as `headers` or `timeout`
1926
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1432
1927
  */
1433
- async getWithdrawableStake(options) {
1434
- return stake.getWithdrawableStake(this.getRequestOptionsForCall(options));
1928
+ async getWithdrawableStake(requestOptions) {
1929
+ return stake.getWithdrawableStake(this.getRequestOptionsForCall(requestOptions));
1435
1930
  }
1436
1931
  /**
1437
- * Withdraws ALL surplus staked BZZ to the node wallet.
1932
+ * Withdraws all surplus staked BZZ to the node wallet.
1438
1933
  *
1439
- * Use the `getWithdrawableStake` method to check how much surplus stake is available.
1934
+ * Use the {@link getWithdrawableStake} method to check how much surplus stake is available.
1440
1935
  *
1441
- * @param options HTTP request options, such as `headers` or `timeout`
1936
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1442
1937
  */
1443
- async withdrawSurplusStake(options) {
1444
- return stake.withdrawSurplusStake(this.getRequestOptionsForCall(options));
1938
+ async withdrawSurplusStake(requestOptions) {
1939
+ return stake.withdrawSurplusStake(this.getRequestOptionsForCall(requestOptions));
1445
1940
  }
1446
1941
  /**
1447
1942
  * Withdraws all staked BZZ to the node wallet.
1448
1943
  *
1449
1944
  * **Only available when the staking contract is paused and is in the process of being migrated to a new contract!**
1450
1945
  *
1451
- * @param options HTTP request options, such as `headers` or `timeout`
1946
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1452
1947
  */
1453
- async migrateStake(options) {
1454
- return stake.migrateStake(this.getRequestOptionsForCall(options));
1948
+ async migrateStake(requestOptions) {
1949
+ return stake.migrateStake(this.getRequestOptionsForCall(requestOptions));
1455
1950
  }
1456
1951
  /**
1457
1952
  * Stakes the given amount of BZZ. Initial deposit must be at least 10 BZZ.
@@ -1459,7 +1954,8 @@ export class Bee {
1459
1954
  * Be aware that staked BZZ tokens can **not** be withdrawn.
1460
1955
  *
1461
1956
  * @param amount Amount of BZZ tokens to be staked. If not providing a `BZZ` instance, the amount is denoted in PLUR.
1462
- * @param options HTTP request options, such as `headers` or `timeout`
1957
+ * @param options
1958
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1463
1959
  */
1464
1960
  async depositStake(amount, options, requestOptions) {
1465
1961
  const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
@@ -1472,12 +1968,14 @@ export class Bee {
1472
1968
  return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
1473
1969
  }
1474
1970
  /**
1475
- * Gets current status of node in redistribution game
1971
+ * Gets current status of node in redistribution game.
1476
1972
  *
1477
- * @param options HTTP request options, such as `headers` or `timeout`
1973
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1974
+ *
1975
+ * @see [Bee API reference - `GET /redistributionstate`](https://docs.ethswarm.org/api/#tag/RedistributionState/paths/~1redistributionstate/get)
1478
1976
  */
1479
- async getRedistributionState(options) {
1480
- return stake.getRedistributionState(this.getRequestOptionsForCall(options));
1977
+ async getRedistributionState(requestOptions) {
1978
+ return stake.getRedistributionState(this.getRequestOptionsForCall(requestOptions));
1481
1979
  }
1482
1980
  async waitForUsablePostageStamp(id, timeout = 240000) {
1483
1981
  const TIME_STEP = 3000;
@@ -1494,10 +1992,10 @@ export class Bee {
1494
1992
  }
1495
1993
  throw new BeeError('Timeout on waiting for postage stamp to become usable');
1496
1994
  }
1497
- getRequestOptionsForCall(options) {
1498
- if (options) {
1499
- options = prepareBeeRequestOptions(options);
1995
+ getRequestOptionsForCall(requestOptions) {
1996
+ if (requestOptions) {
1997
+ requestOptions = prepareBeeRequestOptions(requestOptions);
1500
1998
  }
1501
- return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
1999
+ return requestOptions ? Objects.deepMerge2(this.requestOptions, requestOptions) : this.requestOptions;
1502
2000
  }
1503
2001
  }