@ethersphere/bee-js 8.3.0 → 9.0.1

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 (228) hide show
  1. package/README.md +192 -50
  2. package/dist/cjs/bee-dev.js +78 -0
  3. package/dist/cjs/bee.js +341 -417
  4. package/dist/cjs/chunk/bmt.js +15 -32
  5. package/dist/cjs/chunk/cac.js +26 -36
  6. package/dist/cjs/chunk/soc.js +56 -51
  7. package/dist/cjs/feed/identifier.js +3 -28
  8. package/dist/cjs/feed/index.js +95 -44
  9. package/dist/cjs/feed/retrievable.js +11 -22
  10. package/dist/cjs/index.js +17 -1
  11. package/dist/cjs/manifest/manifest.js +369 -0
  12. package/dist/cjs/modules/bytes.js +24 -12
  13. package/dist/cjs/modules/bzz.js +24 -34
  14. package/dist/cjs/modules/chunk.js +13 -7
  15. package/dist/cjs/modules/debug/balance.js +29 -4
  16. package/dist/cjs/modules/debug/chequebook.js +60 -16
  17. package/dist/cjs/modules/debug/connectivity.js +82 -4
  18. package/dist/cjs/modules/debug/settlements.js +22 -2
  19. package/dist/cjs/modules/debug/stake.js +29 -11
  20. package/dist/cjs/modules/debug/stamps.js +88 -7
  21. package/dist/cjs/modules/debug/states.js +25 -3
  22. package/dist/cjs/modules/debug/status.js +45 -47
  23. package/dist/cjs/modules/debug/transactions.js +27 -5
  24. package/dist/cjs/modules/envelope.js +8 -6
  25. package/dist/cjs/modules/feed.js +25 -10
  26. package/dist/cjs/modules/grantee.js +18 -12
  27. package/dist/cjs/modules/gsoc.js +24 -0
  28. package/dist/cjs/modules/pinning.js +13 -2
  29. package/dist/cjs/modules/pss.js +9 -3
  30. package/dist/cjs/modules/soc.js +9 -4
  31. package/dist/cjs/modules/stewardship.js +7 -3
  32. package/dist/cjs/modules/tag.js +35 -3
  33. package/dist/cjs/package.json +1 -0
  34. package/dist/cjs/stamper/stamper.js +43 -0
  35. package/dist/cjs/types/debug.js +16 -1
  36. package/dist/cjs/types/index.js +2 -24
  37. package/dist/cjs/utils/bytes.js +67 -115
  38. package/dist/cjs/utils/chunk-size.js +17 -0
  39. package/dist/cjs/utils/chunk-stream.browser.js +85 -0
  40. package/dist/cjs/utils/chunk-stream.js +84 -0
  41. package/dist/cjs/utils/cid.js +5 -6
  42. package/dist/cjs/utils/collection.browser.js +2 -2
  43. package/dist/cjs/utils/collection.js +3 -2
  44. package/dist/cjs/utils/collection.node.js +0 -2
  45. package/dist/cjs/utils/constants.js +7 -3
  46. package/dist/cjs/utils/data.browser.js +6 -3
  47. package/dist/cjs/utils/data.js +8 -4
  48. package/dist/cjs/utils/duration.js +51 -0
  49. package/dist/cjs/utils/expose.js +11 -40
  50. package/dist/cjs/utils/headers.js +79 -52
  51. package/dist/cjs/utils/http.js +34 -10
  52. package/dist/cjs/utils/mime.js +78 -0
  53. package/dist/cjs/utils/pss.js +3 -4
  54. package/dist/cjs/utils/redundancy.js +18 -14
  55. package/dist/cjs/utils/resource-locator.js +17 -0
  56. package/dist/cjs/utils/size.js +35 -0
  57. package/dist/cjs/utils/stamps.js +67 -51
  58. package/dist/cjs/utils/tar-uploader.browser.js +2 -2
  59. package/dist/cjs/utils/tar-uploader.js +2 -2
  60. package/dist/cjs/utils/tar-writer.js +4 -0
  61. package/dist/cjs/utils/tar.browser.js +1 -1
  62. package/dist/cjs/utils/tokens.js +144 -0
  63. package/dist/cjs/utils/type.js +141 -350
  64. package/dist/cjs/utils/typed-bytes.js +179 -0
  65. package/dist/cjs/utils/upload-progress.js +2 -0
  66. package/dist/cjs/utils/url.js +0 -4
  67. package/dist/cjs/utils/workaround.js +27 -0
  68. package/dist/index.browser.min.js +1 -2
  69. package/dist/index.browser.min.js.map +1 -1
  70. package/dist/mjs/bee-dev.js +98 -0
  71. package/dist/mjs/bee.js +367 -411
  72. package/dist/mjs/chunk/bmt.js +13 -29
  73. package/dist/mjs/chunk/cac.js +26 -34
  74. package/dist/mjs/chunk/soc.js +57 -53
  75. package/dist/mjs/feed/identifier.js +3 -26
  76. package/dist/mjs/feed/index.js +98 -51
  77. package/dist/mjs/feed/retrievable.js +12 -23
  78. package/dist/mjs/index.js +10 -1
  79. package/dist/mjs/manifest/manifest.js +371 -0
  80. package/dist/mjs/modules/bytes.js +27 -15
  81. package/dist/mjs/modules/bzz.js +25 -32
  82. package/dist/mjs/modules/chunk.js +16 -8
  83. package/dist/mjs/modules/debug/balance.js +61 -4
  84. package/dist/mjs/modules/debug/chequebook.js +116 -16
  85. package/dist/mjs/modules/debug/connectivity.js +144 -3
  86. package/dist/mjs/modules/debug/settlements.js +46 -2
  87. package/dist/mjs/modules/debug/stake.js +69 -11
  88. package/dist/mjs/modules/debug/stamps.js +184 -7
  89. package/dist/mjs/modules/debug/states.js +55 -3
  90. package/dist/mjs/modules/debug/status.js +97 -45
  91. package/dist/mjs/modules/debug/transactions.js +61 -5
  92. package/dist/mjs/modules/envelope.js +11 -9
  93. package/dist/mjs/modules/feed.js +26 -10
  94. package/dist/mjs/modules/grantee.js +35 -13
  95. package/dist/mjs/modules/gsoc.js +16 -0
  96. package/dist/mjs/modules/pinning.js +23 -2
  97. package/dist/mjs/modules/pss.js +10 -4
  98. package/dist/mjs/modules/soc.js +10 -5
  99. package/dist/mjs/modules/stewardship.js +14 -4
  100. package/dist/mjs/modules/tag.js +93 -3
  101. package/dist/mjs/package.json +2 -1
  102. package/dist/mjs/stamper/stamper.js +39 -0
  103. package/dist/mjs/types/debug.js +15 -1
  104. package/dist/mjs/types/index.js +2 -24
  105. package/dist/mjs/utils/bytes.js +63 -104
  106. package/dist/mjs/utils/chunk-size.js +13 -0
  107. package/dist/mjs/utils/chunk-stream.browser.js +85 -0
  108. package/dist/mjs/utils/chunk-stream.js +87 -0
  109. package/dist/mjs/utils/cid.js +5 -6
  110. package/dist/mjs/utils/collection.browser.js +2 -2
  111. package/dist/mjs/utils/collection.js +2 -2
  112. package/dist/mjs/utils/collection.node.js +0 -2
  113. package/dist/mjs/utils/constants.js +6 -2
  114. package/dist/mjs/utils/data.browser.js +9 -3
  115. package/dist/mjs/utils/data.js +12 -4
  116. package/dist/mjs/utils/duration.js +47 -0
  117. package/dist/mjs/utils/expose.js +2 -7
  118. package/dist/mjs/utils/headers.js +73 -48
  119. package/dist/mjs/utils/http.js +33 -11
  120. package/dist/mjs/utils/mime.js +75 -0
  121. package/dist/mjs/utils/pss.js +3 -4
  122. package/dist/mjs/utils/redundancy.js +18 -8
  123. package/dist/mjs/utils/resource-locator.js +13 -0
  124. package/dist/mjs/utils/size.js +31 -0
  125. package/dist/mjs/utils/stamps.js +47 -44
  126. package/dist/mjs/utils/tar-uploader.browser.js +2 -2
  127. package/dist/mjs/utils/tar-uploader.js +2 -2
  128. package/dist/mjs/utils/tar-writer.js +3 -0
  129. package/dist/mjs/utils/tar.browser.js +1 -1
  130. package/dist/mjs/utils/tokens.js +139 -0
  131. package/dist/mjs/utils/type.js +215 -310
  132. package/dist/mjs/utils/typed-bytes.js +160 -0
  133. package/dist/mjs/utils/upload-progress.js +1 -0
  134. package/dist/mjs/utils/url.js +0 -4
  135. package/dist/mjs/utils/workaround.js +22 -0
  136. package/dist/types/bee-dev.d.ts +5 -0
  137. package/dist/types/bee.d.ts +88 -165
  138. package/dist/types/chunk/bmt.d.ts +2 -2
  139. package/dist/types/chunk/cac.d.ts +7 -24
  140. package/dist/types/chunk/soc.d.ts +15 -15
  141. package/dist/types/feed/identifier.d.ts +2 -4
  142. package/dist/types/feed/index.d.ts +14 -18
  143. package/dist/types/feed/retrievable.d.ts +3 -4
  144. package/dist/types/index.d.ts +28 -1
  145. package/dist/types/manifest/manifest.d.ts +106 -0
  146. package/dist/types/modules/bytes.d.ts +8 -5
  147. package/dist/types/modules/bzz.d.ts +8 -10
  148. package/dist/types/modules/chunk.d.ts +4 -3
  149. package/dist/types/modules/debug/balance.d.ts +3 -2
  150. package/dist/types/modules/debug/chequebook.d.ts +7 -6
  151. package/dist/types/modules/debug/connectivity.d.ts +5 -3
  152. package/dist/types/modules/debug/settlements.d.ts +2 -1
  153. package/dist/types/modules/debug/stake.d.ts +4 -2
  154. package/dist/types/modules/debug/stamps.d.ts +5 -4
  155. package/dist/types/modules/debug/status.d.ts +6 -25
  156. package/dist/types/modules/debug/transactions.d.ts +5 -4
  157. package/dist/types/modules/envelope.d.ts +3 -2
  158. package/dist/types/modules/feed.d.ts +20 -16
  159. package/dist/types/modules/grantee.d.ts +7 -6
  160. package/dist/types/modules/gsoc.d.ts +7 -0
  161. package/dist/types/modules/pinning.d.ts +2 -4
  162. package/dist/types/modules/pss.d.ts +4 -3
  163. package/dist/types/modules/soc.d.ts +3 -2
  164. package/dist/types/modules/stewardship.d.ts +4 -4
  165. package/dist/types/modules/tag.d.ts +2 -1
  166. package/dist/types/stamper/stamper.d.ts +15 -0
  167. package/dist/types/types/debug.d.ts +63 -115
  168. package/dist/types/types/index.d.ts +103 -204
  169. package/dist/types/utils/bytes.d.ts +16 -90
  170. package/dist/types/utils/chunk-size.d.ts +1 -0
  171. package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
  172. package/dist/types/utils/chunk-stream.d.ts +6 -0
  173. package/dist/types/utils/cid.d.ts +3 -2
  174. package/dist/types/utils/collection.browser.d.ts +2 -2
  175. package/dist/types/utils/collection.d.ts +2 -1
  176. package/dist/types/utils/collection.node.d.ts +0 -1
  177. package/dist/types/utils/constants.d.ts +4 -1
  178. package/dist/types/utils/duration.d.ts +17 -0
  179. package/dist/types/utils/error.d.ts +2 -2
  180. package/dist/types/utils/expose.d.ts +2 -7
  181. package/dist/types/utils/headers.d.ts +3 -4
  182. package/dist/types/utils/mime.d.ts +1 -0
  183. package/dist/types/utils/pss.d.ts +2 -2
  184. package/dist/types/utils/resource-locator.d.ts +6 -0
  185. package/dist/types/utils/size.d.ts +16 -0
  186. package/dist/types/utils/stamps.d.ts +27 -33
  187. package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
  188. package/dist/types/utils/tar-uploader.d.ts +3 -4
  189. package/dist/types/utils/tokens.d.ts +77 -0
  190. package/dist/types/utils/type.d.ts +20 -52
  191. package/dist/types/utils/typed-bytes.d.ts +68 -0
  192. package/dist/types/utils/upload-progress.d.ts +4 -0
  193. package/dist/types/utils/workaround.d.ts +2 -0
  194. package/package.json +11 -17
  195. package/dist/cjs/chunk/signer.js +0 -126
  196. package/dist/cjs/chunk/span.js +0 -25
  197. package/dist/cjs/feed/json.js +0 -28
  198. package/dist/cjs/feed/topic.js +0 -25
  199. package/dist/cjs/feed/type.js +0 -15
  200. package/dist/cjs/modules/debug/chunk.js +0 -21
  201. package/dist/cjs/modules/debug/tag.js +0 -19
  202. package/dist/cjs/utils/eth.js +0 -216
  203. package/dist/cjs/utils/hash.js +0 -21
  204. package/dist/cjs/utils/hex.js +0 -150
  205. package/dist/cjs/utils/reference.js +0 -36
  206. package/dist/index.browser.min.js.LICENSE.txt +0 -8
  207. package/dist/mjs/chunk/signer.js +0 -114
  208. package/dist/mjs/chunk/span.js +0 -21
  209. package/dist/mjs/feed/json.js +0 -26
  210. package/dist/mjs/feed/topic.js +0 -19
  211. package/dist/mjs/feed/type.js +0 -10
  212. package/dist/mjs/modules/debug/chunk.js +0 -17
  213. package/dist/mjs/modules/debug/tag.js +0 -15
  214. package/dist/mjs/utils/eth.js +0 -192
  215. package/dist/mjs/utils/hash.js +0 -16
  216. package/dist/mjs/utils/hex.js +0 -135
  217. package/dist/mjs/utils/reference.js +0 -29
  218. package/dist/types/chunk/signer.d.ts +0 -31
  219. package/dist/types/chunk/span.d.ts +0 -10
  220. package/dist/types/feed/json.d.ts +0 -4
  221. package/dist/types/feed/topic.d.ts +0 -3
  222. package/dist/types/feed/type.d.ts +0 -6
  223. package/dist/types/modules/debug/chunk.d.ts +0 -10
  224. package/dist/types/modules/debug/tag.d.ts +0 -8
  225. package/dist/types/utils/eth.d.ts +0 -67
  226. package/dist/types/utils/hash.d.ts +0 -9
  227. package/dist/types/utils/hex.d.ts +0 -86
  228. package/dist/types/utils/reference.d.ts +0 -2
package/dist/cjs/bee.js CHANGED
@@ -25,13 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Bee = void 0;
27
27
  const cafe_utility_1 = require("cafe-utility");
28
- const signer_1 = require("./chunk/signer");
28
+ const cac_1 = require("./chunk/cac");
29
29
  const soc_1 = require("./chunk/soc");
30
30
  const feed_1 = require("./feed");
31
- const json_1 = require("./feed/json");
32
31
  const retrievable_1 = require("./feed/retrievable");
33
- const topic_1 = require("./feed/topic");
34
- const type_1 = require("./feed/type");
35
32
  const bytes = __importStar(require("./modules/bytes"));
36
33
  const bzz = __importStar(require("./modules/bzz"));
37
34
  const chunk = __importStar(require("./modules/chunk"));
@@ -43,11 +40,11 @@ const stake = __importStar(require("./modules/debug/stake"));
43
40
  const stamps = __importStar(require("./modules/debug/stamps"));
44
41
  const states = __importStar(require("./modules/debug/states"));
45
42
  const debugStatus = __importStar(require("./modules/debug/status"));
46
- const debugTag = __importStar(require("./modules/debug/tag"));
47
43
  const transactions = __importStar(require("./modules/debug/transactions"));
48
44
  const envelope_1 = require("./modules/envelope");
49
45
  const feed_2 = require("./modules/feed");
50
46
  const grantee = __importStar(require("./modules/grantee"));
47
+ const gsoc = __importStar(require("./modules/gsoc"));
51
48
  const pinning = __importStar(require("./modules/pinning"));
52
49
  const pss = __importStar(require("./modules/pss"));
53
50
  const status = __importStar(require("./modules/status"));
@@ -55,13 +52,17 @@ const stewardship = __importStar(require("./modules/stewardship"));
55
52
  const tag = __importStar(require("./modules/tag"));
56
53
  const types_1 = require("./types");
57
54
  const bytes_1 = require("./utils/bytes");
55
+ const chunk_stream_1 = require("./utils/chunk-stream");
58
56
  const collection_1 = require("./utils/collection");
59
57
  const collection_node_1 = require("./utils/collection.node");
60
58
  const data_1 = require("./utils/data");
61
59
  const error_1 = require("./utils/error");
62
- const eth_1 = require("./utils/eth");
63
60
  const file_1 = require("./utils/file");
64
- const type_2 = require("./utils/type");
61
+ const resource_locator_1 = require("./utils/resource-locator");
62
+ const stamps_1 = require("./utils/stamps");
63
+ const tokens_1 = require("./utils/tokens");
64
+ const type_1 = require("./utils/type");
65
+ const typed_bytes_1 = require("./utils/typed-bytes");
65
66
  const url_1 = require("./utils/url");
66
67
  /**
67
68
  * The main component that abstracts operations available on the main Bee API.
@@ -81,11 +82,11 @@ class Bee {
81
82
  // unnecessary redirects.
82
83
  this.url = (0, url_1.stripLastSlash)(url);
83
84
  if (options?.signer) {
84
- this.signer = (0, signer_1.makeSigner)(options.signer);
85
+ this.signer = new typed_bytes_1.PrivateKey(options.signer);
85
86
  }
86
87
  this.requestOptions = {
87
88
  baseURL: this.url,
88
- timeout: options?.timeout ?? false,
89
+ timeout: options?.timeout ?? 0,
89
90
  headers: options?.headers,
90
91
  onRequest: options?.onRequest,
91
92
  httpAgent: options?.httpAgent,
@@ -104,11 +105,10 @@ class Bee {
104
105
  * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
105
106
  */
106
107
  async uploadData(postageBatchId, data, options, requestOptions) {
107
- (0, type_2.assertBatchId)(postageBatchId);
108
- (0, type_2.assertData)(data);
109
- (0, type_2.assertRequestOptions)(requestOptions);
108
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
109
+ (0, type_1.assertData)(data);
110
110
  if (options) {
111
- (0, type_2.assertUploadOptions)(options);
111
+ options = (0, type_1.prepareRedundantUploadOptions)(options);
112
112
  }
113
113
  return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
114
114
  }
@@ -118,39 +118,40 @@ class Bee {
118
118
  * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
119
119
  */
120
120
  async probeData(reference, options) {
121
- (0, type_2.assertRequestOptions)(options);
122
- (0, type_2.assertReferenceOrEns)(reference);
121
+ reference = new typed_bytes_1.Reference(reference);
123
122
  return bytes.head(this.getRequestOptionsForCall(options), reference);
124
123
  }
125
124
  /**
126
125
  * Download data as a byte array
127
126
  *
128
- * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
127
+ * @param resource Swarm reference, Swarm CID, or ENS domain
129
128
  * @param options Options that affects the request behavior
130
129
  * @throws TypeError if some of the input parameters is not expected type
131
130
  * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
132
131
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
133
132
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
134
133
  */
135
- async downloadData(reference, options) {
136
- (0, type_2.assertRequestOptions)(options);
137
- (0, type_2.assertReferenceOrEns)(reference);
138
- return bytes.download(this.getRequestOptionsForCall(options), reference);
134
+ async downloadData(resource, options, requestOptions) {
135
+ if (options) {
136
+ options = (0, type_1.prepareDownloadOptions)(options);
137
+ }
138
+ return bytes.download(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), options);
139
139
  }
140
140
  /**
141
141
  * Download data as a Readable stream
142
142
  *
143
- * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
143
+ * @param resource Swarm reference, Swarm CID, or ENS domain
144
144
  * @param options Options that affects the request behavior
145
145
  * @throws TypeError if some of the input parameters is not expected type
146
146
  * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
147
147
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
148
148
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
149
149
  */
150
- async downloadReadableData(reference, options) {
151
- (0, type_2.assertRequestOptions)(options);
152
- (0, type_2.assertReferenceOrEns)(reference);
153
- return bytes.downloadReadable(this.getRequestOptionsForCall(options), reference);
150
+ async downloadReadableData(resource, options, requestOptions) {
151
+ if (options) {
152
+ options = (0, type_1.prepareDownloadOptions)(options);
153
+ }
154
+ return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), options);
154
155
  }
155
156
  /**
156
157
  * Upload chunk to a Bee node
@@ -164,18 +165,15 @@ class Bee {
164
165
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
165
166
  */
166
167
  async uploadChunk(stamp, data, options, requestOptions) {
167
- (0, type_2.assertRequestOptions)(requestOptions);
168
- if (!(data instanceof Uint8Array)) {
169
- throw new TypeError('Data has to be Uint8Array instance!');
170
- }
171
- if (data.length < types_1.SPAN_SIZE) {
172
- throw new error_1.BeeArgumentError(`Chunk has to have size of at least ${types_1.SPAN_SIZE}.`, data);
168
+ data = data instanceof Uint8Array ? data : data.data;
169
+ if (options) {
170
+ options = (0, type_1.prepareUploadOptions)(options);
173
171
  }
174
- if (data.length > types_1.CHUNK_SIZE + types_1.SPAN_SIZE) {
175
- throw new error_1.BeeArgumentError(`Chunk has to have size of at most ${types_1.CHUNK_SIZE}.`, data);
172
+ if (data.length < typed_bytes_1.Span.LENGTH) {
173
+ throw new error_1.BeeArgumentError(`Chunk has to have size of at least ${typed_bytes_1.Span.LENGTH}.`, data);
176
174
  }
177
- if (options) {
178
- (0, type_2.assertUploadOptions)(options);
175
+ if (data.length > types_1.CHUNK_SIZE + typed_bytes_1.Span.LENGTH) {
176
+ throw new error_1.BeeArgumentError(`Chunk has to have size of at most ${types_1.CHUNK_SIZE + typed_bytes_1.Span.LENGTH}.`, data);
179
177
  }
180
178
  return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
181
179
  }
@@ -189,10 +187,12 @@ class Bee {
189
187
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
190
188
  * @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{address}/get)
191
189
  */
192
- async downloadChunk(reference, options) {
193
- (0, type_2.assertRequestOptions)(options);
194
- (0, type_2.assertReferenceOrEns)(reference);
195
- return chunk.download(this.getRequestOptionsForCall(options), reference);
190
+ async downloadChunk(reference, options, requestOptions) {
191
+ reference = new typed_bytes_1.Reference(reference);
192
+ if (options) {
193
+ options = (0, type_1.prepareDownloadOptions)(options);
194
+ }
195
+ return chunk.download(this.getRequestOptionsForCall(requestOptions), reference, options);
196
196
  }
197
197
  /**
198
198
  * Create a grantees list from the given array of public keys.
@@ -205,8 +205,8 @@ class Bee {
205
205
  * @returns A promise that resolves to a `GranteesResult` object.
206
206
  */
207
207
  async createGrantees(postageBatchId, grantees, requestOptions) {
208
- (0, type_2.assertRequestOptions)(requestOptions);
209
- (0, type_2.assertBatchId)(postageBatchId);
208
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
209
+ grantees = grantees.map(x => new typed_bytes_1.PublicKey(x));
210
210
  return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
211
211
  }
212
212
  /**
@@ -217,7 +217,7 @@ class Bee {
217
217
  * @returns A promise that resolves to a `GetGranteesResult` object.
218
218
  */
219
219
  async getGrantees(reference, requestOptions) {
220
- (0, type_2.assertRequestOptions)(requestOptions);
220
+ reference = new typed_bytes_1.Reference(reference);
221
221
  return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
222
222
  }
223
223
  /**
@@ -231,16 +231,18 @@ class Bee {
231
231
  * @returns A Promise that resolves to to a `GranteesResult` object.
232
232
  */
233
233
  async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
234
- (0, type_2.assertRequestOptions)(requestOptions);
235
- (0, type_2.assertBatchId)(postageBatchId);
236
- return grantee.patchGrantees(postageBatchId, reference, history, { add: grantees.add || [], revoke: grantees.revoke || [] }, this.getRequestOptionsForCall(requestOptions));
234
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
235
+ reference = new typed_bytes_1.Reference(reference);
236
+ history = new typed_bytes_1.Reference(history);
237
+ const publicKeys = {
238
+ add: grantees.add?.map(x => new typed_bytes_1.PublicKey(x)) ?? [],
239
+ revoke: grantees.revoke?.map(x => new typed_bytes_1.PublicKey(x)) ?? [],
240
+ };
241
+ return grantee.patchGrantees(postageBatchId, reference, history, publicKeys, this.getRequestOptionsForCall(requestOptions));
237
242
  }
238
243
  /**
239
244
  * Upload single file to a Bee node.
240
245
  *
241
- * **To make sure that you won't lose critical data it is highly recommended to also
242
- * locally pin the data with `options.pin = true`**
243
- *
244
246
  * @param postageBatchId Postage BatchId to be used to upload the data with
245
247
  * @param data Data or file to be uploaded
246
248
  * @param name Optional name of the uploaded file
@@ -252,11 +254,10 @@ class Bee {
252
254
  * @returns reference is a content hash of the file
253
255
  */
254
256
  async uploadFile(postageBatchId, data, name, options, requestOptions) {
255
- (0, type_2.assertRequestOptions)(requestOptions);
256
- (0, type_2.assertBatchId)(postageBatchId);
257
- (0, type_2.assertFileData)(data);
257
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
258
+ (0, type_1.assertFileData)(data);
258
259
  if (options) {
259
- (0, type_2.assertFileUploadOptions)(options);
260
+ options = (0, type_1.prepareFileUploadOptions)(options);
260
261
  }
261
262
  if (name && typeof name !== 'string') {
262
263
  throw new TypeError('name has to be string or undefined!');
@@ -266,22 +267,16 @@ class Bee {
266
267
  const fileName = name ?? data.name;
267
268
  const contentType = data.type;
268
269
  const fileOptions = { contentType, ...options };
269
- return (0, type_2.addCidConversionFunction)(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions), 'manifest');
270
- }
271
- else if ((0, type_2.isReadable)(data) && options?.tag && !options.size) {
272
- // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
273
- const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
274
- await this.updateTag(options.tag, result.reference);
275
- return (0, type_2.addCidConversionFunction)(result, 'manifest');
270
+ return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
276
271
  }
277
272
  else {
278
- return (0, type_2.addCidConversionFunction)(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options), 'manifest');
273
+ return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
279
274
  }
280
275
  }
281
276
  /**
282
277
  * Download single file.
283
278
  *
284
- * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
279
+ * @param resource Swarm reference, Swarm CID, or ENS domain
285
280
  * @param path If reference points to manifest, then this parameter defines path to the file
286
281
  * @param options Options that affects the request behavior
287
282
  * @throws TypeError if some of the input parameters is not expected type
@@ -290,10 +285,11 @@ class Bee {
290
285
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
291
286
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
292
287
  */
293
- async downloadFile(reference, path = '', options) {
294
- (0, type_2.assertRequestOptions)(options);
295
- reference = (0, type_2.makeReferenceOrEns)(reference, 'manifest');
296
- return bzz.downloadFile(this.getRequestOptionsForCall(options), reference, path);
288
+ async downloadFile(resource, path = '', options, requestOptions) {
289
+ if (options) {
290
+ options = (0, type_1.prepareDownloadOptions)(options);
291
+ }
292
+ return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), path, options);
297
293
  }
298
294
  /**
299
295
  * Download single file as a readable stream
@@ -307,10 +303,12 @@ class Bee {
307
303
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
308
304
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
309
305
  */
310
- async downloadReadableFile(reference, path = '', options) {
311
- (0, type_2.assertRequestOptions)(options);
312
- reference = (0, type_2.makeReferenceOrEns)(reference, 'manifest');
313
- return bzz.downloadFileReadable(this.getRequestOptionsForCall(options), reference, path);
306
+ async downloadReadableFile(reference, path = '', options, requestOptions) {
307
+ reference = new typed_bytes_1.Reference(reference);
308
+ if (options) {
309
+ options = (0, type_1.prepareDownloadOptions)(options);
310
+ }
311
+ return bzz.downloadFileReadable(this.getRequestOptionsForCall(requestOptions), reference, path, options);
314
312
  }
315
313
  /**
316
314
  * Upload collection of files to a Bee node
@@ -329,13 +327,23 @@ class Bee {
329
327
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
330
328
  */
331
329
  async uploadFiles(postageBatchId, fileList, options, requestOptions) {
332
- (0, type_2.assertRequestOptions)(requestOptions);
333
- (0, type_2.assertBatchId)(postageBatchId);
330
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
334
331
  if (options) {
335
- (0, type_2.assertCollectionUploadOptions)(options);
332
+ options = (0, type_1.prepareCollectionUploadOptions)(options);
336
333
  }
337
- const data = await (0, collection_1.makeCollectionFromFileList)(fileList);
338
- return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), 'manifest');
334
+ const data = (0, collection_1.makeCollectionFromFileList)(fileList);
335
+ return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
336
+ }
337
+ async hashDirectory(dir) {
338
+ return (0, chunk_stream_1.hashDirectory)(dir);
339
+ }
340
+ async streamDirectory(postageBatchId, dir, onUploadProgress, options, requestOptions) {
341
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
342
+ return (0, chunk_stream_1.streamDirectory)(this, dir, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
343
+ }
344
+ async streamFiles(postageBatchId, files, onUploadProgress, options, requestOptions) {
345
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
346
+ return (0, chunk_stream_1.streamFiles)(this, files, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
339
347
  }
340
348
  /**
341
349
  * Upload Collection that you can assembly yourself.
@@ -348,12 +356,12 @@ class Bee {
348
356
  * @param options Collections and request options
349
357
  */
350
358
  async uploadCollection(postageBatchId, collection, options, requestOptions) {
351
- (0, type_2.assertRequestOptions)(requestOptions);
352
- (0, type_2.assertBatchId)(postageBatchId);
359
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
353
360
  (0, collection_1.assertCollection)(collection);
354
- if (options)
355
- (0, type_2.assertCollectionUploadOptions)(options);
356
- return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), 'manifest');
361
+ if (options) {
362
+ options = (0, type_1.prepareCollectionUploadOptions)(options);
363
+ }
364
+ return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), collection, postageBatchId, options);
357
365
  }
358
366
  /**
359
367
  * Upload collection of files.
@@ -372,12 +380,12 @@ class Bee {
372
380
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
373
381
  */
374
382
  async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
375
- (0, type_2.assertBatchId)(postageBatchId);
376
- (0, type_2.assertRequestOptions)(requestOptions);
377
- if (options)
378
- (0, type_2.assertCollectionUploadOptions)(options);
383
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
384
+ if (options) {
385
+ options = (0, type_1.prepareCollectionUploadOptions)(options);
386
+ }
379
387
  const data = await (0, collection_node_1.makeCollectionFromFS)(dir);
380
- return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), 'manifest');
388
+ return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
381
389
  }
382
390
  /**
383
391
  * Create a new Tag which is meant for tracking progres of syncing data across network.
@@ -387,7 +395,6 @@ class Bee {
387
395
  * @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
388
396
  */
389
397
  async createTag(options) {
390
- (0, type_2.assertRequestOptions)(options);
391
398
  return tag.createTag(this.getRequestOptionsForCall(options));
392
399
  }
393
400
  /**
@@ -403,8 +410,9 @@ class Bee {
403
410
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
404
411
  */
405
412
  async getAllTags(options, requestOptions) {
406
- (0, type_2.assertRequestOptions)(requestOptions);
407
- (0, type_2.assertAllTagsOptions)(options);
413
+ if (options) {
414
+ options = (0, type_1.prepareAllTagsOptions)(options);
415
+ }
408
416
  return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
409
417
  }
410
418
  /**
@@ -419,8 +427,7 @@ class Bee {
419
427
  *
420
428
  */
421
429
  async retrieveTag(tagUid, options) {
422
- (0, type_2.assertRequestOptions)(options);
423
- tagUid = (0, type_2.makeTagUid)(tagUid);
430
+ tagUid = (0, type_1.makeTagUid)(tagUid);
424
431
  return tag.retrieveTag(this.getRequestOptionsForCall(options), tagUid);
425
432
  }
426
433
  /**
@@ -435,8 +442,7 @@ class Bee {
435
442
  * @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
436
443
  */
437
444
  async deleteTag(tagUid, options) {
438
- (0, type_2.assertRequestOptions)(options);
439
- tagUid = (0, type_2.makeTagUid)(tagUid);
445
+ tagUid = (0, type_1.makeTagUid)(tagUid);
440
446
  return tag.deleteTag(this.getRequestOptionsForCall(options), tagUid);
441
447
  }
442
448
  /**
@@ -455,9 +461,8 @@ class Bee {
455
461
  * @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
456
462
  */
457
463
  async updateTag(tagUid, reference, options) {
458
- (0, type_2.assertReference)(reference);
459
- (0, type_2.assertRequestOptions)(options);
460
- tagUid = (0, type_2.makeTagUid)(tagUid);
464
+ reference = new typed_bytes_1.Reference(reference);
465
+ tagUid = (0, type_1.makeTagUid)(tagUid);
461
466
  return tag.updateTag(this.getRequestOptionsForCall(options), tagUid, reference);
462
467
  }
463
468
  /**
@@ -470,8 +475,7 @@ class Bee {
470
475
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
471
476
  */
472
477
  async pin(reference, options) {
473
- (0, type_2.assertRequestOptions)(options);
474
- (0, type_2.assertReference)(reference);
478
+ reference = new typed_bytes_1.Reference(reference);
475
479
  return pinning.pin(this.getRequestOptionsForCall(options), reference);
476
480
  }
477
481
  /**
@@ -484,8 +488,7 @@ class Bee {
484
488
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
485
489
  */
486
490
  async unpin(reference, options) {
487
- (0, type_2.assertRequestOptions)(options);
488
- (0, type_2.assertReference)(reference);
491
+ reference = new typed_bytes_1.Reference(reference);
489
492
  return pinning.unpin(this.getRequestOptionsForCall(options), reference);
490
493
  }
491
494
  /**
@@ -495,7 +498,6 @@ class Bee {
495
498
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
496
499
  */
497
500
  async getAllPins(options) {
498
- (0, type_2.assertRequestOptions)(options);
499
501
  return pinning.getAllPins(this.getRequestOptionsForCall(options));
500
502
  }
501
503
  /**
@@ -509,8 +511,7 @@ class Bee {
509
511
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
510
512
  */
511
513
  async getPin(reference, options) {
512
- (0, type_2.assertRequestOptions)(options);
513
- (0, type_2.assertReference)(reference);
514
+ reference = new typed_bytes_1.Reference(reference);
514
515
  return pinning.getPin(this.getRequestOptionsForCall(options), reference);
515
516
  }
516
517
  /**
@@ -524,10 +525,10 @@ class Bee {
524
525
  *
525
526
  * @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
526
527
  */
527
- async reuploadPinnedData(reference, options) {
528
- (0, type_2.assertRequestOptions)(options);
529
- (0, type_2.assertReferenceOrEns)(reference);
530
- await stewardship.reupload(this.getRequestOptionsForCall(options), reference);
528
+ async reuploadPinnedData(postageBatchId, reference, options) {
529
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
530
+ reference = new typed_bytes_1.Reference(reference);
531
+ await stewardship.reupload(this.getRequestOptionsForCall(options), postageBatchId, reference);
531
532
  }
532
533
  /**
533
534
  * Checks if content specified by reference is retrievable from the network.
@@ -540,8 +541,7 @@ class Bee {
540
541
  * @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
541
542
  */
542
543
  async isReferenceRetrievable(reference, options) {
543
- (0, type_2.assertRequestOptions)(options);
544
- (0, type_2.assertReferenceOrEns)(reference);
544
+ reference = new typed_bytes_1.Reference(reference);
545
545
  return stewardship.isRetrievable(this.getRequestOptionsForCall(options), reference);
546
546
  }
547
547
  /**
@@ -559,25 +559,26 @@ class Bee {
559
559
  * @param index
560
560
  * @param options
561
561
  */
562
- async isFeedRetrievable(type, owner, topic, index, options) {
563
- const canonicalOwner = (0, eth_1.makeEthAddress)(owner);
564
- const canonicalTopic = (0, topic_1.makeTopic)(topic);
562
+ async isFeedRetrievable(owner, topic, index, options, requestOptions) {
563
+ owner = new typed_bytes_1.EthAddress(owner);
564
+ topic = new typed_bytes_1.Topic(topic);
565
+ if (options) {
566
+ options = (0, type_1.prepareDownloadOptions)(options);
567
+ }
565
568
  if (!index) {
566
569
  try {
567
- await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
570
+ await this.makeFeedReader(topic, owner, requestOptions).download();
568
571
  return true;
569
572
  }
570
573
  catch (e) {
571
- if (e?.status === 404 || e?.status === 500) {
574
+ const status = cafe_utility_1.Objects.getDeep(e, 'status');
575
+ if (status === 404 || status === 500) {
572
576
  return false;
573
577
  }
574
578
  throw e;
575
579
  }
576
580
  }
577
- if (type !== 'sequence') {
578
- throw new error_1.BeeError('Only Sequence type of Feeds is supported at the moment');
579
- }
580
- return (0, retrievable_1.areAllSequentialFeedsUpdateRetrievable)(this, canonicalOwner, canonicalTopic, index, this.getRequestOptionsForCall(options));
581
+ return (0, retrievable_1.areAllSequentialFeedsUpdateRetrievable)(this, owner, topic, index, options, this.getRequestOptionsForCall(requestOptions));
581
582
  }
582
583
  /**
583
584
  * Send data to recipient or target with Postal Service for Swarm.
@@ -602,15 +603,10 @@ class Bee {
602
603
  * @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
  */
604
605
  async pssSend(postageBatchId, topic, target, data, recipient, options) {
605
- (0, type_2.assertRequestOptions)(options);
606
- (0, type_2.assertData)(data);
607
- (0, type_2.assertBatchId)(postageBatchId);
608
- (0, type_2.assertAddressPrefix)(target);
609
- if (typeof topic !== 'string') {
610
- throw new TypeError('topic has to be an string!');
611
- }
606
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
607
+ (0, type_1.assertData)(data);
612
608
  if (recipient) {
613
- (0, type_2.assertPublicKey)(recipient);
609
+ recipient = new typed_bytes_1.PublicKey(recipient);
614
610
  return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId, recipient);
615
611
  }
616
612
  else {
@@ -632,11 +628,8 @@ class Bee {
632
628
  * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
633
629
  */
634
630
  pssSubscribe(topic, handler) {
635
- (0, type_2.assertPssMessageHandler)(handler);
636
- if (typeof topic !== 'string') {
637
- throw new TypeError('topic has to be an string!');
638
- }
639
- const ws = pss.subscribe(this.url, topic);
631
+ handler = (0, type_1.preparePssMessageHandler)(handler);
632
+ const ws = pss.subscribe(this.url, topic, this.requestOptions.headers);
640
633
  let cancelled = false;
641
634
  const cancel = () => {
642
635
  if (cancelled === false) {
@@ -644,27 +637,28 @@ class Bee {
644
637
  // although the WebSocket API offers a `close` function, it seems that
645
638
  // with the library that we are using (isomorphic-ws) it doesn't close
646
639
  // the websocket properly, whereas `terminate` does
647
- if (ws.terminate)
640
+ if (ws.terminate) {
648
641
  ws.terminate();
649
- else
650
- ws.close(); // standard Websocket in browser does not have terminate function
642
+ }
643
+ else {
644
+ ws.close();
645
+ } // standard Websocket in browser does not have terminate function
651
646
  }
652
647
  };
653
648
  const subscription = {
654
649
  topic,
655
650
  cancel,
656
651
  };
657
- ws.onmessage = async (ev) => {
658
- const data = await (0, data_1.prepareWebsocketData)(ev.data);
659
- // ignore empty messages
660
- if (data.length > 0) {
661
- handler.onMessage((0, bytes_1.wrapBytesWithHelpers)(data), subscription);
652
+ ws.onmessage = async (event) => {
653
+ const data = await (0, data_1.prepareWebsocketData)(event.data);
654
+ if (data.length) {
655
+ handler.onMessage(new bytes_1.Bytes(data), subscription);
662
656
  }
663
657
  };
664
- ws.onerror = ev => {
658
+ ws.onerror = event => {
665
659
  // ignore errors after subscription was cancelled
666
660
  if (!cancelled) {
667
- handler.onError(new error_1.BeeError(ev.message), subscription);
661
+ handler.onError(new error_1.BeeError(event.message), subscription);
668
662
  }
669
663
  };
670
664
  return subscription;
@@ -694,9 +688,6 @@ class Bee {
694
688
  * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
695
689
  */
696
690
  async pssReceive(topic, timeoutMsec = 0) {
697
- if (typeof topic !== 'string') {
698
- throw new TypeError('topic has to be an string!');
699
- }
700
691
  if (typeof timeoutMsec !== 'number') {
701
692
  throw new TypeError('timeoutMsc parameter has to be a number!');
702
693
  }
@@ -715,8 +706,6 @@ class Bee {
715
706
  },
716
707
  });
717
708
  if (timeoutMsec > 0) {
718
- // we need to cast the type because Typescript is getting confused with Node.js'
719
- // alternative type definitions
720
709
  timeout = setTimeout(() => {
721
710
  subscription.cancel();
722
711
  reject(new error_1.BeeError('pssReceive timeout'));
@@ -724,13 +713,69 @@ class Bee {
724
713
  }
725
714
  });
726
715
  }
716
+ gsocMine(targetOverlay, identifier, proximity = 12) {
717
+ targetOverlay = new typed_bytes_1.PeerAddress(targetOverlay);
718
+ identifier = new typed_bytes_1.Identifier(identifier);
719
+ const start = 0xb33n;
720
+ for (let i = 0n; i < 0xffffn; i++) {
721
+ const signer = new typed_bytes_1.PrivateKey(cafe_utility_1.Binary.numberToUint256(start + i, 'BE'));
722
+ const socAddress = (0, soc_1.makeSOCAddress)(identifier, signer.publicKey().address());
723
+ const actualProximity = 256 - cafe_utility_1.Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array(), 256);
724
+ if (actualProximity <= 256 - proximity) {
725
+ return signer;
726
+ }
727
+ }
728
+ throw Error('Could not mine a valid signer');
729
+ }
730
+ async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
731
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
732
+ signer = new typed_bytes_1.PrivateKey(signer);
733
+ identifier = new typed_bytes_1.Identifier(identifier);
734
+ const cac = (0, cac_1.makeContentAddressedChunk)(data);
735
+ const soc = (0, soc_1.makeSingleOwnerChunk)(cac, identifier, signer);
736
+ return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
737
+ }
738
+ gsocSubscribe(address, identifier, handler) {
739
+ address = new typed_bytes_1.EthAddress(address);
740
+ identifier = new typed_bytes_1.Identifier(identifier);
741
+ handler = (0, type_1.prepareGsocMessageHandler)(handler);
742
+ const socAddress = (0, soc_1.makeSOCAddress)(identifier, address);
743
+ const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
744
+ let cancelled = false;
745
+ const cancel = () => {
746
+ if (cancelled === false) {
747
+ cancelled = true;
748
+ if (ws.terminate) {
749
+ ws.terminate();
750
+ }
751
+ else {
752
+ ws.close();
753
+ }
754
+ }
755
+ };
756
+ const subscription = {
757
+ address,
758
+ cancel,
759
+ };
760
+ ws.onmessage = async (event) => {
761
+ const data = await (0, data_1.prepareWebsocketData)(event.data);
762
+ if (data.length) {
763
+ handler.onMessage(new bytes_1.Bytes(data), subscription);
764
+ }
765
+ };
766
+ ws.onerror = event => {
767
+ if (!cancelled) {
768
+ handler.onError(new error_1.BeeError(event.message), subscription);
769
+ }
770
+ };
771
+ return subscription;
772
+ }
727
773
  /**
728
774
  * Create feed manifest chunk and return the reference to it.
729
775
  *
730
776
  * Feed manifest chunk allows for a feed to be able to be resolved through `/bzz` endpoint.
731
777
  *
732
778
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
733
- * @param type The type of the feed, can be 'epoch' or 'sequence'
734
779
  * @param topic Topic in hex or bytes
735
780
  * @param owner Owner's ethereum address in hex or bytes
736
781
  * @param options Options that affects the request behavior
@@ -738,130 +783,50 @@ class Bee {
738
783
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
739
784
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
740
785
  */
741
- async createFeedManifest(stamp, type, topic, owner, options) {
742
- (0, type_2.assertRequestOptions)(options);
743
- (0, type_1.assertFeedType)(type);
744
- const canonicalTopic = (0, topic_1.makeTopic)(topic);
745
- const canonicalOwner = (0, eth_1.makeHexEthAddress)(owner);
746
- const reference = await (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, stamp);
747
- return (0, type_2.addCidConversionFunction)({ reference }, 'feed');
786
+ async createFeedManifest(postageBatchId, topic, owner, options, requestOptions) {
787
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
788
+ topic = new typed_bytes_1.Topic(topic);
789
+ owner = new typed_bytes_1.EthAddress(owner);
790
+ if (options) {
791
+ options = (0, type_1.prepareUploadOptions)(options);
792
+ }
793
+ return (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(requestOptions), owner, topic, postageBatchId, options);
748
794
  }
749
795
  /**
750
796
  * Make a new feed reader for downloading feed updates.
751
797
  *
752
- * @param type The type of the feed, can be 'epoch' or 'sequence'
753
798
  * @param topic Topic in hex or bytes
754
799
  * @param owner Owner's ethereum address in hex or bytes
755
800
  * @param options Options that affects the request behavior
756
801
  *
757
802
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
758
803
  */
759
- makeFeedReader(type, topic, owner, options) {
760
- (0, type_2.assertRequestOptions)(options);
761
- (0, type_1.assertFeedType)(type);
762
- const canonicalTopic = (0, topic_1.makeTopic)(topic);
763
- const canonicalOwner = (0, eth_1.makeHexEthAddress)(owner);
764
- return (0, feed_1.makeFeedReader)(this.getRequestOptionsForCall(options), type, canonicalTopic, canonicalOwner);
804
+ makeFeedReader(topic, owner, options) {
805
+ topic = new typed_bytes_1.Topic(topic);
806
+ owner = new typed_bytes_1.EthAddress(owner);
807
+ return (0, feed_1.makeFeedReader)(this.getRequestOptionsForCall(options), topic, owner);
765
808
  }
766
809
  /**
767
810
  * Make a new feed writer for updating feeds
768
811
  *
769
- * @param type The type of the feed, can be 'epoch' or 'sequence'
770
812
  * @param topic Topic in hex or bytes
771
813
  * @param signer The signer's private key or a Signer instance that can sign data
772
814
  * @param options Options that affects the request behavior
773
815
  *
774
816
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
775
817
  */
776
- makeFeedWriter(type, topic, signer, options) {
777
- (0, type_2.assertRequestOptions)(options);
778
- (0, type_1.assertFeedType)(type);
779
- const canonicalTopic = (0, topic_1.makeTopic)(topic);
780
- const canonicalSigner = this.resolveSigner(signer);
781
- return (0, feed_1.makeFeedWriter)(this.getRequestOptionsForCall(options), type, canonicalTopic, canonicalSigner);
782
- }
783
- /**
784
- * High-level function that allows you to easily set JSON data to feed.
785
- * JSON-like data types are supported.
786
- *
787
- * The default Signer of Bee instance is used if `options.signer` is not specified.
788
- * If none of those two is set error is thrown.
789
- *
790
- * @param postageBatchId Postage BatchId to be used to upload the data with
791
- * @param topic Human readable string, that is internally hashed so there are no constrains there.
792
- * @param data JSON compatible data
793
- * @param options
794
- * @param options.signer Custom instance of Signer or string with private key.
795
- * @param options.type Type of Feed
796
- *
797
- * @throws BeeError if `options.signer` is not specified nor the default Signer on Bee's instance is specified.
798
- *
799
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
800
- */
801
- async setJsonFeed(postageBatchId, topic, data, options, requestOptions) {
802
- (0, type_2.assertRequestOptions)(requestOptions, 'JsonFeedOptions');
803
- (0, type_2.assertBatchId)(postageBatchId);
804
- const hashedTopic = this.makeFeedTopic(topic);
805
- const feedType = options?.type ?? type_1.DEFAULT_FEED_TYPE;
806
- const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, requestOptions);
807
- return (0, json_1.setJsonData)(this, writer, postageBatchId, data, options, requestOptions);
808
- }
809
- /**
810
- * High-level function that allows you to easily get data from feed.
811
- * Returned data are parsed using JSON.parse().
812
- *
813
- * This method also supports specification of `signer` object passed to constructor. The order of evaluation is:
814
- * - `options.address`
815
- * - `options.signer`
816
- * - `this.signer`
817
- *
818
- * At least one of these has to be specified!
819
- *
820
- * @param topic Human readable string, that is internally hashed so there are no constrains there.
821
- * @param options
822
- * @param options.signer Custom instance of Signer or string with private key. This option is exclusive with `address` option.
823
- * @param options.address Ethereum address of owner of the feed that signed it. This option is exclusive with `signer` option.
824
- * @param options.type Type of Feed
825
- *
826
- * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
827
- */
828
- async getJsonFeed(topic, options, requestOptions) {
829
- (0, type_2.assertRequestOptions)(requestOptions);
830
- const hashedTopic = this.makeFeedTopic(topic);
831
- const feedType = options?.type ?? type_1.DEFAULT_FEED_TYPE;
832
- if (options?.signer && options?.address) {
833
- throw new error_1.BeeError('Both options "signer" and "address" can not be specified at one time!');
834
- }
835
- let address;
836
- if (options?.address) {
837
- address = (0, eth_1.makeEthAddress)(options?.address);
838
- }
839
- else {
840
- try {
841
- address = this.resolveSigner(options?.signer).address;
842
- }
843
- catch (e) {
844
- if (e instanceof error_1.BeeError) {
845
- throw new error_1.BeeError('Either address, signer or default signer has to be specified!');
846
- }
847
- else {
848
- throw e;
849
- }
850
- }
818
+ makeFeedWriter(topic, signer, options) {
819
+ topic = new typed_bytes_1.Topic(topic);
820
+ signer = signer ? new typed_bytes_1.PrivateKey(signer) : this.signer;
821
+ if (!signer) {
822
+ throw Error('No signer provided');
851
823
  }
852
- const reader = this.makeFeedReader(feedType, hashedTopic, address, requestOptions);
853
- return (0, json_1.getJsonData)(this, reader);
824
+ return (0, feed_1.makeFeedWriter)(this.getRequestOptionsForCall(options), topic, signer);
854
825
  }
855
- /**
856
- * Make a new feed topic from a string
857
- *
858
- * Because the topic has to be 32 bytes long this function
859
- * hashes the input string to create a topic string of arbitrary length.
860
- *
861
- * @param topic The input string
862
- */
863
- makeFeedTopic(topic) {
864
- return (0, topic_1.makeTopicFromString)(topic);
826
+ async fetchLatestFeedUpdate(topic, owner, requestOptions) {
827
+ topic = new typed_bytes_1.Topic(topic);
828
+ owner = new typed_bytes_1.EthAddress(owner);
829
+ return (0, feed_2.fetchLatestFeedUpdate)(this.getRequestOptionsForCall(requestOptions), owner, topic);
865
830
  }
866
831
  /**
867
832
  * Returns an object for reading single owner chunks
@@ -871,11 +836,10 @@ class Bee {
871
836
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
872
837
  */
873
838
  makeSOCReader(ownerAddress, options) {
874
- (0, type_2.assertRequestOptions)(options);
875
- const canonicalOwner = (0, eth_1.makeEthAddress)(ownerAddress);
839
+ ownerAddress = new typed_bytes_1.EthAddress(ownerAddress);
876
840
  return {
877
- owner: (0, eth_1.makeHexEthAddress)(canonicalOwner),
878
- download: soc_1.downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(options), canonicalOwner),
841
+ owner: ownerAddress,
842
+ download: soc_1.downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(options), ownerAddress),
879
843
  };
880
844
  }
881
845
  /**
@@ -886,15 +850,18 @@ class Bee {
886
850
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
887
851
  */
888
852
  makeSOCWriter(signer, options) {
889
- (0, type_2.assertRequestOptions)(options);
890
- const canonicalSigner = this.resolveSigner(signer);
853
+ signer = signer ? new typed_bytes_1.PrivateKey(signer) : this.signer;
854
+ if (!signer) {
855
+ throw Error('No signer provided');
856
+ }
891
857
  return {
892
- ...this.makeSOCReader(canonicalSigner.address, options),
893
- upload: soc_1.uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), canonicalSigner),
858
+ ...this.makeSOCReader(signer.publicKey().address(), options),
859
+ upload: soc_1.uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), signer),
894
860
  };
895
861
  }
896
862
  async createEnvelope(postageBatchId, reference, options) {
897
- (0, type_2.assertRequestOptions)(options);
863
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
864
+ reference = new typed_bytes_1.Reference(reference);
898
865
  return (0, envelope_1.postEnvelope)(this.getRequestOptionsForCall(options), postageBatchId, reference);
899
866
  }
900
867
  /**
@@ -904,7 +871,6 @@ class Bee {
904
871
  * @throws If connection was not successful throw error
905
872
  */
906
873
  async checkConnection(options) {
907
- (0, type_2.assertRequestOptions)(options, 'PostageBatchOptions');
908
874
  return status.checkConnection(this.getRequestOptionsForCall(options));
909
875
  }
910
876
  /**
@@ -914,7 +880,6 @@ class Bee {
914
880
  * @returns true if successful, false on error
915
881
  */
916
882
  async isConnected(options) {
917
- (0, type_2.assertRequestOptions)(options, 'PostageBatchOptions');
918
883
  try {
919
884
  await status.checkConnection(this.getRequestOptionsForCall(options));
920
885
  }
@@ -925,55 +890,26 @@ class Bee {
925
890
  }
926
891
  // Legacy debug API
927
892
  async getNodeAddresses(options) {
928
- (0, type_2.assertRequestOptions)(options);
929
893
  return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
930
894
  }
931
895
  async getBlocklist(options) {
932
- (0, type_2.assertRequestOptions)(options);
933
896
  return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
934
897
  }
935
- /**
936
- * Retrieve tag extended information from Bee node
937
- *
938
- * @param tagUid UID or tag object to be retrieved
939
- * @throws TypeError if tagUid is in not correct format
940
- *
941
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
942
- * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
943
- *
944
- */
945
- async retrieveExtendedTag(tagUid, options) {
946
- (0, type_2.assertRequestOptions)(options);
947
- if ((0, type_2.isTag)(tagUid)) {
948
- tagUid = tagUid.uid;
949
- }
950
- else if (typeof tagUid === 'number') {
951
- (0, type_2.assertNonNegativeInteger)(tagUid, 'UID');
952
- }
953
- else {
954
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
955
- }
956
- return debugTag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
957
- }
958
898
  /**
959
899
  * Get list of peers for this node
960
900
  */
961
901
  async getPeers(options) {
962
- (0, type_2.assertRequestOptions)(options);
963
902
  return connectivity.getPeers(this.getRequestOptionsForCall(options));
964
903
  }
965
904
  async removePeer(peer, options) {
966
- (0, type_2.assertRequestOptions)(options);
967
- (0, type_2.assertAddress)(peer);
905
+ peer = new typed_bytes_1.PeerAddress(peer);
968
906
  return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
969
907
  }
970
908
  async getTopology(options) {
971
- (0, type_2.assertRequestOptions)(options);
972
909
  return connectivity.getTopology(this.getRequestOptionsForCall(options));
973
910
  }
974
911
  async pingPeer(peer, options) {
975
- (0, type_2.assertRequestOptions)(options);
976
- (0, type_2.assertAddress)(peer);
912
+ peer = new typed_bytes_1.PeerAddress(peer);
977
913
  return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
978
914
  }
979
915
  /*
@@ -983,7 +919,6 @@ class Bee {
983
919
  * Get the balances with all known peers including prepaid services
984
920
  */
985
921
  async getAllBalances(options) {
986
- (0, type_2.assertRequestOptions)(options);
987
922
  return balance.getAllBalances(this.getRequestOptionsForCall(options));
988
923
  }
989
924
  /**
@@ -992,15 +927,13 @@ class Bee {
992
927
  * @param address Swarm address of peer
993
928
  */
994
929
  async getPeerBalance(address, options) {
995
- (0, type_2.assertRequestOptions)(options);
996
- (0, type_2.assertAddress)(address);
930
+ address = new typed_bytes_1.PeerAddress(address);
997
931
  return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
998
932
  }
999
933
  /**
1000
934
  * Get the past due consumption balances with all known peers
1001
935
  */
1002
936
  async getPastDueConsumptionBalances(options) {
1003
- (0, type_2.assertRequestOptions)(options);
1004
937
  return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
1005
938
  }
1006
939
  /**
@@ -1009,8 +942,7 @@ class Bee {
1009
942
  * @param address Swarm address of peer
1010
943
  */
1011
944
  async getPastDueConsumptionPeerBalance(address, options) {
1012
- (0, type_2.assertRequestOptions)(options);
1013
- (0, type_2.assertAddress)(address);
945
+ address = new typed_bytes_1.PeerAddress(address);
1014
946
  return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
1015
947
  }
1016
948
  /*
@@ -1023,21 +955,18 @@ class Bee {
1023
955
  * https://github.com/ethersphere/bee/issues/1443
1024
956
  */
1025
957
  async getChequebookAddress(options) {
1026
- (0, type_2.assertRequestOptions)(options);
1027
958
  return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
1028
959
  }
1029
960
  /**
1030
961
  * Get the balance of the chequebook
1031
962
  */
1032
963
  async getChequebookBalance(options) {
1033
- (0, type_2.assertRequestOptions)(options);
1034
964
  return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
1035
965
  }
1036
966
  /**
1037
967
  * Get last cheques for all peers
1038
968
  */
1039
969
  async getLastCheques(options) {
1040
- (0, type_2.assertRequestOptions)(options);
1041
970
  return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
1042
971
  }
1043
972
  /**
@@ -1046,8 +975,7 @@ class Bee {
1046
975
  * @param address Swarm address of peer
1047
976
  */
1048
977
  async getLastChequesForPeer(address, options) {
1049
- (0, type_2.assertRequestOptions)(options);
1050
- (0, type_2.assertAddress)(address);
978
+ address = new typed_bytes_1.PeerAddress(address);
1051
979
  return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
1052
980
  }
1053
981
  /**
@@ -1056,8 +984,7 @@ class Bee {
1056
984
  * @param address Swarm address of peer
1057
985
  */
1058
986
  async getLastCashoutAction(address, options) {
1059
- (0, type_2.assertRequestOptions)(options);
1060
- (0, type_2.assertAddress)(address);
987
+ address = new typed_bytes_1.PeerAddress(address);
1061
988
  return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
1062
989
  }
1063
990
  /**
@@ -1069,9 +996,10 @@ class Bee {
1069
996
  * @param options.gasLimit Gas limit for the cashout transaction in WEI
1070
997
  */
1071
998
  async cashoutLastCheque(address, options, requestOptions) {
1072
- (0, type_2.assertCashoutOptions)(options);
1073
- (0, type_2.assertAddress)(address);
1074
- (0, type_2.assertRequestOptions)(requestOptions);
999
+ address = new typed_bytes_1.PeerAddress(address);
1000
+ if (options) {
1001
+ (0, type_1.prepareTransactionOptions)(options);
1002
+ }
1075
1003
  return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
1076
1004
  }
1077
1005
  /**
@@ -1082,12 +1010,12 @@ class Bee {
1082
1010
  * @return string Hash of the transaction
1083
1011
  */
1084
1012
  async depositTokens(amount, gasPrice, options) {
1085
- (0, type_2.assertRequestOptions)(options);
1086
- (0, type_2.assertNonNegativeInteger)(amount);
1013
+ const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
1014
+ let gasPriceString;
1087
1015
  if (gasPrice) {
1088
- (0, type_2.assertNonNegativeInteger)(gasPrice);
1016
+ gasPriceString = (0, type_1.asNumberString)(amount, { min: 0n, name: 'gasPrice' });
1089
1017
  }
1090
- return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
1018
+ return chequebook.depositTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
1091
1019
  }
1092
1020
  /**
1093
1021
  * Withdraw tokens from the chequebook to the overlay address
@@ -1097,12 +1025,13 @@ class Bee {
1097
1025
  * @return string Hash of the transaction
1098
1026
  */
1099
1027
  async withdrawTokens(amount, gasPrice, options) {
1100
- (0, type_2.assertRequestOptions)(options);
1101
- (0, type_2.assertNonNegativeInteger)(amount);
1028
+ // TODO: check BZZ in tests
1029
+ const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
1030
+ let gasPriceString;
1102
1031
  if (gasPrice) {
1103
- (0, type_2.assertNonNegativeInteger)(gasPrice);
1032
+ gasPriceString = (0, type_1.asNumberString)(amount, { min: 0n, name: 'gasPrice' });
1104
1033
  }
1105
- return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
1034
+ return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
1106
1035
  }
1107
1036
  /*
1108
1037
  * Settlements endpoint
@@ -1113,81 +1042,47 @@ class Bee {
1113
1042
  * @param address Swarm address of peer
1114
1043
  */
1115
1044
  async getSettlements(address, options) {
1116
- (0, type_2.assertRequestOptions)(options);
1117
- (0, type_2.assertAddress)(address);
1045
+ address = new typed_bytes_1.PeerAddress(address);
1118
1046
  return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
1119
1047
  }
1120
1048
  /**
1121
1049
  * Get settlements with all known peers and total amount sent or received
1122
1050
  */
1123
1051
  async getAllSettlements(options) {
1124
- (0, type_2.assertRequestOptions)(options);
1125
1052
  return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
1126
1053
  }
1127
1054
  /**
1128
1055
  * Get status of node
1129
1056
  */
1130
1057
  async getStatus(options) {
1131
- (0, type_2.assertRequestOptions)(options);
1132
1058
  return debugStatus.getDebugStatus(this.getRequestOptionsForCall(options));
1133
1059
  }
1134
1060
  /**
1135
1061
  * Get health of node
1136
1062
  */
1137
1063
  async getHealth(options) {
1138
- (0, type_2.assertRequestOptions)(options);
1139
1064
  return debugStatus.getHealth(this.getRequestOptionsForCall(options));
1140
1065
  }
1141
1066
  /**
1142
1067
  * Get readiness of node
1143
1068
  */
1144
1069
  async getReadiness(options) {
1145
- (0, type_2.assertRequestOptions)(options);
1146
1070
  return debugStatus.getReadiness(this.getRequestOptionsForCall(options));
1147
1071
  }
1148
1072
  /**
1149
1073
  * Get mode information of node
1150
1074
  */
1151
1075
  async getNodeInfo(options) {
1152
- (0, type_2.assertRequestOptions)(options);
1153
1076
  return debugStatus.getNodeInfo(this.getRequestOptionsForCall(options));
1154
1077
  }
1155
- /**
1156
- * Connnects to a node and checks if it is a supported Bee version by the bee-js
1157
- *
1158
- * @returns true if the Bee node version is supported
1159
- * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
1160
- */
1161
- async isSupportedVersion(options) {
1162
- (0, type_2.assertRequestOptions)(options);
1163
- return debugStatus.isSupportedVersion(this.getRequestOptionsForCall(options));
1164
- }
1165
1078
  /**
1166
1079
  * Connects to a node and checks if its version matches with the one that bee-js supports.
1167
1080
  *
1168
- * Be aware that this is the most strict version check and most probably
1169
- * you will want to use more relaxed API-versions based checks like
1170
- * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
1171
- * based on your use-case.
1172
- *
1173
1081
  * @param options
1174
1082
  */
1175
1083
  async isSupportedExactVersion(options) {
1176
- (0, type_2.assertRequestOptions)(options);
1177
1084
  return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(options));
1178
1085
  }
1179
- /**
1180
- * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
1181
- *
1182
- * This is useful if you are not using `BeeDebug` class (for anything else then this check)
1183
- * and want to make sure about compatibility.
1184
- *
1185
- * @param options
1186
- */
1187
- async isSupportedMainApiVersion(options) {
1188
- (0, type_2.assertRequestOptions)(options);
1189
- return debugStatus.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
1190
- }
1191
1086
  /**
1192
1087
  *
1193
1088
  * Connects to a node and checks if its Main API version matches with the one that bee-js supports.
@@ -1197,7 +1092,6 @@ class Bee {
1197
1092
  * @param options
1198
1093
  */
1199
1094
  async isSupportedApiVersion(options) {
1200
- (0, type_2.assertRequestOptions)(options);
1201
1095
  return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(options));
1202
1096
  }
1203
1097
  /**
@@ -1207,21 +1101,18 @@ class Bee {
1207
1101
  * @param options
1208
1102
  */
1209
1103
  async getVersions(options) {
1210
- (0, type_2.assertRequestOptions)(options);
1211
1104
  return debugStatus.getVersions(this.getRequestOptionsForCall(options));
1212
1105
  }
1213
1106
  /**
1214
1107
  * Get reserve state
1215
1108
  */
1216
1109
  async getReserveState(options) {
1217
- (0, type_2.assertRequestOptions)(options);
1218
1110
  return states.getReserveState(this.getRequestOptionsForCall(options));
1219
1111
  }
1220
1112
  /**
1221
1113
  * Get chain state
1222
1114
  */
1223
1115
  async getChainState(options) {
1224
- (0, type_2.assertRequestOptions)(options);
1225
1116
  return states.getChainState(this.getRequestOptionsForCall(options));
1226
1117
  }
1227
1118
  /**
@@ -1230,7 +1121,6 @@ class Bee {
1230
1121
  * @param options
1231
1122
  */
1232
1123
  async getWalletBalance(options) {
1233
- (0, type_2.assertRequestOptions)(options);
1234
1124
  return states.getWalletBalance(this.getRequestOptionsForCall(options));
1235
1125
  }
1236
1126
  /**
@@ -1248,48 +1138,101 @@ class Bee {
1248
1138
  * @throws TypeError if non-integer value is passed to amount or depth
1249
1139
  *
1250
1140
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1251
- * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
1141
+ * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
1252
1142
  */
1253
1143
  async createPostageBatch(amount, depth, options, requestOptions) {
1254
- (0, type_2.assertPostageBatchOptions)(options);
1255
- (0, type_2.assertPositiveInteger)(amount);
1256
- (0, type_2.assertNonNegativeInteger)(depth);
1257
- (0, type_2.assertRequestOptions)(requestOptions);
1258
- if (depth < types_1.STAMPS_DEPTH_MIN) {
1259
- throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
1144
+ const amountString = (0, type_1.asNumberString)(amount, { min: 0n, name: 'amount' });
1145
+ if (options) {
1146
+ options = (0, type_1.preparePostageBatchOptions)(options);
1260
1147
  }
1261
- if (depth > types_1.STAMPS_DEPTH_MAX) {
1262
- throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
1148
+ if (depth < types_1.STAMPS_DEPTH_MIN || depth > types_1.STAMPS_DEPTH_MAX) {
1149
+ throw new error_1.BeeArgumentError(`Depth has to be between ${types_1.STAMPS_DEPTH_MIN}..${types_1.STAMPS_DEPTH_MAX}`, depth);
1263
1150
  }
1264
- if (parseInt(amount, 10) < types_1.STAMPS_AMOUNT_MIN) {
1265
- throw new error_1.BeeArgumentError(`Amount has to be at least ${types_1.STAMPS_AMOUNT_MIN} (1 day)`, amount);
1151
+ const chainState = await this.getChainState();
1152
+ const minimumAmount = BigInt(chainState.currentPrice) * 17280n;
1153
+ if (BigInt(amountString) < minimumAmount) {
1154
+ throw new error_1.BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
1266
1155
  }
1267
- const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
1156
+ const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amountString, depth, options);
1268
1157
  if (options?.waitForUsable !== false) {
1269
1158
  await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
1270
1159
  }
1271
1160
  return stamp;
1272
1161
  }
1162
+ async buyStorage(size, duration, options, requestOptions) {
1163
+ const chainState = await this.getChainState(requestOptions);
1164
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1165
+ const depth = (0, stamps_1.getDepthForSize)(size);
1166
+ if (options) {
1167
+ options = (0, type_1.preparePostageBatchOptions)(options);
1168
+ }
1169
+ return this.createPostageBatch(amount, depth, options, requestOptions);
1170
+ }
1171
+ async getStorageCost(size, duration, options) {
1172
+ const chainState = await this.getChainState(options);
1173
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1174
+ const depth = (0, stamps_1.getDepthForSize)(size);
1175
+ return (0, stamps_1.getStampCost)(depth, amount);
1176
+ }
1177
+ async extendStorageSize(postageBatchId, size, options) {
1178
+ const batch = await this.getPostageBatch(postageBatchId, options);
1179
+ const depth = (0, stamps_1.getDepthForSize)(size);
1180
+ const delta = depth - batch.depth;
1181
+ if (delta <= 0) {
1182
+ throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
1183
+ }
1184
+ await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options);
1185
+ return this.diluteBatch(batch.batchID, depth, options);
1186
+ }
1187
+ async extendStorageDuration(postageBatchId, duration, options) {
1188
+ const batch = await this.getPostageBatch(postageBatchId, options);
1189
+ const chainState = await this.getChainState(options);
1190
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1191
+ return this.topUpBatch(batch.batchID, amount, options);
1192
+ }
1193
+ async getExtensionCost(postageBatchId, size, duration, options) {
1194
+ const batch = await this.getPostageBatch(postageBatchId, options);
1195
+ const chainState = await this.getChainState(options);
1196
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1197
+ const depth = (0, stamps_1.getDepthForSize)(size);
1198
+ const currentValue = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
1199
+ const newValue = (0, stamps_1.getStampCost)(depth, amount);
1200
+ return newValue.minus(currentValue);
1201
+ }
1202
+ async getSizeExtensionCost(postageBatchId, size, options) {
1203
+ const batch = await this.getPostageBatch(postageBatchId, options);
1204
+ const depth = (0, stamps_1.getDepthForSize)(size);
1205
+ const delta = depth - batch.depth;
1206
+ if (delta <= 0) {
1207
+ throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
1208
+ }
1209
+ const currentPaid = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
1210
+ const newPaid = (0, stamps_1.getStampCost)(depth, batch.amount);
1211
+ return newPaid.minus(currentPaid);
1212
+ }
1213
+ async getDurationExtensionCost(postageBatchId, duration, options) {
1214
+ const batch = await this.getPostageBatch(postageBatchId, options);
1215
+ const chainState = await this.getChainState(options);
1216
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1217
+ return (0, stamps_1.getStampCost)(batch.depth, amount);
1218
+ }
1273
1219
  /**
1274
1220
  * Topup a fresh amount of BZZ to given Postage Batch.
1275
1221
  *
1276
1222
  * For better understanding what each parameter means and what are the optimal values please see
1277
1223
  * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
1278
1224
  *
1279
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
1280
- *
1281
1225
  * @param postageBatchId Batch ID
1282
1226
  * @param amount Amount to be added to the batch
1283
1227
  * @param options Request options
1284
1228
  *
1285
1229
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1286
- * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
1230
+ * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{batch_id}~1{amount}/patch)
1287
1231
  */
1288
1232
  async topUpBatch(postageBatchId, amount, options) {
1289
- (0, type_2.assertRequestOptions)(options);
1290
- (0, type_2.assertNonNegativeInteger)(amount, 'Amount');
1291
- (0, type_2.assertBatchId)(postageBatchId);
1292
- await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
1233
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
1234
+ const amountString = (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
1235
+ return stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amountString);
1293
1236
  }
1294
1237
  /**
1295
1238
  * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
@@ -1298,20 +1241,17 @@ class Bee {
1298
1241
  * For better understanding what each parameter means and what are the optimal values please see
1299
1242
  * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
1300
1243
  *
1301
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
1302
- *
1303
1244
  * @param postageBatchId Batch ID
1304
1245
  * @param depth Amount to be added to the batch
1305
1246
  * @param options Request options
1306
1247
  *
1307
1248
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1308
- * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
1249
+ * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1dilute~1%7Bbatch_id%7D~1%7Bdepth%7D/patch)
1309
1250
  */
1310
1251
  async diluteBatch(postageBatchId, depth, options) {
1311
- (0, type_2.assertRequestOptions)(options);
1312
- (0, type_2.assertNonNegativeInteger)(depth, 'Depth');
1313
- (0, type_2.assertBatchId)(postageBatchId);
1314
- await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
1252
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
1253
+ depth = cafe_utility_1.Types.asNumber(depth, { name: 'depth', min: 18, max: 255 });
1254
+ return stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
1315
1255
  }
1316
1256
  /**
1317
1257
  * Return details for specific postage batch.
@@ -1319,11 +1259,10 @@ class Bee {
1319
1259
  * @param postageBatchId Batch ID
1320
1260
  *
1321
1261
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1322
- * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
1262
+ * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
1323
1263
  */
1324
1264
  async getPostageBatch(postageBatchId, options) {
1325
- (0, type_2.assertRequestOptions)(options);
1326
- (0, type_2.assertBatchId)(postageBatchId);
1265
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
1327
1266
  return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
1328
1267
  }
1329
1268
  /**
@@ -1332,35 +1271,31 @@ class Bee {
1332
1271
  * @param postageBatchId Batch ID
1333
1272
  *
1334
1273
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1335
- * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
1274
+ * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D~1buckets/get)
1336
1275
  */
1337
1276
  async getPostageBatchBuckets(postageBatchId, options) {
1338
- (0, type_2.assertRequestOptions)(options);
1339
- (0, type_2.assertBatchId)(postageBatchId);
1277
+ postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
1340
1278
  return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
1341
1279
  }
1342
1280
  /**
1343
1281
  * Return all postage batches that has the node available.
1344
1282
  *
1345
1283
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1346
- * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
1284
+ * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
1347
1285
  */
1348
1286
  async getAllPostageBatch(options) {
1349
- (0, type_2.assertRequestOptions)(options);
1350
1287
  return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
1351
1288
  }
1352
1289
  /**
1353
1290
  * Return all globally available postage batches.
1354
1291
  */
1355
1292
  async getAllGlobalPostageBatch(options) {
1356
- (0, type_2.assertRequestOptions)(options);
1357
1293
  return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
1358
1294
  }
1359
1295
  /**
1360
1296
  * Return lists of all current pending transactions that the Bee made
1361
1297
  */
1362
1298
  async getAllPendingTransactions(options) {
1363
- (0, type_2.assertRequestOptions)(options);
1364
1299
  return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
1365
1300
  }
1366
1301
  /**
@@ -1368,8 +1303,7 @@ class Bee {
1368
1303
  * @param transactionHash
1369
1304
  */
1370
1305
  async getPendingTransaction(transactionHash, options) {
1371
- (0, type_2.assertRequestOptions)(options);
1372
- (0, type_2.assertTransactionHash)(transactionHash);
1306
+ transactionHash = new typed_bytes_1.TransactionId(transactionHash);
1373
1307
  return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
1374
1308
  }
1375
1309
  /**
@@ -1379,8 +1313,7 @@ class Bee {
1379
1313
  * @param transactionHash
1380
1314
  */
1381
1315
  async rebroadcastPendingTransaction(transactionHash, options) {
1382
- (0, type_2.assertRequestOptions)(options);
1383
- (0, type_2.assertTransactionHash)(transactionHash);
1316
+ transactionHash = new typed_bytes_1.TransactionId(transactionHash);
1384
1317
  return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
1385
1318
  }
1386
1319
  /**
@@ -1389,12 +1322,12 @@ class Bee {
1389
1322
  * @param gasPrice
1390
1323
  */
1391
1324
  async cancelPendingTransaction(transactionHash, gasPrice, options) {
1392
- (0, type_2.assertRequestOptions)(options);
1393
- (0, type_2.assertTransactionHash)(transactionHash);
1325
+ transactionHash = new typed_bytes_1.TransactionId(transactionHash);
1326
+ let gasPriceString;
1394
1327
  if (gasPrice) {
1395
- (0, type_2.assertNonNegativeInteger)(gasPrice);
1328
+ gasPriceString = (0, type_1.asNumberString)(gasPrice, { min: 0n, name: 'gasPrice' });
1396
1329
  }
1397
- return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
1330
+ return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPriceString);
1398
1331
  }
1399
1332
  /**
1400
1333
  * Gets the staked amount of BZZ (in PLUR unit) as number string.
@@ -1402,7 +1335,6 @@ class Bee {
1402
1335
  * @param options
1403
1336
  */
1404
1337
  async getStake(options) {
1405
- (0, type_2.assertRequestOptions)(options);
1406
1338
  return stake.getStake(this.getRequestOptionsForCall(options));
1407
1339
  }
1408
1340
  /**
@@ -1414,9 +1346,11 @@ class Bee {
1414
1346
  * @param options
1415
1347
  */
1416
1348
  async depositStake(amount, options, requestOptions) {
1417
- (0, type_2.assertTransactionOptions)(options);
1418
- (0, type_2.assertRequestOptions)(requestOptions);
1419
- await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
1349
+ const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
1350
+ if (options) {
1351
+ options = (0, type_1.prepareTransactionOptions)(options);
1352
+ }
1353
+ return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
1420
1354
  }
1421
1355
  /**
1422
1356
  * Get current status of node in redistribution game
@@ -1424,7 +1358,6 @@ class Bee {
1424
1358
  * @param options
1425
1359
  */
1426
1360
  async getRedistributionState(options) {
1427
- (0, type_2.assertRequestOptions)(options);
1428
1361
  return stake.getRedistributionState(this.getRequestOptionsForCall(options));
1429
1362
  }
1430
1363
  async waitForUsablePostageStamp(id, timeout = 240000) {
@@ -1436,26 +1369,17 @@ class Bee {
1436
1369
  return;
1437
1370
  }
1438
1371
  }
1439
- catch (error) { }
1372
+ catch (error) {
1373
+ // ignore error
1374
+ }
1440
1375
  await cafe_utility_1.System.sleepMillis(TIME_STEP);
1441
1376
  }
1442
1377
  throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
1443
1378
  }
1444
- /**
1445
- * @param signer
1446
- * @private
1447
- * @throws BeeError if either no Signer was passed or no default Signer was specified for the instance
1448
- */
1449
- resolveSigner(signer) {
1450
- if (signer) {
1451
- return (0, signer_1.makeSigner)(signer);
1452
- }
1453
- if (this.signer) {
1454
- return this.signer;
1455
- }
1456
- throw new TypeError('You have to pass Signer as property to either the method call or constructor! Non found.');
1457
- }
1458
1379
  getRequestOptionsForCall(options) {
1380
+ if (options) {
1381
+ options = (0, type_1.prepareBeeRequestOptions)(options);
1382
+ }
1459
1383
  return options ? cafe_utility_1.Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
1460
1384
  }
1461
1385
  }