@ethersphere/bee-js 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +2 -2
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/src/bee-debug.d.ts +38 -6
  8. package/dist/src/bee.d.ts +34 -46
  9. package/dist/src/modules/chunk.d.ts +2 -10
  10. package/dist/src/modules/debug/stamps.d.ts +2 -0
  11. package/dist/src/modules/debug/status.d.ts +10 -4
  12. package/dist/src/modules/stewardship.d.ts +1 -0
  13. package/dist/src/types/debug.d.ts +11 -0
  14. package/dist/src/types/index.d.ts +6 -7
  15. package/dist/src/utils/bytes.d.ts +1 -1
  16. package/dist/src/utils/expose.d.ts +1 -0
  17. package/dist/src/utils/stamps.d.ts +12 -0
  18. package/package.json +10 -8
  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/CODEOWNERS +0 -1
  35. package/CODE_OF_CONDUCT.md +0 -76
  36. package/commitlint.config.js +0 -3
  37. package/dist/src/modules/stamps.d.ts +0 -4
  38. package/jest-puppeteer.config.js +0 -5
  39. package/jest.config.ts +0 -85
  40. package/src/bee-debug.ts +0 -559
  41. package/src/bee.ts +0 -1070
  42. package/src/chunk/bmt.ts +0 -55
  43. package/src/chunk/cac.ts +0 -79
  44. package/src/chunk/serialize.ts +0 -16
  45. package/src/chunk/signer.ts +0 -141
  46. package/src/chunk/soc.ts +0 -190
  47. package/src/chunk/span.ts +0 -33
  48. package/src/feed/index.ts +0 -217
  49. package/src/feed/json.ts +0 -33
  50. package/src/feed/topic.ts +0 -23
  51. package/src/feed/type.ts +0 -12
  52. package/src/index.ts +0 -24
  53. package/src/modules/bytes.ts +0 -70
  54. package/src/modules/bzz.ts +0 -179
  55. package/src/modules/chunk.ts +0 -69
  56. package/src/modules/debug/balance.ts +0 -63
  57. package/src/modules/debug/chequebook.ts +0 -175
  58. package/src/modules/debug/chunk.ts +0 -39
  59. package/src/modules/debug/connectivity.ts +0 -61
  60. package/src/modules/debug/settlements.ts +0 -33
  61. package/src/modules/debug/stamps.ts +0 -76
  62. package/src/modules/debug/states.ts +0 -35
  63. package/src/modules/debug/status.ts +0 -35
  64. package/src/modules/debug/tag.ts +0 -19
  65. package/src/modules/debug/transactions.ts +0 -79
  66. package/src/modules/feed.ts +0 -105
  67. package/src/modules/pinning.ts +0 -74
  68. package/src/modules/pss.ts +0 -49
  69. package/src/modules/soc.ts +0 -40
  70. package/src/modules/stamps.ts +0 -59
  71. package/src/modules/status.ts +0 -13
  72. package/src/modules/stewardship.ts +0 -18
  73. package/src/modules/tag.ts +0 -83
  74. package/src/types/debug.ts +0 -204
  75. package/src/types/index.ts +0 -566
  76. package/src/types/ky-universal/common.d.ts +0 -17
  77. package/src/types/ky-universal/hooks.d.ts +0 -103
  78. package/src/types/ky-universal/index.d.ts +0 -125
  79. package/src/types/ky-universal/options.d.ts +0 -235
  80. package/src/types/ky-universal/response.d.ts +0 -38
  81. package/src/types/ky-universal/retry.d.ts +0 -39
  82. package/src/types/tar-js.d.ts +0 -1
  83. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  84. package/src/utils/bytes.ts +0 -144
  85. package/src/utils/collection.ts +0 -151
  86. package/src/utils/data.browser.ts +0 -68
  87. package/src/utils/data.ts +0 -48
  88. package/src/utils/error.ts +0 -23
  89. package/src/utils/eth.ts +0 -229
  90. package/src/utils/expose.ts +0 -48
  91. package/src/utils/file.ts +0 -40
  92. package/src/utils/hash.ts +0 -16
  93. package/src/utils/headers.ts +0 -63
  94. package/src/utils/hex.ts +0 -186
  95. package/src/utils/http.ts +0 -141
  96. package/src/utils/merge.ts +0 -34
  97. package/src/utils/pss.ts +0 -16
  98. package/src/utils/stream.ts +0 -146
  99. package/src/utils/tar.ts +0 -30
  100. package/src/utils/type.ts +0 -394
  101. package/src/utils/uint64.ts +0 -31
  102. package/src/utils/url.ts +0 -52
  103. package/test/bee.sh +0 -187
  104. package/test/data/1.txt +0 -1
  105. package/test/data/2.txt +0 -0
  106. package/test/data/empty +0 -0
  107. package/test/data/sub/3.txt +0 -1
  108. package/test/data/sub//303/251 +0 -0
  109. package/test/data/sub//360/237/230/216 +0 -0
  110. package/test/integration/bee-class.browser.spec.ts +0 -272
  111. package/test/integration/bee-class.spec.ts +0 -631
  112. package/test/integration/bee-debug-class.spec.ts +0 -85
  113. package/test/integration/chunk/bmt.spec.ts +0 -33
  114. package/test/integration/chunk/cac.spec.ts +0 -27
  115. package/test/integration/chunk/soc.spec.ts +0 -38
  116. package/test/integration/feed/index.spec.ts +0 -84
  117. package/test/integration/modules/bytes.spec.ts +0 -23
  118. package/test/integration/modules/bzz.spec.ts +0 -265
  119. package/test/integration/modules/chunk.spec.ts +0 -29
  120. package/test/integration/modules/debug/balance.spec.ts +0 -70
  121. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  122. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  123. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  124. package/test/integration/modules/debug/states.spec.ts +0 -34
  125. package/test/integration/modules/debug/status.spec.ts +0 -65
  126. package/test/integration/modules/debug/tag.spec.ts +0 -27
  127. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  128. package/test/integration/modules/feed.spec.ts +0 -61
  129. package/test/integration/modules/pinning.spec.ts +0 -155
  130. package/test/integration/modules/pss.spec.ts +0 -97
  131. package/test/integration/modules/status.spec.ts +0 -10
  132. package/test/integration/modules/stewardship.spec.ts +0 -32
  133. package/test/integration/modules/tag.spec.ts +0 -51
  134. package/test/test-type-sequencer.js +0 -36
  135. package/test/testpage/testpage.html +0 -20
  136. package/test/tests-setup.ts +0 -94
  137. package/test/unit/assertions.ts +0 -460
  138. package/test/unit/bee-class.spec.ts +0 -976
  139. package/test/unit/bee-debug-class.spec.ts +0 -435
  140. package/test/unit/chunk/bmt.spec.ts +0 -16
  141. package/test/unit/chunk/cac.spec.ts +0 -29
  142. package/test/unit/chunk/serialize.spec.ts +0 -24
  143. package/test/unit/chunk/signer.spec.ts +0 -140
  144. package/test/unit/chunk/soc.spec.ts +0 -25
  145. package/test/unit/chunk/span.spec.ts +0 -38
  146. package/test/unit/feed/json.spec.ts +0 -73
  147. package/test/unit/nock.ts +0 -151
  148. package/test/unit/utils/bytes.spec.ts +0 -32
  149. package/test/unit/utils/collection.spec.ts +0 -22
  150. package/test/unit/utils/eth.spec.ts +0 -224
  151. package/test/unit/utils/hex.spec.ts +0 -115
  152. package/test/unit/utils/stream.spec.ts +0 -30
  153. package/test/unit/utils/type.spec.ts +0 -32
  154. package/test/unit/utils/uint64.spec.ts +0 -102
  155. package/test/utils.ts +0 -328
  156. package/tsconfig.json +0 -18
  157. package/tsconfig.test.json +0 -11
  158. package/typedoc.json +0 -7
  159. package/webpack.config.ts +0 -141
package/src/bee.ts DELETED
@@ -1,1070 +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
- async reuploadPinnedData(reference: Reference | string, options?: RequestOptions): Promise<void> {
557
- assertRequestOptions(options)
558
- assertReference(reference)
559
-
560
- await stewardship.reupload(this.getKy(options), reference)
561
- }
562
-
563
- /**
564
- * Send data to recipient or target with Postal Service for Swarm.
565
- *
566
- * Because sending a PSS message is slow and CPU intensive,
567
- * it is not supposed to be used for general messaging but
568
- * most likely for setting up an encrypted communication
569
- * channel by sending an one-off message.
570
- *
571
- * **Warning! Not allowed when node is in Gateway mode!**
572
- *
573
- * **Warning! If the recipient Bee node is a light node, then he will never receive the message!**
574
- * 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.
575
- *
576
- * @param postageBatchId Postage BatchId that will be assigned to sent message
577
- * @param topic Topic name
578
- * @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.
579
- * @param data Message to be sent
580
- * @param recipient Recipient public key
581
- * @param options Options that affects the request behavior
582
- * @throws TypeError if `data`, `batchId`, `target` or `recipient` are in invalid format
583
- *
584
- * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
585
- * @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
586
- */
587
- async pssSend(
588
- postageBatchId: string | BatchId,
589
- topic: string,
590
- target: AddressPrefix,
591
- data: string | Uint8Array,
592
- recipient?: string | PublicKey,
593
- options?: RequestOptions,
594
- ): Promise<void> {
595
- assertRequestOptions(options)
596
- assertData(data)
597
- assertBatchId(postageBatchId)
598
- assertAddressPrefix(target)
599
-
600
- if (typeof topic !== 'string') {
601
- throw new TypeError('topic has to be an string!')
602
- }
603
-
604
- if (recipient) {
605
- assertPublicKey(recipient)
606
-
607
- return pss.send(this.getKy(options), topic, target, data, postageBatchId, recipient)
608
- } else {
609
- return pss.send(this.getKy(options), topic, target, data, postageBatchId)
610
- }
611
- }
612
-
613
- /**
614
- * Subscribe to messages for given topic with Postal Service for Swarm
615
- *
616
- * **Warning! Not allowed when node is in Gateway mode!**
617
- *
618
- * **Warning! If connected Bee node is a light node, then he will never receive any message!**
619
- * 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.
620
- *
621
- * @param topic Topic name
622
- * @param handler Message handler interface
623
- *
624
- * @returns Subscription to a given topic
625
- *
626
- * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
627
- * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
628
- */
629
- pssSubscribe(topic: string, handler: PssMessageHandler): PssSubscription {
630
- assertPssMessageHandler(handler)
631
-
632
- if (typeof topic !== 'string') {
633
- throw new TypeError('topic has to be an string!')
634
- }
635
-
636
- const ws = pss.subscribe(this.url, topic)
637
-
638
- let cancelled = false
639
- const cancel = () => {
640
- if (cancelled === false) {
641
- cancelled = true
642
-
643
- // although the WebSocket API offers a `close` function, it seems that
644
- // with the library that we are using (isomorphic-ws) it doesn't close
645
- // the websocket properly, whereas `terminate` does
646
- if (ws.terminate) ws.terminate()
647
- else ws.close() // standard Websocket in browser does not have terminate function
648
- }
649
- }
650
-
651
- const subscription = {
652
- topic,
653
- cancel,
654
- }
655
-
656
- ws.onmessage = async ev => {
657
- const data = await prepareWebsocketData(ev.data)
658
-
659
- // ignore empty messages
660
- if (data.length > 0) {
661
- handler.onMessage(wrapBytesWithHelpers(data), subscription)
662
- }
663
- }
664
- ws.onerror = ev => {
665
- // ignore errors after subscription was cancelled
666
- if (!cancelled) {
667
- handler.onError(new BeeError(ev.message), subscription)
668
- }
669
- }
670
-
671
- return subscription
672
- }
673
-
674
- /**
675
- * Receive message with Postal Service for Swarm
676
- *
677
- * Because sending a PSS message is slow and CPU intensive,
678
- * it is not supposed to be used for general messaging but
679
- * most likely for setting up an encrypted communication
680
- * channel by sending an one-off message.
681
- *
682
- * This is a helper function to wait for exactly one message to
683
- * arrive and then cancel the subscription. Additionally a
684
- * timeout can be provided for the message to arrive or else
685
- * an error will be thrown.
686
- *
687
- * **Warning! Not allowed when node is in Gateway mode!**
688
- *
689
- * **Warning! If connected Bee node is a light node, then he will never receive any message!**
690
- * 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.
691
- *
692
- * @param topic Topic name
693
- * @param timeoutMsec Timeout in milliseconds
694
- *
695
- * @returns Message in byte array
696
- *
697
- * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
698
- * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
699
- */
700
- async pssReceive(topic: string, timeoutMsec = 0): Promise<Data> {
701
- if (typeof topic !== 'string') {
702
- throw new TypeError('topic has to be an string!')
703
- }
704
-
705
- if (typeof timeoutMsec !== 'number') {
706
- throw new TypeError('timeoutMsc parameter has to be a number!')
707
- }
708
-
709
- return new Promise((resolve, reject) => {
710
- let timeout: number | undefined
711
- const subscription = this.pssSubscribe(topic, {
712
- onError: error => {
713
- clearTimeout(timeout)
714
- subscription.cancel()
715
- reject(error.message)
716
- },
717
- onMessage: message => {
718
- clearTimeout(timeout)
719
- subscription.cancel()
720
- resolve(message)
721
- },
722
- })
723
-
724
- if (timeoutMsec > 0) {
725
- // we need to cast the type because Typescript is getting confused with Node.js'
726
- // alternative type definitions
727
- timeout = setTimeout(() => {
728
- subscription.cancel()
729
- reject(new BeeError('pssReceive timeout'))
730
- }, timeoutMsec) as unknown as number
731
- }
732
- })
733
- }
734
-
735
- /**
736
- * Create feed manifest chunk and return the reference to it.
737
- *
738
- * Feed manifest chunk allows for a feed to be able to be resolved through `/bzz` endpoint.
739
- *
740
- * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
741
- * @param type The type of the feed, can be 'epoch' or 'sequence'
742
- * @param topic Topic in hex or bytes
743
- * @param owner Owner's ethereum address in hex or bytes
744
- * @param options Options that affects the request behavior
745
- *
746
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
747
- * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
748
- */
749
- async createFeedManifest(
750
- postageBatchId: string | BatchId,
751
- type: FeedType,
752
- topic: Topic | Uint8Array | string,
753
- owner: EthAddress | Uint8Array | string,
754
- options?: RequestOptions,
755
- ): Promise<Reference> {
756
- assertRequestOptions(options)
757
- assertFeedType(type)
758
- assertBatchId(postageBatchId)
759
-
760
- const canonicalTopic = makeTopic(topic)
761
- const canonicalOwner = makeHexEthAddress(owner)
762
-
763
- return createFeedManifest(this.getKy(options), canonicalOwner, canonicalTopic, postageBatchId, { type })
764
- }
765
-
766
- /**
767
- * Make a new feed reader for downloading feed updates.
768
- *
769
- * @param type The type of the feed, can be 'epoch' or 'sequence'
770
- * @param topic Topic in hex or bytes
771
- * @param owner Owner's ethereum address in hex or bytes
772
- * @param options Options that affects the request behavior
773
- *
774
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
775
- */
776
- makeFeedReader(
777
- type: FeedType,
778
- topic: Topic | Uint8Array | string,
779
- owner: EthAddress | Uint8Array | string,
780
- options?: RequestOptions,
781
- ): FeedReader {
782
- assertRequestOptions(options)
783
- assertFeedType(type)
784
-
785
- const canonicalTopic = makeTopic(topic)
786
- const canonicalOwner = makeHexEthAddress(owner)
787
-
788
- return makeFeedReader(this.getKy(options), type, canonicalTopic, canonicalOwner)
789
- }
790
-
791
- /**
792
- * Make a new feed writer for updating feeds
793
- *
794
- * @param type The type of the feed, can be 'epoch' or 'sequence'
795
- * @param topic Topic in hex or bytes
796
- * @param signer The signer's private key or a Signer instance that can sign data
797
- * @param options Options that affects the request behavior
798
- *
799
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
800
- */
801
- makeFeedWriter(
802
- type: FeedType,
803
- topic: Topic | Uint8Array | string,
804
- signer?: Signer | Uint8Array | string,
805
- options?: RequestOptions,
806
- ): FeedWriter {
807
- assertRequestOptions(options)
808
- assertFeedType(type)
809
-
810
- const canonicalTopic = makeTopic(topic)
811
- const canonicalSigner = this.resolveSigner(signer)
812
-
813
- return makeFeedWriter(this.getKy(options), type, canonicalTopic, canonicalSigner)
814
- }
815
-
816
- /**
817
- * High-level function that allows you to easily set JSON data to feed.
818
- * JSON-like data types are supported.
819
- *
820
- * The default Signer of Bee instance is used if `options.signer` is not specified.
821
- * If none of those two is set error is thrown.
822
- *
823
- * @param postageBatchId Postage BatchId to be used to upload the data with
824
- * @param topic Human readable string, that is internally hashed so there are no constrains there.
825
- * @param data JSON compatible data
826
- * @param options
827
- * @param options.signer Custom instance of Signer or string with private key.
828
- * @param options.type Type of Feed
829
- *
830
- * @throws BeeError if `options.signer` is not specified nor the default Signer on Bee's instance is specified.
831
- *
832
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
833
- */
834
- async setJsonFeed<T extends AnyJson>(
835
- postageBatchId: string | BatchId,
836
- topic: string,
837
- data: T,
838
- options?: JsonFeedOptions,
839
- ): Promise<Reference> {
840
- assertRequestOptions(options, 'JsonFeedOptions')
841
- assertBatchId(postageBatchId)
842
-
843
- const hashedTopic = this.makeFeedTopic(topic)
844
- const feedType = options?.type ?? DEFAULT_FEED_TYPE
845
- const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, options)
846
-
847
- return setJsonData(this, writer, postageBatchId, data, options)
848
- }
849
-
850
- /**
851
- * High-level function that allows you to easily get data from feed.
852
- * Returned data are parsed using JSON.parse().
853
- *
854
- * This method also supports specification of `signer` object passed to constructor. The order of evaluation is:
855
- * - `options.address`
856
- * - `options.signer`
857
- * - `this.signer`
858
- *
859
- * At least one of these has to be specified!
860
- *
861
- * @param topic Human readable string, that is internally hashed so there are no constrains there.
862
- * @param options
863
- * @param options.signer Custom instance of Signer or string with private key. This option is exclusive with `address` option.
864
- * @param options.address Ethereum address of owner of the feed that signed it. This option is exclusive with `signer` option.
865
- * @param options.type Type of Feed
866
- *
867
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
868
- */
869
- async getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions): Promise<T> {
870
- assertRequestOptions(options, 'JsonFeedOptions')
871
-
872
- const hashedTopic = this.makeFeedTopic(topic)
873
- const feedType = options?.type ?? DEFAULT_FEED_TYPE
874
-
875
- if (options?.signer && options?.address) {
876
- throw new BeeError('Both options "signer" and "address" can not be specified at one time!')
877
- }
878
-
879
- let address: EthAddress
880
-
881
- if (options?.address) {
882
- address = makeEthAddress(options?.address)
883
- } else {
884
- try {
885
- address = this.resolveSigner(options?.signer).address
886
- } catch (e) {
887
- if (e instanceof BeeError) {
888
- throw new BeeError('Either address, signer or default signer has to be specified!')
889
- } else {
890
- throw e
891
- }
892
- }
893
- }
894
-
895
- const reader = this.makeFeedReader(feedType, hashedTopic, address, options)
896
-
897
- return getJsonData(this, reader)
898
- }
899
-
900
- /**
901
- * Make a new feed topic from a string
902
- *
903
- * Because the topic has to be 32 bytes long this function
904
- * hashes the input string to create a topic string of arbitrary length.
905
- *
906
- * @param topic The input string
907
- */
908
- makeFeedTopic(topic: string): Topic {
909
- return makeTopicFromString(topic)
910
- }
911
-
912
- /**
913
- * Returns an object for reading single owner chunks
914
- *
915
- * @param ownerAddress The ethereum address of the owner
916
- * @param options Options that affects the request behavior
917
- * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/dapps-on-swarm/chunk-types#single-owner-chunks)
918
- */
919
- makeSOCReader(ownerAddress: EthAddress | Uint8Array | string, options?: RequestOptions): SOCReader {
920
- assertRequestOptions(options)
921
- const canonicalOwner = makeEthAddress(ownerAddress)
922
-
923
- return {
924
- download: downloadSingleOwnerChunk.bind(null, this.getKy(options), canonicalOwner),
925
- }
926
- }
927
-
928
- /**
929
- * Returns an object for reading and writing single owner chunks
930
- *
931
- * @param signer The signer's private key or a Signer instance that can sign data
932
- * @param options Options that affects the request behavior
933
- * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/dapps-on-swarm/chunk-types#single-owner-chunks)
934
- */
935
- makeSOCWriter(signer?: Signer | Uint8Array | string, options?: RequestOptions): SOCWriter {
936
- assertRequestOptions(options)
937
- const canonicalSigner = this.resolveSigner(signer)
938
-
939
- return {
940
- ...this.makeSOCReader(canonicalSigner.address, options),
941
-
942
- upload: uploadSingleOwnerChunkData.bind(null, this.getKy(options), canonicalSigner),
943
- }
944
- }
945
-
946
- /**
947
- * Creates new postage batch from the funds that the node has available in its Ethereum account.
948
- *
949
- * For better understanding what each parameter means and what are the optimal values please see
950
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
951
- *
952
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
953
- * **Warning! Not allowed when node is in Gateway mode!**
954
- *
955
- * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
956
- * @param depth Logarithm of the number of chunks that can be stamped with the batch.
957
- * @param options Options for creation of postage batch and request options
958
- * @throws BeeArgumentError when negative amount or depth is specified
959
- * @throws TypeError if non-integer value is passed to amount or depth
960
- *
961
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
962
- * @see [Bee API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
963
- * @deprecated Use DebugBee for postage batch management
964
- */
965
- async createPostageBatch(amount: NumberString, depth: number, options?: PostageBatchOptions): Promise<BatchId> {
966
- assertPostageBatchOptions(options)
967
- assertNonNegativeInteger(amount)
968
- assertNonNegativeInteger(depth)
969
-
970
- if (depth < STAMPS_DEPTH_MIN) {
971
- throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth)
972
- }
973
-
974
- if (depth > STAMPS_DEPTH_MAX) {
975
- throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth)
976
- }
977
-
978
- return stamps.createPostageBatch(this.getKy(options), amount, depth, options)
979
- }
980
-
981
- /**
982
- * Return details for specific postage batch.
983
- *
984
- * **Warning! Not allowed when node is in Gateway mode!**
985
- *
986
- * @param postageBatchId Batch ID
987
- * @param options Options that affects the request behavior
988
- *
989
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
990
- * @see [Bee API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
991
- * @deprecated Use DebugBee for postage batch management
992
- */
993
- async getPostageBatch(postageBatchId: BatchId | string, options?: RequestOptions): Promise<PostageBatch> {
994
- assertRequestOptions(options, 'PostageBatchOptions')
995
- assertBatchId(postageBatchId)
996
-
997
- return stamps.getPostageBatch(this.getKy(options), postageBatchId)
998
- }
999
-
1000
- /**
1001
- * Return all postage batches that has the node available.
1002
- *
1003
- * **Warning! Not allowed when node is in Gateway mode!**
1004
- *
1005
- * @param options Options that affects the request behavior
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`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
1008
- * @deprecated Use DebugBee for postage batch management
1009
- */
1010
- async getAllPostageBatch(options?: RequestOptions): Promise<PostageBatch[]> {
1011
- assertRequestOptions(options, 'PostageBatchOptions')
1012
-
1013
- return stamps.getAllPostageBatches(this.getKy(options))
1014
- }
1015
-
1016
- /**
1017
- * Ping the Bee node to see if there is a live Bee node on the given URL.
1018
- *
1019
- * @param options Options that affects the request behavior
1020
- * @throws If connection was not successful throw error
1021
- */
1022
- async checkConnection(options?: RequestOptions): Promise<void> | never {
1023
- assertRequestOptions(options, 'PostageBatchOptions')
1024
-
1025
- return status.checkConnection(this.getKy(options))
1026
- }
1027
-
1028
- /**
1029
- * Ping the Bee node to see if there is a live Bee node on the given URL.
1030
- *
1031
- * @param options Options that affects the request behavior
1032
- * @returns true if successful, false on error
1033
- */
1034
- async isConnected(options?: RequestOptions): Promise<boolean> {
1035
- assertRequestOptions(options, 'PostageBatchOptions')
1036
-
1037
- try {
1038
- await status.checkConnection(this.getKy(options))
1039
- } catch (e) {
1040
- return false
1041
- }
1042
-
1043
- return true
1044
- }
1045
-
1046
- /**
1047
- * @param signer
1048
- * @private
1049
- * @throws BeeError if either no Signer was passed or no default Signer was specified for the instance
1050
- */
1051
- private resolveSigner(signer?: Signer | Uint8Array | string): Signer {
1052
- if (signer) {
1053
- return makeSigner(signer)
1054
- }
1055
-
1056
- if (this.signer) {
1057
- return this.signer
1058
- }
1059
-
1060
- throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.')
1061
- }
1062
-
1063
- private getKy(options?: RequestOptions): Ky {
1064
- if (!options) {
1065
- return this.ky
1066
- }
1067
-
1068
- return this.ky.extend(options)
1069
- }
1070
- }