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