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