@ethersphere/bee-js 3.2.0 → 3.3.2-pre.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 (193) hide show
  1. package/dist/cjs/bee-debug.js +615 -0
  2. package/dist/cjs/bee.js +922 -0
  3. package/dist/cjs/chunk/bmt.js +55 -0
  4. package/dist/cjs/chunk/cac.js +56 -0
  5. package/dist/cjs/chunk/serialize.js +19 -0
  6. package/dist/cjs/chunk/signer.js +137 -0
  7. package/dist/cjs/chunk/soc.js +172 -0
  8. package/dist/cjs/chunk/span.js +29 -0
  9. package/dist/cjs/feed/index.js +184 -0
  10. package/dist/cjs/feed/json.js +41 -0
  11. package/dist/cjs/feed/topic.js +25 -0
  12. package/dist/cjs/feed/type.js +15 -0
  13. package/dist/cjs/index.js +35 -0
  14. package/dist/cjs/modules/bytes.js +74 -0
  15. package/dist/cjs/modules/bzz.js +131 -0
  16. package/dist/cjs/modules/chunk.js +58 -0
  17. package/dist/cjs/modules/debug/balance.js +77 -0
  18. package/dist/cjs/modules/debug/chequebook.js +167 -0
  19. package/dist/cjs/modules/debug/chunk.js +51 -0
  20. package/dist/cjs/modules/debug/connectivity.js +75 -0
  21. package/dist/cjs/modules/debug/settlements.js +45 -0
  22. package/dist/cjs/modules/debug/stamps.js +89 -0
  23. package/dist/cjs/modules/debug/states.js +47 -0
  24. package/dist/cjs/modules/debug/status.js +153 -0
  25. package/dist/cjs/modules/debug/tag.js +30 -0
  26. package/dist/cjs/modules/debug/transactions.js +81 -0
  27. package/dist/cjs/modules/feed.js +76 -0
  28. package/dist/cjs/modules/pinning.js +84 -0
  29. package/dist/cjs/modules/pss.js +55 -0
  30. package/dist/cjs/modules/soc.js +40 -0
  31. package/dist/cjs/modules/status.js +26 -0
  32. package/dist/cjs/modules/stewardship.js +41 -0
  33. package/dist/cjs/modules/tag.js +96 -0
  34. package/dist/cjs/package.json +8 -0
  35. package/dist/cjs/types/debug.js +9 -0
  36. package/dist/cjs/types/index.js +46 -0
  37. package/dist/cjs/types/ky-options.js +8 -0
  38. package/dist/cjs/types/ky-universal/common.js +8 -0
  39. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  40. package/dist/cjs/types/ky-universal/retry.js +8 -0
  41. package/dist/cjs/utils/bytes.js +107 -0
  42. package/dist/cjs/utils/collection.browser.js +36 -0
  43. package/dist/cjs/utils/collection.js +70 -0
  44. package/dist/cjs/utils/collection.node.js +115 -0
  45. package/dist/cjs/utils/data.browser.js +78 -0
  46. package/dist/cjs/utils/data.js +60 -0
  47. package/dist/cjs/utils/error.js +50 -0
  48. package/dist/cjs/utils/eth.js +211 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +49 -0
  51. package/dist/cjs/utils/hash.js +21 -0
  52. package/dist/cjs/utils/headers.js +59 -0
  53. package/dist/cjs/utils/hex.js +150 -0
  54. package/dist/cjs/utils/http.js +166 -0
  55. package/dist/cjs/utils/merge.js +34 -0
  56. package/dist/cjs/utils/pss.js +18 -0
  57. package/dist/cjs/utils/stamps.js +17 -0
  58. package/dist/cjs/utils/stream.js +146 -0
  59. package/dist/cjs/utils/tar.js +25 -0
  60. package/dist/cjs/utils/type.js +327 -0
  61. package/dist/cjs/utils/uint64.js +29 -0
  62. package/dist/cjs/utils/url.js +56 -0
  63. package/dist/index.browser.min.js +1 -1
  64. package/dist/index.browser.min.js.LICENSE.txt +12 -11
  65. package/dist/index.browser.min.js.map +1 -1
  66. package/dist/mjs/bee-debug.js +609 -0
  67. package/dist/mjs/bee.js +944 -0
  68. package/dist/mjs/chunk/bmt.js +56 -0
  69. package/dist/mjs/chunk/cac.js +52 -0
  70. package/dist/mjs/chunk/serialize.js +15 -0
  71. package/dist/mjs/chunk/signer.js +131 -0
  72. package/dist/mjs/chunk/soc.js +139 -0
  73. package/dist/mjs/chunk/span.js +28 -0
  74. package/dist/mjs/feed/index.js +145 -0
  75. package/dist/mjs/feed/json.js +27 -0
  76. package/dist/mjs/feed/topic.js +21 -0
  77. package/dist/mjs/feed/type.js +10 -0
  78. package/dist/mjs/index.js +7 -0
  79. package/dist/mjs/modules/bytes.js +59 -0
  80. package/dist/mjs/modules/bzz.js +122 -0
  81. package/dist/mjs/modules/chunk.js +45 -0
  82. package/dist/mjs/modules/debug/balance.js +57 -0
  83. package/dist/mjs/modules/debug/chequebook.js +150 -0
  84. package/dist/mjs/modules/debug/chunk.js +35 -0
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +29 -0
  87. package/dist/mjs/modules/debug/stamps.js +64 -0
  88. package/dist/mjs/modules/debug/states.js +31 -0
  89. package/dist/mjs/modules/debug/status.js +134 -0
  90. package/dist/mjs/modules/debug/tag.js +16 -0
  91. package/dist/mjs/modules/debug/transactions.js +63 -0
  92. package/dist/mjs/modules/feed.js +67 -0
  93. package/dist/mjs/modules/pinning.js +66 -0
  94. package/dist/mjs/modules/pss.js +40 -0
  95. package/dist/mjs/modules/soc.js +31 -0
  96. package/dist/mjs/modules/status.js +12 -0
  97. package/dist/mjs/modules/stewardship.js +24 -0
  98. package/dist/mjs/modules/tag.js +77 -0
  99. package/dist/mjs/package.json +8 -0
  100. package/dist/mjs/types/debug.js +7 -0
  101. package/dist/mjs/types/index.js +37 -0
  102. package/dist/mjs/types/ky-options.js +7 -0
  103. package/dist/mjs/types/ky-universal/common.js +7 -0
  104. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  105. package/dist/mjs/types/ky-universal/retry.js +7 -0
  106. package/dist/mjs/utils/bytes.js +101 -0
  107. package/dist/mjs/utils/collection.browser.js +19 -0
  108. package/dist/mjs/utils/collection.js +64 -0
  109. package/dist/mjs/utils/collection.node.js +74 -0
  110. package/dist/mjs/utils/data.browser.js +73 -0
  111. package/dist/mjs/utils/data.js +43 -0
  112. package/dist/mjs/utils/error.js +56 -0
  113. package/dist/mjs/utils/eth.js +199 -0
  114. package/dist/mjs/utils/expose.js +9 -0
  115. package/dist/mjs/utils/file.js +36 -0
  116. package/dist/mjs/utils/hash.js +17 -0
  117. package/dist/mjs/utils/headers.js +58 -0
  118. package/dist/mjs/utils/hex.js +154 -0
  119. package/dist/mjs/utils/http.js +155 -0
  120. package/dist/mjs/utils/merge.js +36 -0
  121. package/dist/mjs/utils/pss.js +16 -0
  122. package/dist/mjs/utils/stamps.js +17 -0
  123. package/dist/mjs/utils/stream.js +156 -0
  124. package/dist/mjs/utils/tar.js +21 -0
  125. package/dist/mjs/utils/type.js +336 -0
  126. package/dist/mjs/utils/uint64.js +23 -0
  127. package/dist/mjs/utils/url.js +57 -0
  128. package/dist/{src → types}/bee-debug.d.ts +47 -1
  129. package/dist/{src → types}/bee.d.ts +0 -0
  130. package/dist/{src → types}/chunk/bmt.d.ts +0 -0
  131. package/dist/{src → types}/chunk/cac.d.ts +0 -0
  132. package/dist/{src → types}/chunk/serialize.d.ts +0 -0
  133. package/dist/{src → types}/chunk/signer.d.ts +0 -0
  134. package/dist/{src → types}/chunk/soc.d.ts +0 -0
  135. package/dist/{src → types}/chunk/span.d.ts +0 -0
  136. package/dist/{src → types}/feed/index.d.ts +0 -0
  137. package/dist/{src → types}/feed/json.d.ts +0 -0
  138. package/dist/{src → types}/feed/topic.d.ts +0 -0
  139. package/dist/{src → types}/feed/type.d.ts +0 -0
  140. package/dist/{src → types}/index.d.ts +0 -0
  141. package/dist/{src → types}/modules/bytes.d.ts +0 -0
  142. package/dist/{src → types}/modules/bzz.d.ts +0 -0
  143. package/dist/{src → types}/modules/chunk.d.ts +0 -0
  144. package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
  145. package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
  146. package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
  147. package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
  148. package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
  149. package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
  150. package/dist/{src → types}/modules/debug/states.d.ts +0 -0
  151. package/dist/types/modules/debug/status.d.ts +72 -0
  152. package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
  153. package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
  154. package/dist/{src → types}/modules/feed.d.ts +0 -0
  155. package/dist/{src → types}/modules/pinning.d.ts +0 -0
  156. package/dist/{src → types}/modules/pss.d.ts +0 -0
  157. package/dist/{src → types}/modules/soc.d.ts +0 -0
  158. package/dist/{src → types}/modules/status.d.ts +0 -0
  159. package/dist/{src → types}/modules/stewardship.d.ts +0 -0
  160. package/dist/{src → types}/modules/tag.d.ts +0 -0
  161. package/dist/{src → types}/types/debug.d.ts +8 -0
  162. package/dist/{src → types}/types/index.d.ts +3 -2
  163. package/dist/types/types/ky-options.d.ts +221 -0
  164. package/dist/types/types/ky-universal/common.d.ts +13 -0
  165. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  166. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  167. package/dist/{src → types}/utils/bytes.d.ts +0 -0
  168. package/dist/types/utils/collection.browser.d.ts +15 -0
  169. package/dist/{src → types}/utils/collection.d.ts +0 -14
  170. package/dist/types/utils/collection.node.d.ts +15 -0
  171. package/dist/{src → types}/utils/data.browser.d.ts +0 -0
  172. package/dist/{src → types}/utils/data.d.ts +0 -0
  173. package/dist/{src → types}/utils/error.d.ts +0 -0
  174. package/dist/{src → types}/utils/eth.d.ts +0 -0
  175. package/dist/{src → types}/utils/expose.d.ts +2 -1
  176. package/dist/{src → types}/utils/file.d.ts +0 -0
  177. package/dist/{src → types}/utils/hash.d.ts +0 -0
  178. package/dist/{src → types}/utils/headers.d.ts +0 -0
  179. package/dist/{src → types}/utils/hex.d.ts +0 -0
  180. package/dist/{src → types}/utils/http.d.ts +0 -0
  181. package/dist/{src → types}/utils/merge.d.ts +0 -0
  182. package/dist/{src → types}/utils/pss.d.ts +0 -0
  183. package/dist/{src → types}/utils/stamps.d.ts +0 -0
  184. package/dist/{src → types}/utils/stream.d.ts +11 -8
  185. package/dist/{src → types}/utils/tar.d.ts +0 -0
  186. package/dist/{src → types}/utils/type.d.ts +0 -0
  187. package/dist/{src → types}/utils/uint64.d.ts +0 -0
  188. package/dist/{src → types}/utils/url.d.ts +0 -0
  189. package/package.json +55 -36
  190. package/dist/index.min.js +0 -3
  191. package/dist/index.min.js.LICENSE.txt +0 -50
  192. package/dist/index.min.js.map +0 -1
  193. package/dist/src/modules/debug/status.d.ts +0 -24
@@ -0,0 +1,944 @@
1
+ import * as bzz from "./modules/bzz.js";
2
+ import * as stewardship from "./modules/stewardship.js";
3
+ import * as tag from "./modules/tag.js";
4
+ import * as pinning from "./modules/pinning.js";
5
+ import * as bytes from "./modules/bytes.js";
6
+ import * as chunk from "./modules/chunk.js";
7
+ import * as pss from "./modules/pss.js";
8
+ import * as status from "./modules/status.js";
9
+ import { BeeArgumentError, BeeError } from "./utils/error.js";
10
+ import { prepareWebsocketData } from "./utils/data.js";
11
+ import { fileArrayBuffer, isFile } from "./utils/file.js";
12
+ import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
13
+ import { makeSigner } from "./chunk/signer.js";
14
+ import { assertFeedType, DEFAULT_FEED_TYPE } from "./feed/type.js";
15
+ import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
16
+ import { makeTopic, makeTopicFromString } from "./feed/topic.js";
17
+ import { createFeedManifest } from "./modules/feed.js";
18
+ import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
19
+ import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
20
+ import { wrapBytesWithHelpers } from "./utils/bytes.js";
21
+ import { assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertRequestOptions, assertUploadOptions, makeTagUid } from "./utils/type.js";
22
+ import { setJsonData, getJsonData } from "./feed/json.js";
23
+ import { makeCollectionFromFileList, assertCollection } from "./utils/collection.js";
24
+ import { makeCollectionFromFS } from "./utils/collection.node.js";
25
+ import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
26
+ import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
27
+ import { isReadable } from "./utils/stream.js";
28
+ /**
29
+ * The main component that abstracts operations available on the main Bee API.
30
+ *
31
+ * Not all methods are always available as it depends in what mode is Bee node launched in.
32
+ * For example gateway mode and light node mode has only limited set of endpoints enabled.
33
+ */
34
+
35
+ export class Bee {
36
+ /**
37
+ * URL on which is the main API of Bee node exposed
38
+ */
39
+ url;
40
+ /**
41
+ * Default Signer object used for signing operations, mainly Feeds.
42
+ */
43
+
44
+ signer;
45
+ /**
46
+ * Ky instance that defines connection to Bee node
47
+ * @private
48
+ */
49
+
50
+ ky;
51
+ /**
52
+ * @param url URL on which is the main API of Bee node exposed
53
+ * @param options
54
+ */
55
+
56
+ constructor(url, options) {
57
+ assertBeeUrl(url); // Remove last slash if present, as our endpoint strings starts with `/...`
58
+ // which could lead to double slash in URL to which Bee responds with
59
+ // unnecessary redirects.
60
+
61
+ this.url = stripLastSlash(url);
62
+
63
+ if (options?.signer) {
64
+ this.signer = makeSigner(options.signer);
65
+ }
66
+
67
+ const kyOptions = {
68
+ prefixUrl: this.url,
69
+ timeout: options?.timeout ?? false,
70
+ retry: options?.retry,
71
+ fetch: options?.fetch,
72
+ hooks: {
73
+ beforeRequest: [],
74
+ afterResponse: []
75
+ }
76
+ };
77
+
78
+ if (options?.defaultHeaders) {
79
+ kyOptions.headers = options.defaultHeaders;
80
+ }
81
+
82
+ if (options?.onRequest) {
83
+ kyOptions.hooks.beforeRequest.push(wrapRequestClosure(options.onRequest));
84
+ }
85
+
86
+ if (options?.onResponse) {
87
+ kyOptions.hooks.afterResponse.push(wrapResponseClosure(options.onResponse));
88
+ }
89
+
90
+ this.ky = makeDefaultKy(kyOptions);
91
+ }
92
+ /**
93
+ * Upload data to a Bee node
94
+ *
95
+ * @param postageBatchId Postage BatchId to be used to upload the data with
96
+ * @param data Data to be uploaded
97
+ * @param options Additional options like tag, encryption, pinning, content-type and request options
98
+ *
99
+ * @returns reference is a content hash of the data
100
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
101
+ * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
102
+ */
103
+
104
+
105
+ async uploadData(postageBatchId, data, options) {
106
+ assertBatchId(postageBatchId);
107
+ assertData(data);
108
+ if (options) assertUploadOptions(options);
109
+ return bytes.upload(this.getKy(options), data, postageBatchId, options);
110
+ }
111
+ /**
112
+ * Download data as a byte array
113
+ *
114
+ * @param reference Bee data reference
115
+ * @param options Options that affects the request behavior
116
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
117
+ * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
118
+ */
119
+
120
+
121
+ async downloadData(reference, options) {
122
+ assertRequestOptions(options);
123
+ assertReference(reference);
124
+ return bytes.download(this.getKy(options), reference);
125
+ }
126
+ /**
127
+ * Download data as a Readable stream
128
+ *
129
+ * @param reference Bee data reference
130
+ * @param options Options that affects the request behavior
131
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
132
+ * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
133
+ */
134
+
135
+
136
+ async downloadReadableData(reference, options) {
137
+ assertRequestOptions(options);
138
+ assertReference(reference);
139
+ return bytes.downloadReadable(this.getKy(options), reference);
140
+ }
141
+ /**
142
+ * Upload chunk to a Bee node
143
+ *
144
+ * @param postageBatchId Postage BatchId to be used to upload the chunk with
145
+ * @param data Raw chunk to be uploaded
146
+ * @param options Additional options like tag, encryption, pinning, content-type and request options
147
+ *
148
+ * @returns reference is a content hash of the data
149
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
150
+ * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
151
+ */
152
+
153
+
154
+ async uploadChunk(postageBatchId, data, options) {
155
+ assertBatchId(postageBatchId);
156
+
157
+ if (!(data instanceof Uint8Array)) {
158
+ throw new TypeError('Data has to be Uint8Array instance!');
159
+ }
160
+
161
+ if (data.length < SPAN_SIZE) {
162
+ throw new BeeArgumentError(`Chunk has to have size of at least ${SPAN_SIZE}.`, data);
163
+ }
164
+
165
+ if (data.length > CHUNK_SIZE + SPAN_SIZE) {
166
+ throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
167
+ }
168
+
169
+ if (options) assertUploadOptions(options);
170
+ return chunk.upload(this.getKy(options), data, postageBatchId, options);
171
+ }
172
+ /**
173
+ * Download chunk as a byte array
174
+ *
175
+ * @param reference Bee chunk reference
176
+ * @param options Options that affects the request behavior
177
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
178
+ * @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
179
+ */
180
+
181
+
182
+ async downloadChunk(reference, options) {
183
+ assertRequestOptions(options);
184
+ assertReference(reference);
185
+ return chunk.download(this.getKy(options), reference);
186
+ }
187
+ /**
188
+ * Upload single file to a Bee node.
189
+ *
190
+ * **To make sure that you won't loose critical data it is highly recommended to also
191
+ * locally pin the data with `options.pin = true`**
192
+ *
193
+ * @param postageBatchId Postage BatchId to be used to upload the data with
194
+ * @param data Data or file to be uploaded
195
+ * @param name Optional name of the uploaded file
196
+ * @param options Additional options like tag, encryption, pinning, content-type and request options
197
+ *
198
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
199
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
200
+ * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File/paths/~1bzz/post)
201
+ * @returns reference is a content hash of the file
202
+ */
203
+
204
+
205
+ async uploadFile(postageBatchId, data, name, options) {
206
+ assertBatchId(postageBatchId);
207
+ assertFileData(data);
208
+ if (options) assertFileUploadOptions(options);
209
+
210
+ if (name && typeof name !== 'string') {
211
+ throw new TypeError('name has to be string or undefined!');
212
+ }
213
+
214
+ if (isFile(data)) {
215
+ const fileData = await fileArrayBuffer(data);
216
+ const fileName = name ?? data.name;
217
+ const contentType = data.type;
218
+ const fileOptions = {
219
+ contentType,
220
+ ...options
221
+ };
222
+ return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
223
+ } else if (isReadable(data) && options?.tag && !options.size) {
224
+ // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
225
+ const result = await bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
226
+ await this.updateTag(options.tag, result.reference);
227
+ return result;
228
+ } else {
229
+ return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
230
+ }
231
+ }
232
+ /**
233
+ * Download single file.
234
+ *
235
+ * @param reference Bee file reference
236
+ * @param path If reference points to manifest, then this parameter defines path to the file
237
+ * @param options Options that affects the request behavior
238
+ *
239
+ * @see Data
240
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
241
+ * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
242
+ */
243
+
244
+
245
+ async downloadFile(reference, path = '', options) {
246
+ assertRequestOptions(options);
247
+ assertReference(reference);
248
+ return bzz.downloadFile(this.getKy(options), reference, path);
249
+ }
250
+ /**
251
+ * Download single file as a readable stream
252
+ *
253
+ * @param reference Hash reference to file
254
+ * @param path If reference points to manifest / collections, then this parameter defines path to the file
255
+ * @param options Options that affects the request behavior
256
+ *
257
+ * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
258
+ * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
259
+ */
260
+
261
+
262
+ async downloadReadableFile(reference, path = '', options) {
263
+ assertRequestOptions(options);
264
+ assertReference(reference);
265
+ return bzz.downloadFileReadable(this.getKy(options), reference, path);
266
+ }
267
+ /**
268
+ * Upload collection of files to a Bee node
269
+ *
270
+ * Uses the FileList API from the browser.
271
+ *
272
+ * The returned `UploadResult.tag` might be undefined if called in CORS-enabled environment.
273
+ * This will be fixed upon next Bee release. https://github.com/ethersphere/bee-js/issues/406
274
+ *
275
+ * @param postageBatchId Postage BatchId to be used to upload the data with
276
+ * @param fileList list of files to be uploaded
277
+ * @param options Additional options like tag, encryption, pinning and request options
278
+ *
279
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
280
+ * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
281
+ * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
282
+ */
283
+
284
+
285
+ async uploadFiles(postageBatchId, fileList, options) {
286
+ assertBatchId(postageBatchId);
287
+ if (options) assertCollectionUploadOptions(options);
288
+ const data = await makeCollectionFromFileList(fileList);
289
+ return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
290
+ }
291
+ /**
292
+ * Upload Collection that you can assembly yourself.
293
+ *
294
+ * The returned `UploadResult.tag` might be undefined if called in CORS-enabled environment.
295
+ * This will be fixed upon next Bee release. https://github.com/ethersphere/bee-js/issues/406
296
+ *
297
+ * @param postageBatchId
298
+ * @param collection
299
+ * @param options Collections and request options
300
+ */
301
+
302
+
303
+ async uploadCollection(postageBatchId, collection, options) {
304
+ assertBatchId(postageBatchId);
305
+ assertCollection(collection);
306
+ if (options) assertCollectionUploadOptions(options);
307
+ return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
308
+ }
309
+ /**
310
+ * Upload collection of files.
311
+ *
312
+ * Available only in Node.js as it uses the `fs` module.
313
+ *
314
+ * The returned `UploadResult.tag` might be undefined if called in CORS-enabled environment.
315
+ * This will be fixed upon next Bee release. https://github.com/ethersphere/bee-js/issues/406
316
+ *
317
+ * @param postageBatchId Postage BatchId to be used to upload the data with
318
+ * @param dir the path of the files to be uploaded
319
+ * @param options Additional options like tag, encryption, pinning and request options
320
+ *
321
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
322
+ * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
323
+ * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
324
+ */
325
+
326
+
327
+ async uploadFilesFromDirectory(postageBatchId, dir, options) {
328
+ assertBatchId(postageBatchId);
329
+ if (options) assertCollectionUploadOptions(options);
330
+ const data = await makeCollectionFromFS(dir);
331
+ return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
332
+ }
333
+ /**
334
+ * Create a new Tag which is meant for tracking progres of syncing data across network.
335
+ *
336
+ * **Warning! Not allowed when node is in Gateway mode!**
337
+ *
338
+ * @param options Options that affects the request behavior
339
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
340
+ * @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
341
+ */
342
+
343
+
344
+ async createTag(options) {
345
+ assertRequestOptions(options);
346
+ return tag.createTag(this.getKy(options));
347
+ }
348
+ /**
349
+ * Fetches all tags.
350
+ *
351
+ * The listing is limited by options.limit. So you have to iterate using options.offset to get all tags.
352
+ *
353
+ * **Warning! Not allowed when node is in Gateway mode!**
354
+ *
355
+ * @param options Options that affects the request behavior
356
+ * @throws TypeError if limit or offset are not numbers or undefined
357
+ * @throws BeeArgumentError if limit or offset have invalid options
358
+ *
359
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
360
+ * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
361
+ */
362
+
363
+
364
+ async getAllTags(options) {
365
+ assertRequestOptions(options);
366
+ assertAllTagsOptions(options);
367
+ return tag.getAllTags(this.getKy(options), options?.offset, options?.limit);
368
+ }
369
+ /**
370
+ * Retrieve tag information from Bee node
371
+ *
372
+ * **Warning! Not allowed when node is in Gateway mode!**
373
+ *
374
+ * @param tagUid UID or tag object to be retrieved
375
+ * @param options Options that affects the request behavior
376
+ * @throws TypeError if tagUid is in not correct format
377
+ *
378
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
379
+ * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/get)
380
+ *
381
+ */
382
+
383
+
384
+ async retrieveTag(tagUid, options) {
385
+ assertRequestOptions(options);
386
+ tagUid = makeTagUid(tagUid);
387
+ return tag.retrieveTag(this.getKy(options), tagUid);
388
+ }
389
+ /**
390
+ * Delete Tag
391
+ *
392
+ * **Warning! Not allowed when node is in Gateway mode!**
393
+ *
394
+ * @param tagUid UID or tag object to be retrieved
395
+ * @param options Options that affects the request behavior
396
+ * @throws TypeError if tagUid is in not correct format
397
+ * @throws BeeResponse error if something went wrong on the Bee node side while deleting the tag.
398
+ *
399
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
400
+ * @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
401
+ */
402
+
403
+
404
+ async deleteTag(tagUid, options) {
405
+ assertRequestOptions(options);
406
+ tagUid = makeTagUid(tagUid);
407
+ return tag.deleteTag(this.getKy(options), tagUid);
408
+ }
409
+ /**
410
+ * Update tag's total chunks count.
411
+ *
412
+ * This is important if you are uploading individual chunks with a tag. Then upon finishing the final root chunk,
413
+ * you can use this method to update the total chunks count for the tag.
414
+ *
415
+ * **Warning! Not allowed when node is in Gateway mode!**
416
+ *
417
+ * @param tagUid UID or tag object to be retrieved
418
+ * @param reference The root reference that contains all the chunks to be counted
419
+ * @param options Options that affects the request behavior
420
+ * @throws TypeError if tagUid is in not correct format
421
+ * @throws BeeResponse error if something went wrong on the Bee node side while deleting the tag.
422
+ *
423
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
424
+ * @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
425
+ */
426
+
427
+
428
+ async updateTag(tagUid, reference, options) {
429
+ assertReference(reference);
430
+ assertRequestOptions(options);
431
+ tagUid = makeTagUid(tagUid);
432
+ return tag.updateTag(this.getKy(options), tagUid, reference);
433
+ }
434
+ /**
435
+ * Pin local data with given reference
436
+ *
437
+ * **Warning! Not allowed when node is in Gateway mode!**
438
+ *
439
+ * @param reference Data reference
440
+ * @param options Options that affects the request behavior
441
+ * @throws TypeError if reference is in not correct format
442
+ *
443
+ * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
444
+ */
445
+
446
+
447
+ async pin(reference, options) {
448
+ assertRequestOptions(options);
449
+ assertReference(reference);
450
+ return pinning.pin(this.getKy(options), reference);
451
+ }
452
+ /**
453
+ * Unpin local data with given reference
454
+ *
455
+ * **Warning! Not allowed when node is in Gateway mode!**
456
+ *
457
+ * @param reference Data reference
458
+ * @param options Options that affects the request behavior
459
+ * @throws TypeError if reference is in not correct format
460
+ *
461
+ * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
462
+ */
463
+
464
+
465
+ async unpin(reference, options) {
466
+ assertRequestOptions(options);
467
+ assertReference(reference);
468
+ return pinning.unpin(this.getKy(options), reference);
469
+ }
470
+ /**
471
+ * Get list of all locally pinned references
472
+ *
473
+ * **Warning! Not allowed when node is in Gateway mode!**
474
+ *
475
+ * @param options Options that affects the request behavior
476
+ * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
477
+ */
478
+
479
+
480
+ async getAllPins(options) {
481
+ assertRequestOptions(options);
482
+ return pinning.getAllPins(this.getKy(options));
483
+ }
484
+ /**
485
+ * Get pinning status of chunk with given reference
486
+ *
487
+ * **Warning! Not allowed when node is in Gateway mode!**
488
+ *
489
+ * @param reference Bee data reference
490
+ * @param options Options that affects the request behavior
491
+ * @throws TypeError if reference is in not correct format
492
+ *
493
+ * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
494
+ */
495
+
496
+
497
+ async getPin(reference, options) {
498
+ assertRequestOptions(options);
499
+ assertReference(reference);
500
+ return pinning.getPin(this.getKy(options), reference);
501
+ }
502
+ /**
503
+ * Instructs the Bee node to reupload a locally pinned data into the network.
504
+ *
505
+ * @param reference
506
+ * @param options Options that affects the request behavior
507
+ * @throws BeeArgumentError if the reference is not locally pinned
508
+ * @throws TypeError if reference is in not correct format
509
+ *
510
+ * @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
511
+ */
512
+
513
+
514
+ async reuploadPinnedData(reference, options) {
515
+ assertRequestOptions(options);
516
+ assertReference(reference);
517
+ await stewardship.reupload(this.getKy(options), reference);
518
+ }
519
+ /**
520
+ * Checks if content specified by reference is retrievable from the network.
521
+ *
522
+ * @param reference The checked content
523
+ * @param options Options that affects the request behavior
524
+ *
525
+ * @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
526
+ */
527
+
528
+
529
+ async isReferenceRetrievable(reference, options) {
530
+ assertRequestOptions(options);
531
+ assertReference(reference);
532
+ return stewardship.isRetrievable(this.getKy(options), reference);
533
+ }
534
+ /**
535
+ * Send data to recipient or target with Postal Service for Swarm.
536
+ *
537
+ * Because sending a PSS message is slow and CPU intensive,
538
+ * it is not supposed to be used for general messaging but
539
+ * most likely for setting up an encrypted communication
540
+ * channel by sending an one-off message.
541
+ *
542
+ * **Warning! Not allowed when node is in Gateway mode!**
543
+ *
544
+ * **Warning! If the recipient Bee node is a light node, then he will never receive the message!**
545
+ * 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.
546
+ *
547
+ * @param postageBatchId Postage BatchId that will be assigned to sent message
548
+ * @param topic Topic name
549
+ * @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.
550
+ * @param data Message to be sent
551
+ * @param recipient Recipient public key
552
+ * @param options Options that affects the request behavior
553
+ * @throws TypeError if `data`, `batchId`, `target` or `recipient` are in invalid format
554
+ *
555
+ * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
556
+ * @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
557
+ */
558
+
559
+
560
+ async pssSend(postageBatchId, topic, target, data, recipient, options) {
561
+ assertRequestOptions(options);
562
+ assertData(data);
563
+ assertBatchId(postageBatchId);
564
+ assertAddressPrefix(target);
565
+
566
+ if (typeof topic !== 'string') {
567
+ throw new TypeError('topic has to be an string!');
568
+ }
569
+
570
+ if (recipient) {
571
+ assertPublicKey(recipient);
572
+ return pss.send(this.getKy(options), topic, target, data, postageBatchId, recipient);
573
+ } else {
574
+ return pss.send(this.getKy(options), topic, target, data, postageBatchId);
575
+ }
576
+ }
577
+ /**
578
+ * Subscribe to messages for given topic with Postal Service for Swarm
579
+ *
580
+ * **Warning! Not allowed when node is in Gateway mode!**
581
+ *
582
+ * **Warning! If connected Bee node is a light node, then he will never receive any message!**
583
+ * 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.
584
+ *
585
+ * @param topic Topic name
586
+ * @param handler Message handler interface
587
+ *
588
+ * @returns Subscription to a given topic
589
+ *
590
+ * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
591
+ * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
592
+ */
593
+
594
+
595
+ pssSubscribe(topic, handler) {
596
+ assertPssMessageHandler(handler);
597
+
598
+ if (typeof topic !== 'string') {
599
+ throw new TypeError('topic has to be an string!');
600
+ }
601
+
602
+ const ws = pss.subscribe(this.url, topic);
603
+ let cancelled = false;
604
+
605
+ const cancel = () => {
606
+ if (cancelled === false) {
607
+ cancelled = true; // although the WebSocket API offers a `close` function, it seems that
608
+ // with the library that we are using (isomorphic-ws) it doesn't close
609
+ // the websocket properly, whereas `terminate` does
610
+
611
+ if (ws.terminate) ws.terminate();else ws.close(); // standard Websocket in browser does not have terminate function
612
+ }
613
+ };
614
+
615
+ const subscription = {
616
+ topic,
617
+ cancel
618
+ };
619
+
620
+ ws.onmessage = async ev => {
621
+ const data = await prepareWebsocketData(ev.data); // ignore empty messages
622
+
623
+ if (data.length > 0) {
624
+ handler.onMessage(wrapBytesWithHelpers(data), subscription);
625
+ }
626
+ };
627
+
628
+ ws.onerror = ev => {
629
+ // ignore errors after subscription was cancelled
630
+ if (!cancelled) {
631
+ handler.onError(new BeeError(ev.message), subscription);
632
+ }
633
+ };
634
+
635
+ return subscription;
636
+ }
637
+ /**
638
+ * Receive message with Postal Service for Swarm
639
+ *
640
+ * Because sending a PSS message is slow and CPU intensive,
641
+ * it is not supposed to be used for general messaging but
642
+ * most likely for setting up an encrypted communication
643
+ * channel by sending an one-off message.
644
+ *
645
+ * This is a helper function to wait for exactly one message to
646
+ * arrive and then cancel the subscription. Additionally a
647
+ * timeout can be provided for the message to arrive or else
648
+ * an error will be thrown.
649
+ *
650
+ * **Warning! Not allowed when node is in Gateway mode!**
651
+ *
652
+ * **Warning! If connected Bee node is a light node, then he will never receive any message!**
653
+ * 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.
654
+ *
655
+ * @param topic Topic name
656
+ * @param timeoutMsec Timeout in milliseconds
657
+ *
658
+ * @returns Message in byte array
659
+ *
660
+ * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
661
+ * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
662
+ */
663
+
664
+
665
+ async pssReceive(topic, timeoutMsec = 0) {
666
+ if (typeof topic !== 'string') {
667
+ throw new TypeError('topic has to be an string!');
668
+ }
669
+
670
+ if (typeof timeoutMsec !== 'number') {
671
+ throw new TypeError('timeoutMsc parameter has to be a number!');
672
+ }
673
+
674
+ return new Promise((resolve, reject) => {
675
+ let timeout;
676
+ const subscription = this.pssSubscribe(topic, {
677
+ onError: error => {
678
+ clearTimeout(timeout);
679
+ subscription.cancel();
680
+ reject(error.message);
681
+ },
682
+ onMessage: message => {
683
+ clearTimeout(timeout);
684
+ subscription.cancel();
685
+ resolve(message);
686
+ }
687
+ });
688
+
689
+ if (timeoutMsec > 0) {
690
+ // we need to cast the type because Typescript is getting confused with Node.js'
691
+ // alternative type definitions
692
+ timeout = setTimeout(() => {
693
+ subscription.cancel();
694
+ reject(new BeeError('pssReceive timeout'));
695
+ }, timeoutMsec);
696
+ }
697
+ });
698
+ }
699
+ /**
700
+ * Create feed manifest chunk and return the reference to it.
701
+ *
702
+ * Feed manifest chunk allows for a feed to be able to be resolved through `/bzz` endpoint.
703
+ *
704
+ * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
705
+ * @param type The type of the feed, can be 'epoch' or 'sequence'
706
+ * @param topic Topic in hex or bytes
707
+ * @param owner Owner's ethereum address in hex or bytes
708
+ * @param options Options that affects the request behavior
709
+ *
710
+ * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
711
+ * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
712
+ */
713
+
714
+
715
+ async createFeedManifest(postageBatchId, type, topic, owner, options) {
716
+ assertRequestOptions(options);
717
+ assertFeedType(type);
718
+ assertBatchId(postageBatchId);
719
+ const canonicalTopic = makeTopic(topic);
720
+ const canonicalOwner = makeHexEthAddress(owner);
721
+ return createFeedManifest(this.getKy(options), canonicalOwner, canonicalTopic, postageBatchId, {
722
+ type
723
+ });
724
+ }
725
+ /**
726
+ * Make a new feed reader for downloading feed updates.
727
+ *
728
+ * @param type The type of the feed, can be 'epoch' or 'sequence'
729
+ * @param topic Topic in hex or bytes
730
+ * @param owner Owner's ethereum address in hex or bytes
731
+ * @param options Options that affects the request behavior
732
+ *
733
+ * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
734
+ */
735
+
736
+
737
+ makeFeedReader(type, topic, owner, options) {
738
+ assertRequestOptions(options);
739
+ assertFeedType(type);
740
+ const canonicalTopic = makeTopic(topic);
741
+ const canonicalOwner = makeHexEthAddress(owner);
742
+ return makeFeedReader(this.getKy(options), type, canonicalTopic, canonicalOwner);
743
+ }
744
+ /**
745
+ * Make a new feed writer for updating feeds
746
+ *
747
+ * @param type The type of the feed, can be 'epoch' or 'sequence'
748
+ * @param topic Topic in hex or bytes
749
+ * @param signer The signer's private key or a Signer instance that can sign data
750
+ * @param options Options that affects the request behavior
751
+ *
752
+ * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
753
+ */
754
+
755
+
756
+ makeFeedWriter(type, topic, signer, options) {
757
+ assertRequestOptions(options);
758
+ assertFeedType(type);
759
+ const canonicalTopic = makeTopic(topic);
760
+ const canonicalSigner = this.resolveSigner(signer);
761
+ return makeFeedWriter(this.getKy(options), type, canonicalTopic, canonicalSigner);
762
+ }
763
+ /**
764
+ * High-level function that allows you to easily set JSON data to feed.
765
+ * JSON-like data types are supported.
766
+ *
767
+ * The default Signer of Bee instance is used if `options.signer` is not specified.
768
+ * If none of those two is set error is thrown.
769
+ *
770
+ * @param postageBatchId Postage BatchId to be used to upload the data with
771
+ * @param topic Human readable string, that is internally hashed so there are no constrains there.
772
+ * @param data JSON compatible data
773
+ * @param options
774
+ * @param options.signer Custom instance of Signer or string with private key.
775
+ * @param options.type Type of Feed
776
+ *
777
+ * @throws BeeError if `options.signer` is not specified nor the default Signer on Bee's instance is specified.
778
+ *
779
+ * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
780
+ */
781
+
782
+
783
+ async setJsonFeed(postageBatchId, topic, data, options) {
784
+ assertRequestOptions(options, 'JsonFeedOptions');
785
+ assertBatchId(postageBatchId);
786
+ const hashedTopic = this.makeFeedTopic(topic);
787
+ const feedType = options?.type ?? DEFAULT_FEED_TYPE;
788
+ const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, options);
789
+ return setJsonData(this, writer, postageBatchId, data, options);
790
+ }
791
+ /**
792
+ * High-level function that allows you to easily get data from feed.
793
+ * Returned data are parsed using JSON.parse().
794
+ *
795
+ * This method also supports specification of `signer` object passed to constructor. The order of evaluation is:
796
+ * - `options.address`
797
+ * - `options.signer`
798
+ * - `this.signer`
799
+ *
800
+ * At least one of these has to be specified!
801
+ *
802
+ * @param topic Human readable string, that is internally hashed so there are no constrains there.
803
+ * @param options
804
+ * @param options.signer Custom instance of Signer or string with private key. This option is exclusive with `address` option.
805
+ * @param options.address Ethereum address of owner of the feed that signed it. This option is exclusive with `signer` option.
806
+ * @param options.type Type of Feed
807
+ *
808
+ * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
809
+ */
810
+
811
+
812
+ async getJsonFeed(topic, options) {
813
+ assertRequestOptions(options, 'JsonFeedOptions');
814
+ const hashedTopic = this.makeFeedTopic(topic);
815
+ const feedType = options?.type ?? DEFAULT_FEED_TYPE;
816
+
817
+ if (options?.signer && options?.address) {
818
+ throw new BeeError('Both options "signer" and "address" can not be specified at one time!');
819
+ }
820
+
821
+ let address;
822
+
823
+ if (options?.address) {
824
+ address = makeEthAddress(options?.address);
825
+ } else {
826
+ try {
827
+ address = this.resolveSigner(options?.signer).address;
828
+ } catch (e) {
829
+ if (e instanceof BeeError) {
830
+ throw new BeeError('Either address, signer or default signer has to be specified!');
831
+ } else {
832
+ throw e;
833
+ }
834
+ }
835
+ }
836
+
837
+ const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
838
+ return getJsonData(this, reader);
839
+ }
840
+ /**
841
+ * Make a new feed topic from a string
842
+ *
843
+ * Because the topic has to be 32 bytes long this function
844
+ * hashes the input string to create a topic string of arbitrary length.
845
+ *
846
+ * @param topic The input string
847
+ */
848
+
849
+
850
+ makeFeedTopic(topic) {
851
+ return makeTopicFromString(topic);
852
+ }
853
+ /**
854
+ * Returns an object for reading single owner chunks
855
+ *
856
+ * @param ownerAddress The ethereum address of the owner
857
+ * @param options Options that affects the request behavior
858
+ * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/dapps-on-swarm/chunk-types#single-owner-chunks)
859
+ */
860
+
861
+
862
+ makeSOCReader(ownerAddress, options) {
863
+ assertRequestOptions(options);
864
+ const canonicalOwner = makeEthAddress(ownerAddress);
865
+ return {
866
+ owner: makeHexEthAddress(canonicalOwner),
867
+ download: downloadSingleOwnerChunk.bind(null, this.getKy(options), canonicalOwner)
868
+ };
869
+ }
870
+ /**
871
+ * Returns an object for reading and writing single owner chunks
872
+ *
873
+ * @param signer The signer's private key or a Signer instance that can sign data
874
+ * @param options Options that affects the request behavior
875
+ * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/dapps-on-swarm/chunk-types#single-owner-chunks)
876
+ */
877
+
878
+
879
+ makeSOCWriter(signer, options) {
880
+ assertRequestOptions(options);
881
+ const canonicalSigner = this.resolveSigner(signer);
882
+ return { ...this.makeSOCReader(canonicalSigner.address, options),
883
+ upload: uploadSingleOwnerChunkData.bind(null, this.getKy(options), canonicalSigner)
884
+ };
885
+ }
886
+ /**
887
+ * Ping the Bee node to see if there is a live Bee node on the given URL.
888
+ *
889
+ * @param options Options that affects the request behavior
890
+ * @throws If connection was not successful throw error
891
+ */
892
+
893
+
894
+ async checkConnection(options) {
895
+ assertRequestOptions(options, 'PostageBatchOptions');
896
+ return status.checkConnection(this.getKy(options));
897
+ }
898
+ /**
899
+ * Ping the Bee node to see if there is a live Bee node on the given URL.
900
+ *
901
+ * @param options Options that affects the request behavior
902
+ * @returns true if successful, false on error
903
+ */
904
+
905
+
906
+ async isConnected(options) {
907
+ assertRequestOptions(options, 'PostageBatchOptions');
908
+
909
+ try {
910
+ await status.checkConnection(this.getKy(options));
911
+ } catch (e) {
912
+ return false;
913
+ }
914
+
915
+ return true;
916
+ }
917
+ /**
918
+ * @param signer
919
+ * @private
920
+ * @throws BeeError if either no Signer was passed or no default Signer was specified for the instance
921
+ */
922
+
923
+
924
+ resolveSigner(signer) {
925
+ if (signer) {
926
+ return makeSigner(signer);
927
+ }
928
+
929
+ if (this.signer) {
930
+ return this.signer;
931
+ }
932
+
933
+ throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.');
934
+ }
935
+
936
+ getKy(options) {
937
+ if (!options) {
938
+ return this.ky;
939
+ }
940
+
941
+ return this.ky.extend(options);
942
+ }
943
+
944
+ }