@ethersphere/bee-js 6.9.1 → 7.0.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 (143) hide show
  1. package/README.md +107 -65
  2. package/dist/cjs/bee.js +533 -6
  3. package/dist/cjs/chunk/cac.js +3 -3
  4. package/dist/cjs/chunk/soc.js +5 -5
  5. package/dist/cjs/chunk/span.js +2 -6
  6. package/dist/cjs/feed/identifier.js +2 -2
  7. package/dist/cjs/feed/index.js +5 -6
  8. package/dist/cjs/feed/retrievable.js +2 -2
  9. package/dist/cjs/index.js +1 -3
  10. package/dist/cjs/modules/bytes.js +3 -3
  11. package/dist/cjs/modules/bzz.js +9 -20
  12. package/dist/cjs/modules/chunk.js +2 -2
  13. package/dist/cjs/modules/debug/balance.js +4 -4
  14. package/dist/cjs/modules/debug/chequebook.js +8 -8
  15. package/dist/cjs/modules/debug/chunk.js +2 -19
  16. package/dist/cjs/modules/debug/settlements.js +2 -2
  17. package/dist/cjs/modules/debug/stake.js +3 -3
  18. package/dist/cjs/modules/debug/states.js +4 -19
  19. package/dist/cjs/modules/debug/status.js +15 -32
  20. package/dist/cjs/modules/debug/tag.js +1 -1
  21. package/dist/cjs/modules/debug/transactions.js +4 -4
  22. package/dist/cjs/modules/feed.js +6 -7
  23. package/dist/cjs/modules/pinning.js +4 -4
  24. package/dist/cjs/modules/pss.js +1 -1
  25. package/dist/cjs/modules/soc.js +1 -1
  26. package/dist/cjs/modules/status.js +1 -1
  27. package/dist/cjs/modules/stewardship.js +1 -1
  28. package/dist/cjs/package.json +4 -0
  29. package/dist/cjs/types/index.js +5 -1
  30. package/dist/cjs/utils/collection.js +7 -22
  31. package/dist/cjs/utils/collection.node.js +2 -1
  32. package/dist/cjs/utils/data.browser.js +1 -49
  33. package/dist/cjs/utils/error.js +2 -6
  34. package/dist/cjs/utils/eth.js +1 -1
  35. package/dist/cjs/utils/expose.js +1 -8
  36. package/dist/cjs/utils/file.js +2 -2
  37. package/dist/cjs/utils/http.js +6 -25
  38. package/dist/cjs/utils/tar-uploader.browser.js +26 -0
  39. package/dist/cjs/utils/tar-uploader.js +27 -0
  40. package/dist/cjs/utils/tar-writer.browser.js +17 -0
  41. package/dist/cjs/utils/tar-writer.js +21 -0
  42. package/dist/cjs/utils/tar.browser.js +65 -0
  43. package/dist/cjs/utils/tar.js +47 -21
  44. package/dist/cjs/utils/type.js +7 -3
  45. package/dist/cjs/utils/url.js +1 -6
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +0 -42
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee.js +533 -9
  50. package/dist/mjs/chunk/cac.js +4 -4
  51. package/dist/mjs/chunk/soc.js +6 -6
  52. package/dist/mjs/chunk/span.js +2 -6
  53. package/dist/mjs/feed/identifier.js +2 -2
  54. package/dist/mjs/feed/index.js +5 -9
  55. package/dist/mjs/feed/retrievable.js +2 -2
  56. package/dist/mjs/index.js +1 -2
  57. package/dist/mjs/modules/bytes.js +3 -3
  58. package/dist/mjs/modules/bzz.js +8 -20
  59. package/dist/mjs/modules/chunk.js +2 -2
  60. package/dist/mjs/modules/debug/balance.js +4 -4
  61. package/dist/mjs/modules/debug/chequebook.js +8 -8
  62. package/dist/mjs/modules/debug/chunk.js +1 -17
  63. package/dist/mjs/modules/debug/settlements.js +2 -2
  64. package/dist/mjs/modules/debug/stake.js +3 -3
  65. package/dist/mjs/modules/debug/states.js +4 -19
  66. package/dist/mjs/modules/debug/status.js +15 -34
  67. package/dist/mjs/modules/debug/tag.js +1 -1
  68. package/dist/mjs/modules/debug/transactions.js +4 -4
  69. package/dist/mjs/modules/feed.js +6 -7
  70. package/dist/mjs/modules/pinning.js +4 -4
  71. package/dist/mjs/modules/pss.js +1 -1
  72. package/dist/mjs/modules/soc.js +1 -1
  73. package/dist/mjs/modules/status.js +1 -1
  74. package/dist/mjs/modules/stewardship.js +1 -1
  75. package/dist/mjs/package.json +6 -2
  76. package/dist/mjs/types/index.js +4 -0
  77. package/dist/mjs/utils/collection.js +7 -22
  78. package/dist/mjs/utils/collection.node.js +2 -1
  79. package/dist/mjs/utils/data.browser.js +0 -57
  80. package/dist/mjs/utils/error.js +2 -6
  81. package/dist/mjs/utils/eth.js +1 -1
  82. package/dist/mjs/utils/expose.js +0 -1
  83. package/dist/mjs/utils/http.js +5 -2
  84. package/dist/mjs/utils/tar-uploader.browser.js +22 -0
  85. package/dist/mjs/utils/tar-uploader.js +23 -0
  86. package/dist/mjs/utils/tar-writer.browser.js +12 -0
  87. package/dist/mjs/utils/tar-writer.js +16 -0
  88. package/dist/mjs/utils/tar.browser.js +61 -0
  89. package/dist/mjs/utils/tar.js +45 -16
  90. package/dist/mjs/utils/type.js +4 -1
  91. package/dist/mjs/utils/url.js +1 -6
  92. package/dist/types/bee.d.ts +305 -4
  93. package/dist/types/chunk/soc.d.ts +2 -2
  94. package/dist/types/feed/identifier.d.ts +1 -1
  95. package/dist/types/index.d.ts +1 -3
  96. package/dist/types/modules/bytes.d.ts +3 -3
  97. package/dist/types/modules/bzz.d.ts +14 -6
  98. package/dist/types/modules/chunk.d.ts +2 -2
  99. package/dist/types/modules/debug/balance.d.ts +4 -4
  100. package/dist/types/modules/debug/chequebook.d.ts +8 -8
  101. package/dist/types/modules/debug/chunk.d.ts +1 -10
  102. package/dist/types/modules/debug/settlements.d.ts +2 -2
  103. package/dist/types/modules/debug/stake.d.ts +3 -3
  104. package/dist/types/modules/debug/states.d.ts +3 -3
  105. package/dist/types/modules/debug/status.d.ts +10 -20
  106. package/dist/types/modules/debug/tag.d.ts +1 -1
  107. package/dist/types/modules/debug/transactions.d.ts +4 -4
  108. package/dist/types/modules/feed.d.ts +6 -9
  109. package/dist/types/modules/pinning.d.ts +4 -4
  110. package/dist/types/modules/pss.d.ts +1 -1
  111. package/dist/types/modules/soc.d.ts +1 -1
  112. package/dist/types/modules/status.d.ts +1 -1
  113. package/dist/types/modules/stewardship.d.ts +1 -1
  114. package/dist/types/types/debug.d.ts +0 -3
  115. package/dist/types/types/index.d.ts +9 -17
  116. package/dist/types/utils/collection.browser.d.ts +1 -1
  117. package/dist/types/utils/collection.d.ts +3 -3
  118. package/dist/types/utils/collection.node.d.ts +1 -1
  119. package/dist/types/utils/data.browser.d.ts +0 -7
  120. package/dist/types/utils/data.d.ts +1 -2
  121. package/dist/types/utils/error.d.ts +2 -7
  122. package/dist/types/utils/eth.d.ts +1 -1
  123. package/dist/types/utils/expose.d.ts +0 -1
  124. package/dist/types/utils/tar-uploader.browser.d.ts +4 -0
  125. package/dist/types/utils/tar-uploader.d.ts +4 -0
  126. package/dist/types/utils/tar-writer.browser.d.ts +3 -0
  127. package/dist/types/utils/tar-writer.d.ts +3 -0
  128. package/dist/types/utils/tar.browser.d.ts +9 -0
  129. package/dist/types/utils/tar.d.ts +10 -2
  130. package/dist/types/utils/type.d.ts +4 -1
  131. package/package.json +4 -19
  132. package/dist/cjs/bee-debug.js +0 -590
  133. package/dist/cjs/chunk/serialize.js +0 -19
  134. package/dist/cjs/utils/stream.js +0 -146
  135. package/dist/cjs/utils/uint64.js +0 -29
  136. package/dist/mjs/bee-debug.js +0 -560
  137. package/dist/mjs/chunk/serialize.js +0 -15
  138. package/dist/mjs/utils/stream.js +0 -129
  139. package/dist/mjs/utils/uint64.js +0 -22
  140. package/dist/types/bee-debug.d.ts +0 -323
  141. package/dist/types/chunk/serialize.d.ts +0 -6
  142. package/dist/types/utils/stream.d.ts +0 -40
  143. package/dist/types/utils/uint64.d.ts +0 -4
@@ -1,590 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.BeeDebug = void 0;
27
- const balance = __importStar(require("./modules/debug/balance"));
28
- const chequebook = __importStar(require("./modules/debug/chequebook"));
29
- const connectivity = __importStar(require("./modules/debug/connectivity"));
30
- const settlements = __importStar(require("./modules/debug/settlements"));
31
- const stake = __importStar(require("./modules/debug/stake"));
32
- const states = __importStar(require("./modules/debug/states"));
33
- const status = __importStar(require("./modules/debug/status"));
34
- const transactions = __importStar(require("./modules/debug/transactions"));
35
- const cafe_utility_1 = require("cafe-utility");
36
- const stamps = __importStar(require("./modules/debug/stamps"));
37
- const tag = __importStar(require("./modules/debug/tag"));
38
- const types_1 = require("./types");
39
- const error_1 = require("./utils/error");
40
- const type_1 = require("./utils/type");
41
- const url_1 = require("./utils/url");
42
- class BeeDebug {
43
- constructor(url, options) {
44
- (0, url_1.assertBeeUrl)(url);
45
- // Remove last slash if present, as our endpoint strings starts with `/...`
46
- // which could lead to double slash in URL to which Bee responds with
47
- // unnecessary redirects.
48
- this.url = (0, url_1.stripLastSlash)(url);
49
- this.requestOptions = {
50
- baseURL: this.url,
51
- timeout: options?.timeout ?? false,
52
- headers: options?.headers,
53
- onRequest: options?.onRequest,
54
- adapter: options?.adapter,
55
- };
56
- }
57
- async getNodeAddresses(options) {
58
- (0, type_1.assertRequestOptions)(options);
59
- return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
60
- }
61
- async getBlocklist(options) {
62
- (0, type_1.assertRequestOptions)(options);
63
- return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
64
- }
65
- /**
66
- * Retrieve tag extended information from Bee node
67
- *
68
- * @param tagUid UID or tag object to be retrieved
69
- * @throws TypeError if tagUid is in not correct format
70
- *
71
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
72
- * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
73
- *
74
- */
75
- async retrieveExtendedTag(tagUid, options) {
76
- (0, type_1.assertRequestOptions)(options);
77
- if ((0, type_1.isTag)(tagUid)) {
78
- tagUid = tagUid.uid;
79
- }
80
- else if (typeof tagUid === 'number') {
81
- (0, type_1.assertNonNegativeInteger)(tagUid, 'UID');
82
- }
83
- else {
84
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
85
- }
86
- return tag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
87
- }
88
- /**
89
- * Get list of peers for this node
90
- */
91
- async getPeers(options) {
92
- (0, type_1.assertRequestOptions)(options);
93
- return connectivity.getPeers(this.getRequestOptionsForCall(options));
94
- }
95
- async removePeer(peer, options) {
96
- (0, type_1.assertRequestOptions)(options);
97
- (0, type_1.assertAddress)(peer);
98
- return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
99
- }
100
- async getTopology(options) {
101
- (0, type_1.assertRequestOptions)(options);
102
- return connectivity.getTopology(this.getRequestOptionsForCall(options));
103
- }
104
- async pingPeer(peer, options) {
105
- (0, type_1.assertRequestOptions)(options);
106
- (0, type_1.assertAddress)(peer);
107
- return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
108
- }
109
- /*
110
- * Balance endpoints
111
- */
112
- /**
113
- * Get the balances with all known peers including prepaid services
114
- */
115
- async getAllBalances(options) {
116
- (0, type_1.assertRequestOptions)(options);
117
- return balance.getAllBalances(this.getRequestOptionsForCall(options));
118
- }
119
- /**
120
- * Get the balances with a specific peer including prepaid services
121
- *
122
- * @param address Swarm address of peer
123
- */
124
- async getPeerBalance(address, options) {
125
- (0, type_1.assertRequestOptions)(options);
126
- (0, type_1.assertAddress)(address);
127
- return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
128
- }
129
- /**
130
- * Get the past due consumption balances with all known peers
131
- */
132
- async getPastDueConsumptionBalances(options) {
133
- (0, type_1.assertRequestOptions)(options);
134
- return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
135
- }
136
- /**
137
- * Get the past due consumption balance with a specific peer
138
- *
139
- * @param address Swarm address of peer
140
- */
141
- async getPastDueConsumptionPeerBalance(address, options) {
142
- (0, type_1.assertRequestOptions)(options);
143
- (0, type_1.assertAddress)(address);
144
- return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
145
- }
146
- /*
147
- * Chequebook endpoints
148
- */
149
- /**
150
- * Get the address of the chequebook contract used.
151
- *
152
- * **Warning:** The address is returned with 0x prefix unlike all other calls.
153
- * https://github.com/ethersphere/bee/issues/1443
154
- */
155
- async getChequebookAddress(options) {
156
- (0, type_1.assertRequestOptions)(options);
157
- return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
158
- }
159
- /**
160
- * Get the balance of the chequebook
161
- */
162
- async getChequebookBalance(options) {
163
- (0, type_1.assertRequestOptions)(options);
164
- return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
165
- }
166
- /**
167
- * Get last cheques for all peers
168
- */
169
- async getLastCheques(options) {
170
- (0, type_1.assertRequestOptions)(options);
171
- return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
172
- }
173
- /**
174
- * Get last cheques for the peer
175
- *
176
- * @param address Swarm address of peer
177
- */
178
- async getLastChequesForPeer(address, options) {
179
- (0, type_1.assertRequestOptions)(options);
180
- (0, type_1.assertAddress)(address);
181
- return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
182
- }
183
- /**
184
- * Get last cashout action for the peer
185
- *
186
- * @param address Swarm address of peer
187
- */
188
- async getLastCashoutAction(address, options) {
189
- (0, type_1.assertRequestOptions)(options);
190
- (0, type_1.assertAddress)(address);
191
- return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
192
- }
193
- /**
194
- * Cashout the last cheque for the peer
195
- *
196
- * @param address Swarm address of peer
197
- * @param options
198
- * @param options.gasPrice Gas price for the cashout transaction in WEI
199
- * @param options.gasLimit Gas limit for the cashout transaction in WEI
200
- */
201
- async cashoutLastCheque(address, options, requestOptions) {
202
- (0, type_1.assertCashoutOptions)(options);
203
- (0, type_1.assertAddress)(address);
204
- return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
205
- }
206
- /**
207
- * Deposit tokens from overlay address into chequebook
208
- *
209
- * @param amount Amount of tokens to deposit (must be positive integer)
210
- * @param gasPrice Gas Price in WEI for the transaction call
211
- * @return string Hash of the transaction
212
- */
213
- async depositTokens(amount, gasPrice, options) {
214
- (0, type_1.assertRequestOptions)(options);
215
- (0, type_1.assertNonNegativeInteger)(amount);
216
- if (gasPrice) {
217
- (0, type_1.assertNonNegativeInteger)(gasPrice);
218
- }
219
- return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
220
- }
221
- /**
222
- * Withdraw tokens from the chequebook to the overlay address
223
- *
224
- * @param amount Amount of tokens to withdraw (must be positive integer)
225
- * @param gasPrice Gas Price in WEI for the transaction call
226
- * @return string Hash of the transaction
227
- */
228
- async withdrawTokens(amount, gasPrice, options) {
229
- (0, type_1.assertRequestOptions)(options);
230
- (0, type_1.assertNonNegativeInteger)(amount);
231
- if (gasPrice) {
232
- (0, type_1.assertNonNegativeInteger)(gasPrice);
233
- }
234
- return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
235
- }
236
- /*
237
- * Settlements endpoint
238
- */
239
- /**
240
- * Get amount of sent and received from settlements with a peer
241
- *
242
- * @param address Swarm address of peer
243
- */
244
- async getSettlements(address, options) {
245
- (0, type_1.assertRequestOptions)(options);
246
- (0, type_1.assertAddress)(address);
247
- return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
248
- }
249
- /**
250
- * Get settlements with all known peers and total amount sent or received
251
- */
252
- async getAllSettlements(options) {
253
- (0, type_1.assertRequestOptions)(options);
254
- return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
255
- }
256
- /**
257
- * Get status of node
258
- */
259
- async getStatus(options) {
260
- (0, type_1.assertRequestOptions)(options);
261
- return status.getDebugStatus(this.getRequestOptionsForCall(options));
262
- }
263
- /**
264
- * Get health of node
265
- */
266
- async getHealth(options) {
267
- (0, type_1.assertRequestOptions)(options);
268
- return status.getHealth(this.getRequestOptionsForCall(options));
269
- }
270
- /**
271
- * Get readiness of node
272
- */
273
- async getReadiness(options) {
274
- (0, type_1.assertRequestOptions)(options);
275
- return status.getReadiness(this.getRequestOptionsForCall(options));
276
- }
277
- /**
278
- * Get mode information of node
279
- */
280
- async getNodeInfo(options) {
281
- (0, type_1.assertRequestOptions)(options);
282
- return status.getNodeInfo(this.getRequestOptionsForCall(options));
283
- }
284
- /**
285
- * Connnects to a node and checks if it is a supported Bee version by the bee-js
286
- *
287
- * @returns true if the Bee node version is supported
288
- * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
289
- */
290
- async isSupportedVersion(options) {
291
- (0, type_1.assertRequestOptions)(options);
292
- return status.isSupportedVersion(this.getRequestOptionsForCall(options));
293
- }
294
- /**
295
- * Connects to a node and checks if its version matches with the one that bee-js supports.
296
- *
297
- * Be aware that this is the most strict version check and most probably
298
- * you will want to use more relaxed API-versions based checks like
299
- * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
300
- * based on your use-case.
301
- *
302
- * @param options
303
- */
304
- async isSupportedExactVersion(options) {
305
- (0, type_1.assertRequestOptions)(options);
306
- return status.isSupportedExactVersion(this.getRequestOptionsForCall(options));
307
- }
308
- /**
309
- * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
310
- *
311
- * This is useful if you are not using `BeeDebug` class (for anything else then this check)
312
- * and want to make sure about compatibility.
313
- *
314
- * @param options
315
- */
316
- async isSupportedMainApiVersion(options) {
317
- (0, type_1.assertRequestOptions)(options);
318
- return status.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
319
- }
320
- /**
321
- * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
322
- *
323
- * This is useful if you are not using `Bee` class in your application and want to make sure
324
- * about compatibility.
325
- *
326
- * @param options
327
- */
328
- async isSupportedDebugApiVersion(options) {
329
- (0, type_1.assertRequestOptions)(options);
330
- return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
331
- }
332
- /**
333
- *
334
- * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
335
- *
336
- * This should be the main way how to check compatibility for your app and Bee node.
337
- *
338
- * @param options
339
- */
340
- async isSupportedApiVersion(options) {
341
- (0, type_1.assertRequestOptions)(options);
342
- return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
343
- }
344
- /**
345
- * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
346
- * and versions that bee-js supports (properties prefixed with `supported*`).
347
- *
348
- * @param options
349
- */
350
- async getVersions(options) {
351
- (0, type_1.assertRequestOptions)(options);
352
- return status.getVersions(this.getRequestOptionsForCall(options));
353
- }
354
- /**
355
- * Get reserve state
356
- */
357
- async getReserveState(options) {
358
- (0, type_1.assertRequestOptions)(options);
359
- return states.getReserveState(this.getRequestOptionsForCall(options));
360
- }
361
- /**
362
- * Get chain state
363
- */
364
- async getChainState(options) {
365
- (0, type_1.assertRequestOptions)(options);
366
- return states.getChainState(this.getRequestOptionsForCall(options));
367
- }
368
- /**
369
- * Get wallet balances for xDai and BZZ of the Bee node
370
- *
371
- * @param options
372
- */
373
- async getWalletBalance(options) {
374
- (0, type_1.assertRequestOptions)(options);
375
- return states.getWalletBalance(this.getRequestOptionsForCall(options));
376
- }
377
- /**
378
- * Creates new postage batch from the funds that the node has available in its Ethereum account.
379
- *
380
- * For better understanding what each parameter means and what are the optimal values please see
381
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
382
- *
383
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
384
- *
385
- * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
386
- * @param depth Logarithm of the number of chunks that can be stamped with the batch.
387
- * @param options Options for creation of postage batch
388
- * @throws BeeArgumentError when negative amount or depth is specified
389
- * @throws TypeError if non-integer value is passed to amount or depth
390
- *
391
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
392
- * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
393
- */
394
- async createPostageBatch(amount, depth, options, requestOptions) {
395
- (0, type_1.assertPostageBatchOptions)(options);
396
- (0, type_1.assertPositiveInteger)(amount);
397
- (0, type_1.assertNonNegativeInteger)(depth);
398
- if (depth < types_1.STAMPS_DEPTH_MIN) {
399
- throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
400
- }
401
- if (depth > types_1.STAMPS_DEPTH_MAX) {
402
- throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
403
- }
404
- const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
405
- if (options?.waitForUsable !== false) {
406
- await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
407
- }
408
- return stamp;
409
- }
410
- /**
411
- * Topup a fresh amount of BZZ to given Postage Batch.
412
- *
413
- * For better understanding what each parameter means and what are the optimal values please see
414
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
415
- *
416
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
417
- *
418
- * @param postageBatchId Batch ID
419
- * @param amount Amount to be added to the batch
420
- * @param options Request options
421
- *
422
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
423
- * @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)
424
- */
425
- async topUpBatch(postageBatchId, amount, options) {
426
- (0, type_1.assertRequestOptions)(options);
427
- (0, type_1.assertNonNegativeInteger)(amount, 'Amount');
428
- (0, type_1.assertBatchId)(postageBatchId);
429
- await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
430
- }
431
- /**
432
- * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
433
- * the Postage Batch to be used for more chunks.
434
- *
435
- * For better understanding what each parameter means and what are the optimal values please see
436
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
437
- *
438
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
439
- *
440
- * @param postageBatchId Batch ID
441
- * @param depth Amount to be added to the batch
442
- * @param options Request options
443
- *
444
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
445
- * @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)
446
- */
447
- async diluteBatch(postageBatchId, depth, options) {
448
- (0, type_1.assertRequestOptions)(options);
449
- (0, type_1.assertNonNegativeInteger)(depth, 'Depth');
450
- (0, type_1.assertBatchId)(postageBatchId);
451
- await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
452
- }
453
- /**
454
- * Return details for specific postage batch.
455
- *
456
- * @param postageBatchId Batch ID
457
- *
458
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
459
- * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
460
- */
461
- async getPostageBatch(postageBatchId, options) {
462
- (0, type_1.assertRequestOptions)(options);
463
- (0, type_1.assertBatchId)(postageBatchId);
464
- return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
465
- }
466
- /**
467
- * Return detailed information related to buckets for specific postage batch.
468
- *
469
- * @param postageBatchId Batch ID
470
- *
471
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
472
- * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
473
- */
474
- async getPostageBatchBuckets(postageBatchId, options) {
475
- (0, type_1.assertRequestOptions)(options);
476
- (0, type_1.assertBatchId)(postageBatchId);
477
- return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
478
- }
479
- /**
480
- * Return all postage batches that has the node available.
481
- *
482
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
483
- * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
484
- */
485
- async getAllPostageBatch(options) {
486
- (0, type_1.assertRequestOptions)(options);
487
- return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
488
- }
489
- /**
490
- * Return all globally available postage batches.
491
- */
492
- async getAllGlobalPostageBatch(options) {
493
- (0, type_1.assertRequestOptions)(options);
494
- return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
495
- }
496
- /**
497
- * Return lists of all current pending transactions that the Bee made
498
- */
499
- async getAllPendingTransactions(options) {
500
- (0, type_1.assertRequestOptions)(options);
501
- return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
502
- }
503
- /**
504
- * Return transaction information for specific transaction
505
- * @param transactionHash
506
- */
507
- async getPendingTransaction(transactionHash, options) {
508
- (0, type_1.assertRequestOptions)(options);
509
- (0, type_1.assertTransactionHash)(transactionHash);
510
- return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
511
- }
512
- /**
513
- * Rebroadcast already created transaction.
514
- * This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
515
- *
516
- * @param transactionHash
517
- */
518
- async rebroadcastPendingTransaction(transactionHash, options) {
519
- (0, type_1.assertRequestOptions)(options);
520
- (0, type_1.assertTransactionHash)(transactionHash);
521
- return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
522
- }
523
- /**
524
- * Cancel currently pending transaction
525
- * @param transactionHash
526
- * @param gasPrice
527
- */
528
- async cancelPendingTransaction(transactionHash, gasPrice, options) {
529
- (0, type_1.assertRequestOptions)(options);
530
- (0, type_1.assertTransactionHash)(transactionHash);
531
- if (gasPrice) {
532
- (0, type_1.assertNonNegativeInteger)(gasPrice);
533
- }
534
- return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
535
- }
536
- /**
537
- * Gets the staked amount of BZZ (in PLUR unit) as number string.
538
- *
539
- * @param options
540
- */
541
- async getStake(options) {
542
- (0, type_1.assertRequestOptions)(options);
543
- return stake.getStake(this.getRequestOptionsForCall(options));
544
- }
545
- /**
546
- * Deposits given amount of BZZ token (in PLUR unit).
547
- *
548
- * Be aware that staked BZZ tokens can **not** be withdrawn.
549
- *
550
- * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
551
- * @param options
552
- */
553
- async depositStake(amount, options, requestOptions) {
554
- (0, type_1.assertRequestOptions)(options);
555
- (0, type_1.assertTransactionOptions)(options);
556
- await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
557
- }
558
- /**
559
- * Get current status of node in redistribution game
560
- *
561
- * @param options
562
- */
563
- async getRedistributionState(options) {
564
- (0, type_1.assertRequestOptions)(options);
565
- return stake.getRedistributionState(this.getRequestOptionsForCall(options));
566
- }
567
- async waitForUsablePostageStamp(id, timeout = 240000) {
568
- const TIME_STEP = 2000;
569
- for (let time = 0; time < timeout; time += TIME_STEP) {
570
- try {
571
- const stamp = await this.getPostageBatch(id);
572
- if (stamp.usable) {
573
- return;
574
- }
575
- }
576
- catch (error) {
577
- const message = error?.response?.data?.message || error?.message || '';
578
- if (!message.includes('batch not usable')) {
579
- throw error;
580
- }
581
- }
582
- await cafe_utility_1.System.sleepMillis(TIME_STEP);
583
- }
584
- throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
585
- }
586
- getRequestOptionsForCall(options) {
587
- return options ? cafe_utility_1.Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
588
- }
589
- }
590
- exports.BeeDebug = BeeDebug;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeBytes = void 0;
4
- /**
5
- * Helper function for serialize byte arrays
6
- *
7
- * @param arrays Any number of byte array arguments
8
- */
9
- function serializeBytes(...arrays) {
10
- const length = arrays.reduce((prev, curr) => prev + curr.length, 0);
11
- const buffer = new Uint8Array(length);
12
- let offset = 0;
13
- arrays.forEach(arr => {
14
- buffer.set(arr, offset);
15
- offset += arr.length;
16
- });
17
- return buffer;
18
- }
19
- exports.serializeBytes = serializeBytes;